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 mechanism for displaying the WAT signatures of WASI modules #377

Closed
wants to merge 1 commit into from

Conversation

abrown
Copy link
Contributor

@abrown abrown commented Jan 20, 2021

@pchickey, here are the beginnings of an idea for displaying signatures of WITX interfaces. What I need is some way to easily determine what WASI modules will look like after the WITX is translated away. I felt like WAT was a good format for this, though ideally I would want to generate the same type of information in other languages (e.g. as C headers or AssemblyScript declarations).

Currently, when I run cargo run --example witx -- wat-signature ../../phases/ephemeral/witx/wasi_ephemeral_nn.witx, this PR outputs something like the following:

(module
 (import "wasi_ephemeral_nn" "load" (func (param I32 I32 I32 I32 I32) (result I32)))
 (import "wasi_ephemeral_nn" "init_execution_context" (func (param I32 I32) (result I32)))
 ...
)

I am seeking feedback on whether this type of helper command is useful to others before I invest more time to fix it up (e.g. use a proper WAT library, add comments, fix type casing, etc.).

Copy link
Contributor

@pchickey pchickey left a comment

Choose a reason for hiding this comment

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

This looks useful and I'm glad that its a very compact and easy thing to implement so far. I don't have a strong opinion about whether it should use a library to help render it - the current witx sexpr-rendering code does not, and probably should. Thank you for doing this!

@abrown
Copy link
Contributor Author

abrown commented Jan 27, 2021

the current witx sexpr-rendering code does not, and probably should

Is this the ideal way to proceed? E.g. I see that SExpr implements Display--should I build up an sexpr for each signature and print those?

@pchickey
Copy link
Contributor

That is the "good enough" solution I got working, but its still a pretty unpleasant output for a human to read because it doesn't try to put line breaks or whitespace in sensible places.

@alexcrichton are you aware of any s-expr pretty printing libraries we could use?

@alexcrichton
Copy link
Contributor

Nah unfortunately not that I'm aware of :(

Crates like wasmprinter just hand-roll their own management of indentation levels and such.

@abrown
Copy link
Contributor Author

abrown commented May 20, 2021

As discussed in today's WASI meeting (cc: @sunfishcode, @lukewagner), if/once WebAssembly/interface-types#132 is merged then this PR should be replaced by some tooling to do some form of "WITX-> WIT" conversion (i.e. generating an official core-wasm signature for the high-level WITX).

@sunfishcode
Copy link
Member

Since this PR was filed, a lot has changed. Using wasm-tools, the signature of a component can now be printed using wasm-tools component wit.

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.

4 participants