Skip to content

Commit b516b04

Browse files
committed
[SIL] end_apply insts maySynchronize.
Just as a full apply may have side-effects including synchronization, so may an end_apply, which is lowered to the apply of a continuation.
1 parent 53c728e commit b516b04

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/SIL/IR/SILInstruction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ bool SILInstruction::mayTrap() const {
13821382
bool SILInstruction::maySynchronize() const {
13831383
// TODO: We need side-effect analysis and library annotation for this to be
13841384
// a reasonable API. For now, this is just a placeholder.
1385-
return isa<FullApplySite>(this);
1385+
return isa<FullApplySite>(this) || isa<EndApplyInst>(this);
13861386
}
13871387

13881388
bool SILInstruction::isMetaInstruction() const {

test/SILOptimizer/shrink_borrow_scope.sil

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class C {
1111
weak var d: D?
1212
}
1313
class D {}
14+
struct S {}
1415
class DBox {
1516
var d: D
1617
}
@@ -32,6 +33,7 @@ sil [ossa] @callee_guaranteed: $@convention(thin) (@guaranteed C) -> ()
3233
sil [ossa] @callee_owned : $@convention(thin) (@owned C) -> ()
3334
sil [ossa] @callee_optional_d_guaranteed: $@convention(thin) (@guaranteed Optional<D>) -> ()
3435
sil [ossa] @synchronization_point : $@convention(thin) () -> ()
36+
sil [ossa] @modify_s : $@yield_once @convention(thin) () -> @yields @inout S
3537

3638
// =============================================================================
3739
// = DECLARATIONS }}
@@ -807,6 +809,27 @@ exit:
807809
return %retval : $()
808810
}
809811

812+
// Don't hoist over end_apply. These are lowered to calls to continuations
813+
// which can have the same sorts of side-effects as function calls.
814+
815+
// CHECK-LABEL: sil [ossa] @dont_hoist_over_end_apply : {{.*}} {
816+
// CHECK: end_apply
817+
// CHECK: end_borrow
818+
// CHECK-LABEL: } // end sil function 'dont_hoist_over_end_apply'
819+
sil [ossa] @dont_hoist_over_end_apply : $@convention(thin) (@owned C, S) -> () {
820+
entry(%instance : @owned $C, %input : $S):
821+
%lifetime = begin_borrow [lexical] %instance : $C
822+
%modify_s = function_ref @modify_s : $@yield_once @convention(thin) () -> @yields @inout S
823+
(%addr, %continuation) = begin_apply %modify_s() : $@yield_once @convention(thin) () -> @yields @inout S
824+
store %input to [trivial] %addr : $*S
825+
end_apply %continuation
826+
end_borrow %lifetime : $C
827+
destroy_value %instance : $C
828+
%retval = tuple ()
829+
return %retval : $()
830+
}
831+
832+
810833
// =============================================================================
811834
// instruction tests }}
812835
// =============================================================================

0 commit comments

Comments
 (0)