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 support for converting between integer types #4753

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from

Conversation

zygoloid
Copy link
Contributor

@zygoloid zygoloid commented Jan 3, 2025

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 explicit As 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.

@github-actions github-actions bot requested a review from josh11b January 3, 2025 01:11
Copy link
Contributor

@chandlerc chandlerc left a 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.
Copy link
Contributor

Choose a reason for hiding this comment

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

N > M + 1?

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