mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 20:11:12 +01:00
Remove ImportRefUsed (#3934)
This was to track use of a declaration after import, prior to a redeclaration. Per [discussion on Discord](https://discord.com/channels/655572317891461132/1217182321933815820/1236016521059237962), we likely don't need this check due to the change in behavior of `extern`. Rather than potentially getting one of many `extern` decls and depending on it by accident, it is now planned to be _required_ to be imported, and the library doing a non-`extern` decl must _know_ it's importing the `extern` decl. The stricter requirement on the library means it now seems more reasonable to use the `extern` decl. So kind of rolling back #3831, though keeping `ImportIRInstId` (at least for now) and keeping `Loaded`/`Unloaded` terminology (seems a nicer fit).
This commit is contained in:
+13
-20
@@ -211,8 +211,7 @@ auto Context::AddNameToLookup(SemIR::NameId name_id, SemIR::InstId target_id)
|
||||
}
|
||||
|
||||
auto Context::LookupNameInDecl(SemIR::LocId loc_id, SemIR::NameId name_id,
|
||||
SemIR::NameScopeId scope_id,
|
||||
bool mark_imports_used) -> SemIR::InstId {
|
||||
SemIR::NameScopeId scope_id) -> SemIR::InstId {
|
||||
if (!scope_id.is_valid()) {
|
||||
// Look for a name in the current scope only. There are two cases where the
|
||||
// name would be in an outer scope:
|
||||
@@ -248,8 +247,7 @@ auto Context::LookupNameInDecl(SemIR::LocId loc_id, SemIR::NameId name_id,
|
||||
//
|
||||
// // Error, no `F` in `B`.
|
||||
// fn B.F() {}
|
||||
return LookupNameInExactScope(loc_id, name_id, name_scopes().Get(scope_id),
|
||||
mark_imports_used);
|
||||
return LookupNameInExactScope(loc_id, name_id, name_scopes().Get(scope_id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -284,8 +282,8 @@ auto Context::LookupUnqualifiedName(Parse::NodeId node_id,
|
||||
// Handles lookup through the import_ir_scopes for LookupNameInExactScope.
|
||||
static auto LookupInImportIRScopes(Context& context, SemIRLoc loc,
|
||||
SemIR::NameId name_id,
|
||||
const SemIR::NameScope& scope,
|
||||
bool mark_imports_used) -> SemIR::InstId {
|
||||
const SemIR::NameScope& scope)
|
||||
-> SemIR::InstId {
|
||||
auto identifier_id = name_id.AsIdentifierId();
|
||||
llvm::StringRef identifier;
|
||||
if (identifier_id.is_valid()) {
|
||||
@@ -328,8 +326,7 @@ static auto LookupInImportIRScopes(Context& context, SemIRLoc loc,
|
||||
if (result_id.is_valid()) {
|
||||
context.DiagnoseDuplicateName(import_inst_id, result_id);
|
||||
} else {
|
||||
LoadImportRef(context, import_inst_id,
|
||||
mark_imports_used ? loc : SemIR::LocId::Invalid);
|
||||
LoadImportRef(context, import_inst_id);
|
||||
result_id = import_inst_id;
|
||||
}
|
||||
}
|
||||
@@ -338,16 +335,14 @@ static auto LookupInImportIRScopes(Context& context, SemIRLoc loc,
|
||||
}
|
||||
|
||||
auto Context::LookupNameInExactScope(SemIRLoc loc, SemIR::NameId name_id,
|
||||
const SemIR::NameScope& scope,
|
||||
bool mark_imports_used) -> SemIR::InstId {
|
||||
const SemIR::NameScope& scope)
|
||||
-> SemIR::InstId {
|
||||
if (auto it = scope.names.find(name_id); it != scope.names.end()) {
|
||||
LoadImportRef(*this, it->second,
|
||||
mark_imports_used ? loc : SemIR::LocId::Invalid);
|
||||
LoadImportRef(*this, it->second);
|
||||
return it->second;
|
||||
}
|
||||
if (!scope.import_ir_scopes.empty()) {
|
||||
return LookupInImportIRScopes(*this, loc, name_id, scope,
|
||||
mark_imports_used);
|
||||
return LookupInImportIRScopes(*this, loc, name_id, scope);
|
||||
}
|
||||
return SemIR::InstId::Invalid;
|
||||
}
|
||||
@@ -364,8 +359,7 @@ auto Context::LookupQualifiedName(Parse::NodeId node_id, SemIR::NameId name_id,
|
||||
const auto& scope = name_scopes().Get(scope_ids.pop_back_val());
|
||||
has_error |= scope.has_error;
|
||||
|
||||
auto scope_result_id = LookupNameInExactScope(node_id, name_id, scope,
|
||||
/*mark_imports_used=*/true);
|
||||
auto scope_result_id = LookupNameInExactScope(node_id, name_id, scope);
|
||||
if (!scope_result_id.is_valid()) {
|
||||
// Nothing found in this scope: also look in its extended scopes.
|
||||
auto extended = llvm::reverse(scope.extended_scopes);
|
||||
@@ -415,8 +409,8 @@ static auto GetCorePackage(Context& context, SemIRLoc loc)
|
||||
|
||||
// Look up `package.Core`.
|
||||
auto core_inst_id = context.LookupNameInExactScope(
|
||||
loc, core_name_id, context.name_scopes().Get(SemIR::NameScopeId::Package),
|
||||
/*mark_imports_used=*/true);
|
||||
loc, core_name_id,
|
||||
context.name_scopes().Get(SemIR::NameScopeId::Package));
|
||||
if (!core_inst_id.is_valid()) {
|
||||
context.DiagnoseNameNotFound(loc, core_name_id);
|
||||
return SemIR::NameScopeId::Invalid;
|
||||
@@ -441,8 +435,7 @@ auto Context::LookupNameInCore(SemIRLoc loc, llvm::StringRef name)
|
||||
|
||||
auto name_id = SemIR::NameId::ForIdentifier(identifiers().Add(name));
|
||||
auto inst_id =
|
||||
LookupNameInExactScope(loc, name_id, name_scopes().Get(core_package_id),
|
||||
/*mark_imports_used=*/true);
|
||||
LookupNameInExactScope(loc, name_id, name_scopes().Get(core_package_id));
|
||||
if (!inst_id.is_valid()) {
|
||||
DiagnoseNameNotFound(loc, name_id);
|
||||
return SemIR::InstId::BuiltinError;
|
||||
|
||||
Reference in New Issue
Block a user