@@ -30,6 +30,8 @@ static TypeDecl *findTypeInModuleByName(ASTContext &ctx,
30
30
// Find all of the declarations with this name in the Swift module.
31
31
SmallVector<ValueDecl *, 1 > results;
32
32
module ->lookupValue (typeName, NLKind::UnqualifiedLookup, results);
33
+ assert (results.size () <= 1 &&
34
+ " Expected at most one match for a primitive type" );
33
35
for (auto result : results) {
34
36
if (auto nominal = dyn_cast<NominalTypeDecl>(result))
35
37
return nominal;
@@ -45,7 +47,8 @@ void PrimitiveTypeMapping::initialize(ASTContext &ctx) {
45
47
assert (mappedTypeNames.empty () && " expected empty type map" );
46
48
47
49
auto addMappedType = [&](Identifier moduleName, Identifier typeName,
48
- FullClangTypeInfo info) {
50
+ FullClangTypeInfo info,
51
+ bool applyToUnderlying = true ) {
49
52
auto decl = findTypeInModuleByName (ctx, moduleName, typeName);
50
53
if (!decl)
51
54
return ;
@@ -56,7 +59,8 @@ void PrimitiveTypeMapping::initialize(ASTContext &ctx) {
56
59
57
60
// If the underlying type of a typealias doesn't have a type, set it here.
58
61
// 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) {
60
64
auto underlying = typealias->getDeclaredInterfaceType ()->getAnyNominal ();
61
65
if (underlying && !mappedTypeNames.contains (underlying))
62
66
mappedTypeNames[underlying] = info;
@@ -154,13 +158,16 @@ void PrimitiveTypeMapping::initialize(ASTContext &ctx) {
154
158
#define MAP_SIMD_TYPE (BASENAME, _, __ ) \
155
159
StringRef simd2##BASENAME = " swift_" #BASENAME " 2" ; \
156
160
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 ); \
158
163
StringRef simd3##BASENAME = " swift_" #BASENAME " 3" ; \
159
164
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 ); \
161
167
StringRef simd4##BASENAME = " swift_" #BASENAME " 4" ; \
162
168
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 );
164
171
#include " swift/ClangImporter/SIMDMappedTypes.def"
165
172
static_assert (SWIFT_MAX_IMPORTED_SIMD_ELEMENTS == 4 ,
166
173
" must add or remove special name mappings if max number of "
0 commit comments