Replies: 1 comment
-
Update: I didn't make appreciable progress on my goal, but I wanted to give an update on additional things I found out.
|
Beta Was this translation helpful? Give feedback.
-
Update: I didn't make appreciable progress on my goal, but I wanted to give an update on additional things I found out.
|
Beta Was this translation helpful? Give feedback.
-
Awesome library!
I want to print a list of all types, including generic types. The output should be something like this (for a program that links Foundation):
I start out with
Echo.types
, which returns an array ofContextDescriptor
s. Getting theMetadata
for non-generic types such asInt
is no problem, but I'm struggling with generic types. TakeDictionary
as an example.Here’s how to get the
StructDescriptor
forDictionary
(extracted fromEcho.types
):I have to call the metadata access function to instantiate the
Metadata
. To do this for a generic type, I need to provide arguments for the generic parameters. If I know I'm dealing withDictionary
, this would look like this:But I don't know what type I'm dealing with. I'm looking for a generic (hah) solution that works for any type.
Here's where I'm struggling:
descriptor.genericContext?.parameters
returns an array of 2GenericParameterDescriptor
s for the two generic parameters,Key
andValue
. There's very little information in aGenericParameterDescriptor
, e.g. the parameter's name isn't part of the API. Q1: Are the names of a type's generic parameters not included in the type metadata?descriptor.genericContext?.requirements
returns an array of 1GenericRequirementDescriptor
, representing theHashable
requirement forKey
. Q2: How do I know which of the two generic params this requirement belongs to? From what I'm seeing, it could be either<Key: Hashable, Value>
or<Key, Value: Hashable>
or maybe even<Key: Hashable, Value: Hashable>
. I'm not sure how to tell the difference.I was hoping that
GenericRequirementDescriptor.paramMangledName
would give me more information, but when trying to extract this name, I only get"x"
forDictionary
. Is this code correct for turning the mangled name (UnsafeRawPointer
) into aString
?I wonder if what I want is actually possible. Thanks for any help!
Beta Was this translation helpful? Give feedback.
All reactions