Skip to content

Re-apply "AST: Fix excessive deserialization in GenericSignatureBuilder" #7857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1142,9 +1142,17 @@ auto GenericSignatureBuilder::PotentialArchetype::getNestedType(
SmallVector<std::pair<ProtocolDecl *, const RequirementSource *>, 4>
conformsTo(rep->ConformsTo.begin(), rep->ConformsTo.end());
for (auto &conforms : conformsTo) {
auto proto = conforms.first;

for (auto member : proto->lookupDirect(nestedName)) {
// Make sure we don't trigger deserialization of extensions,
// since they can refer back to a protocol we're currently
// type checking.
//
// Note that typealiases in extensions won't matter here,
// because a typealias is never going to be a representative
// PA.
auto *proto = conforms.first;
auto members = proto->lookupDirect(nestedName,
/*ignoreNewExtensions=*/true);
for (auto member : members) {
PotentialArchetype *pa;
std::function<void(Type, Type)> diagnoseMismatch;

Expand Down
3 changes: 3 additions & 0 deletions test/Serialization/Inputs/circular-associated-type/a.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public protocol A {
associatedtype T : B
}
7 changes: 7 additions & 0 deletions test/Serialization/Inputs/circular-associated-type/b.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public protocol BB {
associatedtype T
}

public protocol B {
associatedtype T : BB
}
5 changes: 5 additions & 0 deletions test/Serialization/Inputs/circular-associated-type/c.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extension B {
public init?<T : A>(_: T) where T.T == Self {
return nil
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: rm -rf %t && mkdir -p %t

// 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
// 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
// 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

// RUN: %target-swift-frontend -parse-as-library -emit-module -module-name Multi %t/a.swiftmodule %t/b.swiftmodule %t/c.swiftmodule -o %t