@@ -669,18 +669,16 @@ SwiftLanguageRuntimeImpl::GetNumChildren(CompilerType type,
669669 return {};
670670
671671 ThreadSafeReflectionContext reflection_ctx = GetReflectionContext ();
672- auto &builder = reflection_ctx->GetBuilder ();
673- auto tc = swift::reflection::TypeConverter (builder);
674672 LLDBTypeInfoProvider tip (*this , *ts);
675- auto *cti = tc. getClassInstanceTypeInfo (tr, 0 , &tip);
673+ auto *cti = reflection_ctx-> GetClassInstanceTypeInfo (tr, &tip);
676674 if (auto *rti =
677675 llvm::dyn_cast_or_null<swift::reflection::RecordTypeInfo>(cti)) {
678676 LLDB_LOGF (GetLog (LLDBLog::Types),
679677 " %s: class RecordTypeInfo(num_fields=%i)" ,
680678 type.GetMangledTypeName ().GetCString (), rti->getNumFields ());
681679
682680 // The superclass, if any, is an extra child.
683- if (builder. lookupSuperclass (tr))
681+ if (reflection_ctx-> LookupSuperclass (tr))
684682 return rti->getNumFields () + 1 ;
685683 return rti->getNumFields ();
686684 }
@@ -743,9 +741,9 @@ SwiftLanguageRuntimeImpl::GetNumFields(CompilerType type,
743741 return referent.GetNumFields (exe_ctx);
744742 return 0 ;
745743 case ReferenceKind::Strong:
746- TypeConverter tc ( GetReflectionContext ()-> GetBuilder () );
744+ ThreadSafeReflectionContext reflection_ctx = GetReflectionContext ();
747745 LLDBTypeInfoProvider tip (*this , *ts);
748- auto *cti = tc. getClassInstanceTypeInfo (tr, 0 , &tip);
746+ auto *cti = reflection_ctx-> GetClassInstanceTypeInfo (tr, &tip);
749747 if (auto *rti = llvm::dyn_cast_or_null<RecordTypeInfo>(cti)) {
750748 return rti->getNumFields ();
751749 }
@@ -876,18 +874,16 @@ SwiftLanguageRuntimeImpl::GetIndexOfChildMemberWithName(
876874 child_indexes);
877875 case ReferenceKind::Strong: {
878876 ThreadSafeReflectionContext reflection_ctx = GetReflectionContext ();
879- auto &builder = reflection_ctx->GetBuilder ();
880- TypeConverter tc (builder);
881877 LLDBTypeInfoProvider tip (*this , *ts);
882878 // `current_tr` iterates the class hierarchy, from the current class, each
883879 // superclass, and ends on null.
884880 auto *current_tr = tr;
885881 while (current_tr) {
886882 auto *record_ti = llvm::dyn_cast_or_null<RecordTypeInfo>(
887- tc. getClassInstanceTypeInfo (current_tr, 0 , &tip));
883+ reflection_ctx-> GetClassInstanceTypeInfo (current_tr, &tip));
888884 if (!record_ti)
889885 break ;
890- auto *super_tr = builder. lookupSuperclass (current_tr);
886+ auto *super_tr = reflection_ctx-> LookupSuperclass (current_tr);
891887 uint32_t offset = super_tr ? 1 : 0 ;
892888 auto found_size = findFieldWithName (record_ti->getFields (), name, false ,
893889 child_indexes, offset);
@@ -1393,18 +1389,13 @@ bool SwiftLanguageRuntimeImpl::GetDynamicTypeAndAddress_Pack(
13931389 });
13941390
13951391 // Build a TypeRef from the demangle tree.
1396- auto typeref_or_err =
1397- decodeMangledType (reflection_ctx->GetBuilder (), pack_element);
1398- if (typeref_or_err.isError ()) {
1399- LLDB_LOGF (log, " Couldn't get TypeRef for %s" ,
1400- pack_type.GetMangledTypeName ().GetCString ());
1392+ auto type_ref = reflection_ctx->GetTypeRefOrNull (dem, pack_element);
1393+ if (!type_ref)
14011394 return {};
1402- }
1403- auto typeref = typeref_or_err.getType ();
14041395
14051396 // Apply the substitutions.
14061397 auto bound_typeref =
1407- typeref-> subst ( reflection_ctx->GetBuilder () , substitutions);
1398+ reflection_ctx->ApplySubstitutions (type_ref , substitutions);
14081399 swift::Demangle::NodePointer node = bound_typeref->getDemangling (dem);
14091400 CompilerType type = ts->RemangleAsType (dem, node);
14101401
@@ -1818,11 +1809,10 @@ CompilerType SwiftLanguageRuntimeImpl::BindGenericTypeParameters(
18181809 Demangler dem;
18191810 NodePointer unbound_node =
18201811 dem.demangleSymbol (unbound_type.GetMangledTypeName ().GetStringRef ());
1821- auto type_ref_or_err =
1822- decodeMangledType (reflection_ctx->GetBuilder (), unbound_node);
1823- if (type_ref_or_err.isError ()) {
1812+ auto type_ref = reflection_ctx->GetTypeRefOrNull (dem, unbound_node);
1813+ if (!type_ref) {
18241814 LLDB_LOG (GetLog (LLDBLog::Expressions | LLDBLog::Types),
1825- " Couldn't get TypeRef of unbound type. " );
1815+ " Couldn't get TypeRef of unbound type" );
18261816 return {};
18271817 }
18281818
@@ -1842,28 +1832,24 @@ CompilerType SwiftLanguageRuntimeImpl::BindGenericTypeParameters(
18421832 return ;
18431833 }
18441834
1845- NodePointer child_node =
1846- dem.demangleSymbol (type.GetMangledTypeName ().GetStringRef ());
1847- auto type_ref_or_err =
1848- decodeMangledType (reflection_ctx->GetBuilder (), child_node);
1849- if (type_ref_or_err.isError ()) {
1835+ auto type_ref = reflection_ctx->GetTypeRefOrNull (
1836+ type.GetMangledTypeName ().GetStringRef ());
1837+ if (!type_ref) {
18501838 LLDB_LOG (GetLog (LLDBLog::Expressions | LLDBLog::Types),
18511839 " Couldn't get TypeRef when binding generic type parameters." );
18521840 failure = true ;
18531841 return ;
18541842 }
18551843
1856- substitutions.insert ({{depth, index}, type_ref_or_err. getType () });
1844+ substitutions.insert ({{depth, index}, type_ref });
18571845 });
18581846
18591847 if (failure)
18601848 return {};
18611849
1862- const swift::reflection::TypeRef *type_ref = type_ref_or_err.getType ();
1863-
18641850 // Apply the substitutions.
18651851 const swift::reflection::TypeRef *bound_type_ref =
1866- type_ref-> subst ( reflection_ctx->GetBuilder () , substitutions);
1852+ reflection_ctx->ApplySubstitutions (type_ref , substitutions);
18671853 NodePointer node = bound_type_ref->getDemangling (dem);
18681854 return ts->GetTypeSystemSwiftTypeRef ().RemangleAsType (dem, node);
18691855}
@@ -1918,18 +1904,14 @@ SwiftLanguageRuntimeImpl::BindGenericTypeParameters(StackFrame &stack_frame,
19181904 return get_canonical ();
19191905
19201906 // Build a TypeRef from the demangle tree.
1921- auto type_ref_or_err =
1922- decodeMangledType (reflection_ctx->GetBuilder (), canonical);
1923- if (type_ref_or_err.isError ()) {
1924- LLDB_LOG (GetLog (LLDBLog::Expressions | LLDBLog::Types),
1925- " Couldn't get TypeRef" );
1907+ const swift::reflection::TypeRef *type_ref =
1908+ reflection_ctx->GetTypeRefOrNull (dem, canonical);
1909+ if (!type_ref)
19261910 return get_canonical ();
1927- }
1928- const swift::reflection::TypeRef *type_ref = type_ref_or_err.getType ();
19291911
19301912 // Apply the substitutions.
19311913 const swift::reflection::TypeRef *bound_type_ref =
1932- type_ref-> subst ( reflection_ctx->GetBuilder () , substitutions);
1914+ reflection_ctx->ApplySubstitutions (type_ref , substitutions);
19331915 NodePointer node = bound_type_ref->getDemangling (dem);
19341916
19351917 // Import the type into the scratch context. Subsequent conversions
@@ -2647,32 +2629,16 @@ SwiftLanguageRuntimeImpl::GetTypeRef(CompilerType type,
26472629 if (!reflection_ctx)
26482630 return nullptr ;
26492631
2650- auto type_ref_or_err =
2651- swift::Demangle::decodeMangledType (reflection_ctx->GetBuilder (), node);
2652- if (type_ref_or_err.isError ()) {
2653- LLDB_LOGF (log,
2654- " [SwiftLanguageRuntimeImpl::GetTypeRef] Could not find typeref "
2655- " for type: %s. Decode mangled type failed. Error: %s\n ." ,
2656- type.GetMangledTypeName ().GetCString (),
2657- type_ref_or_err.getError ()->copyErrorString ());
2632+ auto type_ref = reflection_ctx->GetTypeRefOrNull (dem, node);
2633+ if (!type_ref)
26582634 return nullptr ;
2659- }
2660- const swift::reflection::TypeRef *type_ref = type_ref_or_err.getType ();
2661- if (type_ref) {
2662- if (log && log->GetVerbose ()) {
2663- std::stringstream ss;
2664- type_ref->dump (ss);
2665- LLDB_LOGF (log,
2666- " [SwiftLanguageRuntimeImpl::GetTypeRef] Found typeref for "
2667- " type: %s:\n %s" ,
2668- type.GetMangledTypeName ().GetCString (), ss.str ().c_str ());
2669- }
2670- } else {
2671- LLDB_LOGF (
2672- log,
2673- " [SwiftLanguageRuntimeImpl::GetTypeRef] could not find typeref for "
2674- " type: %s:\n " ,
2675- type.GetMangledTypeName ().GetCString ());
2635+ if (log && log->GetVerbose ()) {
2636+ std::stringstream ss;
2637+ type_ref->dump (ss);
2638+ LLDB_LOGF (log,
2639+ " [SwiftLanguageRuntimeImpl::GetTypeRef] Found typeref for "
2640+ " type: %s:\n %s" ,
2641+ type.GetMangledTypeName ().GetCString (), ss.str ().c_str ());
26762642 }
26772643 return type_ref;
26782644}
0 commit comments