-
Notifications
You must be signed in to change notification settings - Fork 26
MetadataAccessFunction
The Metadata Access Function is a special function within every type context descriptor that instantiates metadata of that type.
public struct MetadataAccessFunction
To give an example, consider the following:
struct Foo {}
struct Bar<T> {}
In this example, Foo
's metadata access function will just return the
already cached metadata, Foo.self
. Bar
in this case is special because
of the generic parameter meaning that any type can be held in there. The
Swift runtime does not instantiate every single type metadata combination
for Bar
, instead it instantiates type metadata for combinations that are
asked for through this metadata access function. For example:
// In this case we ask for the Bar<Int> which the Swift runtime will
// generate metadata for, but in our case we just want the context
// descriptor.
let metadata = reflectStruct(Bar<Int>.self)!
let accessor = metadata.descriptor.accessor
// Here we call the accessor to give us complete metadata with the first
// argument to be a `String`.
print(accessor(.complete, String.self).type) // Bar<String>
Calls the metadata access function.
public func callAsFunction(_ request: MetadataRequest) -> Echo.MetadataResponse
- request:
MetadataRequest
that instructs what state of metadata we want and whether we want to block or not. In most cases just ask for.complete
.
MetadataResponse
that has our requested metadata and tells us what state that metadata is in.
Calls the metadata access function for a type who has no conformances on their generic parameters.
public func callAsFunction(_ request: MetadataRequest, _ args: Any.Type) -> Echo.MetadataResponse
- request:
MetadataRequest
that instructs what state of metadata we want and whether we want to block or not. In most cases just ask for.complete
. - args: A variadic parameter for including generic arguments to types that have generic requirements in their type signature. This field MUST be correct for the function to work correctly.
MetadataResponse
that has our requested metadata and tells us what state that metadata is in.
Calls the metadata access function for a type who has generic arguments that require conformances.
public func callAsFunction(_ request: MetadataRequest, _ args: (Any.Type, WitnessTable?)) -> Echo.MetadataResponse
Example:
protocol Testable {}
extension Int: Testable {}
extension Double: Testable {}
struct Foo<T: Testable> {}
// We need to grab Int's testable witness table.
let testableMetadata = reflect(Testable.self) as! ExistentialMetadata
let testable = testableMetadata.protocols[0]
var intTestable: WitnessTable? = nil
// Iterate through all of Int's conformances to find the Testable
// conformance.
for conformance in reflectStruct(Int.self)!.conformances {
if conformance.protocol == testable {
assert(!conformance.flags.hasGenericWitnessTable)
intTestable = conformance.witnessTablePattern
}
}
let fooMetadata = reflectStruct(Foo<Double>.self)!
let fooAccessor = fooMetadata.descriptor.accessor
// Foo<Int>
print(fooAccessor(.complete, (Int.self, intTestable)).type)
- request:
MetadataRequest
that instructs what state of metadata we want and whether we want to block or not. In most cases just ask for.complete
. - args: A variadic parameter for including generic arguments and witness tables to types that have generic requirements and conformances in their type signature. This field MUST be correct for the function to work correctly.
MetadataResponse
that has our requested metadata and tells us what state that metadata is in.
Generated at 2021-05-06T17:56:33+0000 using swift-doc 1.0.0-beta.6.
Types
- AnonymousDescriptor
- AnonymousDescriptor.Flags
- AnyExistentialContainer
- BoxPair
- ClassDescriptor
- ClassMetadata
- ClassMetadata.Flags
- ConformanceDescriptor
- ConformanceDescriptor.Flags
- ContextDescriptorFlags
- ContextDescriptorKind
- DualExistentialContainer
- EnumDescriptor
- EnumMetadata
- EnumValueWitnessTable
- ExistentialContainer
- ExistentialMetadata
- ExistentialMetadata.Flags
- ExistentialMetatypeMetadata
- ExtensionDescriptor
- FieldDescriptor
- FieldDescriptor.Kind
- FieldRecord
- FieldRecord.Flags
- ForeignClassMetadata
- ForeignMetadataInitialization
- FunctionConvention
- FunctionMetadata
- FunctionMetadata.Flags
- FunctionMetadata.ParamFlags
- GenericContext
- GenericMetadataPattern
- GenericMetadataPattern.Flags
- GenericParameterDescriptor
- GenericParameterKind
- GenericRequirementDescriptor
- GenericRequirementDescriptor.Flags
- GenericRequirementKind
- GenericRequirementLayoutKind
- HeapGenericLocalVariableMetadata
- HeapLocalVariableMetadata
- HeapObject
- KnownMetadata
- KnownMetadata.Builtin
- MetadataAccessFunction
- MetadataBounds
- MetadataInitializationKind
- MetadataKind
- MetadataRequest
- MetadataResponse
- MetadataState
- MetatypeMetadata
- MethodDescriptor
- MethodDescriptor.Flags
- MethodDescriptor.Kind
- MethodOverrideDescriptor
- ModuleDescriptor
- ObjCClassWrapperMetadata
- OpaqueDescriptor
- OpaqueMetadata
- OverrideTableHeader
- ProtocolDescriptor
- ProtocolDescriptor.Flags
- ProtocolRequirement
- ProtocolRequirement.Flags
- ProtocolRequirement.Kind
- ReferenceStorageKind
- SingletonMetadataInitialization
- SpecialProtocol
- StructDescriptor
- StructMetadata
- TupleMetadata
- TupleMetadata.Element
- TypeContextDescriptorFlags
- TypeGenericContext
- TypeReferenceKind
- VTableDescriptorHeader
- ValueOwnership
- ValueWitnessTable
- ValueWitnessTable.Flags
- WitnessTable