Skip to content

Commit 7c6df82

Browse files
authored
Add a custom descriptors feature (#7339)
Although the proposal is called "Custom RTTs," the more precise term for its main feature is "custom descriptors." To decrease long-term confusion at the expense of some possible short-term confusion, name the corresponding new feature "custom descriptors." This feature will guard the use of both descriptor/describes clauses and exact reference types.
1 parent bda29e4 commit 7c6df82

18 files changed

+86
-9
lines changed

src/tools/tool-options.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ struct ToolOptions : public Options {
106106
.addFeature(FeatureSet::StackSwitching, "stack switching")
107107
.addFeature(FeatureSet::SharedEverything, "shared-everything threads")
108108
.addFeature(FeatureSet::FP16, "float 16 operations")
109+
.addFeature(FeatureSet::CustomDescriptors,
110+
"custom descriptors (RTTs) and exact references")
109111
.add("--enable-typed-function-references",
110112
"",
111113
"Deprecated compatibility flag",

src/wasm-binary.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ extern const char* SharedEverythingFeature;
398398
extern const char* FP16Feature;
399399
extern const char* BulkMemoryOptFeature;
400400
extern const char* CallIndirectOverlongFeature;
401+
extern const char* CustomDescriptorsFeature;
401402

402403
enum Subsection {
403404
NameModule = 0,

src/wasm-features.h

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,12 @@ struct FeatureSet {
5454
// that we can automatically generate tool flags that set it, but otherwise
5555
// it does nothing. Binaryen always accepts LEB call-indirect encodings.
5656
CallIndirectOverlong = 1 << 20,
57+
CustomDescriptors = 1 << 21,
5758
MVP = None,
5859
// Keep in sync with llvm default features:
5960
// https://github.com/llvm/llvm-project/blob/c7576cb89d6c95f03968076e902d3adfd1996577/clang/lib/Basic/Targets/WebAssembly.cpp#L150-L153
6061
Default = SignExt | MutableGlobals,
61-
All = (1 << 21) - 1,
62+
All = (1 << 22) - 1,
6263
};
6364

6465
static std::string toString(Feature f) {
@@ -105,9 +106,14 @@ struct FeatureSet {
105106
return "bulk-memory-opt";
106107
case CallIndirectOverlong:
107108
return "call-indirect-overlong";
108-
default:
109-
WASM_UNREACHABLE("unexpected feature");
109+
case CustomDescriptors:
110+
return "custom-descriptors";
111+
case MVP:
112+
case Default:
113+
case All:
114+
break;
110115
}
116+
WASM_UNREACHABLE("unexpected feature");
111117
}
112118

113119
std::string toString() const {
@@ -159,6 +165,9 @@ struct FeatureSet {
159165
assert(has || !hasBulkMemory());
160166
return has;
161167
}
168+
bool hasCustomDescriptors() const {
169+
return (features & CustomDescriptors) != 0;
170+
}
162171
bool hasAll() const { return (features & All) != 0; }
163172

164173
void set(FeatureSet f, bool v = true) {
@@ -184,6 +193,7 @@ struct FeatureSet {
184193
void setSharedEverything(bool v = true) { set(SharedEverything, v); }
185194
void setFP16(bool v = true) { set(FP16, v); }
186195
void setBulkMemoryOpt(bool v = true) { set(BulkMemoryOpt, v); }
196+
void setCustomDescriptors(bool v = true) { set(CustomDescriptors, v); }
187197
void setMVP() { features = MVP; }
188198
void setAll() { features = All; }
189199

src/wasm/wasm-binary.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,8 @@ void WasmBinaryWriter::writeFeaturesSection() {
13581358
return BinaryConsts::CustomSections::BulkMemoryOptFeature;
13591359
case FeatureSet::CallIndirectOverlong:
13601360
return BinaryConsts::CustomSections::CallIndirectOverlongFeature;
1361+
case FeatureSet::CustomDescriptors:
1362+
return BinaryConsts::CustomSections::CustomDescriptorsFeature;
13611363
case FeatureSet::None:
13621364
case FeatureSet::Default:
13631365
case FeatureSet::All:

src/wasm/wasm.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ Name RETURN_FLOW("*return:)*");
2828
Name RETURN_CALL_FLOW("*return-call:)*");
2929
Name NONCONSTANT_FLOW("*nonconstant:)*");
3030

31-
namespace BinaryConsts {
32-
namespace CustomSections {
31+
namespace BinaryConsts::CustomSections {
32+
3333
const char* Name = "name";
3434
const char* SourceMapUrl = "sourceMappingURL";
3535
const char* Dylink = "dylink";
@@ -59,8 +59,9 @@ const char* SharedEverythingFeature = "shared-everything";
5959
const char* FP16Feature = "fp16";
6060
const char* BulkMemoryOptFeature = "bulk-memory-opt";
6161
const char* CallIndirectOverlongFeature = "call-indirect-overlong";
62-
} // namespace CustomSections
63-
} // namespace BinaryConsts
62+
const char* CustomDescriptorsFeature = "custom-descriptors";
63+
64+
} // namespace BinaryConsts::CustomSections
6465

6566
Name STACK_POINTER("__stack_pointer");
6667
Name MODULE("module");

test/binaryen.js/kitchen-sink.js.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Features.RelaxedSIMD: 4096
3333
Features.ExtendedConst: 8192
3434
Features.Strings: 16384
3535
Features.MultiMemory: 32768
36-
Features.All: 2097151
36+
Features.All: 4194303
3737
InvalidId: 0
3838
BlockId: 1
3939
IfId: 2

test/example/c-api-kitchen-sink.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ BinaryenFeatureMemory64: 2048
4747
BinaryenFeatureRelaxedSIMD: 4096
4848
BinaryenFeatureExtendedConst: 8192
4949
BinaryenFeatureStrings: 16384
50-
BinaryenFeatureAll: 2097151
50+
BinaryenFeatureAll: 4194303
5151
(f32.neg
5252
(f32.const -33.61199951171875)
5353
)

test/lit/help/wasm-as.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@
128128
;; CHECK-NEXT:
129129
;; CHECK-NEXT: --disable-fp16 Disable float 16 operations
130130
;; CHECK-NEXT:
131+
;; CHECK-NEXT: --enable-custom-descriptors Enable custom descriptors (RTTs) and
132+
;; CHECK-NEXT: exact references
133+
;; CHECK-NEXT:
134+
;; CHECK-NEXT: --disable-custom-descriptors Disable custom descriptors (RTTs) and
135+
;; CHECK-NEXT: exact references
136+
;; CHECK-NEXT:
131137
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
132138
;; CHECK-NEXT:
133139
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag

test/lit/help/wasm-ctor-eval.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@
135135
;; CHECK-NEXT:
136136
;; CHECK-NEXT: --disable-fp16 Disable float 16 operations
137137
;; CHECK-NEXT:
138+
;; CHECK-NEXT: --enable-custom-descriptors Enable custom descriptors (RTTs) and
139+
;; CHECK-NEXT: exact references
140+
;; CHECK-NEXT:
141+
;; CHECK-NEXT: --disable-custom-descriptors Disable custom descriptors (RTTs) and
142+
;; CHECK-NEXT: exact references
143+
;; CHECK-NEXT:
138144
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
139145
;; CHECK-NEXT:
140146
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag

test/lit/help/wasm-dis.test

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,12 @@
121121
;; CHECK-NEXT:
122122
;; CHECK-NEXT: --disable-fp16 Disable float 16 operations
123123
;; CHECK-NEXT:
124+
;; CHECK-NEXT: --enable-custom-descriptors Enable custom descriptors (RTTs) and
125+
;; CHECK-NEXT: exact references
126+
;; CHECK-NEXT:
127+
;; CHECK-NEXT: --disable-custom-descriptors Disable custom descriptors (RTTs) and
128+
;; CHECK-NEXT: exact references
129+
;; CHECK-NEXT:
124130
;; CHECK-NEXT: --enable-typed-function-references Deprecated compatibility flag
125131
;; CHECK-NEXT:
126132
;; CHECK-NEXT: --disable-typed-function-references Deprecated compatibility flag

0 commit comments

Comments
 (0)