Skip to content

Commit 9d0d176

Browse files
committed
[Associated type inference] Find tentative type witnesses across protocol hierarchy.
As a minor step toward more global associated type inference, allow tentative type witnesses to be found across a protocol hierarchy, eliminating some recursion through associated type inference. Fixes a recent regression in validation-test/stdlib/CollectionTypes.swift, as well as rdar://problem/36453271. (cherry picked from commit 597c955)
1 parent f136b88 commit 9d0d176

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

lib/AST/ProtocolConformance.cpp

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -557,18 +557,16 @@ NormalProtocolConformance::getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
557557
if (known != TypeWitnesses.end())
558558
return known->second;
559559

560-
// If this conformance is in a state where it is inferring type witnesses,
561-
// check tentative witnesses.
562-
if (getState() == ProtocolConformanceState::CheckingTypeWitnesses) {
563-
// If there is a tentative-type-witness function, use it.
564-
if (options.getTentativeTypeWitness) {
565-
if (Type witnessType =
566-
Type(options.getTentativeTypeWitness(this, assocType)))
567-
return { witnessType, nullptr };
568-
}
560+
// If there is a tentative-type-witness function, use it.
561+
if (options.getTentativeTypeWitness) {
562+
if (Type witnessType =
563+
Type(options.getTentativeTypeWitness(this, assocType)))
564+
return { witnessType, nullptr };
565+
}
569566

570-
// Otherwise, we fail; this is the only case in which we can return a
571-
// null type.
567+
// If this conformance is in a state where it is inferring type witnesses but
568+
// we didn't find anything, fail.
569+
if (getState() == ProtocolConformanceState::CheckingTypeWitnesses) {
572570
return { Type(), nullptr };
573571
}
574572

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// RUN: %target-swift-frontend %s -emit-ir -o 0
2+
3+
extension Slice where Base == UnsafeBufferPointer<UInt16> {
4+
var rebased: UnsafeBufferPointer<UInt16> {
5+
return UnsafeBufferPointer(rebasing: self)
6+
}
7+
}
8+
9+
extension Slice where Base == UnsafeMutableBufferPointer<UInt16> {
10+
var rebased: UnsafeMutableBufferPointer<UInt16> {
11+
return UnsafeMutableBufferPointer(rebasing: self)
12+
}
13+
}

0 commit comments

Comments
 (0)