Skip to content

Commit dd6f468

Browse files
authored
Ensure that partial_apply of partial_apply does not produce conservative global side effects. (#62351)
Fixes #62249
1 parent 8e857d5 commit dd6f468

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ComputeSideEffects.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ private extension PartialApplyInst {
463463
struct EscapesToApply : EscapeVisitor {
464464
func visitUse(operand: Operand, path: EscapePath) -> UseResult {
465465
switch operand.instruction {
466-
case is ApplySite:
466+
case is FullApplySite:
467467
// Any escape to apply - regardless if it's an argument or the callee operand - might cause
468468
// the closure to be called.
469469
return .abort

test/SILOptimizer/side_effects.sil

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,17 @@ bb0(%0 : $*Int32):
814814
return %3 : $@callee_owned (Bool) -> Int32
815815
}
816816

817+
// CHECK-LABEL: sil @partial_apply_chain
818+
// CHECK-NEXT: [global: ]
819+
// CHECK-NEXT: {{^[^[]}}
820+
sil @partial_apply_chain : $@convention(thin) (@in Int32, @in Int32) -> @owned @callee_owned (Bool) -> Int32 {
821+
bb0(%0 : $*Int32, %1 : $*Int32):
822+
%3 = function_ref @closure2 : $@convention(thin) (Bool, @in Int32, @in Int32) -> Int32
823+
%4 = partial_apply %3(%0) : $@convention(thin) (Bool, @in Int32, @in Int32) -> Int32
824+
%5 = partial_apply %4(%1) : $@callee_owned (Bool, @in Int32) -> Int32
825+
return %5 : $@callee_owned (Bool) -> Int32
826+
}
827+
817828
// CHECK-LABEL: sil @two_nonstack_partial_applies
818829
// CHECK-NEXT: [%0: read v**]
819830
// CHECK-NEXT: [%1: write v**]
@@ -851,6 +862,7 @@ bb0(%0 : $*Int32, %1 : $*Int32, %2 : $X):
851862
}
852863

853864
sil @closure : $@convention(thin) (Bool, @in Int32) -> Int32
865+
sil @closure2 : $@convention(thin) (Bool, @in Int32, @in Int32) -> Int32
854866

855867
sil public_external @public_external_func : $@convention(thin) () -> () {
856868
bb0:

0 commit comments

Comments
 (0)