Skip to content

[SR-589] Plumbing for dynamic instantiation of generic types #959

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

Closed
wants to merge 1 commit into from

Conversation

lhoward
Copy link
Contributor

@lhoward lhoward commented Jan 13, 2016

This extends b5880f3 with the infrastructure necessary to dynamically instantiate generic types by name. In order to do so it extends GenericParameterDescriptor::Parameter with a list of ProtocolDescriptors for primary associated type requirements.

Some notes:

  • This is "plumbing" as we have not defined a Swift API yet to lookup anything beyond a top-level non-generic class. The test suite uses private API taking a mangled type name in order to exercise this path.
  • There is no support for associated types, i.e. where NumParams != NumPrimaryParams. Still investigating how to implement this.
  • A recursive lock is used on the protocol conformance table, this may be unacceptable.

@lhoward lhoward force-pushed the SR-381-generic branch 30 times, most recently from e60cde2 to 2c951d9 Compare January 16, 2016 09:15
@lhoward lhoward force-pushed the SR-381-generic branch 3 times, most recently from 19417b8 to 2e51637 Compare January 21, 2016 07:06
@lhoward lhoward changed the title Plumbing for dynamic instantiation of generic types [StdLib] Plumbing for dynamic instantiation of generic types Jan 21, 2016
@lhoward lhoward changed the title [StdLib] Plumbing for dynamic instantiation of generic types [SR-589] Plumbing for dynamic instantiation of generic types Jan 21, 2016
@slavapestov
Copy link
Contributor

Hi @lhoward, I made some changes in this area that might require your attention:

65dd0e7
19fe31f

In particular, NominalTypeDescriptors now reference a metadata accessor function rather than a metadata pattern. Let me know if you need help with anything here.

@lhoward
Copy link
Contributor Author

lhoward commented Jan 28, 2016

Thanks for the heads up @slavapestov, won’t be able to take a look until next week but I will do then.

@lhoward
Copy link
Contributor Author

lhoward commented Feb 1, 2016 via email

This extends

    <swiftlang@b5880f3>

with the infrastructure necessary to dynamically instantiate generic types by
name. In order to do so it extends GenericParameterDescriptor::Parameter with a
list of ProtocolDescriptors containing associated type requirements.

NB: no support for secondary archetypes yet.

NB: this is "plumbing" as we have not defined a Swift API yet to lookup
anything beyond a top-level non-generic class. The test suite uses private API
taking a mangled type name in order to exercise this new code.
@tkremenek
Copy link
Member

@swift-ci please test

auto targetAddr = llvm::ConstantExpr::getPtrToInt(target.first, IGM.SizeTy);
auto offset = llvm::ConstantInt::get(IGM.SizeTy, getNextOffset().getValue());
// This seems incredibly baroque, we should be creating an LLVM struct?
// not sure how to define one with nested tail-emplaced values
Copy link
Contributor

Choose a reason for hiding this comment

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

Would an anonymous LLVM struct type work?

@CodaFi
Copy link
Contributor

CodaFi commented Aug 16, 2016

Because there hasn't been action on this in quite some time, I'm going to close this pull request. @lhoward thank you for your work here. Please reopen this if you wish to continue it.

@CodaFi CodaFi closed this Aug 16, 2016
@slavapestov
Copy link
Contributor

With the new remote reflection stuff that went in, the correct way to implement this functionality is now to write a library function for constructing Metadata from a TypeRef. Then we can also use this to replace the field type vectors in IRGen. Unless @lhoward wants to take this on, I'll be working on it some time in the coming year.

@lhoward
Copy link
Contributor Author

lhoward commented Aug 16, 2016

@slavapestov – I’ve not yet looked at the remote reflection stuff, but is this something the metadata lookup path for non-generic types (swift_getTypeByMangledName) should also be using?

@slavapestov
Copy link
Contributor

@lhoward Yes - the goal with the remote reflection stuff is to have one general mechanism for turning a mangled type string into a type. This should allow it to work for mangled function and tuple types, and so on, in full generality.

@lhoward
Copy link
Contributor Author

lhoward commented Aug 17, 2016 via email

MaxDesiatov pushed a commit to MaxDesiatov/swift that referenced this pull request May 12, 2020
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.

5 participants