Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit deeddf1

Browse files
author
Lars T Hansen
committed
Bug 1488205 - Repurpose the --wasm-gc switch for GC. r=jseward
Differential Revision: https://phabricator.services.mozilla.com/D21692 --HG-- extra : rebase_source : 83d2b48fd76a03a8cf175e5f820b4b33f087e4d2 extra : histedit_source : e90289fdb70c787a90a338a2d64e902f4051b34c
1 parent 7170eb5 commit deeddf1

23 files changed

+138
-122
lines changed

js/public/ContextOptions.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class JS_PUBLIC_API ContextOptions {
3434
#ifdef ENABLE_WASM_CRANELIFT
3535
wasmCranelift_(false),
3636
#endif
37-
#ifdef ENABLE_WASM_REFTYPES
37+
#ifdef ENABLE_WASM_GC
3838
wasmGc_(false),
3939
#endif
4040
testWasmAwaitTier2_(false),
@@ -125,7 +125,7 @@ class JS_PUBLIC_API ContextOptions {
125125
return *this;
126126
}
127127

128-
#ifdef ENABLE_WASM_REFTYPES
128+
#ifdef ENABLE_WASM_GC
129129
bool wasmGc() const { return wasmGc_; }
130130
ContextOptions& setWasmGc(bool flag) {
131131
wasmGc_ = flag;
@@ -216,7 +216,7 @@ class JS_PUBLIC_API ContextOptions {
216216
setWasm(false);
217217
setWasmBaseline(false);
218218
setWasmIon(false);
219-
#ifdef ENABLE_WASM_REFTYPES
219+
#ifdef ENABLE_WASM_GC
220220
setWasmGc(false);
221221
#endif
222222
setNativeRegExp(false);
@@ -233,7 +233,7 @@ class JS_PUBLIC_API ContextOptions {
233233
#ifdef ENABLE_WASM_CRANELIFT
234234
bool wasmCranelift_ : 1;
235235
#endif
236-
#ifdef ENABLE_WASM_REFTYPES
236+
#ifdef ENABLE_WASM_GC
237237
bool wasmGc_ : 1;
238238
#endif
239239
bool testWasmAwaitTier2_ : 1;

js/src/builtin/TestingFunctions.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -701,11 +701,7 @@ static bool WasmReftypesEnabled(JSContext* cx, unsigned argc, Value* vp) {
701701

702702
static bool WasmGcEnabled(JSContext* cx, unsigned argc, Value* vp) {
703703
CallArgs args = CallArgsFromVp(argc, vp);
704-
#ifdef ENABLE_WASM_GC
705-
args.rval().setBoolean(wasm::HasReftypesSupport(cx));
706-
#else
707-
args.rval().setBoolean(false);
708-
#endif
704+
args.rval().setBoolean(wasm::HasGcSupport(cx));
709705
return true;
710706
}
711707

@@ -6032,15 +6028,15 @@ gc::ZealModeHelpText),
60326028
"This will return true early if compilation isn't two-tiered. "),
60336029

60346030
JS_FN_HELP("wasmReftypesEnabled", WasmReftypesEnabled, 1, 0,
6035-
"wasmReftypesEnabled(bool)",
6031+
"wasmReftypesEnabled()",
60366032
" Returns a boolean indicating whether the WebAssembly reftypes proposal is enabled."),
60376033

60386034
JS_FN_HELP("wasmGcEnabled", WasmGcEnabled, 1, 0,
6039-
"wasmGcEnabled(bool)",
6035+
"wasmGcEnabled()",
60406036
" Returns a boolean indicating whether the WebAssembly GC types proposal is enabled."),
60416037

60426038
JS_FN_HELP("wasmDebugSupport", WasmDebugSupport, 1, 0,
6043-
"wasmDebugSupport(bool)",
6039+
"wasmDebugSupport()",
60446040
" Returns a boolean indicating whether the WebAssembly compilers support debugging."),
60456041

60466042
JS_FN_HELP("isLazyFunction", IsLazyFunction, 1, 0,

js/src/jit-test/lib/wasm-binary.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,54 @@ const SimdPrefix = 0xfd;
109109
const ThreadPrefix = 0xfe;
110110
const MozPrefix = 0xff;
111111

112+
// See WasmConstants.h for documentation.
113+
// Limit this to a group of 8 per line.
114+
115+
const definedOpcodes =
116+
[0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
117+
0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
118+
0x10, 0x11,
119+
0x1a, 0x1b,
120+
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26,
121+
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
122+
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
123+
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
124+
0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
125+
0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f,
126+
0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
127+
0x58, 0x59, 0x5a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
128+
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
129+
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
130+
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
131+
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
132+
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
133+
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
134+
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
135+
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
136+
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
137+
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
138+
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
139+
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
140+
0xc0, 0xc1, 0xc2, 0xc3, 0xc4,
141+
0xd0, 0xd1, 0xd2,
142+
0xf0,
143+
0xfc, 0xfe, 0xff ];
144+
145+
const undefinedOpcodes = (function () {
146+
let a = [];
147+
let j = 0;
148+
let i = 0;
149+
while (i < 256) {
150+
while (definedOpcodes[j] > i)
151+
a.push(i++);
152+
assertEq(definedOpcodes[j], i);
153+
i++;
154+
j++;
155+
}
156+
assertEq(definedOpcodes.length + a.length, 256);
157+
return a;
158+
})();
159+
112160
// Secondary opcode bytes for misc prefix
113161
const MemoryInitCode = 0x08; // Pending
114162
const DataDropCode = 0x09; // Pending

js/src/jit-test/tests/wasm/binary.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ for (var bad of [0xff, 0, 1, 0x3f])
235235
assertErrorMessage(() => wasmEval(moduleWithSections([sigSection([v2vSig]), declSection([0]), bodySection([funcBody({locals:[], body:[BlockCode, bad, EndCode]})])])), CompileError, /invalid inline block type/);
236236

237237
// Ensure all invalid opcodes rejected
238-
for (let i = FirstInvalidOpcode; i <= LastInvalidOpcode; i++) {
239-
let binary = moduleWithSections([v2vSigSection, declSection([0]), bodySection([funcBody({locals:[], body:[i]})])]);
238+
for (let op of undefinedOpcodes) {
239+
let binary = moduleWithSections([v2vSigSection, declSection([0]), bodySection([funcBody({locals:[], body:[op]})])]);
240240
assertErrorMessage(() => wasmEval(binary), CompileError, /unrecognized opcode/);
241241
assertEq(WebAssembly.validate(binary), false);
242242
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
|jit-test| test-also=--wasm-gc; test-also=--wasm-gc --wasm-compiler=ion; test-also=--wasm-gc --wasm-compiler=baseline; include:wasm.js
1+
|jit-test| test-also=--wasm-gc; test-also=--wasm-compiler=ion; test-also=--wasm-compiler=baseline; test-also=--wasm-gc --wasm-compiler=baseline; include:wasm.js

js/src/jit-test/tests/wasm/gc/disabled-ref.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
wasmCompilationShouldFail(
44
wasmTextToBinary(`(module (func (param (ref 0)) (unreachable)))`),
5-
/reference types not enabled/);
5+
/\(ref T\) types not enabled/);

js/src/jit-test/tests/wasm/gc/ion-and-baseline.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// |jit-test| skip-if: !wasmReftypesEnabled()
1+
// |jit-test| skip-if: !wasmGcEnabled()
22

33
// Attempt to test intercalls from ion to baseline and back.
44
//
@@ -12,17 +12,15 @@
1212
// Some logging with printf confirms that refmod is baseline-compiled and
1313
// nonrefmod is ion-compiled at present, with --wasm-gc enabled.
1414

15-
// Ion can't talk about references yet *but* we can call indirect from Ion to a
16-
// baseline module that has exported a function that accepts or returns anyref,
17-
// without the caller knowing this or having to declare it. All such calls
18-
// should fail in an orderly manner with a type mismatch, at the point of the
19-
// call.
20-
2115
var refmod = new WebAssembly.Module(wasmTextToBinary(
2216
`(module
17+
(gc_feature_opt_in 3)
2318
(import $tbl "" "tbl" (table 4 funcref))
2419
(import $print "" "print" (func (param i32)))
2520
21+
;; Just a dummy
22+
(type $s (struct (field i32)))
23+
2624
(type $htype (func (param anyref)))
2725
(type $itype (func (result anyref)))
2826

js/src/jit/CompileWrappers.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,6 @@ JitCompileOptions::JitCompileOptions()
218218
: cloneSingletons_(false),
219219
profilerSlowAssertionsEnabled_(false),
220220
offThreadCompilationAvailable_(false)
221-
#ifdef ENABLE_WASM_REFTYPES
222-
,
223-
wasmGcEnabled_(false)
224-
#endif
225221
{
226222
}
227223

@@ -231,7 +227,4 @@ JitCompileOptions::JitCompileOptions(JSContext* cx) {
231227
cx->runtime()->geckoProfiler().enabled() &&
232228
cx->runtime()->geckoProfiler().slowAssertionsEnabled();
233229
offThreadCompilationAvailable_ = OffThreadCompilationAvailable(cx);
234-
#ifdef ENABLE_WASM_REFTYPES
235-
wasmGcEnabled_ = wasm::HasReftypesSupport(cx);
236-
#endif
237230
}

js/src/jit/CompileWrappers.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,17 +131,10 @@ class JitCompileOptions {
131131
return offThreadCompilationAvailable_;
132132
}
133133

134-
#ifdef ENABLE_WASM_REFTYPES
135-
bool wasmGcEnabled() const { return wasmGcEnabled_; }
136-
#endif
137-
138134
private:
139135
bool cloneSingletons_;
140136
bool profilerSlowAssertionsEnabled_;
141137
bool offThreadCompilationAvailable_;
142-
#ifdef ENABLE_WASM_REFTYPES
143-
bool wasmGcEnabled_;
144-
#endif
145138
};
146139

147140
} // namespace jit

js/src/shell/js.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ static bool enableSharedMemory = SHARED_MEMORY_DEFAULT;
494494
static bool enableWasmBaseline = false;
495495
static bool enableWasmIon = false;
496496
static bool enableWasmCranelift = false;
497-
#ifdef ENABLE_WASM_REFTYPES
497+
#ifdef ENABLE_WASM_GC
498498
static bool enableWasmGc = false;
499499
#endif
500500
static bool enableWasmVerbose = false;
@@ -9883,7 +9883,7 @@ static bool SetContextOptions(JSContext* cx, const OptionParser& op) {
98839883
}
98849884
}
98859885

9886-
#ifdef ENABLE_WASM_REFTYPES
9886+
#ifdef ENABLE_WASM_GC
98879887
enableWasmGc = op.getBoolOption("wasm-gc");
98889888
#endif
98899889
enableWasmVerbose = op.getBoolOption("wasm-verbose");
@@ -9902,7 +9902,7 @@ static bool SetContextOptions(JSContext* cx, const OptionParser& op) {
99029902
#ifdef ENABLE_WASM_CRANELIFT
99039903
.setWasmCranelift(enableWasmCranelift)
99049904
#endif
9905-
#ifdef ENABLE_WASM_REFTYPES
9905+
#ifdef ENABLE_WASM_GC
99069906
.setWasmGc(enableWasmGc)
99079907
#endif
99089908
.setWasmVerbose(enableWasmVerbose)
@@ -10205,7 +10205,7 @@ static void SetWorkerContextOptions(JSContext* cx) {
1020510205
#ifdef ENABLE_WASM_CRANELIFT
1020610206
.setWasmCranelift(enableWasmCranelift)
1020710207
#endif
10208-
#ifdef ENABLE_WASM_REFTYPES
10208+
#ifdef ENABLE_WASM_GC
1020910209
.setWasmGc(enableWasmGc)
1021010210
#endif
1021110211
.setWasmVerbose(enableWasmVerbose)
@@ -10590,8 +10590,8 @@ int main(int argc, char** argv, char** envp) {
1059010590
!op.addBoolOption('\0', "test-wasm-await-tier2",
1059110591
"Forcibly activate tiering and block "
1059210592
"instantiation on completion of tier2")
10593-
#ifdef ENABLE_WASM_REFTYPES
10594-
|| !op.addBoolOption('\0', "wasm-gc", "Enable wasm GC features")
10593+
#ifdef ENABLE_WASM_GC
10594+
|| !op.addBoolOption('\0', "wasm-gc", "Enable experimental wasm GC features")
1059510595
#else
1059610596
|| !op.addBoolOption('\0', "wasm-gc", "No-op")
1059710597
#endif

0 commit comments

Comments
 (0)