-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[embedded] Initial support for generic classes in embedded Swift #68461
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
[embedded] Initial support for generic classes in embedded Swift #68461
Conversation
- VTableSpecializer, a new pass that synthesizes a new vtable per each observed concrete type used - Don't use full type metadata refs in embedded Swift - Lazily emit specialized class metadata (LazySpecializedClassMetadata) in IRGen - Don't emit regular class metadata for a class decl if it's generic (only emit the specialized metadata)
…alized vtables have intentionally different ABIs from the non-generic one
… on non-final generic functions
@swift-ci please test |
@swift-ci please test |
@swift-ci please test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
@@ -3322,7 +3329,8 @@ IRGenFunction::emitTypeMetadataRef(CanType type, | |||
|
|||
if (type->hasArchetype() || | |||
!shouldTypeMetadataAccessUseAccessor(IGM, type) || | |||
isa<PackType>(type)) { | |||
isa<PackType>(type) || | |||
type->getASTContext().LangOpts.hasFeature(Feature::Embedded)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional nit: might be good to assert that type
is a class type so that it's easier to diagnose if this path is taken by a non-class-type accidentally (so we'd assert sooner).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is already covered by the assert at the top of the function.
/*ConvertIndirectToDirect=*/true, | ||
/*dropMetatypeArgs=*/false); | ||
|
||
if (!ReInfo.canBeSpecialized()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this would just be if it's not serialized, right?
llvm::errs() << "unsupported use of class method " | ||
<< newCM->getMember().getDecl()->getName() << " in function " | ||
<< newCM->getFunction()->getName() << '\n'; | ||
llvm::report_fatal_error("unsupported class method"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the case where this could happen? If there are uses of a class method that aren't an apply? For example escaping the function pointer maybe? Seems like some of these fatal errors should be turned into diagnostics (that can be a follow up though).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We discussed this with Erik a bit, and I think we concluded that this is something that you shouldn't be able to trigger this assert from any Swift source code, but it's technically possible to write (custom) SIL that fails this (e.g. by doing what you're saying, but SILGen or SILOptimizer shouldn't really ever produce that code).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
as?
) of class instances