mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Handle lookup into Builtin with module selector
Lookups like Builtin::Int64 were failing because BuiltinUnit rejected all unqualified lookups. Make it allow unqualified lookups with a module selector.
This commit is contained in:
@@ -66,11 +66,16 @@ public:
|
||||
/// \param moduleScopeContext The top-level context from which the lookup is
|
||||
/// being performed, for checking access. This must be either a
|
||||
/// FileUnit or a Module.
|
||||
/// \param hasModuleSelector Whether \p name was originally qualified by a
|
||||
/// module selector. This information is threaded through to underlying
|
||||
/// lookup calls; the callee is responsible for actually applying the
|
||||
/// module selector.
|
||||
/// \param options Lookup options to apply.
|
||||
void lookupInModule(SmallVectorImpl<ValueDecl *> &decls,
|
||||
const DeclContext *moduleOrFile,
|
||||
ImportPath::Access accessPath,
|
||||
const DeclContext *moduleScopeContext,
|
||||
bool hasModuleSelector,
|
||||
NLOptions options);
|
||||
};
|
||||
|
||||
@@ -173,6 +178,7 @@ void ModuleNameLookup<LookupStrategy>::lookupInModule(
|
||||
const DeclContext *moduleOrFile,
|
||||
ImportPath::Access accessPath,
|
||||
const DeclContext *moduleScopeContext,
|
||||
bool hasModuleSelector,
|
||||
NLOptions options) {
|
||||
assert(moduleOrFile->isModuleScopeContext());
|
||||
|
||||
@@ -189,7 +195,7 @@ void ModuleNameLookup<LookupStrategy>::lookupInModule(
|
||||
selfOverlay = true;
|
||||
else
|
||||
lookupInModule(decls, overlay, accessPath, moduleScopeContext,
|
||||
options);
|
||||
hasModuleSelector, options);
|
||||
}
|
||||
// FIXME: This may not work gracefully if more than one of these lookups
|
||||
// finds something.
|
||||
@@ -228,6 +234,8 @@ void ModuleNameLookup<LookupStrategy>::lookupInModule(
|
||||
currentModuleLookupFlags |= ModuleLookupFlags::ExcludeMacroExpansions;
|
||||
if (options & NL_ABIProviding)
|
||||
currentModuleLookupFlags |= ModuleLookupFlags::ABIProviding;
|
||||
if (hasModuleSelector)
|
||||
currentModuleLookupFlags |= ModuleLookupFlags::HasModuleSelector;
|
||||
|
||||
// Do the lookup into the current module.
|
||||
auto *module = moduleOrFile->getParentModule();
|
||||
@@ -255,6 +263,7 @@ void ModuleNameLookup<LookupStrategy>::lookupInModule(
|
||||
OptionSet<ModuleLookupFlags> importedModuleLookupFlags = {};
|
||||
if (options & NL_ABIProviding)
|
||||
currentModuleLookupFlags |= ModuleLookupFlags::ABIProviding;
|
||||
// Do not propagate HasModuleSelector here; the selector wasn't specific.
|
||||
|
||||
auto visitImport = [&](ImportedModule import,
|
||||
const DeclContext *moduleScopeContext) {
|
||||
@@ -357,27 +366,29 @@ void ModuleNameLookup<LookupStrategy>::lookupInModule(
|
||||
QualifiedLookupResult
|
||||
LookupInModuleRequest::evaluate(
|
||||
Evaluator &evaluator, const DeclContext *moduleOrFile, DeclName name,
|
||||
NLKind lookupKind, ResolutionKind resolutionKind,
|
||||
bool hasModuleSelector, NLKind lookupKind, ResolutionKind resolutionKind,
|
||||
const DeclContext *moduleScopeContext, NLOptions options) const {
|
||||
assert(moduleScopeContext->isModuleScopeContext());
|
||||
|
||||
QualifiedLookupResult decls;
|
||||
LookupByName lookup(moduleOrFile->getASTContext(), resolutionKind,
|
||||
name, lookupKind);
|
||||
lookup.lookupInModule(decls, moduleOrFile, {}, moduleScopeContext, options);
|
||||
lookup.lookupInModule(decls, moduleOrFile, {}, moduleScopeContext,
|
||||
hasModuleSelector, options);
|
||||
return decls;
|
||||
}
|
||||
|
||||
void namelookup::lookupInModule(const DeclContext *moduleOrFile,
|
||||
DeclName name,
|
||||
bool hasModuleSelector,
|
||||
SmallVectorImpl<ValueDecl *> &decls,
|
||||
NLKind lookupKind,
|
||||
ResolutionKind resolutionKind,
|
||||
const DeclContext *moduleScopeContext,
|
||||
SourceLoc loc, NLOptions options) {
|
||||
auto &ctx = moduleOrFile->getASTContext();
|
||||
LookupInModuleRequest req(moduleOrFile, name, lookupKind, resolutionKind,
|
||||
moduleScopeContext, loc, options);
|
||||
LookupInModuleRequest req(moduleOrFile, name, hasModuleSelector, lookupKind,
|
||||
resolutionKind, moduleScopeContext, loc, options);
|
||||
auto results = evaluateOrDefault(ctx.evaluator, req, {});
|
||||
decls.append(results.begin(), results.end());
|
||||
}
|
||||
@@ -393,6 +404,7 @@ void namelookup::lookupVisibleDeclsInModule(
|
||||
auto &ctx = moduleOrFile->getASTContext();
|
||||
LookupVisibleDecls lookup(ctx, resolutionKind, lookupKind);
|
||||
lookup.lookupInModule(decls, moduleOrFile, accessPath, moduleScopeContext,
|
||||
/*hasModuleSelector=*/false,
|
||||
NL_QualifiedDefault);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user