Skip to content

Commit f037b63

Browse files
committed
LifetimeDependenceUtils: cleanup Scope initialization.
And fix a couple latent bugs.
1 parent 9318928 commit f037b63

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/LifetimeDependenceUtils.swift

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -307,22 +307,21 @@ extension LifetimeDependence.Scope {
307307
/// forwarded (via struct/tuple) from multiple guaranteed values.
308308
init?(base: Value, _ context: some Context) {
309309
if base.type.isAddress {
310-
if let scope = Self(address: base, context) {
311-
self = scope
312-
return
310+
guard let scope = Self(address: base, context) else {
311+
return nil
313312
}
314-
return nil
313+
self = scope
314+
return
315315
}
316316
switch base.ownership {
317317
case .owned:
318318
self = .owned(base)
319319
return
320320
case .guaranteed:
321-
if let scope = Self(guaranteed: base, context) {
322-
self = scope
323-
return
321+
guard let scope = Self(guaranteed: base, context) else {
322+
return nil
324323
}
325-
return nil
324+
self = scope
326325
case .none:
327326
// lifetime dependence requires a nontrivial value"
328327
return nil
@@ -339,23 +338,23 @@ extension LifetimeDependence.Scope {
339338
switch accessBase {
340339
case let .box(projectBox):
341340
// Note: the box may be in a borrow scope.
342-
if let scope = Self(base: projectBox.operand.value, context) {
343-
self = scope
341+
guard let scope = Self(base: projectBox.operand.value, context) else {
342+
return nil
344343
}
345-
return nil
344+
self = scope
346345
case let .stack(allocStack):
347-
if let scope = Self(allocation: allocStack, context) {
348-
self = scope
346+
guard let scope = Self(allocation: allocStack, context) else {
347+
return nil
349348
}
350-
return nil
349+
self = scope
351350
case .global:
352351
self = .unknown(address)
353352
case .class, .tail:
354353
let refElt = address as! UnaryInstruction
355-
if let scope = Self(guaranteed: refElt.operand.value, context) {
356-
self = scope
354+
guard let scope = Self(guaranteed: refElt.operand.value, context) else {
355+
return nil
357356
}
358-
return nil
357+
self = scope
359358
case let .argument(arg):
360359
if arg.convention.isIndirectIn {
361360
self = .initialized(initialAddress: arg, initializingStore: nil)

0 commit comments

Comments
 (0)