Skip to content

Commit 6226d56

Browse files
committed
SmallProjectionPath: add mayHaveTwoClassProjections
1 parent 8daa54a commit 6226d56

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

SwiftCompilerSources/Sources/SIL/SmallProjectionPath.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,18 @@ public struct SmallProjectionPath : Hashable, CustomStringConvertible, NoReflect
268268
return !matches(pattern: Self(.anyValueFields))
269269
}
270270

271+
/// Returns true if the path may have a class projection.
272+
/// For example:
273+
/// returns false for `v**`
274+
/// returns false for `c0`
275+
/// returns true for `c0.c1`
276+
/// returns true for `c0.**` (because '**' can have any number of class projections)
277+
/// returns true for `**` (because '**' can have any number of class projections)
278+
public var mayHaveTwoClassProjections: Bool {
279+
return !matches(pattern: Self(.anyValueFields)) &&
280+
!matches(pattern: Self(.anyValueFields).push(.anyClassField).push(.anyValueFields))
281+
}
282+
271283
/// Pops all value field components from the beginning of the path.
272284
/// For example:
273285
/// `s0.e2.3.c4.s1` -> `c4.s1`
@@ -691,6 +703,12 @@ extension SmallProjectionPath {
691703
testPredicate("1", \.mayHaveClassProjection, expect: false)
692704
testPredicate("**", \.mayHaveClassProjection, expect: true)
693705

706+
testPredicate("v**", \.mayHaveTwoClassProjections, expect: false)
707+
testPredicate("c0", \.mayHaveTwoClassProjections, expect: false)
708+
testPredicate("**", \.mayHaveTwoClassProjections, expect: true)
709+
testPredicate("v**.c*.s2.1.c0", \.mayHaveTwoClassProjections, expect: true)
710+
testPredicate("c*.s2.1.c0.v**", \.mayHaveTwoClassProjections, expect: true)
711+
testPredicate("v**.c*.**", \.mayHaveTwoClassProjections, expect: true)
694712
}
695713

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

0 commit comments

Comments
 (0)