1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* vim: set ts=8 sts=2 et sw=2 tw=80:
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef js_WasmFeatures_h
#define js_WasmFeatures_h
// [SMDOC] WebAssembly feature gating
//
// Declarative listing of WebAssembly optional features. This macro is used to
// generate most of the feature gating code in a centralized manner. See
// 'Adding a feature' below for the exact steps needed to add a new feature.
//
// Each feature is either `DEFAULT`, `TENTATIVE`, or `EXPERIMENTAL`:
//
// Default features are enabled by default in ContextOptions and in the
// JS-shell, and are given a `--no-wasm-FEATURE` shell flag to disable. The
// `--wasm-FEATURE` flag is rejected.
//
// Tentative features are like Default features, but the `--wasm-FEATURE` flag
// is silently ignored.
//
// Experimental features are disabled by default in ContextOptions and in the
// JS-shell, and are given a `--wasm-FEATURE` shell flag to enable. The
// `--no-wasm-FEATURE` flag is silently ignored.
//
// The browser pref is `javascript.options.wasm-FEATURE` for default, tentative,
// and experimental features alike.
//
// # Adding a feature
//
// 1. Add a configure switch for the feature in js/moz.configure
// 2. Add a WASM_FEATURE_ENABLED #define below
// 3. Add the feature to JS_FOR_WASM_FEATURES
// a. capitalized name: Used for naming of feature functions, including
// wasmFeatureEnabled shell function.
// b. lower case name: Used for naming of feature flag variables, including
// in wasm::FeatureArgs.
// c. compile predicate: Set to WASM_FEATURE_ENABLED
// d. compiler predicate: Expression of compilers that this feature depends
// on.
// e. flag predicate: Expression used to predicate enablement of feature
// flag. Useful for disabling a feature when dependent feature is not
// enabled or if we are fuzzing.
// f. shell flag: The stem of the JS-shell flag. Will be expanded to
// --no-wasm-FEATURE or --wasm-FEATURE as explained above.
// g. preference name: The stem of the browser preference. Will be expanded
// to `javascript.options.wasm-FEATURE`.
// 4. Add the preference to module/libpref/init/StaticPrefList.yaml
// a. Use conditionally compiled flag
// b. Set value to 'true' for default features, @IS_NIGHTLY_BUILD@ for
// tentative features, and 'false' for experimental features.
// 5. [fuzzing] Add the feature to gluesmith/src/lib.rs, if wasm-smith has
// support for it.
#ifdef ENABLE_WASM_RELAXED_SIMD
# define WASM_RELAXED_SIMD_ENABLED 1
#else
# define WASM_RELAXED_SIMD_ENABLED 0
#endif
#ifdef ENABLE_WASM_EXTENDED_CONST
# define WASM_EXTENDED_CONST_ENABLED 1
#else
# define WASM_EXTENDED_CONST_ENABLED 0
#endif
#ifdef ENABLE_WASM_FUNCTION_REFERENCES
# define WASM_FUNCTION_REFERENCES_ENABLED 1
#else
# define WASM_FUNCTION_REFERENCES_ENABLED 0
#endif
#ifdef ENABLE_WASM_GC
# define WASM_GC_ENABLED 1
#else
# define WASM_GC_ENABLED 0
#endif
#ifdef ENABLE_WASM_MEMORY64
# define WASM_MEMORY64_ENABLED 1
#else
# define WASM_MEMORY64_ENABLED 0
#endif
#ifdef ENABLE_WASM_MEMORY_CONTROL
# define WASM_MEMORY_CONTROL_ENABLED 1
#else
# define WASM_MEMORY_CONTROL_ENABLED 0
#endif
#ifdef ENABLE_WASM_TAIL_CALLS
# define WASM_TAIL_CALLS_ENABLED 1
#else
# define WASM_TAIL_CALLS_ENABLED 0
#endif
#ifdef ENABLE_WASM_MOZ_INTGEMM
# define WASM_MOZ_INTGEMM_ENABLED 1
#else
# define WASM_MOZ_INTGEMM_ENABLED 0
#endif
#ifdef ENABLE_WASM_MULTI_MEMORY
# define WASM_MULTI_MEMORY_ENABLED 1
#else
# define WASM_MULTI_MEMORY_ENABLED 0
#endif
#ifdef ENABLE_WASM_JS_STRING_BUILTINS
# define WASM_JS_STRING_BUILTINS_ENABLED 1
#else
# define WASM_JS_STRING_BUILTINS_ENABLED 0
#endif
enum class WasmFeatureStage {
Experimental = 0,
Tentative,
Default,
};
// clang-format off
#define JS_FOR_WASM_FEATURES(FEATURE) \
FEATURE( \
/* capitalized name */ ExtendedConst, \
/* lower case name */ extendedConst, \
/* stage */ WasmFeatureStage::Tentative, \
/* compile predicate */ WASM_EXTENDED_CONST_ENABLED, \
/* compiler predicate */ true, \
/* flag predicate */ true, \
/* flag force enable */ false, \
/* flag fuzz enable */ true, \
/* shell flag */ "extended-const", \
/* preference name */ "extended_const") \
FEATURE( \
/* capitalized name */ Exceptions, \
/* lower case name */ exceptions, \
/* stage */ WasmFeatureStage::Default, \
/* compile predicate */ true, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ true, \
/* flag force enable */ WasmExnRefFlag(cx), \
/* flag fuzz enable */ true, \
/* shell flag */ "exceptions", \
/* preference name */ "exceptions") \
FEATURE( \
/* capitalized name */ ExnRef, \
/* lower case name */ exnref, \
/* stage */ WasmFeatureStage::Experimental, \
/* compile predicate */ true, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ true, \
/* flag force enable */ false, \
/* flag fuzz enable */ true, \
/* shell flag */ "exnref", \
/* preference name */ "exnref ") \
FEATURE( \
/* capitalized name */ FunctionReferences, \
/* lower case name */ functionReferences, \
/* stage */ WasmFeatureStage::Tentative, \
/* compile predicate */ WASM_FUNCTION_REFERENCES_ENABLED, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ true, \
/* flag force enable */ WasmGcFlag(cx), \
/* flag fuzz enable */ false, \
/* shell flag */ "function-references", \
/* preference name */ "function_references") \
FEATURE( \
/* capitalized name */ Gc, \
/* lower case name */ gc, \
/* stage */ WasmFeatureStage::Tentative, \
/* compile predicate */ WASM_GC_ENABLED, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ true, \
/* flag force enable */ false, \
/* flag fuzz enable */ false, \
/* shell flag */ "gc", \
/* preference name */ "gc") \
FEATURE( \
/* capitalized name */ JSStringBuiltins, \
/* lower case name */ jsStringBuiltins, \
/* stage */ WasmFeatureStage::Experimental, \
/* compile predicate */ WASM_JS_STRING_BUILTINS_ENABLED, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ true, \
/* flag force enable */ false, \
/* flag fuzz enable */ true, \
/* shell flag */ "js-string-builtins", \
/* preference name */ "js_string_builtins") \
FEATURE( \
/* capitalized name */ RelaxedSimd, \
/* lower case name */ v128Relaxed, \
/* stage */ WasmFeatureStage::Tentative, \
/* compile predicate */ WASM_RELAXED_SIMD_ENABLED, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ js::jit::JitSupportsWasmSimd(), \
/* flag force enable */ false, \
/* flag fuzz enable */ true, \
/* shell flag */ "relaxed-simd", \
/* preference name */ "relaxed_simd") \
FEATURE( \
/* capitalized name */ Memory64, \
/* lower case name */ memory64, \
/* stage */ WasmFeatureStage::Tentative, \
/* compile predicate */ WASM_MEMORY64_ENABLED, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ true, \
/* flag force enable */ false, \
/* flag fuzz enable */ true, \
/* shell flag */ "memory64", \
/* preference name */ "memory64") \
FEATURE( \
/* capitalized name */ MemoryControl, \
/* lower case name */ memoryControl, \
/* stage */ WasmFeatureStage::Experimental, \
/* compile predicate */ WASM_MEMORY_CONTROL_ENABLED, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ true, \
/* flag force enable */ false, \
/* flag fuzz enable */ false, \
/* shell flag */ "memory-control", \
/* preference name */ "memory_control") \
FEATURE( \
/* capitalized name */ MultiMemory, \
/* lower case name */ multiMemory, \
/* stage */ WasmFeatureStage::Experimental, \
/* compile predicate */ WASM_MULTI_MEMORY_ENABLED, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ true, \
/* flag force enable */ false, \
/* flag fuzz enable */ false, \
/* shell flag */ "multi-memory", \
/* preference name */ "multi_memory") \
FEATURE( \
/* capitalized name */ TailCalls, \
/* lower case name */ tailCalls, \
/* stage */ WasmFeatureStage::Tentative, \
/* compile predicate */ WASM_TAIL_CALLS_ENABLED, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ true, \
/* flag force enable */ false, \
/* flag fuzz enable */ true, \
/* shell flag */ "tail-calls", \
/* preference name */ "tail_calls") \
FEATURE( \
/* capitalized name */ MozIntGemm, \
/* lower case name */ mozIntGemm, \
/* stage */ WasmFeatureStage::Experimental, \
/* compile predicate */ WASM_MOZ_INTGEMM_ENABLED, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ IsSimdPrivilegedContext(cx), \
/* flag force enable */ false, \
/* flag fuzz enable */ false, \
/* shell flag */ "moz-intgemm", \
/* preference name */ "moz_intgemm") \
FEATURE( \
/* capitalized name */ TestSerialization, \
/* lower case name */ testSerialization, \
/* stage */ WasmFeatureStage::Experimental, \
/* compile predicate */ 1, \
/* compiler predicate */ IonAvailable(cx), \
/* flag predicate */ true, \
/* flag force enable */ false, \
/* flag fuzz enable */ false, \
/* shell flag */ "test-serialization", \
/* preference name */ "test-serialization") \
FEATURE( \
/* capitalized name */ TestMetadata, \
/* lower case name */ testMetadata, \
/* stage */ WasmFeatureStage::Experimental, \
/* compile predicate */ 1, \
/* compiler predicate */ AnyCompilerAvailable(cx), \
/* flag predicate */ true, \
/* flag force enable */ false, \
/* flag fuzz enable */ false, \
/* shell flag */ "test-metadata", \
/* preference name */ "test_metadata")
// clang-format on
#endif // js_WasmFeatures_h
|