Skip to content

Commit b95635c

Browse files
committed
[SILGen] NFC: Add test-cases for rdar://problem/37790062
Port multiple test-cases from `test/Constraints/closures.swift` to SILGen to verify that closures are inferred as having `Void` result type, and there is no function conversion thunk emitted to convert from `() -> T` to `() -> Void` for literal closures.
1 parent 94dbbd7 commit b95635c

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) {
381381

382382
if (auto *locator = typeVar->getImpl().getLocator()) {
383383
auto path = locator->getPath();
384-
auto voidType = TupleType::getEmpty(getASTContext());
384+
auto voidType = getASTContext().TheEmptyTupleType;
385385

386386
// If this is a type variable representing closure result,
387387
// which is on the right-side of some relational constraint
@@ -391,7 +391,7 @@ ConstraintSystem::getPotentialBindings(TypeVariableType *typeVar) {
391391
if (!path.empty() &&
392392
path.back().getKind() == ConstraintLocator::ClosureResult &&
393393
binding->Kind == AllowedBindingKind::Supertypes &&
394-
exactTypes.insert(voidType->getCanonicalType()).second) {
394+
exactTypes.insert(voidType).second) {
395395
result.addPotentialBinding(
396396
{voidType, binding->Kind, constraint->getKind()},
397397
/*allowJoinMeet=*/false);

test/SILGen/closures.swift

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,3 +791,67 @@ struct r29810997 {
791791

792792
// DI will turn this into a direct capture of the specific stored property.
793793
// CHECK-LABEL: sil hidden @$S8closures16r29810997_helperyS3iXEF : $@convention(thin) (@noescape @callee_guaranteed (Int) -> Int) -> Int
794+
795+
// rdar://problem/37790062
796+
797+
protocol P_37790062 {
798+
associatedtype T
799+
var elt: T { get }
800+
}
801+
802+
func rdar37790062() {
803+
struct S<T> {
804+
init(_ a: () -> T, _ b: () -> T) {}
805+
}
806+
807+
class C1 : P_37790062 {
808+
typealias T = Int
809+
var elt: T { return 42 }
810+
}
811+
812+
class C2 : P_37790062 {
813+
typealias T = (String, Int, Void)
814+
var elt: T { return ("question", 42, ()) }
815+
}
816+
817+
func foo() -> Int { return 42 }
818+
func bar() -> Void {}
819+
func baz() -> (String, Int) { return ("question", 42) }
820+
func bzz<T>(_ a: T) -> T { return a }
821+
func faz<T: P_37790062>(_ a: T) -> T.T { return a.elt }
822+
823+
// CHECK: function_ref @$S8closures12rdar37790062yyFyyXEfU_
824+
// CHECK: function_ref @$S8closures12rdar37790062yyFyyXEfU0_
825+
// CHECK: function_ref @$S8closures12rdar37790062yyF1SL_VyADyxGxyXE_xyXEtcfC
826+
_ = S({ foo() }, { bar() })
827+
828+
// CHECK: function_ref @$S8closures12rdar37790062yyFyyXEfU1_
829+
// CHECK: function_ref @$S8closures12rdar37790062yyFyyXEfU2_
830+
// CHECK: function_ref @$S8closures12rdar37790062yyF1SL_VyADyxGxyXE_xyXEtcfC
831+
_ = S({ baz() }, { bar() })
832+
833+
// CHECK: function_ref @$S8closures12rdar37790062yyFyyXEfU3_
834+
// CHECK: function_ref @$S8closures12rdar37790062yyFyyXEfU4_
835+
// CHECK: function_ref @$S8closures12rdar37790062yyF1SL_VyADyxGxyXE_xyXEtcfC
836+
_ = S({ bzz(("question", 42)) }, { bar() })
837+
838+
// CHECK: function_ref @$S8closures12rdar37790062yyFyyXEfU5_
839+
// CHECK: function_ref @$S8closures12rdar37790062yyFyyXEfU6_
840+
// CHECK: function_ref @$S8closures12rdar37790062yyF1SL_VyADyxGxyXE_xyXEtcfC
841+
_ = S({ bzz(String.self) }, { bar() })
842+
843+
// CHECK: function_ref @$S8closures12rdar37790062yyFyyXEfU7_
844+
// CHECK: function_ref @$S8closures12rdar37790062yyFyyXEfU8_
845+
// CHECK: function_ref @$S8closures12rdar37790062yyF1SL_VyADyxGxyXE_xyXEtcfC
846+
_ = S({ bzz(((), (()))) }, { bar() })
847+
848+
// CHECK: function_ref @$S8closures12rdar37790062yyFyyXEfU9_
849+
// CHECK: function_ref @$S8closures12rdar37790062yyFyyXEfU10_
850+
// CHECK: function_ref @$S8closures12rdar37790062yyF1SL_VyADyxGxyXE_xyXEtcfC
851+
_ = S({ bzz(C1()) }, { bar() })
852+
853+
// CHECK: function_ref @$S8closures12rdar37790062yyFyyXEfU11_
854+
// CHECK: function_ref @$S8closures12rdar37790062yyFyyXEfU12_
855+
// CHECK: function_ref @$S8closures12rdar37790062yyF1SL_VyADyxGxyXE_xyXEtcfC
856+
_ = S({ faz(C2()) }, { bar() })
857+
}

0 commit comments

Comments
 (0)