@@ -11152,83 +11152,8 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
11152
11152
return matchPointerBaseTypes (ptr1, ptr2);
11153
11153
}
11154
11154
11155
- case ConversionRestrictionKind::PointerToCPointer: {
11156
- auto &ctx = getASTContext ();
11157
-
11158
- PointerTypeKind swiftPtrKind, cPtrKind;
11159
-
11160
- auto swiftPtr =
11161
- type1->lookThroughAllOptionalTypes ()->getAnyPointerElementType (
11162
- swiftPtrKind);
11163
-
11164
- auto cPtr = type2->lookThroughAllOptionalTypes ()->getAnyPointerElementType (
11165
- cPtrKind);
11166
-
11167
- // Unsafe[Mutable]RawPointer -> Unsafe[Mutable]Pointer<[U]Int8>
11168
- if (swiftPtrKind == PTK_UnsafeRawPointer ||
11169
- swiftPtrKind == PTK_UnsafeMutableRawPointer) {
11170
- // Since it's a C pointer on parameter side it would always
11171
- // be fully resolved.
11172
- if (cPtr->isInt8 () || cPtr->isUInt8 ())
11173
- return SolutionKind::Solved;
11174
- } else {
11175
- // Unsafe[Mutable]Pointer<T> -> Unsafe[Mutable]Pointer<[U]Int8>
11176
- if (cPtr->isInt8 () || cPtr->isUInt8 ()) {
11177
- // <T> can default to the type of C pointer.
11178
- addConstraint (
11179
- ConstraintKind::Defaultable, swiftPtr, cPtr,
11180
- locator.withPathElement (LocatorPathElt::GenericArgument (0 )));
11181
- return SolutionKind::Solved;
11182
- }
11183
-
11184
- auto elementLoc =
11185
- locator.withPathElement (LocatorPathElt::GenericArgument (0 ));
11186
-
11187
- // Unsafe[Mutable]Pointer<Int{8, 16, ...}> <->
11188
- // Unsafe[Mutable]Pointer<UInt{8, 16, ...}>
11189
-
11190
- if (swiftPtr->isInt () || swiftPtr->isUInt ()) {
11191
- addConstraint (ConstraintKind::Equal, cPtr,
11192
- swiftPtr->isUInt () ? ctx.getIntType () : ctx.getUIntType (),
11193
- elementLoc);
11194
- return SolutionKind::Solved;
11195
- }
11196
-
11197
- if (swiftPtr->isInt8 () || swiftPtr->isUInt8 ()) {
11198
- addConstraint (ConstraintKind::Equal, cPtr,
11199
- swiftPtr->isUInt8 () ? ctx.getInt8Type ()
11200
- : ctx.getUInt8Type (),
11201
- elementLoc);
11202
- return SolutionKind::Solved;
11203
- }
11204
-
11205
- if (swiftPtr->isInt16 () || swiftPtr->isUInt16 ()) {
11206
- addConstraint (ConstraintKind::Equal, cPtr,
11207
- swiftPtr->isUInt16 () ? ctx.getInt16Type ()
11208
- : ctx.getUInt16Type (),
11209
- elementLoc);
11210
- return SolutionKind::Solved;
11211
- }
11212
-
11213
- if (swiftPtr->isInt32 () || swiftPtr->isUInt32 ()) {
11214
- addConstraint (ConstraintKind::Equal, cPtr,
11215
- swiftPtr->isUInt32 () ? ctx.getInt32Type ()
11216
- : ctx.getUInt32Type (),
11217
- elementLoc);
11218
- return SolutionKind::Solved;
11219
- }
11220
-
11221
- if (swiftPtr->isInt64 () || swiftPtr->isUInt64 ()) {
11222
- addConstraint (ConstraintKind::Equal, cPtr,
11223
- swiftPtr->isUInt64 () ? ctx.getInt64Type ()
11224
- : ctx.getUInt64Type (),
11225
- elementLoc);
11226
- return SolutionKind::Solved;
11227
- }
11228
- }
11229
-
11230
- return SolutionKind::Error;
11231
- }
11155
+ case ConversionRestrictionKind::PointerToCPointer:
11156
+ return simplifyPointerToCPointerRestriction (type1, type2, flags, locator);
11232
11157
11233
11158
// T < U or T is bridged to V where V < U ===> Array<T> <c Array<U>
11234
11159
case ConversionRestrictionKind::ArrayUpcast: {
@@ -11456,6 +11381,87 @@ ConstraintSystem::simplifyRestrictedConstraint(
11456
11381
llvm_unreachable (" Unhandled SolutionKind in switch." );
11457
11382
}
11458
11383
11384
+ ConstraintSystem::SolutionKind
11385
+ ConstraintSystem::simplifyPointerToCPointerRestriction (
11386
+ Type type1, Type type2, TypeMatchOptions flags,
11387
+ ConstraintLocatorBuilder locator) {
11388
+ auto &ctx = getASTContext ();
11389
+
11390
+ PointerTypeKind swiftPtrKind, cPtrKind;
11391
+
11392
+ auto swiftPtr =
11393
+ type1->lookThroughAllOptionalTypes ()->getAnyPointerElementType (
11394
+ swiftPtrKind);
11395
+
11396
+ auto cPtr =
11397
+ type2->lookThroughAllOptionalTypes ()->getAnyPointerElementType (cPtrKind);
11398
+
11399
+ // Unsafe[Mutable]RawPointer -> Unsafe[Mutable]Pointer<[U]Int8>
11400
+ if (swiftPtrKind == PTK_UnsafeRawPointer ||
11401
+ swiftPtrKind == PTK_UnsafeMutableRawPointer) {
11402
+ // Since it's a C pointer on parameter side it would always
11403
+ // be fully resolved.
11404
+ if (cPtr->isInt8 () || cPtr->isUInt8 ())
11405
+ return SolutionKind::Solved;
11406
+ } else {
11407
+ // Unsafe[Mutable]Pointer<T> -> Unsafe[Mutable]Pointer<[U]Int8>
11408
+ if (cPtr->isInt8 () || cPtr->isUInt8 ()) {
11409
+ // <T> can default to the type of C pointer.
11410
+ addConstraint (
11411
+ ConstraintKind::Defaultable, swiftPtr, cPtr,
11412
+ locator.withPathElement (LocatorPathElt::GenericArgument (0 )));
11413
+ return SolutionKind::Solved;
11414
+ }
11415
+
11416
+ auto elementLoc =
11417
+ locator.withPathElement (LocatorPathElt::GenericArgument (0 ));
11418
+
11419
+ // Unsafe[Mutable]Pointer<Int{8, 16, ...}> <->
11420
+ // Unsafe[Mutable]Pointer<UInt{8, 16, ...}>
11421
+
11422
+ if (swiftPtr->isInt () || swiftPtr->isUInt ()) {
11423
+ addConstraint (ConstraintKind::Equal, cPtr,
11424
+ swiftPtr->isUInt () ? ctx.getIntType () : ctx.getUIntType (),
11425
+ elementLoc);
11426
+ return SolutionKind::Solved;
11427
+ }
11428
+
11429
+ if (swiftPtr->isInt8 () || swiftPtr->isUInt8 ()) {
11430
+ addConstraint (ConstraintKind::Equal, cPtr,
11431
+ swiftPtr->isUInt8 () ? ctx.getInt8Type ()
11432
+ : ctx.getUInt8Type (),
11433
+ elementLoc);
11434
+ return SolutionKind::Solved;
11435
+ }
11436
+
11437
+ if (swiftPtr->isInt16 () || swiftPtr->isUInt16 ()) {
11438
+ addConstraint (ConstraintKind::Equal, cPtr,
11439
+ swiftPtr->isUInt16 () ? ctx.getInt16Type ()
11440
+ : ctx.getUInt16Type (),
11441
+ elementLoc);
11442
+ return SolutionKind::Solved;
11443
+ }
11444
+
11445
+ if (swiftPtr->isInt32 () || swiftPtr->isUInt32 ()) {
11446
+ addConstraint (ConstraintKind::Equal, cPtr,
11447
+ swiftPtr->isUInt32 () ? ctx.getInt32Type ()
11448
+ : ctx.getUInt32Type (),
11449
+ elementLoc);
11450
+ return SolutionKind::Solved;
11451
+ }
11452
+
11453
+ if (swiftPtr->isInt64 () || swiftPtr->isUInt64 ()) {
11454
+ addConstraint (ConstraintKind::Equal, cPtr,
11455
+ swiftPtr->isUInt64 () ? ctx.getInt64Type ()
11456
+ : ctx.getUInt64Type (),
11457
+ elementLoc);
11458
+ return SolutionKind::Solved;
11459
+ }
11460
+ }
11461
+
11462
+ return SolutionKind::Error;
11463
+ }
11464
+
11459
11465
static bool isAugmentingFix (ConstraintFix *fix) {
11460
11466
switch (fix->getKind ()) {
11461
11467
case FixKind::TreatRValueAsLValue:
0 commit comments