Skip to content

Commit baf5a72

Browse files
committed
SwiftCompilerSources: consider indirect error results in Function.numArguments
1 parent cd8d156 commit baf5a72

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
5555
blocks.reversed().lazy.flatMap { $0.instructions.reversed() }
5656
}
5757

58-
/// The number of indirect result arguments.
5958
public var numIndirectResultArguments: Int { bridged.getNumIndirectFormalResults() }
60-
59+
public var hasIndirectErrorArgument: Bool { bridged.hasIndirectErrorResult() }
60+
6161
/// The number of arguments which correspond to parameters (and not to indirect results).
6262
public var numParameterArguments: Int { bridged.getNumParameters() }
6363

@@ -66,7 +66,9 @@ final public class Function : CustomStringConvertible, HasShortDescription, Hash
6666
/// This is the sum of indirect result arguments and parameter arguments.
6767
/// If the function is a definition (i.e. it has at least an entry block), this is the
6868
/// number of arguments of the function's entry block.
69-
public var numArguments: Int { numIndirectResultArguments + numParameterArguments }
69+
public var numArguments: Int {
70+
numIndirectResultArguments + (hasIndirectErrorArgument ? 1 : 0) + numParameterArguments
71+
}
7072

7173
public var hasSelfArgument: Bool {
7274
bridged.getSelfArgumentIndex() >= 0

include/swift/AST/Types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4785,6 +4785,9 @@ class SILFunctionType final
47854785
unsigned getNumPackResults() const {
47864786
return isCoroutine() ? 0 : NumPackResults;
47874787
}
4788+
bool hasIndirectErrorResult() const {
4789+
return hasErrorResult() && getErrorResult().isFormalIndirect();
4790+
}
47884791

47894792
struct IndirectFormalResultFilter {
47904793
bool operator()(SILResultInfo result) const {

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ struct BridgedFunction {
295295
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedBasicBlock getFirstBlock() const;
296296
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedBasicBlock getLastBlock() const;
297297
BRIDGED_INLINE SwiftInt getNumIndirectFormalResults() const;
298+
BRIDGED_INLINE bool hasIndirectErrorResult() const;
298299
BRIDGED_INLINE SwiftInt getNumParameters() const;
299300
BRIDGED_INLINE SwiftInt getSelfArgumentIndex() const;
300301
BRIDGED_INLINE SwiftInt getNumSILArguments() const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,10 @@ SwiftInt BridgedFunction::getNumIndirectFormalResults() const {
413413
return (SwiftInt)getFunction()->getLoweredFunctionType()->getNumIndirectFormalResults();
414414
}
415415

416+
bool BridgedFunction::hasIndirectErrorResult() const {
417+
return (SwiftInt)getFunction()->getLoweredFunctionType()->hasIndirectErrorResult();
418+
}
419+
416420
SwiftInt BridgedFunction::getNumParameters() const {
417421
return (SwiftInt)getFunction()->getLoweredFunctionType()->getNumParameters();
418422
}

0 commit comments

Comments
 (0)