-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Remove three ObjC metadata fields from non-ObjC runtime #31811
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
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.
Seems reasonable to me.
StoredPointer dataPtr; | ||
if (!Reader->readInteger(RemoteAddress(classAddress + | ||
TargetClassMetadata<Runtime>::offsetToData()), | ||
&dataPtr)) | ||
return StoredPointer(); | ||
#else | ||
StoredPointer dataPtr = SWIFT_CLASS_IS_SWIFT_MASK; |
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 can just return StoredPointer();
here. You'll end up hitting the if (!dataPtr)
path a few lines later anyway.
Ideally, MetadataReader wouldn't be sensitive to target #if conditions, and instead ObjC interop-ness would be reflected in the Target abstraction. That would e.g. allow tools built one way to debug/analyze programs built the other. To make that work, you'll have to play some template games in Metadata.h, but it shouldn't be too bad. |
You are correct that the non-Darwin ABI is still up for grabs. I agree with @rjmccall that it'd be nice if we could make this dependent on the A good followup for non-Darwin optimization would be to start treating class objects as being directly referenceable as metadata, like struct/enum metadata is, since there's no ObjC realization to worry about. That should save a good amount of code size from metadata accesses, and allow dynamic class metadata instantiation for generic or resilient classes to be more efficient and avoid some synchronization that's necessary on Darwin to coordinate with ObjC realization. |
Yeah. It'll need some new logic in order to check for transitive direct-referenceability of superclasses, since right now the condition is just "no, you can't emit this reference directly", but it should be possible to be much more efficient than we are on ObjC-interop platforms. |
lib/IRGen/ClassMetadataVisitor.h
Outdated
@@ -65,8 +65,10 @@ template <class Impl> class ClassMetadataVisitor | |||
// FIXME: Figure out what can be removed altogether in non-objc-interop | |||
// mode and remove it. rdar://problem/18801263 |
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.
Does this not address this FIXME?
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.
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.
The three extra padding fields seem like the biggest obvious thing to remove. I can't off the top of my head think of any other places where we could wholesale remove fields. I'd be fine removing the fixme.
That addresses it for classes, which is the scope of this particular FIXME. Assuming that we're not interested in highly-disruptive layout changes like putting the VWT at a positive offset, I think most of the other ways that ObjC inserts itself into the runtime representation are just extra alternatives in various metadata references — things like protocol references possibly being to ObjC protocols, or type references possibly being to ObjC classes.
I think it's fine to make MetadataReader work cross-ObjC-interop in a different patch. Please base the conditionalization in Metadata.h on the Runtime parameter, though, otherwise it's just not being done right. |
If we base the presence of the ObjC compatibility fields on the |
For this, at least. Dave is right that there are existing |
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please test windows |
Hi @jckarter – If you point me at a few lines of code to see the difference you're talking about, then I can make an attempt at fixing it. |
@swift-ci please test macos |
Hi @compnerd – Does |
Build failed |
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please clean test macos |
Build failed |
@swift-ci please test |
@swift-ci please test windows |
Build failed |
Build failed |
@swift-ci please test windows |
@swift-ci please test |
Build failed |
Build failed |
@davezarzycki If you want to look into making class metadata statically addressable, a good place to start looking would be |
@swift-ci please test Windows platform |
Adjust the test to accommodate environments which do indirect imports, which use the singleton strategy, relying on the runtime initialization of fields which are imported.
#31981 has the test adjustments needed for this. Could you please grab the top commit and put it into this PR? |
@swift-ci please test Windows platform |
@swift-ci please test |
Build failed |
Build failed |
@swift-ci please test Windows platform |
1 similar comment
@swift-ci please test Windows platform |
Yeap, that looks unrelated to this change. sigh time to go track that down. |
Hi @rjmccall – Before I finish this draft pull request, I'd like to verify that:
I'll finish fixing all the broken tests if this is the case. Thanks! As a bonus, what other fields are good candidates for removal from the non-ObjC runtime?
[EDIT] – A related followup question for a followup PR: Should the vtable layout be more like C++? I.e. where the positive displacements are vtable slots and the negative displacements are language/runtime metadata? This would allow for better code density.