Skip to content

Commit 822b7f6

Browse files
committed
Re-apply "AST: Fix excessive deserialization in GenericSignatureBuilder"
This got reverted because it made our non-deterministic deserialization crasher come up more often. Re-applying this patch to test the theory that @jrose-apple's fix addressed the issue.
1 parent df8efc2 commit 822b7f6

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
@@ -1142,9 +1142,17 @@ auto GenericSignatureBuilder::PotentialArchetype::getNestedType(
11421142
SmallVector<std::pair<ProtocolDecl *, const RequirementSource *>, 4>
11431143
conformsTo(rep->ConformsTo.begin(), rep->ConformsTo.end());
11441144
for (auto &conforms : conformsTo) {
1145-
auto proto = conforms.first;
1146-
1147-
for (auto member : proto->lookupDirect(nestedName)) {
1145+
// Make sure we don't trigger deserialization of extensions,
1146+
// since they can refer back to a protocol we're currently
1147+
// type checking.
1148+
//
1149+
// Note that typealiases in extensions won't matter here,
1150+
// because a typealias is never going to be a representative
1151+
// PA.
1152+
auto *proto = conforms.first;
1153+
auto members = proto->lookupDirect(nestedName,
1154+
/*ignoreNewExtensions=*/true);
1155+
for (auto member : members) {
11481156
PotentialArchetype *pa;
11491157
std::function<void(Type, Type)> diagnoseMismatch;
11501158

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)