Skip to content

[5.0] Improve RemoteAST support for private types in LLDB #22136

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 60 additions & 2 deletions include/swift/ABI/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -2807,22 +2807,80 @@ struct TargetExtensionContextDescriptor final

using ExtensionContextDescriptor = TargetExtensionContextDescriptor<InProcess>;

template<typename Runtime>
struct TargetMangledContextName {
/// The mangled name of the context.
TargetRelativeDirectPointer<Runtime, const char, /*nullable*/ false> name;
};

template<typename Runtime>
struct TargetAnonymousContextDescriptor final
: TargetContextDescriptor<Runtime>,
TrailingGenericContextObjects<TargetAnonymousContextDescriptor<Runtime>>
TrailingGenericContextObjects<TargetAnonymousContextDescriptor<Runtime>,
TargetGenericContextDescriptorHeader,
TargetMangledContextName<Runtime>>
{
private:
using TrailingGenericContextObjects
= TrailingGenericContextObjects<TargetAnonymousContextDescriptor<Runtime>>;
= TrailingGenericContextObjects<TargetAnonymousContextDescriptor<Runtime>,
TargetGenericContextDescriptorHeader,
TargetMangledContextName<Runtime>>;
using TrailingObjects =
typename TrailingGenericContextObjects::TrailingObjects;
friend TrailingObjects;

public:
using MangledContextName = TargetMangledContextName<Runtime>;

using TrailingGenericContextObjects::getGenericContext;
using TrailingGenericContextObjects::getGenericContextHeader;
using TrailingGenericContextObjects::getFullGenericContextHeader;
using TrailingGenericContextObjects::getGenericParams;

AnonymousContextDescriptorFlags getAnonymousContextDescriptorFlags() const {
return AnonymousContextDescriptorFlags(this->Flags.getKindSpecificFlags());
}

/// Whether this anonymous context descriptor contains a full mangled name,
/// which can be used to match the anonymous type to its textual form.
bool hasMangledName() const {
return getAnonymousContextDescriptorFlags().hasMangledName();
}

/// Retrieve the mangled name of this context, or NULL if it was not
/// recorded in the metadata.
ConstTargetPointer<Runtime, char> getMangledName() const {
if (!hasMangledName())
return ConstTargetPointer<Runtime, char>();

return this->template getTrailingObjects<MangledContextName>()->name;
}

/// Retrieve a pointer to the mangled context name structure.
const MangledContextName *getMangledContextName() const {
if (!hasMangledName())
return nullptr;

return this->template getTrailingObjects<MangledContextName>();
}

private:
template<typename T>
using OverloadToken =
typename TrailingGenericContextObjects::template OverloadToken<T>;

using TrailingGenericContextObjects::numTrailingObjects;

size_t numTrailingObjects(OverloadToken<MangledContextName>) const {
return this->hasMangledNam() ? 1 : 0;
}

public:
static bool classof(const TargetContextDescriptor<Runtime> *cd) {
return cd->getKind() == ContextDescriptorKind::Anonymous;
}
};
using AnonymousContextDescriptor = TargetAnonymousContextDescriptor<InProcess>;

/// A protocol descriptor.
///
Expand Down
17 changes: 17 additions & 0 deletions include/swift/ABI/MetadataValues.h
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,23 @@ class ProtocolContextDescriptorFlags : public FlagSet<uint16_t> {
setSpecialProtocol)
};

/// Flags for anonymous type context descriptors. These values are used as the
/// kindSpecificFlags of the ContextDescriptorFlags for the anonymous context.
class AnonymousContextDescriptorFlags : public FlagSet<uint16_t> {
enum {
/// Whether this anonymous context descriptor is followed by its
/// mangled name, which can be used to match the descriptor at runtime.
HasMangledName = 0,
};

public:
explicit AnonymousContextDescriptorFlags(uint16_t bits) : FlagSet(bits) {}
constexpr AnonymousContextDescriptorFlags() {}

FLAGSET_DEFINE_FLAG_ACCESSORS(HasMangledName, hasMangledName,
setHasMangledName)
};

enum class GenericParamKind : uint8_t {
/// A type parameter.
Type = 0,
Expand Down
6 changes: 5 additions & 1 deletion include/swift/AST/IRGenOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ class IRGenOptions {
/// Emit names of struct stored properties and enum cases.
unsigned EnableReflectionNames : 1;

/// Emit mangled names of anonymous context descriptors.
unsigned EnableAnonymousContextMangledNames : 1;

/// Enables resilient class layout.
unsigned EnableClassResilience : 1;

Expand Down Expand Up @@ -224,7 +227,8 @@ class IRGenOptions {
EmitStackPromotionChecks(false), PrintInlineTree(false),
EmbedMode(IRGenEmbedMode::None), HasValueNamesSetting(false),
ValueNames(false), EnableReflectionMetadata(true),
EnableReflectionNames(true), EnableClassResilience(false),
EnableReflectionNames(true), EnableAnonymousContextMangledNames(false),
EnableClassResilience(false),
EnableResilienceBypass(false), LazyInitializeClassMetadata(false),
UseIncrementalLLVMCodeGen(true), UseSwiftCall(false),
GenerateProfile(false), EnableDynamicReplacementChaining(false),
Expand Down
4 changes: 4 additions & 0 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ def disable_llvm_value_names : Flag<["-"], "disable-llvm-value-names">,
def enable_llvm_value_names : Flag<["-"], "enable-llvm-value-names">,
HelpText<"Add names to local values in LLVM IR">;

def enable_anonymous_context_mangled_names :
Flag<["-"], "enable-anonymous-context-mangled-names">,
HelpText<"Enable emission of mangled names in anonymous context descriptors">;

def disable_reflection_metadata : Flag<["-"], "disable-reflection-metadata">,
HelpText<"Disable emission of reflection metadata for nominal types">;

Expand Down
Loading