Skip to content

Commit f3a2811

Browse files
committed
(- 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!
1 parent 40bfbc0 commit f3a2811

File tree

6 files changed

+64
-13
lines changed

6 files changed

+64
-13
lines changed

jscomp/syntax/ast_derive_util.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ val notApplicable:
4949
string ->
5050
unit
5151

52-
val invalid_config : Parsetree.expression -> 'a
52+
val invalid_config : Parsetree.expression -> 'a

jscomp/syntax/ast_payload.ml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,11 @@ type action =
130130
*)
131131

132132

133+
let unrecognizedConfigRecord loc text =
134+
Location.prerr_warning
135+
loc
136+
(Warnings.Bs_derive_warning text)
137+
133138

134139
let ident_or_record_as_config
135140
loc
@@ -156,11 +161,11 @@ let ident_or_record_as_config
156161
->
157162
({Asttypes.txt = name ; loc}, Some y)
158163
| _ ->
159-
Location.raise_errorf ~loc "Qualified label is not allood"
164+
Location.raise_errorf ~loc "Qualified label is not allowed"
160165
)
161166

162167
| Some _ ->
163-
Location.raise_errorf ~loc "with is not supported"
168+
unrecognizedConfigRecord loc "`with` is not supported, discarding"; []
164169
end
165170
| PStr [
166171
{pstr_desc =
@@ -174,7 +179,7 @@ let ident_or_record_as_config
174179
] -> [ {Asttypes.txt ; loc = lloc}, None]
175180
| PStr [] -> []
176181
| _ ->
177-
Location.raise_errorf ~loc "this is not a valid record config"
182+
unrecognizedConfigRecord loc "invalid attribute config-record, ignoring"; []
178183

179184

180185

jscomp/syntax/ast_payload.mli

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,10 @@ val empty : t
8383

8484
val table_dispatch :
8585
(Parsetree.expression option -> 'a) Map_string.t -> action -> 'a
86+
87+
(** Report to the user, as a warning, that the bs-attribute parser is bailing out. (This is to allow
88+
external ppx, like ppx_deriving, to pick up where the builtin ppx leave off.) *)
89+
val unrecognizedConfigRecord:
90+
Location.t ->
91+
string ->
92+
unit

lib/4.06.1/unstable/js_compiler.ml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398661,6 +398661,13 @@ val empty : t
398661398661
val table_dispatch :
398662398662
(Parsetree.expression option -> 'a) Map_string.t -> action -> 'a
398663398663

398664+
(** Report to the user, as a warning, that the bs-attribute parser is bailing out. (This is to allow
398665+
external ppx, like ppx_deriving, to pick up where the builtin ppx leave off.) *)
398666+
val unrecognizedConfigRecord:
398667+
Location.t ->
398668+
string ->
398669+
unit
398670+
398664398671
end = struct
398665398672
#1 "ast_payload.ml"
398666398673
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -398795,6 +398802,11 @@ type action =
398795398802
*)
398796398803

398797398804

398805+
let unrecognizedConfigRecord loc text =
398806+
Location.prerr_warning
398807+
loc
398808+
(Warnings.Bs_derive_warning text)
398809+
398798398810

398799398811
let ident_or_record_as_config
398800398812
loc
@@ -398821,11 +398833,11 @@ let ident_or_record_as_config
398821398833
->
398822398834
({Asttypes.txt = name ; loc}, Some y)
398823398835
| _ ->
398824-
Location.raise_errorf ~loc "Qualified label is not allood"
398836+
Location.raise_errorf ~loc "Qualified label is not allowed"
398825398837
)
398826398838

398827398839
| Some _ ->
398828-
Location.raise_errorf ~loc "with is not supported"
398840+
unrecognizedConfigRecord loc "`with` is not supported, discarding"; []
398829398841
end
398830398842
| PStr [
398831398843
{pstr_desc =
@@ -398839,7 +398851,7 @@ let ident_or_record_as_config
398839398851
] -> [ {Asttypes.txt ; loc = lloc}, None]
398840398852
| PStr [] -> []
398841398853
| _ ->
398842-
Location.raise_errorf ~loc "this is not a valid record config"
398854+
unrecognizedConfigRecord loc "invalid attribute config-record, ignoring"; []
398843398855

398844398856

398845398857

@@ -402852,6 +402864,7 @@ val notApplicable:
402852402864
unit
402853402865

402854402866
val invalid_config : Parsetree.expression -> 'a
402867+
402855402868
end = struct
402856402869
#1 "ast_derive_util.ml"
402857402870
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.

lib/4.06.1/unstable/js_refmt_compiler.ml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398661,6 +398661,13 @@ val empty : t
398661398661
val table_dispatch :
398662398662
(Parsetree.expression option -> 'a) Map_string.t -> action -> 'a
398663398663

398664+
(** Report to the user, as a warning, that the bs-attribute parser is bailing out. (This is to allow
398665+
external ppx, like ppx_deriving, to pick up where the builtin ppx leave off.) *)
398666+
val unrecognizedConfigRecord:
398667+
Location.t ->
398668+
string ->
398669+
unit
398670+
398664398671
end = struct
398665398672
#1 "ast_payload.ml"
398666398673
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -398795,6 +398802,11 @@ type action =
398795398802
*)
398796398803

398797398804

398805+
let unrecognizedConfigRecord loc text =
398806+
Location.prerr_warning
398807+
loc
398808+
(Warnings.Bs_derive_warning text)
398809+
398798398810

398799398811
let ident_or_record_as_config
398800398812
loc
@@ -398821,11 +398833,11 @@ let ident_or_record_as_config
398821398833
->
398822398834
({Asttypes.txt = name ; loc}, Some y)
398823398835
| _ ->
398824-
Location.raise_errorf ~loc "Qualified label is not allood"
398836+
Location.raise_errorf ~loc "Qualified label is not allowed"
398825398837
)
398826398838

398827398839
| Some _ ->
398828-
Location.raise_errorf ~loc "with is not supported"
398840+
unrecognizedConfigRecord loc "`with` is not supported, discarding"; []
398829398841
end
398830398842
| PStr [
398831398843
{pstr_desc =
@@ -398839,7 +398851,7 @@ let ident_or_record_as_config
398839398851
] -> [ {Asttypes.txt ; loc = lloc}, None]
398840398852
| PStr [] -> []
398841398853
| _ ->
398842-
Location.raise_errorf ~loc "this is not a valid record config"
398854+
unrecognizedConfigRecord loc "invalid attribute config-record, ignoring"; []
398843398855

398844398856

398845398857

@@ -402852,6 +402864,7 @@ val notApplicable:
402852402864
unit
402853402865

402854402866
val invalid_config : Parsetree.expression -> 'a
402867+
402855402868
end = struct
402856402869
#1 "ast_derive_util.ml"
402857402870
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.

lib/4.06.1/whole_compiler.ml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288146,6 +288146,13 @@ val empty : t
288146288146
val table_dispatch :
288147288147
(Parsetree.expression option -> 'a) Map_string.t -> action -> 'a
288148288148

288149+
(** Report to the user, as a warning, that the bs-attribute parser is bailing out. (This is to allow
288150+
external ppx, like ppx_deriving, to pick up where the builtin ppx leave off.) *)
288151+
val unrecognizedConfigRecord:
288152+
Location.t ->
288153+
string ->
288154+
unit
288155+
288149288156
end = struct
288150288157
#1 "ast_payload.ml"
288151288158
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.
@@ -288280,6 +288287,11 @@ type action =
288280288287
*)
288281288288

288282288289

288290+
let unrecognizedConfigRecord loc text =
288291+
Location.prerr_warning
288292+
loc
288293+
(Warnings.Bs_derive_warning text)
288294+
288283288295

288284288296
let ident_or_record_as_config
288285288297
loc
@@ -288306,11 +288318,11 @@ let ident_or_record_as_config
288306288318
->
288307288319
({Asttypes.txt = name ; loc}, Some y)
288308288320
| _ ->
288309-
Location.raise_errorf ~loc "Qualified label is not allood"
288321+
Location.raise_errorf ~loc "Qualified label is not allowed"
288310288322
)
288311288323

288312288324
| Some _ ->
288313-
Location.raise_errorf ~loc "with is not supported"
288325+
unrecognizedConfigRecord loc "`with` is not supported, discarding"; []
288314288326
end
288315288327
| PStr [
288316288328
{pstr_desc =
@@ -288324,7 +288336,7 @@ let ident_or_record_as_config
288324288336
] -> [ {Asttypes.txt ; loc = lloc}, None]
288325288337
| PStr [] -> []
288326288338
| _ ->
288327-
Location.raise_errorf ~loc "this is not a valid record config"
288339+
unrecognizedConfigRecord loc "invalid attribute config-record, ignoring"; []
288328288340

288329288341

288330288342

@@ -405681,6 +405693,7 @@ val notApplicable:
405681405693
unit
405682405694

405683405695
val invalid_config : Parsetree.expression -> 'a
405696+
405684405697
end = struct
405685405698
#1 "ast_derive_util.ml"
405686405699
(* Copyright (C) 2015-2016 Bloomberg Finance L.P.

0 commit comments

Comments
 (0)