Skip to content

Commit e3f25d7

Browse files
committed
stdlib: make InlineArray work with the new vector_base_addr instruction
Don't unsafe-cast from the InlineArray struct itself, but from `_storage` which is the actual array buffer. This also requires making `_storage` a var.
1 parent f6ce61c commit e3f25d7

File tree

3 files changed

+16
-6
lines changed

3 files changed

+16
-6
lines changed

stdlib/public/core/InlineArray.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
@_addressableForDependencies
4747
public struct InlineArray<let count: Int, Element: ~Copyable>: ~Copyable {
4848
@usableFromInline
49-
internal let _storage: Builtin.FixedArray<count, Element>
49+
internal var _storage: Builtin.FixedArray<count, Element>
5050
}
5151

5252
@available(SwiftStdlib 6.2, *)
@@ -69,7 +69,7 @@ extension InlineArray where Element: ~Copyable {
6969
@_alwaysEmitIntoClient
7070
@_transparent
7171
internal var _address: UnsafePointer<Element> {
72-
unsafe UnsafePointer<Element>(Builtin.unprotectedAddressOfBorrow(self))
72+
unsafe UnsafePointer<Element>(Builtin.unprotectedAddressOfBorrow(_storage))
7373
}
7474

7575
/// Returns a buffer pointer over the entire array.
@@ -86,7 +86,7 @@ extension InlineArray where Element: ~Copyable {
8686
@_transparent
8787
internal var _mutableAddress: UnsafeMutablePointer<Element> {
8888
mutating get {
89-
unsafe UnsafeMutablePointer<Element>(Builtin.unprotectedAddressOf(&self))
89+
unsafe UnsafeMutablePointer<Element>(Builtin.unprotectedAddressOf(&_storage))
9090
}
9191
}
9292

@@ -147,7 +147,7 @@ extension InlineArray where Element: ~Copyable {
147147
@_alwaysEmitIntoClient
148148
public init<E: Error>(_ body: (Index) throws(E) -> Element) throws(E) {
149149
#if $BuiltinEmplaceTypedThrows
150-
self = try Builtin.emplace { (rawPtr) throws(E) -> () in
150+
_storage = try Builtin.emplace { (rawPtr) throws(E) -> () in
151151
let buffer = unsafe Self._initializationBuffer(start: rawPtr)
152152

153153
for i in 0 ..< count {
@@ -204,7 +204,7 @@ extension InlineArray where Element: ~Copyable {
204204
// and take the underlying value within the closure.
205205
var o: Element? = first
206206

207-
self = try Builtin.emplace { (rawPtr) throws(E) -> () in
207+
_storage = try Builtin.emplace { (rawPtr) throws(E) -> () in
208208
let buffer = unsafe Self._initializationBuffer(start: rawPtr)
209209

210210
guard Self.count > 0 else {
@@ -248,7 +248,7 @@ extension InlineArray where Element: Copyable {
248248
@_alwaysEmitIntoClient
249249
public init(repeating value: Element) {
250250
#if $ValueGenericsNameLookup
251-
self = Builtin.emplace {
251+
_storage = Builtin.emplace {
252252
let buffer = unsafe Self._initializationBuffer(start: $0)
253253

254254
unsafe buffer.initialize(repeating: value)

test/abi/macOS/arm64/stdlib.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,3 +1122,8 @@ Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$15.0$_$ss7Ra
11221122

11231123
// Duration.nanoseconds(_:)
11241124
Added: _$ss8DurationV11nanosecondsyABSdFZ
1125+
1126+
// var InlineArray._storage
1127+
Added: _$ss11InlineArrayVsRi__rlE8_storagexq_BVvM
1128+
Added: _$ss11InlineArrayVsRi__rlE8_storagexq_BVvs
1129+

test/abi/macOS/x86_64/stdlib.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,3 +1123,8 @@ Added: $ld$previous$@rpath/libswiftCompatibilitySpan.dylib$$1$10.14$15.0$_$ss7Ra
11231123

11241124
// Duration.nanoseconds(_:)
11251125
Added: _$ss8DurationV11nanosecondsyABSdFZ
1126+
1127+
// var InlineArray._storage
1128+
Added: _$ss11InlineArrayVsRi__rlE8_storagexq_BVvM
1129+
Added: _$ss11InlineArrayVsRi__rlE8_storagexq_BVvs
1130+

0 commit comments

Comments
 (0)