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 {
141141 if let applySite = inst as? FullApplySite ,
142142 let callee = applySite. referencedFunction,
143143 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 {
146146 return true
147147 }
148148 return false
Original file line number Diff line number Diff line change @@ -89,9 +89,9 @@ private extension PartialApplyInst {
8989 guard isOnStack,
9090 let callee = referencedFunction,
9191 callee. isDefinition,
92- let argIdx = calleeArgumentIndex ( of: closure) ,
92+ let calleeArg = calleeArgument ( of: closure, in : callee ) ,
9393 // If the callee only _calls_ the closure argument, it does not escape.
94- callee . arguments [ argIdx ] . uses. allSatisfy ( isCalleeOperandOfApply)
94+ calleeArg . uses. allSatisfy ( isCalleeOperandOfApply)
9595 else {
9696 return true
9797 }
Original file line number Diff line number Diff line change @@ -277,15 +277,24 @@ extension ApplySite {
277277 return argumentOperands [ callerArgIdx]
278278 }
279279
280- /// Returns the argument index of an operand.
280+ /// Returns the argument of ` operand` in a callee function .
281281 ///
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
283283 /// 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.
284292 ///
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 .
287295 ///
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.
289298 public func calleeArgumentIndex( of operand: Operand ) -> Int ? {
290299 operandConventions. calleeArgumentIndex ( of: operand)
291300 }
You can’t perform that action at this time.
0 commit comments