Skip to content

Commit 696330e

Browse files
authored
Merge pull request #22136 from DougGregor/remote-ast-private-types-5.0
[5.0] Improve RemoteAST support for private types in LLDB
2 parents a8a9978 + c4139d6 commit 696330e

File tree

13 files changed

+379
-83
lines changed

13 files changed

+379
-83
lines changed

include/swift/ABI/Metadata.h

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,22 +2807,80 @@ struct TargetExtensionContextDescriptor final
28072807

28082808
using ExtensionContextDescriptor = TargetExtensionContextDescriptor<InProcess>;
28092809

2810+
template<typename Runtime>
2811+
struct TargetMangledContextName {
2812+
/// The mangled name of the context.
2813+
TargetRelativeDirectPointer<Runtime, const char, /*nullable*/ false> name;
2814+
};
2815+
28102816
template<typename Runtime>
28112817
struct TargetAnonymousContextDescriptor final
28122818
: TargetContextDescriptor<Runtime>,
2813-
TrailingGenericContextObjects<TargetAnonymousContextDescriptor<Runtime>>
2819+
TrailingGenericContextObjects<TargetAnonymousContextDescriptor<Runtime>,
2820+
TargetGenericContextDescriptorHeader,
2821+
TargetMangledContextName<Runtime>>
28142822
{
28152823
private:
28162824
using TrailingGenericContextObjects
2817-
= TrailingGenericContextObjects<TargetAnonymousContextDescriptor<Runtime>>;
2825+
= TrailingGenericContextObjects<TargetAnonymousContextDescriptor<Runtime>,
2826+
TargetGenericContextDescriptorHeader,
2827+
TargetMangledContextName<Runtime>>;
2828+
using TrailingObjects =
2829+
typename TrailingGenericContextObjects::TrailingObjects;
2830+
friend TrailingObjects;
28182831

28192832
public:
2833+
using MangledContextName = TargetMangledContextName<Runtime>;
2834+
28202835
using TrailingGenericContextObjects::getGenericContext;
2836+
using TrailingGenericContextObjects::getGenericContextHeader;
2837+
using TrailingGenericContextObjects::getFullGenericContextHeader;
2838+
using TrailingGenericContextObjects::getGenericParams;
2839+
2840+
AnonymousContextDescriptorFlags getAnonymousContextDescriptorFlags() const {
2841+
return AnonymousContextDescriptorFlags(this->Flags.getKindSpecificFlags());
2842+
}
28212843

2844+
/// Whether this anonymous context descriptor contains a full mangled name,
2845+
/// which can be used to match the anonymous type to its textual form.
2846+
bool hasMangledName() const {
2847+
return getAnonymousContextDescriptorFlags().hasMangledName();
2848+
}
2849+
2850+
/// Retrieve the mangled name of this context, or NULL if it was not
2851+
/// recorded in the metadata.
2852+
ConstTargetPointer<Runtime, char> getMangledName() const {
2853+
if (!hasMangledName())
2854+
return ConstTargetPointer<Runtime, char>();
2855+
2856+
return this->template getTrailingObjects<MangledContextName>()->name;
2857+
}
2858+
2859+
/// Retrieve a pointer to the mangled context name structure.
2860+
const MangledContextName *getMangledContextName() const {
2861+
if (!hasMangledName())
2862+
return nullptr;
2863+
2864+
return this->template getTrailingObjects<MangledContextName>();
2865+
}
2866+
2867+
private:
2868+
template<typename T>
2869+
using OverloadToken =
2870+
typename TrailingGenericContextObjects::template OverloadToken<T>;
2871+
2872+
using TrailingGenericContextObjects::numTrailingObjects;
2873+
2874+
size_t numTrailingObjects(OverloadToken<MangledContextName>) const {
2875+
return this->hasMangledNam() ? 1 : 0;
2876+
}
2877+
2878+
public:
28222879
static bool classof(const TargetContextDescriptor<Runtime> *cd) {
28232880
return cd->getKind() == ContextDescriptorKind::Anonymous;
28242881
}
28252882
};
2883+
using AnonymousContextDescriptor = TargetAnonymousContextDescriptor<InProcess>;
28262884

28272885
/// A protocol descriptor.
28282886
///

include/swift/ABI/MetadataValues.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1344,6 +1344,23 @@ class ProtocolContextDescriptorFlags : public FlagSet<uint16_t> {
13441344
setSpecialProtocol)
13451345
};
13461346

1347+
/// Flags for anonymous type context descriptors. These values are used as the
1348+
/// kindSpecificFlags of the ContextDescriptorFlags for the anonymous context.
1349+
class AnonymousContextDescriptorFlags : public FlagSet<uint16_t> {
1350+
enum {
1351+
/// Whether this anonymous context descriptor is followed by its
1352+
/// mangled name, which can be used to match the descriptor at runtime.
1353+
HasMangledName = 0,
1354+
};
1355+
1356+
public:
1357+
explicit AnonymousContextDescriptorFlags(uint16_t bits) : FlagSet(bits) {}
1358+
constexpr AnonymousContextDescriptorFlags() {}
1359+
1360+
FLAGSET_DEFINE_FLAG_ACCESSORS(HasMangledName, hasMangledName,
1361+
setHasMangledName)
1362+
};
1363+
13471364
enum class GenericParamKind : uint8_t {
13481365
/// A type parameter.
13491366
Type = 0,

include/swift/AST/IRGenOptions.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,9 @@ class IRGenOptions {
165165
/// Emit names of struct stored properties and enum cases.
166166
unsigned EnableReflectionNames : 1;
167167

168+
/// Emit mangled names of anonymous context descriptors.
169+
unsigned EnableAnonymousContextMangledNames : 1;
170+
168171
/// Enables resilient class layout.
169172
unsigned EnableClassResilience : 1;
170173

@@ -224,7 +227,8 @@ class IRGenOptions {
224227
EmitStackPromotionChecks(false), PrintInlineTree(false),
225228
EmbedMode(IRGenEmbedMode::None), HasValueNamesSetting(false),
226229
ValueNames(false), EnableReflectionMetadata(true),
227-
EnableReflectionNames(true), EnableClassResilience(false),
230+
EnableReflectionNames(true), EnableAnonymousContextMangledNames(false),
231+
EnableClassResilience(false),
228232
EnableResilienceBypass(false), LazyInitializeClassMetadata(false),
229233
UseIncrementalLLVMCodeGen(true), UseSwiftCall(false),
230234
GenerateProfile(false), EnableDynamicReplacementChaining(false),

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,10 @@ def disable_llvm_value_names : Flag<["-"], "disable-llvm-value-names">,
272272
def enable_llvm_value_names : Flag<["-"], "enable-llvm-value-names">,
273273
HelpText<"Add names to local values in LLVM IR">;
274274

275+
def enable_anonymous_context_mangled_names :
276+
Flag<["-"], "enable-anonymous-context-mangled-names">,
277+
HelpText<"Enable emission of mangled names in anonymous context descriptors">;
278+
275279
def disable_reflection_metadata : Flag<["-"], "disable-reflection-metadata">,
276280
HelpText<"Disable emission of reflection metadata for nominal types">;
277281

0 commit comments

Comments
 (0)