Files
swift-mirror/test/SILOptimizer/optimal_arc.swift
Erik Eckstein 9a7bcbe2c9 tests: add a test which checks that only a minimal ARC operations are generated
This is the case for the test since we enabled OSSA modules.
rdar://143691773
2025-02-07 17:07:18 +01:00

55 lines
1.3 KiB
Swift

// RUN: %target-swift-frontend -module-name test -O -emit-sil -O -primary-file %s | %FileCheck %s
// REQUIRES: optimized_stdlib,swift_stdlib_no_asserts
// Check that there is only a single retain in concat.
// CHECK-LABEL: sil hidden @$s4test6concatyAA14TestCollectionVAD_ADtF :
// CHECK: retain
// CHECK-NOT: retain
// CHECK-NOT: release
// CHECK: apply
// CHECK-NOT: retain
// CHECK-NOT: release
// CHECK: } // end sil function '$s4test6concatyAA14TestCollectionVAD_ADtF'
func concat(_ l: TestCollection, _ r: TestCollection) -> TestCollection {
l + r
}
struct TestCollection: RandomAccessCollection, RangeReplaceableCollection {
private var base: [Int]
init(base: [Int]) {
self.base = base
}
init() {
self.base = []
}
var startIndex: Int { base.startIndex }
var endIndex: Int { base.endIndex }
subscript(index: Int) -> Int {
get {
base[index]
}
set {
base[index] = newValue
}
}
mutating func replaceSubrange<C>(_ range: Range<Int>, with newElements: C) where C: Collection, C.Element == Int {
self.base.replaceSubrange(range, with: newElements)
}
@inline(never)
mutating func append<S>(contentsOf other: S) where S: Sequence, S.Element == Int {
base.append(contentsOf: other)
}
}