Skip to content

Commit d614ed0

Browse files
authored
Assert that non-None NameScopes import as non-None (#5584)
This would've identified c6f25e9 earlier/more clearly. I looked for similar assertions for things like `GetLocalConstantValueOrPush` but it has the right property by construction (if it's going to return `None`, it pushes work) so an assertion didn't seem suitable there. Perhaps there are other such mapping functions that could get this treatment? Open to pointers.
1 parent ae454bb commit d614ed0

File tree

1 file changed

+26
-15
lines changed

1 file changed

+26
-15
lines changed

toolchain/check/import_ref.cpp

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -999,22 +999,9 @@ static auto GetLocalSpecificInterface(
999999
}
10001000
}
10011001

1002-
// Translates a NameScopeId from the import IR to a local NameScopeId. Adds
1003-
// unresolved constants to the resolver's work stack.
1004-
static auto GetLocalNameScopeId(ImportRefResolver& resolver,
1005-
SemIR::NameScopeId name_scope_id)
1002+
static auto GetLocalNameScopeIdImpl(ImportRefResolver& resolver,
1003+
SemIR::ConstantId const_id)
10061004
-> SemIR::NameScopeId {
1007-
// Get the instruction that created the scope.
1008-
auto [inst_id, inst] =
1009-
resolver.import_name_scopes().GetInstIfValid(name_scope_id);
1010-
if (!inst) {
1011-
// Map scopes that aren't associated with an instruction to `None`. For now,
1012-
// such scopes aren't used, and we don't have a good way to remap them.
1013-
return SemIR::NameScopeId::None;
1014-
}
1015-
1016-
// Get the constant value for the scope.
1017-
auto const_id = GetLocalConstantId(resolver, inst_id);
10181005
if (!const_id.has_value()) {
10191006
return SemIR::NameScopeId::None;
10201007
}
@@ -1069,6 +1056,30 @@ static auto GetLocalNameScopeId(ImportRefResolver& resolver,
10691056
name_scope_inst);
10701057
}
10711058

1059+
// Translates a NameScopeId from the import IR to a local NameScopeId. Adds
1060+
// unresolved constants to the resolver's work stack.
1061+
static auto GetLocalNameScopeId(ImportRefResolver& resolver,
1062+
SemIR::NameScopeId name_scope_id)
1063+
-> SemIR::NameScopeId {
1064+
// Get the instruction that created the scope.
1065+
auto [inst_id, inst] =
1066+
resolver.import_name_scopes().GetInstIfValid(name_scope_id);
1067+
if (!inst) {
1068+
// Map scopes that aren't associated with an instruction to `None`. For now,
1069+
// such scopes aren't used, and we don't have a good way to remap them.
1070+
return SemIR::NameScopeId::None;
1071+
}
1072+
1073+
// Get the constant value for the scope.
1074+
auto const_id = GetLocalConstantId(resolver, inst_id);
1075+
if (!const_id.has_value()) {
1076+
return SemIR::NameScopeId::None;
1077+
}
1078+
auto result = GetLocalNameScopeIdImpl(resolver, const_id);
1079+
CARBON_CHECK(result.has_value());
1080+
return result;
1081+
}
1082+
10721083
// Given an imported entity base, returns an incomplete, local version of it.
10731084
//
10741085
// Most fields are set in the third phase once they're imported. Import enough

0 commit comments

Comments
 (0)