Skip to content

Commit 46f4358

Browse files
authored
Merge pull request #7530 from DougGregor/generic-signature-deserialization
2 parents e9ed734 + 464dac7 commit 46f4358

File tree

8 files changed

+43
-11
lines changed

8 files changed

+43
-11
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2854,8 +2854,8 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
28542854
///
28552855
/// \param ignoreNewExtensions Whether to avoid loading any new extension.
28562856
/// Used by the module loader to break recursion.
2857-
ArrayRef<ValueDecl *> lookupDirect(DeclName name,
2858-
bool ignoreNewExtensions = false);
2857+
TinyPtrVector<ValueDecl *> lookupDirect(DeclName name,
2858+
bool ignoreNewExtensions = false);
28592859

28602860
/// Collect the set of protocols to which this type should implicitly
28612861
/// conform, such as AnyObject (for classes).

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,16 @@ auto GenericSignatureBuilder::PotentialArchetype::getNestedType(
554554
SmallVector<std::pair<ProtocolDecl *, RequirementSource>, 4>
555555
conformsTo(rep->ConformsTo.begin(), rep->ConformsTo.end());
556556
for (auto &conforms : conformsTo) {
557-
for (auto member : conforms.first->lookupDirect(nestedName)) {
557+
// Make sure we don't trigger deserialization of extensions,
558+
// since they can refer back to a protocol we're currently
559+
// type checking.
560+
//
561+
// Note that typealiases in extensions won't matter here,
562+
// because a typealias is never going to be a representative
563+
// PA.
564+
auto members = conforms.first->lookupDirect(nestedName,
565+
/*ignoreNewExtensions=*/true);
566+
for (auto member : members) {
558567
PotentialArchetype *pa;
559568

560569
if (auto assocType = dyn_cast<AssociatedTypeDecl>(member)) {

lib/AST/NameLookup.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,8 +1183,9 @@ void NominalTypeDecl::makeMemberVisible(ValueDecl *member) {
11831183
LookupTable.getPointer()->addMember(member);
11841184
}
11851185

1186-
ArrayRef<ValueDecl *> NominalTypeDecl::lookupDirect(DeclName name,
1187-
bool ignoreNewExtensions) {
1186+
TinyPtrVector<ValueDecl *> NominalTypeDecl::lookupDirect(
1187+
DeclName name,
1188+
bool ignoreNewExtensions) {
11881189
// Make sure we have the complete list of members (in this nominal and in all
11891190
// extensions).
11901191
if (!ignoreNewExtensions) {
@@ -1202,7 +1203,7 @@ ArrayRef<ValueDecl *> NominalTypeDecl::lookupDirect(DeclName name,
12021203
return { };
12031204

12041205
// We found something; return it.
1205-
return { known->second.begin(), known->second.size() };
1206+
return known->second;
12061207
}
12071208

12081209
void ClassDecl::createObjCMethodLookup() {

lib/Sema/TypeCheckDecl.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -867,21 +867,20 @@ static void checkRedeclaration(TypeChecker &tc, ValueDecl *current) {
867867
isCascading = (current->getFormalAccess() > Accessibility::FilePrivate);
868868

869869
// Find other potential definitions.
870-
SmallVector<ValueDecl *, 4> otherDefinitionsVec;
871-
ArrayRef<ValueDecl *> otherDefinitions;
870+
SmallVector<ValueDecl *, 4> otherDefinitions;
872871
if (currentDC->isTypeContext()) {
873872
// Look within a type context.
874873
if (auto nominal = currentDC->getAsNominalTypeOrNominalTypeExtensionContext()) {
875-
otherDefinitions = nominal->lookupDirect(current->getBaseName());
874+
auto found = nominal->lookupDirect(current->getBaseName());
875+
otherDefinitions.append(found.begin(), found.end());
876876
if (tracker)
877877
tracker->addUsedMember({nominal, current->getName()}, isCascading);
878878
}
879879
} else {
880880
// Look within a module context.
881881
currentFile->getParentModule()->lookupValue({ }, current->getBaseName(),
882882
NLKind::QualifiedLookup,
883-
otherDefinitionsVec);
884-
otherDefinitions = otherDefinitionsVec;
883+
otherDefinitions);
885884
if (tracker)
886885
tracker->addTopLevelName(current->getName(), isCascading);
887886
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public protocol A {
2+
associatedtype T : B
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
public protocol BB {
2+
associatedtype T
3+
}
4+
5+
public protocol B {
6+
associatedtype T : BB
7+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extension B {
2+
public init?<T : A>(_: T) where T.T == Self {
3+
return nil
4+
}
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: rm -rf %t && mkdir -p %t
2+
3+
// RUN: %target-swift-frontend -emit-module -module-name Multi -o %t/a.swiftmodule -primary-file %S/Inputs/circular-associated-type/a.swift %S/Inputs/circular-associated-type/b.swift %S/Inputs/circular-associated-type/c.swift
4+
// RUN: %target-swift-frontend -emit-module -module-name Multi -o %t/b.swiftmodule -primary-file %S/Inputs/circular-associated-type/b.swift %S/Inputs/circular-associated-type/a.swift %S/Inputs/circular-associated-type/c.swift
5+
// RUN: %target-swift-frontend -emit-module -module-name Multi -o %t/c.swiftmodule -primary-file %S/Inputs/circular-associated-type/c.swift %S/Inputs/circular-associated-type/a.swift %S/Inputs/circular-associated-type/b.swift
6+
7+
// RUN: %target-swift-frontend -parse-as-library -emit-module -module-name Multi %t/a.swiftmodule %t/b.swiftmodule %t/c.swiftmodule -o %t
8+

0 commit comments

Comments
 (0)