Skip to content

Commit d32a371

Browse files
Merge pull request #34410 from varungandhi-apple/vg-revert-import-filtering-refactor
Revert "[NFC] Clarify semantics of getImportedModules."
2 parents dabdd96 + 1f47989 commit d32a371

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();
@@ -1190,13 +1190,6 @@ void SourceFile::lookupPrecedenceGroupDirect(
11901190

11911191
void ModuleDecl::getImportedModules(SmallVectorImpl<ImportedModule> &modules,
11921192
ModuleDecl::ImportFilter filter) const {
1193-
assert(filter.containsAny(ImportFilter({
1194-
ModuleDecl::ImportFilterKind::Exported,
1195-
ModuleDecl::ImportFilterKind::Default,
1196-
ModuleDecl::ImportFilterKind::ImplementationOnly}))
1197-
&& "filter should have at least one of Exported|Private|ImplementationOnly"
1198-
);
1199-
12001193
FORWARD(getImportedModules, (modules, filter));
12011194
}
12021195

@@ -1221,12 +1214,11 @@ SourceFile::getImportedModules(SmallVectorImpl<ImportedModule> &modules,
12211214
requiredFilter |= ModuleDecl::ImportFilterKind::Exported;
12221215
else if (desc.options.contains(ImportFlags::ImplementationOnly))
12231216
requiredFilter |= ModuleDecl::ImportFilterKind::ImplementationOnly;
1217+
else if (desc.options.contains(ImportFlags::SPIAccessControl))
1218+
requiredFilter |= ModuleDecl::ImportFilterKind::SPIAccessControl;
12241219
else
12251220
requiredFilter |= ModuleDecl::ImportFilterKind::Default;
12261221

1227-
if (desc.options.contains(ImportFlags::SPIAccessControl))
1228-
requiredFilter |= ModuleDecl::ImportFilterKind::SPIAccessControl;
1229-
12301222
if (!separatelyImportedOverlays.lookup(desc.module.importedModule).empty())
12311223
requiredFilter |= ModuleDecl::ImportFilterKind::ShadowedByCrossImportOverlay;
12321224

@@ -2401,7 +2393,7 @@ bool FileUnit::walk(ASTWalker &walker) {
24012393
#ifndef NDEBUG
24022394
PrettyStackTraceDecl debugStack("walking into decl", D);
24032395
#endif
2404-
2396+
24052397
if (D->walk(walker))
24062398
return true;
24072399

@@ -2540,15 +2532,15 @@ SourceFile::lookupOpaqueResultType(StringRef MangledName) {
25402532
auto found = ValidatedOpaqueReturnTypes.find(MangledName);
25412533
if (found != ValidatedOpaqueReturnTypes.end())
25422534
return found->second;
2543-
2535+
25442536
// If there are unvalidated decls with opaque types, go through and validate
25452537
// them now.
25462538
(void) getOpaqueReturnTypeDecls();
25472539

25482540
found = ValidatedOpaqueReturnTypes.find(MangledName);
25492541
if (found != ValidatedOpaqueReturnTypes.end())
25502542
return found->second;
2551-
2543+
25522544
// Otherwise, we don't have a matching opaque decl.
25532545
return nullptr;
25542546
}

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
@@ -1057,11 +1057,7 @@ void Serializer::writeInputBlock(const SerializationOptions &options) {
10571057
ImportSet privateImportSet =
10581058
getImportsAsSet(M, ModuleDecl::ImportFilterKind::Default);
10591059
ImportSet spiImportSet =
1060-
getImportsAsSet(M, {
1061-
ModuleDecl::ImportFilterKind::Exported,
1062-
ModuleDecl::ImportFilterKind::Default,
1063-
ModuleDecl::ImportFilterKind::SPIAccessControl
1064-
});
1060+
getImportsAsSet(M, ModuleDecl::ImportFilterKind::SPIAccessControl);
10651061

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

0 commit comments

Comments
 (0)