Skip to content

Commit 380ea88

Browse files
committed
SIL: fix self-argument APIs in Function
`var selfArgument` should return an optional, i.e. nil if the function doesn't have a self argument.
1 parent e41bba3 commit 380ea88

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/Devirtualization.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ extension DestroyValueInst : DevirtualizableDestroy {
122122
let builder = Builder(before: self, context)
123123
let subs = context.getContextSubstitutionMap(for: type)
124124
let deinitRef = builder.createFunctionRef(deinitializer)
125-
if deinitializer.argumentConventions[deinitializer.selfArgumentIndex].isIndirect {
125+
if deinitializer.argumentConventions[deinitializer.selfArgumentIndex!].isIndirect {
126126
let allocStack = builder.createAllocStack(type)
127127
builder.createStore(source: destroyedValue, destination: allocStack, ownership: .initialize)
128128
builder.createApply(function: deinitRef, subs, arguments: [allocStack])
@@ -194,7 +194,7 @@ extension DestroyAddrInst : DevirtualizableDestroy {
194194
let builder = Builder(before: self, context)
195195
let subs = context.getContextSubstitutionMap(for: destroyedAddress.type)
196196
let deinitRef = builder.createFunctionRef(deinitializer)
197-
if !deinitializer.argumentConventions[deinitializer.selfArgumentIndex].isIndirect {
197+
if !deinitializer.argumentConventions[deinitializer.selfArgumentIndex!].isIndirect {
198198
let value = builder.createLoad(fromAddress: destroyedAddress, ownership: .take)
199199
builder.createApply(function: deinitRef, subs, arguments: [value])
200200
} else {

SwiftCompilerSources/Sources/SIL/Effects.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,10 +690,10 @@ extension StringParser {
690690
private mutating func parseArgumentIndexFromSource(for function: Function,
691691
params: Dictionary<String, Int>) throws -> Int {
692692
if consume("self") {
693-
if !function.hasSelfArgument {
693+
guard let selfArgIdx = function.selfArgumentIndex else {
694694
try throwError("function does not have a self argument")
695695
}
696-
return function.selfArgumentIndex
696+
return selfArgIdx
697697
}
698698
if let name = consumeIdentifier() {
699699
guard let idx = params[name] else {

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,15 @@ extension Function {
320320

321321
public var hasSelfArgument: Bool { argumentConventions.selfIndex != nil }
322322

323-
public var selfArgumentIndex: Int { argumentConventions.selfIndex! }
323+
public var selfArgumentIndex: Int? { argumentConventions.selfIndex }
324+
325+
public var selfArgument: FunctionArgument? {
326+
if let selfArgIdx = selfArgumentIndex {
327+
return arguments[selfArgIdx]
328+
}
329+
return nil
330+
}
324331

325-
public var selfArgument: FunctionArgument { arguments[selfArgumentIndex] }
326-
327332
public var dynamicSelfMetadata: FunctionArgument? {
328333
if bridged.hasDynamicSelfMetadata() {
329334
return arguments.last!

0 commit comments

Comments
 (0)