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

Remove the special case for i32. #4543

Merged
merged 8 commits into from
Nov 18, 2024

Conversation

zygoloid
Copy link
Contributor

For the few remaining uses of the builtin i32 type, manually build an
IntType(Signed, 32) value instead. These are:

  • The return type of Run.
  • The type that int literals in an if expression are converted into.
  • The type of an array index expression.

We should consider converting those three cases away from i32 over
time.

For the few remaining uses of the builtin i32 type, manually build an
`IntType(Signed, 32)` value instead. These are:

- The return type of `Run`.
- The type that int literals in an `if` expression are converted into.
- The type of an array index expression.

We should consider converting those three cases away from `i32` over
time.
Copy link
Contributor

@jonmeow jonmeow left a comment

Choose a reason for hiding this comment

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

Generally looks good, though I don't think this is removing all the special-casing I'd expected. Note too that Add(i) is going to be more efficient than AddUnsigned(llvm::APInt(64, i)). I think the order of preference should be:

  1. Add (because it can avoid an APInt conversion)
  2. AddSigned (because it can avoid an unsigned -> signed conversion)
  3. AddUnsigned (primarily exists for lex; see comments at Canonicalize away bit width and embed small integers into IntIds #4487 (comment))

toolchain/check/context.cpp Show resolved Hide resolved
toolchain/check/context.cpp Outdated Show resolved Hide resolved
toolchain/check/context.h Outdated Show resolved Hide resolved
toolchain/check/convert.cpp Outdated Show resolved Hide resolved
@@ -88,9 +88,6 @@ class File : public Printable<File> {
// compute this information.
auto GetIntTypeInfo(TypeId int_type_id) const -> IntTypeInfo {
auto inst_id = types().GetInstId(int_type_id);
if (inst_id == InstId::BuiltinIntType) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think @chandlerc's intent had been to remove this full function upon the i32 type removal (see TODO), are you planning that as a separate PR? That is to say, this is still keepign some of the side-effects of i32 special-casing.

I'd particularly like to make sure there's a clear path forward due to the parallel of GetIntTypeInfo and IsSignedInt, given they're in separate files.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I'd removed these TODOs, but that ended up in the next PR branch rather than this one. Now they're removed in this PR instead.

Given the existence of the IntLiteral type, which is an integer type that's not an IntType, I don't think the TODOs are appropriate. I did add a TODO here to move this function to TypeStore, though -- I think it should either go there or become a non-member function given that we have been trying to avoid File accumulating a bunch of utility methods.

@@ -105,8 +105,7 @@ class TypeStore : public Yaml::Printable<TypeStore> {
// compute this information.
auto IsSignedInt(TypeId int_type_id) const -> bool {
auto inst_id = GetInstId(int_type_id);
if (inst_id == InstId::BuiltinIntType ||
inst_id == InstId::BuiltinIntLiteralType) {
if (inst_id == InstId::BuiltinIntLiteralType) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Note, similarly here about removal.

@jonmeow jonmeow added this pull request to the merge queue Nov 18, 2024
Merged via the queue into carbon-language:trunk with commit e2ae5f2 Nov 18, 2024
8 checks passed
@zygoloid zygoloid deleted the toolchain-remove-int32 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