[stdlib] Make UnsafePointer conversions explicit

Previously, it was possible to write Unsafe[Mutable]Pointer(x) and have
Swift deduce the pointee type based on context.  Since reinterpreting
memory is a fundamentally type-unsafe operation, it's better to be
explicit about conversions from Unsafe[Mutable]Pointer<T> to
Unsafe[Mutable]Pointer<U>.  This change is consistent with the move from
reinterpretCast(x) to unsafeBitCast(x, T.self).

Also, we've encoded the operations of explicitly adding or removing
mutability as properties, so that adding mutability can be separated
from wild reinterpretCast'ing, a much more severe form of unsafety.

Swift SVN r21324
This commit is contained in:
Dave Abrahams
2014-08-20 23:15:56 +00:00
parent f7ebe89949
commit 1fb0f889d7
30 changed files with 152 additions and 105 deletions

View File

@@ -33,8 +33,8 @@ func repr(x: _StringCore) -> String {
if x.hasContiguousStorage {
if let b = x.nativeBuffer {
var offset = x.elementWidth == 2
? UnsafeMutablePointer(b.start) - x.startUTF16
: UnsafeMutablePointer(b.start) - x.startASCII
? b.start.asPointerTo(UTF16.CodeUnit.self) - x.startUTF16
: b.start.asPointerTo(UTF8.CodeUnit.self) - x.startASCII
return "Contiguous(owner: "
+ "\(hexAddr(x._owner))[\(offset)...\(x.count + offset)]"
+ ", capacity = \(b.capacity))"