Skip to content

Commit 5926d5d

Browse files
authored
Remove null function table entry (#1012)
1 parent e2804df commit 5926d5d

File tree

269 files changed

+90
-1073
lines changed

Some content is hidden

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

269 files changed

+90
-1073
lines changed

src/compiler.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ export class Compiler extends DiagnosticEmitter {
303303
memorySegments: MemorySegment[] = [];
304304
/** Map of already compiled static string segments. */
305305
stringSegments: Map<string,MemorySegment> = new Map();
306-
/** Function table being compiled. */
307-
functionTable: string[] = [ "null" ];
306+
/** Function table being compiled. First elem is blank. */
307+
functionTable: string[] = [];
308308
/** Argument count helper global. */
309309
argcVar: GlobalRef = 0;
310310
/** Argument count helper setter. */
@@ -452,10 +452,9 @@ export class Compiler extends DiagnosticEmitter {
452452
// import memory if requested (default memory is named '0' by Binaryen)
453453
if (options.importMemory) module.addMemoryImport("0", "env", "memory", isSharedMemory);
454454

455-
// set up function table
455+
// set up function table (first elem is blank)
456456
var functionTable = this.functionTable;
457-
module.setFunctionTable(functionTable.length, Module.UNLIMITED_TABLE, functionTable, module.i32(0));
458-
module.addFunction("null", NativeType.None, NativeType.None, null, module.unreachable());
457+
module.setFunctionTable(1 + functionTable.length, Module.UNLIMITED_TABLE, functionTable, module.i32(1));
459458

460459
// import and/or export table if requested (default table is named '0' by Binaryen)
461460
if (options.importTable) module.addTableImport("0", "env", "table");
@@ -1605,7 +1604,7 @@ export class Compiler extends DiagnosticEmitter {
16051604
return func.functionTableIndex;
16061605
}
16071606
var functionTable = this.functionTable;
1608-
var index = functionTable.length;
1607+
var index = 1 + functionTable.length; // first elem is blank
16091608
if (!func.is(CommonFlags.TRAMPOLINE) && func.signature.requiredParameters < func.signature.parameterTypes.length) {
16101609
// insert the trampoline if the function has optional parameters
16111610
func = this.ensureTrampoline(func);
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
(module
2-
(type $none_=>_none (func))
32
(memory $0 0)
43
(export "memory" (memory $0))
5-
(func $null (; 0 ;)
6-
unreachable
7-
)
84
)
Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
(module
2-
(type $none_=>_none (func))
32
(memory $0 0)
43
(table $0 1 funcref)
5-
(elem (i32.const 0) $null)
64
(export "memory" (memory $0))
7-
(func $null (; 0 ;)
8-
unreachable
9-
)
105
)

tests/compiler/abi.optimized.wat

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,4 @@
1919
i32.const 0
2020
global.set $abi/y
2121
)
22-
(func $null (; 2 ;)
23-
unreachable
24-
)
2522
)

tests/compiler/abi.untouched.wat

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
(memory $0 1)
77
(data (i32.const 8) "\0c\00\00\00\01\00\00\00\01\00\00\00\0c\00\00\00a\00b\00i\00.\00t\00s\00")
88
(table $0 1 funcref)
9-
(elem (i32.const 0) $null)
109
(global $abi/condition (mut i32) (i32.const 0))
1110
(global $abi/y (mut i32) (i32.const 0))
1211
(export "memory" (memory $0))
@@ -202,7 +201,4 @@
202201
(func $start (; 6 ;)
203202
call $start:abi
204203
)
205-
(func $null (; 7 ;)
206-
unreachable
207-
)
208204
)
Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
(module
2-
(type $none_=>_none (func))
32
(memory $0 0)
43
(export "memory" (memory $0))
5-
(func $null (; 0 ;)
6-
unreachable
7-
)
84
)

tests/compiler/asc-constants.untouched.wat

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
(type $none_=>_none (func))
33
(memory $0 0)
44
(table $0 1 funcref)
5-
(elem (i32.const 0) $null)
65
(global $~lib/ASC_TARGET i32 (i32.const 0))
76
(global $~lib/ASC_NO_ASSERT i32 (i32.const 0))
87
(global $~lib/ASC_MEMORY_BASE i32 (i32.const 0))
@@ -52,7 +51,4 @@
5251
(func $start (; 1 ;)
5352
call $start:asc-constants
5453
)
55-
(func $null (; 2 ;)
56-
unreachable
57-
)
5854
)

tests/compiler/assert-nonnull.optimized.wat

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
(module
22
(type $i32_=>_i32 (func (param i32) (result i32)))
33
(type $none_=>_i32 (func (result i32)))
4-
(type $none_=>_none (func))
54
(type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32)))
65
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
76
(memory $0 1)
87
(data (i32.const 8) "$\00\00\00\01\00\00\00\01\00\00\00$\00\00\00I\00n\00d\00e\00x\00 \00o\00u\00t\00 \00o\00f\00 \00r\00a\00n\00g\00e")
98
(data (i32.const 64) "\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s")
109
(data (i32.const 112) "^\00\00\00\01\00\00\00\01\00\00\00^\00\00\00E\00l\00e\00m\00e\00n\00t\00 \00t\00y\00p\00e\00 \00m\00u\00s\00t\00 \00b\00e\00 \00n\00u\00l\00l\00a\00b\00l\00e\00 \00i\00f\00 \00a\00r\00r\00a\00y\00 \00i\00s\00 \00h\00o\00l\00e\00y")
1110
(table $0 1 funcref)
12-
(elem (i32.const 0) $null)
1311
(global $~lib/argc (mut i32) (i32.const 0))
1412
(export "memory" (memory $0))
1513
(export "testVar" (func $assert-nonnull/testVar))
@@ -192,7 +190,4 @@
192190
unreachable
193191
end
194192
)
195-
(func $null (; 15 ;)
196-
unreachable
197-
)
198193
)

tests/compiler/assert-nonnull.untouched.wat

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
(type $i32_=>_i32 (func (param i32) (result i32)))
33
(type $none_=>_i32 (func (result i32)))
44
(type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
5-
(type $none_=>_none (func))
65
(type $i32_=>_none (func (param i32)))
76
(type $i32_i32_i32_i32_=>_none (func (param i32 i32 i32 i32)))
87
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
@@ -11,7 +10,6 @@
1110
(data (i32.const 64) "\1a\00\00\00\01\00\00\00\01\00\00\00\1a\00\00\00~\00l\00i\00b\00/\00a\00r\00r\00a\00y\00.\00t\00s\00")
1211
(data (i32.const 112) "^\00\00\00\01\00\00\00\01\00\00\00^\00\00\00E\00l\00e\00m\00e\00n\00t\00 \00t\00y\00p\00e\00 \00m\00u\00s\00t\00 \00b\00e\00 \00n\00u\00l\00l\00a\00b\00l\00e\00 \00i\00f\00 \00a\00r\00r\00a\00y\00 \00i\00s\00 \00h\00o\00l\00e\00y\00")
1312
(table $0 1 funcref)
14-
(elem (i32.const 0) $null)
1513
(global $~lib/argc (mut i32) (i32.const 0))
1614
(export "memory" (memory $0))
1715
(export "testVar" (func $assert-nonnull/testVar))
@@ -376,7 +374,4 @@
376374
call $~lib/rt/stub/__release
377375
local.get $2
378376
)
379-
(func $null (; 19 ;)
380-
unreachable
381-
)
382377
)

tests/compiler/assert.optimized.wat

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
(module
2-
(type $none_=>_none (func))
32
(memory $0 0)
43
(export "memory" (memory $0))
5-
(func $null (; 0 ;)
6-
unreachable
7-
)
84
)

0 commit comments

Comments
 (0)