|
|
@@ -13,7 +13,7 @@
|
|
|
#include "toolchain/diagnostics/diagnostic_kind.h"
|
|
|
#include "toolchain/parse/node_kind.h"
|
|
|
#include "toolchain/sem_ir/file.h"
|
|
|
-#include "toolchain/sem_ir/node.h"
|
|
|
+#include "toolchain/sem_ir/inst.h"
|
|
|
#include "toolchain/sem_ir/node_kind.h"
|
|
|
|
|
|
namespace Carbon::Check {
|
|
|
@@ -22,12 +22,12 @@ namespace Carbon::Check {
|
|
|
// there is no return slot, because the initialization is not performed in
|
|
|
// place.
|
|
|
static auto FindReturnSlotForInitializer(SemIR::File& sem_ir,
|
|
|
- SemIR::NodeId init_id)
|
|
|
- -> SemIR::NodeId {
|
|
|
- SemIR::Node init = sem_ir.nodes().Get(init_id);
|
|
|
+ SemIR::InstId init_id)
|
|
|
+ -> SemIR::InstId {
|
|
|
+ SemIR::Inst init = sem_ir.insts().Get(init_id);
|
|
|
switch (init.kind()) {
|
|
|
default:
|
|
|
- CARBON_FATAL() << "Initialization from unexpected node " << init;
|
|
|
+ CARBON_FATAL() << "Initialization from unexpected inst " << init;
|
|
|
|
|
|
case SemIR::StructInit::Kind:
|
|
|
case SemIR::TupleInit::Kind:
|
|
|
@@ -44,13 +44,13 @@ static auto FindReturnSlotForInitializer(SemIR::File& sem_ir,
|
|
|
auto call = init.As<SemIR::Call>();
|
|
|
if (!SemIR::GetInitializingRepresentation(sem_ir, call.type_id)
|
|
|
.has_return_slot()) {
|
|
|
- return SemIR::NodeId::Invalid;
|
|
|
+ return SemIR::InstId::Invalid;
|
|
|
}
|
|
|
- return sem_ir.node_blocks().Get(call.args_id).back();
|
|
|
+ return sem_ir.inst_blocks().Get(call.args_id).back();
|
|
|
}
|
|
|
|
|
|
case SemIR::ArrayInit::Kind: {
|
|
|
- return sem_ir.node_blocks()
|
|
|
+ return sem_ir.inst_blocks()
|
|
|
.Get(init.As<SemIR::ArrayInit>().inits_and_return_slot_id)
|
|
|
.back();
|
|
|
}
|
|
|
@@ -58,17 +58,17 @@ static auto FindReturnSlotForInitializer(SemIR::File& sem_ir,
|
|
|
}
|
|
|
|
|
|
// Marks the initializer `init_id` as initializing `target_id`.
|
|
|
-static auto MarkInitializerFor(SemIR::File& sem_ir, SemIR::NodeId init_id,
|
|
|
- SemIR::NodeId target_id,
|
|
|
+static auto MarkInitializerFor(SemIR::File& sem_ir, SemIR::InstId init_id,
|
|
|
+ SemIR::InstId target_id,
|
|
|
PendingBlock& target_block) -> void {
|
|
|
auto return_slot_id = FindReturnSlotForInitializer(sem_ir, init_id);
|
|
|
if (return_slot_id.is_valid()) {
|
|
|
// Replace the temporary in the return slot with a reference to our target.
|
|
|
- CARBON_CHECK(sem_ir.nodes().Get(return_slot_id).kind() ==
|
|
|
+ CARBON_CHECK(sem_ir.insts().Get(return_slot_id).kind() ==
|
|
|
SemIR::TemporaryStorage::Kind)
|
|
|
<< "Return slot for initializer does not contain a temporary; "
|
|
|
<< "initialized multiple times? Have "
|
|
|
- << sem_ir.nodes().Get(return_slot_id);
|
|
|
+ << sem_ir.insts().Get(return_slot_id);
|
|
|
target_block.MergeReplacing(return_slot_id, target_id);
|
|
|
}
|
|
|
}
|
|
|
@@ -77,44 +77,44 @@ static auto MarkInitializerFor(SemIR::File& sem_ir, SemIR::NodeId init_id,
|
|
|
// expression described by `init_id`, and returns the location of the
|
|
|
// temporary. If `discarded` is `true`, the result is discarded, and no
|
|
|
// temporary will be created if possible; if no temporary is created, the
|
|
|
-// return value will be `SemIR::NodeId::Invalid`.
|
|
|
-static auto FinalizeTemporary(Context& context, SemIR::NodeId init_id,
|
|
|
- bool discarded) -> SemIR::NodeId {
|
|
|
+// return value will be `SemIR::InstId::Invalid`.
|
|
|
+static auto FinalizeTemporary(Context& context, SemIR::InstId init_id,
|
|
|
+ bool discarded) -> SemIR::InstId {
|
|
|
auto& sem_ir = context.sem_ir();
|
|
|
auto return_slot_id = FindReturnSlotForInitializer(sem_ir, init_id);
|
|
|
if (return_slot_id.is_valid()) {
|
|
|
// The return slot should already have a materialized temporary in it.
|
|
|
- CARBON_CHECK(sem_ir.nodes().Get(return_slot_id).kind() ==
|
|
|
+ CARBON_CHECK(sem_ir.insts().Get(return_slot_id).kind() ==
|
|
|
SemIR::TemporaryStorage::Kind)
|
|
|
<< "Return slot for initializer does not contain a temporary; "
|
|
|
<< "initialized multiple times? Have "
|
|
|
- << sem_ir.nodes().Get(return_slot_id);
|
|
|
- auto init = sem_ir.nodes().Get(init_id);
|
|
|
- return context.AddNode(SemIR::Temporary{init.parse_node(), init.type_id(),
|
|
|
+ << sem_ir.insts().Get(return_slot_id);
|
|
|
+ auto init = sem_ir.insts().Get(init_id);
|
|
|
+ return context.AddInst(SemIR::Temporary{init.parse_node(), init.type_id(),
|
|
|
return_slot_id, init_id});
|
|
|
}
|
|
|
|
|
|
if (discarded) {
|
|
|
// Don't invent a temporary that we're going to discard.
|
|
|
- return SemIR::NodeId::Invalid;
|
|
|
+ return SemIR::InstId::Invalid;
|
|
|
}
|
|
|
|
|
|
// The initializer has no return slot, but we want to produce a temporary
|
|
|
// object. Materialize one now.
|
|
|
// TODO: Consider using an invalid ID to mean that we immediately
|
|
|
// materialize and initialize a temporary, rather than two separate
|
|
|
- // nodes.
|
|
|
- auto init = sem_ir.nodes().Get(init_id);
|
|
|
- auto temporary_id = context.AddNode(
|
|
|
+ // instructions.
|
|
|
+ auto init = sem_ir.insts().Get(init_id);
|
|
|
+ auto temporary_id = context.AddInst(
|
|
|
SemIR::TemporaryStorage{init.parse_node(), init.type_id()});
|
|
|
- return context.AddNode(SemIR::Temporary{init.parse_node(), init.type_id(),
|
|
|
+ return context.AddInst(SemIR::Temporary{init.parse_node(), init.type_id(),
|
|
|
temporary_id, init_id});
|
|
|
}
|
|
|
|
|
|
// Materialize a temporary to hold the result of the given expression if it is
|
|
|
// an initializing expression.
|
|
|
-static auto MaterializeIfInitializing(Context& context, SemIR::NodeId expr_id)
|
|
|
- -> SemIR::NodeId {
|
|
|
+static auto MaterializeIfInitializing(Context& context, SemIR::InstId expr_id)
|
|
|
+ -> SemIR::InstId {
|
|
|
if (GetExpressionCategory(context.sem_ir(), expr_id) ==
|
|
|
SemIR::ExpressionCategory::Initializing) {
|
|
|
return FinalizeTemporary(context, expr_id, /*discarded=*/false);
|
|
|
@@ -122,23 +122,23 @@ static auto MaterializeIfInitializing(Context& context, SemIR::NodeId expr_id)
|
|
|
return expr_id;
|
|
|
}
|
|
|
|
|
|
-// Creates and adds a node to perform element access into an aggregate.
|
|
|
-template <typename AccessNodeT, typename NodeBlockT>
|
|
|
-static auto MakeElemAccessNode(Context& context, Parse::Node parse_node,
|
|
|
- SemIR::NodeId aggregate_id,
|
|
|
- SemIR::TypeId elem_type_id, NodeBlockT& block,
|
|
|
+// Creates and adds an instruction to perform element access into an aggregate.
|
|
|
+template <typename AccessInstT, typename InstBlockT>
|
|
|
+static auto MakeElemAccessInst(Context& context, Parse::Node parse_node,
|
|
|
+ SemIR::InstId aggregate_id,
|
|
|
+ SemIR::TypeId elem_type_id, InstBlockT& block,
|
|
|
std::size_t i) {
|
|
|
- if constexpr (std::is_same_v<AccessNodeT, SemIR::ArrayIndex>) {
|
|
|
- // TODO: Add a new node kind for indexing an array at a constant index
|
|
|
- // so that we don't need an integer literal node here, and remove this
|
|
|
- // special case.
|
|
|
- auto index_id = block.AddNode(SemIR::IntegerLiteral{
|
|
|
+ if constexpr (std::is_same_v<AccessInstT, SemIR::ArrayIndex>) {
|
|
|
+ // TODO: Add a new instruction kind for indexing an array at a constant
|
|
|
+ // index so that we don't need an integer literal instruction here, and
|
|
|
+ // remove this special case.
|
|
|
+ auto index_id = block.AddInst(SemIR::IntegerLiteral{
|
|
|
parse_node, context.GetBuiltinType(SemIR::BuiltinKind::IntegerType),
|
|
|
context.sem_ir().integers().Add(llvm::APInt(32, i))});
|
|
|
- return block.AddNode(
|
|
|
- AccessNodeT{parse_node, elem_type_id, aggregate_id, index_id});
|
|
|
+ return block.AddInst(
|
|
|
+ AccessInstT{parse_node, elem_type_id, aggregate_id, index_id});
|
|
|
} else {
|
|
|
- return block.AddNode(AccessNodeT{parse_node, elem_type_id, aggregate_id,
|
|
|
+ return block.AddInst(AccessInstT{parse_node, elem_type_id, aggregate_id,
|
|
|
SemIR::MemberIndex(i)});
|
|
|
}
|
|
|
}
|
|
|
@@ -147,29 +147,29 @@ static auto MakeElemAccessNode(Context& context, Parse::Node parse_node,
|
|
|
// another aggregate.
|
|
|
//
|
|
|
// For the source: `src_id` is the source aggregate, `src_elem_type` is the
|
|
|
-// element type, `i` is the index, and `SourceAccessNodeT` is the kind of node
|
|
|
-// used to access the source element.
|
|
|
+// element type, `i` is the index, and `SourceAccessInstT` is the kind of
|
|
|
+// instruction used to access the source element.
|
|
|
//
|
|
|
// For the target: `kind` is the kind of conversion or initialization,
|
|
|
// `target_elem_type` is the element type. For initialization, `target_id` is
|
|
|
// the destination, `target_block` is a pending block for target location
|
|
|
// calculations that will be spliced as the return slot of the initializer if
|
|
|
-// necessary, `i` is the index, and `TargetAccessNodeT` is the kind of node
|
|
|
-// used to access the destination element.
|
|
|
-template <typename SourceAccessNodeT, typename TargetAccessNodeT>
|
|
|
+// necessary, `i` is the index, and `TargetAccessInstT` is the kind of
|
|
|
+// instruction used to access the destination element.
|
|
|
+template <typename SourceAccessInstT, typename TargetAccessInstT>
|
|
|
static auto ConvertAggregateElement(
|
|
|
- Context& context, Parse::Node parse_node, SemIR::NodeId src_id,
|
|
|
+ Context& context, Parse::Node parse_node, SemIR::InstId src_id,
|
|
|
SemIR::TypeId src_elem_type,
|
|
|
- llvm::ArrayRef<SemIR::NodeId> src_literal_elems,
|
|
|
- ConversionTarget::Kind kind, SemIR::NodeId target_id,
|
|
|
+ llvm::ArrayRef<SemIR::InstId> src_literal_elems,
|
|
|
+ ConversionTarget::Kind kind, SemIR::InstId target_id,
|
|
|
SemIR::TypeId target_elem_type, PendingBlock* target_block, std::size_t i) {
|
|
|
// Compute the location of the source element. This goes into the current code
|
|
|
// block, not into the target block.
|
|
|
- // TODO: Ideally we would discard this node if it's unused.
|
|
|
+ // TODO: Ideally we would discard this instruction if it's unused.
|
|
|
auto src_elem_id =
|
|
|
!src_literal_elems.empty()
|
|
|
? src_literal_elems[i]
|
|
|
- : MakeElemAccessNode<SourceAccessNodeT>(context, parse_node, src_id,
|
|
|
+ : MakeElemAccessInst<SourceAccessInstT>(context, parse_node, src_id,
|
|
|
src_elem_type, context, i);
|
|
|
|
|
|
// If we're performing a conversion rather than an initialization, we won't
|
|
|
@@ -180,9 +180,9 @@ static auto ConvertAggregateElement(
|
|
|
}
|
|
|
|
|
|
// Compute the location of the target element and initialize it.
|
|
|
- PendingBlock::DiscardUnusedNodesScope scope(target_block);
|
|
|
+ PendingBlock::DiscardUnusedInstsScope scope(target_block);
|
|
|
target.init_block = target_block;
|
|
|
- target.init_id = MakeElemAccessNode<TargetAccessNodeT>(
|
|
|
+ target.init_id = MakeElemAccessInst<TargetAccessInstT>(
|
|
|
context, parse_node, target_id, target_elem_type, *target_block, i);
|
|
|
return Convert(context, parse_node, src_elem_id, target);
|
|
|
}
|
|
|
@@ -202,29 +202,29 @@ class CopyOnWriteBlock {
|
|
|
// Constructs the block. If `source_id` is valid, it is used as the initial
|
|
|
// value of the block. Otherwise, uninitialized storage for `size` elements
|
|
|
// is allocated.
|
|
|
- CopyOnWriteBlock(SemIR::File& file, SemIR::NodeBlockId source_id, size_t size)
|
|
|
+ CopyOnWriteBlock(SemIR::File& file, SemIR::InstBlockId source_id, size_t size)
|
|
|
: file_(file), source_id_(source_id) {
|
|
|
if (!source_id_.is_valid()) {
|
|
|
- id_ = file_.node_blocks().AddUninitialized(size);
|
|
|
+ id_ = file_.inst_blocks().AddUninitialized(size);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- auto id() -> SemIR::NodeBlockId const { return id_; }
|
|
|
+ auto id() -> SemIR::InstBlockId const { return id_; }
|
|
|
|
|
|
- auto Set(int i, SemIR::NodeId value) -> void {
|
|
|
- if (source_id_.is_valid() && file_.node_blocks().Get(id_)[i] == value) {
|
|
|
+ auto Set(int i, SemIR::InstId value) -> void {
|
|
|
+ if (source_id_.is_valid() && file_.inst_blocks().Get(id_)[i] == value) {
|
|
|
return;
|
|
|
}
|
|
|
if (id_ == source_id_) {
|
|
|
- id_ = file_.node_blocks().Add(file_.node_blocks().Get(source_id_));
|
|
|
+ id_ = file_.inst_blocks().Add(file_.inst_blocks().Get(source_id_));
|
|
|
}
|
|
|
- file_.node_blocks().Get(id_)[i] = value;
|
|
|
+ file_.inst_blocks().Get(id_)[i] = value;
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
SemIR::File& file_;
|
|
|
- SemIR::NodeBlockId source_id_;
|
|
|
- SemIR::NodeBlockId id_ = source_id_;
|
|
|
+ SemIR::InstBlockId source_id_;
|
|
|
+ SemIR::InstBlockId id_ = source_id_;
|
|
|
};
|
|
|
} // namespace
|
|
|
|
|
|
@@ -232,19 +232,19 @@ class CopyOnWriteBlock {
|
|
|
// final conversion to the requested expression category.
|
|
|
static auto ConvertTupleToArray(Context& context, SemIR::TupleType tuple_type,
|
|
|
SemIR::ArrayType array_type,
|
|
|
- SemIR::NodeId value_id, ConversionTarget target)
|
|
|
- -> SemIR::NodeId {
|
|
|
+ SemIR::InstId value_id, ConversionTarget target)
|
|
|
+ -> SemIR::InstId {
|
|
|
auto& sem_ir = context.sem_ir();
|
|
|
auto tuple_elem_types = sem_ir.type_blocks().Get(tuple_type.elements_id);
|
|
|
|
|
|
- auto value = sem_ir.nodes().Get(value_id);
|
|
|
+ auto value = sem_ir.insts().Get(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
|
|
|
// result.
|
|
|
- llvm::ArrayRef<SemIR::NodeId> literal_elems;
|
|
|
+ llvm::ArrayRef<SemIR::InstId> literal_elems;
|
|
|
if (auto tuple_literal = value.TryAs<SemIR::TupleLiteral>()) {
|
|
|
- literal_elems = sem_ir.node_blocks().Get(tuple_literal->elements_id);
|
|
|
+ literal_elems = sem_ir.inst_blocks().Get(tuple_literal->elements_id);
|
|
|
} else {
|
|
|
value_id = MaterializeIfInitializing(context, value_id);
|
|
|
}
|
|
|
@@ -265,7 +265,7 @@ static auto ConvertTupleToArray(Context& context, SemIR::TupleType tuple_type,
|
|
|
? ArrayInitFromExpressionArgCountMismatch
|
|
|
: ArrayInitFromLiteralArgCountMismatch,
|
|
|
array_bound, tuple_elem_types.size());
|
|
|
- return SemIR::NodeId::BuiltinError;
|
|
|
+ return SemIR::InstId::BuiltinError;
|
|
|
}
|
|
|
|
|
|
PendingBlock target_block_storage(context);
|
|
|
@@ -274,9 +274,9 @@ static auto ConvertTupleToArray(Context& context, SemIR::TupleType tuple_type,
|
|
|
|
|
|
// Arrays are always initialized in-place. Allocate a temporary as the
|
|
|
// destination for the array initialization if we weren't given one.
|
|
|
- SemIR::NodeId return_slot_id = target.init_id;
|
|
|
+ SemIR::InstId return_slot_id = target.init_id;
|
|
|
if (!target.init_id.is_valid()) {
|
|
|
- return_slot_id = target_block->AddNode(
|
|
|
+ return_slot_id = target_block->AddInst(
|
|
|
SemIR::TemporaryStorage{value.parse_node(), target.type_id});
|
|
|
}
|
|
|
|
|
|
@@ -284,7 +284,7 @@ static auto ConvertTupleToArray(Context& context, SemIR::TupleType tuple_type,
|
|
|
// tuple.
|
|
|
// TODO: Annotate diagnostics coming from here with the array element index,
|
|
|
// if initializing from a tuple literal.
|
|
|
- llvm::SmallVector<SemIR::NodeId> inits;
|
|
|
+ llvm::SmallVector<SemIR::InstId> inits;
|
|
|
inits.reserve(array_bound + 1);
|
|
|
for (auto [i, src_type_id] : llvm::enumerate(tuple_elem_types)) {
|
|
|
// TODO: This call recurses back into conversion. Switch to an iterative
|
|
|
@@ -294,8 +294,8 @@ static auto ConvertTupleToArray(Context& context, SemIR::TupleType tuple_type,
|
|
|
context, value.parse_node(), value_id, src_type_id, literal_elems,
|
|
|
ConversionTarget::FullInitializer, return_slot_id,
|
|
|
array_type.element_type_id, target_block, i);
|
|
|
- if (init_id == SemIR::NodeId::BuiltinError) {
|
|
|
- return SemIR::NodeId::BuiltinError;
|
|
|
+ if (init_id == SemIR::InstId::BuiltinError) {
|
|
|
+ return SemIR::InstId::BuiltinError;
|
|
|
}
|
|
|
inits.push_back(init_id);
|
|
|
}
|
|
|
@@ -305,31 +305,31 @@ static auto ConvertTupleToArray(Context& context, SemIR::TupleType tuple_type,
|
|
|
target_block->InsertHere();
|
|
|
inits.push_back(return_slot_id);
|
|
|
|
|
|
- return context.AddNode(SemIR::ArrayInit{value.parse_node(), target.type_id,
|
|
|
+ return context.AddInst(SemIR::ArrayInit{value.parse_node(), target.type_id,
|
|
|
value_id,
|
|
|
- sem_ir.node_blocks().Add(inits)});
|
|
|
+ sem_ir.inst_blocks().Add(inits)});
|
|
|
}
|
|
|
|
|
|
// Performs a conversion from a tuple to a tuple type. Does not perform a
|
|
|
// final conversion to the requested expression category.
|
|
|
static auto ConvertTupleToTuple(Context& context, SemIR::TupleType src_type,
|
|
|
SemIR::TupleType dest_type,
|
|
|
- SemIR::NodeId value_id, ConversionTarget target)
|
|
|
- -> SemIR::NodeId {
|
|
|
+ SemIR::InstId value_id, ConversionTarget target)
|
|
|
+ -> SemIR::InstId {
|
|
|
auto& sem_ir = context.sem_ir();
|
|
|
auto src_elem_types = sem_ir.type_blocks().Get(src_type.elements_id);
|
|
|
auto dest_elem_types = sem_ir.type_blocks().Get(dest_type.elements_id);
|
|
|
|
|
|
- auto value = sem_ir.nodes().Get(value_id);
|
|
|
+ auto value = sem_ir.insts().Get(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
|
|
|
// result.
|
|
|
- llvm::ArrayRef<SemIR::NodeId> literal_elems;
|
|
|
- auto literal_elems_id = SemIR::NodeBlockId::Invalid;
|
|
|
+ llvm::ArrayRef<SemIR::InstId> literal_elems;
|
|
|
+ auto literal_elems_id = SemIR::InstBlockId::Invalid;
|
|
|
if (auto tuple_literal = value.TryAs<SemIR::TupleLiteral>()) {
|
|
|
literal_elems_id = tuple_literal->elements_id;
|
|
|
- literal_elems = sem_ir.node_blocks().Get(literal_elems_id);
|
|
|
+ literal_elems = sem_ir.inst_blocks().Get(literal_elems_id);
|
|
|
} else {
|
|
|
value_id = MaterializeIfInitializing(context, value_id);
|
|
|
}
|
|
|
@@ -342,7 +342,7 @@ static auto ConvertTupleToTuple(Context& context, SemIR::TupleType src_type,
|
|
|
size_t, size_t);
|
|
|
context.emitter().Emit(value.parse_node(), TupleInitElementCountMismatch,
|
|
|
dest_elem_types.size(), src_elem_types.size());
|
|
|
- return SemIR::NodeId::BuiltinError;
|
|
|
+ return SemIR::InstId::BuiltinError;
|
|
|
}
|
|
|
|
|
|
// If we're forming an initializer, then we want an initializer for each
|
|
|
@@ -369,16 +369,16 @@ static auto ConvertTupleToTuple(Context& context, SemIR::TupleType src_type,
|
|
|
ConvertAggregateElement<SemIR::TupleAccess, SemIR::TupleAccess>(
|
|
|
context, value.parse_node(), value_id, src_type_id, literal_elems,
|
|
|
inner_kind, target.init_id, dest_type_id, target.init_block, i);
|
|
|
- if (init_id == SemIR::NodeId::BuiltinError) {
|
|
|
- return SemIR::NodeId::BuiltinError;
|
|
|
+ if (init_id == SemIR::InstId::BuiltinError) {
|
|
|
+ return SemIR::InstId::BuiltinError;
|
|
|
}
|
|
|
new_block.Set(i, init_id);
|
|
|
}
|
|
|
|
|
|
- return is_init ? context.AddNode(SemIR::TupleInit{value.parse_node(),
|
|
|
+ return is_init ? context.AddInst(SemIR::TupleInit{value.parse_node(),
|
|
|
target.type_id, value_id,
|
|
|
new_block.id()})
|
|
|
- : context.AddNode(SemIR::TupleValue{value.parse_node(),
|
|
|
+ : context.AddInst(SemIR::TupleValue{value.parse_node(),
|
|
|
target.type_id, value_id,
|
|
|
new_block.id()});
|
|
|
}
|
|
|
@@ -387,22 +387,22 @@ static auto ConvertTupleToTuple(Context& context, SemIR::TupleType src_type,
|
|
|
// final conversion to the requested expression category.
|
|
|
static auto ConvertStructToStruct(Context& context, SemIR::StructType src_type,
|
|
|
SemIR::StructType dest_type,
|
|
|
- SemIR::NodeId value_id,
|
|
|
- ConversionTarget target) -> SemIR::NodeId {
|
|
|
+ SemIR::InstId value_id,
|
|
|
+ ConversionTarget target) -> SemIR::InstId {
|
|
|
auto& sem_ir = context.sem_ir();
|
|
|
- auto src_elem_fields = sem_ir.node_blocks().Get(src_type.fields_id);
|
|
|
- auto dest_elem_fields = sem_ir.node_blocks().Get(dest_type.fields_id);
|
|
|
+ auto src_elem_fields = sem_ir.inst_blocks().Get(src_type.fields_id);
|
|
|
+ auto dest_elem_fields = sem_ir.inst_blocks().Get(dest_type.fields_id);
|
|
|
|
|
|
- auto value = sem_ir.nodes().Get(value_id);
|
|
|
+ auto value = sem_ir.insts().Get(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
|
|
|
// result.
|
|
|
- llvm::ArrayRef<SemIR::NodeId> literal_elems;
|
|
|
- auto literal_elems_id = SemIR::NodeBlockId::Invalid;
|
|
|
+ llvm::ArrayRef<SemIR::InstId> literal_elems;
|
|
|
+ auto literal_elems_id = SemIR::InstBlockId::Invalid;
|
|
|
if (auto struct_literal = value.TryAs<SemIR::StructLiteral>()) {
|
|
|
literal_elems_id = struct_literal->elements_id;
|
|
|
- literal_elems = sem_ir.node_blocks().Get(literal_elems_id);
|
|
|
+ literal_elems = sem_ir.inst_blocks().Get(literal_elems_id);
|
|
|
} else {
|
|
|
value_id = MaterializeIfInitializing(context, value_id);
|
|
|
}
|
|
|
@@ -417,7 +417,7 @@ static auto ConvertStructToStruct(Context& context, SemIR::StructType src_type,
|
|
|
size_t, size_t);
|
|
|
context.emitter().Emit(value.parse_node(), StructInitElementCountMismatch,
|
|
|
dest_elem_fields.size(), src_elem_fields.size());
|
|
|
- return SemIR::NodeId::BuiltinError;
|
|
|
+ return SemIR::InstId::BuiltinError;
|
|
|
}
|
|
|
|
|
|
// Prepare to look up fields in the source by index.
|
|
|
@@ -425,7 +425,7 @@ static auto ConvertStructToStruct(Context& context, SemIR::StructType src_type,
|
|
|
if (src_type.fields_id != dest_type.fields_id) {
|
|
|
for (auto [i, field_id] : llvm::enumerate(src_elem_fields)) {
|
|
|
auto [it, added] = src_field_indexes.insert(
|
|
|
- {context.nodes().GetAs<SemIR::StructTypeField>(field_id).name_id, i});
|
|
|
+ {context.insts().GetAs<SemIR::StructTypeField>(field_id).name_id, i});
|
|
|
CARBON_CHECK(added) << "Duplicate field in source structure";
|
|
|
}
|
|
|
}
|
|
|
@@ -448,7 +448,7 @@ static auto ConvertStructToStruct(Context& context, SemIR::StructType src_type,
|
|
|
CopyOnWriteBlock new_block(sem_ir, literal_elems_id, src_elem_fields.size());
|
|
|
for (auto [i, dest_field_id] : llvm::enumerate(dest_elem_fields)) {
|
|
|
auto dest_field =
|
|
|
- sem_ir.nodes().GetAs<SemIR::StructTypeField>(dest_field_id);
|
|
|
+ sem_ir.insts().GetAs<SemIR::StructTypeField>(dest_field_id);
|
|
|
|
|
|
// Find the matching source field.
|
|
|
auto src_field_index = i;
|
|
|
@@ -474,11 +474,11 @@ static auto ConvertStructToStruct(Context& context, SemIR::StructType src_type,
|
|
|
sem_ir.StringifyType(target.type_id),
|
|
|
sem_ir.strings().Get(dest_field.name_id));
|
|
|
}
|
|
|
- return SemIR::NodeId::BuiltinError;
|
|
|
+ return SemIR::InstId::BuiltinError;
|
|
|
}
|
|
|
src_field_index = src_field_it->second;
|
|
|
}
|
|
|
- auto src_field = sem_ir.nodes().GetAs<SemIR::StructTypeField>(
|
|
|
+ auto src_field = sem_ir.insts().GetAs<SemIR::StructTypeField>(
|
|
|
src_elem_fields[src_field_index]);
|
|
|
|
|
|
// TODO: This call recurses back into conversion. Switch to an iterative
|
|
|
@@ -488,16 +488,16 @@ static auto ConvertStructToStruct(Context& context, SemIR::StructType src_type,
|
|
|
context, value.parse_node(), 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::NodeId::BuiltinError) {
|
|
|
- return SemIR::NodeId::BuiltinError;
|
|
|
+ if (init_id == SemIR::InstId::BuiltinError) {
|
|
|
+ return SemIR::InstId::BuiltinError;
|
|
|
}
|
|
|
new_block.Set(i, init_id);
|
|
|
}
|
|
|
|
|
|
- return is_init ? context.AddNode(SemIR::StructInit{value.parse_node(),
|
|
|
+ return is_init ? context.AddInst(SemIR::StructInit{value.parse_node(),
|
|
|
target.type_id, value_id,
|
|
|
new_block.id()})
|
|
|
- : context.AddNode(SemIR::StructValue{value.parse_node(),
|
|
|
+ : context.AddInst(SemIR::StructValue{value.parse_node(),
|
|
|
target.type_id, value_id,
|
|
|
new_block.id()});
|
|
|
}
|
|
|
@@ -525,13 +525,13 @@ static bool IsValidExpressionCategoryForConversionTarget(
|
|
|
}
|
|
|
|
|
|
static auto PerformBuiltinConversion(Context& context, Parse::Node parse_node,
|
|
|
- SemIR::NodeId value_id,
|
|
|
- ConversionTarget target) -> SemIR::NodeId {
|
|
|
+ SemIR::InstId value_id,
|
|
|
+ ConversionTarget target) -> SemIR::InstId {
|
|
|
auto& sem_ir = context.sem_ir();
|
|
|
- auto value = sem_ir.nodes().Get(value_id);
|
|
|
+ auto value = sem_ir.insts().Get(value_id);
|
|
|
auto value_type_id = value.type_id();
|
|
|
- auto target_type_node =
|
|
|
- sem_ir.nodes().Get(sem_ir.GetTypeAllowBuiltinTypes(target.type_id));
|
|
|
+ auto target_type_inst =
|
|
|
+ sem_ir.insts().Get(sem_ir.GetTypeAllowBuiltinTypes(target.type_id));
|
|
|
|
|
|
// Various forms of implicit conversion are supported as builtin conversions,
|
|
|
// either in addition to or instead of `impl`s of `ImplicitAs` in the Carbon
|
|
|
@@ -582,7 +582,7 @@ static auto PerformBuiltinConversion(Context& context, Parse::Node parse_node,
|
|
|
// The initializer produces an object representation by copy, and the
|
|
|
// value representation is a copy of the object representation, so we
|
|
|
// already have a value of the right form.
|
|
|
- return context.AddNode(
|
|
|
+ return context.AddInst(
|
|
|
SemIR::ValueOfInitializer{parse_node, value_type_id, value_id});
|
|
|
}
|
|
|
}
|
|
|
@@ -590,10 +590,10 @@ static auto PerformBuiltinConversion(Context& context, Parse::Node parse_node,
|
|
|
|
|
|
// A tuple (T1, T2, ..., Tn) converts to (U1, U2, ..., Un) if each Ti
|
|
|
// converts to Ui.
|
|
|
- if (auto target_tuple_type = target_type_node.TryAs<SemIR::TupleType>()) {
|
|
|
- auto value_type_node =
|
|
|
- sem_ir.nodes().Get(sem_ir.GetTypeAllowBuiltinTypes(value_type_id));
|
|
|
- if (auto src_tuple_type = value_type_node.TryAs<SemIR::TupleType>()) {
|
|
|
+ if (auto target_tuple_type = target_type_inst.TryAs<SemIR::TupleType>()) {
|
|
|
+ auto value_type_inst =
|
|
|
+ sem_ir.insts().Get(sem_ir.GetTypeAllowBuiltinTypes(value_type_id));
|
|
|
+ if (auto src_tuple_type = value_type_inst.TryAs<SemIR::TupleType>()) {
|
|
|
return ConvertTupleToTuple(context, *src_tuple_type, *target_tuple_type,
|
|
|
value_id, target);
|
|
|
}
|
|
|
@@ -603,20 +603,20 @@ static auto PerformBuiltinConversion(Context& context, Parse::Node parse_node,
|
|
|
// {.f_p(1): U_p(1), .f_p(2): U_p(2), ..., .f_p(n): U_p(n)} if
|
|
|
// (p(1), ..., p(n)) is a permutation of (1, ..., n) and each Ti converts
|
|
|
// to Ui.
|
|
|
- if (auto target_struct_type = target_type_node.TryAs<SemIR::StructType>()) {
|
|
|
- auto value_type_node =
|
|
|
- sem_ir.nodes().Get(sem_ir.GetTypeAllowBuiltinTypes(value_type_id));
|
|
|
- if (auto src_struct_type = value_type_node.TryAs<SemIR::StructType>()) {
|
|
|
+ if (auto target_struct_type = target_type_inst.TryAs<SemIR::StructType>()) {
|
|
|
+ auto value_type_inst =
|
|
|
+ sem_ir.insts().Get(sem_ir.GetTypeAllowBuiltinTypes(value_type_id));
|
|
|
+ if (auto src_struct_type = value_type_inst.TryAs<SemIR::StructType>()) {
|
|
|
return ConvertStructToStruct(context, *src_struct_type,
|
|
|
*target_struct_type, value_id, target);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// A tuple (T1, T2, ..., Tn) converts to [T; n] if each Ti converts to T.
|
|
|
- if (auto target_array_type = target_type_node.TryAs<SemIR::ArrayType>()) {
|
|
|
- auto value_type_node =
|
|
|
- sem_ir.nodes().Get(sem_ir.GetTypeAllowBuiltinTypes(value_type_id));
|
|
|
- if (auto src_tuple_type = value_type_node.TryAs<SemIR::TupleType>()) {
|
|
|
+ if (auto target_array_type = target_type_inst.TryAs<SemIR::ArrayType>()) {
|
|
|
+ auto value_type_inst =
|
|
|
+ sem_ir.insts().Get(sem_ir.GetTypeAllowBuiltinTypes(value_type_id));
|
|
|
+ if (auto src_tuple_type = value_type_inst.TryAs<SemIR::TupleType>()) {
|
|
|
return ConvertTupleToArray(context, *src_tuple_type, *target_array_type,
|
|
|
value_id, target);
|
|
|
}
|
|
|
@@ -627,12 +627,12 @@ static auto PerformBuiltinConversion(Context& context, Parse::Node parse_node,
|
|
|
// TODO: This should apply even for non-literal tuples.
|
|
|
if (auto tuple_literal = value.TryAs<SemIR::TupleLiteral>()) {
|
|
|
llvm::SmallVector<SemIR::TypeId> type_ids;
|
|
|
- for (auto tuple_node_id :
|
|
|
- sem_ir.node_blocks().Get(tuple_literal->elements_id)) {
|
|
|
+ for (auto tuple_inst_id :
|
|
|
+ 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(
|
|
|
- ExpressionAsType(context, parse_node, tuple_node_id));
|
|
|
+ ExpressionAsType(context, parse_node, tuple_inst_id));
|
|
|
}
|
|
|
auto tuple_type_id =
|
|
|
context.CanonicalizeTupleType(parse_node, std::move(type_ids));
|
|
|
@@ -644,7 +644,7 @@ static auto PerformBuiltinConversion(Context& context, Parse::Node parse_node,
|
|
|
// of type `{}`.
|
|
|
if (auto struct_literal = value.TryAs<SemIR::StructLiteral>();
|
|
|
struct_literal &&
|
|
|
- struct_literal->elements_id == SemIR::NodeBlockId::Empty) {
|
|
|
+ struct_literal->elements_id == SemIR::InstBlockId::Empty) {
|
|
|
value_id = sem_ir.GetTypeAllowBuiltinTypes(value_type_id);
|
|
|
}
|
|
|
}
|
|
|
@@ -655,12 +655,12 @@ static auto PerformBuiltinConversion(Context& context, Parse::Node parse_node,
|
|
|
|
|
|
// Given a value expression, form a corresponding initializer that copies from
|
|
|
// that value, if it is possible to do so.
|
|
|
-static auto PerformCopy(Context& context, SemIR::NodeId expr_id)
|
|
|
- -> SemIR::NodeId {
|
|
|
- auto expr = context.nodes().Get(expr_id);
|
|
|
+static auto PerformCopy(Context& context, SemIR::InstId expr_id)
|
|
|
+ -> SemIR::InstId {
|
|
|
+ auto expr = context.insts().Get(expr_id);
|
|
|
auto type_id = expr.type_id();
|
|
|
if (type_id == SemIR::TypeId::Error) {
|
|
|
- return SemIR::NodeId::BuiltinError;
|
|
|
+ return SemIR::InstId::BuiltinError;
|
|
|
}
|
|
|
|
|
|
// TODO: Directly track on the value representation whether it's a copy of
|
|
|
@@ -680,19 +680,19 @@ static auto PerformCopy(Context& context, SemIR::NodeId expr_id)
|
|
|
"Cannot copy value of type `{0}`.", std::string);
|
|
|
context.emitter().Emit(expr.parse_node(), CopyOfUncopyableType,
|
|
|
context.sem_ir().StringifyType(type_id));
|
|
|
- return SemIR::NodeId::BuiltinError;
|
|
|
+ return SemIR::InstId::BuiltinError;
|
|
|
}
|
|
|
|
|
|
-auto Convert(Context& context, Parse::Node parse_node, SemIR::NodeId expr_id,
|
|
|
- ConversionTarget target) -> SemIR::NodeId {
|
|
|
+auto Convert(Context& context, Parse::Node parse_node, SemIR::InstId expr_id,
|
|
|
+ ConversionTarget target) -> SemIR::InstId {
|
|
|
auto& sem_ir = context.sem_ir();
|
|
|
auto orig_expr_id = expr_id;
|
|
|
|
|
|
// Start by making sure both sides are valid. If any part is invalid, the
|
|
|
// result is invalid and we shouldn't error.
|
|
|
- if (sem_ir.nodes().Get(expr_id).type_id() == SemIR::TypeId::Error ||
|
|
|
+ if (sem_ir.insts().Get(expr_id).type_id() == SemIR::TypeId::Error ||
|
|
|
target.type_id == SemIR::TypeId::Error) {
|
|
|
- return SemIR::NodeId::BuiltinError;
|
|
|
+ return SemIR::InstId::BuiltinError;
|
|
|
}
|
|
|
|
|
|
if (SemIR::GetExpressionCategory(sem_ir, expr_id) ==
|
|
|
@@ -702,9 +702,9 @@ auto Convert(Context& context, Parse::Node parse_node, SemIR::NodeId expr_id,
|
|
|
// namespace names, and allow use of functions as values.
|
|
|
CARBON_DIAGNOSTIC(UseOfNonExpressionAsValue, Error,
|
|
|
"Expression cannot be used as a value.");
|
|
|
- context.emitter().Emit(sem_ir.nodes().Get(expr_id).parse_node(),
|
|
|
+ context.emitter().Emit(sem_ir.insts().Get(expr_id).parse_node(),
|
|
|
UseOfNonExpressionAsValue);
|
|
|
- return SemIR::NodeId::BuiltinError;
|
|
|
+ return SemIR::InstId::BuiltinError;
|
|
|
}
|
|
|
|
|
|
// We can only perform initialization for complete types.
|
|
|
@@ -725,19 +725,19 @@ auto Convert(Context& context, Parse::Node parse_node, SemIR::NodeId expr_id,
|
|
|
: IncompleteTypeInConversion,
|
|
|
context.sem_ir().StringifyType(target.type_id, true));
|
|
|
})) {
|
|
|
- return SemIR::NodeId::BuiltinError;
|
|
|
+ return SemIR::InstId::BuiltinError;
|
|
|
}
|
|
|
|
|
|
// Check whether any builtin conversion applies.
|
|
|
expr_id = PerformBuiltinConversion(context, parse_node, expr_id, target);
|
|
|
- if (expr_id == SemIR::NodeId::BuiltinError) {
|
|
|
+ if (expr_id == SemIR::InstId::BuiltinError) {
|
|
|
return expr_id;
|
|
|
}
|
|
|
|
|
|
// If the types don't match at this point, we can't perform the conversion.
|
|
|
// TODO: Look for an `ImplicitAs` impl, or an `As` impl in the case where
|
|
|
// `target.kind == ConversionTarget::ExplicitAs`.
|
|
|
- SemIR::Node expr = sem_ir.nodes().Get(expr_id);
|
|
|
+ SemIR::Inst expr = sem_ir.insts().Get(expr_id);
|
|
|
if (expr.type_id() != target.type_id) {
|
|
|
CARBON_DIAGNOSTIC(ImplicitAsConversionFailure, Error,
|
|
|
"Cannot implicitly convert from `{0}` to `{1}`.",
|
|
|
@@ -753,7 +753,7 @@ auto Convert(Context& context, Parse::Node parse_node, SemIR::NodeId expr_id,
|
|
|
sem_ir.StringifyType(expr.type_id()),
|
|
|
sem_ir.StringifyType(target.type_id))
|
|
|
.Emit();
|
|
|
- return SemIR::NodeId::BuiltinError;
|
|
|
+ return SemIR::InstId::BuiltinError;
|
|
|
}
|
|
|
|
|
|
// For `as`, don't perform any value category conversions. In particular, an
|
|
|
@@ -770,7 +770,7 @@ auto Convert(Context& context, Parse::Node parse_node, SemIR::NodeId expr_id,
|
|
|
<< " after builtin conversions";
|
|
|
|
|
|
case SemIR::ExpressionCategory::Error:
|
|
|
- return SemIR::NodeId::BuiltinError;
|
|
|
+ return SemIR::InstId::BuiltinError;
|
|
|
|
|
|
case SemIR::ExpressionCategory::Initializing:
|
|
|
if (target.is_initializer()) {
|
|
|
@@ -803,7 +803,7 @@ auto Convert(Context& context, Parse::Node parse_node, SemIR::NodeId 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.AddNode(
|
|
|
+ expr_id = context.AddInst(
|
|
|
SemIR::BindValue{expr.parse_node(), expr.type_id(), expr_id});
|
|
|
// We now have a value expression.
|
|
|
[[fallthrough]];
|
|
|
@@ -822,7 +822,7 @@ auto Convert(Context& context, Parse::Node parse_node, SemIR::NodeId expr_id,
|
|
|
SemIR::GetInitializingRepresentation(sem_ir, target.type_id);
|
|
|
init_rep.kind == SemIR::InitializingRepresentation::ByCopy) {
|
|
|
target.init_block->InsertHere();
|
|
|
- expr_id = context.AddNode(SemIR::InitializeFrom{
|
|
|
+ expr_id = context.AddInst(SemIR::InitializeFrom{
|
|
|
parse_node, target.type_id, expr_id, target.init_id});
|
|
|
}
|
|
|
}
|
|
|
@@ -831,49 +831,49 @@ auto Convert(Context& context, Parse::Node parse_node, SemIR::NodeId expr_id,
|
|
|
}
|
|
|
|
|
|
auto Initialize(Context& context, Parse::Node parse_node,
|
|
|
- SemIR::NodeId target_id, SemIR::NodeId value_id)
|
|
|
- -> SemIR::NodeId {
|
|
|
+ SemIR::InstId target_id, SemIR::InstId value_id)
|
|
|
+ -> SemIR::InstId {
|
|
|
PendingBlock target_block(context);
|
|
|
return Convert(context, parse_node, value_id,
|
|
|
{.kind = ConversionTarget::Initializer,
|
|
|
- .type_id = context.sem_ir().nodes().Get(target_id).type_id(),
|
|
|
+ .type_id = context.sem_ir().insts().Get(target_id).type_id(),
|
|
|
.init_id = target_id,
|
|
|
.init_block = &target_block});
|
|
|
}
|
|
|
|
|
|
-auto ConvertToValueExpression(Context& context, SemIR::NodeId expr_id)
|
|
|
- -> SemIR::NodeId {
|
|
|
- auto expr = context.sem_ir().nodes().Get(expr_id);
|
|
|
+auto ConvertToValueExpression(Context& context, SemIR::InstId expr_id)
|
|
|
+ -> SemIR::InstId {
|
|
|
+ auto expr = context.sem_ir().insts().Get(expr_id);
|
|
|
return Convert(context, expr.parse_node(), expr_id,
|
|
|
{.kind = ConversionTarget::Value, .type_id = expr.type_id()});
|
|
|
}
|
|
|
|
|
|
auto ConvertToValueOrReferenceExpression(Context& context,
|
|
|
- SemIR::NodeId expr_id)
|
|
|
- -> SemIR::NodeId {
|
|
|
- auto expr = context.sem_ir().nodes().Get(expr_id);
|
|
|
+ SemIR::InstId expr_id)
|
|
|
+ -> SemIR::InstId {
|
|
|
+ auto expr = context.sem_ir().insts().Get(expr_id);
|
|
|
return Convert(
|
|
|
context, expr.parse_node(), expr_id,
|
|
|
{.kind = ConversionTarget::ValueOrReference, .type_id = expr.type_id()});
|
|
|
}
|
|
|
|
|
|
auto ConvertToValueOfType(Context& context, Parse::Node parse_node,
|
|
|
- SemIR::NodeId value_id, SemIR::TypeId type_id)
|
|
|
- -> SemIR::NodeId {
|
|
|
+ SemIR::InstId value_id, SemIR::TypeId type_id)
|
|
|
+ -> SemIR::InstId {
|
|
|
return Convert(context, parse_node, value_id,
|
|
|
{.kind = ConversionTarget::Value, .type_id = type_id});
|
|
|
}
|
|
|
|
|
|
auto ConvertToBoolValue(Context& context, Parse::Node parse_node,
|
|
|
- SemIR::NodeId value_id) -> SemIR::NodeId {
|
|
|
+ SemIR::InstId value_id) -> SemIR::InstId {
|
|
|
return ConvertToValueOfType(
|
|
|
context, parse_node, value_id,
|
|
|
context.GetBuiltinType(SemIR::BuiltinKind::BoolType));
|
|
|
}
|
|
|
|
|
|
auto ConvertForExplicitAs(Context& context, Parse::Node as_node,
|
|
|
- SemIR::NodeId value_id, SemIR::TypeId type_id)
|
|
|
- -> SemIR::NodeId {
|
|
|
+ SemIR::InstId value_id, SemIR::TypeId type_id)
|
|
|
+ -> SemIR::InstId {
|
|
|
return Convert(context, as_node, value_id,
|
|
|
{.kind = ConversionTarget::ExplicitAs, .type_id = type_id});
|
|
|
}
|
|
|
@@ -883,8 +883,8 @@ 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::Node call_parse_node,
|
|
|
Parse::Node callee_parse_node,
|
|
|
- SemIR::SelfParameter self_param, SemIR::NodeId self_id)
|
|
|
- -> SemIR::NodeId {
|
|
|
+ SemIR::SelfParameter self_param, SemIR::InstId self_id)
|
|
|
+ -> SemIR::InstId {
|
|
|
if (!self_id.is_valid()) {
|
|
|
CARBON_DIAGNOSTIC(MissingObjectInMethodCall, Error,
|
|
|
"Missing object argument in method call.");
|
|
|
@@ -892,7 +892,7 @@ static auto ConvertSelf(Context& context, Parse::Node call_parse_node,
|
|
|
.Build(call_parse_node, MissingObjectInMethodCall)
|
|
|
.Note(callee_parse_node, InCallToFunction)
|
|
|
.Emit();
|
|
|
- return SemIR::NodeId::BuiltinError;
|
|
|
+ return SemIR::InstId::BuiltinError;
|
|
|
}
|
|
|
|
|
|
DiagnosticAnnotationScope annotate_diagnostics(
|
|
|
@@ -912,7 +912,7 @@ static auto ConvertSelf(Context& context, Parse::Node call_parse_node,
|
|
|
if (self_param.is_addr_self.index) {
|
|
|
self_or_addr_id =
|
|
|
ConvertToValueOrReferenceExpression(context, self_or_addr_id);
|
|
|
- auto self = context.nodes().Get(self_or_addr_id);
|
|
|
+ auto self = context.insts().Get(self_or_addr_id);
|
|
|
switch (SemIR::GetExpressionCategory(context.sem_ir(), self_id)) {
|
|
|
case SemIR::ExpressionCategory::Error:
|
|
|
case SemIR::ExpressionCategory::DurableReference:
|
|
|
@@ -922,9 +922,9 @@ static auto ConvertSelf(Context& context, Parse::Node call_parse_node,
|
|
|
CARBON_DIAGNOSTIC(AddrSelfIsNonReference, Error,
|
|
|
"`addr self` method cannot be invoked on a value.");
|
|
|
context.emitter().Emit(call_parse_node, AddrSelfIsNonReference);
|
|
|
- return SemIR::NodeId::BuiltinError;
|
|
|
+ return SemIR::InstId::BuiltinError;
|
|
|
}
|
|
|
- self_or_addr_id = context.AddNode(SemIR::AddressOf{
|
|
|
+ self_or_addr_id = context.AddInst(SemIR::AddressOf{
|
|
|
self.parse_node(),
|
|
|
context.GetPointerType(self.parse_node(), self.type_id()),
|
|
|
self_or_addr_id});
|
|
|
@@ -935,15 +935,15 @@ static auto ConvertSelf(Context& context, Parse::Node call_parse_node,
|
|
|
}
|
|
|
|
|
|
auto ConvertCallArgs(Context& context, Parse::Node call_parse_node,
|
|
|
- SemIR::NodeId self_id,
|
|
|
- llvm::ArrayRef<SemIR::NodeId> arg_refs,
|
|
|
- SemIR::NodeId return_storage_id,
|
|
|
+ SemIR::InstId self_id,
|
|
|
+ llvm::ArrayRef<SemIR::InstId> arg_refs,
|
|
|
+ SemIR::InstId return_storage_id,
|
|
|
Parse::Node callee_parse_node,
|
|
|
- SemIR::NodeBlockId implicit_param_refs_id,
|
|
|
- SemIR::NodeBlockId param_refs_id) -> SemIR::NodeBlockId {
|
|
|
+ SemIR::InstBlockId implicit_param_refs_id,
|
|
|
+ SemIR::InstBlockId param_refs_id) -> SemIR::InstBlockId {
|
|
|
auto implicit_param_refs =
|
|
|
- context.sem_ir().node_blocks().Get(implicit_param_refs_id);
|
|
|
- auto param_refs = context.sem_ir().node_blocks().Get(param_refs_id);
|
|
|
+ context.sem_ir().inst_blocks().Get(implicit_param_refs_id);
|
|
|
+ auto param_refs = context.sem_ir().inst_blocks().Get(param_refs_id);
|
|
|
|
|
|
// If sizes mismatch, fail early.
|
|
|
if (arg_refs.size() != param_refs.size()) {
|
|
|
@@ -956,28 +956,28 @@ auto ConvertCallArgs(Context& context, Parse::Node call_parse_node,
|
|
|
param_refs.size())
|
|
|
.Note(callee_parse_node, InCallToFunction)
|
|
|
.Emit();
|
|
|
- return SemIR::NodeBlockId::Invalid;
|
|
|
+ return SemIR::InstBlockId::Invalid;
|
|
|
}
|
|
|
|
|
|
// Start building a block to hold the converted arguments.
|
|
|
- llvm::SmallVector<SemIR::NodeId> args;
|
|
|
+ llvm::SmallVector<SemIR::InstId> args;
|
|
|
args.reserve(implicit_param_refs.size() + param_refs.size() +
|
|
|
return_storage_id.is_valid());
|
|
|
|
|
|
// Check implicit parameters.
|
|
|
for (auto implicit_param_id : implicit_param_refs) {
|
|
|
- auto param = context.nodes().Get(implicit_param_id);
|
|
|
+ auto param = context.insts().Get(implicit_param_id);
|
|
|
if (auto self_param = param.TryAs<SemIR::SelfParameter>()) {
|
|
|
auto converted_self_id = ConvertSelf(
|
|
|
context, call_parse_node, callee_parse_node, *self_param, self_id);
|
|
|
- if (converted_self_id == SemIR::NodeId::BuiltinError) {
|
|
|
- return SemIR::NodeBlockId::Invalid;
|
|
|
+ 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");
|
|
|
- return SemIR::NodeBlockId::Invalid;
|
|
|
+ return SemIR::InstBlockId::Invalid;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -995,13 +995,13 @@ auto ConvertCallArgs(Context& context, Parse::Node call_parse_node,
|
|
|
for (auto [i, arg_id, param_id] : llvm::enumerate(arg_refs, param_refs)) {
|
|
|
diag_param_index = i;
|
|
|
|
|
|
- auto param_type_id = context.sem_ir().nodes().Get(param_id).type_id();
|
|
|
+ auto param_type_id = context.sem_ir().insts().Get(param_id).type_id();
|
|
|
// 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);
|
|
|
- if (converted_arg_id == SemIR::NodeId::BuiltinError) {
|
|
|
- return SemIR::NodeBlockId::Invalid;
|
|
|
+ if (converted_arg_id == SemIR::InstId::BuiltinError) {
|
|
|
+ return SemIR::InstBlockId::Invalid;
|
|
|
}
|
|
|
|
|
|
args.push_back(converted_arg_id);
|
|
|
@@ -1012,11 +1012,11 @@ auto ConvertCallArgs(Context& context, Parse::Node call_parse_node,
|
|
|
args.push_back(return_storage_id);
|
|
|
}
|
|
|
|
|
|
- return context.node_blocks().Add(args);
|
|
|
+ return context.inst_blocks().Add(args);
|
|
|
}
|
|
|
|
|
|
auto ExpressionAsType(Context& context, Parse::Node parse_node,
|
|
|
- SemIR::NodeId value_id) -> SemIR::TypeId {
|
|
|
+ SemIR::InstId value_id) -> SemIR::TypeId {
|
|
|
return context.CanonicalizeType(ConvertToValueOfType(
|
|
|
context, parse_node, value_id, SemIR::TypeId::TypeType));
|
|
|
}
|