Skip to content

Revert "Improve attr_implements_fp.swift test." #20883

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 23 additions & 60 deletions test/attr/attr_implements_fp.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %empty-directory(%t)
// RUN: echo 'main()' >%t/main.swift
// RUN: %target-build-swift -o %t/a.out %s %t/main.swift -Xfrontend -enable-operator-designated-types -Xfrontend -solver-enable-operator-designated-types
// RUN: %target-swiftc_driver -o %t/a.out %s %t/main.swift
// RUN: %target-codesign %t/a.out
// RUN: %target-run %t/a.out | %FileCheck %s
// REQUIRES: executable_test
Expand All @@ -10,33 +10,25 @@
// when only known to be comparable".

// Could calls to the different comparison operators.
public var comparedAsCauxmparablesCount : Int = 0
public var comparedAsComparablesCount : Int = 0
public var comparedAsFauxtsCount : Int = 0

infix operator .< : ComparisonPrecedence, BinaryFauxtingPoint, Cauxmparable

public protocol Cauxmparable {
static func .< (lhs: Self, rhs: Self) -> Bool
}

public protocol FauxtingPoint : Cauxmparable {
public protocol FauxtingPoint : Comparable {
static var nan: Self { get }
static var one: Self { get }
static var two: Self { get }
}

public protocol BinaryFauxtingPoint: FauxtingPoint {
@_nonoverride static func .< (lhs: Self, rhs: Self) -> Bool

var bitPattern: UInt8 { get }
}

public extension BinaryFauxtingPoint {
// This version of .< will be called in a context that only knows it has a Cauxmparable.
@_implements(Cauxmparable, .<(_:_:))
static func _CauxmparableLessThan(_ lhs: Fauxt, _ rhs: Fauxt) -> Bool {
print("compared as Cauxmparables")
comparedAsCauxmparablesCount += 1
// This version of < will be called in a context that only knows it has a Comparable.
@_implements(Comparable, <(_:_:))
static func _ComparableLessThan(_ lhs: Fauxt, _ rhs: Fauxt) -> Bool {
print("compared as Comparables")
comparedAsComparablesCount += 1
return lhs.bitPattern < rhs.bitPattern
}
}
Expand Down Expand Up @@ -78,11 +70,11 @@ extension Fauxt: BinaryFauxtingPoint {
}

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

public func compare_Cauxmparables<T:Cauxmparable>(_ x: T, _ y: T) -> Bool {
return x .< y
}

public func compare_FauxtingPoint<T:FauxtingPoint>(_ x: T, _ y: T) -> Bool {
return x .< y
}

public func compare_BinaryFauxtingPoint<T:BinaryFauxtingPoint>(_ x: T, _ y: T) -> Bool {
return x .< y
public func compare_Comparables<T:Comparable>(_ x: T, _ y: T) -> Bool {
return x < y
}

public func compare_Fauxts(_ x: Fauxt, _ y: Fauxt) -> Bool {
return x .< y
return x < y
}

public func main() {
assert(compare_Cauxmparables(Fauxt.one, Fauxt.two))
assert(comparedAsCauxmparablesCount == 1)
// CHECK: compared as Cauxmparables
assert(compare_Cauxmparables(Fauxt.one, Fauxt.nan))
assert(comparedAsCauxmparablesCount == 2)
// CHECK: compared as Cauxmparables
assert(!compare_Cauxmparables(Fauxt.nan, Fauxt.one))
assert(comparedAsCauxmparablesCount == 3)
// CHECK: compared as Cauxmparables

assert(compare_FauxtingPoint(Fauxt.one, Fauxt.two))
assert(comparedAsCauxmparablesCount == 4)
// CHECK: compared as Cauxmparables
assert(compare_FauxtingPoint(Fauxt.one, Fauxt.nan))
assert(comparedAsCauxmparablesCount == 5)
// CHECK: compared as Cauxmparables
assert(!compare_FauxtingPoint(Fauxt.nan, Fauxt.one))
assert(comparedAsCauxmparablesCount == 6)
// CHECK: compared as Cauxmparables
assert(compare_Comparables(Fauxt.one, Fauxt.two))
assert(comparedAsComparablesCount == 1)
// CHECK: compared as Comparables
assert(compare_Comparables(Fauxt.one, Fauxt.nan))
assert(comparedAsComparablesCount == 2)
// CHECK: compared as Comparables
assert(!compare_Comparables(Fauxt.nan, Fauxt.one))
assert(comparedAsComparablesCount == 3)
// CHECK: compared as Comparables

assert(compare_Fauxts(Fauxt.one, Fauxt.two))
assert(comparedAsFauxtsCount == 1)
Expand All @@ -139,15 +113,4 @@ public func main() {
assert(!compare_Fauxts(Fauxt.nan, Fauxt.one))
assert(comparedAsFauxtsCount == 3)
// CHECK: compared as Fauxts

assert(compare_BinaryFauxtingPoint(Fauxt.one, Fauxt.two))
assert(comparedAsFauxtsCount == 4)
// CHECK: compared as Fauxts
assert(!compare_BinaryFauxtingPoint(Fauxt.one, Fauxt.nan))
assert(comparedAsFauxtsCount == 5)
// CHECK: compared as Fauxts
assert(!compare_BinaryFauxtingPoint(Fauxt.nan, Fauxt.one))
assert(comparedAsFauxtsCount == 6)
// CHECK: compared as Fauxts

}
20 changes: 10 additions & 10 deletions test/attr/attr_implements_serial.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// RUN: %empty-directory(%t)
// RUN: echo 'client()' >%t/main.swift
// 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
// 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
// RUN: %target-build-swift -I %t -o %t/a.out %s %t/main.swift -L %t -Xlinker -rpath -Xlinker %t -lAttrImplFP
// RUN: %target-codesign %t/a.out
// RUN: %target-codesign %t/libAttrImplFP.%target-dylib-extension
Expand All @@ -13,15 +13,15 @@
import AttrImplFP

public func client() {
precondition(compare_Cauxmparables(Fauxt.one, Fauxt.two))
precondition(comparedAsCauxmparablesCount == 1)
// CHECK: compared as Cauxmparables
precondition(compare_Cauxmparables(Fauxt.one, Fauxt.nan))
precondition(comparedAsCauxmparablesCount == 2)
// CHECK: compared as Cauxmparables
precondition(!compare_Cauxmparables(Fauxt.nan, Fauxt.one))
precondition(comparedAsCauxmparablesCount == 3)
// CHECK: compared as Cauxmparables
precondition(compare_Comparables(Fauxt.one, Fauxt.two))
precondition(comparedAsComparablesCount == 1)
// CHECK: compared as Comparables
precondition(compare_Comparables(Fauxt.one, Fauxt.nan))
precondition(comparedAsComparablesCount == 2)
// CHECK: compared as Comparables
precondition(!compare_Comparables(Fauxt.nan, Fauxt.one))
precondition(comparedAsComparablesCount == 3)
// CHECK: compared as Comparables

precondition(compare_Fauxts(Fauxt.one, Fauxt.two))
precondition(comparedAsFauxtsCount == 1)
Expand Down