-
Notifications
You must be signed in to change notification settings - Fork 1.5k
When using a C++ struct as a parameter, map it to a Carbon type #5538
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
base: trunk
Are you sure you want to change the base?
Conversation
toolchain/check/import_cpp.cpp
Outdated
@@ -605,6 +661,9 @@ static auto ImportCXXRecordDecl(Context& context, SemIR::LocId loc_id, | |||
// TODO: Set block. | |||
/*body=*/{}); | |||
|
|||
CompleteTypeOrCheckFail(context, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, you added this to prevent a crash that looks like this:
CHECK failure at toolchain/check/pattern_match.cpp:379: static_cast<size_t>(param_pattern.index.index) == results_.size(): Parameters out of order; expecting 0 but got -1
If so, I think that crash indicates violation of an invariant that CalleePatternMatch
is supposed to establish, but the import logic isn't calling CalleePatternMatch
. Instead MakeParamPatternsBlockId
is trying to emulate it, and there are some bugs in the emulation (see also here). I'd strongly encourage you to use CalleePatternMatch
whenever you're creating an EntityWithParams
. If there are major obstacles to doing that, let me know; I'm happy to help figure out a solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
It seems like CalleePatternMatch()
would be called as part of resolving #5449, so I'll hold off this change until we manage to do that. I know @ivanaivanovska has been working on this as her top priority.
|
||
struct S {}; | ||
|
||
auto foo(S) -> void; | ||
|
||
// --- fail_todo_import_struct_param_type.carbon | ||
// --- todo_import_struct_definition_param_type.carbon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove todo_
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@@ -347,11 +345,60 @@ static auto MapType(Context& context, clang::QualType type) -> TypeExpr { | |||
.type_id = SemIR::ErrorInst::TypeId}; | |||
} | |||
|
|||
// Maps a C++ record type to a Carbon type. | |||
// TODO: Support more record types. | |||
static auto MapRecordType(Context& context, SemIR::LocId loc_id, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test for the scope? (e.g. the name not found in the scope)
…pe complete This is required in order to pass these types as parameters / return values.
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.
…e are no apparent changes to be made.
Remove call to `CompleteTypeOrCheckFail()`
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 #5468.
C++ Interop Demo (that shows missing behavior):
Part of #5533.