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

data.length opcode #1546

Open
SoniEx2 opened this issue Dec 24, 2024 · 2 comments
Open

data.length opcode #1546

SoniEx2 opened this issue Dec 24, 2024 · 2 comments

Comments

@SoniEx2
Copy link

SoniEx2 commented Dec 24, 2024

we should have data.length opcode

(it should return 0 for dropped segments ofc)

@SoniEx2
Copy link
Author

SoniEx2 commented Dec 27, 2024

for context: memory.init (already) needs to know the data segment length so it can trap, but trapping isn't particularly useful for programs. a data.length would expose the length in an useful way (non-trapping).

a hypothetical single-pass compiler could use a data.length opcode for generated data segments, since data segments come after code segments. such data.length opcode also happens to be oddly convenient when hand-writing wasm/wat.

@rossberg
Copy link
Member

A correctly compiled program should never mismatch the length of a segment. That would always be the symptom of a compiler bug, and non-trapping behaviour can't help with that.

I have written single-pass compilers targeting Wasm. They can just backpatch the constants, like they already have to do for various other values in the binary format. Moreover, in practice, data segments (e.g., for string literals) are typically synthesised during code emission itself in such a compiler (and emitted afterwards), so that I never even needed such backpatching.

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

2 participants