Skip to content

Commit a17ee43

Browse files
committed
Swift SIL: fix var ApplySite.arguments
In case of type-dependent operands, not all operands are part of the arguments
1 parent 965a54f commit a17ee43

File tree

4 files changed

+13
-1
lines changed

4 files changed

+13
-1
lines changed

SwiftCompilerSources/Sources/SIL/ApplySite.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ extension ApplySite {
3030
public var callee: Value { operands[ApplyOperands.calleeOperandIndex].value }
3131

3232
public var arguments: LazyMapSequence<OperandArray, Value> {
33-
operands[1..<operands.count].lazy.map { $0.value }
33+
let numArgs = ApplySite_getNumArguments(bridged)
34+
let offset = ApplyOperands.firstArgumentIndex
35+
let argOps = operands[offset..<(numArgs + offset)]
36+
return argOps.lazy.map { $0.value }
3437
}
3538

3639
public var substitutionMap: SubstitutionMap {

SwiftCompilerSources/Sources/SIL/Operand.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ public struct OperandArray : RandomAccessCollection, CustomReflectable {
7070
return Mirror(self, children: c)
7171
}
7272

73+
/// Returns a sub-array defined by `bounds`.
74+
///
75+
/// Note: this does not return a Slice. The first index of the returnd array is always 0.
7376
public subscript(bounds: Range<Int>) -> OperandArray {
7477
precondition(bounds.lowerBound >= 0)
7578
precondition(bounds.upperBound <= endIndex)

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ SwiftInt CondBranchInst_getNumTrueArgs(BridgedInstruction cbr);
328328
BridgedSubstitutionMap ApplySite_getSubstitutionMap(BridgedInstruction inst);
329329
BridgedArgumentConvention
330330
ApplySite_getArgumentConvention(BridgedInstruction inst, SwiftInt calleeArgIdx);
331+
SwiftInt ApplySite_getNumArguments(BridgedInstruction inst);
331332

332333
BridgedInstruction SILBuilder_createBuiltinBinaryFunction(
333334
BridgedBuilder builder, BridgedStringRef name,

lib/SIL/Utils/SILBridging.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,11 @@ ApplySite_getArgumentConvention(BridgedInstruction inst, SwiftInt calleeArgIdx)
778778
}
779779
}
780780

781+
SwiftInt ApplySite_getNumArguments(BridgedInstruction inst) {
782+
auto as = ApplySite(castToInst(inst));
783+
return as.getNumArguments();
784+
}
785+
781786
//===----------------------------------------------------------------------===//
782787
// SILBuilder
783788
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)