Skip to content

Commit 97067ca

Browse files
cknittclaude
andauthored
Remove the call-site @inlined attribute (#8734)
* Remove the call-site @inlined attribute @inlined was translated into Lapply's ap_inlined, but no pass in compiler/core ever read it: the only use in lam_pass_remove_alias was commented out. So (@inlined f)(x) was accepted and ignored, (@inlined(never) f)(x) still inlined, and the natural ReScript placement @inlined f(x) already reported warning 53. Delete the attribute's translation and the ap_inlined field. Any remaining @inlined now reaches check_attribute and is reported as a misplaced attribute (warning 53) instead of being silently ignored. See #8733. Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Add CHANGELOG link for #8734 Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Keep the @inlined warning fixture formattable The formatter drops attributes on functor applications, so @inlined F({}) cannot appear in a formatted fixture. Cover the two expression placements only. Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Check attributes on primitive callees A fully applied primitive call is translated without passing its callee through transl_exp, so check_attribute never saw the callee's attributes and `(@inlined id)(1)` with an external `id` got no warning. Check them on that path too. Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Remove a stale commented-out inlining check Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Honor @warning on primitive callees when checking attributes The attribute check added for fully applied primitives ran outside the callee's warning scope, so `(@warning("-53") @inlined id)(1)` still reported warning 53. Run it in the same scope transl_exp uses. Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Translate module expressions in their warning scope With @inlined no longer removed from a functor application's callee, it reaches check_attribute_on_module, which ran outside any warning scope: `(@warning("-53") @inlined F)(X)` still reported warning 53. Translate a module expression inside the warning scope of its attributes, like transl_exp does for expressions. Signed-off-by: Christoph Knittel <christoph@knittel.cc> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent d7ffff5 commit 97067ca

13 files changed

Lines changed: 77 additions & 79 deletions

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
#### :boom: Breaking Change
1616

17+
- Remove the call-site `@inlined` attribute, which was parsed but never affected code generation. It is now reported as a misplaced attribute (warning 53). https://github.com/rescript-lang/rescript/pull/8734
1718
- Remove `@deriving(abstract)` and `@deriving(jsConverter)`. Use record types (with optional fields, mutable fields and `@as` renaming) and polymorphic variants directly instead. https://github.com/rescript-lang/rescript/pull/8729
1819

1920
#### :eyeglasses: Spec Compliance

‎compiler/core/lam_pass_remove_alias.ml‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,7 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lambda.t) : Lambda.t =
189189
(* Ext_log.dwarn __LOC__ "beta .. %s/%d" v.name v.stamp ; *)
190190
simpl
191191
(Lam_beta_reduce.propagate_beta_reduce meta params body ap_args)
192-
else if
193-
(* Lam_analysis.size body < Lam_analysis.small_inline_size *)
194-
(* ap_inlined = Always_inline || *)
195-
Lam_analysis.ok_to_inline_fun_when_app m ap_args
196-
then
192+
else if Lam_analysis.ok_to_inline_fun_when_app m ap_args then
197193
let param_map =
198194
Lam_closure.is_closed_with_map meta.export_idents params body
199195
in

‎compiler/ml/lambda.ml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ and lfunction = {
362362

363363
and prim_info = {primitive: primitive; args: t list; loc: Location.t}
364364

365-
and ap_info = {ap_loc: Location.t; ap_inlined: inline_attribute}
365+
and ap_info = {ap_loc: Location.t}
366366

367367
and lambda_apply = {
368368
ap_func: t;

‎compiler/ml/lambda.mli‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,7 @@ and lfunction = {
375375

376376
and prim_info = private {primitive: primitive; args: t list; loc: Location.t}
377377

378-
and ap_info = {
379-
ap_loc: Location.t;
380-
ap_inlined: inline_attribute; (* specified with the [@inlined] attribute *)
381-
}
378+
and ap_info = {ap_loc: Location.t}
382379

383380
and lambda_apply = private {
384381
ap_func: t;

‎compiler/ml/lambda_traverse.ml‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,7 @@ let make_key e =
124124
| Lglobal_module _ | Lconst _ -> e
125125
| Lapply ap ->
126126
apply ~ap_transformed_jsx:ap.ap_transformed_jsx (tr_rec env ap.ap_func)
127-
(tr_recs env ap.ap_args)
128-
{ap.ap_info with ap_loc = Location.none}
127+
(tr_recs env ap.ap_args) {ap_loc = Location.none}
129128
| Llet (Alias, x, ex, e) ->
130129
(* Ignore aliases -> substitute *)
131130
let ex = tr_rec env ex in

‎compiler/ml/printlambda.ml‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -231,19 +231,13 @@ let function_attribute ppf {inline; is_a_functor; return_unit} =
231231
| Always_inline -> fprintf ppf "always_inline@ "
232232
| Never_inline -> fprintf ppf "never_inline@ "
233233

234-
let apply_inlined_attribute ppf = function
235-
| Default_inline -> ()
236-
| Always_inline -> fprintf ppf " always_inline"
237-
| Never_inline -> fprintf ppf " never_inline"
238-
239234
let rec lam ppf = function
240235
| Lvar id -> Ident.print ppf id
241236
| Lglobal_module id -> fprintf ppf "global %a" Ident.print id
242237
| Lconst cst -> struct_const ppf cst
243238
| Lapply ap ->
244239
let lams ppf largs = List.iter (fun l -> fprintf ppf "@ %a" lam l) largs in
245-
fprintf ppf "@[<2>(apply@ %a%a%a)@]" lam ap.ap_func lams ap.ap_args
246-
apply_inlined_attribute ap.ap_info.ap_inlined
240+
fprintf ppf "@[<2>(apply@ %a%a)@]" lam ap.ap_func lams ap.ap_args
247241
| Lfunction {params; body; attr} ->
248242
let pr_params ppf params =
249243
List.iter (fun param -> fprintf ppf "@ %a" Ident.print param) params

‎compiler/ml/translattribute.ml‎

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ let is_inline_attribute (attr : t) =
2020
| {txt = "inline"}, _ -> true
2121
| _ -> false
2222

23-
let is_inlined_attribute (attr : t) =
24-
match attr with
25-
| {txt = "inlined"}, _ -> true
26-
| _ -> false
27-
2823
let find_attribute p (attributes : t list) =
2924
let inline_attribute, other_attributes = List.partition p attributes in
3025
let attr =
@@ -57,7 +52,7 @@ let parse_inline_attribute (attr : t option) : Lambda.inline_attribute =
5752
| None -> Default_inline
5853
| Some ({txt; loc}, payload) -> (
5954
let open Parsetree in
60-
(* the 'inline' and 'inlined' attributes can be used as
55+
(* the 'inline' attribute can be used as
6156
[@inline], [@inline never] or [@inline always].
6257
[@inline] is equivalent to [@inline always] *)
6358
let warning txt =
@@ -98,33 +93,14 @@ let add_inline_attribute (expr : Lambda.t) loc attributes =
9893
Location.prerr_warning loc (Warnings.Misplaced_attribute "inline");
9994
expr
10095

101-
(* Get the [@inlined] attribute payload (or default if not present).
102-
It also returns the expression without this attribute. This is
103-
used to ensure that this attribute is not misplaced: If it
104-
appears on any expression, it is an error, otherwise it would
105-
have been removed by this function *)
106-
let get_and_remove_inlined_attribute (e : Typedtree.expression) =
107-
let attr, exp_attributes =
108-
find_attribute is_inlined_attribute e.exp_attributes
109-
in
110-
let inlined = parse_inline_attribute attr in
111-
(inlined, {e with exp_attributes})
112-
113-
let get_and_remove_inlined_attribute_on_module (e : Typedtree.module_expr) =
114-
let attr, mod_attributes =
115-
find_attribute is_inlined_attribute e.mod_attributes
116-
in
117-
let inlined = parse_inline_attribute attr in
118-
(inlined, {e with mod_attributes})
119-
12096
let check_attribute (e : Typedtree.expression) (({txt; loc}, _) : t) =
12197
match txt with
12298
| "inline" -> (
12399
match e.exp_desc with
124100
| Texp_function _ -> ()
125101
| _ -> Location.prerr_warning loc (Warnings.Misplaced_attribute txt))
126102
| "inlined" ->
127-
(* Removed by the Texp_apply cases *)
103+
(* Call-site inlining hints are not supported *)
128104
Location.prerr_warning loc (Warnings.Misplaced_attribute txt)
129105
| _ -> ()
130106

@@ -136,6 +112,6 @@ let check_attribute_on_module (e : Typedtree.module_expr) (({txt; loc}, _) : t)
136112
| Tmod_functor _ -> ()
137113
| _ -> Location.prerr_warning loc (Warnings.Misplaced_attribute txt))
138114
| "inlined" ->
139-
(* Removed by the Texp_apply cases *)
115+
(* Call-site inlining hints are not supported *)
140116
Location.prerr_warning loc (Warnings.Misplaced_attribute txt)
141117
| _ -> ()

‎compiler/ml/translattribute.mli‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,3 @@ val add_inline_attribute :
2424
val get_inline_attribute : Parsetree.attributes -> Lambda.inline_attribute
2525

2626
val get_empty_attribute : string -> Parsetree.attributes -> Location.t option
27-
28-
val get_and_remove_inlined_attribute :
29-
Typedtree.expression -> Lambda.inline_attribute * Typedtree.expression
30-
31-
val get_and_remove_inlined_attribute_on_module :
32-
Typedtree.module_expr -> Lambda.inline_attribute * Typedtree.module_expr

‎compiler/ml/translcore.ml‎

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -909,8 +909,7 @@ let wrap_exn loc arg =
909909
~args:
910910
[global_module (Ident.create_persistent Primitive_modules.exceptions)]
911911
loc)
912-
[arg]
913-
{ap_loc = loc; ap_inlined = Default_inline}
912+
[arg] {ap_loc = loc}
914913
let exception_id_destructed (l : Lambda.t) (fv : Ident.t) : bool =
915914
let rec hit_opt = function
916915
| None -> false
@@ -1044,14 +1043,14 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.t =
10441043
}
10451044
when List.length oargs >= p.prim_arity
10461045
&& List.for_all (fun (_, arg) -> arg <> None) oargs -> (
1046+
(* [funct] is not translated with [transl_exp], so check its attributes
1047+
here, in the warning scope [transl_exp] would use *)
1048+
Builtin_attributes.warning_scope ~ppwarning:false funct.exp_attributes
1049+
(fun () ->
1050+
List.iter (Translattribute.check_attribute funct) funct.exp_attributes);
10471051
let args, args' = cut p.prim_arity oargs in
10481052
let wrap f =
1049-
if args' = [] then f
1050-
else
1051-
let inlined, _ =
1052-
Translattribute.get_and_remove_inlined_attribute funct
1053-
in
1054-
transl_apply ~inlined ~transformed_jsx f args' e.exp_loc
1053+
if args' = [] then f else transl_apply ~transformed_jsx f args' e.exp_loc
10551054
in
10561055
let args =
10571056
List.map
@@ -1104,9 +1103,6 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.t =
11041103
warn_polymorphic_comparison e.exp_loc builtin argl;
11051104
wrap (mk_builtin builtin argl e.exp_loc))))
11061105
| Texp_apply {funct; args = oargs; partial; transformed_jsx} ->
1107-
let inlined, funct =
1108-
Translattribute.get_and_remove_inlined_attribute funct
1109-
in
11101106
let uncurried_partial_application =
11111107
(* In case of partial application foo(args, ...) when some args are missing,
11121108
get the arity *)
@@ -1119,7 +1115,7 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.t =
11191115
| None -> None
11201116
else None
11211117
in
1122-
transl_apply ~inlined ~uncurried_partial_application ~transformed_jsx
1118+
transl_apply ~uncurried_partial_application ~transformed_jsx
11231119
(transl_exp funct) oargs e.exp_loc
11241120
| Texp_match (arg, pat_expr_list, exn_pat_expr_list, partial) ->
11251121
transl_match e arg pat_expr_list exn_pat_expr_list partial
@@ -1315,12 +1311,10 @@ and transl_case {c_lhs; c_guard; c_rhs} = (c_lhs, transl_guard c_guard c_rhs)
13151311

13161312
and transl_cases cases = List.map transl_case cases
13171313

1318-
and transl_apply ?(inlined = Default_inline)
1319-
?(uncurried_partial_application = None) ?(transformed_jsx = false) lam sargs
1320-
loc =
1314+
and transl_apply ?(uncurried_partial_application = None)
1315+
?(transformed_jsx = false) lam sargs loc =
13211316
let lapply ap_func ap_args =
1322-
apply ~ap_transformed_jsx:transformed_jsx ap_func ap_args
1323-
{ap_loc = loc; ap_inlined = inlined}
1317+
apply ~ap_transformed_jsx:transformed_jsx ap_func ap_args {ap_loc = loc}
13241318
in
13251319
let rec build_apply lam args = function
13261320
| (None, optional) :: l ->
@@ -1371,8 +1365,7 @@ and transl_apply ?(inlined = Default_inline)
13711365
let extra_args = Ext_list.map extra_ids (fun id -> var id) in
13721366
let ap_args = args @ extra_args in
13731367
let l0 =
1374-
apply ~ap_transformed_jsx:transformed_jsx lam ap_args
1375-
{ap_loc = loc; ap_inlined = inlined}
1368+
apply ~ap_transformed_jsx:transformed_jsx lam ap_args {ap_loc = loc}
13761369
in
13771370
function_ ~loc ~attr:default_function_attribute
13781371
~params:(List.rev_append !none_ids extra_ids)

‎compiler/ml/translmod.ml‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ and apply_coercion_result loc strict funct param arg cc_res =
126126
~body:
127127
(apply_coercion loc Strict cc_res
128128
(Lambda.apply ~ap_transformed_jsx:false (Lambda.var id) [arg]
129-
{ap_loc = loc; ap_inlined = Default_inline})))
129+
{ap_loc = loc})))
130130

131131
and wrap_id_pos_list loc id_pos_list get_field lam =
132132
let fv = Lambda_traverse.free_variables lam in
@@ -262,9 +262,17 @@ let rec compile_functor mexp coercion root_path loc =
262262
}
263263
~params:[param'] ~body
264264

265-
(* Compile a module expression *)
265+
(* Compile a module expression, in the warning scope of its attributes like
266+
[Translcore.transl_exp] *)
266267
and transl_module cc rootpath mexp =
267-
List.iter (Translattribute.check_attribute_on_module mexp) mexp.mod_attributes;
268+
Builtin_attributes.warning_scope ~ppwarning:false mexp.mod_attributes
269+
(fun () ->
270+
List.iter
271+
(Translattribute.check_attribute_on_module mexp)
272+
mexp.mod_attributes;
273+
transl_module0 cc rootpath mexp)
274+
275+
and transl_module0 cc rootpath mexp =
268276
let loc = mexp.mod_loc in
269277
match mexp.mod_type with
270278
| Mty_alias (Mta_absent, _) ->
@@ -277,14 +285,11 @@ and transl_module cc rootpath mexp =
277285
| Tmod_structure str -> fst (transl_struct loc [] cc rootpath str)
278286
| Tmod_functor _ -> compile_functor mexp cc rootpath loc
279287
| Tmod_apply (funct, arg, ccarg) ->
280-
let inlined_attribute, funct =
281-
Translattribute.get_and_remove_inlined_attribute_on_module funct
282-
in
283288
apply_coercion loc Strict cc
284289
(Lambda.apply ~ap_transformed_jsx:false
285290
(transl_module Tcoerce_none None funct)
286291
[transl_module ccarg None arg]
287-
{ap_loc = loc; ap_inlined = inlined_attribute})
292+
{ap_loc = loc})
288293
| Tmod_constraint (arg, _, _, ccarg) ->
289294
transl_module (compose_coercions cc ccarg) rootpath arg
290295
| Tmod_unpack (arg, _) ->

0 commit comments

Comments
 (0)