Skip to content

Commit 8daa54a

Browse files
committed
SmallProjectionPath: replace hasNoClassProjection with mayHaveClassProjection
It's less confusing. NFC
1 parent cc60815 commit 8daa54a

File tree

3 files changed

+18
-17
lines changed

3 files changed

+18
-17
lines changed

SwiftCompilerSources/Sources/Optimizer/Utilities/EscapeUtils.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
382382

383383
// Class references, which are directly located in the array elements cannot escape,
384384
// because those are passed as `self` to their deinits - and `self` cannot escape in a deinit.
385-
if path.projectionPath.hasNoClassProjection {
385+
if !path.projectionPath.mayHaveClassProjection {
386386
return .continueWalk
387387
}
388388
return isEscaping
@@ -818,7 +818,7 @@ fileprivate struct EscapeWalker<V: EscapeVisitor> : ValueDefUseWalker,
818818
private func followLoads(at path: SmallProjectionPath) -> Bool {
819819
return visitor.followLoads ||
820820
// When part of a class field we have to follow loads.
821-
!path.hasNoClassProjection
821+
path.mayHaveClassProjection
822822
}
823823

824824
private func pathForArgumentEscapeChecking(_ path: SmallProjectionPath) -> SmallProjectionPath {

SwiftCompilerSources/Sources/SIL/Effects.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ public struct SideEffects : CustomStringConvertible, NoReflectionChildren {
499499
case .directGuaranteed:
500500
// Note that `directGuaranteed` still has a "destroy" effect, because an object stored in
501501
// a class property could be destroyed.
502-
if argument.path.hasNoClassProjection {
502+
if !argument.path.mayHaveClassProjection {
503503
result.ownership.destroy = false
504504
}
505505
fallthrough

SwiftCompilerSources/Sources/SIL/SmallProjectionPath.swift

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -244,15 +244,6 @@ public struct SmallProjectionPath : Hashable, CustomStringConvertible, NoReflect
244244
}
245245
}
246246

247-
/// Returns true if the path does not have any class projections.
248-
/// For example:
249-
/// returns true for `v**`
250-
/// returns false for `c0`
251-
/// returns false for `**` (because '**' can have any number of class projections)
252-
public var hasNoClassProjection: Bool {
253-
return matches(pattern: Self(.anyValueFields))
254-
}
255-
256247
/// Returns true if the path has at least one class projection.
257248
/// For example:
258249
/// returns false for `v**`
@@ -268,6 +259,15 @@ public struct SmallProjectionPath : Hashable, CustomStringConvertible, NoReflect
268259
}
269260
}
270261

262+
/// Returns true if the path may have a class projection.
263+
/// For example:
264+
/// returns false for `v**`
265+
/// returns true for `c0`
266+
/// returns true for `**` (because '**' can have any number of class projections)
267+
public var mayHaveClassProjection: Bool {
268+
return !matches(pattern: Self(.anyValueFields))
269+
}
270+
271271
/// Pops all value field components from the beginning of the path.
272272
/// For example:
273273
/// `s0.e2.3.c4.s1` -> `c4.s1`
@@ -679,17 +679,18 @@ extension SmallProjectionPath {
679679
}
680680

681681
func predicates() {
682-
testPredicate("v**", \.hasNoClassProjection, expect: true)
683-
testPredicate("c0", \.hasNoClassProjection, expect: false)
684-
testPredicate("1", \.hasNoClassProjection, expect: true)
685-
testPredicate("**", \.hasNoClassProjection, expect: false)
686-
687682
testPredicate("v**", \.hasClassProjection, expect: false)
688683
testPredicate("v**.c0.s1.v**", \.hasClassProjection, expect: true)
689684
testPredicate("c0.**", \.hasClassProjection, expect: true)
690685
testPredicate("c0.c1", \.hasClassProjection, expect: true)
691686
testPredicate("ct", \.hasClassProjection, expect: true)
692687
testPredicate("s0", \.hasClassProjection, expect: false)
688+
689+
testPredicate("v**", \.mayHaveClassProjection, expect: false)
690+
testPredicate("c0", \.mayHaveClassProjection, expect: true)
691+
testPredicate("1", \.mayHaveClassProjection, expect: false)
692+
testPredicate("**", \.mayHaveClassProjection, expect: true)
693+
693694
}
694695

695696
func testPredicate(_ pathStr: String, _ property: (SmallProjectionPath) -> Bool, expect: Bool) {

0 commit comments

Comments
 (0)