Skip to content

Commit c1bc576

Browse files
committedMar 20, 2018
Revert "[Associated type inference] Infer escaping function types, not noescape ones."
This reverts commit 60e8de7.
1 parent 2c0d406 commit c1bc576

File tree

2 files changed

+1
-61
lines changed

2 files changed

+1
-61
lines changed
 

‎lib/Sema/TypeCheckProtocolInference.cpp

+1-32
Original file line numberDiff line numberDiff line change
@@ -607,33 +607,6 @@ AssociatedTypeInference::inferTypeWitnessesViaAssociatedType(
607607
return result;
608608
}
609609

610-
/// Perform any necessary adjustments to the inferred associated type to
611-
/// make it suitable for later use.
612-
static Type adjustInferredAssociatedType(Type type) {
613-
// If we have an optional type, adjust its wrapped type.
614-
if (auto optionalObjectType = type->getOptionalObjectType()) {
615-
auto newOptionalObjectType =
616-
adjustInferredAssociatedType(optionalObjectType);
617-
if (newOptionalObjectType.getPointer() == optionalObjectType.getPointer())
618-
return type;
619-
620-
return OptionalType::get(newOptionalObjectType);
621-
}
622-
623-
// If we have a noescape function type, make it escaping.
624-
if (auto funcType = type->getAs<FunctionType>()) {
625-
if (funcType->isNoEscape()) {
626-
return FunctionType::get(funcType->getParams(), funcType->getResult(),
627-
funcType->getExtInfo().withNoEscape(false));
628-
}
629-
}
630-
631-
// We can only infer materializable types.
632-
if (!type->isMaterializable()) return nullptr;
633-
634-
return type;
635-
}
636-
637610
/// Attempt to resolve a type witness via a specific value witness.
638611
InferredAssociatedTypesByWitness
639612
AssociatedTypeInference::inferTypeWitnessesViaValueWitness(ValueDecl *req,
@@ -689,14 +662,10 @@ AssociatedTypeInference::inferTypeWitnessesViaValueWitness(ValueDecl *req,
689662
if (secondType->hasError())
690663
return true;
691664

692-
Type inferredType = adjustInferredAssociatedType(secondType);
693-
if (!inferredType)
694-
return true;
695-
696665
auto proto = Conformance->getProtocol();
697666
if (auto assocType = getReferencedAssocTypeOfProtocol(firstDepMember,
698667
proto)) {
699-
Inferred.Inferred.push_back({assocType, inferredType});
668+
Inferred.Inferred.push_back({assocType, secondType});
700669
}
701670

702671
// Always allow mismatches here.

‎test/decl/protocol/conforms/associated_type.swift

-29
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,3 @@ class Foo: FooType {
3232
func foo(action: (Bar) -> Void) {
3333
}
3434
}
35-
36-
// rdar://problem/35297911: noescape function types
37-
protocol P1 {
38-
associatedtype A
39-
40-
func f(_: A)
41-
// expected-note@-1 {{protocol requires function 'f' with type '(X1c.A) -> ()' (aka '((Int) -> Int) -> ()'); do you want to add a stub?}}
42-
// expected-note@-2 {{protocol requires function 'f' with type '((Int) -> Int) -> ()'; do you want to add a stub?}}
43-
}
44-
45-
struct X1a : P1 {
46-
func f(_: @escaping (Int) -> Int) { }
47-
}
48-
49-
struct X1b : P1 {
50-
typealias A = (Int) -> Int
51-
52-
func f(_: @escaping (Int) -> Int) { }
53-
}
54-
55-
struct X1c : P1 { // expected-error{{type 'X1c' does not conform to protocol 'P1'}}
56-
typealias A = (Int) -> Int
57-
58-
func f(_: (Int) -> Int) { } // expected-note{{candidate has non-matching type '((Int) -> Int) -> ()'}}
59-
}
60-
61-
struct X1d : P1 { // expected-error{{type 'X1d' does not conform to protocol 'P1'}}
62-
func f(_: (Int) -> Int) { } // expected-note{{candidate has non-matching type '((Int) -> Int) -> ()' [with A = (Int) -> Int]}}
63-
}

0 commit comments

Comments
 (0)
Please sign in to comment.