Skip to content
Open
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 changes/inline-literal-args.polish.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Put a literal or a function passed to an inlined function from another module straight into its body when the body uses it once, instead of binding it to a variable first.
17 changes: 13 additions & 4 deletions compiler/backend/lam_pass_remove_alias.ml
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,16 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lambda.t) : Lambda.t =
| _ -> true)
args
&& Lambda.lfunction_can_be_inlined lfunction ->
(* Like the inlining in [Lam_compile]: an argument without side
effects that the body reads once takes the parameter's place,
instead of a binding of its own *)
let _, param_map =
Lam_closure.is_closed_with_map Set_ident.empty params body
in
simpl
(record_assigned
(Lam_beta_reduce.propagate_beta_reduce (current_meta ()) params
body args))
(Lam_beta_reduce.propagate_beta_reduce_with_map (current_meta ())
param_map params body args))
| _ ->
let fn = simpl l1 in
let args' = Ext_list.map_sharing args simpl in
Expand Down Expand Up @@ -259,10 +265,13 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lambda.t) : Lambda.t =
{ap_func = Lfunction ({params; body} as lfunction); ap_args = args; _}
when List.compare_lengths params args = 0
&& Lambda.lfunction_can_be_inlined lfunction ->
let _, param_map =
Lam_closure.is_closed_with_map Set_ident.empty params body
in
simpl
(record_assigned
(Lam_beta_reduce.propagate_beta_reduce (current_meta ()) params body
args))
(Lam_beta_reduce.propagate_beta_reduce_with_map (current_meta ())
param_map params body args))
| Lstringswitch (l, sw, d) -> (
let known_constant =
match l with
Expand Down
3 changes: 1 addition & 2 deletions packages/@rescript/runtime/lib/es6/Stdlib_Option.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ function getOrThrow(x, message) {
if (x !== undefined) {
return Primitive_option.valFromOption(x);
}
let msg = message !== undefined ? message : "Option.getOrThrow called for None value";
throw new Error(`Panic! ${msg}`);
throw new Error(`Panic! ${message !== undefined ? message : "Option.getOrThrow called for None value"}`);
}

function mapOr(opt, $$default, f) {
Expand Down
3 changes: 1 addition & 2 deletions packages/@rescript/runtime/lib/es6/Stdlib_Result.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ function getOrThrow(x, message) {
if (x.TAG === "Ok") {
return x._0;
}
let msg = message !== undefined ? message : "Result.getOrThrow called for Error value";
throw new Error(`Panic! ${msg}`);
throw new Error(`Panic! ${message !== undefined ? message : "Result.getOrThrow called for Error value"}`);
}

function mapOr(opt, $$default, f) {
Expand Down
3 changes: 1 addition & 2 deletions packages/@rescript/runtime/lib/js/Stdlib_Option.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ function getOrThrow(x, message) {
if (x !== undefined) {
return Primitive_option.valFromOption(x);
}
let msg = message !== undefined ? message : "Option.getOrThrow called for None value";
throw new Error(`Panic! ${msg}`);
throw new Error(`Panic! ${message !== undefined ? message : "Option.getOrThrow called for None value"}`);
}

function mapOr(opt, $$default, f) {
Expand Down
3 changes: 1 addition & 2 deletions packages/@rescript/runtime/lib/js/Stdlib_Result.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ function getOrThrow(x, message) {
if (x.TAG === "Ok") {
return x._0;
}
let msg = message !== undefined ? message : "Result.getOrThrow called for Error value";
throw new Error(`Panic! ${msg}`);
throw new Error(`Panic! ${message !== undefined ? message : "Result.getOrThrow called for Error value"}`);
}

function mapOr(opt, $$default, f) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,9 @@ function bumpThenRead(x) {

function readThenCall() {
let s = 0;
let next = () => {
s = s + 1 | 0;
return y => y;
};
let x = s;
return next()(x);
s = s + 1 | 0;
return x;
}

Mocha.describe("Inline_arg_order_cross_module_test", () => {
Expand Down
24 changes: 6 additions & 18 deletions tests/compiler_tests/src/splice_test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ Mocha.test("splice_test_static", () => {
function dynamic(arr) {
let a = [];
a.push(1, ...arr);
let arrays = [
[1],
arr
];
Test_utils.eq("File \"splice_test.res\", line 28, characters 5-12", a, [].concat(...arrays));
Test_utils.eq("File \"splice_test.res\", line 28, characters 5-12", a, [].concat([1], arr));
}

dynamic([
Expand Down Expand Up @@ -58,14 +54,10 @@ Mocha.test("splice_test_newArr_static", () => {

function dynamicNew(arr) {
let a = new Array(1, 2, ...arr);
let arrays = [
[
1,
2
],
arr
];
Test_utils.eq("File \"splice_test.res\", line 48, characters 5-12", a, [].concat(...arrays));
Test_utils.eq("File \"splice_test.res\", line 48, characters 5-12", a, [].concat([
1,
2
], arr));
}

dynamicNew([
Expand Down Expand Up @@ -125,11 +117,7 @@ Test_utils.eq("File \"splice_test.res\", line 92, characters 7-14", a, [
function dynamic$1(arr) {
let a = [];
a.push(1, ...arr);
let arrays = [
[1],
arr
];
Test_utils.eq("File \"splice_test.res\", line 98, characters 7-14", a, [].concat(...arrays));
Test_utils.eq("File \"splice_test.res\", line 98, characters 7-14", a, [].concat([1], arr));
}

dynamic$1([
Expand Down
4 changes: 1 addition & 3 deletions tests/compiler_tests/src/stdlib/Stdlib_ArrayTests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -445,8 +445,6 @@ Test.run([
]
]);

let arrays$1 = [];

Test.run([
[
"Stdlib_ArrayTests.res",
Expand All @@ -455,7 +453,7 @@ Test.run([
39
],
"concatAll - empty"
], [].concat(...arrays$1), eq, []);
], [].concat(), eq, []);

Test.run([
[
Expand Down
12 changes: 5 additions & 7 deletions tests/compiler_tests/src/stdlib/Stdlib_ObjectTests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -478,16 +478,14 @@ runGetTest({
}),
get: i => {
let opt = i["a"];
let f = i => i.concat([
4,
5
]);
let opt$1 = opt !== undefined ? Primitive_option.some(f(Primitive_option.valFromOption(opt))) : undefined;
let $$default = [];
let opt$1 = opt !== undefined ? Primitive_option.some(Primitive_option.valFromOption(opt).concat([
4,
5
])) : undefined;
if (opt$1 !== undefined) {
return Primitive_option.valFromOption(opt$1);
} else {
return $$default;
return [];
}
},
expected: [
Expand Down
5 changes: 1 addition & 4 deletions tests/compiler_tests/src/stdlib/Stdlib_ResultTests.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ let eq = Primitive_object.equal;

function forEachIfOkCallFunction() {
let called = [];
let f = i => {
called.push(i);
};
f(3);
called.push(3);
Test.run([
[
"Stdlib_ResultTests.res",
Expand Down
3 changes: 1 addition & 2 deletions tests/runtime_tests/docstrings/DocTest.res.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading