mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +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:
@@ -115,7 +115,7 @@ auto PerformCall(Context& context, Parse::NodeId node_id,
|
||||
|
||||
// If there is a return slot, build storage for the result.
|
||||
SemIR::InstId return_storage_id = SemIR::InstId::Invalid;
|
||||
SemIR::ReturnInfo return_info = [&] {
|
||||
SemIR::ReturnTypeInfo return_info = [&] {
|
||||
DiagnosticAnnotationScope annotate_diagnostics(
|
||||
&context.emitter(), [&](auto& builder) {
|
||||
CARBON_DIAGNOSTIC(IncompleteReturnTypeHere, Note,
|
||||
@@ -124,21 +124,23 @@ auto PerformCall(Context& context, Parse::NodeId node_id,
|
||||
});
|
||||
return CheckFunctionReturnType(context, callee_id, callable, specific_id);
|
||||
}();
|
||||
switch (return_info.return_slot) {
|
||||
case SemIR::ReturnSlot::Present:
|
||||
switch (return_info.init_repr.kind) {
|
||||
case SemIR::InitRepr::InPlace:
|
||||
// Tentatively put storage for a temporary in the function's return slot.
|
||||
// This will be replaced if necessary when we perform initialization.
|
||||
return_storage_id = context.AddInst<SemIR::TemporaryStorage>(
|
||||
node_id, {.type_id = return_info.type_id});
|
||||
break;
|
||||
case SemIR::ReturnSlot::Absent:
|
||||
case SemIR::InitRepr::None:
|
||||
// For functions with an implicit return type, the return type is the
|
||||
// empty tuple type.
|
||||
if (!return_info.type_id.is_valid()) {
|
||||
return_info.type_id = context.GetTupleType({});
|
||||
}
|
||||
break;
|
||||
case SemIR::ReturnSlot::Incomplete:
|
||||
case SemIR::InitRepr::ByCopy:
|
||||
break;
|
||||
case SemIR::InitRepr::Incomplete:
|
||||
// Don't form an initializing expression with an incomplete type.
|
||||
// CheckFunctionReturnType will have diagnosed this for us if needed.
|
||||
return_info.type_id = SemIR::TypeId::Error;
|
||||
|
||||
Reference in New Issue
Block a user