From f3a2811623da3ab77aa9906fad50a3c11096004d Mon Sep 17 00:00:00 2001 From: ELLIOTTCABLE Date: Fri, 15 Jan 2021 06:28:49 -0600 Subject: [PATCH] (- re comp err) Relax uninterpretable attributes from error to warn At the moment, @@bs.deriving (and other BuckleScript-interpreted attributes) cause a fatal error if they encounter payloads they don't understand in the AST. This is problematic now that BuckleScript's @@deriving *and* OCaml-native @@deriving (from ppx_deriving) attempt to interpret the same key: ```ocaml type foo = { a: int; b: int; } [@@deriving jsConverter] type bar = { x: int; y: int; } [@@deriving yojson { strict = true }] ``` For compatibility's sake, I've reduced this error to a compile-time *warning* (w+104, the same quieting-category as used in the other 'idk wtf to do with this' deriving-case). Ideally, I'd like to see this more fully understand OCaml-native ppx_deriving payloads - not to interpret them, but to provide better error-messages (i.e. differentiate between "uninterpreted ppx_deriving payload" and "genuinely typo'd-or-incorrect payload"), but for now, at least this fix unblocks existing hybrid BS/native projects, and will allow me to fix the bs-deriving compatibility project! --- jscomp/syntax/ast_derive_util.mli | 2 +- jscomp/syntax/ast_payload.ml | 11 ++++++++--- jscomp/syntax/ast_payload.mli | 7 +++++++ lib/4.06.1/unstable/js_compiler.ml | 19 ++++++++++++++++--- lib/4.06.1/unstable/js_refmt_compiler.ml | 19 ++++++++++++++++--- lib/4.06.1/whole_compiler.ml | 19 ++++++++++++++++--- 6 files changed, 64 insertions(+), 13 deletions(-) diff --git a/jscomp/syntax/ast_derive_util.mli b/jscomp/syntax/ast_derive_util.mli index 99eb9f59d7..601faabc6d 100644 --- a/jscomp/syntax/ast_derive_util.mli +++ b/jscomp/syntax/ast_derive_util.mli @@ -49,4 +49,4 @@ val notApplicable: string -> unit -val invalid_config : Parsetree.expression -> 'a \ No newline at end of file +val invalid_config : Parsetree.expression -> 'a diff --git a/jscomp/syntax/ast_payload.ml b/jscomp/syntax/ast_payload.ml index 31c45c54d8..79a30bedd9 100644 --- a/jscomp/syntax/ast_payload.ml +++ b/jscomp/syntax/ast_payload.ml @@ -130,6 +130,11 @@ type action = *) +let unrecognizedConfigRecord loc text = + Location.prerr_warning + loc + (Warnings.Bs_derive_warning text) + let ident_or_record_as_config loc @@ -156,11 +161,11 @@ let ident_or_record_as_config -> ({Asttypes.txt = name ; loc}, Some y) | _ -> - Location.raise_errorf ~loc "Qualified label is not allood" + Location.raise_errorf ~loc "Qualified label is not allowed" ) | Some _ -> - Location.raise_errorf ~loc "with is not supported" + unrecognizedConfigRecord loc "`with` is not supported, discarding"; [] end | PStr [ {pstr_desc = @@ -174,7 +179,7 @@ let ident_or_record_as_config ] -> [ {Asttypes.txt ; loc = lloc}, None] | PStr [] -> [] | _ -> - Location.raise_errorf ~loc "this is not a valid record config" + unrecognizedConfigRecord loc "invalid attribute config-record, ignoring"; [] diff --git a/jscomp/syntax/ast_payload.mli b/jscomp/syntax/ast_payload.mli index ccead056c6..b61fc25264 100644 --- a/jscomp/syntax/ast_payload.mli +++ b/jscomp/syntax/ast_payload.mli @@ -83,3 +83,10 @@ val empty : t val table_dispatch : (Parsetree.expression option -> 'a) Map_string.t -> action -> 'a + +(** Report to the user, as a warning, that the bs-attribute parser is bailing out. (This is to allow + external ppx, like ppx_deriving, to pick up where the builtin ppx leave off.) *) +val unrecognizedConfigRecord: + Location.t -> + string -> + unit diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index 8aa760af74..fdf287c814 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -398661,6 +398661,13 @@ val empty : t val table_dispatch : (Parsetree.expression option -> 'a) Map_string.t -> action -> 'a +(** Report to the user, as a warning, that the bs-attribute parser is bailing out. (This is to allow + external ppx, like ppx_deriving, to pick up where the builtin ppx leave off.) *) +val unrecognizedConfigRecord: + Location.t -> + string -> + unit + end = struct #1 "ast_payload.ml" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. @@ -398795,6 +398802,11 @@ type action = *) +let unrecognizedConfigRecord loc text = + Location.prerr_warning + loc + (Warnings.Bs_derive_warning text) + let ident_or_record_as_config loc @@ -398821,11 +398833,11 @@ let ident_or_record_as_config -> ({Asttypes.txt = name ; loc}, Some y) | _ -> - Location.raise_errorf ~loc "Qualified label is not allood" + Location.raise_errorf ~loc "Qualified label is not allowed" ) | Some _ -> - Location.raise_errorf ~loc "with is not supported" + unrecognizedConfigRecord loc "`with` is not supported, discarding"; [] end | PStr [ {pstr_desc = @@ -398839,7 +398851,7 @@ let ident_or_record_as_config ] -> [ {Asttypes.txt ; loc = lloc}, None] | PStr [] -> [] | _ -> - Location.raise_errorf ~loc "this is not a valid record config" + unrecognizedConfigRecord loc "invalid attribute config-record, ignoring"; [] @@ -402852,6 +402864,7 @@ val notApplicable: unit val invalid_config : Parsetree.expression -> 'a + end = struct #1 "ast_derive_util.ml" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. diff --git a/lib/4.06.1/unstable/js_refmt_compiler.ml b/lib/4.06.1/unstable/js_refmt_compiler.ml index a032d294a9..285df9675c 100644 --- a/lib/4.06.1/unstable/js_refmt_compiler.ml +++ b/lib/4.06.1/unstable/js_refmt_compiler.ml @@ -398661,6 +398661,13 @@ val empty : t val table_dispatch : (Parsetree.expression option -> 'a) Map_string.t -> action -> 'a +(** Report to the user, as a warning, that the bs-attribute parser is bailing out. (This is to allow + external ppx, like ppx_deriving, to pick up where the builtin ppx leave off.) *) +val unrecognizedConfigRecord: + Location.t -> + string -> + unit + end = struct #1 "ast_payload.ml" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. @@ -398795,6 +398802,11 @@ type action = *) +let unrecognizedConfigRecord loc text = + Location.prerr_warning + loc + (Warnings.Bs_derive_warning text) + let ident_or_record_as_config loc @@ -398821,11 +398833,11 @@ let ident_or_record_as_config -> ({Asttypes.txt = name ; loc}, Some y) | _ -> - Location.raise_errorf ~loc "Qualified label is not allood" + Location.raise_errorf ~loc "Qualified label is not allowed" ) | Some _ -> - Location.raise_errorf ~loc "with is not supported" + unrecognizedConfigRecord loc "`with` is not supported, discarding"; [] end | PStr [ {pstr_desc = @@ -398839,7 +398851,7 @@ let ident_or_record_as_config ] -> [ {Asttypes.txt ; loc = lloc}, None] | PStr [] -> [] | _ -> - Location.raise_errorf ~loc "this is not a valid record config" + unrecognizedConfigRecord loc "invalid attribute config-record, ignoring"; [] @@ -402852,6 +402864,7 @@ val notApplicable: unit val invalid_config : Parsetree.expression -> 'a + end = struct #1 "ast_derive_util.ml" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index 164cac7245..8cded30283 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -288146,6 +288146,13 @@ val empty : t val table_dispatch : (Parsetree.expression option -> 'a) Map_string.t -> action -> 'a +(** Report to the user, as a warning, that the bs-attribute parser is bailing out. (This is to allow + external ppx, like ppx_deriving, to pick up where the builtin ppx leave off.) *) +val unrecognizedConfigRecord: + Location.t -> + string -> + unit + end = struct #1 "ast_payload.ml" (* Copyright (C) 2015-2016 Bloomberg Finance L.P. @@ -288280,6 +288287,11 @@ type action = *) +let unrecognizedConfigRecord loc text = + Location.prerr_warning + loc + (Warnings.Bs_derive_warning text) + let ident_or_record_as_config loc @@ -288306,11 +288318,11 @@ let ident_or_record_as_config -> ({Asttypes.txt = name ; loc}, Some y) | _ -> - Location.raise_errorf ~loc "Qualified label is not allood" + Location.raise_errorf ~loc "Qualified label is not allowed" ) | Some _ -> - Location.raise_errorf ~loc "with is not supported" + unrecognizedConfigRecord loc "`with` is not supported, discarding"; [] end | PStr [ {pstr_desc = @@ -288324,7 +288336,7 @@ let ident_or_record_as_config ] -> [ {Asttypes.txt ; loc = lloc}, None] | PStr [] -> [] | _ -> - Location.raise_errorf ~loc "this is not a valid record config" + unrecognizedConfigRecord loc "invalid attribute config-record, ignoring"; [] @@ -405681,6 +405693,7 @@ val notApplicable: unit val invalid_config : Parsetree.expression -> 'a + end = struct #1 "ast_derive_util.ml" (* Copyright (C) 2015-2016 Bloomberg Finance L.P.