Skip to content

Add new runtime functions for handling dependencies when initializing class metadata #22386

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
16 changes: 16 additions & 0 deletions include/swift/Runtime/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,14 @@ void swift_initClassMetadata(ClassMetadata *self,
const TypeLayout * const *fieldTypes,
size_t *fieldOffsets);

SWIFT_RUNTIME_EXPORT SWIFT_CC(swift)
MetadataDependency
swift_initClassMetadata2(ClassMetadata *self,
ClassLayoutFlags flags,
size_t numFields,
const TypeLayout * const *fieldTypes,
size_t *fieldOffsets);

#if SWIFT_OBJC_INTEROP
/// Initialize various fields of the class metadata.
///
Expand All @@ -612,6 +620,14 @@ void swift_updateClassMetadata(ClassMetadata *self,
size_t numFields,
const TypeLayout * const *fieldTypes,
size_t *fieldOffsets);

SWIFT_RUNTIME_EXPORT SWIFT_CC(swift)
MetadataDependency
swift_updateClassMetadata2(ClassMetadata *self,
ClassLayoutFlags flags,
size_t numFields,
const TypeLayout * const *fieldTypes,
size_t *fieldOffsets);
#endif

/// Given class metadata, a class descriptor and a method descriptor, look up
Expand Down
28 changes: 28 additions & 0 deletions include/swift/Runtime/RuntimeFunctions.def
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,34 @@ FUNCTION(UpdateClassMetadata,
SizeTy->getPointerTo()),
ATTRS(NoUnwind))

// struct FieldInfo { size_t Size; size_t AlignMask; };
Copy link
Contributor

@beccadax beccadax Feb 5, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a comment fix, but what is this "FieldInfo"? Is it supposed to be the "TypeLayout" type mentioned in the comment's function signature?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. I just copied that comment from another declaration, but I can fix it.

// MetadataDependency swift_initClassMetadata2(Metadata *self,
// ClassLayoutFlags flags,
// size_t numFields,
// TypeLayout * const *fieldTypes,
// size_t *fieldOffsets);
FUNCTION(InitClassMetadata2,
swift_initClassMetadata2, SwiftCC,
RETURNS(TypeMetadataDependencyTy),
ARGS(TypeMetadataPtrTy, SizeTy, SizeTy,
Int8PtrPtrTy->getPointerTo(),
SizeTy->getPointerTo()),
ATTRS(NoUnwind))

// struct FieldInfo { size_t Size; size_t AlignMask; };
// MetadataDependency swift_updateClassMetadata2(Metadata *self,
// ClassLayoutFlags flags,
// size_t numFields,
// TypeLayout * const *fieldTypes,
// size_t *fieldOffsets);
FUNCTION(UpdateClassMetadata2,
swift_updateClassMetadata2, SwiftCC,
RETURNS(TypeMetadataDependencyTy),
ARGS(TypeMetadataPtrTy, SizeTy, SizeTy,
Int8PtrPtrTy->getPointerTo(),
SizeTy->getPointerTo()),
ATTRS(NoUnwind))

// void *swift_lookUpClassMethod(Metadata *metadata,
// ClassDescriptor *description,
// MethodDescriptor *method);
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/runtime/CompatibilityOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ using namespace swift;
struct OverrideSection {
uintptr_t version;

#define OVERRIDE(name, ret, attrs, namespace, typedArgs, namedArgs) \
#define OVERRIDE(name, ret, attrs, ccAttrs, namespace, typedArgs, namedArgs) \
Override_ ## name name;
#include "CompatibilityOverride.def"
};
Expand All @@ -61,7 +61,7 @@ static OverrideSection *getOverrideSectionPtr() {
return OverrideSectionPtr;
}

#define OVERRIDE(name, ret, attrs, namespace, typedArgs, namedArgs) \
#define OVERRIDE(name, ret, attrs, ccAttrs, namespace, typedArgs, namedArgs) \
Override_ ## name swift::getOverride_ ## name() { \
auto *Section = getOverrideSectionPtr(); \
if (Section == nullptr) \
Expand Down
54 changes: 28 additions & 26 deletions stdlib/public/runtime/CompatibilityOverride.def
Original file line number Diff line number Diff line change
Expand Up @@ -69,104 +69,106 @@
# endif
#endif

OVERRIDE_CASTING(dynamicCast, bool, , swift::,
OVERRIDE_CASTING(dynamicCast, bool, , , swift::,
(OpaqueValue *dest, OpaqueValue *src,
const Metadata *srcType,
const Metadata *targetType,
DynamicCastFlags flags),
(dest, src, srcType, targetType, flags))


OVERRIDE_CASTING(dynamicCastClass, const void *, , swift::,
OVERRIDE_CASTING(dynamicCastClass, const void *, , , swift::,
(const void *object,
const ClassMetadata *targetType),
(object, targetType))


OVERRIDE_CASTING(dynamicCastClassUnconditional, const void *, , swift::,
OVERRIDE_CASTING(dynamicCastClassUnconditional, const void *, , , swift::,
(const void *object,
const ClassMetadata *targetType,
const char *file, unsigned line, unsigned column),
(object, targetType, file, line, column))



OVERRIDE_CASTING(dynamicCastUnknownClass, const void *, , swift::,
OVERRIDE_CASTING(dynamicCastUnknownClass, const void *, , , swift::,
(const void *object, const Metadata *targetType),
(object, targetType))


OVERRIDE_CASTING(dynamicCastUnknownClassUnconditional, const void *, , swift::,
OVERRIDE_CASTING(dynamicCastUnknownClassUnconditional, const void *, , , swift::,
(const void *object, const Metadata *targetType,
const char *file, unsigned line, unsigned column),
(object, targetType, file, line, column))


OVERRIDE_CASTING(dynamicCastMetatype, const Metadata *, , swift::,
OVERRIDE_CASTING(dynamicCastMetatype, const Metadata *, , , swift::,
(const Metadata *sourceType,
const Metadata *targetType),
(sourceType, targetType))


OVERRIDE_CASTING(dynamicCastMetatypeUnconditional, const Metadata *, , swift::,
OVERRIDE_CASTING(dynamicCastMetatypeUnconditional, const Metadata *, , , swift::,
(const Metadata *sourceType,
const Metadata *targetType,
const char *file, unsigned line, unsigned column),
(sourceType, targetType, file, line, column))


OVERRIDE_FOREIGN(dynamicCastForeignClassMetatype, const ClassMetadata *, , swift::,
OVERRIDE_FOREIGN(dynamicCastForeignClassMetatype, const ClassMetadata *, , , swift::,
(const ClassMetadata *sourceType,
const ClassMetadata *targetType),
(sourceType, targetType))


OVERRIDE_FOREIGN(dynamicCastForeignClassMetatypeUnconditional,
const ClassMetadata *, , swift::,
const ClassMetadata *, , , swift::,
(const ClassMetadata *sourceType,
const ClassMetadata *targetType,
const char *file, unsigned line, unsigned column),
(sourceType, targetType, file, line, column))


OVERRIDE_PROTOCOLCONFORMANCE(conformsToProtocol, const WitnessTable *, , swift::,
OVERRIDE_PROTOCOLCONFORMANCE(conformsToProtocol, const WitnessTable *, , , swift::,
(const Metadata * const type,
const ProtocolDescriptor *protocol),
(type, protocol))

OVERRIDE_PROTOCOLCONFORMANCE(conformsToSwiftProtocol,
const ProtocolConformanceDescriptor *, , swift::,
const ProtocolConformanceDescriptor *, , , swift::,
(const Metadata * const type,
const ProtocolDescriptor *protocol,
StringRef moduleName),
(type, protocol, moduleName))

OVERRIDE_KEYPATH(getKeyPath, const HeapObject *, , swift::,
OVERRIDE_KEYPATH(getKeyPath, const HeapObject *, , , swift::,
(const void *pattern, const void *arguments),
(pattern, arguments))

OVERRIDE_METADATALOOKUP(getTypeByMangledNode, TypeInfo, , swift::,
(Demangler &demangler,
OVERRIDE_METADATALOOKUP(getTypeByMangledNode, TypeInfo, , SWIFT_CC(swift), swift::,
(MetadataRequest request,
Demangler &demangler,
Demangle::NodePointer node,
SubstGenericParameterFn substGenericParam,
SubstDependentWitnessTableFn substWitnessTable),
(demangler, node, substGenericParam, substWitnessTable))
OVERRIDE_METADATALOOKUP(getTypeByMangledName, TypeInfo, , swift::,
(StringRef typeName,
(request, demangler, node, substGenericParam, substWitnessTable))
OVERRIDE_METADATALOOKUP(getTypeByMangledName, TypeInfo, , SWIFT_CC(swift), swift::,
(MetadataRequest request,
StringRef typeName,
SubstGenericParameterFn substGenericParam,
SubstDependentWitnessTableFn substWitnessTable),
(typeName, substGenericParam, substWitnessTable))
(request, typeName, substGenericParam, substWitnessTable))

OVERRIDE_WITNESSTABLE(getAssociatedTypeWitnessSlow, MetadataResponse,
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERNAL, swift::,
SWIFT_RUNTIME_STDLIB_INTERNAL, SWIFT_CC(swift), swift::,
(MetadataRequest request, WitnessTable *wtable,
const Metadata *conformingType,
const ProtocolRequirement *reqBase,
const ProtocolRequirement *assocType),
(request, wtable, conformingType, reqBase, assocType))

OVERRIDE_WITNESSTABLE(getAssociatedConformanceWitnessSlow, const WitnessTable *,
SWIFT_CC(swift) SWIFT_RUNTIME_STDLIB_INTERNAL, swift::,
SWIFT_RUNTIME_STDLIB_INTERNAL, SWIFT_CC(swift), swift::,
(WitnessTable *wtable, const Metadata *conformingType,
const Metadata *assocType,
const ProtocolRequirement *reqBase,
Expand All @@ -175,37 +177,37 @@ OVERRIDE_WITNESSTABLE(getAssociatedConformanceWitnessSlow, const WitnessTable *,
assocConformance))
#if SWIFT_OBJC_INTEROP

OVERRIDE_OBJC(dynamicCastObjCClass, const void *, , swift::,
OVERRIDE_OBJC(dynamicCastObjCClass, const void *, , , swift::,
(const void *object,
const ClassMetadata *targetType),
(object, targetType))


OVERRIDE_OBJC(dynamicCastObjCClassUnconditional, const void *, , swift::,
OVERRIDE_OBJC(dynamicCastObjCClassUnconditional, const void *, , , swift::,
(const void *object,
const ClassMetadata *targetType,
const char *file, unsigned line, unsigned column),
(object, targetType, file, line, column))

OVERRIDE_OBJC(dynamicCastObjCClassMetatype, const ClassMetadata *, , swift::,
OVERRIDE_OBJC(dynamicCastObjCClassMetatype, const ClassMetadata *, , , swift::,
(const ClassMetadata *sourceType,
const ClassMetadata *targetType),
(sourceType, targetType))


OVERRIDE_OBJC(dynamicCastObjCClassMetatypeUnconditional, const ClassMetadata *, , swift::,
OVERRIDE_OBJC(dynamicCastObjCClassMetatypeUnconditional, const ClassMetadata *, , , swift::,
(const ClassMetadata *sourceType, const ClassMetadata *targetType,
const char *file, unsigned line, unsigned column),
(sourceType, targetType, file, line, column))


OVERRIDE_FOREIGN(dynamicCastForeignClass, const void *, , swift::,
OVERRIDE_FOREIGN(dynamicCastForeignClass, const void *, , , swift::,
(const void *object,
const ForeignClassMetadata *targetType),
(object, targetType))


OVERRIDE_FOREIGN(dynamicCastForeignClassUnconditional, const void *, , swift::,
OVERRIDE_FOREIGN(dynamicCastForeignClassUnconditional, const void *, , , swift::,
(const void *object, const ForeignClassMetadata *targetType,
const char *file, unsigned line, unsigned column),
(object, targetType, file, line, column))
Expand Down
16 changes: 8 additions & 8 deletions stdlib/public/runtime/CompatibilityOverride.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ namespace swift {

#define COMPATIBILITY_UNPAREN(...) __VA_ARGS__

#define OVERRIDE(name, ret, attrs, namespace, typedArgs, namedArgs) \
typedef ret (*Original_ ## name) typedArgs;
#define OVERRIDE(name, ret, attrs, ccAttrs, namespace, typedArgs, namedArgs) \
ccAttrs typedef ret (*Original_ ## name) typedArgs;
#include "CompatibilityOverride.def"

#define OVERRIDE(name, ret, attrs, namespace, typedArgs, namedArgs) \
typedef ret (*Override_ ## name)(COMPATIBILITY_UNPAREN typedArgs, \
Original_ ## name originalImpl);
#define OVERRIDE(name, ret, attrs, ccAttrs, namespace, typedArgs, namedArgs) \
ccAttrs typedef ret (*Override_ ## name)(COMPATIBILITY_UNPAREN typedArgs, \
Original_ ## name originalImpl);
#include "CompatibilityOverride.def"

#define OVERRIDE(name, ret, attrs, namespace, typedArgs, namedArgs) \
#define OVERRIDE(name, ret, attrs, ccAttrs, namespace, typedArgs, namedArgs) \
Override_ ## name getOverride_ ## name();
#include "CompatibilityOverride.def"

Expand All @@ -44,8 +44,8 @@ namespace swift {
/// OVERRIDE macro from CompatibilityOverride.def to this macro, then includes
/// the file to generate the override points. The original implementation of the
/// functionality must be available as swift_funcNameHereImpl.
#define COMPATIBILITY_OVERRIDE(name, ret, attrs, namespace, typedArgs, namedArgs) \
attrs ret namespace swift_ ## name typedArgs { \
#define COMPATIBILITY_OVERRIDE(name, ret, attrs, ccAttrs, namespace, typedArgs, namedArgs) \
attrs ccAttrs ret namespace swift_ ## name typedArgs { \
static Override_ ## name Override; \
static swift_once_t Predicate; \
swift_once(&Predicate, [](void *) { \
Expand Down
Loading