Skip to content

stdlib: SE-0101: remove old syntax #3885

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stdlib/public/SDK/Foundation/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
public mutating func next() -> UInt8? {
guard _idx < _endIdx else { return nil }
defer { _idx += 1 }
let bufferSize = sizeofValue(_buffer)
let bufferSize = MemoryLayout._ofInstance(_buffer).size
return withUnsafeMutablePointer(to: &_buffer) { ptr_ in
let ptr = UnsafeMutableRawPointer(ptr_).assumingMemoryBound(to: UInt8.self)
let bufferIdx = _idx % bufferSize
Expand Down
46 changes: 12 additions & 34 deletions stdlib/public/core/Builtin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,56 +15,34 @@ import SwiftShims
// Definitions that make elements of Builtin usable in real code
// without gobs of boilerplate.

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

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

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

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

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

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

// This function is the implementation of the `_roundUp` overload set. It is
Expand Down
8 changes: 4 additions & 4 deletions validation-test/stdlib/CoreAudio.swift
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ CoreAudioTestSuite.test(
CoreAudioTestSuite.test("UnsafeMutableAudioBufferListPointer.count") {
let sizeInBytes = AudioBufferList.sizeInBytes(maximumBuffers: 16)
let rawPtr = UnsafeMutableRawPointer.allocate(
bytes: sizeInBytes, alignedTo: alignof(AudioBufferList.self))
bytes: sizeInBytes, alignedTo: MemoryLayout<AudioBufferList>.alignment)
let ablPtr = rawPtr.bindMemory(to: AudioBufferList.self,
capacity: sizeInBytes / strideof(AudioBufferList.self))
capacity: sizeInBytes / MemoryLayout<AudioBufferList>.stride)

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

rawPtr.deallocate(
bytes: sizeInBytes, alignedTo: alignof(AudioBufferList.self))
bytes: sizeInBytes, alignedTo: MemoryLayout<AudioBufferList>.alignment)
}

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

let ablPtr = rawPtr.bindMemory(
to: AudioBufferList.self,
capacity: sizeInBytes / sizeof(AudioBufferList.self))
capacity: sizeInBytes / MemoryLayout<AudioBufferList>.stride)

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