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

convert wuffs asserts into back-end asserts #77

Open
ratchetfreak opened this issue May 21, 2022 · 2 comments
Open

convert wuffs asserts into back-end asserts #77

ratchetfreak opened this issue May 21, 2022 · 2 comments

Comments

@ratchetfreak
Copy link

Can there be an option to convert wuffs-side asserts into asserts in the generated code?

This could be a macro which lets the user code pick which behavior to have for them.

So the assert can translate into nothing (like it is now), or a full error like if not cond {return "#internal error: failed assert";}, or an actual assert(cond);, or even an assume(cond);.

Theoretically the compiler should be able to optimize out all these checks but there will be cases where it cannot make the assumptions necessary like across a yield. This in turn could help the optimizer figure out better options based on the invariants that are present in wuffs but not present in the backend.

@nigeltao
Copy link
Collaborator

Do you have an actual example (with benchmark numbers) where this helps the compiler / optimizer or is it hypothetical at this stage?

If we do do this, one subtlety is that Wuffs-side asserts work in ideal numbers but compilers work in fixed-sized integers. assert (x + 1) > x is valid for mathematical integers but isn't always true for uint32_t integers (and for signed fixed-size integers, this might even be "undefined behavior").

@ratchetfreak
Copy link
Author

It's hypothetical at this stage.

and yeah that does complicate matters

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