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

Add builtin for performing checked conversion between integer types. #4523

Merged
merged 4 commits into from
Nov 14, 2024

Conversation

zygoloid
Copy link
Contributor

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.

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";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrap?

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// --- sext.carbon
// --- signed_extend.carbon

Copy link
Contributor Author

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.

@josh11b josh11b added this pull request to the merge queue Nov 14, 2024
Merged via the queue into carbon-language:trunk with commit cbd88e5 Nov 14, 2024
8 checks passed
@zygoloid zygoloid deleted the toolchain-int-checked-convert branch November 20, 2024 18:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants