mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Strict memory safety] Update standard library for unsafe treated as a call effect
This commit is contained in:
@@ -162,7 +162,7 @@ public struct CheckedContinuation<T, E: Error>: Sendable {
|
||||
/// the caller. The task continues executing when its executor is
|
||||
/// able to reschedule it.
|
||||
public func resume(returning value: sending T) {
|
||||
if let c: UnsafeContinuation<T, E> = unsafe canary.takeContinuation() {
|
||||
if let c: UnsafeContinuation<T, E> = canary.takeContinuation() {
|
||||
unsafe c.resume(returning: value)
|
||||
} else {
|
||||
#if !$Embedded
|
||||
@@ -186,7 +186,7 @@ public struct CheckedContinuation<T, E: Error>: Sendable {
|
||||
/// the caller. The task continues executing when its executor is
|
||||
/// able to reschedule it.
|
||||
public func resume(throwing error: __owned E) {
|
||||
if let c: UnsafeContinuation<T, E> = unsafe canary.takeContinuation() {
|
||||
if let c: UnsafeContinuation<T, E> = canary.takeContinuation() {
|
||||
unsafe c.resume(throwing: error)
|
||||
} else {
|
||||
#if !$Embedded
|
||||
|
||||
@@ -886,7 +886,7 @@ internal func _task_serialExecutor_getExecutorRef<E>(_ executor: E) -> Builtin.E
|
||||
@_silgen_name("_task_taskExecutor_getTaskExecutorRef")
|
||||
internal func _task_taskExecutor_getTaskExecutorRef<E>(_ taskExecutor: E) -> Builtin.Executor
|
||||
where E: TaskExecutor {
|
||||
return unsafe taskExecutor.asUnownedTaskExecutor().executor
|
||||
return taskExecutor.asUnownedTaskExecutor().executor
|
||||
}
|
||||
|
||||
// Used by the concurrency runtime
|
||||
|
||||
@@ -324,7 +324,7 @@ public struct ExecutorJob: Sendable, ~Copyable {
|
||||
/// Returns the result of executing the closure.
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
public func withUnsafeExecutorPrivateData<R, E>(body: (UnsafeMutableRawBufferPointer) throws(E) -> R) throws(E) -> R {
|
||||
let base = unsafe _jobGetExecutorPrivateData(self.context)
|
||||
let base = _jobGetExecutorPrivateData(self.context)
|
||||
let size = unsafe 2 * MemoryLayout<OpaquePointer>.stride
|
||||
return unsafe try body(UnsafeMutableRawBufferPointer(start: base,
|
||||
count: size))
|
||||
@@ -476,13 +476,13 @@ extension ExecutorJob {
|
||||
|
||||
/// Allocate a specified number of bytes of uninitialized memory.
|
||||
public func allocate(capacity: Int) -> UnsafeMutableRawBufferPointer {
|
||||
let base = unsafe _jobAllocate(context, capacity)
|
||||
let base = _jobAllocate(context, capacity)
|
||||
return unsafe UnsafeMutableRawBufferPointer(start: base, count: capacity)
|
||||
}
|
||||
|
||||
/// Allocate uninitialized memory for a single instance of type `T`.
|
||||
public func allocate<T>(as type: T.Type) -> UnsafeMutablePointer<T> {
|
||||
let base = unsafe _jobAllocate(context, MemoryLayout<T>.size)
|
||||
let base = _jobAllocate(context, MemoryLayout<T>.size)
|
||||
return unsafe base.bindMemory(to: type, capacity: 1)
|
||||
}
|
||||
|
||||
@@ -490,7 +490,7 @@ extension ExecutorJob {
|
||||
/// instances of type `T`.
|
||||
public func allocate<T>(capacity: Int, as type: T.Type)
|
||||
-> UnsafeMutableBufferPointer<T> {
|
||||
let base = unsafe _jobAllocate(context, MemoryLayout<T>.stride * capacity)
|
||||
let base = _jobAllocate(context, MemoryLayout<T>.stride * capacity)
|
||||
let typedBase = unsafe base.bindMemory(to: T.self, capacity: capacity)
|
||||
return unsafe UnsafeMutableBufferPointer<T>(start: typedBase, count: capacity)
|
||||
}
|
||||
|
||||
@@ -125,7 +125,7 @@ func __withTaskPriorityEscalationHandler0<T, E>(
|
||||
onPriorityEscalated handler0: @Sendable (UInt8, UInt8) -> Void,
|
||||
isolation: isolated (any Actor)? = #isolation
|
||||
) async throws(E) -> T {
|
||||
let record = unsafe _taskAddPriorityEscalationHandler(handler: handler0)
|
||||
let record = _taskAddPriorityEscalationHandler(handler: handler0)
|
||||
defer { unsafe _taskRemovePriorityEscalationHandler(record: record) }
|
||||
|
||||
return try await operation()
|
||||
|
||||
@@ -146,9 +146,9 @@ public func withTaskExecutorPreference<T, Failure>(
|
||||
}
|
||||
|
||||
let taskExecutorBuiltin: Builtin.Executor =
|
||||
unsafe taskExecutor.asUnownedTaskExecutor().executor
|
||||
taskExecutor.asUnownedTaskExecutor().executor
|
||||
|
||||
let record = unsafe _pushTaskExecutorPreference(taskExecutorBuiltin)
|
||||
let record = _pushTaskExecutorPreference(taskExecutorBuiltin)
|
||||
defer {
|
||||
unsafe _popTaskExecutorPreference(record: record)
|
||||
}
|
||||
@@ -177,9 +177,9 @@ public func _unsafeInheritExecutor_withTaskExecutorPreference<T: Sendable>(
|
||||
}
|
||||
|
||||
let taskExecutorBuiltin: Builtin.Executor =
|
||||
unsafe taskExecutor.asUnownedTaskExecutor().executor
|
||||
taskExecutor.asUnownedTaskExecutor().executor
|
||||
|
||||
let record = unsafe _pushTaskExecutorPreference(taskExecutorBuiltin)
|
||||
let record = _pushTaskExecutorPreference(taskExecutorBuiltin)
|
||||
defer {
|
||||
unsafe _popTaskExecutorPreference(record: record)
|
||||
}
|
||||
|
||||
@@ -1301,7 +1301,7 @@ extension Task where Success == Never, Failure == Never {
|
||||
@available(SwiftStdlib 5.1, *)
|
||||
public func withUnsafeCurrentTask<T>(body: (UnsafeCurrentTask?) throws -> T) rethrows -> T {
|
||||
guard let _task = _getCurrentAsyncTask() else {
|
||||
return try unsafe body(nil)
|
||||
return try body(nil)
|
||||
}
|
||||
|
||||
// FIXME: This retain seems pretty wrong, however if we don't we WILL crash
|
||||
@@ -1315,7 +1315,7 @@ public func withUnsafeCurrentTask<T>(body: (UnsafeCurrentTask?) throws -> T) ret
|
||||
@available(SwiftStdlib 6.0, *)
|
||||
public func withUnsafeCurrentTask<T>(body: (UnsafeCurrentTask?) async throws -> T) async rethrows -> T {
|
||||
guard let _task = _getCurrentAsyncTask() else {
|
||||
return try unsafe await body(nil)
|
||||
return try await body(nil)
|
||||
}
|
||||
|
||||
// FIXME: This retain seems pretty wrong, however if we don't we WILL crash
|
||||
@@ -1601,7 +1601,7 @@ internal func _getCurrentTaskName() -> UnsafePointer<UInt8>?
|
||||
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
internal func _getCurrentTaskNameString() -> String? {
|
||||
if let stringPtr = unsafe _getCurrentTaskName() {
|
||||
if let stringPtr = _getCurrentTaskName() {
|
||||
unsafe String(cString: stringPtr)
|
||||
} else {
|
||||
nil
|
||||
|
||||
@@ -77,7 +77,7 @@ public func withTaskCancellationHandler<T>(
|
||||
) async rethrows -> T {
|
||||
// unconditionally add the cancellation record to the task.
|
||||
// if the task was already cancelled, it will be executed right away.
|
||||
let record = unsafe _taskAddCancellationHandler(handler: handler)
|
||||
let record = _taskAddCancellationHandler(handler: handler)
|
||||
defer { unsafe _taskRemoveCancellationHandler(record: record) }
|
||||
|
||||
return try await operation()
|
||||
@@ -98,7 +98,7 @@ public func _unsafeInheritExecutor_withTaskCancellationHandler<T>(
|
||||
) async rethrows -> T {
|
||||
// unconditionally add the cancellation record to the task.
|
||||
// if the task was already cancelled, it will be executed right away.
|
||||
let record = unsafe _taskAddCancellationHandler(handler: handler)
|
||||
let record = _taskAddCancellationHandler(handler: handler)
|
||||
defer { unsafe _taskRemoveCancellationHandler(record: record) }
|
||||
|
||||
return try await operation()
|
||||
|
||||
@@ -178,7 +178,7 @@ public final class TaskLocal<Value: Sendable>: Sendable, CustomStringConvertible
|
||||
/// or if the task-local has no value bound, this will return the `defaultValue`
|
||||
/// of the task local.
|
||||
public func get() -> Value {
|
||||
guard let rawValue = unsafe _taskLocalValueGet(key: key) else {
|
||||
guard let rawValue = _taskLocalValueGet(key: key) else {
|
||||
return self.defaultValue
|
||||
}
|
||||
|
||||
|
||||
@@ -549,7 +549,7 @@ extension DistributedActorSystem {
|
||||
errorCode: .typeDeserializationFailure)
|
||||
}
|
||||
|
||||
guard let resultBuffer = _openExistential(returnTypeFromTypeInfo, do: unsafe doAllocateReturnTypeBuffer) else {
|
||||
guard let resultBuffer = _openExistential(returnTypeFromTypeInfo, do: doAllocateReturnTypeBuffer) else {
|
||||
throw ExecuteDistributedTargetError(
|
||||
message: "Failed to allocate buffer for distributed target return type",
|
||||
errorCode: .typeDeserializationFailure)
|
||||
|
||||
@@ -951,6 +951,7 @@ extension Array: RangeReplaceableCollection {
|
||||
/// Entry point for `Array` literal construction; builds and returns
|
||||
/// an Array of `count` uninitialized elements.
|
||||
@inlinable
|
||||
@unsafe
|
||||
@_semantics("array.uninitialized")
|
||||
internal static func _allocateUninitialized(
|
||||
_ count: Int
|
||||
@@ -966,6 +967,7 @@ extension Array: RangeReplaceableCollection {
|
||||
///
|
||||
/// - Precondition: `storage is _ContiguousArrayStorage`.
|
||||
@inlinable
|
||||
@unsafe
|
||||
@_semantics("array.uninitialized")
|
||||
@_effects(escaping storage => return.0.value**)
|
||||
@_effects(escaping storage.class*.value** => return.0.value**.class*.value**)
|
||||
|
||||
@@ -73,7 +73,7 @@ internal struct _CocoaArrayWrapper: RandomAccessCollection {
|
||||
}
|
||||
|
||||
// Look for contiguous storage in the NSArray
|
||||
let cocoaStorageBaseAddress = unsafe self.contiguousStorage(self.indices)
|
||||
let cocoaStorageBaseAddress = self.contiguousStorage(self.indices)
|
||||
|
||||
if let cocoaStorageBaseAddress = unsafe cocoaStorageBaseAddress {
|
||||
return unsafe _SliceBuffer(
|
||||
@@ -113,7 +113,7 @@ internal struct _CocoaArrayWrapper: RandomAccessCollection {
|
||||
) -> UnsafeMutablePointer<AnyObject>?
|
||||
{
|
||||
_internalInvariant(!subRange.isEmpty)
|
||||
var enumerationState = unsafe _makeSwiftNSFastEnumerationState()
|
||||
var enumerationState = _makeSwiftNSFastEnumerationState()
|
||||
|
||||
// This function currently returns nil unless the first
|
||||
// subRange.upperBound items are stored contiguously. This is an
|
||||
|
||||
@@ -190,13 +190,13 @@ internal final class _ContiguousArrayStorage<
|
||||
@objc(objectAtIndexedSubscript:)
|
||||
@_effects(readonly)
|
||||
final override internal func objectAtSubscript(_ index: Int) -> Unmanaged<AnyObject> {
|
||||
return unsafe _objectAt(index)
|
||||
return _objectAt(index)
|
||||
}
|
||||
|
||||
@objc(objectAtIndex:)
|
||||
@_effects(readonly)
|
||||
final override internal func objectAt(_ index: Int) -> Unmanaged<AnyObject> {
|
||||
return unsafe _objectAt(index)
|
||||
return _objectAt(index)
|
||||
}
|
||||
|
||||
@objc internal override final var count: Int {
|
||||
|
||||
@@ -315,8 +315,8 @@ final internal class _SwiftDeferredNSDictionary<Key: Hashable, Value>
|
||||
) {
|
||||
_precondition(count >= 0, "Invalid count")
|
||||
guard count > 0 else { return }
|
||||
let bridgedKeys = unsafe bridgeKeys()
|
||||
let bridgedValues = unsafe bridgeValues()
|
||||
let bridgedKeys = bridgeKeys()
|
||||
let bridgedValues = bridgeValues()
|
||||
var i = 0 // Current position in the output buffers
|
||||
|
||||
defer { _fixLifetime(self) }
|
||||
@@ -355,8 +355,8 @@ final internal class _SwiftDeferredNSDictionary<Key: Hashable, Value>
|
||||
Unmanaged<AnyObject>,
|
||||
UnsafeMutablePointer<UInt8>
|
||||
) -> Void) {
|
||||
let bridgedKeys = unsafe bridgeKeys()
|
||||
let bridgedValues = unsafe bridgeValues()
|
||||
let bridgedKeys = bridgeKeys()
|
||||
let bridgedValues = bridgeValues()
|
||||
|
||||
defer { _fixLifetime(self) }
|
||||
|
||||
@@ -409,7 +409,7 @@ final internal class _SwiftDeferredNSDictionary<Key: Hashable, Value>
|
||||
var stored = 0
|
||||
|
||||
// Only need to bridge once, so we can hoist it out of the loop.
|
||||
let bridgedKeys = unsafe bridgeKeys()
|
||||
let bridgedKeys = bridgeKeys()
|
||||
for i in 0..<count {
|
||||
if bucket == endBucket { break }
|
||||
|
||||
@@ -700,7 +700,7 @@ extension __CocoaDictionary: Sequence {
|
||||
// This stored property should be stored at offset zero. There's code below
|
||||
// relying on this.
|
||||
internal var _fastEnumerationState: _SwiftNSFastEnumerationState =
|
||||
unsafe _makeSwiftNSFastEnumerationState()
|
||||
_makeSwiftNSFastEnumerationState()
|
||||
|
||||
// This stored property should be stored right after
|
||||
// `_fastEnumerationState`. There's code below relying on this.
|
||||
|
||||
@@ -157,7 +157,7 @@ public func swift_slowAlloc(_ size: Int, _ alignMask: Int) -> UnsafeMutableRawPo
|
||||
} else {
|
||||
alignment = alignMask + 1
|
||||
}
|
||||
return unsafe alignedAlloc(size: size, alignment: alignment)
|
||||
return alignedAlloc(size: size, alignment: alignment)
|
||||
}
|
||||
|
||||
@_cdecl("swift_slowDealloc")
|
||||
@@ -171,7 +171,7 @@ public func swift_allocObject(metadata: Builtin.RawPointer, requiredSize: Int, r
|
||||
}
|
||||
|
||||
func swift_allocObject(metadata: UnsafeMutablePointer<ClassMetadata>, requiredSize: Int, requiredAlignmentMask: Int) -> UnsafeMutablePointer<HeapObject> {
|
||||
let p = unsafe swift_slowAlloc(requiredSize, requiredAlignmentMask)!
|
||||
let p = swift_slowAlloc(requiredSize, requiredAlignmentMask)!
|
||||
let object = unsafe p.assumingMemoryBound(to: HeapObject.self)
|
||||
unsafe _swift_embedded_set_heap_object_metadata_pointer(object, metadata)
|
||||
unsafe object.pointee.refcount = 1
|
||||
|
||||
@@ -106,6 +106,7 @@ extension InlineArray where Element: ~Copyable {
|
||||
/// Converts the given raw pointer, which points at an uninitialized array
|
||||
/// instance, to a mutable buffer suitable for initialization.
|
||||
@available(SwiftStdlib 6.2, *)
|
||||
@unsafe
|
||||
@_alwaysEmitIntoClient
|
||||
@_transparent
|
||||
internal static func _initializationBuffer(
|
||||
|
||||
@@ -629,7 +629,7 @@ public class ReferenceWritableKeyPath<
|
||||
return unsafe UnsafeMutablePointer(mutating: typedPointer)
|
||||
}
|
||||
}
|
||||
return _openExistential(base, do: unsafe formalMutation(_:))
|
||||
return _openExistential(base, do: formalMutation(_:))
|
||||
}
|
||||
|
||||
return unsafe (address, keepAlive)
|
||||
@@ -1825,7 +1825,7 @@ internal struct RawKeyPathComponent {
|
||||
case .get(id: _, accessors: let accessors, argument: let argument),
|
||||
.mutatingGetSet(id: _, accessors: let accessors, argument: let argument),
|
||||
.nonmutatingGetSet(id: _, accessors: let accessors, argument: let argument):
|
||||
let getter: ComputedAccessorsPtr.Getter<CurValue, NewValue> = unsafe accessors.getter()
|
||||
let getter: ComputedAccessorsPtr.Getter<CurValue, NewValue> = accessors.getter()
|
||||
|
||||
unsafe pointer.initialize(
|
||||
to: getter(
|
||||
@@ -2263,7 +2263,7 @@ func _modifyAtReferenceWritableKeyPath_impl<Root, Value>(
|
||||
root: Root,
|
||||
keyPath: ReferenceWritableKeyPath<Root, Value>
|
||||
) -> (UnsafeMutablePointer<Value>, AnyObject?) {
|
||||
return unsafe keyPath._projectMutableAddress(from: root)
|
||||
return keyPath._projectMutableAddress(from: root)
|
||||
}
|
||||
|
||||
@_silgen_name("swift_setAtWritableKeyPath")
|
||||
@@ -2299,7 +2299,7 @@ func _setAtReferenceWritableKeyPath<Root, Value>(
|
||||
value: __owned Value
|
||||
) {
|
||||
// TODO: we should be able to do this more efficiently than projecting.
|
||||
let (addr, owner) = unsafe keyPath._projectMutableAddress(from: root)
|
||||
let (addr, owner) = keyPath._projectMutableAddress(from: root)
|
||||
unsafe addr.pointee = value
|
||||
_fixLifetime(owner)
|
||||
// FIXME: this needs a deallocation barrier to ensure that the
|
||||
@@ -3222,7 +3222,7 @@ internal func _walkKeyPathPattern<W: KeyPathPatternVisitor>(
|
||||
let witnessesRef = unsafe _pop(from: &componentBuffer, as: Int32.self)
|
||||
let witnesses: UnsafeRawPointer
|
||||
if witnessesRef == 0 {
|
||||
unsafe witnesses = unsafe __swift_keyPathGenericWitnessTable_addr()
|
||||
unsafe witnesses = __swift_keyPathGenericWitnessTable_addr()
|
||||
} else {
|
||||
unsafe witnesses = unsafe _resolveRelativeAddress(witnessesBase, witnessesRef)
|
||||
}
|
||||
@@ -4353,7 +4353,7 @@ fileprivate func dynamicLibraryAddress<Base, Leaf>(
|
||||
_: Base.Type,
|
||||
_ leaf: Leaf.Type
|
||||
) -> String {
|
||||
let getter: ComputedAccessorsPtr.Getter<Base, Leaf> = unsafe pointer.getter()
|
||||
let getter: ComputedAccessorsPtr.Getter<Base, Leaf> = pointer.getter()
|
||||
let pointer = unsafe unsafeBitCast(getter, to: UnsafeRawPointer.self)
|
||||
if let cString = unsafe keyPath_copySymbolName(UnsafeRawPointer(pointer)) {
|
||||
defer {
|
||||
|
||||
@@ -90,7 +90,7 @@ public func _getTypeName(_ type: Any.Type, qualified: Bool)
|
||||
@_unavailableInEmbedded
|
||||
public // @testable
|
||||
func _typeName(_ type: Any.Type, qualified: Bool = true) -> String {
|
||||
let (stringPtr, count) = unsafe _getTypeName(type, qualified: qualified)
|
||||
let (stringPtr, count) = _getTypeName(type, qualified: qualified)
|
||||
return unsafe String._fromUTF8Repairing(
|
||||
UnsafeBufferPointer(start: stringPtr, count: count)).0
|
||||
}
|
||||
@@ -107,7 +107,7 @@ public func _getMangledTypeName(_ type: any (~Copyable & ~Escapable).Type)
|
||||
@_preInverseGenerics
|
||||
public // SPI
|
||||
func _mangledTypeName(_ type: any (~Copyable & ~Escapable).Type) -> String? {
|
||||
let (stringPtr, count) = unsafe _getMangledTypeName(type)
|
||||
let (stringPtr, count) = _getMangledTypeName(type)
|
||||
guard count > 0 else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -354,7 +354,7 @@ internal func _adHocPrint_unlocked<T, TargetStream: TextOutputStream>(
|
||||
}
|
||||
target.write(")")
|
||||
case .enum:
|
||||
if let cString = unsafe _getEnumCaseName(value),
|
||||
if let cString = _getEnumCaseName(value),
|
||||
let caseName = unsafe String(validatingCString: cString) {
|
||||
// Write the qualified type name in debugPrint.
|
||||
if isDebugPrint {
|
||||
@@ -389,7 +389,7 @@ internal func _adHocPrint_unlocked<T, TargetStream: TextOutputStream>(
|
||||
printTypeName(metatypeValue)
|
||||
} else {
|
||||
// Fall back to the type or an opaque summary of the kind
|
||||
if let cString = unsafe _opaqueSummary(mirror.subjectType),
|
||||
if let cString = _opaqueSummary(mirror.subjectType),
|
||||
let opaqueSummary = unsafe String(validatingCString: cString) {
|
||||
target.write(opaqueSummary)
|
||||
} else {
|
||||
@@ -533,7 +533,7 @@ internal func _dumpPrint_unlocked<T, TargetStream: TextOutputStream>(
|
||||
return
|
||||
case .`enum`:
|
||||
target.write(_typeName(mirror.subjectType, qualified: true))
|
||||
if let cString = unsafe _getEnumCaseName(value),
|
||||
if let cString = _getEnumCaseName(value),
|
||||
let caseName = unsafe String(validatingCString: cString) {
|
||||
target.write(".")
|
||||
target.write(caseName)
|
||||
|
||||
@@ -434,7 +434,7 @@ func _convertConstArrayToPointerArgument<
|
||||
FromElement,
|
||||
ToPointer: _Pointer
|
||||
>(_ arr: [FromElement]) -> (AnyObject?, ToPointer) {
|
||||
let (owner, opaquePointer) = unsafe arr._cPointerArgs()
|
||||
let (owner, opaquePointer) = arr._cPointerArgs()
|
||||
|
||||
let validPointer: ToPointer
|
||||
if let addr = unsafe opaquePointer {
|
||||
@@ -453,7 +453,7 @@ func _convertConstArrayToPointerArgument<
|
||||
FromElement,
|
||||
ToPointer: _Pointer
|
||||
>(_ arr: [FromElement]) -> (Builtin.NativeObject?, ToPointer) {
|
||||
let (owner, opaquePointer) = unsafe arr._cPointerArgs()
|
||||
let (owner, opaquePointer) = arr._cPointerArgs()
|
||||
|
||||
let validPointer: ToPointer
|
||||
if let addr = unsafe opaquePointer {
|
||||
|
||||
@@ -106,7 +106,7 @@ struct _RuntimeFunctionCounters {
|
||||
public static let runtimeFunctionNames =
|
||||
getRuntimeFunctionNames()
|
||||
public static let runtimeFunctionCountersOffsets =
|
||||
unsafe _RuntimeFunctionCounters.getRuntimeFunctionCountersOffsets()
|
||||
_RuntimeFunctionCounters.getRuntimeFunctionCountersOffsets()
|
||||
public static let numRuntimeFunctionCounters =
|
||||
Int(_RuntimeFunctionCounters.getNumRuntimeFunctionCounters())
|
||||
public static let runtimeFunctionNameToIndex: [String: Int] =
|
||||
@@ -119,7 +119,7 @@ struct _RuntimeFunctionCounters {
|
||||
UnsafePointer<UnsafePointer<CChar>>
|
||||
|
||||
public static func getRuntimeFunctionNames() -> [String] {
|
||||
let names = unsafe _RuntimeFunctionCounters._getRuntimeFunctionNames()
|
||||
let names = _RuntimeFunctionCounters._getRuntimeFunctionNames()
|
||||
let numRuntimeFunctionCounters =
|
||||
Int(_RuntimeFunctionCounters.getNumRuntimeFunctionCounters())
|
||||
var functionNames: [String] = []
|
||||
@@ -504,7 +504,7 @@ public // @testable
|
||||
func _collectReferencesInsideObject(_ value: Any) -> [UnsafeRawPointer] {
|
||||
let savedMode = _RuntimeFunctionCounters.disableRuntimeFunctionCountersUpdates()
|
||||
// Collect all references inside the object
|
||||
let refs = unsafe _RuntimeFunctionCounters.collectAllReferencesInsideObject(value)
|
||||
let refs = _RuntimeFunctionCounters.collectAllReferencesInsideObject(value)
|
||||
_RuntimeFunctionCounters.enableRuntimeFunctionCountersUpdates(mode: savedMode)
|
||||
return unsafe refs
|
||||
}
|
||||
|
||||
@@ -227,7 +227,7 @@ final internal class _SwiftDeferredNSSet<Element: Hashable>
|
||||
|
||||
let (bucket, found) = native.find(element)
|
||||
guard found else { return nil }
|
||||
let bridged = unsafe bridgeElements()
|
||||
let bridged = bridgeElements()
|
||||
return unsafe bridged[bucket]
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ final internal class _SwiftDeferredNSSet<Element: Hashable>
|
||||
"Invalid fast enumeration state")
|
||||
|
||||
// Only need to bridge once, so we can hoist it out of the loop.
|
||||
let bridgedElements = unsafe bridgeElements()
|
||||
let bridgedElements = bridgeElements()
|
||||
|
||||
var stored = 0
|
||||
for i in 0..<count {
|
||||
@@ -526,7 +526,7 @@ extension __CocoaSet: Sequence {
|
||||
// This stored property should be stored at offset zero. There's code below
|
||||
// relying on this.
|
||||
internal var _fastEnumerationState: _SwiftNSFastEnumerationState =
|
||||
unsafe _makeSwiftNSFastEnumerationState()
|
||||
_makeSwiftNSFastEnumerationState()
|
||||
|
||||
// This stored property should be stored right after
|
||||
// `_fastEnumerationState`. There's code below relying on this.
|
||||
|
||||
@@ -171,7 +171,7 @@ extension RawSpan {
|
||||
@_alwaysEmitIntoClient
|
||||
@lifetime(borrow mutableRawSpan)
|
||||
public init(_mutableRawSpan mutableRawSpan: borrowing MutableRawSpan) {
|
||||
let (start, count) = unsafe (mutableRawSpan._start(), mutableRawSpan._count)
|
||||
let (start, count) = (mutableRawSpan._start(), mutableRawSpan._count)
|
||||
let span = unsafe RawSpan(_unsafeStart: start, byteCount: count)
|
||||
self = unsafe _overrideLifetime(span, borrowing: mutableRawSpan)
|
||||
}
|
||||
|
||||
@@ -600,7 +600,7 @@ extension MutableSpan where Element: BitwiseCopyable {
|
||||
) where Element: BitwiseCopyable {
|
||||
guard count > 0 else { return }
|
||||
// rebind _start manually in order to avoid assumptions about alignment.
|
||||
let rp = unsafe _start()._rawValue
|
||||
let rp = _start()._rawValue
|
||||
let binding = Builtin.bindMemory(rp, count._builtinWordValue, Element.self)
|
||||
let rebound = unsafe UnsafeMutablePointer<Element>(rp)
|
||||
unsafe rebound.update(repeating: repeatedValue, count: count)
|
||||
|
||||
@@ -81,7 +81,7 @@ private func _objc(_ str: _CocoaString) -> _StringSelectorHolder {
|
||||
|
||||
@_effects(releasenone)
|
||||
private func _copyNSString(_ str: _StringSelectorHolder) -> _CocoaString {
|
||||
return unsafe str.copy(with: nil)
|
||||
return str.copy(with: nil)
|
||||
}
|
||||
|
||||
@usableFromInline // @testable
|
||||
@@ -127,7 +127,7 @@ private func _stdlib_binary_createIndirectTaggedPointerNSString(
|
||||
internal func _stdlib_binary_CFStringGetCharactersPtr(
|
||||
_ source: _CocoaString
|
||||
) -> UnsafeMutablePointer<UTF16.CodeUnit>? {
|
||||
return unsafe _NSStringCharactersPtr(_objc(source))
|
||||
return _NSStringCharactersPtr(_objc(source))
|
||||
}
|
||||
|
||||
@_effects(releasenone)
|
||||
@@ -284,7 +284,7 @@ internal func _cocoaHashASCIIBytes(
|
||||
internal func _cocoaCStringUsingEncodingTrampoline(
|
||||
_ string: _CocoaString, _ encoding: UInt
|
||||
) -> UnsafePointer<UInt8>? {
|
||||
return unsafe _swift_stdlib_NSStringCStringUsingEncodingTrampoline(string, encoding)
|
||||
return _swift_stdlib_NSStringCStringUsingEncodingTrampoline(string, encoding)
|
||||
}
|
||||
|
||||
@_effects(releasenone)
|
||||
@@ -373,7 +373,7 @@ private func _NSStringASCIIPointer(_ str: _StringSelectorHolder) -> UnsafePointe
|
||||
@_effects(readonly)
|
||||
private func _NSStringUTF8Pointer(_ str: _StringSelectorHolder) -> UnsafePointer<UInt8>? {
|
||||
//We don't have a way to ask for UTF8 here currently
|
||||
return unsafe _NSStringASCIIPointer(str)
|
||||
return _NSStringASCIIPointer(str)
|
||||
}
|
||||
|
||||
@_effects(readonly)
|
||||
@@ -405,7 +405,7 @@ private func _withCocoaASCIIPointer<R>(
|
||||
}
|
||||
#endif
|
||||
defer { _fixLifetime(str) }
|
||||
if let ptr = unsafe _NSStringASCIIPointer(_objc(str)) {
|
||||
if let ptr = _NSStringASCIIPointer(_objc(str)) {
|
||||
return unsafe work(ptr)
|
||||
}
|
||||
return nil
|
||||
@@ -430,7 +430,7 @@ private func _withCocoaUTF8Pointer<R>(
|
||||
}
|
||||
#endif
|
||||
defer { _fixLifetime(str) }
|
||||
if let ptr = unsafe _NSStringUTF8Pointer(_objc(str)) {
|
||||
if let ptr = _NSStringUTF8Pointer(_objc(str)) {
|
||||
return unsafe work(ptr)
|
||||
}
|
||||
return nil
|
||||
@@ -476,7 +476,7 @@ private enum CocoaStringPointer {
|
||||
private func _getCocoaStringPointer(
|
||||
_ cfImmutableValue: _CocoaString
|
||||
) -> CocoaStringPointer {
|
||||
if let ascii = unsafe stableCocoaASCIIPointer(cfImmutableValue) {
|
||||
if let ascii = stableCocoaASCIIPointer(cfImmutableValue) {
|
||||
return unsafe .ascii(ascii)
|
||||
}
|
||||
// We could ask for UTF16 here via _stdlib_binary_CFStringGetCharactersPtr,
|
||||
@@ -527,7 +527,7 @@ internal func _bridgeCocoaString(_ cocoaString: _CocoaString) -> _StringGuts {
|
||||
#endif
|
||||
|
||||
let (fastUTF8, isASCII): (Bool, Bool)
|
||||
switch unsafe _getCocoaStringPointer(immutableCopy) {
|
||||
switch _getCocoaStringPointer(immutableCopy) {
|
||||
case .ascii(_): (fastUTF8, isASCII) = (true, true)
|
||||
case .utf8(_): (fastUTF8, isASCII) = (true, false)
|
||||
default: (fastUTF8, isASCII) = (false, false)
|
||||
|
||||
@@ -973,7 +973,7 @@ extension _StringObject {
|
||||
#if _runtime(_ObjC)
|
||||
if largeFastIsConstantCocoa {
|
||||
return unsafe withCocoaObject {
|
||||
unsafe _getNSCFConstantStringContentsPointer($0)
|
||||
_getNSCFConstantStringContentsPointer($0)
|
||||
}
|
||||
}
|
||||
if largeIsCocoa {
|
||||
@@ -989,7 +989,7 @@ extension _StringObject {
|
||||
internal var sharedUTF8: UnsafeBufferPointer<UInt8> {
|
||||
@_effects(releasenone) @inline(never) get {
|
||||
_internalInvariant(largeFastIsShared)
|
||||
let start = unsafe self.getSharedUTF8Start()
|
||||
let start = self.getSharedUTF8Start()
|
||||
return unsafe UnsafeBufferPointer(start: start, count: largeCount)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -87,7 +87,7 @@ extension _AbstractStringStorage {
|
||||
(_cocoaUTF8Encoding, _):
|
||||
return unsafe start
|
||||
default:
|
||||
return unsafe _cocoaCStringUsingEncodingTrampoline(self, encoding)
|
||||
return _cocoaCStringUsingEncodingTrampoline(self, encoding)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -212,7 +212,7 @@ extension __StringStorage {
|
||||
@objc(cStringUsingEncoding:)
|
||||
@_effects(readonly)
|
||||
final internal func cString(encoding: UInt) -> UnsafePointer<UInt8>? {
|
||||
return unsafe _cString(encoding: encoding)
|
||||
return _cString(encoding: encoding)
|
||||
}
|
||||
|
||||
@objc(getCString:maxLength:encoding:)
|
||||
@@ -318,7 +318,7 @@ extension __SharedStringStorage {
|
||||
@objc(cStringUsingEncoding:)
|
||||
@_effects(readonly)
|
||||
final internal func cString(encoding: UInt) -> UnsafePointer<UInt8>? {
|
||||
return unsafe _cString(encoding: encoding)
|
||||
return _cString(encoding: encoding)
|
||||
}
|
||||
|
||||
@objc(getCString:maxLength:encoding:)
|
||||
|
||||
@@ -178,7 +178,7 @@ extension _StringGuts {
|
||||
usesScratch: false, allocatedMemory: false)
|
||||
}
|
||||
|
||||
let (object, ptr, len) = unsafe self._allocateForDeconstruct()
|
||||
let (object, ptr, len) = self._allocateForDeconstruct()
|
||||
return unsafe (
|
||||
owner: object,
|
||||
_convertPointerToPointerArgument(ptr),
|
||||
|
||||
@@ -852,7 +852,7 @@ extension String.UTF16View {
|
||||
return _utf16Distance(from: startIndex, to: idx)
|
||||
}
|
||||
|
||||
let breadcrumbs = unsafe _guts.loadUnmanagedBreadcrumbs()
|
||||
let breadcrumbs = _guts.loadUnmanagedBreadcrumbs()
|
||||
|
||||
// Simple and common: endIndex aka `length`.
|
||||
if idx == endIndex {
|
||||
@@ -896,7 +896,7 @@ extension String.UTF16View {
|
||||
}
|
||||
|
||||
// Simple and common: endIndex aka `length`.
|
||||
let breadcrumbs = unsafe _guts.loadUnmanagedBreadcrumbs()
|
||||
let breadcrumbs = _guts.loadUnmanagedBreadcrumbs()
|
||||
let utf16Count = unsafe breadcrumbs._withUnsafeGuaranteedRef { $0.utf16Length }
|
||||
if offset == utf16Count { return endIndex }
|
||||
|
||||
|
||||
@@ -84,13 +84,13 @@ extension __SwiftNativeNSArrayWithContiguousStorage {
|
||||
@objc(objectAtIndexedSubscript:)
|
||||
@_effects(readonly)
|
||||
dynamic internal func objectAtSubscript(_ index: Int) -> Unmanaged<AnyObject> {
|
||||
return unsafe _objectAt(index)
|
||||
return _objectAt(index)
|
||||
}
|
||||
|
||||
@objc(objectAtIndex:)
|
||||
@_effects(readonly)
|
||||
dynamic internal func objectAt(_ index: Int) -> Unmanaged<AnyObject> {
|
||||
return unsafe _objectAt(index)
|
||||
return _objectAt(index)
|
||||
}
|
||||
|
||||
@objc internal func getObjects(
|
||||
|
||||
@@ -28,7 +28,7 @@ extension UTF8Span {
|
||||
}
|
||||
|
||||
private var _start: UnsafeRawPointer {
|
||||
unsafe codeUnits._start()
|
||||
codeUnits._start()
|
||||
}
|
||||
|
||||
/// Decode and return the scalar starting at `currentCodeUnitOffset`.
|
||||
@@ -227,7 +227,7 @@ extension UTF8Span {
|
||||
}
|
||||
|
||||
private var _start: UnsafeRawPointer {
|
||||
unsafe codeUnits._start()
|
||||
codeUnits._start()
|
||||
}
|
||||
|
||||
/// Return the `Character` starting at `currentCodeUnitOffset`. After the
|
||||
|
||||
@@ -1277,7 +1277,7 @@ extension Unicode.Scalar.Properties {
|
||||
/// This property corresponds to the "Name_Alias" property in the
|
||||
/// [Unicode Standard](http://www.unicode.org/versions/latest/).
|
||||
public var nameAlias: String? {
|
||||
guard let nameAliasPtr = unsafe _swift_stdlib_getNameAlias(_scalar.value) else {
|
||||
guard let nameAliasPtr = _swift_stdlib_getNameAlias(_scalar.value) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user