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 support for new WASI snapshot, backwards compat too #957

Merged
merged 8 commits into from
Nov 22, 2019

Conversation

MarkMcCaskey
Copy link
Contributor

@MarkMcCaskey MarkMcCaskey commented Nov 12, 2019

Review

  • Add a short description of the the change to the CHANGELOG.md file

@MarkMcCaskey MarkMcCaskey added the 📦 lib-wasi About wasmer-wasi label Nov 12, 2019
Cargo.toml Outdated Show resolved Hide resolved
Snapshot1,
}

pub fn get_wasi_version(module: &Module) -> Option<WasiVersion> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please rustdoc the public functions/types or suppress with doc hidden.

@MarkMcCaskey MarkMcCaskey force-pushed the feature/add-support-for-new-wasi branch from 6150fa6 to 3f2a84d Compare November 12, 2019 21:00
@MarkMcCaskey MarkMcCaskey force-pushed the feature/add-support-for-new-wasi branch from 3f2a84d to f1e5cd3 Compare November 12, 2019 21:01
Cargo.lock Outdated
@@ -1504,7 +1504,6 @@ dependencies = [
"tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"wabt 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)",
"wasmer-clif-backend 0.10.1",
"wasmer-llvm-backend 0.10.1",
Copy link
Member

Choose a reason for hiding this comment

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

Probably you don't want to commit this either


// returns None if empty
let first = import_iter.next()?;
if import_iter.all(|idx| idx == first) {
Copy link
Member

Choose a reason for hiding this comment

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

What is this .all(|idx| idx == first) doing?

Because Emscripten implements part of wasi (setting some of the imported functions as wasi_unstable), we need to check that all the imports have this namespace (not just one). That way we can differentiate Emscripten and WASI modules

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It checks that all namespaces have the same index, which I understood to be a faster way to check if they all share a namespace than looking up every one and doing string comparisons.

After it guarantees that they're all the same, it does logic on it. I can add comments to clarify this logic

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, it creates a bug. If the import namespaces are the following: wasi_unstable and env, we have 2 different namespaces, and get_wasi_version will return None. Working on a fix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Hywan as mentioned in #1028 , I think this is not a bug and that the behavior in #1028 is much closer to a bug because we'll start calling things which are not WASI (won't run with WASI imports) WASI and have no way to detect real WASI anymore.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it specified in the specification that, in case of WASI, all imports must land in the same namespace? I think it is very restrictive, and would be break some design (like blockchain or stuff like that that have special namespaces too).

.get(import_name.namespace_index);
if namespace != "wasi_unstable" {
return false;
get_wasi_version(module) == Some(WasiVersion::Snapshot1)
Copy link
Member

Choose a reason for hiding this comment

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

I would do it just .is_some() ? (both snapshot0 and snapshot1 are wasi modules)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking that I'd attempt to preserve more of the semantics of the function call; either way this is a breaking change -- I think you're right that it doesn't make sense to keep the function name as what it is and not have that behavior. I'll update it

@MarkMcCaskey
Copy link
Contributor Author

bors r+

bors bot added a commit that referenced this pull request Nov 13, 2019
957: Add support for new WASI snapshot, backwards compat too r=MarkMcCaskey a=MarkMcCaskey


# Review

- [x] Add a short description of the the change to the CHANGELOG.md file


Co-authored-by: Mark McCaskey <[email protected]>
Co-authored-by: Mark McCaskey <[email protected]>
@bors
Copy link
Contributor

bors bot commented Nov 13, 2019

Build failed

  • wasmerio.wasmer

@MarkMcCaskey
Copy link
Contributor Author

bors try

1 similar comment
@MarkMcCaskey
Copy link
Contributor Author

bors try

@bors
Copy link
Contributor

bors bot commented Nov 21, 2019

try

Already running a review

bors bot added a commit that referenced this pull request Nov 21, 2019
@bors
Copy link
Contributor

bors bot commented Nov 21, 2019

try

Build failed

@MarkMcCaskey
Copy link
Contributor Author

bors try

bors bot added a commit that referenced this pull request Nov 21, 2019
@bors
Copy link
Contributor

bors bot commented Nov 21, 2019

try

Build failed

@MarkMcCaskey
Copy link
Contributor Author

bors try

bors bot added a commit that referenced this pull request Nov 21, 2019
@bors
Copy link
Contributor

bors bot commented Nov 21, 2019

try

Build succeeded

@syrusakbary syrusakbary merged commit b9138aa into master Nov 22, 2019
@bors bors bot deleted the feature/add-support-for-new-wasi branch November 22, 2019 00:17
bors bot added a commit that referenced this pull request Dec 6, 2019
1028: feat(wasi) Introduce strict/non-strict modes for `get_wasi_version` r=Hywan a=Hywan

Sequel of #957.

If a module has multiple import namespaces, `get_wasi_version` is
broken because it assumes a module must only have a single namespace.

This patch updates `get_wasi_version` to introduce a `strict` flag:

* In strict mode, the previous behavior applies; only one namespace is expected to be found, and this namespace must be a WASI namespace to detect the version,
* In non-strict mode, at least one WASI namespace must be declared, and the first one is used to detect the version if any.

The non-strict mode is slower because it compares namespace strings.

2 new private constants have been declared: `SNAPSHOT0_NAMESPACE` and `SNAPSHOT1_NAMESPACE` to avoid repetition and bugs.

Co-authored-by: Ivan Enderlin <[email protected]>
bors bot added a commit that referenced this pull request Dec 6, 2019
1028: feat(wasi) Introduce strict/non-strict modes for `get_wasi_version` r=Hywan a=Hywan

Sequel of #957.

If a module has multiple import namespaces, `get_wasi_version` is
broken because it assumes a module must only have a single namespace.

This patch updates `get_wasi_version` to introduce a `strict` flag:

* In strict mode, the previous behavior applies; only one namespace is expected to be found, and this namespace must be a WASI namespace to detect the version,
* In non-strict mode, at least one WASI namespace must be declared, and the first one is used to detect the version if any.

The non-strict mode is slower because it compares namespace strings.

2 new private constants have been declared: `SNAPSHOT0_NAMESPACE` and `SNAPSHOT1_NAMESPACE` to avoid repetition and bugs.

Co-authored-by: Ivan Enderlin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
📦 lib-wasi About wasmer-wasi
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants