From ab507becb45d08ef66a2c0547b8f9ad2a6b2b668 Mon Sep 17 00:00:00 2001 From: Augusto Noronha Date: Mon, 8 Dec 2025 14:35:11 -0800 Subject: [PATCH] [RemoteInspection] Factor out buildContextDescriptorManglingForSymbol A previous commit introduced the usage of buildContextManglingForSymbol in buildContextDescriptorMangling, which was not quite correct, since type nodes needed extra handling, which was done in the other version of buildContextDescriptorMangling. This patch factors out the handling of building context descriptors mangling from symbols, and updates both call sites to use the new function instead. rdar://165950673 --- include/swift/Remote/MetadataReader.h | 32 ++++++++++++++++++--------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/include/swift/Remote/MetadataReader.h b/include/swift/Remote/MetadataReader.h index 17e0b0dd855ce..6ff58aa1b0647 100644 --- a/include/swift/Remote/MetadataReader.h +++ b/include/swift/Remote/MetadataReader.h @@ -2643,6 +2643,26 @@ class MetadataReader { return resultAddress; } + Demangle::NodePointer + buildContextDescriptorManglingForSymbol(llvm::StringRef symbol, + Demangler &dem) { + if (auto demangledSymbol = buildContextManglingForSymbol(symbol, dem)) { + // Look through Type nodes since we're building up a mangling here. + if (demangledSymbol->getKind() == Demangle::Node::Kind::Type) { + demangledSymbol = demangledSymbol->getChild(0); + } + return demangledSymbol; + } + + return nullptr; + } + + Demangle::NodePointer + buildContextDescriptorManglingForSymbol(const std::string &symbol, + Demangler &dem) { + return buildContextDescriptorManglingForSymbol(dem.copyString(symbol), dem); + } + Demangle::NodePointer buildContextDescriptorMangling(const ParentContextDescriptorRef &descriptor, Demangler &dem, int recursion_limit) { @@ -2656,15 +2676,7 @@ class MetadataReader { // Try to demangle the symbol name to figure out what context it would // point to. - auto demangledSymbol = buildContextManglingForSymbol(descriptor.getSymbol(), - dem); - if (!demangledSymbol) - return nullptr; - // Look through Type notes since we're building up a mangling here. - if (demangledSymbol->getKind() == Demangle::Node::Kind::Type){ - demangledSymbol = demangledSymbol->getChild(0); - } - return demangledSymbol; + return buildContextDescriptorManglingForSymbol(descriptor.getSymbol(), dem); } Demangle::NodePointer @@ -2680,7 +2692,7 @@ class MetadataReader { Reader->resolvePointerAsSymbol(descriptor.getRemoteAddress())) { auto symbol = remoteAbsolutePointer->getSymbol(); if (!symbol.empty()) { - if (auto demangledSymbol = buildContextManglingForSymbol(symbol, dem)) { + if (auto demangledSymbol = buildContextDescriptorManglingForSymbol(symbol, dem)) { return demangledSymbol; } }