|
|
@@ -95,7 +95,7 @@ static auto FinalizeTemporary(Context& context, SemIR::InstId init_id,
|
|
|
<< sem_ir.insts().Get(return_slot_id);
|
|
|
auto init = sem_ir.insts().Get(init_id);
|
|
|
return context.AddInst(
|
|
|
- {sem_ir.insts().GetParseNode(init_id),
|
|
|
+ {sem_ir.insts().GetNodeId(init_id),
|
|
|
SemIR::Temporary{init.type_id(), return_slot_id, init_id}});
|
|
|
}
|
|
|
|
|
|
@@ -110,11 +110,11 @@ static auto FinalizeTemporary(Context& context, SemIR::InstId init_id,
|
|
|
// materialize and initialize a temporary, rather than two separate
|
|
|
// instructions.
|
|
|
auto init = sem_ir.insts().Get(init_id);
|
|
|
- auto parse_node = sem_ir.insts().GetParseNode(init_id);
|
|
|
+ auto node_id = sem_ir.insts().GetNodeId(init_id);
|
|
|
auto temporary_id =
|
|
|
- context.AddInst({parse_node, SemIR::TemporaryStorage{init.type_id()}});
|
|
|
+ context.AddInst({node_id, SemIR::TemporaryStorage{init.type_id()}});
|
|
|
return context.AddInst(
|
|
|
- {parse_node, SemIR::Temporary{init.type_id(), temporary_id, init_id}});
|
|
|
+ {node_id, SemIR::Temporary{init.type_id(), temporary_id, init_id}});
|
|
|
}
|
|
|
|
|
|
// Materialize a temporary to hold the result of the given expression if it is
|
|
|
@@ -130,7 +130,7 @@ static auto MaterializeIfInitializing(Context& context, SemIR::InstId expr_id)
|
|
|
|
|
|
// Creates and adds an instruction to perform element access into an aggregate.
|
|
|
template <typename AccessInstT, typename InstBlockT>
|
|
|
-static auto MakeElementAccessInst(Context& context, Parse::NodeId parse_node,
|
|
|
+static auto MakeElementAccessInst(Context& context, Parse::NodeId node_id,
|
|
|
SemIR::InstId aggregate_id,
|
|
|
SemIR::TypeId elem_type_id, InstBlockT& block,
|
|
|
std::size_t i) {
|
|
|
@@ -139,14 +139,14 @@ static auto MakeElementAccessInst(Context& context, Parse::NodeId parse_node,
|
|
|
// index so that we don't need an integer literal instruction here, and
|
|
|
// remove this special case.
|
|
|
auto index_id = block.AddInst(
|
|
|
- {parse_node,
|
|
|
+ {node_id,
|
|
|
SemIR::IntLiteral{context.GetBuiltinType(SemIR::BuiltinKind::IntType),
|
|
|
context.ints().Add(llvm::APInt(32, i))}});
|
|
|
return block.AddInst(
|
|
|
- {parse_node, AccessInstT{elem_type_id, aggregate_id, index_id}});
|
|
|
+ {node_id, AccessInstT{elem_type_id, aggregate_id, index_id}});
|
|
|
} else {
|
|
|
- return block.AddInst({parse_node, AccessInstT{elem_type_id, aggregate_id,
|
|
|
- SemIR::ElementIndex(i)}});
|
|
|
+ return block.AddInst({node_id, AccessInstT{elem_type_id, aggregate_id,
|
|
|
+ SemIR::ElementIndex(i)}});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -165,7 +165,7 @@ static auto MakeElementAccessInst(Context& context, Parse::NodeId parse_node,
|
|
|
// instruction used to access the destination element.
|
|
|
template <typename SourceAccessInstT, typename TargetAccessInstT>
|
|
|
static auto ConvertAggregateElement(
|
|
|
- Context& context, Parse::NodeId parse_node, SemIR::InstId src_id,
|
|
|
+ Context& context, Parse::NodeId node_id, SemIR::InstId src_id,
|
|
|
SemIR::TypeId src_elem_type,
|
|
|
llvm::ArrayRef<SemIR::InstId> src_literal_elems,
|
|
|
ConversionTarget::Kind kind, SemIR::InstId target_id,
|
|
|
@@ -176,22 +176,22 @@ static auto ConvertAggregateElement(
|
|
|
auto src_elem_id =
|
|
|
!src_literal_elems.empty()
|
|
|
? src_literal_elems[i]
|
|
|
- : MakeElementAccessInst<SourceAccessInstT>(
|
|
|
- context, parse_node, src_id, src_elem_type, context, i);
|
|
|
+ : MakeElementAccessInst<SourceAccessInstT>(context, node_id, src_id,
|
|
|
+ src_elem_type, context, i);
|
|
|
|
|
|
// If we're performing a conversion rather than an initialization, we won't
|
|
|
// have or need a target.
|
|
|
ConversionTarget target = {.kind = kind, .type_id = target_elem_type};
|
|
|
if (!target.is_initializer()) {
|
|
|
- return Convert(context, parse_node, src_elem_id, target);
|
|
|
+ return Convert(context, node_id, src_elem_id, target);
|
|
|
}
|
|
|
|
|
|
// Compute the location of the target element and initialize it.
|
|
|
PendingBlock::DiscardUnusedInstsScope scope(target_block);
|
|
|
target.init_block = target_block;
|
|
|
target.init_id = MakeElementAccessInst<TargetAccessInstT>(
|
|
|
- context, parse_node, target_id, target_elem_type, *target_block, i);
|
|
|
- return Convert(context, parse_node, src_elem_id, target);
|
|
|
+ context, node_id, target_id, target_elem_type, *target_block, i);
|
|
|
+ return Convert(context, node_id, src_elem_id, target);
|
|
|
}
|
|
|
|
|
|
namespace {
|
|
|
@@ -246,7 +246,7 @@ static auto ConvertTupleToArray(Context& context, SemIR::TupleType tuple_type,
|
|
|
auto tuple_elem_types = sem_ir.type_blocks().Get(tuple_type.elements_id);
|
|
|
|
|
|
auto value = sem_ir.insts().Get(value_id);
|
|
|
- auto value_parse_node = sem_ir.insts().GetParseNode(value_id);
|
|
|
+ auto value_node_id = sem_ir.insts().GetNodeId(value_id);
|
|
|
|
|
|
// If we're initializing from a tuple literal, we will use its elements
|
|
|
// directly. Otherwise, materialize a temporary if needed and index into the
|
|
|
@@ -269,7 +269,7 @@ static auto ConvertTupleToArray(Context& context, SemIR::TupleType tuple_type,
|
|
|
"Cannot initialize array of {0} element(s) from tuple "
|
|
|
"with {1} element(s).",
|
|
|
uint64_t, size_t);
|
|
|
- context.emitter().Emit(value_parse_node,
|
|
|
+ context.emitter().Emit(value_node_id,
|
|
|
literal_elems.empty()
|
|
|
? ArrayInitFromExprArgCountMismatch
|
|
|
: ArrayInitFromLiteralArgCountMismatch,
|
|
|
@@ -286,7 +286,7 @@ static auto ConvertTupleToArray(Context& context, SemIR::TupleType tuple_type,
|
|
|
SemIR::InstId return_slot_id = target.init_id;
|
|
|
if (!target.init_id.is_valid()) {
|
|
|
return_slot_id = target_block->AddInst(
|
|
|
- {value_parse_node, SemIR::TemporaryStorage{target.type_id}});
|
|
|
+ {value_node_id, SemIR::TemporaryStorage{target.type_id}});
|
|
|
}
|
|
|
|
|
|
// Initialize each element of the array from the corresponding element of the
|
|
|
@@ -300,7 +300,7 @@ static auto ConvertTupleToArray(Context& context, SemIR::TupleType tuple_type,
|
|
|
// approach.
|
|
|
auto init_id =
|
|
|
ConvertAggregateElement<SemIR::TupleAccess, SemIR::ArrayIndex>(
|
|
|
- context, value_parse_node, value_id, src_type_id, literal_elems,
|
|
|
+ context, value_node_id, value_id, src_type_id, literal_elems,
|
|
|
ConversionTarget::FullInitializer, return_slot_id,
|
|
|
array_type.element_type_id, target_block, i);
|
|
|
if (init_id == SemIR::InstId::BuiltinError) {
|
|
|
@@ -313,7 +313,7 @@ static auto ConvertTupleToArray(Context& context, SemIR::TupleType tuple_type,
|
|
|
// reference to the return slot.
|
|
|
target_block->InsertHere();
|
|
|
return context.AddInst(
|
|
|
- {value_parse_node,
|
|
|
+ {value_node_id,
|
|
|
SemIR::ArrayInit{target.type_id, sem_ir.inst_blocks().Add(inits),
|
|
|
return_slot_id}});
|
|
|
}
|
|
|
@@ -330,7 +330,7 @@ static auto ConvertTupleToTuple(Context& context, SemIR::TupleType src_type,
|
|
|
auto dest_elem_types = sem_ir.type_blocks().Get(dest_type.elements_id);
|
|
|
|
|
|
auto value = sem_ir.insts().Get(value_id);
|
|
|
- auto value_parse_node = sem_ir.insts().GetParseNode(value_id);
|
|
|
+ auto value_node_id = sem_ir.insts().GetNodeId(value_id);
|
|
|
|
|
|
// If we're initializing from a tuple literal, we will use its elements
|
|
|
// directly. Otherwise, materialize a temporary if needed and index into the
|
|
|
@@ -350,7 +350,7 @@ static auto ConvertTupleToTuple(Context& context, SemIR::TupleType src_type,
|
|
|
"Cannot initialize tuple of {0} element(s) from tuple "
|
|
|
"with {1} element(s).",
|
|
|
size_t, size_t);
|
|
|
- context.emitter().Emit(value_parse_node, TupleInitElementCountMismatch,
|
|
|
+ context.emitter().Emit(value_node_id, TupleInitElementCountMismatch,
|
|
|
dest_elem_types.size(), src_elem_types.size());
|
|
|
return SemIR::InstId::BuiltinError;
|
|
|
}
|
|
|
@@ -377,7 +377,7 @@ static auto ConvertTupleToTuple(Context& context, SemIR::TupleType src_type,
|
|
|
// approach.
|
|
|
auto init_id =
|
|
|
ConvertAggregateElement<SemIR::TupleAccess, SemIR::TupleAccess>(
|
|
|
- context, value_parse_node, value_id, src_type_id, literal_elems,
|
|
|
+ context, value_node_id, value_id, src_type_id, literal_elems,
|
|
|
inner_kind, target.init_id, dest_type_id, target.init_block, i);
|
|
|
if (init_id == SemIR::InstId::BuiltinError) {
|
|
|
return SemIR::InstId::BuiltinError;
|
|
|
@@ -388,11 +388,11 @@ static auto ConvertTupleToTuple(Context& context, SemIR::TupleType src_type,
|
|
|
if (is_init) {
|
|
|
target.init_block->InsertHere();
|
|
|
return context.AddInst(
|
|
|
- {value_parse_node,
|
|
|
+ {value_node_id,
|
|
|
SemIR::TupleInit{target.type_id, new_block.id(), target.init_id}});
|
|
|
} else {
|
|
|
return context.AddInst(
|
|
|
- {value_parse_node, SemIR::TupleValue{target.type_id, new_block.id()}});
|
|
|
+ {value_node_id, SemIR::TupleValue{target.type_id, new_block.id()}});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -409,7 +409,7 @@ static auto ConvertStructToStructOrClass(Context& context,
|
|
|
auto dest_elem_fields = sem_ir.inst_blocks().Get(dest_type.fields_id);
|
|
|
|
|
|
auto value = sem_ir.insts().Get(value_id);
|
|
|
- auto value_parse_node = sem_ir.insts().GetParseNode(value_id);
|
|
|
+ auto value_node_id = sem_ir.insts().GetNodeId(value_id);
|
|
|
|
|
|
// If we're initializing from a struct literal, we will use its elements
|
|
|
// directly. Otherwise, materialize a temporary if needed and index into the
|
|
|
@@ -432,7 +432,7 @@ static auto ConvertStructToStructOrClass(Context& context,
|
|
|
"with {2} field(s).",
|
|
|
llvm::StringLiteral, size_t, size_t);
|
|
|
context.emitter().Emit(
|
|
|
- value_parse_node, StructInitElementCountMismatch,
|
|
|
+ value_node_id, StructInitElementCountMismatch,
|
|
|
is_class ? llvm::StringLiteral("class") : llvm::StringLiteral("struct"),
|
|
|
dest_elem_fields.size(), src_elem_fields.size());
|
|
|
return SemIR::InstId::BuiltinError;
|
|
|
@@ -478,8 +478,7 @@ static auto ConvertStructToStructOrClass(Context& context,
|
|
|
StructInitMissingFieldInLiteral, Error,
|
|
|
"Missing value for field `{0}` in struct initialization.",
|
|
|
SemIR::NameId);
|
|
|
- context.emitter().Emit(value_parse_node,
|
|
|
- StructInitMissingFieldInLiteral,
|
|
|
+ context.emitter().Emit(value_node_id, StructInitMissingFieldInLiteral,
|
|
|
dest_field.name_id);
|
|
|
} else {
|
|
|
CARBON_DIAGNOSTIC(StructInitMissingFieldInConversion, Error,
|
|
|
@@ -487,7 +486,7 @@ static auto ConvertStructToStructOrClass(Context& context,
|
|
|
"missing field `{2}` in source type.",
|
|
|
SemIR::TypeId, SemIR::TypeId, SemIR::NameId);
|
|
|
context.emitter().Emit(
|
|
|
- value_parse_node, StructInitMissingFieldInConversion,
|
|
|
+ value_node_id, StructInitMissingFieldInConversion,
|
|
|
value.type_id(), target.type_id, dest_field.name_id);
|
|
|
}
|
|
|
return SemIR::InstId::BuiltinError;
|
|
|
@@ -501,7 +500,7 @@ static auto ConvertStructToStructOrClass(Context& context,
|
|
|
// approach.
|
|
|
auto init_id =
|
|
|
ConvertAggregateElement<SemIR::StructAccess, TargetAccessInstT>(
|
|
|
- context, value_parse_node, value_id, src_field.field_type_id,
|
|
|
+ context, value_node_id, value_id, src_field.field_type_id,
|
|
|
literal_elems, inner_kind, target.init_id, dest_field.field_type_id,
|
|
|
target.init_block, src_field_index);
|
|
|
if (init_id == SemIR::InstId::BuiltinError) {
|
|
|
@@ -515,16 +514,16 @@ static auto ConvertStructToStructOrClass(Context& context,
|
|
|
CARBON_CHECK(is_init)
|
|
|
<< "Converting directly to a class value is not supported";
|
|
|
return context.AddInst(
|
|
|
- {value_parse_node,
|
|
|
+ {value_node_id,
|
|
|
SemIR::ClassInit{target.type_id, new_block.id(), target.init_id}});
|
|
|
} else if (is_init) {
|
|
|
target.init_block->InsertHere();
|
|
|
return context.AddInst(
|
|
|
- {value_parse_node,
|
|
|
+ {value_node_id,
|
|
|
SemIR::StructInit{target.type_id, new_block.id(), target.init_id}});
|
|
|
} else {
|
|
|
return context.AddInst(
|
|
|
- {value_parse_node, SemIR::StructValue{target.type_id, new_block.id()}});
|
|
|
+ {value_node_id, SemIR::StructValue{target.type_id, new_block.id()}});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -570,7 +569,7 @@ static auto ConvertStructToClass(Context& context, SemIR::StructType src_type,
|
|
|
target.kind = ConversionTarget::Initializer;
|
|
|
target.init_block = &target_block;
|
|
|
target.init_id =
|
|
|
- target_block.AddInst({context.insts().GetParseNode(value_id),
|
|
|
+ target_block.AddInst({context.insts().GetNodeId(value_id),
|
|
|
SemIR::TemporaryStorage{target.type_id}});
|
|
|
}
|
|
|
|
|
|
@@ -580,7 +579,7 @@ static auto ConvertStructToClass(Context& context, SemIR::StructType src_type,
|
|
|
if (need_temporary) {
|
|
|
target_block.InsertHere();
|
|
|
result_id = context.AddInst(
|
|
|
- {context.insts().GetParseNode(value_id),
|
|
|
+ {context.insts().GetNodeId(value_id),
|
|
|
SemIR::Temporary{target.type_id, target.init_id, result_id}});
|
|
|
}
|
|
|
return result_id;
|
|
|
@@ -627,7 +626,7 @@ static auto ComputeInheritancePath(Context& context, SemIR::TypeId derived_id,
|
|
|
|
|
|
// Performs a conversion from a derived class value or reference to a base class
|
|
|
// value or reference.
|
|
|
-static auto ConvertDerivedToBase(Context& context, Parse::NodeId parse_node,
|
|
|
+static auto ConvertDerivedToBase(Context& context, Parse::NodeId node_id,
|
|
|
SemIR::InstId value_id,
|
|
|
const InheritancePath& path) -> SemIR::InstId {
|
|
|
// Materialize a temporary if necessary.
|
|
|
@@ -637,27 +636,27 @@ static auto ConvertDerivedToBase(Context& context, Parse::NodeId parse_node,
|
|
|
for (auto base_id : path) {
|
|
|
auto base_decl = context.insts().GetAs<SemIR::BaseDecl>(base_id);
|
|
|
value_id = context.AddInst(
|
|
|
- {parse_node, SemIR::ClassElementAccess{base_decl.base_type_id, value_id,
|
|
|
- base_decl.index}});
|
|
|
+ {node_id, SemIR::ClassElementAccess{base_decl.base_type_id, value_id,
|
|
|
+ base_decl.index}});
|
|
|
}
|
|
|
return value_id;
|
|
|
}
|
|
|
|
|
|
// Performs a conversion from a derived class pointer to a base class pointer.
|
|
|
static auto ConvertDerivedPointerToBasePointer(
|
|
|
- Context& context, Parse::NodeId parse_node, SemIR::PointerType src_ptr_type,
|
|
|
+ Context& context, Parse::NodeId node_id, SemIR::PointerType src_ptr_type,
|
|
|
SemIR::TypeId dest_ptr_type_id, SemIR::InstId ptr_id,
|
|
|
const InheritancePath& path) -> SemIR::InstId {
|
|
|
// Form `*p`.
|
|
|
ptr_id = ConvertToValueExpr(context, ptr_id);
|
|
|
- auto ref_id = context.AddInst(
|
|
|
- {parse_node, SemIR::Deref{src_ptr_type.pointee_id, ptr_id}});
|
|
|
+ auto ref_id =
|
|
|
+ context.AddInst({node_id, SemIR::Deref{src_ptr_type.pointee_id, ptr_id}});
|
|
|
|
|
|
// Convert as a reference expression.
|
|
|
- ref_id = ConvertDerivedToBase(context, parse_node, ref_id, path);
|
|
|
+ ref_id = ConvertDerivedToBase(context, node_id, ref_id, path);
|
|
|
|
|
|
// Take the address.
|
|
|
- return context.AddInst({parse_node, SemIR::AddrOf{dest_ptr_type_id, ref_id}});
|
|
|
+ return context.AddInst({node_id, SemIR::AddrOf{dest_ptr_type_id, ref_id}});
|
|
|
}
|
|
|
|
|
|
// Returns whether `category` is a valid expression category to produce as a
|
|
|
@@ -682,7 +681,7 @@ static auto IsValidExprCategoryForConversionTarget(
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static auto PerformBuiltinConversion(Context& context, Parse::NodeId parse_node,
|
|
|
+static auto PerformBuiltinConversion(Context& context, Parse::NodeId node_id,
|
|
|
SemIR::InstId value_id,
|
|
|
ConversionTarget target) -> SemIR::InstId {
|
|
|
auto& sem_ir = context.sem_ir();
|
|
|
@@ -740,7 +739,7 @@ static auto PerformBuiltinConversion(Context& context, Parse::NodeId parse_node,
|
|
|
// value representation is a copy of the object representation, so we
|
|
|
// already have a value of the right form.
|
|
|
return context.AddInst(
|
|
|
- {parse_node, SemIR::ValueOfInitializer{value_type_id, value_id}});
|
|
|
+ {node_id, SemIR::ValueOfInitializer{value_type_id, value_id}});
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -791,7 +790,7 @@ static auto PerformBuiltinConversion(Context& context, Parse::NodeId parse_node,
|
|
|
if (auto path =
|
|
|
ComputeInheritancePath(context, value_type_id, target.type_id);
|
|
|
path && !path->empty()) {
|
|
|
- return ConvertDerivedToBase(context, parse_node, value_id, *path);
|
|
|
+ return ConvertDerivedToBase(context, node_id, value_id, *path);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -804,7 +803,7 @@ static auto PerformBuiltinConversion(Context& context, Parse::NodeId parse_node,
|
|
|
target_pointer_type->pointee_id);
|
|
|
path && !path->empty()) {
|
|
|
return ConvertDerivedPointerToBasePointer(
|
|
|
- context, parse_node, *src_pointer_type, target.type_id, value_id,
|
|
|
+ context, node_id, *src_pointer_type, target.type_id, value_id,
|
|
|
*path);
|
|
|
}
|
|
|
}
|
|
|
@@ -819,7 +818,7 @@ static auto PerformBuiltinConversion(Context& context, Parse::NodeId parse_node,
|
|
|
sem_ir.inst_blocks().Get(tuple_literal->elements_id)) {
|
|
|
// TODO: This call recurses back into conversion. Switch to an
|
|
|
// iterative approach.
|
|
|
- type_ids.push_back(ExprAsType(context, parse_node, tuple_inst_id));
|
|
|
+ type_ids.push_back(ExprAsType(context, node_id, tuple_inst_id));
|
|
|
}
|
|
|
auto tuple_type_id = context.GetTupleType(type_ids);
|
|
|
return sem_ir.types().GetInstId(tuple_type_id);
|
|
|
@@ -843,7 +842,7 @@ static auto PerformBuiltinConversion(Context& context, Parse::NodeId parse_node,
|
|
|
// combining the above conversions and this one in a single conversion.
|
|
|
if (sem_ir.types().Is<SemIR::InterfaceType>(value_type_id)) {
|
|
|
return context.AddInst(
|
|
|
- {parse_node, SemIR::FacetTypeAccess{target.type_id, value_id}});
|
|
|
+ {node_id, SemIR::FacetTypeAccess{target.type_id, value_id}});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -880,7 +879,7 @@ static auto PerformCopy(Context& context, SemIR::InstId expr_id)
|
|
|
return SemIR::InstId::BuiltinError;
|
|
|
}
|
|
|
|
|
|
-auto Convert(Context& context, Parse::NodeId parse_node, SemIR::InstId expr_id,
|
|
|
+auto Convert(Context& context, Parse::NodeId node_id, SemIR::InstId expr_id,
|
|
|
ConversionTarget target) -> SemIR::InstId {
|
|
|
auto& sem_ir = context.sem_ir();
|
|
|
auto orig_expr_id = expr_id;
|
|
|
@@ -913,7 +912,7 @@ auto Convert(Context& context, Parse::NodeId parse_node, SemIR::InstId expr_id,
|
|
|
CARBON_DIAGNOSTIC(IncompleteTypeInConversion, Error,
|
|
|
"Invalid use of incomplete type `{0}`.",
|
|
|
SemIR::TypeId);
|
|
|
- return context.emitter().Build(parse_node,
|
|
|
+ return context.emitter().Build(node_id,
|
|
|
target.is_initializer()
|
|
|
? IncompleteTypeInInit
|
|
|
: target.kind == ConversionTarget::Value
|
|
|
@@ -925,7 +924,7 @@ auto Convert(Context& context, Parse::NodeId parse_node, SemIR::InstId expr_id,
|
|
|
}
|
|
|
|
|
|
// Check whether any builtin conversion applies.
|
|
|
- expr_id = PerformBuiltinConversion(context, parse_node, expr_id, target);
|
|
|
+ expr_id = PerformBuiltinConversion(context, node_id, expr_id, target);
|
|
|
if (expr_id == SemIR::InstId::BuiltinError) {
|
|
|
return expr_id;
|
|
|
}
|
|
|
@@ -942,7 +941,7 @@ auto Convert(Context& context, Parse::NodeId parse_node, SemIR::InstId expr_id,
|
|
|
"Cannot convert from `{0}` to `{1}` with `as`.",
|
|
|
SemIR::TypeId, SemIR::TypeId);
|
|
|
context.emitter()
|
|
|
- .Build(parse_node,
|
|
|
+ .Build(node_id,
|
|
|
target.kind == ConversionTarget::ExplicitAs
|
|
|
? ExplicitAsConversionFailure
|
|
|
: ImplicitAsConversionFailure,
|
|
|
@@ -954,7 +953,7 @@ auto Convert(Context& context, Parse::NodeId parse_node, SemIR::InstId expr_id,
|
|
|
// Track that we performed a type conversion, if we did so.
|
|
|
if (orig_expr_id != expr_id) {
|
|
|
expr_id = context.AddInst(
|
|
|
- {context.insts().GetParseNode(orig_expr_id),
|
|
|
+ {context.insts().GetNodeId(orig_expr_id),
|
|
|
SemIR::Converted{target.type_id, orig_expr_id, expr_id}});
|
|
|
}
|
|
|
|
|
|
@@ -1005,7 +1004,7 @@ auto Convert(Context& context, Parse::NodeId parse_node, SemIR::InstId expr_id,
|
|
|
|
|
|
// If we have a reference and don't want one, form a value binding.
|
|
|
// TODO: Support types with custom value representations.
|
|
|
- expr_id = context.AddInst({context.insts().GetParseNode(expr_id),
|
|
|
+ expr_id = context.AddInst({context.insts().GetNodeId(expr_id),
|
|
|
SemIR::BindValue{expr.type_id(), expr_id}});
|
|
|
// We now have a value expression.
|
|
|
[[fallthrough]];
|
|
|
@@ -1024,7 +1023,7 @@ auto Convert(Context& context, Parse::NodeId parse_node, SemIR::InstId expr_id,
|
|
|
init_rep.kind == SemIR::InitRepr::ByCopy) {
|
|
|
target.init_block->InsertHere();
|
|
|
expr_id = context.AddInst(
|
|
|
- {parse_node,
|
|
|
+ {node_id,
|
|
|
SemIR::InitializeFrom{target.type_id, expr_id, target.init_id}});
|
|
|
}
|
|
|
}
|
|
|
@@ -1032,11 +1031,11 @@ auto Convert(Context& context, Parse::NodeId parse_node, SemIR::InstId expr_id,
|
|
|
return expr_id;
|
|
|
}
|
|
|
|
|
|
-auto Initialize(Context& context, Parse::NodeId parse_node,
|
|
|
+auto Initialize(Context& context, Parse::NodeId node_id,
|
|
|
SemIR::InstId target_id, SemIR::InstId value_id)
|
|
|
-> SemIR::InstId {
|
|
|
PendingBlock target_block(context);
|
|
|
- return Convert(context, parse_node, value_id,
|
|
|
+ return Convert(context, node_id, value_id,
|
|
|
{.kind = ConversionTarget::Initializer,
|
|
|
.type_id = context.insts().Get(target_id).type_id(),
|
|
|
.init_id = target_id,
|
|
|
@@ -1045,36 +1044,36 @@ auto Initialize(Context& context, Parse::NodeId parse_node,
|
|
|
|
|
|
auto ConvertToValueExpr(Context& context, SemIR::InstId expr_id)
|
|
|
-> SemIR::InstId {
|
|
|
- return Convert(context, context.insts().GetParseNode(expr_id), expr_id,
|
|
|
+ return Convert(context, context.insts().GetNodeId(expr_id), expr_id,
|
|
|
{.kind = ConversionTarget::Value,
|
|
|
.type_id = context.insts().Get(expr_id).type_id()});
|
|
|
}
|
|
|
|
|
|
auto ConvertToValueOrRefExpr(Context& context, SemIR::InstId expr_id)
|
|
|
-> SemIR::InstId {
|
|
|
- return Convert(context, context.insts().GetParseNode(expr_id), expr_id,
|
|
|
+ return Convert(context, context.insts().GetNodeId(expr_id), expr_id,
|
|
|
{.kind = ConversionTarget::ValueOrRef,
|
|
|
.type_id = context.insts().Get(expr_id).type_id()});
|
|
|
}
|
|
|
|
|
|
-auto ConvertToValueOfType(Context& context, Parse::NodeId parse_node,
|
|
|
+auto ConvertToValueOfType(Context& context, Parse::NodeId node_id,
|
|
|
SemIR::InstId expr_id, SemIR::TypeId type_id)
|
|
|
-> SemIR::InstId {
|
|
|
- return Convert(context, parse_node, expr_id,
|
|
|
+ return Convert(context, node_id, expr_id,
|
|
|
{.kind = ConversionTarget::Value, .type_id = type_id});
|
|
|
}
|
|
|
|
|
|
-auto ConvertToValueOrRefOfType(Context& context, Parse::NodeId parse_node,
|
|
|
+auto ConvertToValueOrRefOfType(Context& context, Parse::NodeId node_id,
|
|
|
SemIR::InstId expr_id, SemIR::TypeId type_id)
|
|
|
-> SemIR::InstId {
|
|
|
- return Convert(context, parse_node, expr_id,
|
|
|
+ return Convert(context, node_id, expr_id,
|
|
|
{.kind = ConversionTarget::ValueOrRef, .type_id = type_id});
|
|
|
}
|
|
|
|
|
|
-auto ConvertToBoolValue(Context& context, Parse::NodeId parse_node,
|
|
|
+auto ConvertToBoolValue(Context& context, Parse::NodeId node_id,
|
|
|
SemIR::InstId value_id) -> SemIR::InstId {
|
|
|
return ConvertToValueOfType(
|
|
|
- context, parse_node, value_id,
|
|
|
+ context, node_id, value_id,
|
|
|
context.GetBuiltinType(SemIR::BuiltinKind::BoolType));
|
|
|
}
|
|
|
|
|
|
@@ -1088,7 +1087,7 @@ auto ConvertForExplicitAs(Context& context, Parse::NodeId as_node,
|
|
|
CARBON_DIAGNOSTIC(InCallToFunction, Note, "Calling function declared here.");
|
|
|
|
|
|
// Convert the object argument in a method call to match the `self` parameter.
|
|
|
-static auto ConvertSelf(Context& context, Parse::NodeId call_parse_node,
|
|
|
+static auto ConvertSelf(Context& context, Parse::NodeId call_node_id,
|
|
|
SemIR::InstId callee_id,
|
|
|
std::optional<SemIR::AddrPattern> addr_pattern,
|
|
|
SemIR::InstId self_param_id, SemIR::Param self_param,
|
|
|
@@ -1097,7 +1096,7 @@ static auto ConvertSelf(Context& context, Parse::NodeId call_parse_node,
|
|
|
CARBON_DIAGNOSTIC(MissingObjectInMethodCall, Error,
|
|
|
"Missing object argument in method call.");
|
|
|
context.emitter()
|
|
|
- .Build(call_parse_node, MissingObjectInMethodCall)
|
|
|
+ .Build(call_node_id, MissingObjectInMethodCall)
|
|
|
.Note(callee_id, InCallToFunction)
|
|
|
.Emit();
|
|
|
return SemIR::InstId::BuiltinError;
|
|
|
@@ -1127,20 +1126,20 @@ static auto ConvertSelf(Context& context, Parse::NodeId call_parse_node,
|
|
|
default:
|
|
|
CARBON_DIAGNOSTIC(AddrSelfIsNonRef, Error,
|
|
|
"`addr self` method cannot be invoked on a value.");
|
|
|
- context.emitter().Emit(TokenOnly(call_parse_node), AddrSelfIsNonRef);
|
|
|
+ context.emitter().Emit(TokenOnly(call_node_id), AddrSelfIsNonRef);
|
|
|
return SemIR::InstId::BuiltinError;
|
|
|
}
|
|
|
- auto parse_node = context.insts().GetParseNode(self_or_addr_id);
|
|
|
+ auto node_id = context.insts().GetNodeId(self_or_addr_id);
|
|
|
self_or_addr_id = context.AddInst(
|
|
|
- {parse_node, SemIR::AddrOf{context.GetPointerType(self.type_id()),
|
|
|
- self_or_addr_id}});
|
|
|
+ {node_id, SemIR::AddrOf{context.GetPointerType(self.type_id()),
|
|
|
+ self_or_addr_id}});
|
|
|
}
|
|
|
|
|
|
- return ConvertToValueOfType(context, call_parse_node, self_or_addr_id,
|
|
|
+ return ConvertToValueOfType(context, call_node_id, self_or_addr_id,
|
|
|
self_param.type_id);
|
|
|
}
|
|
|
|
|
|
-auto ConvertCallArgs(Context& context, Parse::NodeId call_parse_node,
|
|
|
+auto ConvertCallArgs(Context& context, Parse::NodeId call_node_id,
|
|
|
SemIR::InstId self_id,
|
|
|
llvm::ArrayRef<SemIR::InstId> arg_refs,
|
|
|
SemIR::InstId return_storage_id, SemIR::InstId callee_id,
|
|
|
@@ -1156,7 +1155,7 @@ auto ConvertCallArgs(Context& context, Parse::NodeId call_parse_node,
|
|
|
"{1} argument(s).",
|
|
|
int, int);
|
|
|
context.emitter()
|
|
|
- .Build(call_parse_node, CallArgCountMismatch, arg_refs.size(),
|
|
|
+ .Build(call_node_id, CallArgCountMismatch, arg_refs.size(),
|
|
|
param_refs.size())
|
|
|
.Note(callee_id, InCallToFunction)
|
|
|
.Emit();
|
|
|
@@ -1176,15 +1175,15 @@ auto ConvertCallArgs(Context& context, Parse::NodeId call_parse_node,
|
|
|
context.sem_ir(), implicit_param_id);
|
|
|
if (param.name_id == SemIR::NameId::SelfValue) {
|
|
|
auto converted_self_id =
|
|
|
- ConvertSelf(context, call_parse_node, callee_id, addr_pattern,
|
|
|
- param_id, param, self_id);
|
|
|
+ ConvertSelf(context, call_node_id, callee_id, addr_pattern, param_id,
|
|
|
+ param, self_id);
|
|
|
if (converted_self_id == SemIR::InstId::BuiltinError) {
|
|
|
return SemIR::InstBlockId::Invalid;
|
|
|
}
|
|
|
args.push_back(converted_self_id);
|
|
|
} else {
|
|
|
// TODO: Form argument values for implicit parameters.
|
|
|
- context.TODO(call_parse_node, "Call with implicit parameters");
|
|
|
+ context.TODO(call_node_id, "Call with implicit parameters");
|
|
|
return SemIR::InstBlockId::Invalid;
|
|
|
}
|
|
|
}
|
|
|
@@ -1206,7 +1205,7 @@ auto ConvertCallArgs(Context& context, Parse::NodeId call_parse_node,
|
|
|
// TODO: Convert to the proper expression category. For now, we assume
|
|
|
// parameters are all `let` bindings.
|
|
|
auto converted_arg_id =
|
|
|
- ConvertToValueOfType(context, call_parse_node, arg_id, param_type_id);
|
|
|
+ ConvertToValueOfType(context, call_node_id, arg_id, param_type_id);
|
|
|
if (converted_arg_id == SemIR::InstId::BuiltinError) {
|
|
|
return SemIR::InstBlockId::Invalid;
|
|
|
}
|
|
|
@@ -1222,10 +1221,10 @@ auto ConvertCallArgs(Context& context, Parse::NodeId call_parse_node,
|
|
|
return context.inst_blocks().Add(args);
|
|
|
}
|
|
|
|
|
|
-auto ExprAsType(Context& context, Parse::NodeId parse_node,
|
|
|
- SemIR::InstId value_id) -> SemIR::TypeId {
|
|
|
- auto type_inst_id = ConvertToValueOfType(context, parse_node, value_id,
|
|
|
- SemIR::TypeId::TypeType);
|
|
|
+auto ExprAsType(Context& context, Parse::NodeId node_id, SemIR::InstId value_id)
|
|
|
+ -> SemIR::TypeId {
|
|
|
+ auto type_inst_id =
|
|
|
+ ConvertToValueOfType(context, node_id, value_id, SemIR::TypeId::TypeType);
|
|
|
if (type_inst_id == SemIR::InstId::BuiltinError) {
|
|
|
return SemIR::TypeId::Error;
|
|
|
}
|
|
|
@@ -1234,7 +1233,7 @@ auto ExprAsType(Context& context, Parse::NodeId parse_node,
|
|
|
if (!type_const_id.is_constant()) {
|
|
|
CARBON_DIAGNOSTIC(TypeExprEvaluationFailure, Error,
|
|
|
"Cannot evaluate type expression.");
|
|
|
- context.emitter().Emit(parse_node, TypeExprEvaluationFailure);
|
|
|
+ context.emitter().Emit(node_id, TypeExprEvaluationFailure);
|
|
|
return SemIR::TypeId::Error;
|
|
|
}
|
|
|
|