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

Feature request: test-local variables in .wast #1586

Open
titzer opened this issue Feb 6, 2023 · 3 comments
Open

Feature request: test-local variables in .wast #1586

titzer opened this issue Feb 6, 2023 · 3 comments

Comments

@titzer
Copy link
Contributor

titzer commented Feb 6, 2023

In a CG call a few weeks back, I mentioned that having the ability to have test-local variables in .wast files would be useful.

In particular, many tests that use reference types, mostly in proposals right now (such as function-references and gc use tables internal to a module and an initializer. These tests would be shorter, easier to write, and easier to debug (a key productivity boost for engine implementers) if the test itself could bind variables.

Exact details of syntax and semantics TBD.

Sketch:

(module
  (func "create_ref1" (result anyref))
  ...
  (func "take_ref" (param anyref) (result i32))
)

(test-local $ref1 anyref (invoke "create_ref1"))

(assert_return (invoke "take_ref" (test-local.get $ref1)) (i32.const 11))

That would remove the need for tables, but the issue of needing to create objects/functions inside a module (because types and decls live in modules) remains.

@tlively
Copy link
Member

tlively commented Feb 6, 2023

I agree writing tests in terms of table indices makes them hard to understand and modify. Would using exported globals give a similar DevX? I suppose that you can't initialize an exported global with the result of a function call, but maybe it would be ok to keep the init() function pattern the test currently use.

@rossberg
Copy link
Member

rossberg commented Feb 6, 2023

I was about to suggest the same -- fwiw, the wast script language already has a (get "name") action for accessing exported globals.

There is a gap though, namely, that invoke can only take constants as arguments. I think what we need first and foremost is to beef up the syntax of these script "actions" and turn them into a tiny expression language of nested calls and global reads.

In addition, we could introduce new forms of top-level definitions, like @titzer suggests. However, that is inherently limited by the inability to refer to types, not having arbitrary instructions, etc.. So the added value over module globals is likely small.

@titzer
Copy link
Contributor Author

titzer commented Feb 7, 2023

I'm also fine with using globals as arguments to invoke as a first step.

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

No branches or pull requests

3 participants