Skip to content

Add Features enum to IR#1250

Merged
dschuff merged 4 commits intomasterfrom
features
Oct 27, 2017
Merged

Add Features enum to IR#1250
dschuff merged 4 commits intomasterfrom
features

Conversation

@dschuff
Copy link
Copy Markdown
Member

@dschuff dschuff commented Oct 26, 2017

This enum describes which wasm features the IR is expected to include. The
validator should reject operations which require excluded features, and passes
should avoid producing IR which requires excluded features.

This makes it easier to catch possible errors in Binaryen producers (e.g.
emscripten). Asm2wasm has a flag to enable or disable atomics. Other
tools currently just accept all features (as, dis and opt are just for
inspecting or modifying existing modules, so it would be annoying to have to use
flags with those tools and I expect the risk of accidentally introducing
atomics to be low).

This enum describes which wasm features the IR is expected to include. The
validator should reject operations which require excluded features, and passes
should avoid producing IR which requires excluded features.

This makes it easier to catch possible errors in Binaryen producers (e.g.
emscripten). Asm2wasm has a flag to enable or disable atomics. Other
tools currently just accept all features (as, dis and opt are just for
inspecting or modifying existing modules, so it would be annoying to have to use
flags with those tools and I expect the risk of accidentally introducing
atomics to be low).
Comment thread src/tools/asm2wasm.cpp Outdated
.add("--emit-text", "-S", "Emit text instead of binary for the output file",
Options::Arguments::Zero,
[&](Options *o, const std::string &argument) { emitBinary = false; })
.add("--enable-atomics", "-a", "Enable the Atomics wasm feature",
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.

I called the flag --enable-threads in wabt, probably worthwhile to be consistent.

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.

Yeah, sounds good.

Copy link
Copy Markdown
Member

@kripken kripken left a comment

Choose a reason for hiding this comment

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

For wasm-as etc., why not default the features to All?

Comment thread src/asm2wasm.h
@@ -1286,6 +1285,7 @@ void Asm2WasmBuilder::processAsm(Ref ast) {
};

PassRunner passRunner(&wasm);
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.

Can use the second passRunner constructor, which receives passOptions as a second param. That would copy in the features.

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.

Wouldn't that also copy in OptLevel and ShrinkLevel, which we don't want?

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.

Good point, yeah.

Comment thread src/pass.h
void setValidateGlobally(bool validate) {
options.validateGlobally = validate;
}
void setFeatures(FeatureSet features) {
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.

we don't strictly need this (can use the constructor as mentioned above, or also do getPassOptions().features = ) but I suppose this could be a useful convenience

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 figured we'd want to be able to set this without optLevel (see above)

Comment thread src/wasm.h Outdated

namespace wasm {

enum Features : uint32_t {
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.

32 bits should be enough for all the features? ;)

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.

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.

Then we wouldn't be able to bitwise or them together like Real C Programmers should.... although if they are going to have names, then generating them from a def file like that might make sense. Maybe an improvement for the future.

Comment thread src/wasm/wasm-validator.cpp Outdated

template <typename T, typename S>
std::ostream& fail(S text, T curr, Function* func) {
__builtin_trap();
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.

what is this?

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.

Debug break that I forgot to remove. Removed in
6f85f55

Comment thread src/wasm/wasm-validator.cpp Outdated
}

void FunctionValidator::visitLoad(Load *curr) {
shouldBeTrue(!curr->isAtomic || info.features & Features::Atomics, curr, "Atomic operation (atomics are disabled)");
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.

i personally think it's clearer to write if (curr->isAtomic) shouldBeTrue(..atomics feature enabled..)

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.

Me too, done.

Comment thread src/wasm.h Outdated

namespace wasm {

enum Features : uint32_t {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: Given we have Features and FeatureSet, would it make sense to call the enum of flags just Feature? Benefit would be that it would be clear that a variable named features is probably a FeatureSet

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.

Yeah, done.

Comment thread src/tools/optimization-options.h Outdated

std::vector<std::string> passes;
PassOptions passOptions;
Features features = Features::Atomics;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

FeatureSet features maybe?

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.

Yes, done.

…/store validation for readability, validate shared mem
@dschuff dschuff merged commit 2e51491 into master Oct 27, 2017
@dschuff dschuff deleted the features branch January 10, 2018 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants