Skip to content

Commit 302a875

Browse files
authored
Merge pull request #3885 from apple/stdlib-remove-sizeof
stdlib: SE-0101: remove old syntax
2 parents c77ecd3 + 833854f commit 302a875

File tree

3 files changed

+17
-39
lines changed

3 files changed

+17
-39
lines changed

stdlib/public/SDK/Foundation/Data.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
669669
public mutating func next() -> UInt8? {
670670
guard _idx < _endIdx else { return nil }
671671
defer { _idx += 1 }
672-
let bufferSize = sizeofValue(_buffer)
672+
let bufferSize = MemoryLayout._ofInstance(_buffer).size
673673
return withUnsafeMutablePointer(to: &_buffer) { ptr_ in
674674
let ptr = UnsafeMutableRawPointer(ptr_).assumingMemoryBound(to: UInt8.self)
675675
let bufferIdx = _idx % bufferSize

stdlib/public/core/Builtin.swift

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,56 +15,34 @@ import SwiftShims
1515
// Definitions that make elements of Builtin usable in real code
1616
// without gobs of boilerplate.
1717

18-
/// Returns the contiguous memory footprint of `T`.
19-
///
20-
/// Does not include any dynamically-allocated or "remote" storage.
21-
/// In particular, `sizeof(X.self)`, when `X` is a class type, is the
22-
/// same regardless of how many stored properties `X` has.
23-
@available(*, deprecated, message: "use MemoryLayout<T>.size instead.")
24-
@_transparent
18+
@available(*, unavailable, message: "use MemoryLayout<T>.size instead.")
2519
public func sizeof<T>(_:T.Type) -> Int {
26-
return Int(Builtin.sizeof(T.self))
20+
Builtin.unreachable()
2721
}
2822

29-
/// Returns the contiguous memory footprint of `T`.
30-
///
31-
/// Does not include any dynamically-allocated or "remote" storage.
32-
/// In particular, `sizeof(a)`, when `a` is a class instance, is the
33-
/// same regardless of how many stored properties `a` has.
34-
@available(*, deprecated, message: "use MemoryLayout<T>.size instead.")
35-
@_transparent
23+
@available(*, unavailable, message: "use MemoryLayout<T>.size instead.")
3624
public func sizeofValue<T>(_:T) -> Int {
37-
return sizeof(T.self)
25+
Builtin.unreachable()
3826
}
3927

40-
/// Returns the minimum memory alignment of `T`.
41-
@available(*, deprecated, message: "use MemoryLayout<T>.alignment instead.")
42-
@_transparent
28+
@available(*, unavailable, message: "use MemoryLayout<T>.alignment instead.")
4329
public func alignof<T>(_:T.Type) -> Int {
44-
return Int(Builtin.alignof(T.self))
30+
Builtin.unreachable()
4531
}
4632

47-
/// Returns the minimum memory alignment of `T`.
48-
@available(*, deprecated, message: "use MemoryLayout<T>.alignment instead.")
49-
@_transparent
33+
@available(*, unavailable, message: "use MemoryLayout<T>.alignment instead.")
5034
public func alignofValue<T>(_:T) -> Int {
51-
return alignof(T.self)
35+
Builtin.unreachable()
5236
}
5337

54-
/// Returns the least possible interval between distinct instances of
55-
/// `T` in memory. The result is always positive.
56-
@available(*, deprecated, message: "use MemoryLayout<T>.stride instead.")
57-
@_transparent
38+
@available(*, unavailable, message: "use MemoryLayout<T>.stride instead.")
5839
public func strideof<T>(_:T.Type) -> Int {
59-
return Int(Builtin.strideof_nonzero(T.self))
40+
Builtin.unreachable()
6041
}
6142

62-
/// Returns the least possible interval between distinct instances of
63-
/// `T` in memory. The result is always positive.
64-
@available(*, deprecated, message: "use MemoryLayout<T>.stride instead.")
65-
@_transparent
43+
@available(*, unavailable, message: "use MemoryLayout<T>.stride instead.")
6644
public func strideofValue<T>(_:T) -> Int {
67-
return strideof(T.self)
45+
Builtin.unreachable()
6846
}
6947

7048
// This function is the implementation of the `_roundUp` overload set. It is

validation-test/stdlib/CoreAudio.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@ CoreAudioTestSuite.test(
202202
CoreAudioTestSuite.test("UnsafeMutableAudioBufferListPointer.count") {
203203
let sizeInBytes = AudioBufferList.sizeInBytes(maximumBuffers: 16)
204204
let rawPtr = UnsafeMutableRawPointer.allocate(
205-
bytes: sizeInBytes, alignedTo: alignof(AudioBufferList.self))
205+
bytes: sizeInBytes, alignedTo: MemoryLayout<AudioBufferList>.alignment)
206206
let ablPtr = rawPtr.bindMemory(to: AudioBufferList.self,
207-
capacity: sizeInBytes / strideof(AudioBufferList.self))
207+
capacity: sizeInBytes / MemoryLayout<AudioBufferList>.stride)
208208

209209
// It is important that 'ablPtrWrapper' is a 'let'. We are verifying that
210210
// the 'count' property has a nonmutating setter.
@@ -219,7 +219,7 @@ CoreAudioTestSuite.test("UnsafeMutableAudioBufferListPointer.count") {
219219
expectEqual(0x7765_4321, rawPtr.load(as: UInt32.self))
220220

221221
rawPtr.deallocate(
222-
bytes: sizeInBytes, alignedTo: alignof(AudioBufferList.self))
222+
bytes: sizeInBytes, alignedTo: MemoryLayout<AudioBufferList>.alignment)
223223
}
224224

225225
CoreAudioTestSuite.test("UnsafeMutableAudioBufferListPointer.subscript(_: Int)") {
@@ -230,7 +230,7 @@ CoreAudioTestSuite.test("UnsafeMutableAudioBufferListPointer.subscript(_: Int)")
230230

231231
let ablPtr = rawPtr.bindMemory(
232232
to: AudioBufferList.self,
233-
capacity: sizeInBytes / sizeof(AudioBufferList.self))
233+
capacity: sizeInBytes / MemoryLayout<AudioBufferList>.stride)
234234

235235
// It is important that 'ablPtrWrapper' is a 'let'. We are verifying that
236236
// the subscript has a nonmutating setter.

0 commit comments

Comments
 (0)