-
Notifications
You must be signed in to change notification settings - Fork 148
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
Z_static_cast should record whether it's a cast up or cast down #939
Comments
In fact it would be nice to distinguish three different cases: (lossless) widen, lossless narrow, and truncating narrow. |
Hi Jason, Do you think this is doable? The generated Zig code currently works around this, but that workaround has a significant impact on compilation time. |
It's doable, but a bit non-trivial. I don't have the time to work on it right now, but if you wanted to take a stab at it, the thing to do would be to add Variant cast_kind := annotation | truncating. Then update fiat-crypto/src/Language/PreExtra.v Lines 34 to 43 in 94919dc
to take in such cast_kind arguments, add cast_kind tofiat-crypto/src/Language/IdentifierParameters.v Lines 45 to 50 in 94919dc
Then, for each rewrite rule involving a cast, you need to either make it parametric over the kind of cast, or else go from any kind of cast to a truncating cast (for the few rules that do truncate). There's no help from the typechecker here, so this part needs to be done carefully. The code is at fiat-crypto/src/Rewriter/Rules.v Lines 301 to 1179 in 94919dc
The corresponding tactics and proofs in https://github.com/mit-plv/fiat-crypto/blob/master/src/Rewriter/RulesProofs.v need to be updated, as well as the lemmas in https://github.com/mit-plv/fiat-crypto/blob/master/src/CastLemmas.v. Then you need to update fiat-crypto/src/AbstractInterpretation/AbstractInterpretation.v Lines 392 to 401 in 94919dc
Then you want update fiat-crypto/src/Stringification/IR.v Line 92 in 94919dc
Variant static_cast_kind := lossless_widen | lossless_narrow | truncating_narrow. The logic at fiat-crypto/src/Stringification/IR.v Lines 459 to 594 in 94919dc
Then you can use this information in the Zig backend. Finally, any other things that break from Coq typechecking / proofs need to be fixed. |
Ah, I should be able to add an extra argument to
Z_static_cast
that says whether we're increasing the size or decreasing it. I'll open an issue to remind myself to do it.Originally posted by @JasonGross in #936 (comment)
The text was updated successfully, but these errors were encountered: