Skip to content

[swift-4.0-branch][stdlib] Removing < overloads #9343

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 3 commits into from
May 5, 2017
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
74 changes: 0 additions & 74 deletions stdlib/public/core/Integers.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -2640,80 +2640,6 @@ public struct ${Self}
return Bool(Builtin.cmp_${u}lt_Int${bits}(lhs._value, rhs._value))
}

// FIXME(integers): it should be possible to turn this into an optimizer pass
% if Self != 'Int':
@_transparent
public static func < (lhs: ${Self}, rhs: Int) -> Bool {
% if not signed:
if rhs < 0 { return false }
% end

% if bits < word_bits:
let lhs_ = Int(_truncatingBits: lhs._lowUWord)
return lhs_ < rhs
% elif bits == word_bits:
return Bool(Builtin.cmp_${u}lt_Int${bits}(lhs._value, rhs._value))
% else:
let rhs_ = ${Self}(_truncatingBits: rhs._lowUWord)
return lhs < rhs_
% end
}

@_transparent
public static func < (lhs: Int, rhs: ${Self}) -> Bool {
% if not signed:
if lhs < 0 { return true }
% end
% if bits < word_bits:
let rhs_ = Int(_truncatingBits: rhs._lowUWord)
return lhs < rhs_
% elif bits == word_bits:
return Bool(Builtin.cmp_${u}lt_Int${bits}(lhs._value, rhs._value))
% else:
let lhs_ = ${Self}(_truncatingBits: lhs._lowUWord)
return lhs_ < rhs
% end
}

% for Args in ['lhs: %s, rhs: Int' % Self, 'lhs: Int, rhs: %s' % Self]:
@_transparent
public static func > (${Args}) -> Bool {
return rhs < lhs
}

@_transparent
public static func <= (${Args}) -> Bool {
return !(rhs < lhs)
}

@_transparent
public static func >= (${Args}) -> Bool {
return !(lhs < rhs)
}

% end

% else: # if Self != 'Int'

// FIXME(integers): Comparable default implementations should really be
// chosen by the compiler. <rdar://problem/29340480>
@_transparent
public static func > (lhs: Int, rhs: Int) -> Bool {
return rhs < lhs
}

@_transparent
public static func <= (lhs: Int, rhs: Int) -> Bool {
return !(rhs < lhs)
}

@_transparent
public static func >= (lhs: Int, rhs: Int) -> Bool {
return !(lhs < rhs)
}

% end # if Self != 'Int'

// FIXME(integers): pending compiler improvements.
// Basically, most simple arithmetic expressions become too complex when `+`
// gets defined on the protocol rather than on concrete type.
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/StringComparable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ extension String {
}

extension String : Equatable {
@inline(__always)
public static func == (lhs: String, rhs: String) -> Bool {
#if _runtime(_ObjC)
// We only want to perform this optimization on objc runtimes. Elsewhere,
Expand Down
6 changes: 6 additions & 0 deletions test/stdlib/MixedTypeArithmeticsDiagnostics3.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ func mixedTypeArithemtics() {
x += (42 as Int)
}
}

func radar31909031() {
let x = UInt64()
let y = UInt64()
_ = (x - y) < UInt64(42) // should not produce a mixed-type warning
}
6 changes: 6 additions & 0 deletions test/stdlib/MixedTypeArithmeticsDiagnostics4.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,9 @@ func mixedTypeArithemtics() {
x += (42 as Int)
}
}

func radar31909031() {
let x = UInt64()
let y = UInt64()
_ = (x - y) < UInt64(42) // should not produce a mixed-type warning
}