-
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 builtin for performing checked conversion between integer types. #4523
Add builtin for performing checked conversion between integer types. #4523
Conversation
fn Int32ToUint32(a: i32) -> u32 = "int.convert_checked"; | ||
fn Uint32ToInt32(a: u32) -> i32 = "int.convert_checked"; | ||
fn Uint32ToUint32(a: u32) -> u32 = "int.convert_checked"; | ||
fn IntLiteralToIntLiteral(a: IntLiteral()) -> IntLiteral() = "int.convert_checked"; |
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.
Wrap?
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.
Done.
AddU32(Int32ToUint32(0x7FFF_FFFF), Int32ToUint32(0x7FFF_FFFF)), | ||
Int32ToUint32(1))); | ||
|
||
// --- sext.carbon |
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.
// --- sext.carbon | |
// --- signed_extend.carbon |
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.
Done, but sign_extend
instead.
As a prerequisite for switching the type of int literals to be the
IntLiteral
type, add support for performing conversions of in-bounds integer constant values to other integer types in which they fit.This incidentally is our first compile-time-only builtin function, so add very minimal support for compile-time-only functions while we're here.