Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bulk-memory-opt feature and ignore call-indirect-overlong #7139

Merged
merged 13 commits into from
Dec 6, 2024

Conversation

dschuff
Copy link
Member

@dschuff dschuff commented Dec 5, 2024

LLVM recently split the bulk-memory-opt feature out from bulk-memory,
containing just memory.copy and memory.fill. This change follows that,
making bulk-memory-opt also enabled when all of bulk-memory is enabled.

It also introduces call-indirect-overlong following LLVM, but ignores
it, since Binaryen has always allowed the encoding (i.e. command
line flags enabling or disabling the feature are accepted but
ignored).

LLVM recently split the bulk-memory-opt feature out from bulk-memory,
containing just memory.copy and memory.fill. This change follows that,
making bulk-memory-opt also enabled when all of bulk-memory is enabled.

It also introduces call-indirect-overlong following LLVM, but ignores
it, since Binaryen has always allowed the encoding (i.e. command
line flags enabling or disabling the feature are accepted but
ignored).
@dschuff dschuff requested review from kripken and tlively December 5, 2024 23:35
// This features is a no-op for compatibility. Having it in this list means
// that we can automatically generate tool flags that set it, but otherwise
// it does nothing. Binaryen always accepts LEB call-indirect encodings.
CallIndirectOverlong = 1 << 20,
Copy link
Member

Choose a reason for hiding this comment

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

Please link to the tool-conventions doc that explains what these are, as all the other features are easily found on the main wasm website, but not these.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually these are missing from the tool-conventions doc, we should fix that.

Copy link
Member Author

Choose a reason for hiding this comment

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

src/wasm-features.h Outdated Show resolved Hide resolved
src/wasm-features.h Outdated Show resolved Hide resolved
src/wasm/wasm-validator.cpp Outdated Show resolved Hide resolved
Copy link
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 (can add the link later if landing this is urgent)

@dschuff
Copy link
Member Author

dschuff commented Dec 6, 2024

I can just add a link to the section: https://github.com/WebAssembly/tool-conventions/blob/main/Linking.md#target-features-section

Comment on lines 231 to 234
if (enabledFeatures & FeatureSet::BulkMemory) {
// Enable this subfeature for backward compatibility.
module.features.enable(FeatureSet::BulkMemoryOpt);
}
Copy link
Member

Choose a reason for hiding this comment

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

We don't have a precedent for making features depend on other features, but it makes sense here, I think. Should we also disable BulkMemoryOpt when BulkMemory is disabled for symmetry?

Copy link
Member Author

Choose a reason for hiding this comment

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

Funny you should mention the dependence, I just had to fix a bug that I introduced in a late refactoring, and it's here. PTAL the current version; I think applyOptionsBeforeParse isn't actually the right place to do this (because it's const and we can't actually change enabledFeatures). But fixing that meant making parse virtual so that there would be a place that made sense.
Currently we maintain the invariant that we assert in hasBulkMemoryOpt, that bulk-memory-opt is always on when build-memory is on. It makes sense to allow bulk-memory-opt to be on with bulk-memory off though. Although for command-line compatibility, maybe there's an expectation that --disable-bulk-memory should also diable --bulk-memory-opt? (which would presumably matter only when they become default)?

src/wasm/wasm-binary.cpp Outdated Show resolved Hide resolved
Comment on lines 247 to 251
if (enabledFeatures & FeatureSet::BulkMemory) {
// Enable this subfeature for backward compatibility.
enabledFeatures.setBulkMemoryOpt();
disabledFeatures.setBulkMemoryOpt(false);
}
Copy link
Member

Choose a reason for hiding this comment

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

If we'd rather not do this as part of parsing, we could also implement this feature implication in the parsing of the --enable-bulk-memory and --disable-bulk-memory flags themselves. Giving addFeature an optional parameter that is a list of implied features would be nice.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sounds good, done.

.addFeature(FeatureSet::BulkMemoryOpt,
"memory.copy and memory.fill",
FeatureSet::None,
FeatureSet(FeatureSet::BulkMemoryOpt))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
FeatureSet(FeatureSet::BulkMemoryOpt))
FeatureSet(FeatureSet::BulkMemory))

Is this the intended behavior?

Copy link
Member Author

Choose a reason for hiding this comment

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

Er yes, done.

FeatureSet::None,
FeatureSet(FeatureSet::BulkMemoryOpt))
.addFeature(FeatureSet::CallIndirectOverlong,
"(ignored for compatibility)")
Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should write a little more here so the help message isn't "Enable (ignored for compatibility)" 😆

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, yeah it's a little unfortunate that the "Enable" and "Disable" bits are generated separately... how about "Enable call-indirect-overlong (ignored for compatibility as this has no effect on Binaryen)" with the idea that call-indirect-overlong can now be looked up in tool-conventions along with the rest?

Copy link
Member

Choose a reason for hiding this comment

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

sgtm 👍

@dschuff dschuff enabled auto-merge (squash) December 6, 2024 19:53
@dschuff dschuff merged commit 729ea41 into main Dec 6, 2024
13 checks passed
@dschuff dschuff deleted the bulk-memory-opt branch December 6, 2024 20:34
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.

3 participants