File tree Expand file tree Collapse file tree 3 files changed +18
-9
lines changed
SwiftCompilerSources/Sources
InstructionSimplification Expand file tree Collapse file tree 3 files changed +18
-9
lines changed Original file line number Diff line number Diff line change @@ -141,8 +141,8 @@ private func isOperandOfRecursiveCall(_ op: Operand) -> Bool {
141
141
if let applySite = inst as? FullApplySite ,
142
142
let callee = applySite. referencedFunction,
143
143
callee == inst. parentFunction,
144
- let argIdx = applySite. calleeArgumentIndex ( of: op) ,
145
- op. value == callee . arguments [ argIdx ] {
144
+ let calleeArg = applySite. calleeArgument ( of: op, in : callee ) ,
145
+ op. value == calleeArg {
146
146
return true
147
147
}
148
148
return false
Original file line number Diff line number Diff line change @@ -89,9 +89,9 @@ private extension PartialApplyInst {
89
89
guard isOnStack,
90
90
let callee = referencedFunction,
91
91
callee. isDefinition,
92
- let argIdx = calleeArgumentIndex ( of: closure) ,
92
+ let calleeArg = calleeArgument ( of: closure, in : callee ) ,
93
93
// If the callee only _calls_ the closure argument, it does not escape.
94
- callee . arguments [ argIdx ] . uses. allSatisfy ( isCalleeOperandOfApply)
94
+ calleeArg . uses. allSatisfy ( isCalleeOperandOfApply)
95
95
else {
96
96
return true
97
97
}
Original file line number Diff line number Diff line change @@ -277,15 +277,24 @@ extension ApplySite {
277
277
return argumentOperands [ callerArgIdx]
278
278
}
279
279
280
- /// Returns the argument index of an operand.
280
+ /// Returns the argument of ` operand` in a callee function .
281
281
///
282
- /// Returns nil if ' operand' is not an argument operand. This is the case if
282
+ /// Returns nil if ` operand` is not an argument operand. This is the case if
283
283
/// it's the callee function operand.
284
+ public func calleeArgument( of operand: Operand , in callee: Function ) -> FunctionArgument ? {
285
+ if let argIdx = calleeArgumentIndex ( of: operand) {
286
+ return callee. arguments [ argIdx]
287
+ }
288
+ return nil
289
+ }
290
+
291
+ /// Returns the argument index of an operand.
284
292
///
285
- /// Warning: the returned integer can be misused as an index into
286
- /// the wrong collection. Replace uses of this API with safer APIs .
293
+ /// Returns nil if `operand` is not an argument operand. This is the case if
294
+ /// it's the callee function operand .
287
295
///
288
- /// TODO: delete this API and rewrite the users.
296
+ /// Warning: the returned integer can be misused as an index into the wrong collection.
297
+ /// Use `calleeArgument(of:,in:)` if possible.
289
298
public func calleeArgumentIndex( of operand: Operand ) -> Int ? {
290
299
operandConventions. calleeArgumentIndex ( of: operand)
291
300
}
You can’t perform that action at this time.
0 commit comments