Rename enclosing scope to parent scope (#4020)

Following up on discussion from #3948, doing a general rename of
"enclosing scope" to "parent scope" (and "enclosing scopes" to "ancestor
scopes"). The intent is to improve understandability and collide less
with C++ terminology for "enclosing scope". Note this changes most uses
of "enclosing", but leaves behind a few like "enclosing function" and
"enclosing block".

Note this does create some "parent class" mentions for "adapt" and "var"
(the class they're within), which is maybe unfortunate, but we'd
probably say "base class" if we meant inheritance so perhaps that's
okay. Along the same lines, these are the only `parent_class` uses I see
now, and we do have a few `base_class`.
This commit is contained in:
Jon Ross-Perkins
2024-06-04 19:57:14 +00:00
committed by GitHub
parent 83413479d7
commit d9c62b106d
33 changed files with 237 additions and 257 deletions
+5 -6
View File
@@ -38,7 +38,7 @@ auto HandleAnyBindingPattern(Context& context, Parse::NodeId node_id,
// scopes, but right now we don't support qualified names here.
auto bind_name_id = context.bind_names().Add(
{.name_id = name_id,
.enclosing_scope_id = context.scope_stack().PeekNameScopeId(),
.parent_scope_id = context.scope_stack().PeekNameScopeId(),
// TODO: Don't allocate a compile-time binding index for an associated
// constant declaration.
.bind_index = is_generic && !is_associated_constant
@@ -86,22 +86,21 @@ auto HandleAnyBindingPattern(Context& context, Parse::NodeId node_id,
: context.parse_tree().As<Parse::BindingPatternId>(node_id);
// A `var` declaration at class scope introduces a field.
auto enclosing_class_decl = context.GetCurrentScopeAs<SemIR::ClassDecl>();
auto parent_class_decl = context.GetCurrentScopeAs<SemIR::ClassDecl>();
cast_type_id = context.AsCompleteType(cast_type_id, [&] {
CARBON_DIAGNOSTIC(IncompleteTypeInVarDecl, Error,
"{0} has incomplete type `{1}`.", llvm::StringLiteral,
SemIR::TypeId);
return context.emitter().Build(type_node, IncompleteTypeInVarDecl,
enclosing_class_decl
parent_class_decl
? llvm::StringLiteral("Field")
: llvm::StringLiteral("Variable"),
cast_type_id);
});
if (enclosing_class_decl) {
if (parent_class_decl) {
CARBON_CHECK(context_node_kind == Parse::NodeKind::VariableIntroducer)
<< "`returned var` at class scope";
auto& class_info =
context.classes().Get(enclosing_class_decl->class_id);
auto& class_info = context.classes().Get(parent_class_decl->class_id);
auto field_type_id = context.GetUnboundElementType(
class_info.self_type_id, cast_type_id);
auto field_id = context.AddInst<SemIR::FieldDecl>(