Skip to content

Change default feature set to MVP#1993

Merged
tlively merged 15 commits intoWebAssembly:masterfrom
tlively:features-refactor
Apr 16, 2019
Merged

Change default feature set to MVP#1993
tlively merged 15 commits intoWebAssembly:masterfrom
tlively:features-refactor

Conversation

@tlively
Copy link
Copy Markdown
Member

@tlively tlively commented Apr 9, 2019

This greatly simplifies the feature handling logic and does not
change the user experience when a target features section is present.
Also refactors features to be stored on the Module after they are read
out of the target features section, allowing us to emit a (potentially
modified) target features section and conditionally emit sections
based on features, such as the DataCount section.

This greatly simplifies the feature handling logic and does not
change the user experience when a target features section is present.
Also refactors features to be stored on the Module after they are read
out of the target features section, allowing us to emit a (potentially
modified) target features section and conditionally emit sections
based on features, such as the DataCount section.
@tlively tlively requested a review from kripken April 9, 2019 22:44
@@ -1 +1 @@
{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c","(unknown)"],"names":[],"mappings":"yLAIA,IACA,ICyylTA,aC7vlTA,OAkDA,0BCnGA,OACA,OACA,uBCAA,4BAKA,QAJA,OADA,8CAKA,0ICsi1DA,MCrvyDA"} No newline at end of file
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.

TBH I have no idea what this change means.

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 think it means that things moved around - the location of code is not the same as before. That's surprising, I think?

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.

Aha, this is because I changed the element section to only be emitted if it has any elements. That moved the code section up in the file.

Comment thread check.py Outdated
run_command(WASM_REDUCE + ['a.wasm', '--command=%s b.wasm --fuzz-exec' % WASM_OPT[0], '-t', 'b.wasm', '-w', 'c.wasm'])
after = os.stat('c.wasm').st_size
assert after < 0.6 * before, [before, after]
assert after < 0.7 * before, [before, after]
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 haven't really examined why this changed yet.

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 should definitely look into that before landing, yeah, since this PR should be NFC wrt this test?

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.

Nice, mostly lgtm, but some issues left for discussion first.

Comment thread check.py Outdated
run_command(WASM_REDUCE + ['a.wasm', '--command=%s b.wasm --fuzz-exec' % WASM_OPT[0], '-t', 'b.wasm', '-w', 'c.wasm'])
after = os.stat('c.wasm').st_size
assert after < 0.6 * before, [before, after]
assert after < 0.7 * before, [before, after]
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 should definitely look into that before landing, yeah, since this PR should be NFC wrt this test?

Comment thread src/passes/StripTargetFeatures.cpp Outdated
};

Pass *createStripTargetFeaturesPass() {
return new FeaturesStrip();
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.

why is the pass StripTargetFeatures and the instance FeaturesStrip? I think the convention we have is to keep them the same (i.e. both are the former).

Comment thread src/wasm.h Outdated
std::vector<std::string> debugInfoFileNames;

FeatureSet features = FeatureSet::MVP;
bool emitFeaturesSection = false;
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.

Perhaps we should handle the features section the same way we handle the names section - we read it if it's there, but we don't emit it unless the user specifically asks us to?

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.

Hmm, it would make sense to unify what we do with the features section and the names section (and the producers section? I forget what we do there). OTOH, it is very useful to preserve the features section through long chains of wasm-opt calls such as when running the reducer. Otherwise all but the first call of wasm-opt would have a validation failure.

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 believe we decided offline to leave this how it is for now but to leave this open for unification with how we treat other sections in the future.

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.

(and rename to hasFeaturesSection)

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.

Right, thank you.

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

void WasmBinaryWriter::writeFeaturesSection() {
if (!wasm->emitFeaturesSection || wasm->features <= FeatureSet{}) {
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.

does the right side of the if mean "if MVP, don't emit the features section"?

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, I forgot about the isMVP() method which I should definitely use here.

Comment thread src/wasm/wasm-binary.cpp
@@ -1 +1 @@
{"version":3,"sources":["tests/hello_world.c","tests/other_file.cpp","return.cpp","even-opted.cpp","fib.c","/tmp/emscripten_test_binaryen2_28hnAe/src.c","(unknown)"],"names":[],"mappings":"yLAIA,IACA,ICyylTA,aC7vlTA,OAkDA,0BCnGA,OACA,OACA,uBCAA,4BAKA,QAJA,OADA,8CAKA,0ICsi1DA,MCrvyDA"} No newline at end of file
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 think it means that things moved around - the location of code is not the same as before. That's surprising, I think?

@kripken
Copy link
Copy Markdown
Member

kripken commented Apr 11, 2019

Having to sprinkle -all everywhere (to tell it "all features are ok") worries me that it will be annoying in the day to day. How do other tools do this, like wabt? cc @binji

@tlively
Copy link
Copy Markdown
Member Author

tlively commented Apr 11, 2019

I believe WABT simply enables all features all the time (AFAIK it doesn't have any feature options). This makes sense for tools that read but do not modify modules and is what we do for wasm-as and wasm-dis. Tools that can modify modules need to know what features they are allowed to use, and it seems best to be conservative about that.

That being said, we probably do have more -all sprinkled around than would be optimal. In check.py there is one instance where we pass -all to wasm-shell. wasm-shell should be changed to assume -all. But all other instances of -all are passed to wasm-opt, which I think makes sense.

tlively added 3 commits April 16, 2019 14:52
Also:

 - Error when target features do not exactly match feature options
 - Add --print-features pass and use it in testing
@tlively
Copy link
Copy Markdown
Member Author

tlively commented Apr 16, 2019

@kripken PTAL. This PR move towards implementing the plan described in #2004. I also expect this to fix current waterfall breakage, though I have not finished testing locally.

  • MVP is the default feature set.
  • When there is a target features section and no command line feature flags, the features section is used
  • When there is a target features section and there are command line feature flags, error if they do not exactly match, unless --detect-features was one of the feature flags.
  • --detect-features sets the current feature set equal to the contents of the target features section

There is not yet a way to crawl a binary and detect what features it uses.

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.

lgtm with those comments fixed

Comment thread src/tools/wasm-reduce.cpp
Module wasm;
ModuleReader reader;
reader.read(working, *module);
wasm.features = FeatureSet::All;
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'm not sure this is optimal - it might lead the optimizer to attempt odd things that hurt reduction. Please add a comment that we should likely autodetect features from the binary here instead, once we can do that.

Comment thread src/tools/wasm-reduce.cpp
{
// read and write it
auto cmd = Path::getBinaryenBinaryTool("wasm-opt") + " " + input + " -o " + test;
auto cmd = Path::getBinaryenBinaryTool("wasm-opt") + " " + input + " -all -o " + test;
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.

same issue

Comment thread src/wasm/wasm-binary.cpp Outdated
if (debug) std::cerr << "getInt8: " << (int)(uint8_t)input[pos] << " (at " << pos << ")" << std::endl;
return input[pos++];
if (debug) std::cerr << "getInt8: " << (int)(uint8_t)input.at(pos) << " (at " << pos << ")" << std::endl;
return input.at(pos++);
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.

why is this change here? seems offtopic for the PR; also we already have a check right above it that throws an error.

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.

Right, sorry. My reverting of this change in #2001 was not backported to this branch. Fixing.

Comment thread CHANGELOG.md Outdated
- Add `segmentPassive` argument to `BinaryenSetMemory` for marking segments
passive.
- Make `-o -` print to stdout instead of a file named "-".
- Change default feature set in the absence of a target features section from
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.

This should go up above in Current Trunk

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.

Thanks.

Comment thread test/unit/utils.py Outdated
testcase.assertEqual(str(p.stdout), str(f.read()))


def disassemble(self, filename):
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.

Surely these should be left as members? They take self as arg0 after all.

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, but I want to share them across multiple unittest.TestCase subclasses. I suppose the proper way to do that would be to make all my test cases inherit from a new class that contains these methods.

@tlively tlively merged commit 4d81752 into WebAssembly:master Apr 16, 2019
@binji
Copy link
Copy Markdown
Member

binji commented Apr 17, 2019

Having to sprinkle -all everywhere (to tell it "all features are ok") worries me that it will be annoying in the day to day. How do other tools do this, like wabt? cc @binji

I believe WABT simply enables all features all the time (AFAIK it doesn't have any feature options).

Sorry, missed this. Wabt does have feature flags for all tools. But wasm-objdump enables all features by default.

tlively added a commit to tlively/binaryen that referenced this pull request Apr 18, 2019
This reverts commit cb2d635.
The issues with feature validation were mostly resolved in WebAssembly#1993, and
this PR finishes the job by adding feature flags to wasm-as to avoid
emitting the DataCount section when bulk-memory is not enabled.
tlively added a commit that referenced this pull request Apr 18, 2019
This reverts commit cb2d635.
The issues with feature validation were mostly resolved in #1993, and
this PR finishes the job by adding feature flags to wasm-as to avoid
emitting the DataCount section when bulk-memory is not enabled.
@tlively tlively deleted the features-refactor branch April 24, 2020 23:15
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