Skip to content

Commit e773dfd

Browse files
authored
[EH] Make tag's attribute encoding detail (#3947)
This removes `attribute` field from `Tag` class, making the reserved and unused field known only to binary encoder and decoder. This also removes the `attribute` parameter from `makeTag` and `addTag` methods in wasm-builder.h, C API, and Binaryen JS API. Suggested in #3946 (review).
1 parent 9fc2762 commit e773dfd

15 files changed

+19
-46
lines changed

src/binaryen-c.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3352,12 +3352,10 @@ BinaryenGlobalRef BinaryenGetGlobalByIndex(BinaryenModuleRef module,
33523352

33533353
BinaryenTagRef BinaryenAddTag(BinaryenModuleRef module,
33543354
const char* name,
3355-
uint32_t attribute,
33563355
BinaryenType params,
33573356
BinaryenType results) {
33583357
auto* ret = new Tag();
33593358
ret->setExplicitName(name);
3360-
ret->attribute = attribute;
33613359
ret->sig = Signature(Type(params), Type(results));
33623360
((Module*)module)->addTag(ret);
33633361
return ret;
@@ -3423,7 +3421,6 @@ void BinaryenAddTagImport(BinaryenModuleRef module,
34233421
const char* internalName,
34243422
const char* externalModuleName,
34253423
const char* externalBaseName,
3426-
uint32_t attribute,
34273424
BinaryenType params,
34283425
BinaryenType results) {
34293426
auto* ret = new Tag();
@@ -4152,9 +4149,6 @@ BinaryenExpressionRef BinaryenGlobalGetInitExpr(BinaryenGlobalRef global) {
41524149
const char* BinaryenTagGetName(BinaryenTagRef tag) {
41534150
return ((Tag*)tag)->name.c_str();
41544151
}
4155-
uint32_t BinaryenTagGetAttribute(BinaryenTagRef tag) {
4156-
return ((Tag*)tag)->attribute;
4157-
}
41584152
BinaryenType BinaryenTagGetParams(BinaryenTagRef tag) {
41594153
return ((Tag*)tag)->sig.params.getID();
41604154
}

src/binaryen-c.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2072,7 +2072,6 @@ BINARYEN_API void BinaryenAddTagImport(BinaryenModuleRef module,
20722072
const char* internalName,
20732073
const char* externalModuleName,
20742074
const char* externalBaseName,
2075-
uint32_t attribute,
20762075
BinaryenType params,
20772076
BinaryenType results);
20782077

@@ -2142,7 +2141,6 @@ BINARYEN_REF(Tag);
21422141
// Adds a tag to the module.
21432142
BINARYEN_API BinaryenTagRef BinaryenAddTag(BinaryenModuleRef module,
21442143
const char* name,
2145-
uint32_t attribute,
21462144
BinaryenType params,
21472145
BinaryenType results);
21482146
// Gets a tag reference by name. Returns NULL if the tag does not exist.
@@ -2555,8 +2553,6 @@ BinaryenGlobalGetInitExpr(BinaryenGlobalRef global);
25552553

25562554
// Gets the name of the specified `Tag`.
25572555
BINARYEN_API const char* BinaryenTagGetName(BinaryenTagRef tag);
2558-
// Gets the attribute of the specified `Tag`.
2559-
BINARYEN_API uint32_t BinaryenTagGetAttribute(BinaryenTagRef tag);
25602556
// Gets the parameters type of the specified `Tag`.
25612557
BINARYEN_API BinaryenType BinaryenTagGetParams(BinaryenTagRef tag);
25622558
// Gets the results type of the specified `Tag`.

src/ir/module-splitting.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,6 @@ void ModuleSplitter::shareImportableItems() {
650650

651651
for (auto& tag : primary.tags) {
652652
auto secondaryTag = std::make_unique<Tag>();
653-
secondaryTag->attribute = tag->attribute;
654653
secondaryTag->sig = tag->sig;
655654
makeImportExport(*tag, *secondaryTag, "tag", ExternalKind::Tag);
656655
secondary.addTag(std::move(secondaryTag));

src/ir/module-utils.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ inline Global* copyGlobal(Global* global, Module& out) {
6666
inline Tag* copyTag(Tag* tag, Module& out) {
6767
auto* ret = new Tag();
6868
ret->name = tag->name;
69-
ret->attribute = tag->attribute;
7069
ret->sig = tag->sig;
7170
out.addTag(ret);
7271
return ret;

src/js/binaryen.js-post.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2396,8 +2396,8 @@ function wrapModule(module, self = {}) {
23962396
self['removeElementSegment'] = function(name) {
23972397
return preserveStack(() => Module['_BinaryenRemoveElementSegment'](module, strToStack(name)));
23982398
};
2399-
self['addTag'] = function(name, attribute, params, results) {
2400-
return preserveStack(() => Module['_BinaryenAddTag'](module, strToStack(name), attribute, params, results));
2399+
self['addTag'] = function(name, params, results) {
2400+
return preserveStack(() => Module['_BinaryenAddTag'](module, strToStack(name), params, results));
24012401
};
24022402
self['getTag'] = function(name) {
24032403
return preserveStack(() => Module['_BinaryenGetTag'](module, strToStack(name)));
@@ -2425,9 +2425,9 @@ function wrapModule(module, self = {}) {
24252425
Module['_BinaryenAddGlobalImport'](module, strToStack(internalName), strToStack(externalModuleName), strToStack(externalBaseName), globalType, mutable)
24262426
);
24272427
};
2428-
self['addTagImport'] = function(internalName, externalModuleName, externalBaseName, attribute, params, results) {
2428+
self['addTagImport'] = function(internalName, externalModuleName, externalBaseName, params, results) {
24292429
return preserveStack(() =>
2430-
Module['_BinaryenAddTagImport'](module, strToStack(internalName), strToStack(externalModuleName), strToStack(externalBaseName), attribute, params, results)
2430+
Module['_BinaryenAddTagImport'](module, strToStack(internalName), strToStack(externalModuleName), strToStack(externalBaseName), params, results)
24312431
);
24322432
};
24332433
self['addExport'] = // deprecated
@@ -3212,7 +3212,6 @@ Module['getTagInfo'] = function(tag) {
32123212
'name': UTF8ToString(Module['_BinaryenTagGetName'](tag)),
32133213
'module': UTF8ToString(Module['_BinaryenTagImportGetModule'](tag)),
32143214
'base': UTF8ToString(Module['_BinaryenTagImportGetBase'](tag)),
3215-
'attribute': Module['_BinaryenTagGetAttribute'](tag),
32163215
'params': Module['_BinaryenTagGetParams'](tag),
32173216
'results': Module['_BinaryenTagGetResults'](tag)
32183217
};

src/tools/fuzzing.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,6 @@ class TranslateToFuzzReader {
499499
Index num = upTo(3);
500500
for (size_t i = 0; i < num; i++) {
501501
auto tag = builder.makeTag(Names::getValidTagName(wasm, "tag$"),
502-
WASM_TAG_ATTRIBUTE_EXCEPTION,
503502
Signature(getControlFlowType(), Type::none));
504503
wasm.addTag(std::move(tag));
505504
}

src/wasm-builder.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,9 @@ class Builder {
125125
return glob;
126126
}
127127

128-
static std::unique_ptr<Tag>
129-
makeTag(Name name, uint32_t attribute, Signature sig) {
128+
static std::unique_ptr<Tag> makeTag(Name name, Signature sig) {
130129
auto tag = std::make_unique<Tag>();
131130
tag->name = name;
132-
tag->attribute = attribute;
133131
tag->sig = sig;
134132
return tag;
135133
}

src/wasm.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1801,13 +1801,8 @@ class Global : public Importable {
18011801
bool mutable_ = false;
18021802
};
18031803

1804-
// Kinds of tag attributes.
1805-
enum WasmTagAttribute : unsigned { WASM_TAG_ATTRIBUTE_EXCEPTION = 0x0 };
1806-
18071804
class Tag : public Importable {
18081805
public:
1809-
// Kind of tag. Currently only WASM_TAG_ATTRIBUTE_EXCEPTION is possible.
1810-
uint32_t attribute = WASM_TAG_ATTRIBUTE_EXCEPTION;
18111806
Signature sig;
18121807
};
18131808

src/wasm/wasm-binary.cpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ void WasmBinaryWriter::writeImports() {
282282
BYN_TRACE("write one tag\n");
283283
writeImportHeader(tag);
284284
o << U32LEB(int32_t(ExternalKind::Tag));
285-
o << U32LEB(tag->attribute);
285+
o << U32LEB(0); // Reserved 'attribute' field. Always 0.
286286
o << U32LEB(getTypeIndex(tag->sig));
287287
});
288288
if (wasm->memory.imported()) {
@@ -656,7 +656,7 @@ void WasmBinaryWriter::writeTags() {
656656
o << U32LEB(num);
657657
ModuleUtils::iterDefinedTags(*wasm, [&](Tag* tag) {
658658
BYN_TRACE("write one\n");
659-
o << U32LEB(tag->attribute);
659+
o << U32LEB(0); // Reserved 'attribute' field. Always 0.
660660
o << U32LEB(getTypeIndex(tag->sig));
661661
});
662662

@@ -2071,10 +2071,9 @@ void WasmBinaryBuilder::readImports() {
20712071
}
20722072
case ExternalKind::Tag: {
20732073
Name name(std::string("eimport$") + std::to_string(tagCounter++));
2074-
auto attribute = getU32LEB();
2074+
getU32LEB(); // Reserved 'attribute' field
20752075
auto index = getU32LEB();
2076-
auto curr =
2077-
builder.makeTag(name, attribute, getSignatureByTypeIndex(index));
2076+
auto curr = builder.makeTag(name, getSignatureByTypeIndex(index));
20782077
curr->module = module;
20792078
curr->base = base;
20802079
wasm.addTag(std::move(curr));
@@ -2908,10 +2907,9 @@ void WasmBinaryBuilder::readTags() {
29082907
BYN_TRACE("num: " << numTags << std::endl);
29092908
for (size_t i = 0; i < numTags; i++) {
29102909
BYN_TRACE("read one\n");
2911-
auto attribute = getU32LEB();
2910+
getU32LEB(); // Reserved 'attribute' field
29122911
auto typeIndex = getU32LEB();
29132912
wasm.addTag(Builder::makeTag("tag$" + std::to_string(i),
2914-
attribute,
29152913
getSignatureByTypeIndex(typeIndex)));
29162914
}
29172915
}

src/wasm/wasm-validator.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2984,10 +2984,6 @@ static void validateTags(Module& module, ValidationInfo& info) {
29842984
"Module has tags (exception-handling is disabled)");
29852985
}
29862986
for (auto& curr : module.tags) {
2987-
info.shouldBeEqual(curr->attribute,
2988-
(unsigned)0,
2989-
curr->attribute,
2990-
"Currently only attribute 0 is supported");
29912987
info.shouldBeEqual(curr->sig.results,
29922988
Type(Type::none),
29932989
curr->name,

test/binaryen.js/exception-handling.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var module = new binaryen.Module();
1919
module.setFeatures(binaryen.Features.ReferenceTypes |
2020
binaryen.Features.ExceptionHandling);
2121

22-
module.addTag("e", 0, binaryen.i32, binaryen.none);
22+
module.addTag("e", binaryen.i32, binaryen.none);
2323

2424
// (try $l0
2525
// (do

test/binaryen.js/kitchen-sink.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ function test_core() {
192192
module = new binaryen.Module();
193193

194194
// Create a tag
195-
var tag = module.addTag("a-tag", 0, binaryen.i32, binaryen.none);
195+
var tag = module.addTag("a-tag", binaryen.i32, binaryen.none);
196196

197197
// Literals and consts
198198

@@ -702,7 +702,7 @@ function test_core() {
702702
module.addFunctionImport("an-imported", "module", "base", iF, binaryen.f32);
703703
module.addGlobalImport("a-global-imp", "module", "base", binaryen.i32, false);
704704
module.addGlobalImport("a-mut-global-imp", "module", "base", binaryen.i32, true);
705-
module.addTagImport("a-tag-imp", "module", "base", 0, binaryen.i32, binaryen.none);
705+
module.addTagImport("a-tag-imp", "module", "base", binaryen.i32, binaryen.none);
706706

707707
// Exports
708708

@@ -973,7 +973,7 @@ function test_binaries() {
973973
var adder = module.addFunction("adder", ii, binaryen.i32, [], add);
974974
var initExpr = module.i32.const(3);
975975
var global = module.addGlobal("a-global", binaryen.i32, false, initExpr)
976-
var tag = module.addTag("a-tag", 0, binaryen.createType([binaryen.i32, binaryen.i32]), binaryen.none);
976+
var tag = module.addTag("a-tag", binaryen.createType([binaryen.i32, binaryen.i32]), binaryen.none);
977977
binaryen.setDebugInfo(true); // include names section
978978
buffer = module.emitBinary();
979979
binaryen.setDebugInfo(false);
@@ -1038,7 +1038,7 @@ function test_parsing() {
10381038
var adder = module.addFunction("adder", ii, binaryen.i32, [], add);
10391039
var initExpr = module.i32.const(3);
10401040
var global = module.addGlobal("a-global", binaryen.i32, false, initExpr)
1041-
var tag = module.addTag("a-tag", 0, binaryen.i32, binaryen.none);
1041+
var tag = module.addTag("a-tag", binaryen.i32, binaryen.none);
10421042
text = module.emitText();
10431043
module.dispose();
10441044
module = null;

test/binaryen.js/tag.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ module.setFeatures(binaryen.Features.ReferenceTypes |
1313

1414
var pairType = binaryen.createType([binaryen.i32, binaryen.f32]);
1515

16-
var tag = module.addTag("a-tag", 0, binaryen.i32, binaryen.none);
16+
var tag = module.addTag("a-tag", binaryen.i32, binaryen.none);
1717

1818
console.log("GetTag is equal: " + (tag === module.getTag("a-tag")));
1919

2020
var tagInfo = binaryen.getTagInfo(tag);
2121
console.log("getTagInfo=" + JSON.stringify(cleanInfo(tagInfo)));
2222

2323
module.addTagExport("a-tag", "a-tag-exp");
24-
module.addTagImport("a-tag-imp", "module", "base", 0, pairType, binaryen.none);
24+
module.addTagImport("a-tag-imp", "module", "base", pairType, binaryen.none);
2525

2626
assert(module.validate());
2727
console.log(module.emitText());

test/binaryen.js/tag.js.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
GetTag is equal: true
2-
getTagInfo={"name":"a-tag","module":"","base":"","attribute":0,"params":2,"results":0}
2+
getTagInfo={"name":"a-tag","module":"","base":"","params":2,"results":0}
33
(module
44
(type $i32_=>_none (func (param i32)))
55
(type $i32_f32_=>_none (func (param i32 f32)))

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ void test_core() {
317317
BinaryenExpressionRef i31refExpr = BinaryenI31New(module, makeInt32(module, 1));
318318

319319
// Tags
320-
BinaryenAddTag(module, "a-tag", 0, BinaryenTypeInt32(), BinaryenTypeNone());
320+
BinaryenAddTag(module, "a-tag", BinaryenTypeInt32(), BinaryenTypeNone());
321321

322322
BinaryenAddTable(module, "tab", 0, 100);
323323

0 commit comments

Comments
 (0)