mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Lock down on exports from TranslationUnit modules.
Previously, export control (via [exported]) only applied to modules that had been serialized -- anything imported in a TranslationUnit was automatically considered exported. This was done to make life easier when dealing with the main source file, but it turns out we're going to want to load other source files as imports, and export control should work there too. Now, the module iteration methods (Module::forAllVisibleModules, namelookup::lookupInModule, etc.) can consider the module being passed as "top-level", meaning its private imports are visible as well. Otherwise, proper export control is observed even for imported TranslationUnits. This required a number of test changes involving Swift adapter modules that forgot to re-export their Clang modules. Swift SVN r7783
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
||||
#include "ModuleNameLookup.h"
|
||||
#include "llvm/Support/raw_ostream.h"
|
||||
|
||||
using namespace swift;
|
||||
using namespace namelookup;
|
||||
@@ -133,7 +134,8 @@ template <typename OverloadSetTy, typename CallbackTy>
|
||||
static void lookupInModule(Module *module, Module::AccessPathTy accessPath,
|
||||
SmallVectorImpl<ValueDecl *> &decls,
|
||||
ResolutionKind resolutionKind, bool canReturnEarly,
|
||||
ModuleLookupCache &cache, CallbackTy callback) {
|
||||
ModuleLookupCache &cache, bool topLevel,
|
||||
CallbackTy callback) {
|
||||
ModuleLookupCache::MapTy::iterator iter;
|
||||
bool isNew;
|
||||
std::tie(iter, isNew) = cache.Map.insert({{accessPath, module}, {}});
|
||||
@@ -166,7 +168,7 @@ static void lookupInModule(Module *module, Module::AccessPathTy accessPath,
|
||||
if (!foundDecls || !canReturnEarly ||
|
||||
resolutionKind == ResolutionKind::Overloadable) {
|
||||
SmallVector<Module::ImportedModule, 8> reexports;
|
||||
module->getImportedModules(reexports);
|
||||
module->getImportedModules(reexports, topLevel);
|
||||
|
||||
// Prefer scoped imports (import func swift.max) to whole-module imports.
|
||||
SmallVector<ValueDecl *, 8> unscopedValues;
|
||||
@@ -190,7 +192,7 @@ static void lookupInModule(Module *module, Module::AccessPathTy accessPath,
|
||||
auto &resultSet = next.first.empty() ? unscopedValues : scopedValues;
|
||||
lookupInModule<OverloadSetTy>(next.second, combinedAccessPath,
|
||||
resultSet, resolutionKind, canReturnEarly,
|
||||
cache, callback);
|
||||
cache, false, callback);
|
||||
}
|
||||
|
||||
// Add the results from scoped imports.
|
||||
@@ -216,16 +218,17 @@ static void lookupInModule(Module *module, Module::AccessPathTy accessPath,
|
||||
decls.end());
|
||||
}
|
||||
|
||||
void namelookup::lookupInModule(Module *topLevel,
|
||||
void namelookup::lookupInModule(Module *startModule,
|
||||
Module::AccessPathTy topAccessPath,
|
||||
Identifier name,
|
||||
SmallVectorImpl<ValueDecl *> &decls,
|
||||
NLKind lookupKind,
|
||||
ResolutionKind resolutionKind) {
|
||||
ResolutionKind resolutionKind,
|
||||
bool topLevel) {
|
||||
ModuleLookupCache cache;
|
||||
::lookupInModule<CanTypeSet>(topLevel, topAccessPath, decls,
|
||||
::lookupInModule<CanTypeSet>(startModule, topAccessPath, decls,
|
||||
resolutionKind, /*canReturnEarly=*/true,
|
||||
cache,
|
||||
cache, topLevel,
|
||||
[=](Module *module, Module::AccessPathTy path,
|
||||
SmallVectorImpl<ValueDecl *> &localDecls) {
|
||||
module->lookupValue(path, name, lookupKind, localDecls);
|
||||
@@ -256,7 +259,7 @@ void namelookup::lookupVisibleDeclsInModule(Module *topLevel,
|
||||
ModuleLookupCache cache;
|
||||
::lookupInModule<NamedCanTypeSet>(topLevel, topAccessPath, decls,
|
||||
resolutionKind, /*canReturnEarly=*/false,
|
||||
cache,
|
||||
cache, /*topLevel=*/true,
|
||||
[=](Module *module, Module::AccessPathTy path,
|
||||
SmallVectorImpl<ValueDecl *> &localDecls) {
|
||||
VectorDeclConsumer consumer(localDecls);
|
||||
|
||||
Reference in New Issue
Block a user