File tree 4 files changed +63
-1
lines changed
4 files changed +63
-1
lines changed Original file line number Diff line number Diff line change @@ -444,6 +444,13 @@ class SILType {
444
444
return isObject () && isClassOrClassMetatype (getASTType ());
445
445
}
446
446
447
+ bool isFunctionTypeWithContext () const {
448
+ if (auto *fTy = getASTType ()->getAs <SILFunctionType>()) {
449
+ return fTy ->getExtInfo ().hasContext ();
450
+ }
451
+ return false ;
452
+ }
453
+
447
454
// / True if the type involves any archetypes.
448
455
bool hasArchetype () const { return getASTType ()->hasArchetype (); }
449
456
Original file line number Diff line number Diff line change @@ -121,7 +121,10 @@ bool SILType::isOrContainsRawPointer(const SILFunction &F) const {
121
121
bool SILType::isNonTrivialOrContainsRawPointer (const SILFunction &F) const {
122
122
auto contextType = hasTypeParameter () ? F.mapTypeIntoContext (*this ) : *this ;
123
123
const TypeLowering &tyLowering = F.getTypeLowering (contextType);
124
- return !tyLowering.isTrivial () || tyLowering.isOrContainsRawPointer ();
124
+ bool result = !tyLowering.isTrivial () || tyLowering.isOrContainsRawPointer ();
125
+ assert ((result || !isFunctionTypeWithContext ()) &&
126
+ " a function type with context must either be non trivial or marked as containing a pointer" );
127
+ return result;
125
128
}
126
129
127
130
bool SILType::isEmpty (const SILFunction &F) const {
Original file line number Diff line number Diff line change @@ -606,3 +606,30 @@ bb0:
606
606
%11 = tuple ()
607
607
return %11 : $()
608
608
}
609
+
610
+ sil @call_closure : $@convention(method) (@noescape @callee_guaranteed () -> ()) -> ()
611
+ sil @closure : $@convention(thin) (@inout_aliasable Int) -> ()
612
+
613
+ // CHECK-LABEL: Address escape information for test_closure_capturing_address:
614
+ // CHECK: value: %0 = alloc_stack $Int
615
+ // CHECK-NEXT: ==> %7 = apply %6(%4) : $@convention(method) (@noescape @callee_guaranteed () -> ()) -> ()
616
+ // CHECK: End function test_closure_capturing_address
617
+ sil @test_closure_capturing_address : $@convention(thin) () -> Int {
618
+ bb0:
619
+ %0 = alloc_stack $Int
620
+ %1 = integer_literal $Builtin.Int64, 0
621
+ %2 = struct $Int (%1 : $Builtin.Int64)
622
+
623
+ %3 = function_ref @closure : $@convention(thin) (@inout_aliasable Int) -> ()
624
+ %4 = partial_apply [callee_guaranteed] [on_stack] %3(%0) : $@convention(thin) (@inout_aliasable Int) -> ()
625
+ store %2 to %0 : $*Int
626
+
627
+ %6 = function_ref @call_closure : $@convention(method) (@noescape @callee_guaranteed () -> ()) -> ()
628
+ %7 = apply %6(%4) : $@convention(method) (@noescape @callee_guaranteed () -> ()) -> ()
629
+ dealloc_stack %4 : $@noescape @callee_guaranteed () -> ()
630
+ fix_lifetime %0 : $*Int
631
+ %9 = load %0 : $*Int
632
+ dealloc_stack %0 : $*Int
633
+ return %9 : $Int
634
+ }
635
+
Original file line number Diff line number Diff line change @@ -1268,3 +1268,28 @@ bb1:
1268
1268
return %r : $()
1269
1269
}
1270
1270
1271
+ sil @call_closure : $@convention(method) (@noescape @callee_guaranteed () -> ()) -> ()
1272
+ sil @closure : $@convention(thin) (@inout_aliasable Int) -> ()
1273
+
1274
+ // CHECK-LABEL: sil @test_closure_capturing_address :
1275
+ // CHECK: [[L:%[0-9]+]] = load
1276
+ // CHECK: return [[L]]
1277
+ // CHECK-LABEL: } // end sil function 'test_closure_capturing_address'
1278
+ sil @test_closure_capturing_address : $@convention(thin) () -> Int {
1279
+ bb0:
1280
+ %0 = alloc_stack $Int
1281
+ %1 = integer_literal $Builtin.Int64, 0
1282
+ %2 = struct $Int (%1 : $Builtin.Int64)
1283
+
1284
+ %3 = function_ref @closure : $@convention(thin) (@inout_aliasable Int) -> ()
1285
+ %4 = partial_apply [callee_guaranteed] [on_stack] %3(%0) : $@convention(thin) (@inout_aliasable Int) -> ()
1286
+ store %2 to %0 : $*Int
1287
+
1288
+ %6 = function_ref @call_closure : $@convention(method) (@noescape @callee_guaranteed () -> ()) -> ()
1289
+ %7 = apply %6(%4) : $@convention(method) (@noescape @callee_guaranteed () -> ()) -> ()
1290
+ dealloc_stack %4 : $@noescape @callee_guaranteed () -> ()
1291
+ %9 = load %0 : $*Int
1292
+ dealloc_stack %0 : $*Int
1293
+ return %9 : $Int
1294
+ }
1295
+
You can’t perform that action at this time.
0 commit comments