-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SIL]/[SILOpt] Thunks and specializations are never public. #16959
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
@swift-ci please test |
Build failed |
include/swift/SIL/SILFunction.h
Outdated
@@ -430,6 +430,11 @@ class SILFunction | |||
/// method itself, the function can be referenced from vtables of derived | |||
/// classes in other compilation units. | |||
SILLinkage getEffectiveSymbolLinkage() const { | |||
// These are implementations details that don't get special treatment: their | |||
// stored linkage is the correct one. | |||
if (isThunk() || isSpecialization()) |
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 think it would make more sense to turn this into an assertion and fix those places that create thunks no?
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.
Hm, I'm not sure: this is called in places that have just an arbitrary SILFunction
:
We could push this condition down to them, but I'm not sure it makes sense. To me, it seems reasonable to say that getEffectiveSymbolLinkage
is the way to get the true IR/ELF/mach-O linkage, and thus having this split here is the right place.
Maybe I'm not understanding what you're visualizing?
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 suggesting that getClassSubclassScope()
should not be set on thunks. Whoever is creating the thunk's SILFunction is also setting getClassSubclassScope()
, which seems clearly wrong.
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.
Ah, I had misunderstood. That sounds good.
Linux failure (for future reference):
|
Mm. What about override thunks, for concrete subclasses of generic classes?
|
@jrose-apple Override thunks get emitted in each translation unit that has a vtable for a subclass of the class. So you're still relying on the original method having public linkage. |
dd923dd
to
0c67e56
Compare
@swift-ci please test |
Build failed |
@swift-ci please test source compatibility |
0c67e56
to
4b5c62c
Compare
@swift-ci please test @slavapestov I've changed to not setting the subclass scope on thunks, except for signature-optimised thunks, since in that case the original entry point to the code gets marked as a thunk, and thus that needs to have the right subclass scope, so that it remains public if it is |
@swift-ci please smoke test |
include/swift/SIL/SILFunction.h
Outdated
void setThunk(IsThunk_t isThunk, bool forSignatureOptimization = false) { | ||
// The _original_ function for a method can turn into a thunk through | ||
// signature optimization, meaning it needs to retain its subclassScope | ||
assert(getClassSubclassScope() == SubclassScope::NotApplicable || |
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 seems overkill. If you're intent on keeping this, you should add a new case to IsThunk_t for signature-optimized thunks. A future assertion could also ensure that any thunk other than a signature thunk is shared or private, etc.
4b5c62c
to
9576d5d
Compare
@swift-ci please smoke test |
Signature optimization is slightly different to (most) other thunks, in that it's taking an existing function and turning that into a thunk, rather than creating a thunk that calls an existing function. These symbols can be public, etc. and so need to be handled a bit different to other types of thunks.
…heir parent class. The "subclass scope" is meant to represent a connection to a vtable (and how public something needs to be), for things that end up in class vtables. Specializations and thunks are mostly internal implementation details and do not end up there, so subclass scope is not applicable to them. This stops the thunks and specializations being incorrectly public. (Note, there are some thunks that _are_ public facing: if a function has its signature optimized, the original entry point becomes a thunk, and this entry point is what ends up in vtables etc., so needs to remain around, which means keeping the same hacks for `private` members of an `open` class.) Fixes rdar://problem/40738913.
9576d5d
to
ed64fad
Compare
@swift-ci please smoke test |
@swift-ci please test source compatibility |
The current behaviour of (some) open classes means private members are
forced to be public, but this only applies to the real members, not
thunks or specializations associated with them.
Fixes rdar://problem/40738913.