From 204d172b03eba701469af18e248f81db8d4d1e57 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 14 Apr 2023 16:57:32 +0200 Subject: [PATCH] Disable warning on inline attibute on uncurried function. Fixes https://github.com/rescript-lang/rescript-compiler/issues/6149 --- CHANGELOG.md | 1 + jscomp/ml/translattribute.ml | 11 ++++++++--- jscomp/test/UncurriedAlways.js | 10 ++++++++++ jscomp/test/UncurriedAlways.res | 6 ++++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4269b52cd..18dfa86196 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ #### :bug: Bug Fix - Fix broken formatting in uncurried mode for functions with _ placeholder args. https://github.com/rescript-lang/rescript-compiler/pull/6148 +- Disable warning on `@inline` attibute on uncurried functions. https://github.com/rescript-lang/rescript-compiler/pull/6152 # 11.0.0-alpha.3 diff --git a/jscomp/ml/translattribute.ml b/jscomp/ml/translattribute.ml index ac282fdf62..4f7eca2b3d 100644 --- a/jscomp/ml/translattribute.ml +++ b/jscomp/ml/translattribute.ml @@ -62,7 +62,7 @@ let get_inline_attribute l = let attr, _ = find_attribute is_inline_attribute l in parse_inline_attribute attr -let add_inline_attribute (expr : Lambda.lambda) loc attributes = +let rec add_inline_attribute (expr : Lambda.lambda) loc attributes = match (expr, get_inline_attribute attributes) with | expr, Default_inline -> expr | Lfunction ({ attr = { stub = false } as attr } as funct), inline -> @@ -72,8 +72,13 @@ let add_inline_attribute (expr : Lambda.lambda) loc attributes = Location.prerr_warning loc (Warnings.Duplicated_attribute "inline")); let attr = { attr with inline } in Lfunction { funct with attr } - | expr, (Always_inline | Never_inline) -> - Location.prerr_warning loc (Warnings.Misplaced_attribute "inline"); + | Lprim (Pccall {prim_name = "#fn_mk" | "#fn_mk_unit"} as p, [e], l), _ -> + Lambda.Lprim (p, [add_inline_attribute e loc attributes], l) + | expr, (Always_inline) -> + Location.prerr_warning loc (Warnings.Misplaced_attribute "inline1"); + expr + | expr, (Never_inline) -> + Location.prerr_warning loc (Warnings.Misplaced_attribute "inline2"); expr (* Get the [@inlined] attribute payload (or default if not present). diff --git a/jscomp/test/UncurriedAlways.js b/jscomp/test/UncurriedAlways.js index c5d6a223e1..0c8a07287f 100644 --- a/jscomp/test/UncurriedAlways.js +++ b/jscomp/test/UncurriedAlways.js @@ -47,6 +47,14 @@ function q(param) { return null; } +function inl() { + +} + +function inl2(x, y) { + return x + y | 0; +} + exports.foo = foo; exports.z = z; exports.bar = bar; @@ -59,4 +67,6 @@ exports.bar2 = bar2; exports.foo3 = foo3; exports.bar3 = bar3; exports.q = q; +exports.inl = inl; +exports.inl2 = inl2; /* Not a pure module */ diff --git a/jscomp/test/UncurriedAlways.res b/jscomp/test/UncurriedAlways.res index c3b1e13cdc..76f41443d1 100644 --- a/jscomp/test/UncurriedAlways.res +++ b/jscomp/test/UncurriedAlways.res @@ -26,3 +26,9 @@ let bar3: _ => _ = foo3(_, 3, 4) type cmp = Jsx.component let q: cmp = _ => Jsx.null // Check that subtyping works past type definitions + +@inline +let inl = () => () + +@inline +let inl2 = (x,y) => x+y