Skip to content

Commit 380a5e7

Browse files
committed
Bug 1488205 - Repurpose the --wasm-gc switch for GC. r=jseward
Differential Revision: https://phabricator.services.mozilla.com/D21692 UltraBlame original commit: 8085449bd4261f957dff79032f75d95b94fab787
1 parent ed8a079 commit 380a5e7

21 files changed

+151
-117
lines changed

js/public/ContextOptions.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,22 @@ class JS_PUBLIC_API ContextOptions {
1919
public:
2020
ContextOptions()
2121
: baseline_(true),
22+
#ifdef JS_CODEGEN_ARM64
23+
ion_(false),
24+
asmJS_(false),
25+
wasm_(false),
26+
#else
2227
ion_(true),
2328
asmJS_(true),
2429
wasm_(true),
30+
#endif
2531
wasmVerbose_(false),
2632
wasmBaseline_(true),
2733
wasmIon_(true),
2834
#ifdef ENABLE_WASM_CRANELIFT
2935
wasmCranelift_(false),
3036
#endif
31-
#ifdef ENABLE_WASM_REFTYPES
37+
#ifdef ENABLE_WASM_GC
3238
wasmGc_(false),
3339
#endif
3440
testWasmAwaitTier2_(false),
@@ -119,7 +125,7 @@ class JS_PUBLIC_API ContextOptions {
119125
return *this;
120126
}
121127

122-
#ifdef ENABLE_WASM_REFTYPES
128+
#ifdef ENABLE_WASM_GC
123129
bool wasmGc() const { return wasmGc_; }
124130
ContextOptions& setWasmGc(bool flag) {
125131
wasmGc_ = flag;
@@ -210,7 +216,7 @@ class JS_PUBLIC_API ContextOptions {
210216
setWasm(false);
211217
setWasmBaseline(false);
212218
setWasmIon(false);
213-
#ifdef ENABLE_WASM_REFTYPES
219+
#ifdef ENABLE_WASM_GC
214220
setWasmGc(false);
215221
#endif
216222
setNativeRegExp(false);
@@ -227,7 +233,7 @@ class JS_PUBLIC_API ContextOptions {
227233
#ifdef ENABLE_WASM_CRANELIFT
228234
bool wasmCranelift_ : 1;
229235
#endif
230-
#ifdef ENABLE_WASM_REFTYPES
236+
#ifdef ENABLE_WASM_GC
231237
bool wasmGc_ : 1;
232238
#endif
233239
bool testWasmAwaitTier2_ : 1;

js/src/builtin/TestingFunctions.cpp

Lines changed: 8 additions & 11 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

@@ -1657,16 +1653,17 @@ static bool NewRope(JSContext* cx, unsigned argc, Value* vp) {
16571653
}
16581654
}
16591655

1660-
RootedString left(cx, args[0].toString());
1661-
RootedString right(cx, args[1].toString());
1656+
JSString* left = args[0].toString();
1657+
JSString* right = args[1].toString();
16621658
size_t length = JS_GetStringLength(left) + JS_GetStringLength(right);
16631659
if (length > JSString::MAX_LENGTH) {
16641660
JS_ReportErrorASCII(cx, "rope length exceeds maximum string length");
16651661
return false;
16661662
}
16671663

1668-
Rooted<JSRope*> str(cx, JSRope::new_<CanGC>(cx, left, right, length, heap));
1664+
Rooted<JSRope*> str(cx, JSRope::new_<NoGC>(cx, left, right, length, heap));
16691665
if (!str) {
1666+
JS_ReportOutOfMemory(cx);
16701667
return false;
16711668
}
16721669

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

60336030
JS_FN_HELP("wasmReftypesEnabled", WasmReftypesEnabled, 1, 0,
6034-
"wasmReftypesEnabled(bool)",
6031+
"wasmReftypesEnabled()",
60356032
" Returns a boolean indicating whether the WebAssembly reftypes proposal is enabled."),
60366033

60376034
JS_FN_HELP("wasmGcEnabled", WasmGcEnabled, 1, 0,
6038-
"wasmGcEnabled(bool)",
6035+
"wasmGcEnabled()",
60396036
" Returns a boolean indicating whether the WebAssembly GC types proposal is enabled."),
60406037

60416038
JS_FN_HELP("wasmDebugSupport", WasmDebugSupport, 1, 0,
6042-
"wasmDebugSupport(bool)",
6039+
"wasmDebugSupport()",
60436040
" Returns a boolean indicating whether the WebAssembly compilers support debugging."),
60446041

60456042
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
@@ -110,6 +110,54 @@ const ThreadPrefix = 0xfe;
110110
const MozPrefix = 0xff;
111111

112112

113+
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+
160+
113161
const MemoryInitCode = 0x08;
114162
const DataDropCode = 0x09;
115163
const MemoryCopyCode = 0x0a;

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

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: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,15 @@
1212

1313

1414

15-
16-
17-
18-
19-
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
}

js/src/shell/js.cpp

Lines changed: 17 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;
@@ -9840,14 +9840,25 @@ static MOZ_MUST_USE bool ProcessArgs(JSContext* cx, OptionParser* op) {
98409840

98419841
static bool SetContextOptions(JSContext* cx, const OptionParser& op) {
98429842
enableBaseline = !op.getBoolOption("no-baseline");
9843+
#ifdef JS_CODEGEN_ARM64
9844+
9845+
enableIon = false;
9846+
enableAsmJS = false;
9847+
#else
98439848
enableIon = !op.getBoolOption("no-ion");
98449849
enableAsmJS = !op.getBoolOption("no-asmjs");
9850+
#endif
98459851
enableNativeRegExp = !op.getBoolOption("no-native-regexp");
98469852

98479853

98489854
enableWasm = true;
98499855
enableWasmBaseline = true;
9856+
#ifdef JS_CODEGEN_ARM64
9857+
9858+
enableWasmIon = false;
9859+
#else
98509860
enableWasmIon = true;
9861+
#endif
98519862
if (const char* str = op.getStringOption("wasm-compiler")) {
98529863
if (strcmp(str, "none") == 0) {
98539864
enableWasm = false;
@@ -9872,7 +9883,7 @@ static bool SetContextOptions(JSContext* cx, const OptionParser& op) {
98729883
}
98739884
}
98749885

9875-
#ifdef ENABLE_WASM_REFTYPES
9886+
#ifdef ENABLE_WASM_GC
98769887
enableWasmGc = op.getBoolOption("wasm-gc");
98779888
#endif
98789889
enableWasmVerbose = op.getBoolOption("wasm-verbose");
@@ -9891,7 +9902,7 @@ static bool SetContextOptions(JSContext* cx, const OptionParser& op) {
98919902
#ifdef ENABLE_WASM_CRANELIFT
98929903
.setWasmCranelift(enableWasmCranelift)
98939904
#endif
9894-
#ifdef ENABLE_WASM_REFTYPES
9905+
#ifdef ENABLE_WASM_GC
98959906
.setWasmGc(enableWasmGc)
98969907
#endif
98979908
.setWasmVerbose(enableWasmVerbose)
@@ -10194,7 +10205,7 @@ static void SetWorkerContextOptions(JSContext* cx) {
1019410205
#ifdef ENABLE_WASM_CRANELIFT
1019510206
.setWasmCranelift(enableWasmCranelift)
1019610207
#endif
10197-
#ifdef ENABLE_WASM_REFTYPES
10208+
#ifdef ENABLE_WASM_GC
1019810209
.setWasmGc(enableWasmGc)
1019910210
#endif
1020010211
.setWasmVerbose(enableWasmVerbose)
@@ -10579,8 +10590,8 @@ int main(int argc, char** argv, char** envp) {
1057910590
!op.addBoolOption('\0', "test-wasm-await-tier2",
1058010591
"Forcibly activate tiering and block "
1058110592
"instantiation on completion of tier2")
10582-
#ifdef ENABLE_WASM_REFTYPES
10583-
|| !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")
1058410595
#else
1058510596
|| !op.addBoolOption('\0', "wasm-gc", "No-op")
1058610597
#endif

0 commit comments

Comments
 (0)