Skip to content

Commit 0181ea5

Browse files
authored
Merge pull request #22118 from DougGregor/remote-ast-private-types
[RemoteAST] Improve resolution of private types from metadata
2 parents bd4e2ad + 61d14ed commit 0181ea5

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
@@ -2808,22 +2808,80 @@ struct TargetExtensionContextDescriptor final
28082808

28092809
using ExtensionContextDescriptor = TargetExtensionContextDescriptor<InProcess>;
28102810

2811+
template<typename Runtime>
2812+
struct TargetMangledContextName {
2813+
/// The mangled name of the context.
2814+
TargetRelativeDirectPointer<Runtime, const char, /*nullable*/ false> name;
2815+
};
2816+
28112817
template<typename Runtime>
28122818
struct TargetAnonymousContextDescriptor final
28132819
: TargetContextDescriptor<Runtime>,
2814-
TrailingGenericContextObjects<TargetAnonymousContextDescriptor<Runtime>>
2820+
TrailingGenericContextObjects<TargetAnonymousContextDescriptor<Runtime>,
2821+
TargetGenericContextDescriptorHeader,
2822+
TargetMangledContextName<Runtime>>
28152823
{
28162824
private:
28172825
using TrailingGenericContextObjects
2818-
= TrailingGenericContextObjects<TargetAnonymousContextDescriptor<Runtime>>;
2826+
= TrailingGenericContextObjects<TargetAnonymousContextDescriptor<Runtime>,
2827+
TargetGenericContextDescriptorHeader,
2828+
TargetMangledContextName<Runtime>>;
2829+
using TrailingObjects =
2830+
typename TrailingGenericContextObjects::TrailingObjects;
2831+
friend TrailingObjects;
28192832

28202833
public:
2834+
using MangledContextName = TargetMangledContextName<Runtime>;
2835+
28212836
using TrailingGenericContextObjects::getGenericContext;
2837+
using TrailingGenericContextObjects::getGenericContextHeader;
2838+
using TrailingGenericContextObjects::getFullGenericContextHeader;
2839+
using TrailingGenericContextObjects::getGenericParams;
2840+
2841+
AnonymousContextDescriptorFlags getAnonymousContextDescriptorFlags() const {
2842+
return AnonymousContextDescriptorFlags(this->Flags.getKindSpecificFlags());
2843+
}
28222844

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

28282886
/// A protocol descriptor.
28292887
///

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)