-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add support for converting between integer types #4753
base: trunk
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just some drive-by thoughts -- this seems to really demonstrate that the SemIR formatted output is too brittle given the number of changes, all of which seemingly just due to 4 new impls appearing.
Also maybe a comment tweak suggested inline. I couldn't really find the tests of this logic due to all the churn.
fn Convert[self: Self]() -> UInt(N) = "int.convert"; | ||
} | ||
|
||
// TODO: Allow as an implicit conversion if N > M. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
N > M + 1?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is right as-is: all values of uN fit in i(N+1), so it's OK for that to be implicit. The other comments could use >=
instead of >
, but that would only allow identity conversions which we already allow.
Add a builtin
"int.convert"
supporting unchecked conversions between different integer types. This performs a truncation, zero-extension, or sign-extension, depending on the widths of the operands and the signedness of the source type. Add explicitAs
support to the prelude. No implicit conversions are supported yet as we don't have a way to express the constraint that we can only implicitly convert to wider types.