-
Notifications
You must be signed in to change notification settings - Fork 661
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
[Proposal] Type Casting Implementation #600
Comments
@Protryon I think we should make all implicit upcasting explicit. In implementing a cryptographic primitive in Leo, it could be risky to support implicit upcasting. For the purposes of Leo, language safety matters a lot, and I realize this case would tradeoff ease-of-use for that slightly, but I do believe it's preferred |
I agree with Howard - use explicit syntax when upcasting. |
@collinc97 @howardwu Implicit upcasting has been removed. |
The proposal looks good to me, and I agree with the explicitness of casting. But to elaborate on the latter point a bit, I believe that:
|
One common operation people will want to do is to multiply two N-bit unsigned integers to get a single 2N-bit unsigned integer. Does this proposal handle that? I could see something like
|
When we discussed this proposal in meetings, I remember we also discussed overflow issues. |
@Protryon I have a few questions about the current implementation:
|
|
💥 Proposal
Context
See issue #438 .
What It Is
This proposal includes explicit upcasting and downcasting for integer type values with Rust-like syntax.
Syntax
Rust-like syntax was chosen over C-like syntax to keep the parser logic as simple as possible, and avoid extra semantic ambiguity at AST level.
Explicit Cast Semantics
A given
type_cast_expression
is valid if:Downcasting will be evaluated with C-like bit truncation.
Upcasting will be evaluated with normal unsigned/signed respective extension.
Signedness casting will not modify the underlying bits at all, just coerce the type represented at asg/compiler level. (manifested in snarkos as moving bit gadgets between, for example,
Uint8
->Int8
)Upcasting bit extensions will be calculated BEFORE a signedness transformation if both are performed.
Examples:
Implications
as
is a new reserved keywordPossible Derivative Proposals
The text was updated successfully, but these errors were encountered: