Skip to content

Commit ff3cf98

Browse files
committed
[stdlib] ClosedRange.contains: Leave this force-inlined, not transparent
Making it transparent evidently induces new retain/release traffic in Array’s subscript, even though I can find no indication that `ClosedRange.contains` is ever called by that code path. Oh well.
1 parent 487baca commit ff3cf98

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

stdlib/public/core/ClosedRange.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ extension ClosedRange: RangeExpression {
128128
/// - Parameter element: The element to check for containment.
129129
/// - Returns: `true` if `element` is contained in the range; otherwise,
130130
/// `false`.
131-
@_transparent
131+
@inlinable
132+
@inline(__always)
132133
public func contains(_ element: Bound) -> Bool {
133134
return element >= self.lowerBound && element <= self.upperBound
134135
}

stdlib/public/core/Range.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ extension Range {
10801080
other.isEmpty ||
10811081
(lowerBound <= other.lowerBound && upperBound >= other.upperBound)
10821082
}
1083-
1083+
10841084
/// Returns a Boolean value indicating whether the given closed range is
10851085
/// contained within this range.
10861086
///

test/stdlib/RangeContainsInlining.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
// RUN: %target-swift-emit-ir -primary-file %s -O 2>&1 | %FileCheck --check-prefixes CHECK,CHECK-OPTIMIZED %s
33
// 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` over a
6-
// `Range` instance to result in direct bound comparisons in all compilation
7-
// modes, including unoptimized builds. (These are often used to implement
8-
// bounds checking.)
5+
// We expect calls to `Range.contains` to result in direct bound comparisons in
6+
// all compilation modes, including unoptimized builds. (These are often used to
7+
// implement bounds checking.)
98
//
109
// The sample functions below use bounds of different integer types to avoid
1110
// them tail-calling each other.
@@ -19,11 +18,14 @@ public func halfOpenContains(_ r: Range<Int8>, _ i: Int8) -> Bool {
1918
r.contains(i)
2019
}
2120

22-
// CHECK-LABEL: define {{.*}} i1 @"$s21RangeContainsInlining06closedB0ySbSNys5Int16VG_ADtF"
23-
// CHECK-NOT: call swiftcc
24-
// CHECK: icmp
25-
// CHECK-NOT: call swiftcc
26-
// CHECK-LABEL: {{^}}}
21+
// `ClosedRange.contains is only marked `@inline(__always)`; unfortunately it
22+
// doesn't get inlined in deug builds.
23+
24+
// CHECK-OPTIMIZED-LABEL: define {{.*}} i1 @"$s21RangeContainsInlining06closedB0ySbSNys5Int16VG_ADtF"
25+
// CHECK-OPTIMIZED-NOT: call swiftcc
26+
// CHECK-OPTIMIZED: icmp
27+
// CHECK-OPTIMIZED-NOT: call swiftcc
28+
// CHECK-OPTIMIZED-LABEL: {{^}}}
2729
public func closedContains(_ r: ClosedRange<Int16>, _ i: Int16) -> Bool {
2830
r.contains(i)
2931
}

0 commit comments

Comments
 (0)