Skip to content

Commit 517f5d6

Browse files
authored
[ClangImporter] Retire the term "adapter" in favor of "overlay" (#24427)
Way back in Swift 1 I was trying to draw a distinction between "overlays", separate libraries that added Swift content to an existing Objective-C framework, and "the Swift part of a mixed-source framework", even though they're implemented in almost exactly the same way. "Adapter module" was the term that covered both of those. In practice, however, no one knew what "adapter" meant. Bring an end to this confusion by just using "overlay" within the compiler even for the mixed-source framework case. No intended functionality change.
1 parent f76d2c3 commit 517f5d6

File tree

19 files changed

+65
-66
lines changed

19 files changed

+65
-66
lines changed

include/swift/AST/Module.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,7 @@ class LoadedFile : public FileUnit {
13971397
}
13981398

13991399
/// Returns the Swift module that overlays a Clang module.
1400-
virtual ModuleDecl *getAdapterModule() const { return nullptr; }
1400+
virtual ModuleDecl *getOverlayModule() const { return nullptr; }
14011401

14021402
virtual bool isSystemModule() const { return false; }
14031403

include/swift/ClangImporter/ClangImporterOptions.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@ class ClangImporterOptions {
9494
/// and this is not set, clang will rebuild the module.
9595
bool DisableModulesValidateSystemHeaders = false;
9696

97-
/// When set, don't look for or load adapter modules.
98-
bool DisableAdapterModules = false;
97+
/// When set, don't look for or load overlays.
98+
bool DisableOverlayModules = false;
9999

100100
/// When set, don't enforce warnings with -Werror.
101101
bool DebuggerSupport = false;
@@ -118,7 +118,7 @@ class ClangImporterOptions {
118118
Code = hash_combine(Code, InferImportAsMember);
119119
Code = hash_combine(Code, DisableSwiftBridgeAttr);
120120
Code = hash_combine(Code, DisableModulesValidateSystemHeaders);
121-
Code = hash_combine(Code, DisableAdapterModules);
121+
Code = hash_combine(Code, DisableOverlayModules);
122122
return Code;
123123
}
124124
};

include/swift/ClangImporter/ClangModule.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ModuleLoader;
3434
class ClangModuleUnit final : public LoadedFile {
3535
ClangImporter::Implementation &owner;
3636
const clang::Module *clangModule;
37-
llvm::PointerIntPair<ModuleDecl *, 1, bool> adapterModule;
37+
llvm::PointerIntPair<ModuleDecl *, 1, bool> overlayModule;
3838
mutable ArrayRef<ModuleDecl::ImportedModule> importedModulesForLookup;
3939
/// The metadata of the underlying Clang module.
4040
clang::ExternalASTSource::ASTSourceDescriptor ASTSourceDescriptor;
@@ -57,7 +57,7 @@ class ClangModuleUnit final : public LoadedFile {
5757
bool isTopLevel() const;
5858

5959
/// Returns the Swift module that overlays this Clang module.
60-
ModuleDecl *getAdapterModule() const override;
60+
ModuleDecl *getOverlayModule() const override;
6161

6262
/// Retrieve the "exported" name of the module, which is usually the module
6363
/// name, but might be the name of the public module through which this

lib/AST/ProtocolConformance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ bool NormalProtocolConformance::isRetroactive() const {
441441
// defined in a Clang module.
442442
if (auto nominalLoadedModule =
443443
dyn_cast<LoadedFile>(nominal->getModuleScopeContext())) {
444-
if (auto overlayModule = nominalLoadedModule->getAdapterModule())
444+
if (auto overlayModule = nominalLoadedModule->getOverlayModule())
445445
nominalModule = overlayModule;
446446
}
447447

lib/ClangImporter/ClangImporter.cpp

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,13 +1627,12 @@ ModuleDecl *ClangImporter::loadModule(
16271627
if (!clangModule)
16281628
return nullptr;
16291629

1630-
return Impl.finishLoadingClangModule(clangModule,
1631-
/*preferAdapter=*/false);
1630+
return Impl.finishLoadingClangModule(clangModule, /*preferOverlay=*/false);
16321631
}
16331632

16341633
ModuleDecl *ClangImporter::Implementation::finishLoadingClangModule(
16351634
const clang::Module *clangModule,
1636-
bool findAdapter) {
1635+
bool findOverlay) {
16371636
assert(clangModule);
16381637

16391638
// Bump the generation count.
@@ -1645,7 +1644,7 @@ ModuleDecl *ClangImporter::Implementation::finishLoadingClangModule(
16451644
if ((wrapperUnit = cacheEntry.getPointer())) {
16461645
result = wrapperUnit->getParentModule();
16471646
if (!cacheEntry.getInt()) {
1648-
// Force load adapter modules for all imported modules.
1647+
// Force load overlays for all imported modules.
16491648
// FIXME: This forces the creation of wrapper modules for all imports as
16501649
// well, and may do unnecessary work.
16511650
cacheEntry.setInt(true);
@@ -1666,7 +1665,7 @@ ModuleDecl *ClangImporter::Implementation::finishLoadingClangModule(
16661665
result->addFile(*wrapperUnit);
16671666
cacheEntry.setPointerAndInt(wrapperUnit, true);
16681667

1669-
// Force load adapter modules for all imported modules.
1668+
// Force load overlays for all imported modules.
16701669
// FIXME: This forces the creation of wrapper modules for all imports as
16711670
// well, and may do unnecessary work.
16721671
result->forAllVisibleModules({}, [](ModuleDecl::ImportedModule import) {});
@@ -1680,9 +1679,9 @@ ModuleDecl *ClangImporter::Implementation::finishLoadingClangModule(
16801679
loaded = result;
16811680
}
16821681

1683-
if (findAdapter)
1684-
if (ModuleDecl *adapter = wrapperUnit->getAdapterModule())
1685-
result = adapter;
1682+
if (findOverlay)
1683+
if (ModuleDecl *overlay = wrapperUnit->getOverlayModule())
1684+
result = overlay;
16861685

16871686
return result;
16881687
}
@@ -1702,7 +1701,7 @@ void ClangImporter::Implementation::handleDeferredImports()
17021701
}
17031702
PCHImportedSubmodules.clear();
17041703
for (const clang::Module *M : ImportedHeaderExports)
1705-
(void)finishLoadingClangModule(M, /*preferAdapter=*/true);
1704+
(void)finishLoadingClangModule(M, /*preferOverlay=*/true);
17061705
}
17071706

17081707
ModuleDecl *ClangImporter::getImportedHeaderModule() const {
@@ -1801,7 +1800,7 @@ ClangImporter::Implementation::Implementation(ASTContext &ctx,
18011800
InferImportAsMember(opts.InferImportAsMember),
18021801
DisableSwiftBridgeAttr(opts.DisableSwiftBridgeAttr),
18031802
BridgingHeaderExplicitlyRequested(!opts.BridgingHeader.empty()),
1804-
DisableAdapterModules(opts.DisableAdapterModules),
1803+
DisableOverlayModules(opts.DisableOverlayModules),
18051804
IsReadingBridgingPCH(false),
18061805
CurrentVersion(ImportNameVersion::fromOptions(ctx.LangOpts)),
18071806
BridgingHeaderLookupTable(new SwiftLookupTable(nullptr)),
@@ -3164,40 +3163,40 @@ StringRef ClangModuleUnit::getExportedModuleName() const {
31643163
return getParentModule()->getName().str();
31653164
}
31663165

3167-
ModuleDecl *ClangModuleUnit::getAdapterModule() const {
3166+
ModuleDecl *ClangModuleUnit::getOverlayModule() const {
31683167
if (!clangModule)
31693168
return nullptr;
31703169

3171-
if (owner.DisableAdapterModules)
3170+
if (owner.DisableOverlayModules)
31723171
return nullptr;
31733172

31743173
if (!isTopLevel()) {
31753174
// FIXME: Is this correct for submodules?
31763175
auto topLevel = clangModule->getTopLevelModule();
31773176
auto wrapper = owner.getWrapperForModule(topLevel);
3178-
return wrapper->getAdapterModule();
3177+
return wrapper->getOverlayModule();
31793178
}
31803179

3181-
if (!adapterModule.getInt()) {
3180+
if (!overlayModule.getInt()) {
31823181
// FIXME: Include proper source location.
31833182
ModuleDecl *M = getParentModule();
31843183
ASTContext &Ctx = M->getASTContext();
3185-
auto adapter = Ctx.getModule(ModuleDecl::AccessPathTy({M->getName(),
3186-
SourceLoc()}));
3187-
if (adapter == M) {
3188-
adapter = nullptr;
3184+
auto overlay = Ctx.getModule(ModuleDecl::AccessPathTy({M->getName(),
3185+
SourceLoc()}));
3186+
if (overlay == M) {
3187+
overlay = nullptr;
31893188
} else {
31903189
auto &sharedModuleRef = Ctx.LoadedModules[M->getName()];
3191-
assert(!sharedModuleRef || sharedModuleRef == adapter ||
3190+
assert(!sharedModuleRef || sharedModuleRef == overlay ||
31923191
sharedModuleRef == M);
3193-
sharedModuleRef = adapter;
3192+
sharedModuleRef = overlay;
31943193
}
31953194

31963195
auto mutableThis = const_cast<ClangModuleUnit *>(this);
3197-
mutableThis->adapterModule.setPointerAndInt(adapter, true);
3196+
mutableThis->overlayModule.setPointerAndInt(overlay, true);
31983197
}
31993198

3200-
return adapterModule.getPointer();
3199+
return overlayModule.getPointer();
32013200
}
32023201

32033202
void ClangModuleUnit::getImportedModules(
@@ -3243,11 +3242,11 @@ void ClangModuleUnit::getImportedModules(
32433242
}
32443243
}
32453244

3246-
auto topLevelAdapter = getAdapterModule();
3245+
auto topLevelOverlay = getOverlayModule();
32473246
for (auto importMod : imported) {
32483247
auto wrapper = owner.getWrapperForModule(importMod);
32493248

3250-
auto actualMod = wrapper->getAdapterModule();
3249+
auto actualMod = wrapper->getOverlayModule();
32513250
if (!actualMod) {
32523251
// HACK: Deal with imports of submodules by importing the top-level module
32533252
// as well.
@@ -3260,11 +3259,11 @@ void ClangModuleUnit::getImportedModules(
32603259
}
32613260
}
32623261
actualMod = wrapper->getParentModule();
3263-
} else if (actualMod == topLevelAdapter) {
3262+
} else if (actualMod == topLevelOverlay) {
32643263
actualMod = wrapper->getParentModule();
32653264
}
32663265

3267-
assert(actualMod && "Missing imported adapter module");
3266+
assert(actualMod && "Missing imported overlay");
32683267
imports.push_back({ModuleDecl::AccessPathTy(), actualMod});
32693268
}
32703269
}
@@ -3283,7 +3282,7 @@ void ClangModuleUnit::getImportedModulesForLookup(
32833282

32843283
SmallVector<clang::Module *, 8> imported;
32853284
const clang::Module *topLevel;
3286-
ModuleDecl *topLevelAdapter = getAdapterModule();
3285+
ModuleDecl *topLevelOverlay = getOverlayModule();
32873286
if (!clangModule) {
32883287
// This is the special "imported headers" module.
32893288
imported.append(owner.ImportedHeaderExports.begin(),
@@ -3315,7 +3314,7 @@ void ClangModuleUnit::getImportedModulesForLookup(
33153314
// Don't continue looking through submodules of modules that have
33163315
// overlays. The overlay might shadow things.
33173316
auto wrapper = owner.getWrapperForModule(nextTopLevel);
3318-
if (wrapper->getAdapterModule())
3317+
if (wrapper->getOverlayModule())
33193318
continue;
33203319
}
33213320

@@ -3334,11 +3333,11 @@ void ClangModuleUnit::getImportedModulesForLookup(
33343333
for (auto importMod : topLevelImported) {
33353334
auto wrapper = owner.getWrapperForModule(importMod);
33363335

3337-
auto actualMod = wrapper->getAdapterModule();
3338-
if (!actualMod || actualMod == topLevelAdapter)
3336+
auto actualMod = wrapper->getOverlayModule();
3337+
if (!actualMod || actualMod == topLevelOverlay)
33393338
actualMod = wrapper->getParentModule();
33403339

3341-
assert(actualMod && "Missing imported adapter module");
3340+
assert(actualMod && "Missing imported overlay");
33423341
imports.push_back({ModuleDecl::AccessPathTy(), actualMod});
33433342
}
33443343

@@ -3725,7 +3724,7 @@ bool ClangImporter::isInOverlayModuleForImportedModule(
37253724
return false;
37263725

37273726
auto overlayModule = overlayDC->getParentModule();
3728-
if (overlayModule == importedClangModuleUnit->getAdapterModule())
3727+
if (overlayModule == importedClangModuleUnit->getOverlayModule())
37293728
return true;
37303729

37313730
// Is this a private module that's re-exported to the public (overlay) name?

lib/ClangImporter/ImportDecl.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4330,12 +4330,12 @@ namespace {
43304330
}
43314331

43324332
template <typename T, typename U>
4333-
T *resolveSwiftDeclImpl(const U *decl, Identifier name, ModuleDecl *adapter) {
4333+
T *resolveSwiftDeclImpl(const U *decl, Identifier name, ModuleDecl *overlay) {
43344334
const auto &languageVersion =
43354335
Impl.SwiftContext.LangOpts.EffectiveLanguageVersion;
43364336

43374337
SmallVector<ValueDecl *, 4> results;
4338-
adapter->lookupValue({}, name, NLKind::QualifiedLookup, results);
4338+
overlay->lookupValue({}, name, NLKind::QualifiedLookup, results);
43394339
T *found = nullptr;
43404340
for (auto result : results) {
43414341
if (auto singleResult = dyn_cast<T>(result)) {
@@ -4361,8 +4361,8 @@ namespace {
43614361
template <typename T, typename U>
43624362
T *resolveSwiftDecl(const U *decl, Identifier name,
43634363
ClangModuleUnit *clangModule) {
4364-
if (auto adapter = clangModule->getAdapterModule())
4365-
return resolveSwiftDeclImpl<T>(decl, name, adapter);
4364+
if (auto overlay = clangModule->getOverlayModule())
4365+
return resolveSwiftDeclImpl<T>(decl, name, overlay);
43664366
if (clangModule == Impl.ImportedHeaderUnit) {
43674367
// Use an index-based loop because new owners can come in as we're
43684368
// iterating.
@@ -4414,7 +4414,7 @@ namespace {
44144414
// FIXME: Figure out how to deal with incomplete protocols, since that
44154415
// notion doesn't exist in Swift.
44164416
if (!decl->hasDefinition()) {
4417-
// Check if this protocol is implemented in its adapter.
4417+
// Check if this protocol is implemented in its overlay.
44184418
if (auto clangModule = Impl.getClangModuleForDecl(decl, true))
44194419
if (auto native = resolveSwiftDecl<ProtocolDecl>(decl, name,
44204420
clangModule))
@@ -4545,7 +4545,7 @@ namespace {
45454545
auto name = importedName.getDeclName().getBaseIdentifier();
45464546

45474547
if (!decl->hasDefinition()) {
4548-
// Check if this class is implemented in its adapter.
4548+
// Check if this class is implemented in its overlay.
45494549
if (auto clangModule = Impl.getClangModuleForDecl(decl, true)) {
45504550
if (auto native = resolveSwiftDecl<ClassDecl>(decl, name,
45514551
clangModule)) {
@@ -5199,13 +5199,13 @@ static bool conformsToProtocolInOriginalModule(NominalTypeDecl *nominal,
51995199
const DeclContext *containingFile = nominal->getModuleScopeContext();
52005200
ModuleDecl *originalModule = containingFile->getParentModule();
52015201

5202-
ModuleDecl *adapterModule = nullptr;
5202+
ModuleDecl *overlayModule = nullptr;
52035203
if (auto *clangUnit = dyn_cast<ClangModuleUnit>(containingFile))
5204-
adapterModule = clangUnit->getAdapterModule();
5204+
overlayModule = clangUnit->getOverlayModule();
52055205

52065206
for (ExtensionDecl *extension : nominal->getExtensions()) {
52075207
ModuleDecl *extensionModule = extension->getParentModule();
5208-
if (extensionModule != originalModule && extensionModule != adapterModule &&
5208+
if (extensionModule != originalModule && extensionModule != overlayModule &&
52095209
extensionModule != foundationModule) {
52105210
continue;
52115211
}
@@ -5302,7 +5302,7 @@ SwiftDeclConverter::importSwiftNewtype(const clang::TypedefNameDecl *decl,
53025302
return false;
53035303

53045304
// Break circularity by only looking for declared conformances in the
5305-
// original module, or possibly its adapter.
5305+
// original module, or possibly its overlay.
53065306
if (conformsToProtocolInOriginalModule(computedNominal, proto,
53075307
Impl.tryLoadFoundationModule(),
53085308
Impl.getTypeResolver())) {

lib/ClangImporter/ImportType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2354,7 +2354,7 @@ Type ClangImporter::Implementation::getNamedSwiftType(ModuleDecl *module,
23542354
if (auto clangUnit = dyn_cast<ClangModuleUnit>(file)) {
23552355
// If we have an overlay, look in the overlay. Otherwise, skip
23562356
// the lookup to avoid infinite recursion.
2357-
if (auto module = clangUnit->getAdapterModule())
2357+
if (auto module = clangUnit->getOverlayModule())
23582358
module->lookupValue({ }, identifier,
23592359
NLKind::UnqualifiedLookup, results);
23602360
} else {

lib/ClangImporter/ImporterImpl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
334334
const bool InferImportAsMember;
335335
const bool DisableSwiftBridgeAttr;
336336
const bool BridgingHeaderExplicitlyRequested;
337-
const bool DisableAdapterModules;
337+
const bool DisableOverlayModules;
338338

339339
bool IsReadingBridgingPCH;
340340
llvm::SmallVector<clang::serialization::SubmoduleID, 2> PCHImportedSubmodules;
@@ -520,7 +520,7 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
520520
Type NSObjectTy;
521521

522522
/// A pair containing a ClangModuleUnit,
523-
/// and whether the adapters of its re-exported modules have all been forced
523+
/// and whether the overlays of its re-exported modules have all been forced
524524
/// to load already.
525525
using ModuleInitPair = llvm::PointerIntPair<ClangModuleUnit *, 1, bool>;
526526

@@ -894,7 +894,7 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
894894

895895
/// Constructs a Swift module for the given Clang module.
896896
ModuleDecl *finishLoadingClangModule(const clang::Module *clangModule,
897-
bool preferAdapter);
897+
bool preferOverlay);
898898

899899
/// Call finishLoadingClangModule on each deferred import collected
900900
/// while scanning a bridging header or PCH.

lib/DWARFImporter/DWARFImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class DWARFImporter::Implementation {
127127
ModuleWrappers.insert({name, wrapperUnit});
128128
decl->addFile(*wrapperUnit);
129129

130-
// Force load adapter modules for all imported modules.
130+
// Force load overlay modules for all imported modules.
131131
decl->forAllVisibleModules({}, [](ModuleDecl::ImportedModule import) {});
132132

133133
return decl;

lib/Frontend/CompilerInvocation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ static bool ParseClangImporterArgs(ClangImporterOptions &Opts,
558558

559559
Opts.DisableModulesValidateSystemHeaders |= Args.hasArg(OPT_disable_modules_validate_system_headers);
560560

561-
Opts.DisableAdapterModules |= Args.hasArg(OPT_emit_imported_modules);
561+
Opts.DisableOverlayModules |= Args.hasArg(OPT_emit_imported_modules);
562562

563563
if (const Arg *A = Args.getLastArg(OPT_pch_output_dir)) {
564564
Opts.PrecompiledHeaderOutputDir = A->getValue();

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ bool WitnessChecker::findBestWitness(
11281128
if (!clangModule)
11291129
continue;
11301130

1131-
DeclContext *overlay = clangModule->getAdapterModule();
1131+
DeclContext *overlay = clangModule->getOverlayModule();
11321132
if (!overlay)
11331133
continue;
11341134

test/ClangImporter/Inputs/adapter.swift

Lines changed: 0 additions & 3 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
@import ClangModuleWithAdapter;
1+
@import ClangModuleWithOverlay;

test/ClangImporter/Inputs/custom-modules/module.map

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module ClangModuleUser {
2222
export *
2323
}
2424

25-
module ClangModuleWithAdapter {
25+
module ClangModuleWithOverlay {
2626
link "UnderlyingClangLibrary"
2727
}
2828

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@_exported import ClangModuleWithOverlay
2+
3+
public func fromSwiftOverlay() {}

0 commit comments

Comments
 (0)