mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-04 19:31:08 +01:00
Remove return_slot_id (#4577)
Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
co-authored by
Richard Smith
parent
33110d096c
commit
78d7a7c291
@@ -45,11 +45,12 @@ auto HandleParseNode(Context& context, Parse::ReturnTypeId node_id) -> bool {
|
||||
// Propagate the type expression.
|
||||
auto [type_node_id, type_inst_id] = context.node_stack().PopExprWithNodeId();
|
||||
auto type_id = ExprAsType(context, type_node_id, type_inst_id).type_id;
|
||||
auto return_slot_id = context.AddPatternInst<SemIR::ReturnSlotPattern>(
|
||||
node_id, {.type_id = type_id, .type_inst_id = type_inst_id});
|
||||
auto return_slot_pattern_id =
|
||||
context.AddPatternInst<SemIR::ReturnSlotPattern>(
|
||||
node_id, {.type_id = type_id, .type_inst_id = type_inst_id});
|
||||
auto param_pattern_id = context.AddPatternInst<SemIR::OutParamPattern>(
|
||||
node_id, {.type_id = type_id,
|
||||
.subpattern_id = return_slot_id,
|
||||
.subpattern_id = return_slot_pattern_id,
|
||||
.runtime_index = SemIR::RuntimeParamIndex::Unknown});
|
||||
context.node_stack().Push(node_id, param_pattern_id);
|
||||
return true;
|
||||
@@ -102,7 +103,7 @@ static auto MergeFunctionRedecl(Context& context, SemIRLoc new_loc,
|
||||
// Track the signature from the definition, so that IDs in the body
|
||||
// match IDs in the signature.
|
||||
prev_function.MergeDefinition(new_function);
|
||||
prev_function.return_slot_id = new_function.return_slot_id;
|
||||
prev_function.return_slot_pattern_id = new_function.return_slot_pattern_id;
|
||||
}
|
||||
if ((prev_import_ir_id.is_valid() && !new_is_import)) {
|
||||
ReplacePrevInstForMerge(context, new_function.parent_scope_id,
|
||||
@@ -243,7 +244,6 @@ static auto BuildFunctionDecl(Context& context,
|
||||
SemIR::Function{{name_context.MakeEntityWithParamsBase(
|
||||
name, decl_id, is_extern, introducer.extern_library)},
|
||||
{.return_slot_pattern_id = name.return_slot_pattern_id,
|
||||
.return_slot_id = name.return_slot_id,
|
||||
.virtual_modifier = virtual_modifier}};
|
||||
if (is_definition) {
|
||||
function_info.definition_id = decl_id;
|
||||
@@ -345,12 +345,12 @@ static auto HandleFunctionDefinitionAfterSignature(
|
||||
context.AddCurrentCodeBlockToFunction();
|
||||
|
||||
// Check the return type is complete.
|
||||
CheckFunctionReturnType(context, function.return_slot_id, function,
|
||||
CheckFunctionReturnType(context, function.return_slot_pattern_id, function,
|
||||
SemIR::SpecificId::Invalid);
|
||||
|
||||
auto params_to_complete =
|
||||
context.inst_blocks().GetOrEmpty(function.call_params_id);
|
||||
if (function.return_slot_id.is_valid()) {
|
||||
if (function.return_slot_pattern_id.is_valid()) {
|
||||
// Exclude the return slot because it's diagnosed above.
|
||||
params_to_complete = params_to_complete.drop_back();
|
||||
}
|
||||
@@ -412,7 +412,9 @@ auto HandleParseNode(Context& context, Parse::FunctionDefinitionId node_id)
|
||||
// If the `}` of the function is reachable, reject if we need a return value
|
||||
// and otherwise add an implicit `return;`.
|
||||
if (context.is_current_position_reachable()) {
|
||||
if (context.functions().Get(function_id).return_slot_id.is_valid()) {
|
||||
if (context.functions()
|
||||
.Get(function_id)
|
||||
.return_slot_pattern_id.is_valid()) {
|
||||
CARBON_DIAGNOSTIC(
|
||||
MissingReturnStatement, Error,
|
||||
"missing `return` at end of function with declared return type");
|
||||
|
||||
Reference in New Issue
Block a user