@@ -2226,29 +2226,43 @@ class LowerType
2226
2226
}
2227
2227
2228
2228
const TypeInfo *visitAnyNominalTypeRef (const TypeRef *TR) {
2229
+ auto QueryExternalTypeInfoProvider = [&]() -> const TypeInfo * {
2230
+ if (ExternalTypeInfo) {
2231
+ std::string MangledName;
2232
+ if (auto N = dyn_cast<NominalTypeRef>(TR))
2233
+ MangledName = N->getMangledName ();
2234
+ else if (auto BG = dyn_cast<BoundGenericTypeRef>(TR))
2235
+ MangledName = BG->getMangledName ();
2236
+ if (!MangledName.empty ())
2237
+ if (auto *imported = ExternalTypeInfo->getTypeInfo (MangledName))
2238
+ return imported;
2239
+ }
2240
+ return nullptr ;
2241
+ };
2242
+
2229
2243
auto FD = TC.getBuilder ().getFieldTypeInfo (TR);
2230
2244
if (FD == nullptr || FD->isStruct ()) {
2231
2245
// Maybe this type is opaque -- look for a builtin
2232
2246
// descriptor to see if we at least know its size
2233
2247
// and alignment.
2234
- if (auto ImportedTypeDescriptor = TC.getBuilder ().getBuiltinTypeInfo (TR))
2248
+ if (auto ImportedTypeDescriptor =
2249
+ TC.getBuilder ().getBuiltinTypeInfo (TR)) {
2250
+ // This might be an external type we treat as opaque (like C structs),
2251
+ // the external type info provider might have better type information,
2252
+ // so ask it first.
2253
+ if (auto External = QueryExternalTypeInfoProvider ())
2254
+ return External;
2255
+
2235
2256
return TC.makeTypeInfo <BuiltinTypeInfo>(TC.getBuilder (),
2236
2257
ImportedTypeDescriptor);
2258
+ }
2237
2259
2238
- // Otherwise, we're out of luck.
2239
2260
if (FD == nullptr ) {
2240
- if (ExternalTypeInfo) {
2241
- // Ask the ExternalTypeInfo. It may be a Clang-imported type.
2242
- std::string MangledName;
2243
- if (auto N = dyn_cast<NominalTypeRef>(TR))
2244
- MangledName = N->getMangledName ();
2245
- else if (auto BG = dyn_cast<BoundGenericTypeRef>(TR))
2246
- MangledName = BG->getMangledName ();
2247
- if (!MangledName.empty ())
2248
- if (auto *imported = ExternalTypeInfo->getTypeInfo (MangledName))
2249
- return imported;
2250
- }
2261
+ // If we still have no type info ask the external provider.
2262
+ if (auto External = QueryExternalTypeInfoProvider ())
2263
+ return External;
2251
2264
2265
+ // If the external provider also fails we're out of luck.
2252
2266
DEBUG_LOG (fprintf (stderr, " No TypeInfo for nominal type: " ); TR->dump ());
2253
2267
return nullptr ;
2254
2268
}
0 commit comments