Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/binaryen-c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,9 @@ BinaryenFeatures BinaryenFeatureCustomPageSizes(void) {
BinaryenFeatures BinaryenFeatureWideArithmetic(void) {
return static_cast<BinaryenFeatures>(FeatureSet::WideArithmetic);
}
BinaryenFeatures BinaryenFeatureCompactImports(void) {
return static_cast<BinaryenFeatures>(FeatureSet::CompactImports);
}
BinaryenFeatures BinaryenFeatureAll(void) {
return static_cast<BinaryenFeatures>(FeatureSet::All);
}
Expand Down
1 change: 1 addition & 0 deletions src/binaryen-c.h
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ BINARYEN_API BinaryenFeatures BinaryenFeatureRelaxedAtomics(void);
BINARYEN_API BinaryenFeatures BinaryenFeatureMultibyte(void);
BINARYEN_API BinaryenFeatures BinaryenFeatureCustomPageSizes(void);
BINARYEN_API BinaryenFeatures BinaryenFeatureWideArithmetic(void);
BINARYEN_API BinaryenFeatures BinaryenFeatureCompactImports(void);
BINARYEN_API BinaryenFeatures BinaryenFeatureAll(void);

// Modules
Expand Down
1 change: 1 addition & 0 deletions src/js/binaryen.js-post.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ function initializeConstants() {
'RelaxedAtomics',
'CustomPageSizes',
'WideArithmetic',
'CompactImports',
'All'
].forEach(name => {
Module['Features'][name] = Module['_BinaryenFeature' + name]();
Expand Down
1 change: 1 addition & 0 deletions src/tools/tool-options.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ struct ToolOptions : public Options {
"acquire/release atomic memory operations")
.addFeature(FeatureSet::CustomPageSizes, "custom page sizes")
.addFeature(FeatureSet::WideArithmetic, "wide arithmetic")
.addFeature(FeatureSet::CompactImports, "compact import section")
.add("--enable-typed-function-references",
"",
"Deprecated compatibility flag",
Expand Down
7 changes: 7 additions & 0 deletions src/wasm-binary.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ extern const char* RelaxedAtomicsFeature;
extern const char* MultibyteFeature;
extern const char* CustomPageSizesFeature;
extern const char* WideArithmeticFeature;
extern const char* CompactImportsFeature;

enum Subsection {
NameModule = 0,
Expand Down Expand Up @@ -1671,6 +1672,12 @@ class WasmBinaryReader {
Address defaultIfNoMax);
void readImports();

void addImport(uint32_t kind, std::unique_ptr<Importable> importable);
std::unique_ptr<Importable>
readImportDetails(Name module, Name field, uint32_t kind);
std::unique_ptr<Importable> copyImportable(uint32_t kind,
Importable& details);

Comment on lines +1675 to +1680
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Importable doesn't define a virtual destructor, so IIUC we shouldn't put subclasses of Importable in a unique_ptr because deleting it is UB and will leak resources (i.e. this looks like slicing).

Maybe we can just add the virtual destructor? I'm not sure if we didn't add it on purpose to avoid a performance penalty. Or otherwise, maybe we'd want to split these out into different functions for each type of Importable or use a std::variant.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I see stuff like std::unique_ptr<Function> all over the codbase.. so isn't "subclasses of Importable in a unique_ptr" just something that exists already?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or did you mean we shouldn't put Importable itself in a unique_ptr?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, unique_ptr<Function> is fine because it will invoke Function's destructor, but an instance of Function in a unique_ptr<Importable> isn't ok because it will invoke Importable's destructor and leak memory (in particular Function has a vector field which has a non-trivial destructor).

It could work if we give the unique_ptr a custom deleter when constructing it, but I feel it would be better to just split these methods into different ones for functions, tables, etc.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A std::variant might also be an option here (but I don't feel strongly one way or the other).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I guess we don't want to add virtual dtors everywhere to allow this kind of thing?

It does seem kind of backwards to create a std::variant to hold bunch of different things that all share a common supertype. Isn't that exactly what a supertype pointer/reference is supposed to be able to do.

// The signatures of each function, including imported functions, given in the
// import and function sections. Store HeapTypes instead of Signatures because
// reconstructing the HeapTypes from the Signatures is expensive.
Expand Down
7 changes: 6 additions & 1 deletion src/wasm-features.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ struct FeatureSet {
CustomPageSizes = 1 << 23,
Multibyte = 1 << 24,
WideArithmetic = 1 << 25,
CompactImports = 1 << 26,
MVP = None,
// Keep in sync with llvm default features:
// https://github.com/llvm/llvm-project/blob/c7576cb89d6c95f03968076e902d3adfd1996577/clang/lib/Basic/Targets/WebAssembly.cpp#L150-L153
Default = SignExt | MutableGlobals,
All = (1 << 26) - 1,
All = (1 << 27) - 1,
};

static std::string toString(Feature f) {
Expand Down Expand Up @@ -120,6 +121,8 @@ struct FeatureSet {
return "multibyte";
case WideArithmetic:
return "wide-arithmetic";
case CompactImports:
return "compact-imports";
case MVP:
case Default:
case All:
Expand Down Expand Up @@ -184,6 +187,7 @@ struct FeatureSet {
bool hasCustomPageSizes() const { return (features & CustomPageSizes) != 0; }
bool hasMultibyte() const { return (features & Multibyte) != 0; }
bool hasWideArithmetic() const { return (features & WideArithmetic) != 0; }
bool hasCompactImports() const { return (features & CompactImports) != 0; }
bool hasAll() const { return (features & All) != 0; }

void set(FeatureSet f, bool v = true) {
Expand Down Expand Up @@ -213,6 +217,7 @@ struct FeatureSet {
void setRelaxedAtomics(bool v = true) { set(RelaxedAtomics, v); }
void setMultibyte(bool v = true) { set(Multibyte, v); }
void setWideArithmetic(bool v = true) { set(WideArithmetic, v); }
void setCompactImports(bool v = true) { set(CompactImports, v); }
void setMVP() { features = MVP; }
void setAll() { features = All; }

Expand Down
Loading
Loading