Rename SemIR::Node to SemIR::Inst (#3355)

And generally replace "node" by "inst" in the code and "instruction" in
comments.

---------

Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
This commit is contained in:
josh11b
2023-11-02 17:58:30 +00:00
committed by GitHub
co-authored by Chandler Carruth
parent 35c2142392
commit 7edfd8e02a
63 changed files with 2136 additions and 2115 deletions
+40 -38
View File
@@ -11,11 +11,13 @@
#include "llvm/ADT/SmallVector.h"
#include "toolchain/parse/node_kind.h"
#include "toolchain/parse/tree.h"
#include "toolchain/sem_ir/node.h"
#include "toolchain/sem_ir/inst.h"
namespace Carbon::Check {
// Wraps the stack of nodes for Context.
// Wraps the stack of parse nodes for Context. Each parse node can have an
// associated id of some kind (instruction, instruction block, function, class,
// ...).
//
// All pushes and pops will be vlogged.
//
@@ -23,7 +25,7 @@ namespace Carbon::Check {
//
// - If receiving a pop_parse_kind, verify that the parse_node being popped is
// of pop_parse_kind.
// - Validates presence of node_id based on whether it's a solo
// - Validates presence of inst_id based on whether it's a solo
// parse_node.
//
// These should be assumed API constraints unless otherwise mentioned on a
@@ -44,7 +46,7 @@ class NodeStack {
<< parse_tree_->node_kind(parse_node) << " -> <none>\n";
CARBON_CHECK(stack_.size() < (1 << 20))
<< "Excessive stack size: likely infinite loop";
stack_.push_back(Entry(parse_node, SemIR::NodeId::Invalid));
stack_.push_back(Entry(parse_node, SemIR::InstId::Invalid));
}
// Pushes a parse tree node onto the stack with an ID.
@@ -70,12 +72,12 @@ class NodeStack {
}
// Pops the top of the stack without any verification.
auto PopAndIgnore() -> void { PopEntry<SemIR::NodeId>(); }
auto PopAndIgnore() -> void { PopEntry<SemIR::InstId>(); }
// Pops the top of the stack and returns the parse_node.
template <Parse::NodeKind::RawEnumType RequiredParseKind>
auto PopForSoloParseNode() -> Parse::Node {
Entry back = PopEntry<SemIR::NodeId>();
Entry back = PopEntry<SemIR::InstId>();
RequireIdKind(Parse::NodeKind::Create(RequiredParseKind),
IdKind::SoloParseNode);
RequireParseKind<RequiredParseKind>(back.parse_node);
@@ -100,8 +102,8 @@ class NodeStack {
// Pops an expression from the top of the stack and returns the parse_node and
// the ID.
auto PopExpressionWithParseNode() -> std::pair<Parse::Node, SemIR::NodeId> {
return PopWithParseNode<SemIR::NodeId>();
auto PopExpressionWithParseNode() -> std::pair<Parse::Node, SemIR::InstId> {
return PopWithParseNode<SemIR::InstId>();
}
// Pops the top of the stack and returns the parse_node and the ID.
@@ -109,13 +111,13 @@ class NodeStack {
auto PopWithParseNode() -> auto {
constexpr IdKind RequiredIdKind =
ParseNodeKindToIdKind(Parse::NodeKind::Create(RequiredParseKind));
if constexpr (RequiredIdKind == IdKind::NodeId) {
auto back = PopWithParseNode<SemIR::NodeId>();
if constexpr (RequiredIdKind == IdKind::InstId) {
auto back = PopWithParseNode<SemIR::InstId>();
RequireParseKind<RequiredParseKind>(back.first);
return back;
}
if constexpr (RequiredIdKind == IdKind::NodeBlockId) {
auto back = PopWithParseNode<SemIR::NodeBlockId>();
if constexpr (RequiredIdKind == IdKind::InstBlockId) {
auto back = PopWithParseNode<SemIR::InstBlockId>();
RequireParseKind<RequiredParseKind>(back.first);
return back;
}
@@ -145,8 +147,8 @@ class NodeStack {
}
// Pops an expression from the top of the stack and returns the ID.
// Expressions map multiple Parse::NodeKinds to SemIR::NodeId always.
auto PopExpression() -> SemIR::NodeId {
// Expressions map multiple Parse::NodeKinds to SemIR::InstId always.
auto PopExpression() -> SemIR::InstId {
return PopExpressionWithParseNode().second;
}
@@ -166,7 +168,7 @@ class NodeStack {
return std::nullopt;
}
// Peeks at the parse_node of the given depth in the stack, or by default the
// Peeks at the parse node of the given depth in the stack, or by default the
// top node.
auto PeekParseNode() const -> Parse::Node { return stack_.back().parse_node; }
@@ -178,11 +180,11 @@ class NodeStack {
RequireParseKind<RequiredParseKind>(back.parse_node);
constexpr IdKind RequiredIdKind =
ParseNodeKindToIdKind(Parse::NodeKind::Create(RequiredParseKind));
if constexpr (RequiredIdKind == IdKind::NodeId) {
return back.id<SemIR::NodeId>();
if constexpr (RequiredIdKind == IdKind::InstId) {
return back.id<SemIR::InstId>();
}
if constexpr (RequiredIdKind == IdKind::NodeBlockId) {
return back.id<SemIR::NodeBlockId>();
if constexpr (RequiredIdKind == IdKind::InstBlockId) {
return back.id<SemIR::InstBlockId>();
}
if constexpr (RequiredIdKind == IdKind::FunctionId) {
return back.id<SemIR::FunctionId>();
@@ -210,8 +212,8 @@ class NodeStack {
private:
// Possible associated ID types.
enum class IdKind : int8_t {
NodeId,
NodeBlockId,
InstId,
InstBlockId,
FunctionId,
ClassId,
StringId,
@@ -224,10 +226,10 @@ class NodeStack {
// An entry in stack_.
struct Entry {
explicit Entry(Parse::Node parse_node, SemIR::NodeId node_id)
: parse_node(parse_node), node_id(node_id) {}
explicit Entry(Parse::Node parse_node, SemIR::NodeBlockId node_block_id)
: parse_node(parse_node), node_block_id(node_block_id) {}
explicit Entry(Parse::Node parse_node, SemIR::InstId inst_id)
: parse_node(parse_node), inst_id(inst_id) {}
explicit Entry(Parse::Node parse_node, SemIR::InstBlockId inst_block_id)
: parse_node(parse_node), inst_block_id(inst_block_id) {}
explicit Entry(Parse::Node parse_node, SemIR::FunctionId function_id)
: parse_node(parse_node), function_id(function_id) {}
explicit Entry(Parse::Node parse_node, SemIR::ClassId class_id)
@@ -240,11 +242,11 @@ class NodeStack {
// Returns the appropriate ID basaed on type.
template <typename T>
auto id() -> T& {
if constexpr (std::is_same<T, SemIR::NodeId>()) {
return node_id;
if constexpr (std::is_same<T, SemIR::InstId>()) {
return inst_id;
}
if constexpr (std::is_same<T, SemIR::NodeBlockId>()) {
return node_block_id;
if constexpr (std::is_same<T, SemIR::InstBlockId>()) {
return inst_block_id;
}
if constexpr (std::is_same<T, SemIR::FunctionId>()) {
return function_id;
@@ -260,7 +262,7 @@ class NodeStack {
}
}
// The node associated with the stack entry.
// The parse node associated with the stack entry.
Parse::Node parse_node;
// The entries will evaluate as invalid if and only if they're a solo
@@ -269,8 +271,8 @@ class NodeStack {
// A discriminator isn't needed because the caller can determine which field
// is used based on the Parse::NodeKind.
union {
SemIR::NodeId node_id;
SemIR::NodeBlockId node_block_id;
SemIR::InstId inst_id;
SemIR::InstBlockId inst_block_id;
SemIR::FunctionId function_id;
SemIR::ClassId class_id;
StringId name_id;
@@ -305,14 +307,14 @@ class NodeStack {
case Parse::NodeKind::StructFieldType:
case Parse::NodeKind::StructTypeLiteral:
case Parse::NodeKind::TupleLiteral:
return IdKind::NodeId;
return IdKind::InstId;
case Parse::NodeKind::IfCondition:
case Parse::NodeKind::IfExpressionIf:
case Parse::NodeKind::ImplicitParameterList:
case Parse::NodeKind::ParameterList:
case Parse::NodeKind::WhileCondition:
case Parse::NodeKind::WhileConditionStart:
return IdKind::NodeBlockId;
return IdKind::InstBlockId;
case Parse::NodeKind::FunctionDefinitionStart:
return IdKind::FunctionId;
case Parse::NodeKind::ClassDefinitionStart:
@@ -344,11 +346,11 @@ class NodeStack {
// ParseNodeKindToIdKind.
template <typename IdT>
static constexpr auto IdTypeToIdKind() -> IdKind {
if constexpr (std::is_same_v<IdT, SemIR::NodeId>) {
return IdKind::NodeId;
if constexpr (std::is_same_v<IdT, SemIR::InstId>) {
return IdKind::InstId;
}
if constexpr (std::is_same_v<IdT, SemIR::NodeBlockId>) {
return IdKind::NodeBlockId;
if constexpr (std::is_same_v<IdT, SemIR::InstBlockId>) {
return IdKind::InstBlockId;
}
if constexpr (std::is_same_v<IdT, SemIR::FunctionId>) {
return IdKind::FunctionId;