Files
swift-mirror/stdlib/private/StdlibUnittest/OpaqueIdentityFunctions.swift
Dave Abrahams 64a5165ecf stdlib: deinitializePointee(_) => deinitialize()
Tacking "Pointee" on just for unary operations (and especially
operations with an optional count) created inconsistency.
2016-02-23 15:34:20 -08:00

83 lines
2.4 KiB
Swift

//===--- OpaqueIdentityFunctions.swift ------------------------------------===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2016 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See http://swift.org/LICENSE.txt for license information
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
@_silgen_name("swift_stdlib_getPointer")
func _stdlib_getPointer(x: OpaquePointer) -> OpaquePointer
public func _opaqueIdentity<T>(x: T) -> T {
let ptr = UnsafeMutablePointer<T>(allocatingCapacity: 1)
ptr.initialize(with: x)
let result =
UnsafeMutablePointer<T>(_stdlib_getPointer(OpaquePointer(ptr))).pointee
ptr.deinitialize()
ptr.deallocateCapacity(1)
return result
}
func _blackHolePtr<T>(x: UnsafePointer<T>) {
_stdlib_getPointer(OpaquePointer(x))
}
public func _blackHole<T>(x: T) {
var x = x
_blackHolePtr(&x)
}
@inline(never)
public func getBool(x: Bool) -> Bool { return _opaqueIdentity(x) }
@inline(never)
public func getInt8(x: Int8) -> Int8 { return _opaqueIdentity(x) }
@inline(never)
public func getInt16(x: Int16) -> Int16 { return _opaqueIdentity(x) }
@inline(never)
public func getInt32(x: Int32) -> Int32 { return _opaqueIdentity(x) }
@inline(never)
public func getInt64(x: Int64) -> Int64 { return _opaqueIdentity(x) }
@inline(never)
public func getInt(x: Int) -> Int { return _opaqueIdentity(x) }
@inline(never)
public func getUInt8(x: UInt8) -> UInt8 { return _opaqueIdentity(x) }
@inline(never)
public func getUInt16(x: UInt16) -> UInt16 { return _opaqueIdentity(x) }
@inline(never)
public func getUInt32(x: UInt32) -> UInt32 { return _opaqueIdentity(x) }
@inline(never)
public func getUInt64(x: UInt64) -> UInt64 { return _opaqueIdentity(x) }
@inline(never)
public func getUInt(x: UInt) -> UInt { return _opaqueIdentity(x) }
@inline(never)
public func getFloat32(x: Float32) -> Float32 { return _opaqueIdentity(x) }
@inline(never)
public func getFloat64(x: Float64) -> Float64 { return _opaqueIdentity(x) }
#if arch(i386) || arch(x86_64)
@inline(never)
public func getFloat80(x: Float80) -> Float80 { return _opaqueIdentity(x) }
#endif
public func getPointer(x: OpaquePointer) -> OpaquePointer {
return _opaqueIdentity(x)
}