Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#### :boom: Breaking Change

- 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
- 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

#### :eyeglasses: Spec Compliance
Expand Down
1 change: 0 additions & 1 deletion compiler/core/lam_pass_remove_alias.ml
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lambda.t) : Lambda.t =
(Lam_beta_reduce.propagate_beta_reduce meta params body ap_args)
else if
(* Lam_analysis.size body < Lam_analysis.small_inline_size *)
(* ap_inlined = Always_inline || *)
Lam_analysis.ok_to_inline_fun_when_app m ap_args
then
let param_map =
Expand Down
2 changes: 1 addition & 1 deletion compiler/ml/lambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ and lfunction = {

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

and ap_info = {ap_loc: Location.t; ap_inlined: inline_attribute}
and ap_info = {ap_loc: Location.t}

and lambda_apply = {
ap_func: t;
Expand Down
5 changes: 1 addition & 4 deletions compiler/ml/lambda.mli
Original file line number Diff line number Diff line change
Expand Up @@ -375,10 +375,7 @@ and lfunction = {

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

and ap_info = {
ap_loc: Location.t;
ap_inlined: inline_attribute; (* specified with the [@inlined] attribute *)
}
and ap_info = {ap_loc: Location.t}

and lambda_apply = private {
ap_func: t;
Expand Down
3 changes: 1 addition & 2 deletions compiler/ml/lambda_traverse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ let make_key e =
| Lglobal_module _ | Lconst _ -> e
| Lapply ap ->
apply ~ap_transformed_jsx:ap.ap_transformed_jsx (tr_rec env ap.ap_func)
(tr_recs env ap.ap_args)
{ap.ap_info with ap_loc = Location.none}
(tr_recs env ap.ap_args) {ap_loc = Location.none}
| Llet (Alias, x, ex, e) ->
(* Ignore aliases -> substitute *)
let ex = tr_rec env ex in
Expand Down
8 changes: 1 addition & 7 deletions compiler/ml/printlambda.ml
Original file line number Diff line number Diff line change
Expand Up @@ -231,19 +231,13 @@ let function_attribute ppf {inline; is_a_functor; return_unit} =
| Always_inline -> fprintf ppf "always_inline@ "
| Never_inline -> fprintf ppf "never_inline@ "

let apply_inlined_attribute ppf = function
| Default_inline -> ()
| Always_inline -> fprintf ppf " always_inline"
| Never_inline -> fprintf ppf " never_inline"

let rec lam ppf = function
| Lvar id -> Ident.print ppf id
| Lglobal_module id -> fprintf ppf "global %a" Ident.print id
| Lconst cst -> struct_const ppf cst
| Lapply ap ->
let lams ppf largs = List.iter (fun l -> fprintf ppf "@ %a" lam l) largs in
fprintf ppf "@[<2>(apply@ %a%a%a)@]" lam ap.ap_func lams ap.ap_args
apply_inlined_attribute ap.ap_info.ap_inlined
fprintf ppf "@[<2>(apply@ %a%a)@]" lam ap.ap_func lams ap.ap_args
| Lfunction {params; body; attr} ->
let pr_params ppf params =
List.iter (fun param -> fprintf ppf "@ %a" Ident.print param) params
Expand Down
30 changes: 3 additions & 27 deletions compiler/ml/translattribute.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ let is_inline_attribute (attr : t) =
| {txt = "inline"}, _ -> true
| _ -> false

let is_inlined_attribute (attr : t) =
match attr with
| {txt = "inlined"}, _ -> true
| _ -> false

let find_attribute p (attributes : t list) =
let inline_attribute, other_attributes = List.partition p attributes in
let attr =
Expand Down Expand Up @@ -57,7 +52,7 @@ let parse_inline_attribute (attr : t option) : Lambda.inline_attribute =
| None -> Default_inline
| Some ({txt; loc}, payload) -> (
let open Parsetree in
(* the 'inline' and 'inlined' attributes can be used as
(* the 'inline' attribute can be used as
[@inline], [@inline never] or [@inline always].
[@inline] is equivalent to [@inline always] *)
let warning txt =
Expand Down Expand Up @@ -98,33 +93,14 @@ let add_inline_attribute (expr : Lambda.t) loc attributes =
Location.prerr_warning loc (Warnings.Misplaced_attribute "inline");
expr

(* Get the [@inlined] attribute payload (or default if not present).
It also returns the expression without this attribute. This is
used to ensure that this attribute is not misplaced: If it
appears on any expression, it is an error, otherwise it would
have been removed by this function *)
let get_and_remove_inlined_attribute (e : Typedtree.expression) =
let attr, exp_attributes =
find_attribute is_inlined_attribute e.exp_attributes
in
let inlined = parse_inline_attribute attr in
(inlined, {e with exp_attributes})

let get_and_remove_inlined_attribute_on_module (e : Typedtree.module_expr) =
let attr, mod_attributes =
find_attribute is_inlined_attribute e.mod_attributes
in
let inlined = parse_inline_attribute attr in
(inlined, {e with mod_attributes})

let check_attribute (e : Typedtree.expression) (({txt; loc}, _) : t) =
match txt with
| "inline" -> (
match e.exp_desc with
| Texp_function _ -> ()
| _ -> Location.prerr_warning loc (Warnings.Misplaced_attribute txt))
| "inlined" ->
(* Removed by the Texp_apply cases *)
(* Call-site inlining hints are not supported *)
Location.prerr_warning loc (Warnings.Misplaced_attribute txt)
| _ -> ()

Expand All @@ -136,6 +112,6 @@ let check_attribute_on_module (e : Typedtree.module_expr) (({txt; loc}, _) : t)
| Tmod_functor _ -> ()
| _ -> Location.prerr_warning loc (Warnings.Misplaced_attribute txt))
| "inlined" ->
(* Removed by the Texp_apply cases *)
(* Call-site inlining hints are not supported *)
Location.prerr_warning loc (Warnings.Misplaced_attribute txt)
| _ -> ()
6 changes: 0 additions & 6 deletions compiler/ml/translattribute.mli
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,3 @@ val add_inline_attribute :
val get_inline_attribute : Parsetree.attributes -> Lambda.inline_attribute

val get_empty_attribute : string -> Parsetree.attributes -> Location.t option

val get_and_remove_inlined_attribute :
Typedtree.expression -> Lambda.inline_attribute * Typedtree.expression

val get_and_remove_inlined_attribute_on_module :
Typedtree.module_expr -> Lambda.inline_attribute * Typedtree.module_expr
28 changes: 8 additions & 20 deletions compiler/ml/translcore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -909,8 +909,7 @@ let wrap_exn loc arg =
~args:
[global_module (Ident.create_persistent Primitive_modules.exceptions)]
loc)
[arg]
{ap_loc = loc; ap_inlined = Default_inline}
[arg] {ap_loc = loc}
let exception_id_destructed (l : Lambda.t) (fv : Ident.t) : bool =
let rec hit_opt = function
| None -> false
Expand Down Expand Up @@ -1038,20 +1037,15 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.t =
{
exp_desc = Texp_ident (_, _, ({val_kind = Val_prim p} as prim_vd));
exp_type = prim_type;
} as funct;
};
args = oargs;
transformed_jsx;
}
when List.length oargs >= p.prim_arity
&& List.for_all (fun (_, arg) -> arg <> None) oargs -> (
let args, args' = cut p.prim_arity oargs in
let wrap f =
if args' = [] then f
else
let inlined, _ =
Translattribute.get_and_remove_inlined_attribute funct
in
transl_apply ~inlined ~transformed_jsx f args' e.exp_loc
if args' = [] then f else transl_apply ~transformed_jsx f args' e.exp_loc
in
let args =
List.map
Expand Down Expand Up @@ -1104,9 +1098,6 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.t =
warn_polymorphic_comparison e.exp_loc builtin argl;
wrap (mk_builtin builtin argl e.exp_loc))))
| Texp_apply {funct; args = oargs; partial; transformed_jsx} ->
let inlined, funct =
Translattribute.get_and_remove_inlined_attribute funct
in
let uncurried_partial_application =
(* In case of partial application foo(args, ...) when some args are missing,
get the arity *)
Expand All @@ -1119,7 +1110,7 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.t =
| None -> None
else None
in
transl_apply ~inlined ~uncurried_partial_application ~transformed_jsx
transl_apply ~uncurried_partial_application ~transformed_jsx
(transl_exp funct) oargs e.exp_loc
| Texp_match (arg, pat_expr_list, exn_pat_expr_list, partial) ->
transl_match e arg pat_expr_list exn_pat_expr_list partial
Expand Down Expand Up @@ -1315,12 +1306,10 @@ and transl_case {c_lhs; c_guard; c_rhs} = (c_lhs, transl_guard c_guard c_rhs)

and transl_cases cases = List.map transl_case cases

and transl_apply ?(inlined = Default_inline)
?(uncurried_partial_application = None) ?(transformed_jsx = false) lam sargs
loc =
and transl_apply ?(uncurried_partial_application = None)
?(transformed_jsx = false) lam sargs loc =
let lapply ap_func ap_args =
apply ~ap_transformed_jsx:transformed_jsx ap_func ap_args
{ap_loc = loc; ap_inlined = inlined}
apply ~ap_transformed_jsx:transformed_jsx ap_func ap_args {ap_loc = loc}
in
let rec build_apply lam args = function
| (None, optional) :: l ->
Expand Down Expand Up @@ -1371,8 +1360,7 @@ and transl_apply ?(inlined = Default_inline)
let extra_args = Ext_list.map extra_ids (fun id -> var id) in
let ap_args = args @ extra_args in
let l0 =
apply ~ap_transformed_jsx:transformed_jsx lam ap_args
{ap_loc = loc; ap_inlined = inlined}
apply ~ap_transformed_jsx:transformed_jsx lam ap_args {ap_loc = loc}
in
function_ ~loc ~attr:default_function_attribute
~params:(List.rev_append !none_ids extra_ids)
Expand Down
7 changes: 2 additions & 5 deletions compiler/ml/translmod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ and apply_coercion_result loc strict funct param arg cc_res =
~body:
(apply_coercion loc Strict cc_res
(Lambda.apply ~ap_transformed_jsx:false (Lambda.var id) [arg]
{ap_loc = loc; ap_inlined = Default_inline})))
{ap_loc = loc})))

and wrap_id_pos_list loc id_pos_list get_field lam =
let fv = Lambda_traverse.free_variables lam in
Expand Down Expand Up @@ -277,14 +277,11 @@ and transl_module cc rootpath mexp =
| Tmod_structure str -> fst (transl_struct loc [] cc rootpath str)
| Tmod_functor _ -> compile_functor mexp cc rootpath loc
| Tmod_apply (funct, arg, ccarg) ->
let inlined_attribute, funct =
Translattribute.get_and_remove_inlined_attribute_on_module funct
in
apply_coercion loc Strict cc
(Lambda.apply ~ap_transformed_jsx:false
(transl_module Tcoerce_none None funct)
[transl_module ccarg None arg]
{ap_loc = loc; ap_inlined = inlined_attribute})
{ap_loc = loc})
| Tmod_constraint (arg, _, _, ccarg) ->
transl_module (compose_coercions cc ccarg) rootpath arg
| Tmod_unpack (arg, _) ->
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Warning number 53
/.../fixtures/warning_53_inlined_attribute.res:4:9-16

2 │
3 │ let a = (@inlined f)(1)
4 │ let b = @inlined f(2)
5 │

the @inlined attribute cannot appear in this context


Warning number 53
/.../fixtures/warning_53_inlined_attribute.res:3:10-17

1 │ let f = x => x + 1
2 │
3 │ let a = (@inlined f)(1)
4 │ let b = @inlined f(2)
5 │

the @inlined attribute cannot appear in this context
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
let f = x => x + 1

let a = (@inlined f)(1)
let b = @inlined f(2)
2 changes: 1 addition & 1 deletion tests/ounit_tests/ounit_lambda_traverse_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let var = Lambda.var x
would pass either check below without exercising anything. *)
let nodes : (string * Lambda.t) list =
[
("apply", Lambda.apply var [var] {ap_loc = loc; ap_inlined = Default_inline});
("apply", Lambda.apply var [var] {ap_loc = loc});
( "function",
Lambda.function_ ~loc ~attr:Lambda.default_function_attribute ~params:[x]
~body:debugger );
Expand Down
Loading