Skip to content

Move the metadata-pattern header into the type context descriptor #14826

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
2 changes: 2 additions & 0 deletions docs/ABI/Mangling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ Globals
global ::= type 'MP' // type metadata pattern
global ::= type 'Ma' // type metadata access function
global ::= type 'ML' // type metadata lazy cache variable
global ::= nominal-type 'Mi' // generic type instantiation function
global ::= nominal-type 'MI' // generic type instantiation cache
global ::= nominal-type 'Mm' // class metaclass
global ::= nominal-type 'Mn' // nominal type descriptor
global ::= module 'MXM' // module descriptor
Expand Down
2 changes: 2 additions & 0 deletions include/swift/Demangling/DemangleNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ NODE(TypeList)
NODE(TypeMangling)
NODE(TypeMetadata)
NODE(TypeMetadataAccessFunction)
NODE(TypeMetadataInstantiationCache)
NODE(TypeMetadataInstantiationFunction)
NODE(TypeMetadataLazyCache)
NODE(UncurriedFunctionType)
NODE(Unmanaged)
Expand Down
43 changes: 33 additions & 10 deletions include/swift/IRGen/Linking.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,8 @@ class LinkEntity {
// This field appears in the ValueWitness kind.
ValueWitnessShift = 8, ValueWitnessMask = 0xFF00,

// These fields appear in the TypeMetadata kind.
// This field appears in the TypeMetadata kind.
MetadataAddressShift = 8, MetadataAddressMask = 0x0300,
IsPatternShift = 10, IsPatternMask = 0x0400,

// This field appears in associated type access functions.
AssociatedTypeIndexShift = 8, AssociatedTypeIndexMask = ~KindMask,
Expand Down Expand Up @@ -148,6 +147,18 @@ class LinkEntity {
/// The pointer is a NominalTypeDecl*.
NominalTypeDescriptor,

/// The metadata pattern for a generic nominal type.
/// The pointer is a NominalTypeDecl*.
TypeMetadataPattern,

/// The instantiation cache for a generic nominal type.
/// The pointer is a NominalTypeDecl*.
TypeMetadataInstantiationCache,

/// The instantiation function for a generic nominal type.
/// The pointer is a NominalTypeDecl*.
TypeMetadataInstantiationFunction,

/// The module descriptor for a module.
/// The pointer is a ModuleDecl*.
ModuleDescriptor,
Expand Down Expand Up @@ -444,14 +455,18 @@ class LinkEntity {
}

static LinkEntity forTypeMetadata(CanType concreteType,
TypeMetadataAddress addr,
bool isPattern) {
TypeMetadataAddress addr) {
LinkEntity entity;
entity.Pointer = concreteType.getPointer();
entity.SecondaryPointer = nullptr;
entity.Data = LINKENTITY_SET_FIELD(Kind, unsigned(Kind::TypeMetadata))
| LINKENTITY_SET_FIELD(MetadataAddress, unsigned(addr))
| LINKENTITY_SET_FIELD(IsPattern, unsigned(isPattern));
| LINKENTITY_SET_FIELD(MetadataAddress, unsigned(addr));
return entity;
}

static LinkEntity forTypeMetadataPattern(NominalTypeDecl *decl) {
LinkEntity entity;
entity.setForDecl(Kind::TypeMetadataPattern, decl);
return entity;
}

Expand All @@ -461,6 +476,18 @@ class LinkEntity {
return entity;
}

static LinkEntity forTypeMetadataInstantiationCache(NominalTypeDecl *decl) {
LinkEntity entity;
entity.setForDecl(Kind::TypeMetadataInstantiationCache, decl);
return entity;
}

static LinkEntity forTypeMetadataInstantiationFunction(NominalTypeDecl *decl){
LinkEntity entity;
entity.setForDecl(Kind::TypeMetadataInstantiationFunction, decl);
return entity;
}

static LinkEntity forTypeMetadataLazyCacheVariable(CanType type) {
LinkEntity entity;
entity.setForType(Kind::TypeMetadataLazyCacheVariable, type);
Expand Down Expand Up @@ -726,10 +753,6 @@ class LinkEntity {
assert(getKind() == Kind::TypeMetadata);
return (TypeMetadataAddress)LINKENTITY_GET_FIELD(Data, MetadataAddress);
}
bool isMetadataPattern() const {
assert(getKind() == Kind::TypeMetadata);
return LINKENTITY_GET_FIELD(Data, IsPattern);
}
bool isForeignTypeMetadataCandidate() const {
return getKind() == Kind::ForeignTypeMetadataCandidate;
}
Expand Down
4 changes: 2 additions & 2 deletions include/swift/Remote/MetadataReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ class MetadataReader {
// If this class has a null descriptor, it's artificial,
// and we need to skip it upon request. Otherwise, we're done.
if (descriptorAddress || !skipArtificialSubclasses)
return static_cast<uintptr_t>(descriptorAddress);
return static_cast<StoredPointer>(descriptorAddress);

auto superclassMetadataAddress = classMeta->SuperClass;
if (!superclassMetadataAddress)
Expand All @@ -942,7 +942,7 @@ class MetadataReader {
case MetadataKind::Optional:
case MetadataKind::Enum: {
auto valueMeta = cast<TargetValueMetadata<Runtime>>(metadata);
return reinterpret_cast<uintptr_t>(valueMeta->getDescription());
return valueMeta->getDescription();
}

default:
Expand Down
4 changes: 3 additions & 1 deletion include/swift/Runtime/Exclusivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
namespace swift {

enum class ExclusivityFlags : uintptr_t;
struct ValueBuffer;
template <typename Runtime> struct TargetValueBuffer;
struct InProcess;
using ValueBuffer = TargetValueBuffer<InProcess>;

/// Begin dynamically tracking an access.
///
Expand Down
Loading