Skip to content

features.json: Add w2c2 runtime - #580

Merged
tomayac merged 2 commits into
WebAssembly:mainfrom
turbolent:add-w2c2
Nov 2, 2026
Merged

tomayac merged 2 commits into
WebAssembly:mainfrom
turbolent:add-w2c2

Conversation

@turbolent

Copy link
Copy Markdown
Contributor

No description provided.

@tomayac tomayac left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just missing a logo, but otherwise looks good. Please check if the quite detailed logo (w2c2.svg) works in this context.

Comment thread features.json Resolved

@tomayac tomayac left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, thank you

(Drive-by comment: Maybe a good opportunity to simplify the logo and just make it the Wasm logo in front of the four direction arrows, so it looks less like a book.)

@tomayac
tomayac merged commit 128c381 into WebAssembly:main Nov 2, 2026
@turbolent

Copy link
Copy Markdown
Contributor Author

Yeah, I'll add a smaller logo upstream and open another PR here soon.

so it looks less like a book

It's supposed to be a software box, inspired by e.g. these https://www.reddit.com/r/VintageApple/comments/k4yji8/apple_software_box_gallery_mid1990s_love_the/

@keithw

keithw commented Nov 2, 2026

Copy link
Copy Markdown
Member

w2c2 is a great piece of software, but should we distinguish somewhere between the Wasm runtimes that implement the language semantics vs. ones (like w2c2 but not only w2c2) that diverge from it for performance or other reasons? E.g. my understanding had been that w2c2 doesn't have deterministic traps on memory OOB (e.g. when compiled through an optimizing C compiler), and by default (but can be turned on by the user) skips various runtime traps (e.g. memory load/store OOB, call_indirect type mismatch).I should be clear that (per Shravan Narayan's talk at the last CG meeting research day) it sounds like several engines (not just w2c2) have some of these properties.

@turbolent

Copy link
Copy Markdown
Contributor Author

I don't know if this is the right place to discuss it, but I want to at least correct this false statement:

my understanding had been that w2c2 doesn't have deterministic traps on memory OOB

Deterministic memory-OOB traps are supported, but disabled by default, like other run-time traps.

The "default use-case" for w2c2 is translating modules that are assumed to behave correctly and not exercise such run-time traps. It can support modules that do exercise run-time traps and add run-time checks, it's just not the default.

I don't see why it would be useful to distinguish that, but feel free to do so. I just hope it is not shown with a negative indicator.

@turbolent
turbolent deleted the add-w2c2 branch November 3, 2026 04:45
@keithw

keithw commented Nov 3, 2026

Copy link
Copy Markdown
Member

Deterministic memory-OOB traps are supported, but disabled by default, like other run-time traps.

Hmm, I don't think so -- are you running the testsuite with the same optimizer flags you use for performance measurements (and do the tests pass)? I'm looking at the generated output and there doesn't seem to be anything protecting the W2C2_MEMCPY from being optimized out by the C compiler (if the rest of the function is invariant to the result). See https://youtu.be/meSkbrFFbe8 for a broader discussion of this.

@keithw

keithw commented Nov 3, 2026

Copy link
Copy Markdown
Member

I should probably say, I've worked on wasm2c in the past and this has been a vexing and annoying issue, so I hope my comments are received in the spirit intended -- w2c2 is great.

@turbolent

Copy link
Copy Markdown
Contributor Author

@keithw Again, I don't think this PR is the right place to have a discussion about that.

If you have constructive feedback for w2c2, I'd appreciate an issue: https://github.com/turbolent/w2c2/issues/new

I hope my comments are received in the spirit intended

I'm not getting a positive/constructive one if that's what you intended: Jumping in to ask if flaws can be pointed out in an overview isn't. Especially also after you've previously made dismissive comments like at WebAssembly/wabt#2289 (comment)

@keithw

keithw commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

Hey, I'm sorry to hear that. For a PR to list w2c2 among the WebAssembly engines, it seemed reasonable and in-scope to ask if w2c2 is really implementing WebAssembly. I had understood w2c2's intent to be otherwise (e.g. diverging from the strict semantics, and in particular the deterministic traps, to gain performance) and didn't mean my comments to be dismissive. If you are really trying to implement the full WebAssembly semantics, I think w2c2's test runner will need to start doing something for assert_trap (even if the test script doesn't use register), and then if you run something like this through an optimizing compiler I don't think it will pass currently:

(module
  (memory 0)
  (func (export "f") (drop (i32.load (i32.const 0))))
)
(assert_trap (invoke "f") "out of bounds memory access")

If you want issues for this, I can make them if you really want.

@turbolent

Copy link
Copy Markdown
Contributor Author

I had understood w2c2's intent to be otherwise

Maybe check/ask before assuming? Through this PR I was also trying to show that w2c2 is spec compliant.
Again, if you think w2c2 is not spec compliant yet, then please report issues, instead of assuming the project aims to not be spec compliant, and please also verify your claims before reporting issues (no "I don't think it will pass").

if you run something like this through an optimizing compiler I don't think it will pass currently:

(module
  (memory 0)
  (func (export "f") (drop (i32.load (i32.const 0))))
)
(assert_trap (invoke "f") "out of bounds memory access")

Do you ever check your accusations before you post them?

I ran your exact example with W2C2_RUNTIME_CHECKS=1 using Clang 17 and GCC 15.2, at -O0, -O2, -O3, and -O3 -flto. It traps correctly in every configuration. The compiler does eliminate the unused load, but the explicit bounds check and call to trap() remain. w2c2 matches wasm2c's explicit-bounds-check approach.

@tomayac

tomayac commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

Please sleep over it, reconsider if the argument is still worth it, and if so continue the discussion over in https://github.com/turbolent/w2c2/issues/new.

Thanks for the PR.

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.

3 participants