Skip to content

Commit 78e1713

Browse files
committed
Swift AccessUtils: improve ergonomics of getAccessPathWithScope
It doesn't make sense to let getAccessPathWithScope return an `EnclosingScope` as the second tuple element, because in case it's a `base`, it duplicates the `AccessBase` (which is returned in the first tuple element). Instead just return an optional `BeginAccessInst` which is not nil if such an "scope" is found.
1 parent ff874f8 commit 78e1713

File tree

2 files changed

+28
-20
lines changed

2 files changed

+28
-20
lines changed

SwiftCompilerSources/Sources/Optimizer/TestPasses/AccessDumper.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,9 @@ private func printAccessInfo(address: Value) {
6161

6262
var apw = AccessPathWalker()
6363
let (ap, scope) = apw.getAccessPathWithScope(of: address)
64-
switch scope {
65-
case let .scope(ba):
66-
print(" Scope: \(ba)")
67-
case .base(_):
64+
if let beginAccess = scope {
65+
print(" Scope: \(beginAccess)")
66+
} else {
6867
print(" Scope: base")
6968
}
7069

SwiftCompilerSources/Sources/Optimizer/Utilities/AccessUtils.swift

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -381,34 +381,31 @@ struct AccessPathWalker {
381381
return walker.result
382382
}
383383

384-
mutating func getAccessPathWithScope(of address: Value) -> (AccessPath, EnclosingScope) {
384+
mutating func getAccessPathWithScope(of address: Value) -> (AccessPath, scope: BeginAccessInst?) {
385385
let ap = getAccessPath(of: address)
386-
return (ap, walker.scope)
386+
return (ap, walker.foundBeginAccess)
387387
}
388388

389389
mutating func getAccessBase(of address: Value) -> AccessBase {
390390
getAccessPath(of: address).base
391391
}
392392

393-
mutating func getAccessScope(of address: Value) -> EnclosingScope {
394-
getAccessPathWithScope(of: address).1
393+
mutating func getEnclosingScope(of address: Value) -> EnclosingScope {
394+
let accessPath = getAccessPath(of: address)
395+
396+
if let ba = walker.foundBeginAccess {
397+
return .scope(ba)
398+
}
399+
return .base(accessPath.base)
395400
}
396401

397402
private var walker = Walker()
398403

399404
private struct Walker : AddressUseDefWalker {
400405
private(set) var result = AccessPath.unidentified()
401-
private var foundBeginAccess: BeginAccessInst? = nil
406+
private(set) var foundBeginAccess: BeginAccessInst?
402407
private var pointerId = PointerIdentification()
403408

404-
var scope: EnclosingScope {
405-
if let ba = foundBeginAccess {
406-
return .scope(ba)
407-
} else {
408-
return .base(result.base)
409-
}
410-
}
411-
412409
mutating func start() {
413410
result = .unidentified()
414411
foundBeginAccess = nil
@@ -489,11 +486,23 @@ extension Value {
489486
var apWalker = AccessPathWalker()
490487
return apWalker.getAccessBase(of: self)
491488
}
492-
489+
490+
/// Computes the access path of this address value.
491+
var accessPath: AccessPath {
492+
var apWalker = AccessPathWalker()
493+
return apWalker.getAccessPath(of: self)
494+
}
495+
496+
/// Computes the access path of this address value and also returns the scope.
497+
var accessPathWithScope: (AccessPath, scope: BeginAccessInst?) {
498+
var apWalker = AccessPathWalker()
499+
return apWalker.getAccessPathWithScope(of: self)
500+
}
501+
493502
/// Computes the enclosing access scope of this address value.
494-
var accessScope: EnclosingScope {
503+
var enclosingAccessScope: EnclosingScope {
495504
var apWalker = AccessPathWalker()
496-
return apWalker.getAccessScope(of: self)
505+
return apWalker.getEnclosingScope(of: self)
497506
}
498507
}
499508

0 commit comments

Comments
 (0)