Skip to content

Commit 5e3ed85

Browse files
committed
finally clean up bs.inline handling
let f = 1 + 3 [@@bs.inline] will emit a warning
1 parent a860258 commit 5e3ed85

File tree

9 files changed

+34
-484
lines changed

9 files changed

+34
-484
lines changed

jscomp/main/js_main.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ let _ : unit =
538538
exit 2
539539
| x ->
540540
begin
541-
#if undefined BS_RELEASE_BUILD then
541+
#if false (* undefined BS_RELEASE_BUILD *) then
542542
Ext_obj.bt ();
543543
#end
544544
Location.report_exception ppf x;

jscomp/syntax/ast_attributes.ml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,17 +136,12 @@ let external_needs_to_be_encoded (attrs : t)=
136136

137137
let is_inline : attr -> bool =
138138
(fun
139-
(({txt;},_) as attr) ->
140-
let b = txt = "bs.inline" || txt = "inline" in
141-
(if b then
142-
Bs_ast_invariant.mark_used_bs_attribute attr);
143-
b
144-
) (* still needs to be marked, since we are going to drop it right now *)
139+
(({txt;},_)) ->
140+
txt = "bs.inline" || txt = "inline"
141+
)
145142

146-
let has_inline_in_stru (attrs : t) : bool =
147-
Ext_list.exists attrs is_inline
148143

149-
let has_inline_payload_in_sig (attrs : t) =
144+
let has_inline_payload (attrs : t) =
150145
Ext_list.find_first attrs is_inline
151146

152147

jscomp/syntax/ast_attributes.mli

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@ val process_bs :
5050
val external_needs_to_be_encoded :
5151
t -> bool
5252

53-
val has_inline_in_stru :
54-
t ->
55-
bool
5653

57-
val has_inline_payload_in_sig :
54+
val has_inline_payload :
5855
t ->
5956
attr option
6057

jscomp/syntax/ast_derive_abstract.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ let isAbstract (xs :Ast_payload.action list) =
5050
match txt with
5151
| "abstract" ->
5252
Location.raise_errorf ~loc
53-
"bs.deriving abstract does not work with any other deriving"
53+
"deriving abstract does not work with any other deriving"
5454
| _ -> ()
5555
) ;
5656
Not_abstract

jscomp/syntax/bs_builtin_ppx.ml

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ let () =
6060
Ast_derive_js_mapper.init ()
6161

6262

63-
63+
let succeed attr attrs =
64+
match attrs with
65+
| [ _ ] -> ()
66+
| _ ->
67+
Bs_ast_invariant.mark_used_bs_attribute attr;
68+
Bs_ast_invariant.warn_discarded_unused_attributes attrs
6469

6570
type mapper = Bs_ast_mapper.mapper
6671
let default_mapper = Bs_ast_mapper.default_mapper
@@ -243,14 +248,14 @@ let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) =
243248
Ast_external.handleExternalInSig self value_desc sigi
244249
else
245250
(match
246-
Ast_attributes.has_inline_payload_in_sig
251+
Ast_attributes.has_inline_payload
247252
pval_attributes with
248-
| Some (_,PStr [{pstr_desc = Pstr_eval ({pexp_desc },_)}]) ->
253+
| Some ((_,PStr [{pstr_desc = Pstr_eval ({pexp_desc },_)}]) as attr) ->
249254
begin match pexp_desc with
250255
| Pexp_constant (
251256
Pconst_string
252257
(s,dec)) ->
253-
Bs_ast_invariant.warn_discarded_unused_attributes pval_attributes;
258+
succeed attr pval_attributes;
254259
{ sigi with
255260
psig_desc = Psig_value
256261
{
@@ -260,8 +265,8 @@ let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) =
260265
}}
261266
| Pexp_constant(
262267
Pconst_integer (s,None)
263-
) ->
264-
Bs_ast_invariant.warn_discarded_unused_attributes pval_attributes;
268+
) ->
269+
succeed attr pval_attributes;
265270
let s = Int32.of_string s in
266271
{ sigi with
267272
psig_desc = Psig_value
@@ -273,22 +278,22 @@ let signature_item_mapper (self : mapper) (sigi : Parsetree.signature_item) =
273278
| Pexp_constant(Pconst_integer (s, Some 'L'))
274279
->
275280
let s = Int64.of_string s in
276-
Bs_ast_invariant.warn_discarded_unused_attributes pval_attributes;
281+
succeed attr pval_attributes;
277282
{sigi with psig_desc = Psig_value {
278283
value_desc with
279284
pval_prim = External_ffi_types.inline_int64_primitive s;
280285
pval_attributes = [];
281286
} }
282287
| Pexp_constant (Pconst_float(s,None)) ->
283-
Bs_ast_invariant.warn_discarded_unused_attributes pval_attributes;
288+
succeed attr pval_attributes;
284289
{sigi with psig_desc = Psig_value {
285290
value_desc with
286291
pval_prim = External_ffi_types.inline_float_primitive s;
287292
pval_attributes = [];
288293
} }
289294
| Pexp_construct ({txt = Lident ("true" | "false" as txt)}, None)
290295
->
291-
Bs_ast_invariant.warn_discarded_unused_attributes pval_attributes;
296+
succeed attr pval_attributes;
292297
{ sigi with
293298
psig_desc = Psig_value
294299
{
@@ -326,54 +331,54 @@ let structure_item_mapper (self : mapper) (str : Parsetree.structure_item) =
326331
->
327332
let pvb_expr = self.expr self pvb_expr in
328333
let pvb_attributes = self.attributes self pvb_attributes in
329-
let has_inline_property = Ast_attributes.has_inline_in_stru pvb_attributes in
334+
let has_inline_property = Ast_attributes.has_inline_payload pvb_attributes in
330335
begin match has_inline_property, pvb_expr.pexp_desc with
331-
| true, Pexp_constant(
336+
| Some attr, Pexp_constant(
332337
Pconst_string
333338
(s,dec))
334339
->
335-
Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
340+
succeed attr pvb_attributes;
336341
{str with pstr_desc = Pstr_primitive {
337342
pval_name = pval_name ;
338343
pval_type = Ast_literal.type_string ();
339344
pval_loc = pvb_loc;
340345
pval_attributes = [];
341346
pval_prim = External_ffi_types.inline_string_primitive s dec
342347
} }
343-
| true, Pexp_constant(Pconst_integer (s,None))
348+
| Some attr, Pexp_constant(Pconst_integer (s,None))
344349
->
345350
let s = Int32.of_string s in
346-
Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
351+
succeed attr pvb_attributes;
347352
{str with pstr_desc = Pstr_primitive {
348353
pval_name = pval_name ;
349354
pval_type = Ast_literal.type_int ();
350355
pval_loc = pvb_loc;
351356
pval_attributes = [];
352357
pval_prim = External_ffi_types.inline_int_primitive s
353358
} }
354-
| true, Pexp_constant(Pconst_integer (s, Some 'L'))
359+
| Some attr, Pexp_constant(Pconst_integer (s, Some 'L'))
355360
->
356361
let s = Int64.of_string s in
357-
Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
362+
succeed attr pvb_attributes;
358363
{str with pstr_desc = Pstr_primitive {
359364
pval_name = pval_name ;
360365
pval_type = Ast_literal.type_int64;
361366
pval_loc = pvb_loc;
362367
pval_attributes = [];
363368
pval_prim = External_ffi_types.inline_int64_primitive s
364369
} }
365-
| true, Pexp_constant(Pconst_float (s, None))
370+
| Some attr, Pexp_constant(Pconst_float (s, None))
366371
->
367-
Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
372+
succeed attr pvb_attributes;
368373
{str with pstr_desc = Pstr_primitive {
369374
pval_name = pval_name ;
370375
pval_type = Ast_literal.type_float;
371376
pval_loc = pvb_loc;
372377
pval_attributes = [];
373378
pval_prim = External_ffi_types.inline_float_primitive s
374379
} }
375-
| true, Pexp_construct ({txt = Lident ("true" | "false" as txt) },None) ->
376-
Bs_ast_invariant.warn_discarded_unused_attributes pvb_attributes;
380+
| Some attr, Pexp_construct ({txt = Lident ("true" | "false" as txt) },None) ->
381+
succeed attr pvb_attributes;
377382
{str with pstr_desc = Pstr_primitive {
378383
pval_name = pval_name ;
379384
pval_type = Ast_literal.type_bool ();

jscomp/test/build.ninja

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,8 +650,7 @@ build test/test_js_ffi.cmi test/test_js_ffi.cmj : cc test/test_js_ffi.ml | $stdl
650650
build test/test_let.cmi test/test_let.cmj : cc test/test_let.ml | $stdlib
651651
build test/test_list.cmi test/test_list.cmj : cc test/test_list.ml | $stdlib
652652
build test/test_literal.cmi test/test_literal.cmj : cc test/test_literal.ml | $stdlib
653-
build test/test_literals.cmj : cc_cmi test/test_literals.ml | test/test_literals.cmi $stdlib
654-
build test/test_literals.cmi : cc test/test_literals.mli | $stdlib
653+
build test/test_literals.cmi test/test_literals.cmj : cc test/test_literals.ml | $stdlib
655654
build test/test_match_exception.cmi test/test_match_exception.cmj : cc test/test_match_exception.ml | $stdlib
656655
build test/test_mutliple.cmi test/test_mutliple.cmj : cc test/test_mutliple.ml | $stdlib
657656
build test/test_nat64.cmi test/test_nat64.cmj : cc test/test_nat64.ml | $stdlib

0 commit comments

Comments
 (0)