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.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
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 ofContextDescriptors. Getting theMetadatafor non-generic types such asIntis no problem, but I'm struggling with generic types. TakeDictionaryas an example.Here’s how to get the
StructDescriptorforDictionary(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?.parametersreturns an array of 2GenericParameterDescriptors for the two generic parameters,KeyandValue. 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?.requirementsreturns an array of 1GenericRequirementDescriptor, representing theHashablerequirement 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.paramMangledNamewould 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