@@ -46,6 +46,21 @@ using namespace reflection;
46
46
#include < objc/objc.h>
47
47
#endif
48
48
49
+ // / Produce a Demangler value suitable for resolving runtime type metadata
50
+ // / strings.
51
+ static Demangler getDemanglerForRuntimeTypeResolution () {
52
+ Demangler dem;
53
+ // Resolve symbolic references to type contexts into the absolute address of
54
+ // the type context descriptor, so that if we see a symbolic reference in the
55
+ // mangled name we can immediately find the associated metadata.
56
+ dem.setSymbolicReferenceResolver ([&](int32_t offset,
57
+ const void *base) -> NodePointer {
58
+ auto absolute_addr = (uintptr_t )detail::applyRelativeOffset (base, offset);
59
+ return dem.createNode (Node::Kind::SymbolicReference, absolute_addr);
60
+ });
61
+ return dem;
62
+ }
63
+
49
64
template <typename T> struct DescriptorCacheEntry {
50
65
private:
51
66
std::string Name;
@@ -162,6 +177,14 @@ swift::_contextDescriptorMatchesMangling(const ContextDescriptor *context,
162
177
node = node->getChild (0 );
163
178
164
179
while (context) {
180
+ // We can directly match symbolic references to the current context.
181
+ if (node && node->getKind () == Demangle::Node::Kind::SymbolicReference) {
182
+ if (equalContexts (context, reinterpret_cast <const ContextDescriptor *>(
183
+ node->getIndex ()))) {
184
+ return true ;
185
+ }
186
+ }
187
+
165
188
switch (context->getKind ()) {
166
189
case ContextDescriptorKind::Module: {
167
190
auto module = cast<ModuleContextDescriptor>(context);
@@ -935,7 +958,7 @@ class DecodedMetadataBuilder {
935
958
TypeInfo
936
959
swift::_getTypeByMangledName (StringRef typeName,
937
960
SubstGenericParameterFn substGenericParam) {
938
- Demangler demangler;
961
+ auto demangler = getDemanglerForRuntimeTypeResolution () ;
939
962
NodePointer node;
940
963
941
964
// Check whether this is the convenience syntax "ModuleName.ClassName".
@@ -950,16 +973,6 @@ swift::_getTypeByMangledName(StringRef typeName,
950
973
return dotPos;
951
974
};
952
975
953
- // Resolve symbolic references to type contexts into the absolute address of
954
- // the type context descriptor, so that if we see a symbolic reference in the
955
- // mangled name we can immediately find the associated metadata.
956
- demangler.setSymbolicReferenceResolver (
957
- [&](int32_t offset, const void *base) -> NodePointer {
958
- auto absolute_addr = (uintptr_t )detail::applyRelativeOffset (base, offset);
959
- return demangler.createNode (Node::Kind::SymbolicReference,
960
- absolute_addr);
961
- });
962
-
963
976
auto dotPos = getDotPosForConvenienceSyntax ();
964
977
if (dotPos != llvm::StringRef::npos) {
965
978
// Form a demangle tree for this class.
@@ -1081,7 +1094,7 @@ void swift::swift_getFieldAt(
1081
1094
1082
1095
};
1083
1096
1084
- Demangler dem;
1097
+ auto dem = getDemanglerForRuntimeTypeResolution () ;
1085
1098
auto &cache = FieldCache.get ();
1086
1099
auto isRequestedDescriptor = [&](const FieldDescriptor &descriptor) {
1087
1100
assert (descriptor.hasMangledTypeName ());
0 commit comments