Add mechanism for per-SourceFile overlays

When a “separately imported overlay” is added to a SourceFile, two things happen:

1. The direct import of the underlying module is removed from getImports*() by default. It is only visible if the caller passes ImportFilterKind:: ShadowedBySeparateOverlay. This means that non-module-scoped lookups will search _OverlayModule before searching its re-export UnderlyingModule, allowing it to shadow underlying declarations.

2. When you ask for lookupInModule() to look in the underlying module in that source file, it looks in the overlays instead. This means that UnderlyingModule.foo() can find declarations in _OverlayModule.
This commit is contained in:
Brent Royal-Gordon
2020-02-15 12:35:45 -08:00
parent e248f82773
commit f8df2f66fd
13 changed files with 85 additions and 6 deletions

View File

@@ -883,6 +883,7 @@ static void collectModuleDependencies(ModuleDecl *TopMod,
// Only collect implementation-only dependencies from the main module.
ImportFilter |= ModuleDecl::ImportFilterKind::ImplementationOnly;
}
// FIXME: ImportFilterKind::ShadowedBySeparateOverlay?
SmallVector<ModuleDecl::ImportedModule, 8> Imports;
TopMod->getImportedModules(Imports, ImportFilter);