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

feat(wasi) Introduce strict/non-strict modes for get_wasi_version #1028

Merged
merged 9 commits into from
Dec 6, 2019

Conversation

Hywan
Copy link
Contributor

@Hywan Hywan commented Dec 2, 2019

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.

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 fixes it by a slower `get_wasi_version` function, but a
correct one. As soon as the `wasi_unstable` or
`wasi_snapshot_preview1` namespace is met, `get_wasi_version` maps it
to the respective `WasiVersion` variant. It assumes however that a
module must hold a unique WASI version.
@Hywan Hywan added bug Something isn't working 📦 lib-wasi About wasmer-wasi labels Dec 2, 2019
@Hywan
Copy link
Contributor Author

Hywan commented Dec 2, 2019

bors try

@bors
Copy link
Contributor

bors bot commented Dec 2, 2019

try

Timed out

Copy link
Contributor

@MarkMcCaskey MarkMcCaskey left a comment

Choose a reason for hiding this comment

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

Syrus and I talked about a more complete solution for this using an upgraded version of Wasm interfaces https://github.com/wasmerio/wapm-cli/tree/master/lib/wasm-interface ; I think that's the way to go here:

The problem is that Emscripten contains some WASI functions now and this function is used by the Wasmer CLI tool to find out which import object will run the code -- if it contains extra imports, then it won't actually run.

I'll prioritize getting an MVP on this; perhaps it's fine to ship this as-is or to make another function that does this logic under a new name.

I'm going to approve the PR so I don't block you, but I'm not sure if this PR should be shipped as-is.

@MarkMcCaskey
Copy link
Contributor

I think the best path forward is to expose functions for partial and complete detection, or have a boolean for strict vs not-strict mode. We can then put the solution we come up with later underneath that API

@Hywan
Copy link
Contributor Author

Hywan commented Dec 4, 2019

I think a strict mode is a good idea. Gonna update the PR.

In strict mode, `get_wasi_version` uses the previous behavior, i.e. it
checks that there is only one namespace for all imports, and that this
namespace is a WASI namespace (and uses it to find the WASI version).

In non-strict mode, `get_wasi_version` checks that at least one WASI
namespace exists (and uses it to find the WASI version).

By default, `is_wasi_module` uses the non-strict mode.
@Hywan Hywan changed the title fix(wasi) get_wasi_version is broken with multiple namespaces feat(wasi) Introduce strict/non-strict modes for get_wasi_version Dec 4, 2019
@Hywan
Copy link
Contributor Author

Hywan commented Dec 4, 2019

@MarkMcCaskey Is it good to merge?

Copy link
Contributor

@MarkMcCaskey MarkMcCaskey left a comment

Choose a reason for hiding this comment

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

Looks good! Sorry I missed the notification for this yesterday!

the "single namespace" logic and documentation will change with the release of the next WASI version with modularity, but hopefully by then we have a simpler way of detecting this. Thinking about it now, the current detection isn't very precise

@Hywan
Copy link
Contributor Author

Hywan commented Dec 6, 2019

bors r+

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 <ivan.enderlin@hoa-project.net>
@bors
Copy link
Contributor

bors bot commented Dec 6, 2019

Canceled

@Hywan
Copy link
Contributor Author

Hywan commented Dec 6, 2019

bors r+

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 <ivan.enderlin@hoa-project.net>
@bors
Copy link
Contributor

bors bot commented Dec 6, 2019

Build succeeded

@bors bors bot merged commit 8aa49f5 into wasmerio:master Dec 6, 2019
bors bot added a commit that referenced this pull request Dec 6, 2019
1030: feat(runtime-c-api) Ability to generate `ImportObject` for a specific WASI version r=Hywan a=Hywan

❗️⚠️ Contains #1028, must be merged before this one.

This patch introduces 2 new functions:

* `wasmer_wasi_generate_import_object_for_version` and
* `wasmer_wasi_get_version`.

It mimics the current API provided by `wasmer_wasi`, nothing fancy
here. It's just a regular port to C/C++.

Because `wasmer_wasi::get_wasi_version` returns an option, and in
order to simplify the C/C++ API, `wasmer_wasi_get_version` can return
`Version::Unknown` in case of an error. It's up to the user to check
the version is valid (i.e. not unknown).

To see only the changes provided by this PR (excluding #1028), check Hywan/wasmer@fix-wasi-get-version...feat-runtime-c-api-wasi-version.

Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
bors bot added a commit to wasmerio/wasmer-go that referenced this pull request Jan 7, 2020
92: feat(wasi) Support `WasiGetVersion` & other `*ForVersion` WASI API r=Hywan a=Hywan

Fix #90.
Fix #77.

⚠️ Depends on wasmerio/wasmer#1028, wasmerio/wasmer#1029, and wasmerio/wasmer#1030. They must be merged before merging this PR! Marking this PR as a draft to be sure (the shared libraries must be updated too).

This patch updates `bridge.go` and `wasmer.h` to support the new `wasmer_wasi_generate_import_object_for_version` and `wasmer_wasi_get_version` functions.

After that, this patch updates `wasi.go` to implement the new `NewDefaultWasiImportObjectForVersion`, `NewWasiImportObjectForVersion` and the `WasiGetVersion` functions. In addition to that, we create a new `WasiVersion` type.

Finally, this patch updates the tests to test this new API. And it works like a charm 👌.

Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
bors bot added a commit to wasmerio/wasmer-go that referenced this pull request Jan 8, 2020
92: feat(wasi) Support `WasiGetVersion` & other `*ForVersion` WASI API r=Hywan a=Hywan

Fix #90.
Fix #77.

⚠️ Depends on wasmerio/wasmer#1028, wasmerio/wasmer#1029, and wasmerio/wasmer#1030. They must be merged before merging this PR! Marking this PR as a draft to be sure (the shared libraries must be updated too).

This patch updates `bridge.go` and `wasmer.h` to support the new `wasmer_wasi_generate_import_object_for_version` and `wasmer_wasi_get_version` functions.

After that, this patch updates `wasi.go` to implement the new `NewDefaultWasiImportObjectForVersion`, `NewWasiImportObjectForVersion` and the `WasiGetVersion` functions. In addition to that, we create a new `WasiVersion` type.

Finally, this patch updates the tests to test this new API. And it works like a charm 👌.

Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
bors bot added a commit to wasmerio/wasmer-go that referenced this pull request Jan 15, 2020
92: feat(wasi) Support `WasiGetVersion` & other `*ForVersion` WASI API r=Hywan a=Hywan

Fix #90.
Fix #77.

⚠️ Depends on wasmerio/wasmer#1028, wasmerio/wasmer#1029, and wasmerio/wasmer#1030. They must be merged before merging this PR! Marking this PR as a draft to be sure (the shared libraries must be updated too).

This patch updates `bridge.go` and `wasmer.h` to support the new `wasmer_wasi_generate_import_object_for_version` and `wasmer_wasi_get_version` functions.

After that, this patch updates `wasi.go` to implement the new `NewDefaultWasiImportObjectForVersion`, `NewWasiImportObjectForVersion` and the `WasiGetVersion` functions. In addition to that, we create a new `WasiVersion` type.

Finally, this patch updates the tests to test this new API. And it works like a charm 👌.

Co-authored-by: Ivan Enderlin <ivan.enderlin@hoa-project.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 📦 lib-wasi About wasmer-wasi
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants