Skip to content

Commit 5b48acf

Browse files
authored
Merge pull request #7857 from slavapestov/fix-circular-deserialization-with-extensions
Re-apply "AST: Fix excessive deserialization in GenericSignatureBuilder"
2 parents b432296 + 822b7f6 commit 5b48acf

File tree

5 files changed

+34
-3
lines changed

5 files changed

+34
-3
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,9 +1231,17 @@ auto GenericSignatureBuilder::PotentialArchetype::getNestedType(
12311231
SmallVector<std::pair<ProtocolDecl *, const RequirementSource *>, 4>
12321232
conformsTo(rep->ConformsTo.begin(), rep->ConformsTo.end());
12331233
for (auto &conforms : conformsTo) {
1234-
auto proto = conforms.first;
1235-
1236-
for (auto member : proto->lookupDirect(nestedName)) {
1234+
// Make sure we don't trigger deserialization of extensions,
1235+
// since they can refer back to a protocol we're currently
1236+
// type checking.
1237+
//
1238+
// Note that typealiases in extensions won't matter here,
1239+
// because a typealias is never going to be a representative
1240+
// PA.
1241+
auto *proto = conforms.first;
1242+
auto members = proto->lookupDirect(nestedName,
1243+
/*ignoreNewExtensions=*/true);
1244+
for (auto member : members) {
12371245
PotentialArchetype *pa;
12381246
std::function<void(Type, Type)> diagnoseMismatch;
12391247

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)