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 @@ -508,6 +508,9 @@ BinaryenFeatures BinaryenFeatureMultibyte(void) {
BinaryenFeatures BinaryenFeatureCustomPageSizes(void) {
return static_cast<BinaryenFeatures>(FeatureSet::CustomPageSizes);
}
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 @@ -246,6 +246,7 @@ BINARYEN_API BinaryenFeatures BinaryenFeatureCallIndirectOverlong(void);
BINARYEN_API BinaryenFeatures BinaryenFeatureRelaxedAtomics(void);
BINARYEN_API BinaryenFeatures BinaryenFeatureMultibyte(void);
BINARYEN_API BinaryenFeatures BinaryenFeatureCustomPageSizes(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 @@ -194,6 +194,7 @@ function initializeConstants() {
'CallIndirectOverlong',
'RelaxedAtomics',
'CustomPageSizes',
'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 @@ -112,6 +112,7 @@ struct ToolOptions : public Options {
.addFeature(FeatureSet::RelaxedAtomics,
"acquire/release atomic memory operations")
.addFeature(FeatureSet::CustomPageSizes, "custom page sizes")
.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 @@ -471,6 +471,7 @@ extern const char* CustomDescriptorsFeature;
extern const char* RelaxedAtomicsFeature;
extern const char* MultibyteFeature;
extern const char* CustomPageSizesFeature;
extern const char* CompactImportsFeature;

enum Subsection {
NameModule = 0,
Expand Down Expand Up @@ -1663,6 +1664,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 +1667 to +1672
Copy link
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
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
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
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
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
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 @@ -58,11 +58,12 @@ struct FeatureSet {
RelaxedAtomics = 1 << 22,
CustomPageSizes = 1 << 23,
Multibyte = 1 << 24,
CompactImports = 1 << 25,
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 << 25) - 1,
All = (1 << 26) - 1,
};

static std::string toString(Feature f) {
Expand Down Expand Up @@ -117,6 +118,8 @@ struct FeatureSet {
return "custom-page-sizes";
case Multibyte:
return "multibyte";
case CompactImports:
return "compact-imports";
case MVP:
case Default:
case All:
Expand Down Expand Up @@ -180,6 +183,7 @@ struct FeatureSet {
bool hasRelaxedAtomics() const { return (features & RelaxedAtomics) != 0; }
bool hasCustomPageSizes() const { return (features & CustomPageSizes) != 0; }
bool hasMultibyte() const { return (features & Multibyte) != 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 @@ -208,6 +212,7 @@ struct FeatureSet {
void setCustomDescriptors(bool v = true) { set(CustomDescriptors, v); }
void setRelaxedAtomics(bool v = true) { set(RelaxedAtomics, v); }
void setMultibyte(bool v = true) { set(Multibyte, v); }
void setCompactImports(bool v = true) { set(CompactImports, v); }
void setMVP() { features = MVP; }
void setAll() { features = All; }

Expand Down
Loading
Loading