Skip to content

[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

Merged
merged 5 commits into from
Sep 13, 2023

Conversation

kubamracek
Copy link
Contributor

@kubamracek kubamracek commented Sep 12, 2023

  • 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)
  • Does not (yet?) support downcasts (as?) of class instances

- 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
@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek
Copy link
Contributor Author

@swift-ci please test

@kubamracek kubamracek added the embedded Embedded Swift label Sep 13, 2023
Copy link
Contributor

@eeckstein eeckstein left a 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)) {
Copy link
Contributor

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).

Copy link
Contributor Author

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()) {
Copy link
Contributor

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");
Copy link
Contributor

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).

Copy link
Contributor Author

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).

Copy link
Contributor

@zoecarver zoecarver left a comment

Choose a reason for hiding this comment

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

LGTM!

@kubamracek kubamracek merged commit b503f28 into swiftlang:main Sep 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
embedded Embedded Swift
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants