Skip to content

Commit 11131c4

Browse files
authored
Merge pull request #20841 from rudkx/update-implements-test
Improve attr_implements_fp.swift test.
2 parents 78bf97c + 6ba307d commit 11131c4

File tree

2 files changed

+70
-33
lines changed

2 files changed

+70
-33
lines changed

test/attr/attr_implements_fp.swift

Lines changed: 60 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: echo 'main()' >%t/main.swift
3-
// RUN: %target-swiftc_driver -o %t/a.out %s %t/main.swift
3+
// RUN: %target-build-swift -o %t/a.out %s %t/main.swift -Xfrontend -enable-operator-designated-types -Xfrontend -solver-enable-operator-designated-types
44
// RUN: %target-codesign %t/a.out
55
// RUN: %target-run %t/a.out | %FileCheck %s
66
// REQUIRES: executable_test
@@ -10,25 +10,33 @@
1010
// when only known to be comparable".
1111

1212
// Could calls to the different comparison operators.
13-
public var comparedAsComparablesCount : Int = 0
13+
public var comparedAsCauxmparablesCount : Int = 0
1414
public var comparedAsFauxtsCount : Int = 0
1515

16-
public protocol FauxtingPoint : Comparable {
16+
infix operator .< : ComparisonPrecedence, BinaryFauxtingPoint, Cauxmparable
17+
18+
public protocol Cauxmparable {
19+
static func .< (lhs: Self, rhs: Self) -> Bool
20+
}
21+
22+
public protocol FauxtingPoint : Cauxmparable {
1723
static var nan: Self { get }
1824
static var one: Self { get }
1925
static var two: Self { get }
2026
}
2127

2228
public protocol BinaryFauxtingPoint: FauxtingPoint {
29+
@_nonoverride static func .< (lhs: Self, rhs: Self) -> Bool
30+
2331
var bitPattern: UInt8 { get }
2432
}
2533

2634
public extension BinaryFauxtingPoint {
27-
// This version of < will be called in a context that only knows it has a Comparable.
28-
@_implements(Comparable, <(_:_:))
29-
static func _ComparableLessThan(_ lhs: Fauxt, _ rhs: Fauxt) -> Bool {
30-
print("compared as Comparables")
31-
comparedAsComparablesCount += 1
35+
// This version of .< will be called in a context that only knows it has a Cauxmparable.
36+
@_implements(Cauxmparable, .<(_:_:))
37+
static func _CauxmparableLessThan(_ lhs: Fauxt, _ rhs: Fauxt) -> Bool {
38+
print("compared as Cauxmparables")
39+
comparedAsCauxmparablesCount += 1
3240
return lhs.bitPattern < rhs.bitPattern
3341
}
3442
}
@@ -70,11 +78,11 @@ extension Fauxt: BinaryFauxtingPoint {
7078
}
7179

7280
public extension Fauxt {
73-
// This version of < will be called in a context that knows it has a Fauxt.
81+
// This version of .< will be called in a context that knows it has a Fauxt.
7482
// It is inside an extension of Fauxt rather than the declaration of Fauxt
7583
// itself in order to avoid a warning about near-matches with the defaulted
76-
// requirement from Comparable.< up above.
77-
static func <(_ lhs: Fauxt, _ rhs: Fauxt) -> Bool {
84+
// requirement from Cauxmparable..< up above.
85+
static func .<(_ lhs: Fauxt, _ rhs: Fauxt) -> Bool {
7886
print("compared as Fauxts")
7987
comparedAsFauxtsCount += 1
8088
if lhs.state == .Nan || rhs.state == .Nan {
@@ -85,24 +93,42 @@ public extension Fauxt {
8593
}
8694
}
8795

88-
public func compare_Comparables<T:Comparable>(_ x: T, _ y: T) -> Bool {
89-
return x < y
96+
public func compare_Cauxmparables<T:Cauxmparable>(_ x: T, _ y: T) -> Bool {
97+
return x .< y
98+
}
99+
100+
public func compare_FauxtingPoint<T:FauxtingPoint>(_ x: T, _ y: T) -> Bool {
101+
return x .< y
102+
}
103+
104+
public func compare_BinaryFauxtingPoint<T:BinaryFauxtingPoint>(_ x: T, _ y: T) -> Bool {
105+
return x .< y
90106
}
91107

92108
public func compare_Fauxts(_ x: Fauxt, _ y: Fauxt) -> Bool {
93-
return x < y
109+
return x .< y
94110
}
95111

96112
public func main() {
97-
assert(compare_Comparables(Fauxt.one, Fauxt.two))
98-
assert(comparedAsComparablesCount == 1)
99-
// CHECK: compared as Comparables
100-
assert(compare_Comparables(Fauxt.one, Fauxt.nan))
101-
assert(comparedAsComparablesCount == 2)
102-
// CHECK: compared as Comparables
103-
assert(!compare_Comparables(Fauxt.nan, Fauxt.one))
104-
assert(comparedAsComparablesCount == 3)
105-
// CHECK: compared as Comparables
113+
assert(compare_Cauxmparables(Fauxt.one, Fauxt.two))
114+
assert(comparedAsCauxmparablesCount == 1)
115+
// CHECK: compared as Cauxmparables
116+
assert(compare_Cauxmparables(Fauxt.one, Fauxt.nan))
117+
assert(comparedAsCauxmparablesCount == 2)
118+
// CHECK: compared as Cauxmparables
119+
assert(!compare_Cauxmparables(Fauxt.nan, Fauxt.one))
120+
assert(comparedAsCauxmparablesCount == 3)
121+
// CHECK: compared as Cauxmparables
122+
123+
assert(compare_FauxtingPoint(Fauxt.one, Fauxt.two))
124+
assert(comparedAsCauxmparablesCount == 4)
125+
// CHECK: compared as Cauxmparables
126+
assert(compare_FauxtingPoint(Fauxt.one, Fauxt.nan))
127+
assert(comparedAsCauxmparablesCount == 5)
128+
// CHECK: compared as Cauxmparables
129+
assert(!compare_FauxtingPoint(Fauxt.nan, Fauxt.one))
130+
assert(comparedAsCauxmparablesCount == 6)
131+
// CHECK: compared as Cauxmparables
106132

107133
assert(compare_Fauxts(Fauxt.one, Fauxt.two))
108134
assert(comparedAsFauxtsCount == 1)
@@ -113,4 +139,15 @@ public func main() {
113139
assert(!compare_Fauxts(Fauxt.nan, Fauxt.one))
114140
assert(comparedAsFauxtsCount == 3)
115141
// CHECK: compared as Fauxts
142+
143+
assert(compare_BinaryFauxtingPoint(Fauxt.one, Fauxt.two))
144+
assert(comparedAsFauxtsCount == 4)
145+
// CHECK: compared as Fauxts
146+
assert(!compare_BinaryFauxtingPoint(Fauxt.one, Fauxt.nan))
147+
assert(comparedAsFauxtsCount == 5)
148+
// CHECK: compared as Fauxts
149+
assert(!compare_BinaryFauxtingPoint(Fauxt.nan, Fauxt.one))
150+
assert(comparedAsFauxtsCount == 6)
151+
// CHECK: compared as Fauxts
152+
116153
}

test/attr/attr_implements_serial.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: echo 'client()' >%t/main.swift
3-
// RUN: %target-build-swift-dylib(%t/libAttrImplFP.%target-dylib-extension) -module-name AttrImplFP -emit-module -emit-module-path %t/AttrImplFP.swiftmodule %S/attr_implements_fp.swift
3+
// RUN: %target-build-swift-dylib(%t/libAttrImplFP.%target-dylib-extension) -module-name AttrImplFP -emit-module -emit-module-path %t/AttrImplFP.swiftmodule %S/attr_implements_fp.swift -Xfrontend -enable-operator-designated-types -Xfrontend -solver-enable-operator-designated-types
44
// RUN: %target-build-swift -I %t -o %t/a.out %s %t/main.swift -L %t -Xlinker -rpath -Xlinker %t -lAttrImplFP
55
// RUN: %target-codesign %t/a.out
66
// RUN: %target-codesign %t/libAttrImplFP.%target-dylib-extension
@@ -13,15 +13,15 @@
1313
import AttrImplFP
1414

1515
public func client() {
16-
precondition(compare_Comparables(Fauxt.one, Fauxt.two))
17-
precondition(comparedAsComparablesCount == 1)
18-
// CHECK: compared as Comparables
19-
precondition(compare_Comparables(Fauxt.one, Fauxt.nan))
20-
precondition(comparedAsComparablesCount == 2)
21-
// CHECK: compared as Comparables
22-
precondition(!compare_Comparables(Fauxt.nan, Fauxt.one))
23-
precondition(comparedAsComparablesCount == 3)
24-
// CHECK: compared as Comparables
16+
precondition(compare_Cauxmparables(Fauxt.one, Fauxt.two))
17+
precondition(comparedAsCauxmparablesCount == 1)
18+
// CHECK: compared as Cauxmparables
19+
precondition(compare_Cauxmparables(Fauxt.one, Fauxt.nan))
20+
precondition(comparedAsCauxmparablesCount == 2)
21+
// CHECK: compared as Cauxmparables
22+
precondition(!compare_Cauxmparables(Fauxt.nan, Fauxt.one))
23+
precondition(comparedAsCauxmparablesCount == 3)
24+
// CHECK: compared as Cauxmparables
2525

2626
precondition(compare_Fauxts(Fauxt.one, Fauxt.two))
2727
precondition(comparedAsFauxtsCount == 1)

0 commit comments

Comments
 (0)