Skip to content

When importing C++ records (struct/class/union), make the imported type complete #5534

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

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

bricknerb
Copy link
Contributor

This is required to allow passing these types as parameters / return values.

Part of #5533.

…pe complete

This is required in order to pass these types as parameters / return values.
@bricknerb bricknerb enabled auto-merge May 27, 2025 08:04
@github-actions github-actions bot requested a review from geoffromer May 27, 2025 08:04
bricknerb added a commit to bricknerb/carbon-lang that referenced this pull request May 27, 2025
This doesn't support actually passing the value of the struct, which is planned to be implemented using thunks.

I plan to add more tests in a separate PR.

Based on carbon-language#5534 and carbon-language#5537.

Part of carbon-language#5533.
@@ -605,6 +606,9 @@ static auto ImportCXXRecordDecl(Context& context, SemIR::LocId loc_id,
// TODO: Set block.
/*body=*/{});

CompleteTypeOrCheckFail(context,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised that this doesn't have a more substantial effect on any of the tests. Were all the types already complete?

(I'm also troubled that this change causes the inst names to get disambiguating suffixes that look unnecessary, but I'm not sure what to do about it.)

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm surprised that this doesn't have a more substantial effect on any of the tests. Were all the types already complete?

From ComputeClassObjectRepr:

  auto complete_type_witness_id = CheckCompleteClassType(
      context, node_id, class_id, field_decls, vtable_contents, body);

That said, maybe there's an edge case that was being missed; maybe a test should be added?

I'm also troubled that this change causes the inst names to get disambiguating suffixes that look unnecessary, but I'm not sure what to do about it.

This probably reflects the addition of instructions which the formatter would name the same, but don't get printed in output due to being unreferenced.

Copy link
Contributor

@jonmeow jonmeow May 27, 2025

Choose a reason for hiding this comment

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

This is required to allow passing these types as parameters / return values.

Note, it's not clear to me that this is the right way to fix if this issue can't be tested in this PR. The code without this PR looks equivalent to Carbon's class behavior.

Copy link
Contributor Author

@bricknerb bricknerb May 28, 2025

Choose a reason for hiding this comment

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

Thanks!
Tests definitely fail (crashes) in #5538 without this so we can continue the review there if you prefer.
I wanted to make the review easier so I split it to two PRs, but I can see the value of having it in one.

FWIW, in ImportCXXRecordDecl(), context.types().IsComplete(context.classes().Get(class_id).self_type_id) always returns false before CompleteTypeOrCheckFail() and true afterwards.
While ComputeClassObjectRepr() calls CheckCompleteClassType(), it doesn't seem to make this type complete, even though it sets complete_type_witness_id.
I believe that Carbon classes that aren't imported from C++ are being completed through a different pass.

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.

3 participants