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

Convert StructTypeField to a specific type. #4492

Merged
merged 5 commits into from
Nov 6, 2024

Conversation

jonmeow
Copy link
Contributor

@jonmeow jonmeow commented Nov 5, 2024

This converts StructTypeField from an instruction to a dedicated type, with its own store. This had originated from discussing how .GetAs<SemIR::StructTypeField> was more prevalent than for other instructions, but is probably more interesting for the storage savings (16 bytes StructTypeField + 4 byte LocId + 4 byte InstId -> 8 byte StructTypeField).

Due to the different structure, these now have their own stack during construction, reducing (but not eliminating) args_type_info_stack_ use-cases.

The test changes of different InstIds is expected because structs and classes generate fewer instructions now. Other than that, results should remain the same.

I'm generally trying to avoid unrelated cleanup here due to the PR size, though I did scrutinize the VerifyOnFinish calls, adding one and commenting others (putting them in member order because that's how I was checking what was verified and what wasn't).

Copy link
Contributor

@josh11b josh11b left a comment

Choose a reason for hiding this comment

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

Nice improvement!

I was expecting you would have to add handling for StructTypeFieldsId to check/deduce.cpp, but it looks like the corresponding test is a TODO, see
https://github.com/carbon-language/carbon-lang/blob/trunk/toolchain/check/testdata/function/generic/deduce.carbon#L84

I think this change makes fixing that test pretty straightforward. If you were feeling ambitious, you could fix it in this PR or a follow-up.

// CHECK:STDERR: let w: i32 = {.def = 1, .def = 2}.def;
// CHECK:STDERR: ^~~
// CHECK:STDERR: fail_duplicate_name.carbon:[[@LINE+4]]:16: note: field with the same name here [StructNamePrevious]
// CHECK:STDERR: ^
Copy link
Contributor

Choose a reason for hiding this comment

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

This location information doesn't seem to be as good as before.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, should be back to what it was. Probably a better approach for transferring names too.

@jonmeow
Copy link
Contributor Author

jonmeow commented Nov 6, 2024

Nice improvement!

I was expecting you would have to add handling for StructTypeFieldsId to check/deduce.cpp, but it looks like the corresponding test is a TODO, see https://github.com/carbon-language/carbon-lang/blob/trunk/toolchain/check/testdata/function/generic/deduce.carbon#L84

I think this change makes fixing that test pretty straightforward. If you were feeling ambitious, you could fix it in this PR or a follow-up.

Thanks for pointing this out, but this PR is already very big and complex, and I don't think fixing an unrelated TODO should be part of it.

Copy link
Contributor

@josh11b josh11b left a comment

Choose a reason for hiding this comment

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

I have recently touched deduce.cpp, I'd be happy to make that change since I'm familiar with what is called for.

@jonmeow jonmeow added this pull request to the merge queue Nov 6, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 6, 2024
@jonmeow jonmeow added this pull request to the merge queue Nov 6, 2024
Merged via the queue into carbon-language:trunk with commit be56ff8 Nov 6, 2024
8 checks passed
@jonmeow jonmeow deleted the struct-type-field branch November 6, 2024 21:58
github-merge-queue bot pushed a commit that referenced this pull request Nov 7, 2024
Follow-on to #4492 .

---------

Co-authored-by: Josh L <[email protected]>
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