Skip to content

Commit 597c955

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.
1 parent e471e40 commit 597c955

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
@@ -577,18 +577,16 @@ NormalProtocolConformance::getTypeWitnessAndDecl(AssociatedTypeDecl *assocType,
577577
if (known != TypeWitnesses.end())
578578
return known->second;
579579

580-
// If this conformance is in a state where it is inferring type witnesses,
581-
// check tentative witnesses.
582-
if (getState() == ProtocolConformanceState::CheckingTypeWitnesses) {
583-
// If there is a tentative-type-witness function, use it.
584-
if (options.getTentativeTypeWitness) {
585-
if (Type witnessType =
586-
Type(options.getTentativeTypeWitness(this, assocType)))
587-
return { witnessType, nullptr };
588-
}
580+
// If there is a tentative-type-witness function, use it.
581+
if (options.getTentativeTypeWitness) {
582+
if (Type witnessType =
583+
Type(options.getTentativeTypeWitness(this, assocType)))
584+
return { witnessType, nullptr };
585+
}
589586

590-
// Otherwise, we fail; this is the only case in which we can return a
591-
// null type.
587+
// If this conformance is in a state where it is inferring type witnesses but
588+
// we didn't find anything, fail.
589+
if (getState() == ProtocolConformanceState::CheckingTypeWitnesses) {
592590
return { Type(), nullptr };
593591
}
594592

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)