Skip to content

Commit 8984046

Browse files
committed
Effects: remove the isExclusive flag from the escapingToArgument effect
An argument-to-argument escape always involves a store, which makes an exclusive escape impossible.
1 parent 7a3ae09 commit 8984046

File tree

7 files changed

+34
-22
lines changed

7 files changed

+34
-22
lines changed

SwiftCompilerSources/Sources/Optimizer/FunctionPasses/ComputeEscapeEffects.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ func addArgEffects(_ arg: FunctionArgument, argPath ap: SmallProjectionPath,
160160
case .toArgument(let toArgIdx, let toPath):
161161
// Exclusive argument -> argument effects cannot appear because such an effect would
162162
// involve a store which is not permitted for exclusive escapes.
163-
effect = EscapeEffects.ArgumentEffect(.escapingToArgument(toArgumentIndex: toArgIdx, toPath: toPath, isExclusive: false),
163+
effect = EscapeEffects.ArgumentEffect(.escapingToArgument(toArgumentIndex: toArgIdx, toPath: toPath),
164164
argumentIndex: arg.index, pathPattern: argPath)
165165
}
166166
newEffects.append(effect)
@@ -176,8 +176,10 @@ private func getArgIndicesWithDefinedEscapingEffects(of function: Function) -> S
176176

177177
argsWithDefinedEffects.insert(effect.argumentIndex)
178178
switch effect.kind {
179-
case .notEscaping, .escapingToReturn: break
180-
case .escapingToArgument(let toArgIdx, _, _): argsWithDefinedEffects.insert(toArgIdx)
179+
case .notEscaping, .escapingToReturn:
180+
break
181+
case .escapingToArgument(let toArgIdx, _):
182+
argsWithDefinedEffects.insert(toArgIdx)
181183
}
182184
}
183185
return argsWithDefinedEffects

SwiftCompilerSources/Sources/Optimizer/Utilities/EscapeUtils.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
594594
var matched = false
595595
for effect in effects.escapeEffects.arguments {
596596
switch effect.kind {
597-
case .escapingToArgument(let toArgIdx, let toPath, _):
597+
case .escapingToArgument(let toArgIdx, let toPath):
598598
// Note: exclusive argument -> argument effects cannot appear, so we don't need to handle them here.
599599
if effect.matches(calleeArgIdx, argPath.projectionPath) {
600600
guard let callerToIdx = apply.callerArgIndex(calleeArgIndex: toArgIdx) else {

SwiftCompilerSources/Sources/SIL/Effects.swift

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,9 @@ public struct EscapeEffects : CustomStringConvertible, NoReflectionChildren {
285285
/// Note that theoretically this rule also applies to the `escapingToReturn` effect, but it's impossible
286286
/// to construct such a situation for an argument which is only escaping to the function return.
287287
///
288-
case escapingToArgument(toArgumentIndex: Int, toPath: SmallProjectionPath, isExclusive: Bool)
288+
/// The `escapingToArgument` doesn't have an `isExclusive` flag, because an argument-to-argument escape
289+
/// always involves a store, which makes an exclusive escape impossible.
290+
case escapingToArgument(toArgumentIndex: Int, toPath: SmallProjectionPath)
289291
}
290292

291293
/// To which argument does this effect apply to?
@@ -330,19 +332,19 @@ public struct EscapeEffects : CustomStringConvertible, NoReflectionChildren {
330332
if resultArgDelta != 1 {
331333
return nil
332334
}
333-
self.kind = .escapingToArgument(toArgumentIndex: 0, toPath: toPath, isExclusive: exclusive)
335+
self.kind = .escapingToArgument(toArgumentIndex: 0, toPath: toPath)
334336
} else {
335337
self.kind = .escapingToReturn(toPath: toPath, isExclusive: exclusive)
336338
}
337-
case .escapingToArgument(let toArgIdx, let toPath, let exclusive):
339+
case .escapingToArgument(let toArgIdx, let toPath):
338340
let resultingToArgIdx = toArgIdx + resultArgDelta
339341
if resultingToArgIdx < 0 {
340342
if resultingToArgIdx != -1 {
341343
return nil
342344
}
343-
self.kind = .escapingToReturn(toPath: toPath, isExclusive: exclusive)
345+
self.kind = .escapingToReturn(toPath: toPath, isExclusive: false)
344346
} else {
345-
self.kind = .escapingToArgument(toArgumentIndex: resultingToArgIdx, toPath: toPath, isExclusive: exclusive)
347+
self.kind = .escapingToArgument(toArgumentIndex: resultingToArgIdx, toPath: toPath)
346348
}
347349
}
348350
}
@@ -362,9 +364,9 @@ public struct EscapeEffects : CustomStringConvertible, NoReflectionChildren {
362364
case .escapingToReturn(let toPath, let exclusive):
363365
let toPathStr = (toPath.isEmpty ? "" : ".\(toPath)")
364366
return "escape\(patternStr) \(exclusive ? "=>" : "->") %r\(toPathStr)"
365-
case .escapingToArgument(let toArgIdx, let toPath, let exclusive):
367+
case .escapingToArgument(let toArgIdx, let toPath):
366368
let toPathStr = (toPath.isEmpty ? "" : ".\(toPath)")
367-
return "escape\(patternStr) \(exclusive ? "=>" : "->") %\(toArgIdx)\(toPathStr)"
369+
return "escape\(patternStr) -> %\(toArgIdx)\(toPathStr)"
368370
}
369371
}
370372

@@ -663,16 +665,21 @@ extension StringParser {
663665
try throwError("multi-value returns not supported yet")
664666
}
665667
let toPath = try parsePathPatternFromSource(for: function, type: function.argumentTypes[0])
666-
return EscapeEffects.ArgumentEffect(.escapingToArgument(toArgumentIndex: 0, toPath: toPath, isExclusive: exclusive),
668+
669+
// Exclusive escapes are ignored for indirect return values.
670+
return EscapeEffects.ArgumentEffect(.escapingToArgument(toArgumentIndex: 0, toPath: toPath),
667671
argumentIndex: fromArgIdx, pathPattern: fromPath, isDerived: false)
668672
}
669673
let toPath = try parsePathPatternFromSource(for: function, type: function.resultType)
670674
return EscapeEffects.ArgumentEffect(.escapingToReturn(toPath: toPath, isExclusive: exclusive),
671675
argumentIndex: fromArgIdx, pathPattern: fromPath, isDerived: false)
672676
}
677+
if exclusive {
678+
try throwError("exclusive escapes to arguments are not supported")
679+
}
673680
let toArgIdx = try parseArgumentIndexFromSource(for: function, params: params)
674681
let toPath = try parsePathPatternFromSource(for: function, type: function.argumentTypes[toArgIdx])
675-
return EscapeEffects.ArgumentEffect(.escapingToArgument(toArgumentIndex: toArgIdx, toPath: toPath, isExclusive: exclusive),
682+
return EscapeEffects.ArgumentEffect(.escapingToArgument(toArgumentIndex: toArgIdx, toPath: toPath),
676683
argumentIndex: fromArgIdx, pathPattern: fromPath, isDerived: false)
677684
}
678685
try throwError("unknown effect")
@@ -739,9 +746,12 @@ extension StringParser {
739746
effect = EscapeEffects.ArgumentEffect(.escapingToReturn(toPath: toPath, isExclusive: exclusive),
740747
argumentIndex: argumentIndex, pathPattern: fromPath, isDerived: isDerived)
741748
} else {
749+
if exclusive {
750+
try throwError("exclusive escapes to arguments are not supported")
751+
}
742752
let toArgIdx = try parseArgumentIndexFromSIL()
743753
let toPath = consume(".") ? try parseProjectionPathFromSIL() : SmallProjectionPath()
744-
effect = EscapeEffects.ArgumentEffect(.escapingToArgument(toArgumentIndex: toArgIdx, toPath: toPath, isExclusive: exclusive),
754+
effect = EscapeEffects.ArgumentEffect(.escapingToArgument(toArgumentIndex: toArgIdx, toPath: toPath),
745755
argumentIndex: argumentIndex, pathPattern: fromPath, isDerived: isDerived)
746756
}
747757
effects.escapeEffects.arguments.append(effect)

test/SILGen/effectsattr.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
@_effects(notEscaping t.**) @_silgen_name("func5") func func5<T>(_ t: T) { }
2121

2222
//CHECK-LABEL: sil hidden [ossa] @func6
23-
//CHECK-NEXT: [%1: escape! v**.c* => %0.v**]
23+
//CHECK-NEXT: [%1: escape! v**.c* -> %0.v**]
2424
//CHECK-NEXT: {{^[^[]}}
2525
@_effects(escaping t.value**.class* => return.value**) @_silgen_name("func6") func func6<T>(_ t: T) -> T { }
2626

test/SILOptimizer/escape_effects.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ bb0(%0 : @guaranteed $Z, %1 : @owned $Y):
197197
}
198198

199199
sil [ossa] @self_arg_callee : $@convention(thin) (@inout Str) -> () {
200-
[%0: escape v** => %0.v**]
200+
[%0: escape v** -> %0.v**]
201201
}
202202

203203
// CHECK-LABEL: sil [ossa] @test_self_arg_escape

test/SILOptimizer/escape_info.sil

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,11 +1011,11 @@ sil @closure3 : $@convention(thin) (@guaranteed Z) -> () {
10111011
[%0: noescape **]
10121012
}
10131013
sil [ossa] @closure4 : $@convention(thin) (@guaranteed X, @guaranteed Y) -> () {
1014-
[%0: escape => %1]
1014+
[%0: escape -> %1]
10151015
[%1: noescape]
10161016
}
10171017
sil [ossa] @closure5 : $@convention(thin) (@guaranteed Y, @guaranteed X) -> () {
1018-
[%1: escape => %0, noescape]
1018+
[%1: escape -> %0, noescape]
10191019
}
10201020

10211021
sil [ossa] @closure6 : $@convention(thin) (@guaranteed Y, @guaranteed Y) -> @owned Y {

test/SILOptimizer/specialize_reabstraction.sil

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -136,21 +136,21 @@ bb0(%0 : $Bool):
136136
}
137137

138138
// CHECK-LABEL: sil shared @$s21arg_escapes_to_return4main1XC_Tg5
139-
// CHECK-NEXT: [%0: escape => %r]
139+
// CHECK-NEXT: [%0: escape -> %r]
140140
// CHECK-NEXT: {{^[^[]}}
141141
sil @arg_escapes_to_return : $@convention(thin) <T> (@in_guaranteed T) -> @out T {
142-
[%1: escape => %0]
142+
[%1: escape -> %0]
143143
bb0(%0 : $*T, %1 : $*T):
144144
copy_addr %1 to [init] %0 : $*T
145145
%4 = tuple ()
146146
return %4 : $()
147147
}
148148

149149
// CHECK-LABEL: sil shared @$s015arg_escapes_to_A04main1XC_Tg5
150-
// CHECK-NEXT: [%1: escape => %0]
150+
// CHECK-NEXT: [%1: escape -> %0]
151151
// CHECK-NEXT: {{^[^[]}}
152152
sil @arg_escapes_to_arg : $@convention(thin) <T> (@inout T, @in_guaranteed T) -> () {
153-
[%1: escape => %0]
153+
[%1: escape -> %0]
154154
bb0(%0 : $*T, %1 : $*T):
155155
copy_addr %1 to %0 : $*T
156156
%4 = tuple ()

0 commit comments

Comments
 (0)