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:
Richard Smith
2024-07-25 21:41:33 +00:00
committed by GitHub
parent 2ef1d1f8b9
commit 37a8bfa488
19 changed files with 194 additions and 194 deletions
+6 -3
View File
@@ -57,7 +57,8 @@ auto CheckReturnedVar(Context& context, Parse::NodeId returned_node,
Parse::NodeId type_node, SemIR::TypeId type_id)
-> SemIR::InstId {
auto& function = GetCurrentFunction(context);
auto return_info = function.GetReturnInfo(context.sem_ir());
auto return_info =
SemIR::ReturnTypeInfo::ForFunction(context.sem_ir(), function);
if (!return_info.is_valid()) {
// We already diagnosed this when we started defining the function. Create a
// placeholder for error recovery.
@@ -131,7 +132,8 @@ auto BuildReturnWithExpr(Context& context, Parse::ReturnStatementId node_id,
const auto& function = GetCurrentFunction(context);
auto returned_var_id = GetCurrentReturnedVar(context);
auto return_slot_id = SemIR::InstId::Invalid;
auto return_info = function.GetReturnInfo(context.sem_ir());
auto return_info =
SemIR::ReturnTypeInfo::ForFunction(context.sem_ir(), function);
if (!return_info.type_id.is_valid()) {
CARBON_DIAGNOSTIC(
@@ -178,7 +180,8 @@ auto BuildReturnVar(Context& context, Parse::ReturnStatementId node_id)
}
auto return_slot_id = function.return_storage_id;
if (!function.GetReturnInfo(context.sem_ir()).has_return_slot()) {
if (!SemIR::ReturnTypeInfo::ForFunction(context.sem_ir(), function)
.has_return_slot()) {
// If we don't have a return slot, we're returning by value. Convert to a
// value expression.
returned_var_id = ConvertToValueExpr(context, returned_var_id);