Skip to content

Commit 6bc15f6

Browse files
committed
Lazily populate BuiltInTypeDescriptorCache, and fix compile error
1 parent aafa317 commit 6bc15f6

File tree

2 files changed

+34
-26
lines changed

2 files changed

+34
-26
lines changed

include/swift/RemoteInspection/TypeRefBuilder.h

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,9 @@ class TypeRefBuilder {
433433
RemoteRef<BuiltinTypeDescriptor>>
434434
BuiltInTypeDescriptorCache;
435435

436+
/// The index of the last ReflectionInfo cached by BuiltInTypeDescriptorCache.
437+
uint32_t NormalizedReflectionNameCacheLastReflectionInfoCache = 0;
438+
436439
std::vector<std::unique_ptr<const GenericSignatureRef>> SignatureRefPool;
437440

438441
TypeConverter TC;
@@ -1052,30 +1055,6 @@ class TypeRefBuilder {
10521055
ReflectionInfos.push_back(I);
10531056
auto InfoID = ReflectionInfos.size() - 1;
10541057
assert(InfoID <= UINT32_MAX && "ReflectionInfo ID overflow");
1055-
1056-
for (auto BuiltinTypeDescriptor : I.Builtin) {
1057-
if (BuiltinTypeDescriptor->Stride <= 0)
1058-
continue;
1059-
if (!BuiltinTypeDescriptor->hasMangledTypeName())
1060-
continue;
1061-
1062-
auto Alignment = BuiltinTypeDescriptor->getAlignment();
1063-
if (Alignment <= 0)
1064-
continue;
1065-
// Reject any alignment that's not a power of two.
1066-
if (Alignment & (Alignment - 1))
1067-
continue;
1068-
1069-
const auto CandidateMangledName =
1070-
readTypeRef(BuiltinTypeDescriptor, BuiltinTypeDescriptor->TypeName);
1071-
const auto CandidateNormalizedName =
1072-
normalizeReflectionName(CandidateMangledName);
1073-
if (CandidateNormalizedName) {
1074-
BuiltInTypeDescriptorCache.insert(
1075-
std::make_pair(*CandidateNormalizedName, BuiltinTypeDescriptor));
1076-
}
1077-
}
1078-
10791058
return InfoID;
10801059
}
10811060

stdlib/public/RemoteInspection/TypeRefBuilder.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,13 @@ TypeRefBuilder::normalizeReflectionName(RemoteRef<char> reflectionName) {
111111
case Node::Kind::OpaqueTypeDescriptorSymbolicReference:
112112
// Symbolic references cannot be mangled, return a failure.
113113
NormalizedReflectionNameCache.insert(std::make_pair(
114-
reflectionNameRemoteAddress, (llvm::Optional<std::string>){}));
114+
reflectionNameRemoteAddress, llvm::Optional<std::string>()));
115115
return {};
116116
default:
117117
auto mangling = mangleNode(node);
118118
if (!mangling.isSuccess()) {
119119
NormalizedReflectionNameCache.insert(std::make_pair(
120-
reflectionNameRemoteAddress, (llvm::Optional<std::string>){}));
120+
reflectionNameRemoteAddress, llvm::Optional<std::string>()));
121121
return {};
122122
}
123123
NormalizedReflectionNameCache.insert(
@@ -415,6 +415,35 @@ TypeRefBuilder::getBuiltinTypeInfo(const TypeRef *TR) {
415415
else
416416
return nullptr;
417417

418+
for (; NormalizedReflectionNameCacheLastReflectionInfoCache <
419+
ReflectionInfos.size();
420+
NormalizedReflectionNameCacheLastReflectionInfoCache++) {
421+
for (auto BuiltinTypeDescriptor :
422+
ReflectionInfos[NormalizedReflectionNameCacheLastReflectionInfoCache]
423+
.Builtin) {
424+
if (BuiltinTypeDescriptor->Stride <= 0)
425+
continue;
426+
if (!BuiltinTypeDescriptor->hasMangledTypeName())
427+
continue;
428+
429+
auto Alignment = BuiltinTypeDescriptor->getAlignment();
430+
if (Alignment <= 0)
431+
continue;
432+
// Reject any alignment that's not a power of two.
433+
if (Alignment & (Alignment - 1))
434+
continue;
435+
436+
auto CandidateMangledName =
437+
readTypeRef(BuiltinTypeDescriptor, BuiltinTypeDescriptor->TypeName);
438+
auto CandidateNormalizedName =
439+
normalizeReflectionName(CandidateMangledName);
440+
if (CandidateNormalizedName) {
441+
BuiltInTypeDescriptorCache.insert(
442+
std::make_pair(*CandidateNormalizedName, BuiltinTypeDescriptor));
443+
}
444+
}
445+
}
446+
418447
if (const auto found = BuiltInTypeDescriptorCache.find(MangledName);
419448
found != BuiltInTypeDescriptorCache.end()) {
420449
return found->second;

0 commit comments

Comments
 (0)