-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[embedded] Add support for (non-generic) classes in embedded Swift #68434
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
Conversation
- In embedded Swift, classes get a simplified metadata: Basically just a vtable + destructor + superclass pointer. - Only non-resilient (intended as permanent restriction), non-generic classes (for now) supported. - Relax the check that prohibits metadata emission and usage to allow classes.
@swift-ci please test |
asImpl().noteStartOfImmediateMembers(theClass); | ||
|
||
// Add vtable entries. | ||
asImpl().addVTableEntries(theClass); |
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.
Do we want the full vtable?
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.
Can we be more lazy and just emit the methods that are used? Or are we assuming that lto will strip them?
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'm actually assuming that SILOptimizer (namely PruneVTables and DeadFunctionElimination) will take care of that, because we can internalize public declarations in embedded Swift.
void irgen::emitEmbeddedClassMetadata(IRGenModule &IGM, ClassDecl *classDecl, | ||
const ClassLayout &fragileLayout) { | ||
assert(!classDecl->isForeign()); | ||
PrettyStackTraceDecl stackTraceRAII("emitting metadata for", classDecl); |
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.
Can you put this above the assertion? If the assertion fires, might be nice to have this diagnostic :)
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.
done!
@@ -0,0 +1,32 @@ | |||
// RUN: %target-swift-emit-ir %s -parse-stdlib -enable-experimental-feature Embedded -target arm64e-apple-none | %FileCheck %s |
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.
Test for calling methods?
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.
added!
// RUN: %target-swift-emit-ir %s -parse-stdlib -enable-experimental-feature Embedded -target arm64e-apple-none | %FileCheck %s | ||
|
||
// TODO: investigate why windows is generating more metadata. | ||
// XFAIL: OS=windows-msvc |
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.
No investigation needed. This is because swift compiler sources doesn't run on windows.
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.
removed!
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.
This is so awesome and exciting to see!!
@swift-ci please test |
@@ -4967,6 +4973,36 @@ void irgen::emitClassMetadata(IRGenModule &IGM, ClassDecl *classDecl, | |||
} | |||
} | |||
|
|||
void irgen::emitEmbeddedClassMetadata(IRGenModule &IGM, ClassDecl *classDecl, |
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.
Why do we need class embedded class metadata at all?
The vtable + pointer to superclass should provide everything which is needed for method dispatch and conditional down casting.
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.
You're right, and that's what this function is trying to do (to emit a simple metadata record with a vtable + superclass pointer), I think the only extra leftover is metadataBuilder.createMetadataAccessFunction();
which I'm removing in #68461
Add support for (non-generic) classes in embedded Swift