Skip to content

Commit cafb064

Browse files
author
Harlan Haskins
committed
---
yaml --- r: 284157 b: refs/heads/swift-5.1-branch c: 3c27d9d h: refs/heads/master i: 284155: f5779c1
1 parent 474057e commit cafb064

24 files changed

+184
-1200
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1242,7 +1242,7 @@ refs/heads/marcrasi-astverifier-disable: 3fac766a23a77ebd0640296bfd7fc116ea60a4e
12421242
refs/heads/revert-22227-a-tall-white-fountain-played: adfce60b2eaa54903ea189bed8a783bca609fa53
12431243
refs/heads/revert-22300-revert-22227-a-tall-white-fountain-played: 5f92040224df7dd4e618fdfb367349df64d8acad
12441244
refs/heads/swift-5.1-old-llvm-branch: 9cef8175146f25b72806154b8a0f4a3f52e3e400
1245-
refs/heads/swift-5.1-branch: b2904fbf994864adc5d351721497abee2d75cede
1245+
refs/heads/swift-5.1-branch: 3c27d9de85c499699faba7f315c07807e64ce493
12461246
refs/tags/swift-4.2.2-RELEASE: e429d1f1aaf59e69d38207a96e56265c7f6fccec
12471247
refs/tags/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-02-02-a: 3e5a03d32ff3b1e9af90d6c1198c14f938379a6e
12481248
refs/tags/swift-5.0-DEVELOPMENT-SNAPSHOT-2019-02-03-a: 4591c933063ddcb0d6cd6d0cdd01086b2f9b244d

branches/swift-5.1-branch/include/swift/AST/AccessScopeChecker.h

Lines changed: 21 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -23,79 +23,47 @@
2323

2424
namespace swift {
2525

26-
class BoundGenericType;
27-
class ComponentIdentTypeRepr;
28-
class NominalType;
26+
class AbstractStorageDecl;
27+
class ExtensionDecl;
2928
class SourceFile;
30-
class TypeAliasType;
29+
class ValueDecl;
3130

3231
class AccessScopeChecker {
3332
const SourceFile *File;
3433
bool TreatUsableFromInlineAsPublic;
3534

35+
protected:
36+
ASTContext &Context;
3637
Optional<AccessScope> Scope = AccessScope::getPublic();
3738

3839
AccessScopeChecker(const DeclContext *useDC,
3940
bool treatUsableFromInlineAsPublic);
40-
bool visitDecl(const ValueDecl *VD);
41+
bool visitDecl(ValueDecl *VD);
42+
};
43+
44+
class TypeReprAccessScopeChecker : private ASTWalker, AccessScopeChecker {
45+
TypeReprAccessScopeChecker(const DeclContext *useDC,
46+
bool treatUsableFromInlineAsPublic);
47+
48+
bool walkToTypeReprPre(TypeRepr *TR) override;
49+
bool walkToTypeReprPost(TypeRepr *TR) override;
4150

4251
public:
4352
static Optional<AccessScope>
4453
getAccessScope(TypeRepr *TR, const DeclContext *useDC,
4554
bool treatUsableFromInlineAsPublic = false);
46-
static Optional<AccessScope>
47-
getAccessScope(Type T, const DeclContext *useDC,
48-
bool treatUsableFromInlineAsPublic = false);
4955
};
5056

51-
/// Walks a Type to find all NominalTypes, BoundGenericTypes, and
52-
/// TypeAliasTypes.
53-
class TypeDeclFinder : public TypeWalker {
54-
Action walkToTypePre(Type T) override;
55-
56-
public:
57-
virtual Action visitNominalType(const NominalType *ty) {
58-
return Action::Continue;
59-
}
60-
virtual Action visitBoundGenericType(const BoundGenericType *ty) {
61-
return Action::Continue;
62-
}
63-
virtual Action visitTypeAliasType(const TypeAliasType *ty) {
64-
return Action::Continue;
65-
}
66-
};
57+
class TypeAccessScopeChecker : private TypeWalker, AccessScopeChecker {
58+
TypeAccessScopeChecker(const DeclContext *useDC,
59+
bool treatUsableFromInlineAsPublic);
6760

68-
/// A TypeDeclFinder for use cases where all types should be treated
69-
/// equivalently and where generic arguments can be walked to separately from
70-
/// the generic type.
71-
class SimpleTypeDeclFinder : public TypeDeclFinder {
72-
/// The function to call when a ComponentIdentTypeRepr is seen.
73-
llvm::function_ref<Action(const TypeDecl *)> Callback;
74-
75-
Action visitNominalType(const NominalType *ty) override;
76-
Action visitBoundGenericType(const BoundGenericType *ty) override;
77-
Action visitTypeAliasType(const TypeAliasType *ty) override;
61+
Action walkToTypePre(Type T);
7862

7963
public:
80-
explicit SimpleTypeDeclFinder(
81-
llvm::function_ref<Action(const TypeDecl *)> callback)
82-
: Callback(callback) {}
83-
};
84-
85-
/// Walks a TypeRepr to find all ComponentIdentTypeReprs with bound TypeDecls.
86-
///
87-
/// Subclasses can either override #visitTypeDecl if they only care about
88-
/// types on their own, or #visitComponentIdentTypeRepr if they want to keep
89-
/// the TypeRepr around.
90-
class TypeReprIdentFinder : public ASTWalker {
91-
/// The function to call when a ComponentIdentTypeRepr is seen.
92-
llvm::function_ref<bool(const ComponentIdentTypeRepr *)> Callback;
93-
94-
bool walkToTypeReprPost(TypeRepr *TR) override;
95-
public:
96-
explicit TypeReprIdentFinder(
97-
llvm::function_ref<bool(const ComponentIdentTypeRepr *)> callback)
98-
: Callback(callback) {}
64+
static Optional<AccessScope>
65+
getAccessScope(Type T, const DeclContext *useDC,
66+
bool treatUsableFromInlineAsPublic = false);
9967
};
10068

10169
}

branches/swift-5.1-branch/include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2397,11 +2397,6 @@ NOTE(enum_raw_value_incrementing_from_zero,none,
23972397
NOTE(construct_raw_representable_from_unwrapped_value,none,
23982398
"construct %0 from unwrapped %1 value", (Type, Type))
23992399

2400-
ERROR(decl_from_implementation_only_module,none,
2401-
"cannot use %0 here; %1 has been imported as "
2402-
"'@_implementationOnly'",
2403-
(DeclName, Identifier))
2404-
24052400
// Derived conformances
24062401
ERROR(cannot_synthesize_init_in_extension_of_nonfinal,none,
24072402
"implementation of %0 for non-final class cannot be automatically "
@@ -4109,11 +4104,6 @@ WARNING(resilience_decl_unavailable_warn,
41094104
"should not be referenced from " FRAGILE_FUNC_KIND "3",
41104105
(DescriptiveDeclKind, DeclName, AccessLevel, unsigned, bool))
41114106

4112-
ERROR(inlinable_decl_ref_implementation_only,
4113-
none, "%0 %1 cannot be used in an inlinable "
4114-
"function because its module was imported implementation-only",
4115-
(DescriptiveDeclKind, DeclName))
4116-
41174107
#undef FRAGILE_FUNC_KIND
41184108

41194109
NOTE(resilience_decl_declared_here_public,

branches/swift-5.1-branch/include/swift/AST/Module.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -959,10 +959,6 @@ class SourceFile final : public FileUnit {
959959
/// May be -1, to indicate no association with a buffer.
960960
int BufferID;
961961

962-
/// Does this source file have any implementation-only imports?
963-
/// If not, we can fast-path module checks.
964-
bool HasImplementationOnlyImports = false;
965-
966962
/// The list of protocol conformances that were "used" within this
967963
/// source file.
968964
llvm::SetVector<NormalProtocolConformance *> UsedConformances;
@@ -1051,12 +1047,6 @@ class SourceFile final : public FileUnit {
10511047
hasTestableOrPrivateImport(AccessLevel accessLevel, const ValueDecl *ofDecl,
10521048
ImportQueryKind kind = TestableAndPrivate) const;
10531049

1054-
bool hasImplementationOnlyImports() const {
1055-
return HasImplementationOnlyImports;
1056-
}
1057-
1058-
bool isImportedImplementationOnly(const ModuleDecl *module) const;
1059-
10601050
void clearLookupCache();
10611051

10621052
void cacheVisibleDecls(SmallVectorImpl<ValueDecl *> &&globals) const;

branches/swift-5.1-branch/include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ class SerializedModuleLoaderBase : public ModuleLoader {
5151
std::unique_ptr<llvm::MemoryBuffer> *moduleDocBuffer,
5252
bool &isFramework);
5353

54+
/// Attempts to search the provided directory for a loadable serialized
55+
/// .swiftmodule with the provided `ModuleFilename`. Subclasses must
56+
/// override this method to perform their custom module lookup behavior.
57+
///
58+
/// If such a module could not be loaded, the subclass must return a
59+
/// `std::error_code` indicating the failure. There are two specific error
60+
/// codes that will be treated specially:
61+
/// - `errc::no_such_file_or_directory`: The module loader will stop looking
62+
/// for loadable modules and will diagnose the lookup failure.
63+
/// - `errc::not_supported`: The module loader will stop looking for loadable
64+
/// modules and will defer to the remaining module loaders to look up this
65+
/// module.
5466
virtual std::error_code findModuleFilesInDirectory(
5567
AccessPathElem ModuleID, StringRef DirPath, StringRef ModuleFilename,
5668
StringRef ModuleDocFilename,

branches/swift-5.1-branch/lib/AST/AccessScopeChecker.cpp

Lines changed: 41 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -24,76 +24,68 @@ using namespace swift;
2424
AccessScopeChecker::AccessScopeChecker(const DeclContext *useDC,
2525
bool treatUsableFromInlineAsPublic)
2626
: File(useDC->getParentSourceFile()),
27-
TreatUsableFromInlineAsPublic(treatUsableFromInlineAsPublic) {}
27+
TreatUsableFromInlineAsPublic(treatUsableFromInlineAsPublic),
28+
Context(File->getASTContext()) {}
2829

2930
bool
30-
AccessScopeChecker::visitDecl(const ValueDecl *VD) {
31-
if (isa<GenericTypeParamDecl>(VD))
31+
AccessScopeChecker::visitDecl(ValueDecl *VD) {
32+
if (!VD || isa<GenericTypeParamDecl>(VD))
3233
return true;
3334

3435
auto AS = VD->getFormalAccessScope(File, TreatUsableFromInlineAsPublic);
3536
Scope = Scope->intersectWith(AS);
3637
return Scope.hasValue();
3738
}
3839

39-
bool TypeReprIdentFinder::walkToTypeReprPost(TypeRepr *TR) {
40-
auto CITR = dyn_cast<ComponentIdentTypeRepr>(TR);
41-
if (!CITR || !CITR->getBoundDecl())
42-
return true;
43-
return Callback(CITR);
40+
TypeReprAccessScopeChecker::TypeReprAccessScopeChecker(const DeclContext *useDC,
41+
bool treatUsableFromInlineAsPublic)
42+
: AccessScopeChecker(useDC, treatUsableFromInlineAsPublic) {
4443
}
4544

46-
Optional<AccessScope>
47-
AccessScopeChecker::getAccessScope(TypeRepr *TR, const DeclContext *useDC,
48-
bool treatUsableFromInlineAsPublic) {
49-
AccessScopeChecker checker(useDC, treatUsableFromInlineAsPublic);
50-
TR->walk(TypeReprIdentFinder([&](const ComponentIdentTypeRepr *typeRepr) {
51-
return checker.visitDecl(typeRepr->getBoundDecl());
52-
}));
53-
return checker.Scope;
45+
bool
46+
TypeReprAccessScopeChecker::walkToTypeReprPre(TypeRepr *TR) {
47+
if (auto CITR = dyn_cast<ComponentIdentTypeRepr>(TR))
48+
return visitDecl(CITR->getBoundDecl());
49+
return true;
5450
}
5551

56-
TypeWalker::Action TypeDeclFinder::walkToTypePre(Type T) {
57-
if (auto *TAT = dyn_cast<TypeAliasType>(T.getPointer()))
58-
return visitTypeAliasType(TAT);
59-
60-
// FIXME: We're looking through sugar here so that we visit, e.g.,
61-
// Swift.Array when we see `[Int]`. But that means we do redundant work when
62-
// we see sugar that's purely structural, like `(Int)`. Fortunately, paren
63-
// types are the only such purely structural sugar at the time this comment
64-
// was written, and they're not so common in the first place.
65-
if (auto *BGT = T->getAs<BoundGenericType>())
66-
return visitBoundGenericType(BGT);
67-
if (auto *NT = T->getAs<NominalType>())
68-
return visitNominalType(NT);
69-
70-
return Action::Continue;
52+
bool
53+
TypeReprAccessScopeChecker::walkToTypeReprPost(TypeRepr *TR) {
54+
return Scope.hasValue();
7155
}
7256

73-
TypeWalker::Action
74-
SimpleTypeDeclFinder::visitNominalType(const NominalType *ty) {
75-
return Callback(ty->getDecl());
57+
Optional<AccessScope>
58+
TypeReprAccessScopeChecker::getAccessScope(TypeRepr *TR, const DeclContext *useDC,
59+
bool treatUsableFromInlineAsPublic) {
60+
TypeReprAccessScopeChecker checker(useDC, treatUsableFromInlineAsPublic);
61+
TR->walk(checker);
62+
return checker.Scope;
7663
}
7764

78-
TypeWalker::Action
79-
SimpleTypeDeclFinder::visitBoundGenericType(const BoundGenericType *ty) {
80-
return Callback(ty->getDecl());
81-
}
65+
TypeAccessScopeChecker::TypeAccessScopeChecker(const DeclContext *useDC,
66+
bool treatUsableFromInlineAsPublic)
67+
: AccessScopeChecker(useDC, treatUsableFromInlineAsPublic) {}
8268

8369
TypeWalker::Action
84-
SimpleTypeDeclFinder::visitTypeAliasType(const TypeAliasType *ty) {
85-
return Callback(ty->getDecl());
86-
}
70+
TypeAccessScopeChecker::walkToTypePre(Type T) {
71+
ValueDecl *VD;
72+
if (auto *BNAD = dyn_cast<TypeAliasType>(T.getPointer()))
73+
VD = BNAD->getDecl();
74+
else if (auto *NTD = T->getAnyNominal())
75+
VD = NTD;
76+
else
77+
VD = nullptr;
78+
79+
if (!visitDecl(VD))
80+
return Action::Stop;
8781

82+
return Action::Continue;
83+
}
8884

8985
Optional<AccessScope>
90-
AccessScopeChecker::getAccessScope(Type T, const DeclContext *useDC,
91-
bool treatUsableFromInlineAsPublic) {
92-
AccessScopeChecker checker(useDC, treatUsableFromInlineAsPublic);
93-
T.walk(SimpleTypeDeclFinder([&](const ValueDecl *VD) {
94-
if (checker.visitDecl(VD))
95-
return TypeWalker::Action::Continue;
96-
return TypeWalker::Action::Stop;
97-
}));
86+
TypeAccessScopeChecker::getAccessScope(Type T, const DeclContext *useDC,
87+
bool treatUsableFromInlineAsPublic) {
88+
TypeAccessScopeChecker checker(useDC, treatUsableFromInlineAsPublic);
89+
T.walk(checker);
9890
return checker.Scope;
9991
}

branches/swift-5.1-branch/lib/AST/Module.cpp

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,14 +1421,6 @@ void SourceFile::addImports(ArrayRef<ImportedModuleDesc> IM) {
14211421
assert(iter == newBuf.end());
14221422

14231423
Imports = newBuf;
1424-
1425-
// Update the HasImplementationOnlyImports flag.
1426-
if (!HasImplementationOnlyImports) {
1427-
for (auto &desc : IM) {
1428-
if (desc.importOptions.contains(ImportFlags::ImplementationOnly))
1429-
HasImplementationOnlyImports = true;
1430-
}
1431-
}
14321424
}
14331425

14341426
bool SourceFile::hasTestableOrPrivateImport(
@@ -1493,43 +1485,6 @@ bool SourceFile::hasTestableOrPrivateImport(
14931485
});
14941486
}
14951487

1496-
bool SourceFile::isImportedImplementationOnly(const ModuleDecl *module) const {
1497-
// Implementation-only imports are (currently) always source-file-specific,
1498-
// so if we don't have any, we know the search is complete.
1499-
if (!hasImplementationOnlyImports())
1500-
return false;
1501-
1502-
auto isImportedBy = [](const ModuleDecl *dest, const ModuleDecl *src) {
1503-
// Fast path.
1504-
if (dest == src) return true;
1505-
1506-
// Walk the transitive imports, respecting visibility.
1507-
// This return true if the search *didn't* short-circuit, and it short
1508-
// circuits if we found `dest`, so we need to invert the sense before
1509-
// returning.
1510-
return !const_cast<ModuleDecl*>(src)
1511-
->forAllVisibleModules({}, [dest](ModuleDecl::ImportedModule im) {
1512-
// Continue searching as long as we haven't found `dest` yet.
1513-
return im.second != dest;
1514-
});
1515-
};
1516-
1517-
// Look at the imports of this source file.
1518-
for (auto &desc : Imports) {
1519-
// Ignore implementation-only imports.
1520-
if (desc.importOptions.contains(ImportFlags::ImplementationOnly))
1521-
continue;
1522-
1523-
// If the module is imported this way, it's not imported
1524-
// implementation-only.
1525-
if (isImportedBy(module, desc.module.second))
1526-
return false;
1527-
}
1528-
1529-
// Now check this file's enclosing module in case there are re-exports.
1530-
return !isImportedBy(module, getParentModule());
1531-
}
1532-
15331488
void SourceFile::clearLookupCache() {
15341489
if (!Cache)
15351490
return;

0 commit comments

Comments
 (0)