Skip to content

Commit 74f1133

Browse files
committed
[Serialization] Filter out XREFs into constrained extensions that should not find declarations there.
The presence of a generic signature in a XREF means that we should only find the result in a (further-constrained) extension with that generic signature. The absence of a generic signature in a XREF means that we should not find the result in a constrained extension. We implemented the former but not the latter, which would lead to deserialization failures if one had both constrained and unconstrained extensions with the same property in them. Methods/initializers weren’t a problem because the generic signature is (redundantly) encoded in their interface type. (cherry picked from commit 5775732)
1 parent 1730bff commit 74f1133

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,6 +1023,13 @@ static void filterValues(Type expectedTy, Module *expectedModule,
10231023
->getCanonicalSignature() != expectedGenericSig)
10241024
return true;
10251025

1026+
// If we don't expect a specific generic signature, ignore anything from a
1027+
// constrained extension.
1028+
if (!expectedGenericSig &&
1029+
isa<ExtensionDecl>(value->getDeclContext()) &&
1030+
cast<ExtensionDecl>(value->getDeclContext())->isConstrainedExtension())
1031+
return true;
1032+
10261033
// If we're looking at members of a protocol or protocol extension,
10271034
// filter by whether we expect to find something in a protocol extension or
10281035
// not. This lets us distinguish between a protocol member and a protocol
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
11
public extension Array {
22
func wobble() -> Element? { return nil }
33
}
4+
5+
public protocol P {
6+
var property: Int { get }
7+
}
8+
9+
public protocol Q { }
10+
11+
extension P {
12+
public var property: Int { return 0 }
13+
}
14+
15+
extension P where Self: Q {
16+
public var property: Int { return 0 }
17+
}
18+
19+
public struct ConformsToP: P { }
20+
21+
22+
23+

test/Serialization/generic_extension.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ import generic_extension_1
1111
["a", "b", "c"].wobble()
1212

1313
// CHECK: sil @_TFE19generic_extension_1Sa6wobble{{.*}} : $@convention(method) <τ_0_0> (@guaranteed Array<τ_0_0>) -> @out Optional<τ_0_0>
14+
15+
func useP<T: P>(_ t: T) -> Int { return t.property }
16+
17+
func testUseP(c: ConformsToP) {
18+
_ = useP(c)
19+
}

0 commit comments

Comments
 (0)