Skip to content

Commit

Permalink
fix: disable warning 61 (unboxable-type-in-prim-decl) for deriving
Browse files Browse the repository at this point in the history
abstract externals
  • Loading branch information
anmonteiro committed Jun 27, 2023
1 parent a1a7884 commit 3b4c576
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 21 deletions.
3 changes: 3 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ Unreleased
- `Dom.*`: we now ship a `melange.dom` library that includes the modules
containing Node.js bindings. This library is included by default so the
`Dom` module will always be available in Melange projects.
- Disable warning 61 (`unboxable-type-in-prim-decl`) for externals generated by
`[@@deriving abstract]`
([#641](https://github.com/melange-re/melange/pull/641),

1.0.0 2023-05-31
---------------
Expand Down
18 changes: 18 additions & 0 deletions ppx/ast_attributes.ml
Original file line number Diff line number Diff line change
Expand Up @@ -394,3 +394,21 @@ let is_inline : attr -> bool =
fun { attr_name = { txt; _ }; _ } -> txt = "bs.inline" || txt = "inline"

let has_inline_payload (attrs : t) = Ext_list.find_first attrs is_inline

(* We disable warning 61 in Melange externals since they're substantially
different from OCaml externals. This warning doesn't make sense for a JS
runtime *)
let unboxable_type_in_prim_decl : Parsetree.attribute =
let open Ast_helper in
{
attr_name = { txt = "ocaml.warning"; loc = Location.none };
attr_payload =
PStr
[
Str.eval
(Exp.constant
(Pconst_string
("-unboxable-type-in-prim-decl", Location.none, None)));
];
attr_loc = Location.none;
}
1 change: 1 addition & 0 deletions ppx/ast_attributes.mli
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ val rs_externals : t -> string list -> bool
type as_const_payload = Int of int | Str of string | Js_literal_str of string

val iter_process_bs_string_or_int_as : t -> as_const_payload option
val unboxable_type_in_prim_decl : attr
4 changes: 3 additions & 1 deletion ppx/ast_derive/ast_derive_abstract.ml
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ let handleTdcl light (tdcl : Parsetree.type_declaration) :
Ast_external_mk.pval_prim_of_option_labels labels has_optional_field
in
let myMaker =
Val.mk ~loc { loc; txt = type_name } ~prim:myPrims makeType
Val.mk ~loc { loc; txt = type_name }
~attrs:[ Ast_attributes.unboxable_type_in_prim_decl ]
~prim:myPrims makeType
in
myMaker :: setter_accessor )
| Ptype_abstract | Ptype_variant _ | Ptype_open ->
Expand Down
24 changes: 4 additions & 20 deletions ppx/ast_external.ml
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,6 @@

open Ppxlib

(* We disable warning 61 in Melange externals since they're substantially
different from OCaml externals. This warning doesn't make sense for a JS
runtime *)
let unboxable_type_in_prim_decl : Parsetree.attribute =
let open Ast_helper in
{
attr_name = { txt = "ocaml.warning"; loc = Location.none };
attr_payload =
PStr
[
Str.eval
(Exp.constant
(Pconst_string
("-unboxable-type-in-prim-decl", Location.none, None)));
];
attr_loc = Location.none;
}

let handleExternalInSig (self : Ast_traverse.map)
(prim : Parsetree.value_description) (sigi : Parsetree.signature_item) :
Parsetree.signature_item =
Expand Down Expand Up @@ -79,7 +61,8 @@ let handleExternalInSig (self : Ast_traverse.map)
prim with
pval_type;
pval_prim = (if no_inline_cross_module then [] else pval_prim);
pval_attributes = unboxable_type_in_prim_decl :: pval_attributes;
pval_attributes =
Ast_attributes.unboxable_type_in_prim_decl :: pval_attributes;
};
}

Expand Down Expand Up @@ -120,7 +103,8 @@ let handleExternalInStru (self : Ast_traverse.map)
prim with
pval_type;
pval_prim;
pval_attributes = unboxable_type_in_prim_decl :: pval_attributes;
pval_attributes =
Ast_attributes.unboxable_type_in_prim_decl :: pval_attributes;
};
}
in
Expand Down

0 comments on commit 3b4c576

Please sign in to comment.