mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Use the new builtins for COW representation in Array, ContiguousArray and ArraySlice. The basic idea is to strictly separate code which mutates an array buffer from code which reads from an array. The concept is explained in more detail in docs/SIL.rst, section "Copy-on-Write Representation". The main change is to use beginCOWMutation() instead of isUniquelyReferenced() and insert endCOWMutation() at the end of all mutating functions. Also, reading from the array buffer must be done differently, depending on if the buffer is in a mutable or immutable state. All the required invariants are enforced by runtime checks - but only in an assert-build of the library: a bit in the buffer object side-table indicates if the buffer is mutable or not. Along with the library changes, also two optimizations needed to be updated: COWArrayOpt and ObjectOutliner.
28 lines
691 B
Plaintext
28 lines
691 B
Plaintext
// RUN: %target-sil-opt -enable-sil-verify-all %s -object-outliner | %FileCheck %s
|
|
|
|
|
|
import Builtin
|
|
import Swift
|
|
class B { }
|
|
class E : B { }
|
|
|
|
// CHECK: sil @patatino : $@convention(thin) () -> () {
|
|
// CHECK: bb0:
|
|
// CHECK-NEXT: integer_literal
|
|
// CHECK-NEXT: global_value @patatinoTv_ : $B
|
|
// CHECK-NEXT: strong_retain
|
|
// CHECK-NEXT: strong_release
|
|
// CHECK-NEXT: tuple ()
|
|
// CHECK-NEXT: return
|
|
// CHECK-NEXT: }
|
|
|
|
sil @patatino : $@convention(thin) () -> () {
|
|
%0 = integer_literal $Builtin.Word, 0
|
|
%1 = alloc_ref [tail_elems $Int64 * %0 : $Builtin.Word] $B
|
|
%2 = end_cow_mutation %1 : $B
|
|
set_deallocating %2 : $B
|
|
dealloc_ref %2 : $B
|
|
%45 = tuple ()
|
|
return %45 : $()
|
|
}
|