Skip to content

Add WASI abort, trace and seed implementations #1159

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

Merged
merged 16 commits into from
Mar 13, 2020
Merged

Add WASI abort, trace and seed implementations #1159

merged 16 commits into from
Mar 13, 2020

Conversation

dcodeIO
Copy link
Member

@dcodeIO dcodeIO commented Mar 11, 2020

Terrible implementations of abort and trace specifically for WASI that are as minimal and robust as it gets (allocation would be especially evil in abort if the abort originates in MM/GC).

Output format is:

abort: MESSAGE in FILE(LINE:COLUMN)
trace: MESSAGE[ $0[ $1[ $2[ $3[ $4]]]]]

Also implements seed, which is a new API for seeding Math.random. Now happens automatically in WASI environments, and requires an import env.seed in other environments.

Presence of the WASI bindings is automatically detected. Usage is:

import "wasi"; // anywhere in your own or one of your dependency's code

with each of the APIs being overridable with --use just as before (with or without WASI being present).

@dcodeIO
Copy link
Member Author

dcodeIO commented Mar 12, 2020

Alright, it now also supports UTF8 and can auto-detect the presence of the WASI bindings. New usage is:

import "wasi"; // anywhere in your code

As soon as the WASI bindings are used, the non-standard fallback abort handler is automatically replaced with WASI's.

@MaxGraey
Copy link
Member

It could be great do same auto-detection for seedRandom: #1080 as well. wdyt?

@dcodeIO dcodeIO changed the title Add a WASI abort implementation Add a WASI abort, trace and seed implementations Mar 12, 2020
@dcodeIO
Copy link
Member Author

dcodeIO commented Mar 12, 2020

This now not only implements abort but also, trace and seed. The latter is new and a potential breaking change superseding #1080. Instead of adding configuration options, the seed function is provided by the WASI bindings respectively imported as env.seed, returning an f64. It's still possible to call NativeMath.seedRandom with this, but the import must always be present if random is used. Similar to abort, this one can also be overridden via --use seed=assembly/index/mySeed.

@dcodeIO dcodeIO changed the title Add a WASI abort, trace and seed implementations Add WASI abort, trace and seed implementations Mar 12, 2020
@dcodeIO
Copy link
Member Author

dcodeIO commented Mar 12, 2020

Also verified that the tests "just work" in a few actual headless Wasm VMs, but I guess we'll want something to do that as part of the test suite eventually. Tried Wasmtime and Wasmer, which both seem very similar.

@dcodeIO dcodeIO requested a review from MaxGraey March 13, 2020 17:43
Copy link
Contributor

@torch2424 torch2424 left a comment

Choose a reason for hiding this comment

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

Thank you sooooooo much for this! 🙏 😄

I think this is going to make WASI like 1000x easier to get started with in my opinion 😄 Especially once we update as-wasi on top of this 😄 👍

@@ -0,0 +1,5 @@
import "wasi";
Copy link
Contributor

Choose a reason for hiding this comment

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

Wooooaaaahhh this is soooo cool! 💥 🎉

Thank you so much for this, it's like 1000x cooler than what I was suggesting haha! 😄

return reinterpret<f64>(rand);
}

export * from "bindings/wasi";
Copy link
Contributor

Choose a reason for hiding this comment

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

With the import "wasi" syntax. Does this automatically provide all of the bindings, without having to import them individually?

And I assume current projects can just keep importing them individually right? 😄 This is such a great solution 😄

Copy link
Member Author

@dcodeIO dcodeIO Mar 13, 2020

Choose a reason for hiding this comment

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

Yes, one can either enable all this stuff including stdlib-provided implementations abort/trace/seed by import "wasi" or use the bindings with custom implementations and command line options (similar to before, import "bindings/wasi"), with the former implying (and re-exporting) the latter.

Copy link
Member Author

Choose a reason for hiding this comment

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

In case this didn't exactly answer the question: import * as wasi from "wasi" is what one would do to also have all the bindings at their fingertips :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh that's perfect! Thank you! 😄 👍

@jedisct1
Copy link

That's a very nice improvement!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants