Rename semantics to semantics_ir (#2858)

This is a rename of a commonly used accessor. I tend to prefer shorter names, but it's semantics_ir in LoweringContext, and it feels odder to shorten to semantics there than to lengthen to semantics_ir here. I already have builtins_ir around here, too. I think it's helpful to use consistent names for semantics_ir since they're dealing with essentially the same thing.
This commit is contained in:
Jon Ross-Perkins
2023-06-01 14:32:22 -07:00
committed by GitHub
parent 81e53886a8
commit dce67e4062
7 changed files with 86 additions and 81 deletions
+30 -30
View File
@@ -20,19 +20,19 @@ namespace Carbon {
SemanticsContext::SemanticsContext(const TokenizedBuffer& tokens,
DiagnosticEmitter<ParseTree::Node>& emitter,
const ParseTree& parse_tree,
SemanticsIR& semantics,
SemanticsIR& semantics_ir,
llvm::raw_ostream* vlog_stream)
: tokens_(&tokens),
emitter_(&emitter),
parse_tree_(&parse_tree),
semantics_(&semantics),
semantics_ir_(&semantics_ir),
vlog_stream_(vlog_stream),
node_stack_(parse_tree, vlog_stream),
node_block_stack_("node_block_stack_", semantics.node_blocks(),
node_block_stack_("node_block_stack_", semantics_ir.node_blocks(),
vlog_stream),
params_or_args_stack_("params_or_args_stack_", semantics.node_blocks(),
params_or_args_stack_("params_or_args_stack_", semantics_ir.node_blocks(),
vlog_stream),
args_type_info_stack_("args_type_info_stack_", semantics.node_blocks(),
args_type_info_stack_("args_type_info_stack_", semantics_ir.node_blocks(),
vlog_stream) {
// Inserts the "Invalid" and "Type" types as "used types" so that
// canonicalization can skip them. We don't emit either for lowering.
@@ -63,7 +63,7 @@ auto SemanticsContext::VerifyOnFinish() -> void {
auto SemanticsContext::AddNode(SemanticsNode node) -> SemanticsNodeId {
auto block = node_block_stack_.PeekForAdd();
CARBON_VLOG() << "AddNode " << block << ": " << node << "\n";
return semantics_->AddNode(block, node);
return semantics_ir_->AddNode(block, node);
}
auto SemanticsContext::AddNodeAndPush(ParseTree::Node parse_node,
@@ -80,9 +80,9 @@ auto SemanticsContext::AddNameToLookup(ParseTree::Node name_node,
llvm::StringRef);
CARBON_DIAGNOSTIC(PreviousDefinition, Note, "Previous definition is here.");
auto prev_def_id = name_lookup_[name_id].back();
auto prev_def = semantics_->GetNode(prev_def_id);
auto prev_def = semantics_ir_->GetNode(prev_def_id);
emitter_->Build(name_node, NameRedefined, semantics_->GetString(name_id))
emitter_->Build(name_node, NameRedefined, semantics_ir_->GetString(name_id))
.Note(prev_def.parse_node(), PreviousDefinition)
.Emit();
}
@@ -105,7 +105,7 @@ auto SemanticsContext::BindName(ParseTree::Node name_node,
CARBON_CHECK(parse_tree_->node_kind(name_node) == ParseNodeKind::DeclaredName)
<< parse_tree_->node_kind(name_node);
auto name_str = parse_tree_->GetNodeText(name_node);
auto name_id = semantics_->AddString(name_str);
auto name_id = semantics_ir_->AddString(name_str);
AddNode(
SemanticsNode::BindName::Make(name_node, type_id, name_id, target_id));
@@ -135,7 +135,7 @@ auto SemanticsContext::LookupName(ParseTree::Node parse_node,
llvm::StringRef name) -> SemanticsNodeId {
CARBON_DIAGNOSTIC(NameNotFound, Error, "Name {0} not found", llvm::StringRef);
auto name_id = semantics_->GetStringID(name);
auto name_id = semantics_ir_->GetStringID(name);
if (!name_id) {
emitter_->Emit(parse_node, NameNotFound, name);
return SemanticsNodeId::BuiltinInvalidType;
@@ -178,8 +178,8 @@ auto SemanticsContext::ImplicitAsForArgs(
return true;
}
auto arg_refs = semantics_->GetNodeBlock(arg_refs_id);
auto param_refs = semantics_->GetNodeBlock(param_refs_id);
auto arg_refs = semantics_ir_->GetNodeBlock(arg_refs_id);
auto param_refs = semantics_ir_->GetNodeBlock(param_refs_id);
// If sizes mismatch, fail early.
if (arg_refs.size() != param_refs.size()) {
@@ -198,7 +198,7 @@ auto SemanticsContext::ImplicitAsForArgs(
// It's currently not supported, but will be needed.
for (size_t i = 0; i < arg_refs.size(); ++i) {
auto value_id = arg_refs[i];
auto as_type_id = semantics_->GetNode(param_refs[i]).type_id();
auto as_type_id = semantics_ir_->GetNode(param_refs[i]).type_id();
if (ImplicitAsImpl(value_id, as_type_id,
diagnostic == nullptr ? &value_id : nullptr) ==
ImplicitAsKind::Incompatible) {
@@ -207,10 +207,10 @@ auto SemanticsContext::ImplicitAsForArgs(
"Callable cannot be used: Cannot implicityly convert "
"argument {0} from `{1}` to `{2}`.",
size_t, std::string, std::string);
diagnostic->Note(
param_parse_node, CallArgTypeMismatch, i,
semantics_->StringifyType(semantics_->GetNode(value_id).type_id()),
semantics_->StringifyType(as_type_id));
diagnostic->Note(param_parse_node, CallArgTypeMismatch, i,
semantics_ir_->StringifyType(
semantics_ir_->GetNode(value_id).type_id()),
semantics_ir_->StringifyType(as_type_id));
return false;
}
}
@@ -230,10 +230,10 @@ auto SemanticsContext::ImplicitAsRequired(ParseTree::Node parse_node,
"Cannot implicitly convert from `{0}` to `{1}`.",
std::string, std::string);
emitter_
->Build(
parse_node, ImplicitAsConversionFailure,
semantics_->StringifyType(semantics_->GetNode(value_id).type_id()),
semantics_->StringifyType(as_type_id))
->Build(parse_node, ImplicitAsConversionFailure,
semantics_ir_->StringifyType(
semantics_ir_->GetNode(value_id).type_id()),
semantics_ir_->StringifyType(as_type_id))
.Emit();
}
return output_value_id;
@@ -249,7 +249,7 @@ auto SemanticsContext::ImplicitAsImpl(SemanticsNodeId value_id,
// If the value is invalid, we can't do much, but do "succeed".
return ImplicitAsKind::Identical;
}
auto value = semantics_->GetNode(value_id);
auto value = semantics_ir_->GetNode(value_id);
auto value_type_id = value.type_id();
if (value_type_id == SemanticsTypeId::InvalidType) {
return ImplicitAsKind::Identical;
@@ -276,7 +276,7 @@ auto SemanticsContext::ImplicitAsImpl(SemanticsNodeId value_id,
if (value.kind() == SemanticsNodeKind::StructValue &&
value.GetAsStructValue() == SemanticsNodeBlockId::Empty) {
if (output_value_id != nullptr) {
*output_value_id = semantics_->GetType(value_type_id);
*output_value_id = semantics_ir_->GetType(value_type_id);
}
return ImplicitAsKind::Compatible;
}
@@ -314,21 +314,21 @@ auto SemanticsContext::ParamOrArgSave(bool for_args) -> void {
auto [entry_parse_node, entry_node_id] =
node_stack_.PopForParseNodeAndNodeId();
param_or_arg_id = AddNode(SemanticsNode::StubReference::Make(
entry_parse_node, semantics_->GetNode(entry_node_id).type_id(),
entry_parse_node, semantics_ir_->GetNode(entry_node_id).type_id(),
entry_node_id));
} else {
// For a parameter, there should always be something in the IR.
node_stack_.PopAndIgnore();
auto ir_id = node_block_stack_.Peek();
CARBON_CHECK(ir_id.is_valid());
auto& ir = semantics_->GetNodeBlock(ir_id);
auto& ir = semantics_ir_->GetNodeBlock(ir_id);
CARBON_CHECK(!ir.empty()) << "Should have had a param";
param_or_arg_id = ir.back();
}
// Save the param or arg ID.
auto& params_or_args =
semantics_->GetNodeBlock(params_or_args_stack_.PeekForAdd());
semantics_ir_->GetNodeBlock(params_or_args_stack_.PeekForAdd());
params_or_args.push_back(param_or_arg_id);
}
@@ -339,7 +339,7 @@ auto SemanticsContext::CanonicalizeType(SemanticsNodeId node_id)
return it->second;
}
auto type_id = semantics_->AddType(node_id);
auto type_id = semantics_ir_->AddType(node_id);
CARBON_CHECK(canonical_types_.insert({node_id, type_id}).second);
return type_id;
}
@@ -348,10 +348,10 @@ auto SemanticsContext::CanonicalizeStructType(ParseTree::Node parse_node,
SemanticsNodeBlockId refs_id)
-> SemanticsTypeId {
// Construct the field structure for lookup.
auto refs = semantics_->GetNodeBlock(refs_id);
auto refs = semantics_ir_->GetNodeBlock(refs_id);
llvm::FoldingSetNodeID canonical_id;
for (const auto& ref_id : refs) {
auto ref = semantics_->GetNode(ref_id);
auto ref = semantics_ir_->GetNode(ref_id);
canonical_id.AddInteger(ref.GetAsStructTypeField().index);
canonical_id.AddInteger(ref.type_id().index);
}
@@ -367,7 +367,7 @@ auto SemanticsContext::CanonicalizeStructType(ParseTree::Node parse_node,
// The struct doesn't already exist, so create and store it as canonical.
auto node_id = AddNode(SemanticsNode::StructType::Make(
parse_node, SemanticsTypeId::TypeType, refs_id));
auto type_id = semantics_->AddType(node_id);
auto type_id = semantics_ir_->AddType(node_id);
CARBON_CHECK(canonical_types_.insert({node_id, type_id}).second);
canonical_struct_types_nodes_.push_back(
std::make_unique<StructTypeNode>(canonical_id, type_id));