Skip to content

Commit 1fcb944

Browse files
authored
Merge pull request #79215 from eeckstein/add-arc-test
tests: add a test which checks that only a minimal ARC operations are generated
2 parents e22c09c + 9a7bcbe commit 1fcb944

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

test/SILOptimizer/optimal_arc.swift

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// RUN: %target-swift-frontend -module-name test -O -emit-sil -O -primary-file %s | %FileCheck %s
2+
3+
// REQUIRES: optimized_stdlib,swift_stdlib_no_asserts
4+
5+
// Check that there is only a single retain in concat.
6+
7+
// CHECK-LABEL: sil hidden @$s4test6concatyAA14TestCollectionVAD_ADtF :
8+
// CHECK: retain
9+
// CHECK-NOT: retain
10+
// CHECK-NOT: release
11+
// CHECK: apply
12+
// CHECK-NOT: retain
13+
// CHECK-NOT: release
14+
// CHECK: } // end sil function '$s4test6concatyAA14TestCollectionVAD_ADtF'
15+
func concat(_ l: TestCollection, _ r: TestCollection) -> TestCollection {
16+
l + r
17+
}
18+
19+
struct TestCollection: RandomAccessCollection, RangeReplaceableCollection {
20+
private var base: [Int]
21+
22+
init(base: [Int]) {
23+
self.base = base
24+
}
25+
26+
init() {
27+
self.base = []
28+
}
29+
30+
var startIndex: Int { base.startIndex }
31+
32+
var endIndex: Int { base.endIndex }
33+
34+
subscript(index: Int) -> Int {
35+
get {
36+
base[index]
37+
}
38+
set {
39+
base[index] = newValue
40+
}
41+
}
42+
43+
mutating func replaceSubrange<C>(_ range: Range<Int>, with newElements: C) where C: Collection, C.Element == Int {
44+
self.base.replaceSubrange(range, with: newElements)
45+
}
46+
47+
@inline(never)
48+
mutating func append<S>(contentsOf other: S) where S: Sequence, S.Element == Int {
49+
base.append(contentsOf: other)
50+
}
51+
}
52+
53+
54+

0 commit comments

Comments
 (0)