@@ -905,6 +905,14 @@ extension UnsafeMutablePointer {
905
905
}
906
906
}
907
907
908
+ #if true // Builtin.initialize doesn't support noncopyable types (rdar://123253877)
909
+ extension UnsafeMutablePointer {
910
+ @_alwaysEmitIntoClient
911
+ public func initialize( to value: consuming Pointee ) {
912
+ Builtin . initialize ( value, self . _rawValue)
913
+ }
914
+ }
915
+ #else
908
916
extension UnsafeMutablePointer where Pointee: ~ Copyable {
909
917
/// Initializes this pointer's memory with a single instance of the given
910
918
/// value.
@@ -929,6 +937,7 @@ extension UnsafeMutablePointer {
929
937
Builtin . initialize ( value, self . _rawValue)
930
938
}
931
939
}
940
+ #endif
932
941
933
942
extension UnsafeMutablePointer where Pointee: ~ Copyable {
934
943
/// Retrieves and returns the referenced instance, returning the pointer's
@@ -1046,6 +1055,37 @@ extension UnsafeMutablePointer {
1046
1055
}
1047
1056
}
1048
1057
1058
+ #if true // Builtin.takeArray* don't support noncopyable types (rdar://123253877)
1059
+ extension UnsafeMutablePointer {
1060
+ @_alwaysEmitIntoClient
1061
+ public func moveInitialize(
1062
+ @_nonEphemeral from source: UnsafeMutablePointer , count: Int
1063
+ ) {
1064
+ _debugPrecondition (
1065
+ count >= 0 , " UnsafeMutablePointer.moveInitialize with negative count " )
1066
+ if self < source || self >= source + count {
1067
+ // initialize forward from a disjoint or following overlapping range.
1068
+ Builtin . takeArrayFrontToBack (
1069
+ Pointee . self, self . _rawValue, source. _rawValue, count. _builtinWordValue)
1070
+ // This builtin is equivalent to:
1071
+ // for i in 0..<count {
1072
+ // (self + i).initialize(to: (source + i).move())
1073
+ // }
1074
+ }
1075
+ else if self != source {
1076
+ // initialize backward from a non-following overlapping range.
1077
+ Builtin . takeArrayBackToFront (
1078
+ Pointee . self, self . _rawValue, source. _rawValue, count. _builtinWordValue)
1079
+ // This builtin is equivalent to:
1080
+ // var src = source + count
1081
+ // var dst = self + count
1082
+ // while dst != self {
1083
+ // (--dst).initialize(to: (--src).move())
1084
+ // }
1085
+ }
1086
+ }
1087
+ }
1088
+ #else
1049
1089
extension UnsafeMutablePointer where Pointee: ~ Copyable {
1050
1090
/// Moves instances from initialized source memory into the uninitialized
1051
1091
/// memory referenced by this pointer, leaving the source memory
@@ -1125,6 +1165,7 @@ extension UnsafeMutablePointer {
1125
1165
}
1126
1166
}
1127
1167
}
1168
+ #endif
1128
1169
1129
1170
extension UnsafeMutablePointer {
1130
1171
/// Initializes the memory referenced by this pointer with the values
@@ -1160,6 +1201,26 @@ extension UnsafeMutablePointer {
1160
1201
}
1161
1202
}
1162
1203
1204
+ #if true // Builtin.assignTakeArray doesn't support noncopyable types (rdar://123253877)
1205
+ extension UnsafeMutablePointer {
1206
+ @_alwaysEmitIntoClient
1207
+ public func moveUpdate(
1208
+ @_nonEphemeral from source: UnsafeMutablePointer , count: Int
1209
+ ) {
1210
+ _debugPrecondition (
1211
+ count >= 0 , " UnsafeMutablePointer.moveUpdate(from:) with negative count " )
1212
+ _debugPrecondition (
1213
+ self + count <= source || source + count <= self ,
1214
+ " moveUpdate overlapping range " )
1215
+ Builtin . assignTakeArray (
1216
+ Pointee . self, self . _rawValue, source. _rawValue, count. _builtinWordValue)
1217
+ // These builtins are equivalent to:
1218
+ // for i in 0..<count {
1219
+ // self[i] = (source + i).move()
1220
+ // }
1221
+ }
1222
+ }
1223
+ #else
1163
1224
extension UnsafeMutablePointer where Pointee: ~ Copyable {
1164
1225
/// Update this pointer's initialized memory by moving the specified number
1165
1226
/// of instances the source pointer's memory, leaving the source memory
@@ -1227,7 +1288,21 @@ extension UnsafeMutablePointer {
1227
1288
moveUpdate ( from: source, count: count)
1228
1289
}
1229
1290
}
1291
+ #endif
1230
1292
1293
+ #if true // Builtin.destroyArray doesn't support noncopyable types (rdar://123253877)
1294
+ extension UnsafeMutablePointer {
1295
+ @_alwaysEmitIntoClient
1296
+ @discardableResult
1297
+ public func deinitialize( count: Int ) -> UnsafeMutableRawPointer {
1298
+ _debugPrecondition ( count >= 0 , " UnsafeMutablePointer.deinitialize with negative count " )
1299
+ // TODO: IRGen optimization when `count` value is statically known to be 1,
1300
+ // then call `Builtin.destroy(Pointee.self, _rawValue)` instead.
1301
+ Builtin . destroyArray ( Pointee . self, _rawValue, count. _builtinWordValue)
1302
+ return UnsafeMutableRawPointer ( self )
1303
+ }
1304
+ }
1305
+ #else
1231
1306
extension UnsafeMutablePointer where Pointee: ~ Copyable {
1232
1307
/// Deinitializes the specified number of values starting at this pointer.
1233
1308
///
@@ -1263,6 +1338,7 @@ extension UnsafeMutablePointer {
1263
1338
return UnsafeMutableRawPointer ( self )
1264
1339
}
1265
1340
}
1341
+ #endif
1266
1342
1267
1343
extension UnsafeMutablePointer /* where Pointee: ~Copyable */ {
1268
1344
// FIXME: We want this to have the constraint above, but that triggers a .swiftinterface issue.
0 commit comments