@@ -53,14 +53,14 @@ getKnownTypeInfo(const TypeDecl *typeDecl, PrimitiveTypeMapping &typeMapping,
53
53
}
54
54
55
55
bool isKnownType (Type t, PrimitiveTypeMapping &typeMapping,
56
- OutputLanguageMode languageMode) {
56
+ OutputLanguageMode languageMode, ASTContext &ctx ) {
57
57
if (auto *typeAliasType = dyn_cast<TypeAliasType>(t.getPointer ())) {
58
58
auto aliasInfo =
59
59
getKnownTypeInfo (typeAliasType->getDecl (), typeMapping, languageMode);
60
60
if (aliasInfo != std::nullopt)
61
61
return true ;
62
62
return isKnownType (typeAliasType->getSinglyDesugaredType (), typeMapping,
63
- languageMode);
63
+ languageMode, ctx );
64
64
}
65
65
66
66
const TypeDecl *typeDecl;
@@ -80,6 +80,8 @@ bool isKnownType(Type t, PrimitiveTypeMapping &typeMapping,
80
80
isa<clang::ObjCInterfaceDecl>(
81
81
classType->getClassOrBoundGenericClass ()->getClangDecl ());
82
82
}
83
+ if (t->getAs <BuiltinVectorType>())
84
+ return (bool )typeMapping.getKnownSIMDTypeInfo (t, ctx);
83
85
84
86
if (auto *structDecl = t->getStructOrBoundGenericStruct ())
85
87
typeDecl = structDecl;
@@ -88,12 +90,13 @@ bool isKnownType(Type t, PrimitiveTypeMapping &typeMapping,
88
90
return getKnownTypeInfo (typeDecl, typeMapping, languageMode) != std::nullopt;
89
91
}
90
92
91
- bool isKnownCxxType (Type t, PrimitiveTypeMapping &typeMapping) {
92
- return isKnownType (t, typeMapping, OutputLanguageMode::Cxx);
93
+ bool isKnownCxxType (Type t, PrimitiveTypeMapping &typeMapping,
94
+ ASTContext &ctx) {
95
+ return isKnownType (t, typeMapping, OutputLanguageMode::Cxx, ctx);
93
96
}
94
97
95
- bool isKnownCType (Type t, PrimitiveTypeMapping &typeMapping) {
96
- return isKnownType (t, typeMapping, OutputLanguageMode::ObjC);
98
+ bool isKnownCType (Type t, PrimitiveTypeMapping &typeMapping, ASTContext &ctx ) {
99
+ return isKnownType (t, typeMapping, OutputLanguageMode::ObjC, ctx );
97
100
}
98
101
99
102
struct CFunctionSignatureTypePrinterModifierDelegate {
@@ -463,7 +466,7 @@ class CFunctionSignatureTypePrinter
463
466
llvm::SaveAndRestore<FunctionSignatureTypeUse> typeUseNormal (
464
467
typeUseKind, FunctionSignatureTypeUse::TypeReference);
465
468
// FIXME: We can definitely support pointers to known Clang types.
466
- if (!isKnownCType (args.front (), typeMapping))
469
+ if (!isKnownCType (args.front (), typeMapping, BGT-> getASTContext () ))
467
470
return ClangRepresentation (ClangRepresentation::unsupported);
468
471
auto partRepr = visitPart (args.front (), OTK_None, /* isInOutParam=*/ false );
469
472
if (partRepr.isUnsupported ())
@@ -572,9 +575,11 @@ DeclAndTypeClangFunctionPrinter::printClangFunctionReturnType(
572
575
static void addABIRecordToTypeEncoding (llvm::raw_ostream &typeEncodingOS,
573
576
clang::CharUnits offset,
574
577
clang::CharUnits end, Type t,
575
- PrimitiveTypeMapping &typeMapping) {
576
- auto info =
577
- typeMapping.getKnownCTypeInfo (t->getNominalOrBoundGenericNominal ());
578
+ PrimitiveTypeMapping &typeMapping,
579
+ ASTContext &ctx) {
580
+ auto info = typeMapping.getKnownSIMDTypeInfo (t, ctx);
581
+ if (!info)
582
+ info = typeMapping.getKnownCTypeInfo (t->getNominalOrBoundGenericNominal ());
578
583
assert (info);
579
584
typeEncodingOS << ' _' ;
580
585
for (char c : info->name ) {
@@ -605,7 +610,8 @@ static std::string encodeTypeInfo(const T &abiTypeInfo,
605
610
ClangSyntaxPrinter (moduleContext->getASTContext (), typeEncodingOS).printBaseName (moduleContext);
606
611
abiTypeInfo.enumerateRecordMembers (
607
612
[&](clang::CharUnits offset, clang::CharUnits end, Type t) {
608
- addABIRecordToTypeEncoding (typeEncodingOS, offset, end, t, typeMapping);
613
+ addABIRecordToTypeEncoding (typeEncodingOS, offset, end, t, typeMapping,
614
+ moduleContext->getASTContext ());
609
615
});
610
616
return std::move (typeEncodingOS.str ());
611
617
}
@@ -652,7 +658,8 @@ static bool printDirectReturnOrParamCType(
652
658
clang::CharUnits end, Type t) {
653
659
lastOffset = offset;
654
660
++Count;
655
- addABIRecordToTypeEncoding (typeEncodingOS, offset, end, t, typeMapping);
661
+ addABIRecordToTypeEncoding (typeEncodingOS, offset, end, t, typeMapping,
662
+ emittedModule->getASTContext ());
656
663
}))
657
664
return false ;
658
665
if (isResultType && Count == 0 ) {
@@ -664,7 +671,7 @@ static bool printDirectReturnOrParamCType(
664
671
assert (Count > 0 && " missing return values" );
665
672
666
673
// FIXME: is this "prettyfying" logic sound for multiple return values?
667
- if (isKnownCType (valueType, typeMapping) ||
674
+ if (isKnownCType (valueType, typeMapping, emittedModule-> getASTContext () ) ||
668
675
(Count == 1 && lastOffset.isZero () && !valueType->hasTypeParameter () &&
669
676
(valueType->isAnyClassReferenceType () ||
670
677
isOptionalObjCExistential (valueType) ||
@@ -683,7 +690,10 @@ static bool printDirectReturnOrParamCType(
683
690
abiTypeInfo.enumerateRecordMembers ([&](clang::CharUnits offset,
684
691
clang::CharUnits end, Type t) {
685
692
auto info =
686
- typeMapping.getKnownCTypeInfo (t->getNominalOrBoundGenericNominal ());
693
+ typeMapping.getKnownSIMDTypeInfo (t, emittedModule->getASTContext ());
694
+ if (!info)
695
+ info =
696
+ typeMapping.getKnownCTypeInfo (t->getNominalOrBoundGenericNominal ());
687
697
os << " " << info->name ;
688
698
if (info->canBeNullable )
689
699
os << " _Nullable" ;
@@ -962,8 +972,8 @@ ClangRepresentation DeclAndTypeClangFunctionPrinter::printFunctionSignature(
962
972
->isAnyClassReferenceType ());
963
973
if (isConst)
964
974
functionSignatureOS << " const " ;
965
- if (isKnownCType (param.getParamDecl ().getInterfaceType (),
966
- typeMapping ) ||
975
+ if (isKnownCType (param.getParamDecl ().getInterfaceType (), typeMapping,
976
+ FD-> getASTContext () ) ||
967
977
(!param.getParamDecl ().getInterfaceType ()->hasTypeParameter () &&
968
978
param.getParamDecl ()
969
979
.getInterfaceType ()
@@ -1079,7 +1089,7 @@ void DeclAndTypeClangFunctionPrinter::printCxxToCFunctionParameterUse(
1079
1089
Type type, StringRef name, const ModuleDecl *moduleContext, bool isInOut,
1080
1090
bool isIndirect, std::string directTypeEncoding, bool forceSelf) {
1081
1091
auto namePrinter = [&]() { ClangSyntaxPrinter (moduleContext->getASTContext (), os).printIdentifier (name); };
1082
- if (!isKnownCxxType (type, typeMapping) &&
1092
+ if (!isKnownCxxType (type, typeMapping, moduleContext-> getASTContext () ) &&
1083
1093
!hasKnownOptionalNullableCxxMapping (type)) {
1084
1094
if (type->is <GenericTypeParamType>()) {
1085
1095
os << " swift::" << cxx_synthesis::getCxxImplNamespaceName ()
@@ -1463,7 +1473,7 @@ void DeclAndTypeClangFunctionPrinter::printCxxThunkBody(
1463
1473
1464
1474
// Values types are returned either direcly in their C representation, or
1465
1475
// indirectly by a pointer.
1466
- if (!isKnownCxxType (resultTy, typeMapping) &&
1476
+ if (!isKnownCxxType (resultTy, typeMapping, moduleContext-> getASTContext () ) &&
1467
1477
!hasKnownOptionalNullableCxxMapping (resultTy)) {
1468
1478
if (const auto *gtpt = resultTy->getAs <GenericTypeParamType>()) {
1469
1479
printGenericReturnSequence (os, gtpt, printCallToCFunc);
0 commit comments