Skip to content

Commit f47b292

Browse files
authored
Merge pull request #75975 from atrick/fix-local-var-switch
Improve LocalVariableAccessWalker to handle switch_enum_addr.
2 parents f1b5704 + e4036b9 commit f47b292

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/LocalVariableUtils.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,8 @@ extension LocalVariableAccessWalker: AddressUseVisitor {
420420
mutating func leafAddressUse(of operand: Operand) -> WalkResult {
421421
switch operand.instruction {
422422
case is StoringInstruction, is SourceDestAddrInstruction, is DestroyAddrInst, is DeinitExistentialAddrInst,
423-
is InjectEnumAddrInst, is TupleAddrConstructorInst, is InitBlockStorageHeaderInst, is PackElementSetInst:
423+
is InjectEnumAddrInst, is SwitchEnumAddrInst, is TupleAddrConstructorInst, is InitBlockStorageHeaderInst,
424+
is PackElementSetInst:
424425
// Handle instructions that initialize both temporaries and local variables.
425426
visit(LocalVariableAccess(.store, operand))
426427
case is DeallocStackInst:

test/SILOptimizer/lifetime_dependence/lifetime_dependence_optional.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ extension Nillable where Wrapped: ~Copyable & ~Escapable {
3939
public init(_ some: consuming Wrapped) { self = .some(some) }
4040
}
4141

42+
extension Nillable where Wrapped: ~Escapable {
43+
// Requires local variable analysis over switch_enum_addr.
44+
public func map<E: Error, U: ~Copyable>(
45+
_ transform: (Wrapped) throws(E) -> U
46+
) throws(E) -> U? {
47+
switch self {
48+
case .some(let y):
49+
return .some(try transform(y))
50+
case .none:
51+
return .none
52+
}
53+
}
54+
}
55+
4256
extension Nillable where Wrapped: ~Copyable {
4357
public consuming func _consumingMap<U: ~Copyable, E: Error>(
4458
_ transform: (consuming Wrapped) throws(E) -> U

0 commit comments

Comments
 (0)