@@ -1267,8 +1267,8 @@ static bool canBridgeTypes(ImportTypeKind importKind) {
1267
1267
case ImportTypeKind::Variable:
1268
1268
case ImportTypeKind::AuditedVariable:
1269
1269
case ImportTypeKind::Enum:
1270
- case ImportTypeKind::RecordField:
1271
1270
return false ;
1271
+ case ImportTypeKind::RecordField:
1272
1272
case ImportTypeKind::Result:
1273
1273
case ImportTypeKind::AuditedResult:
1274
1274
case ImportTypeKind::Parameter:
@@ -1419,7 +1419,8 @@ static ImportedType adjustTypeForConcreteImport(
1419
1419
bool allowNSUIntegerAsInt, Bridgeability bridging,
1420
1420
llvm::function_ref<void (Diagnostic &&)> addImportDiagnostic,
1421
1421
ImportTypeAttrs attrs, OptionalTypeKind optKind,
1422
- bool resugarNSErrorPointer) {
1422
+ bool resugarNSErrorPointer,
1423
+ clang::Qualifiers::ObjCLifetime objCLifetime) {
1423
1424
Type importedType = importResult.AbstractType ;
1424
1425
ImportHint hint = importResult.Hint ;
1425
1426
@@ -1464,6 +1465,8 @@ static ImportedType adjustTypeForConcreteImport(
1464
1465
// bridge, do so.
1465
1466
if (canBridgeTypes (importKind) &&
1466
1467
importKind != ImportTypeKind::PropertyWithReferenceSemantics &&
1468
+ !(importKind == ImportTypeKind::RecordField &&
1469
+ objCLifetime <= clang::Qualifiers::OCL_ExplicitNone) &&
1467
1470
!(importKind == ImportTypeKind::Typedef &&
1468
1471
bridging == Bridgeability::None)) {
1469
1472
// id and Any can be bridged without Foundation. There would be
@@ -1484,7 +1487,10 @@ static ImportedType adjustTypeForConcreteImport(
1484
1487
// In some contexts, we bridge them to use the Swift function type
1485
1488
// representation. This includes typedefs of block types, which use the
1486
1489
// Swift function type representation.
1487
- if (!canBridgeTypes (importKind))
1490
+ // FIXME: Do not bridge on RecordFields to keep previous behaviour for
1491
+ // the time being.
1492
+ if (!canBridgeTypes (importKind) ||
1493
+ importKind == ImportTypeKind::RecordField)
1488
1494
break ;
1489
1495
1490
1496
// Determine the function type representation we need.
@@ -1579,15 +1585,26 @@ static ImportedType adjustTypeForConcreteImport(
1579
1585
assert (importedType);
1580
1586
1581
1587
if (importKind == ImportTypeKind::RecordField &&
1582
- importedType->isAnyClassReferenceType () &&
1583
1588
!importedType->isForeignReferenceType ()) {
1584
- // Wrap retainable struct fields in Unmanaged.
1585
- // FIXME: Eventually we might get C++-like support for strong pointers in
1586
- // structs, at which point we should really be checking the lifetime
1587
- // qualifiers.
1588
- // FIXME: This should apply to blocks as well, but Unmanaged is constrained
1589
- // to AnyObject.
1590
- importedType = getUnmanagedType (impl, importedType);
1589
+ switch (objCLifetime) {
1590
+ // Wrap retainable struct fields in Unmanaged.
1591
+ case clang::Qualifiers::OCL_None:
1592
+ case clang::Qualifiers::OCL_ExplicitNone:
1593
+ // FIXME: This should apply to blocks as well, but Unmanaged is constrained
1594
+ // to AnyObject.
1595
+ if (importedType->isAnyClassReferenceType ()) {
1596
+ importedType = getUnmanagedType (impl, importedType);
1597
+ }
1598
+ break ;
1599
+ // FIXME: Eventually we might get C++-like support for strong pointers in
1600
+ // structs, at which point we should really be checking the lifetime
1601
+ // qualifiers.
1602
+ case clang::Qualifiers::OCL_Strong:
1603
+ case clang::Qualifiers::OCL_Weak:
1604
+ return {Type (), false };
1605
+ case clang::Qualifiers::OCL_Autoreleasing:
1606
+ llvm_unreachable (" invalid Objective-C lifetime" );
1607
+ }
1591
1608
}
1592
1609
1593
1610
// Apply attrs.
@@ -1665,6 +1682,8 @@ ImportedType ClangImporter::Implementation::importType(
1665
1682
}
1666
1683
}
1667
1684
1685
+ clang::Qualifiers::ObjCLifetime objCLifetime = type.getObjCLifetime ();
1686
+
1668
1687
// Perform abstract conversion, ignoring how the type is actually used.
1669
1688
SwiftTypeConverter converter (
1670
1689
*this , addImportDiagnosticFn, allowNSUIntegerAsInt, bridging,
@@ -1674,7 +1693,8 @@ ImportedType ClangImporter::Implementation::importType(
1674
1693
// Now fix up the type based on how we're concretely using it.
1675
1694
auto adjustedType = adjustTypeForConcreteImport (
1676
1695
*this , importResult, importKind, allowNSUIntegerAsInt, bridging,
1677
- addImportDiagnosticFn, attrs, optionality, resugarNSErrorPointer);
1696
+ addImportDiagnosticFn, attrs, optionality, resugarNSErrorPointer,
1697
+ objCLifetime);
1678
1698
1679
1699
return adjustedType;
1680
1700
}
0 commit comments