mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Find all the usages of `--enable-experimental-feature` or `--enable-upcoming-feature` in the tests and replace some of the `REQUIRES: asserts` to use `REQUIRES: swift-feature-Foo` instead, which should correctly apply to depending on the asserts/noasserts mode of the toolchain for each feature. Remove some comments that talked about enabling asserts since they don't apply anymore (but I might had miss some). All this was done with an automated script, so some formatting weirdness might happen, but I hope I fixed most of those. There might be some tests that were `REQUIRES: asserts` that might run in `noasserts` toolchains now. This will normally be because their feature went from experimental to upcoming/base and the tests were not updated.
112 lines
2.2 KiB
Swift
112 lines
2.2 KiB
Swift
// RUN: %target-run-stdlib-swift(-O -enable-experimental-feature MoveOnly)
|
|
|
|
// REQUIRES: executable_test
|
|
// REQUIRES: swift_feature_MoveOnly
|
|
|
|
import Swift
|
|
import StdlibUnittest
|
|
|
|
public class Klass {}
|
|
|
|
var tests = TestSuite("move_function_uniqueness")
|
|
defer {
|
|
runAllTests()
|
|
}
|
|
|
|
public enum Enum {
|
|
case foo
|
|
}
|
|
|
|
public class K2 {
|
|
var array: [Enum] = Array(repeating: .foo, count: 10_000)
|
|
|
|
subscript(index: Int) -> Enum {
|
|
@inline(never)
|
|
get {
|
|
array[index]
|
|
}
|
|
@inline(never)
|
|
set {
|
|
array[index] = newValue
|
|
}
|
|
@inline(never)
|
|
_modify {
|
|
yield &array[index]
|
|
}
|
|
}
|
|
}
|
|
|
|
public class Class {
|
|
var k2 = K2()
|
|
var array: [Enum] = Array(repeating: .foo, count: 10_000)
|
|
}
|
|
|
|
extension Class {
|
|
@inline(never)
|
|
func readClassSwitchLetTest(_ userHandle: Int) {
|
|
expectTrue(_isUnique(&self.k2))
|
|
|
|
let x: K2
|
|
do {
|
|
x = self.k2
|
|
}
|
|
switch (consume x)[userHandle] {
|
|
case .foo:
|
|
expectTrue(_isUnique(&self.k2))
|
|
}
|
|
}
|
|
}
|
|
|
|
tests.test("readClassSwitchLetTest") {
|
|
let c = Class()
|
|
for f in 0..<10_000 {
|
|
c.readClassSwitchLetTest(f)
|
|
}
|
|
}
|
|
|
|
extension Class {
|
|
@inline(never)
|
|
func readArraySwitchLetTest(_ userHandle: Int) {
|
|
expectTrue(self.array._buffer.isUniquelyReferenced())
|
|
|
|
let x: [Enum]
|
|
do {
|
|
x = self.array
|
|
}
|
|
switch (x)[userHandle] {
|
|
case .foo:
|
|
expectTrue(self.array._buffer.isUniquelyReferenced())
|
|
}
|
|
}
|
|
}
|
|
|
|
tests.test("readArraySwitchLetTest") {
|
|
let c = Class()
|
|
for f in 0..<10_000 {
|
|
c.readArraySwitchLetTest(f)
|
|
}
|
|
}
|
|
|
|
tests.test("simpleVarTest") {
|
|
var x = Klass()
|
|
expectTrue(_isUnique_native(&x))
|
|
|
|
var y = x
|
|
let _ = consume y
|
|
expectTrue(_isUnique_native(&x))
|
|
y = Klass()
|
|
expectTrue(_isUnique_native(&x))
|
|
}
|
|
|
|
tests.test("simpleInoutVarTest") {
|
|
func inOutTest(_ x: inout Klass) {
|
|
var y = x
|
|
let _ = consume y
|
|
expectTrue(_isUnique_native(&x))
|
|
y = Klass()
|
|
expectTrue(_isUnique_native(&x))
|
|
}
|
|
var outerX = Klass()
|
|
inOutTest(&outerX)
|
|
}
|