@@ -30,6 +30,8 @@ static TypeDecl *findTypeInModuleByName(ASTContext &ctx,
3030 // Find all of the declarations with this name in the Swift module.
3131 SmallVector<ValueDecl *, 1 > results;
3232 module ->lookupValue (typeName, NLKind::UnqualifiedLookup, results);
33+ assert (results.size () <= 1 &&
34+ " Expected at most one match for a primitive type" );
3335 for (auto result : results) {
3436 if (auto nominal = dyn_cast<NominalTypeDecl>(result))
3537 return nominal;
@@ -45,7 +47,8 @@ void PrimitiveTypeMapping::initialize(ASTContext &ctx) {
4547 assert (mappedTypeNames.empty () && " expected empty type map" );
4648
4749 auto addMappedType = [&](Identifier moduleName, Identifier typeName,
48- FullClangTypeInfo info) {
50+ FullClangTypeInfo info,
51+ bool applyToUnderlying = true ) {
4952 auto decl = findTypeInModuleByName (ctx, moduleName, typeName);
5053 if (!decl)
5154 return ;
@@ -56,7 +59,8 @@ void PrimitiveTypeMapping::initialize(ASTContext &ctx) {
5659
5760 // If the underlying type of a typealias doesn't have a type, set it here.
5861 // This aims to reproduce the typealias behavior from BuiltinMappedTypes.
59- if (auto typealias = dyn_cast<TypeAliasDecl>(decl)) {
62+ auto typealias = dyn_cast<TypeAliasDecl>(decl);
63+ if (applyToUnderlying && typealias) {
6064 auto underlying = typealias->getDeclaredInterfaceType ()->getAnyNominal ();
6165 if (underlying && !mappedTypeNames.contains (underlying))
6266 mappedTypeNames[underlying] = info;
@@ -154,13 +158,16 @@ void PrimitiveTypeMapping::initialize(ASTContext &ctx) {
154158#define MAP_SIMD_TYPE (BASENAME, _, __ ) \
155159 StringRef simd2##BASENAME = " swift_" #BASENAME " 2" ; \
156160 addMappedType (ctx.Id_simd , ctx.getIdentifier (#BASENAME " 2" ), \
157- {simd2##BASENAME, simd2##BASENAME, simd2##BASENAME, false }); \
161+ {simd2##BASENAME, simd2##BASENAME, simd2##BASENAME, false }, \
162+ /* applyToUnderlying*/ false ); \
158163 StringRef simd3##BASENAME = " swift_" #BASENAME " 3" ; \
159164 addMappedType (ctx.Id_simd , ctx.getIdentifier (#BASENAME " 3" ), \
160- {simd3##BASENAME, simd3##BASENAME, simd3##BASENAME, false }); \
165+ {simd3##BASENAME, simd3##BASENAME, simd3##BASENAME, false }, \
166+ /* applyToUnderlying*/ false ); \
161167 StringRef simd4##BASENAME = " swift_" #BASENAME " 4" ; \
162168 addMappedType (ctx.Id_simd , ctx.getIdentifier (#BASENAME " 4" ), \
163- {simd4##BASENAME, simd4##BASENAME, simd4##BASENAME, false });
169+ {simd4##BASENAME, simd4##BASENAME, simd4##BASENAME, false }, \
170+ /* applyToUnderlying*/ false );
164171#include " swift/ClangImporter/SIMDMappedTypes.def"
165172 static_assert (SWIFT_MAX_IMPORTED_SIMD_ELEMENTS == 4 ,
166173 " must add or remove special name mappings if max number of "
0 commit comments