mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Remove nearly all uses of StubReferences. (#3249)
The speculative insertion of StubReferences after elements in an argument list turned out to not be necessary, because we decided we want to insert per-argument initialization steps after all arguments are evaluated, rather than interleaving them. The StubReferences we insert are causing some minor code complexity, so remove them. We still create StubReferences when performing patch-ups of already-emitted code, but we no longer ever need to look through them when determining whether an initializer was a literal or when evaluating a type expression.
This commit is contained in:
@@ -318,8 +318,6 @@ auto Context::Initialize(Parse::Node parse_node, SemIR::NodeId target_id,
|
||||
return expr_id;
|
||||
|
||||
case SemIR::ExpressionCategory::Mixed:
|
||||
// Strip off outer stub references.
|
||||
expr_id = SkipStubReferences(expr_id);
|
||||
expr = semantics_ir().GetNode(expr_id);
|
||||
|
||||
// TODO: Make non-recursive.
|
||||
@@ -445,8 +443,6 @@ auto Context::ConvertToValueExpression(SemIR::NodeId expr_id) -> SemIR::NodeId {
|
||||
return expr_id;
|
||||
|
||||
case SemIR::ExpressionCategory::Mixed: {
|
||||
// Strip off outer stub references.
|
||||
expr_id = SkipStubReferences(expr_id);
|
||||
SemIR::Node expr = semantics_ir().GetNode(expr_id);
|
||||
|
||||
// TODO: Make non-recursive.
|
||||
@@ -499,7 +495,6 @@ auto Context::ConvertToValueOrReferenceExpression(SemIR::NodeId expr_id,
|
||||
|
||||
auto Context::MarkInitializerFor(SemIR::NodeId init_id, SemIR::NodeId target_id)
|
||||
-> void {
|
||||
init_id = SkipStubReferences(init_id);
|
||||
SemIR::Node init = semantics_ir().GetNode(init_id);
|
||||
CARBON_CHECK(SemIR::GetExpressionCategory(semantics_ir(), init_id) ==
|
||||
SemIR::ExpressionCategory::Initializing)
|
||||
@@ -556,7 +551,6 @@ auto Context::MarkInitializerFor(SemIR::NodeId init_id, SemIR::NodeId target_id)
|
||||
|
||||
auto Context::FinalizeTemporary(SemIR::NodeId init_id, bool discarded)
|
||||
-> SemIR::NodeId {
|
||||
init_id = SkipStubReferences(init_id);
|
||||
SemIR::Node init = semantics_ir().GetNode(init_id);
|
||||
CARBON_CHECK(SemIR::GetExpressionCategory(semantics_ir(), init_id) ==
|
||||
SemIR::ExpressionCategory::Initializing)
|
||||
@@ -703,9 +697,6 @@ static auto ConvertTupleToArray(Context& context, SemIR::Node tuple_type,
|
||||
const auto& tuple_elem_types =
|
||||
context.semantics_ir().GetTypeBlock(tuple_elem_types_id);
|
||||
|
||||
// Skip back over StubReferences to find if we're being initialized from a
|
||||
// tuple literal.
|
||||
value_id = context.SkipStubReferences(value_id);
|
||||
auto value = context.semantics_ir().GetNode(value_id);
|
||||
|
||||
llvm::ArrayRef<SemIR::NodeId> literal_elems;
|
||||
@@ -861,14 +852,13 @@ auto Context::ImplicitAs(Parse::Node parse_node, SemIR::NodeId value_id,
|
||||
|
||||
auto Context::ParamOrArgStart() -> void { params_or_args_stack_.Push(); }
|
||||
|
||||
auto Context::ParamOrArgComma(bool for_args) -> void {
|
||||
ParamOrArgSave(for_args);
|
||||
auto Context::ParamOrArgComma() -> void {
|
||||
ParamOrArgSave(node_stack_.PopExpression());
|
||||
}
|
||||
|
||||
auto Context::ParamOrArgEndNoPop(bool for_args, Parse::NodeKind start_kind)
|
||||
-> void {
|
||||
auto Context::ParamOrArgEndNoPop(Parse::NodeKind start_kind) -> void {
|
||||
if (parse_tree_->node_kind(node_stack_.PeekParseNode()) != start_kind) {
|
||||
ParamOrArgSave(for_args);
|
||||
ParamOrArgSave(node_stack_.PopExpression());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -876,27 +866,11 @@ auto Context::ParamOrArgPop() -> SemIR::NodeBlockId {
|
||||
return params_or_args_stack_.Pop();
|
||||
}
|
||||
|
||||
auto Context::ParamOrArgEnd(bool for_args, Parse::NodeKind start_kind)
|
||||
-> SemIR::NodeBlockId {
|
||||
ParamOrArgEndNoPop(for_args, start_kind);
|
||||
auto Context::ParamOrArgEnd(Parse::NodeKind start_kind) -> SemIR::NodeBlockId {
|
||||
ParamOrArgEndNoPop(start_kind);
|
||||
return ParamOrArgPop();
|
||||
}
|
||||
|
||||
auto Context::ParamOrArgSave(bool for_args) -> void {
|
||||
auto [entry_parse_node, entry_node_id] =
|
||||
node_stack_.PopExpressionWithParseNode();
|
||||
if (for_args) {
|
||||
// For an argument, we add a stub reference to the expression on the top of
|
||||
// the stack. There may not be anything on the IR prior to this.
|
||||
entry_node_id = AddNode(SemIR::Node::StubReference::Make(
|
||||
entry_parse_node, semantics_ir_->GetNode(entry_node_id).type_id(),
|
||||
entry_node_id));
|
||||
}
|
||||
|
||||
// Save the param or arg ID.
|
||||
params_or_args_stack_.AddNodeId(entry_node_id);
|
||||
}
|
||||
|
||||
auto Context::CanonicalizeTypeImpl(
|
||||
SemIR::NodeKind kind,
|
||||
llvm::function_ref<void(llvm::FoldingSetNodeID& canonical_id)> profile_type,
|
||||
@@ -979,16 +953,6 @@ static auto ProfileType(Context& semantics_context, SemIR::Node node,
|
||||
}
|
||||
break;
|
||||
}
|
||||
case SemIR::NodeKind::StubReference: {
|
||||
// We rely on stub references not referring to each other to ensure we
|
||||
// only recurse once here.
|
||||
auto inner =
|
||||
semantics_context.semantics_ir().GetNode(node.GetAsStubReference());
|
||||
CARBON_CHECK(inner.kind() != SemIR::NodeKind::StubReference)
|
||||
<< "A stub reference should never refer to another stub reference.";
|
||||
ProfileType(semantics_context, inner, canonical_id);
|
||||
break;
|
||||
}
|
||||
case SemIR::NodeKind::TupleType:
|
||||
ProfileTupleType(
|
||||
semantics_context.semantics_ir().GetTypeBlock(node.GetAsTupleType()),
|
||||
|
||||
Reference in New Issue
Block a user