Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable warning on inline attibute on uncurried function. #6152

Merged
merged 2 commits into from
Apr 15, 2023
Merged
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 @@ -17,6 +17,7 @@
- Fix broken formatting in uncurried mode for functions with _ placeholder args. https://github.com/rescript-lang/rescript-compiler/pull/6148
- Fix issue where spreading record types with optional labels would not have their labels preserved as optional. https://github.com/rescript-lang/rescript-compiler/pull/6154
- Fix error location to be the type with the spreads when spreading record types with duplicate labels. https://github.com/rescript-lang/rescript-compiler/pull/6157
- Disable warning on `@inline` attibute on uncurried functions. https://github.com/rescript-lang/rescript-compiler/pull/6152

# 11.0.0-alpha.3

Expand Down
11 changes: 8 additions & 3 deletions jscomp/ml/translattribute.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -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).
Expand Down
10 changes: 10 additions & 0 deletions jscomp/test/UncurriedAlways.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 */
6 changes: 6 additions & 0 deletions jscomp/test/UncurriedAlways.res
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ let bar3: _ => _ = foo3(_, 3, 4)

type cmp = Jsx.component<int>
let q: cmp = _ => Jsx.null // Check that subtyping works past type definitions

@inline
let inl = () => ()

@inline
let inl2 = (x,y) => x+y