mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-24 22:02:23 +01:00
Refactor ReturnTypeInfo and InitRepr. (#4169)
Rename `ReturnInfo` to `ReturnTypeInfo`. Move it and `InitRepr` into `type_info.h` alongside `ValueRepr`. Replace `ReturnSlot` with `InitRepr`, and extend `InitRepr` to be able to represent the incomplete-type case instead of CHECK-failing. Remove `has_return_slot` from `InitRepr` and instead only provide that as part of `ReturnTypeInfo`.
This commit is contained in:
@@ -73,12 +73,13 @@ auto CheckFunctionTypeMatches(Context& context,
|
||||
auto CheckFunctionReturnType(Context& context, SemIRLoc loc,
|
||||
SemIR::Function& function,
|
||||
SemIR::SpecificId specific_id)
|
||||
-> SemIR::ReturnInfo {
|
||||
auto return_info = function.GetReturnInfo(context.sem_ir(), specific_id);
|
||||
-> SemIR::ReturnTypeInfo {
|
||||
auto return_info = SemIR::ReturnTypeInfo::ForFunction(context.sem_ir(),
|
||||
function, specific_id);
|
||||
|
||||
// If we couldn't determine the return information due to the return type
|
||||
// being incomplete, try to complete it now.
|
||||
if (return_info.return_slot == SemIR::ReturnSlot::Incomplete) {
|
||||
if (return_info.init_repr.kind == SemIR::InitRepr::Incomplete) {
|
||||
auto diagnose_incomplete_return_type = [&] {
|
||||
CARBON_DIAGNOSTIC(IncompleteTypeInFunctionReturnType, Error,
|
||||
"Function returns incomplete type `{0}`.",
|
||||
@@ -91,7 +92,8 @@ auto CheckFunctionReturnType(Context& context, SemIRLoc loc,
|
||||
// definition or call to this function.
|
||||
if (context.TryToCompleteType(return_info.type_id,
|
||||
diagnose_incomplete_return_type)) {
|
||||
return_info = function.GetReturnInfo(context.sem_ir(), specific_id);
|
||||
return_info = SemIR::ReturnTypeInfo::ForFunction(context.sem_ir(),
|
||||
function, specific_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user