Skip to content

Commit 5141229

Browse files
authored
Merge pull request #61081 from augusto2112/ask-external-provider-first
Ask the external provider for type info first in visitAnyNominalTypeRef
2 parents 2aaf75c + b30fc55 commit 5141229

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

stdlib/public/Reflection/TypeLowering.cpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,29 +2226,43 @@ class LowerType
22262226
}
22272227

22282228
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+
22292243
auto FD = TC.getBuilder().getFieldTypeInfo(TR);
22302244
if (FD == nullptr || FD->isStruct()) {
22312245
// Maybe this type is opaque -- look for a builtin
22322246
// descriptor to see if we at least know its size
22332247
// 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+
22352256
return TC.makeTypeInfo<BuiltinTypeInfo>(TC.getBuilder(),
22362257
ImportedTypeDescriptor);
2258+
}
22372259

2238-
// Otherwise, we're out of luck.
22392260
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;
22512264

2265+
// If the external provider also fails we're out of luck.
22522266
DEBUG_LOG(fprintf(stderr, "No TypeInfo for nominal type: "); TR->dump());
22532267
return nullptr;
22542268
}

0 commit comments

Comments
 (0)