@@ -39,9 +39,12 @@ public struct StaticString
39
39
CustomDebugStringConvertible ,
40
40
CustomReflectable {
41
41
42
- /// Either a pointer to the start of UTF-8 data, represented as an integer,
43
- /// or an integer representation of a single Unicode scalar.
44
- internal var _startPtrOrData : Builtin . Word
42
+ // FIXME(ABI): RawPointer is non-nullable, but we can store a null Unicode
43
+ // scalar in it. Change it to an integer.
44
+ //
45
+ /// Either a pointer to the start of UTF-8 data, or an integer representation
46
+ /// of a single Unicode scalar.
47
+ internal var _startPtrOrData : Builtin . RawPointer
45
48
46
49
/// If `_startPtrOrData` is a pointer, contains the length of the UTF-8 data
47
50
/// in bytes.
@@ -65,7 +68,7 @@ public struct StaticString
65
68
_precondition (
66
69
hasPointerRepresentation,
67
70
" StaticString should have pointer representation " )
68
- return UnsafePointer ( bitPattern : UInt ( _startPtrOrData) ) !
71
+ return UnsafePointer ( _startPtrOrData)
69
72
}
70
73
71
74
/// The stored Unicode scalar value.
@@ -76,7 +79,9 @@ public struct StaticString
76
79
_precondition (
77
80
!hasPointerRepresentation,
78
81
" StaticString should have Unicode scalar representation " )
79
- return UnicodeScalar ( UInt32 ( UInt ( _startPtrOrData) ) )
82
+ return UnicodeScalar (
83
+ UInt32 ( UInt ( bitPattern: UnsafePointer < Builtin . RawPointer > ( _startPtrOrData) ) )
84
+ )
80
85
}
81
86
82
87
/// If `self` stores a pointer to ASCII or UTF-8 code units, the
@@ -143,10 +148,7 @@ public struct StaticString
143
148
utf8CodeUnitCount: Builtin . Word ,
144
149
isASCII: Builtin . Int1
145
150
) {
146
- // We don't go through UnsafePointer here to make things simpler for alias
147
- // analysis. A higher-level algorithm may be trying to make sure an
148
- // unrelated buffer is not accessed or freed.
149
- self . _startPtrOrData = Builtin . ptrtoint_Word ( _start)
151
+ self . _startPtrOrData = _start
150
152
self . _utf8CodeUnitCount = utf8CodeUnitCount
151
153
self . _flags = Bool ( isASCII) ? ( 0x2 as UInt8 ) . _value : ( 0x0 as UInt8 ) . _value
152
154
}
@@ -156,7 +158,11 @@ public struct StaticString
156
158
internal init (
157
159
unicodeScalar: Builtin . Int32
158
160
) {
159
- self . _startPtrOrData = UInt ( UInt32 ( unicodeScalar) ) . _builtinWordValue
161
+ self . _startPtrOrData =
162
+ unsafeBitCast (
163
+ UInt ( UInt32 ( unicodeScalar) ) ,
164
+ to: OpaquePointer . self
165
+ ) . _rawValue
160
166
self . _utf8CodeUnitCount = 0 . _builtinWordValue
161
167
self . _flags = UnicodeScalar ( _builtinUnicodeScalarLiteral: unicodeScalar) . isASCII
162
168
? ( 0x3 as UInt8 ) . _value
0 commit comments