Skip to content

Commit 487baca

Browse files
committed
[stdlib] Delete transparent ~= overload; mark the regular one always-inlined instead
The new overload messes up diagnostics too much.
1 parent a6ae23d commit 487baca

File tree

2 files changed

+14
-38
lines changed

2 files changed

+14
-38
lines changed

stdlib/public/core/Range.swift

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -94,39 +94,12 @@ extension RangeExpression {
9494
/// - pattern: A range.
9595
/// - bound: A value to match against `pattern`.
9696
@inlinable
97+
@inline(__always)
9798
public static func ~= (pattern: Self, value: Bound) -> Bool {
9899
return pattern.contains(value)
99100
}
100101
}
101102

102-
extension Range {
103-
/// Returns a Boolean value indicating whether a value is included in a
104-
/// range.
105-
///
106-
/// You can use the pattern-matching operator (`~=`) to test whether a value
107-
/// is included in a range. The pattern-matching operator is used
108-
/// internally in `case` statements for pattern matching. The following
109-
/// example uses the `~=` operator to test whether an integer is included in
110-
/// a range of single-digit numbers:
111-
///
112-
/// let chosenNumber = 3
113-
/// if 0..<10 ~= chosenNumber {
114-
/// print("\(chosenNumber) is a single digit.")
115-
/// }
116-
/// // Prints "3 is a single digit."
117-
///
118-
/// - Parameters:
119-
/// - pattern: A range.
120-
/// - bound: A value to match against `pattern`.
121-
@_transparent
122-
public static func ~= (pattern: Self, value: Bound) -> Bool {
123-
// Note: `Range.~=` is used particularly frequently to implement bounds
124-
// checks. This more specific variant of the generic `=~` is intended to
125-
// help improve unoptimized performance of these cases.
126-
pattern.contains(value)
127-
}
128-
}
129-
130103
/// A half-open interval from a lower bound up to, but not including, an upper
131104
/// bound.
132105
///
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
// RUN: %target-swift-emit-ir -primary-file %s 2>&1 | %FileCheck %s
2-
// RUN: %target-swift-emit-ir -primary-file %s -O 2>&1 | %FileCheck %s
3-
// RUN: %target-swift-emit-ir -primary-file %s -Osize 2>&1 | %FileCheck %s
2+
// RUN: %target-swift-emit-ir -primary-file %s -O 2>&1 | %FileCheck --check-prefixes CHECK,CHECK-OPTIMIZED %s
3+
// RUN: %target-swift-emit-ir -primary-file %s -Osize 2>&1 | %FileCheck --check-prefixes CHECK,CHECK-OPTIMIZED %s
44

5-
// We expect calls to `Range.contains`, `ClosedRange.contains` and `~=` over a
5+
// We expect calls to `Range.contains`, `ClosedRange.contains` over a
66
// `Range` instance to result in direct bound comparisons in all compilation
77
// modes, including unoptimized builds. (These are often used to implement
88
// bounds checking.)
99
//
1010
// The sample functions below use bounds of different integer types to avoid
1111
// them tail-calling each other.
1212

13-
// CHECK-LABEL: define swiftcc i1 @"$s21RangeContainsInlining08halfOpenB0ySbSnys4Int8VG_ADtF"
13+
// CHECK-LABEL: define {{.*}} i1 @"$s21RangeContainsInlining08halfOpenB0ySbSnys4Int8VG_ADtF"
1414
// CHECK-NOT: call swiftcc
1515
// CHECK: icmp
1616
// CHECK-NOT: call swiftcc
@@ -19,7 +19,7 @@ public func halfOpenContains(_ r: Range<Int8>, _ i: Int8) -> Bool {
1919
r.contains(i)
2020
}
2121

22-
// CHECK-LABEL: define swiftcc i1 @"$s21RangeContainsInlining06closedB0ySbSNys5Int16VG_ADtF"
22+
// CHECK-LABEL: define {{.*}} i1 @"$s21RangeContainsInlining06closedB0ySbSNys5Int16VG_ADtF"
2323
// CHECK-NOT: call swiftcc
2424
// CHECK: icmp
2525
// CHECK-NOT: call swiftcc
@@ -28,11 +28,14 @@ public func closedContains(_ r: ClosedRange<Int16>, _ i: Int16) -> Bool {
2828
r.contains(i)
2929
}
3030

31-
// CHECK-LABEL: define swiftcc i1 @"$s21RangeContainsInlining20halfOpenPatternMatchySbSnys5Int32VG_ADtF"
32-
// CHECK-NOT: call swiftcc
33-
// CHECK: icmp
34-
// CHECK-NOT: call swiftcc
35-
// CHECK-LABEL: {{^}}}
31+
// `Range.~=` is only marked `@inline(__always)`; unfortunately it doesn't get
32+
// inlined in deug builds.
33+
34+
// CHECK-OPTIMIZED-LABEL: define {{.*}} i1 @"$s21RangeContainsInlining20halfOpenPatternMatchySbSnys5Int32VG_ADtF"
35+
// CHECK-OPTIMIZED-NOT: call swiftcc
36+
// CHECK-OPTIMIZED: icmp
37+
// CHECK-OPTIMIZED-NOT: call swiftcc
38+
// CHECK-OPTIMIZED-LABEL: {{^}}}
3639
public func halfOpenPatternMatch(_ r: Range<Int32>, _ i: Int32) -> Bool {
3740
r ~= i
3841
}

0 commit comments

Comments
 (0)