-
Notifications
You must be signed in to change notification settings - Fork 825
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
Conversation
Snapshot1, | ||
} | ||
|
||
pub fn get_wasi_version(module: &Module) -> Option<WasiVersion> { |
There was a problem hiding this comment.
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.
6150fa6
to
3f2a84d
Compare
3f2a84d
to
f1e5cd3
Compare
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", |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
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).
lib/wasi/src/utils.rs
Outdated
.get(import_name.namespace_index); | ||
if namespace != "wasi_unstable" { | ||
return false; | ||
get_wasi_version(module) == Some(WasiVersion::Snapshot1) |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
bors r+ |
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 <mark@wasmer.io> Co-authored-by: Mark McCaskey <5770194+markmccaskey@users.noreply.github.com>
Build failed
|
bors try |
1 similar comment
bors try |
tryAlready running a review |
tryBuild failed |
…o/wasmer into feature/add-support-for-new-wasi
bors try |
tryBuild failed |
bors try |
tryBuild succeeded |
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 <ivan.enderlin@hoa-project.net>
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 <ivan.enderlin@hoa-project.net>
Review