Skip to content

[Runtime] Retrieve type metadata given a mangled name #13764

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 5 commits into from
Jan 6, 2018

Conversation

DougGregor
Copy link
Member

Start implementing support for computing a type given a mangled name at run time. This currently manifests as a very under implemented function in the standard library:

func _typeByMangledName(_ name: String) -> Any.Type?

Use the same TypeDecoder mangled-name-to-type logic from the remote mirrors library, but within the Swift runtime, to provide the mapping, translating directly into runtime calls.

As proof of concept, implement support for demangling tuple types within _typeByMangledName.

The remote reflection library has a fantastic utility class, TypeDecoder,
to take a mangled type and form an abstract type from it. Move this facility
into the Demangling library so other clients can use it.
Introduce a standard library/runtime entry point that produces type metadata
given a mangled name, based on the TypeDecoder logic lifted from the remote
mirrors library.

Implement support for tuple types as a proof-of-concept.
Fixes some issues in the type decoder with function flags not getting
set when forming function types.
@DougGregor DougGregor force-pushed the type-by-mangled-name branch from 02a2a9b to 83fd37a Compare January 6, 2018 00:25
…ed names.

Introduce basic support for existential types (just Any and AnyObject), so
we can test those, shared/owned parameters, and existential metatypes.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor DougGregor merged commit e04ded9 into swiftlang:master Jan 6, 2018
@DougGregor DougGregor deleted the type-by-mangled-name branch January 6, 2018 02:31
@DevAndArtist
Copy link
Contributor

DevAndArtist commented Jan 6, 2018

@DougGregor assuming we had a slightly different metatype system like Type<T> : AnyType<T>, wouldn't that mean that _typeByMangledName could be used to implement:

func subtype<T>(of type: Type<T>, named: String) -> AnyType<T>? 

I was referring to this idea.

@DougGregor
Copy link
Member Author

I guess you could do it by calling _typeByMangledName and then doing an as? cast (or simply an is) on the result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants