Skip to content

Commit 1f47989

Browse files
Revert "[NFC] Clarify semantics of getImportedModules."
This reverts commit 4b5d885.
1 parent 785b182 commit 1f47989

File tree

6 files changed

+18
-68
lines changed

6 files changed

+18
-68
lines changed

include/swift/AST/Module.h

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,7 @@ class ModuleDecl : public DeclContext, public TypeDecl {
593593
Default = 1 << 1,
594594
/// Include imports declared with `@_implementationOnly`.
595595
ImplementationOnly = 1 << 2,
596-
/// Include imports of SPIs declared with `@_spi`. Non-SPI imports are
597-
/// included whether or not this flag is specified.
596+
/// Include imports of SPIs declared with `@_spi`
598597
SPIAccessControl = 1 << 3,
599598
/// Include imports shadowed by a cross-import overlay. Unshadowed imports
600599
/// are included whether or not this flag is specified.
@@ -605,33 +604,8 @@ class ModuleDecl : public DeclContext, public TypeDecl {
605604

606605
/// Looks up which modules are imported by this module.
607606
///
608-
/// \p filter controls which imports are included in the list.
609-
///
610-
/// There are three axes for categorizing imports:
611-
/// 1. Privacy: Exported/Private/ImplementationOnly (mutually exclusive).
612-
/// 2. SPI/non-SPI: An import of any privacy level may be @_spi("SPIName").
613-
/// 3. Shadowed/Non-shadowed: An import of any privacy level may be shadowed
614-
/// by a cross-import overlay.
615-
///
616-
/// It is also possible for SPI imports to be shadowed by a cross-import
617-
/// overlay.
618-
///
619-
/// If \p filter contains multiple privacy levels, modules at all the privacy
620-
/// levels are included.
621-
///
622-
/// If \p filter contains \c ImportFilterKind::SPIAccessControl, then both
623-
/// SPI and non-SPI imports are included. Otherwise, only non-SPI imports are
624-
/// included.
625-
///
626-
/// If \p filter contains \c ImportFilterKind::ShadowedByCrossImportOverlay,
627-
/// both shadowed and non-shadowed imports are included. Otherwise, only
628-
/// non-shadowed imports are included.
629-
///
630-
/// Clang modules have some additional complexities; see the implementation of
631-
/// \c ClangModuleUnit::getImportedModules for details.
632-
///
633-
/// \pre \p filter must contain at least one privacy level, i.e. one of
634-
/// \c Exported or \c Private or \c ImplementationOnly.
607+
/// \p filter controls whether public, private, or any imports are included
608+
/// in this list.
635609
void getImportedModules(SmallVectorImpl<ImportedModule> &imports,
636610
ImportFilter filter = ImportFilterKind::Exported) const;
637611

include/swift/Basic/OptionSet.h

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
#include "llvm/ADT/None.h"
2121

22-
#include <cassert>
2322
#include <type_traits>
2423
#include <cstdint>
2524
#include <initializer_list>
@@ -99,14 +98,6 @@ class OptionSet {
9998
return Storage == set.Storage;
10099
}
101100

102-
/// Check if this option set contains any options from \p set.
103-
///
104-
/// \pre \p set must be non-empty.
105-
bool containsAny(OptionSet set) const {
106-
assert((bool)set && "argument must be non-empty");
107-
return (bool)((*this) & set);
108-
}
109-
110101
// '==' and '!=' are deliberately not defined because they provide a pitfall
111102
// where someone might use '==' but really want 'contains'. If you actually
112103
// want '==' behavior, use 'containsOnly'.

lib/AST/ImportCache.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ ImportSet &ImportCache::getImportSet(const DeclContext *dc) {
174174
imports.emplace_back(ImportPath::Access(), mod);
175175

176176
if (file) {
177-
// Should include both SPI & non-SPI.
178177
file->getImportedModules(imports,
179178
{ModuleDecl::ImportFilterKind::Default,
180179
ModuleDecl::ImportFilterKind::ImplementationOnly,
@@ -259,7 +258,6 @@ ImportCache::getAllAccessPathsNotShadowedBy(const ModuleDecl *mod,
259258
stack.emplace_back(ImportPath::Access(), currentMod);
260259

261260
if (auto *file = dyn_cast<FileUnit>(dc)) {
262-
// Should include both SPI & non-SPI
263261
file->getImportedModules(stack,
264262
{ModuleDecl::ImportFilterKind::Default,
265263
ModuleDecl::ImportFilterKind::ImplementationOnly,

lib/AST/Module.cpp

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ void BuiltinUnit::LookupCache::lookupValue(
9595
SmallVectorImpl<ValueDecl*> &Result) {
9696
// Only qualified lookup ever finds anything in the builtin module.
9797
if (LookupKind != NLKind::QualifiedLookup) return;
98-
98+
9999
ValueDecl *&Entry = Cache[Name];
100100
ASTContext &Ctx = M.getParentModule()->getASTContext();
101101
if (!Entry) {
@@ -175,7 +175,7 @@ class swift::SourceLookupCache {
175175

176176
/// Throw away as much memory as possible.
177177
void invalidate();
178-
178+
179179
void lookupValue(DeclName Name, NLKind LookupKind,
180180
SmallVectorImpl<ValueDecl*> &Result);
181181

@@ -203,13 +203,13 @@ class swift::SourceLookupCache {
203203
void lookupVisibleDecls(ImportPath::Access AccessPath,
204204
VisibleDeclConsumer &Consumer,
205205
NLKind LookupKind);
206-
206+
207207
void populateMemberCache(const SourceFile &SF);
208208
void populateMemberCache(const ModuleDecl &Mod);
209209

210210
void lookupClassMembers(ImportPath::Access AccessPath,
211211
VisibleDeclConsumer &consumer);
212-
212+
213213
void lookupClassMember(ImportPath::Access accessPath,
214214
DeclName name,
215215
SmallVectorImpl<ValueDecl*> &results);
@@ -331,7 +331,7 @@ void SourceLookupCache::lookupValue(DeclName Name, NLKind LookupKind,
331331
SmallVectorImpl<ValueDecl*> &Result) {
332332
auto I = TopLevelValues.find(Name);
333333
if (I == TopLevelValues.end()) return;
334-
334+
335335
Result.reserve(I->second.size());
336336
for (ValueDecl *Elt : I->second)
337337
Result.push_back(Elt);
@@ -398,7 +398,7 @@ void SourceLookupCache::lookupVisibleDecls(ImportPath::Access AccessPath,
398398
void SourceLookupCache::lookupClassMembers(ImportPath::Access accessPath,
399399
VisibleDeclConsumer &consumer) {
400400
assert(accessPath.size() <= 1 && "can only refer to top-level decls");
401-
401+
402402
if (!accessPath.empty()) {
403403
for (auto &member : ClassMembers) {
404404
// Non-simple names are also stored under their simple name, so make
@@ -432,11 +432,11 @@ void SourceLookupCache::lookupClassMember(ImportPath::Access accessPath,
432432
DeclName name,
433433
SmallVectorImpl<ValueDecl*> &results) {
434434
assert(accessPath.size() <= 1 && "can only refer to top-level decls");
435-
435+
436436
auto iter = ClassMembers.find(name);
437437
if (iter == ClassMembers.end())
438438
return;
439-
439+
440440
if (!accessPath.empty()) {
441441
for (ValueDecl *vd : iter->second) {
442442
auto *nominal = vd->getDeclContext()->getSelfNominalTypeDecl();
@@ -1163,13 +1163,6 @@ void SourceFile::lookupPrecedenceGroupDirect(
11631163

11641164
void ModuleDecl::getImportedModules(SmallVectorImpl<ImportedModule> &modules,
11651165
ModuleDecl::ImportFilter filter) const {
1166-
assert(filter.containsAny(ImportFilter({
1167-
ModuleDecl::ImportFilterKind::Exported,
1168-
ModuleDecl::ImportFilterKind::Default,
1169-
ModuleDecl::ImportFilterKind::ImplementationOnly}))
1170-
&& "filter should have at least one of Exported|Private|ImplementationOnly"
1171-
);
1172-
11731166
FORWARD(getImportedModules, (modules, filter));
11741167
}
11751168

@@ -1194,12 +1187,11 @@ SourceFile::getImportedModules(SmallVectorImpl<ImportedModule> &modules,
11941187
requiredFilter |= ModuleDecl::ImportFilterKind::Exported;
11951188
else if (desc.options.contains(ImportFlags::ImplementationOnly))
11961189
requiredFilter |= ModuleDecl::ImportFilterKind::ImplementationOnly;
1190+
else if (desc.options.contains(ImportFlags::SPIAccessControl))
1191+
requiredFilter |= ModuleDecl::ImportFilterKind::SPIAccessControl;
11971192
else
11981193
requiredFilter |= ModuleDecl::ImportFilterKind::Default;
11991194

1200-
if (desc.options.contains(ImportFlags::SPIAccessControl))
1201-
requiredFilter |= ModuleDecl::ImportFilterKind::SPIAccessControl;
1202-
12031195
if (!separatelyImportedOverlays.lookup(desc.module.importedModule).empty())
12041196
requiredFilter |= ModuleDecl::ImportFilterKind::ShadowedByCrossImportOverlay;
12051197

@@ -2374,7 +2366,7 @@ bool FileUnit::walk(ASTWalker &walker) {
23742366
#ifndef NDEBUG
23752367
PrettyStackTraceDecl debugStack("walking into decl", D);
23762368
#endif
2377-
2369+
23782370
if (D->walk(walker))
23792371
return true;
23802372

@@ -2513,15 +2505,15 @@ SourceFile::lookupOpaqueResultType(StringRef MangledName) {
25132505
auto found = ValidatedOpaqueReturnTypes.find(MangledName);
25142506
if (found != ValidatedOpaqueReturnTypes.end())
25152507
return found->second;
2516-
2508+
25172509
// If there are unvalidated decls with opaque types, go through and validate
25182510
// them now.
25192511
(void) getOpaqueReturnTypeDecls();
25202512

25212513
found = ValidatedOpaqueReturnTypes.find(MangledName);
25222514
if (found != ValidatedOpaqueReturnTypes.end())
25232515
return found->second;
2524-
2516+
25252517
// Otherwise, we don't have a matching opaque decl.
25262518
return nullptr;
25272519
}

lib/Frontend/ModuleInterfaceSupport.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,7 @@ static void printImports(raw_ostream &out,
115115

116116
SmallVector<ImportedModule, 4> ioiImport;
117117
M->getImportedModules(ioiImport,
118-
{ModuleDecl::ImportFilterKind::ImplementationOnly,
119-
ModuleDecl::ImportFilterKind::SPIAccessControl});
118+
ModuleDecl::ImportFilterKind::ImplementationOnly);
120119
ioiImportSet.insert(ioiImport.begin(), ioiImport.end());
121120
}
122121

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,11 +1055,7 @@ void Serializer::writeInputBlock(const SerializationOptions &options) {
10551055
ImportSet privateImportSet =
10561056
getImportsAsSet(M, ModuleDecl::ImportFilterKind::Default);
10571057
ImportSet spiImportSet =
1058-
getImportsAsSet(M, {
1059-
ModuleDecl::ImportFilterKind::Exported,
1060-
ModuleDecl::ImportFilterKind::Default,
1061-
ModuleDecl::ImportFilterKind::SPIAccessControl
1062-
});
1058+
getImportsAsSet(M, ModuleDecl::ImportFilterKind::SPIAccessControl);
10631059

10641060
auto clangImporter =
10651061
static_cast<ClangImporter *>(M->getASTContext().getClangModuleLoader());

0 commit comments

Comments
 (0)