Skip to content

Commit f6e5b00

Browse files
feat(compiler)!: Enable tail calls by default (#1589)
* feat: Make Tail Calls Default * fix: Disable Tail Calls In Near SmokeTest * Update size of smallest grain program --------- Co-authored-by: Oscar Spencer <oscar@grain-lang.org>
1 parent cbd46ee commit f6e5b00

File tree

147 files changed

+1034
-1403
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

147 files changed

+1034
-1403
lines changed

cli/__test__/index.gr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* grainc-flags --no-gc --no-bulk-memory */
1+
/* grainc-flags --no-gc --no-bulk-memory --no-wasm-tail-call */
22
module NearTest
33

44
include "runtime/unsafe/wasmi32"

cli/__test__/nearEnv.gr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* grainc-flags --no-gc --no-bulk-memory */
1+
/* grainc-flags --no-gc --no-bulk-memory --no-wasm-tail-call */
22
module NearEnv
33

44
provide foreign wasm storage_read: (

compiler/src/codegen/compcore.re

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1391,16 +1391,16 @@ let call_lambda =
13911391
| Some(name) =>
13921392
let instr =
13931393
if (tail) {
1394-
if (Config.experimental_tail_call^) {
1395-
Expression.Call.make_return;
1396-
} else {
1394+
if (Config.no_tail_call^) {
13971395
(
13981396
(wasm_mod, name, args, retty) =>
13991397
Expression.Return.make(
14001398
wasm_mod,
14011399
Expression.Call.make(wasm_mod, name, args, retty),
14021400
)
14031401
);
1402+
} else {
1403+
Expression.Call.make_return;
14041404
};
14051405
} else {
14061406
Expression.Call.make;
@@ -1410,9 +1410,7 @@ let call_lambda =
14101410
| None =>
14111411
let instr =
14121412
if (tail) {
1413-
if (Config.experimental_tail_call^) {
1414-
Expression.Call_indirect.make_return;
1415-
} else {
1413+
if (Config.no_tail_call^) {
14161414
(
14171415
(wasm_mod, table, ptr, args, argty, retty) =>
14181416
Expression.Return.make(
@@ -1427,6 +1425,8 @@ let call_lambda =
14271425
),
14281426
)
14291427
);
1428+
} else {
1429+
Expression.Call_indirect.make_return;
14301430
};
14311431
} else {
14321432
Expression.Call_indirect.make;

compiler/src/utils/config.re

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,10 +466,10 @@ let compilation_mode =
466466
let statically_link =
467467
toggle_flag(~names=["no-link"], ~doc="Disable static linking", true);
468468

469-
let experimental_tail_call =
469+
let no_tail_call =
470470
toggle_flag(
471-
~names=["experimental-wasm-tail-call"],
472-
~doc="Enables tail-call optimization",
471+
~names=["no-wasm-tail-call"],
472+
~doc="Disables tail-call optimization",
473473
false,
474474
);
475475

compiler/src/utils/config.rei

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ let compilation_mode: ref(option(string));
9090

9191
let statically_link: ref(bool);
9292

93-
/** Enable tail-call optimizations */
93+
/** Disables tail-call optimizations */
9494

95-
let experimental_tail_call: ref(bool);
95+
let no_tail_call: ref(bool);
9696

9797
/** Whether to allow cyclic types. */
9898

compiler/test/__snapshots__/basic_functionality.0996c5f7.0.snapshot

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,13 @@ basic functionality › modulo4
3636
(local $4 f32)
3737
(local $5 f64)
3838
(block $compile_block.1
39-
(return
40-
(call $%_1113
41-
(call $incRef_0
42-
(global.get $GRAIN$EXPORT$incRef_0)
43-
(global.get $%_1113)
44-
)
45-
(i32.const -33)
46-
(i32.const 35)
39+
(return_call $%_1113
40+
(call $incRef_0
41+
(global.get $GRAIN$EXPORT$incRef_0)
42+
(global.get $%_1113)
4743
)
44+
(i32.const -33)
45+
(i32.const 35)
4846
)
4947
)
5048
)

compiler/test/__snapshots__/basic_functionality.0a230f18.0.snapshot

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,13 @@ basic functionality › land4
3636
(local $4 f32)
3737
(local $5 f64)
3838
(block $compile_block.1
39-
(return
40-
(call $&_1113
41-
(call $incRef_0
42-
(global.get $GRAIN$EXPORT$incRef_0)
43-
(global.get $&_1113)
44-
)
45-
(i32.const 1)
46-
(i32.const 1)
39+
(return_call $&_1113
40+
(call $incRef_0
41+
(global.get $GRAIN$EXPORT$incRef_0)
42+
(global.get $&_1113)
4743
)
44+
(i32.const 1)
45+
(i32.const 1)
4846
)
4947
)
5048
)

compiler/test/__snapshots__/basic_functionality.0a2e4afa.0.snapshot

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,13 @@ basic functionality › lxor1
3636
(local $4 f32)
3737
(local $5 f64)
3838
(block $compile_block.1
39-
(return
40-
(call $^_1113
41-
(call $incRef_0
42-
(global.get $GRAIN$EXPORT$incRef_0)
43-
(global.get $^_1113)
44-
)
45-
(i32.const 3)
46-
(i32.const 3)
39+
(return_call $^_1113
40+
(call $incRef_0
41+
(global.get $GRAIN$EXPORT$incRef_0)
42+
(global.get $^_1113)
4743
)
44+
(i32.const 3)
45+
(i32.const 3)
4846
)
4947
)
5048
)

compiler/test/__snapshots__/basic_functionality.0c0b170b.0.snapshot

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,13 @@ basic functionality › lor1
3636
(local $4 f32)
3737
(local $5 f64)
3838
(block $compile_block.1
39-
(return
40-
(call $|_1113
41-
(call $incRef_0
42-
(global.get $GRAIN$EXPORT$incRef_0)
43-
(global.get $|_1113)
44-
)
45-
(i32.const 3)
46-
(i32.const 3)
39+
(return_call $|_1113
40+
(call $incRef_0
41+
(global.get $GRAIN$EXPORT$incRef_0)
42+
(global.get $|_1113)
4743
)
44+
(i32.const 3)
45+
(i32.const 3)
4846
)
4947
)
5048
)

compiler/test/__snapshots__/basic_functionality.0c400bde.0.snapshot

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,13 @@ basic functionality › modulo6
3636
(local $4 f32)
3737
(local $5 f64)
3838
(block $compile_block.1
39-
(return
40-
(call $%_1113
41-
(call $incRef_0
42-
(global.get $GRAIN$EXPORT$incRef_0)
43-
(global.get $%_1113)
44-
)
45-
(i32.const 35)
46-
(i32.const 35)
39+
(return_call $%_1113
40+
(call $incRef_0
41+
(global.get $GRAIN$EXPORT$incRef_0)
42+
(global.get $%_1113)
4743
)
44+
(i32.const 35)
45+
(i32.const 35)
4846
)
4947
)
5048
)

0 commit comments

Comments
 (0)