-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Support inlinability with [serialized_for_package] #73754
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 smoke test |
dd594f8
to
4152f34
Compare
Thank you! This makes more sense than maintaining two booleans. |
34a67f4
to
cf1a94c
Compare
@swift-ci smoke test |
cf1a94c
to
70c6446
Compare
@swift-ci smoke test |
f2ae567
to
d991810
Compare
@swift-ci test |
d991810
to
ecafc6a
Compare
@swift-ci test |
1 similar comment
@swift-ci test |
27cf40e
to
cc3ca1c
Compare
@swift-ci test |
1 similar comment
@swift-ci test |
d09bf98
to
0e90551
Compare
@swift-ci test |
0e90551
to
9f5d5ee
Compare
@swift-ci test |
@swift-ci test |
|
||
/// Returns true if this function can be referenced from a fragile function | ||
/// body. | ||
bool hasValidLinkageForFragileRef() const; | ||
bool hasValidLinkageForFragileRef( |
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 should remove the optional here and always pass the referencing entity's SerializationKind_t.
It can come from the enclosing/referencing abstraction: function, v-table, witness table, property, movedeinit.
*/ | ||
bool SILFunction::canBeInlinedIntoCaller( | ||
std::optional<SerializedKind_t> callerSerializedKind, | ||
bool assumeFragileCaller) const { |
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 don't understand the need of the boolean assumeFragileCaller
.
If the caller is fragile (i.e serialized) this should be communicated via passing SerializedKind_t::Serialized
That argument should not be optional.
I think the APIs should be:
And we pass down the context from the enclosing entity (I think you are already doing that in some places of your patch). Some examples follow. SILVerifier.cpp (here the context/ referencing entity is the SILWitnessTable):
Devirtualizer.cpp (here the context/referencing entity is the caller function):
|
[serialized_for_package] if Package CMO is enabled. The latter kind allows a function to be serialized even if it contains loadable types, if Package CMO is enabled. Renamed IsSerialized_t as SerializedKind_t. The tri-state serialization kind requires validating inlinability depending on the serialization kinds of callee vs caller; e.g. if the callee is [serialized_for_package], the caller must be _not_ [serialized]. Renamed `hasValidLinkageForFragileInline` as `canBeInlinedIntoCaller` that takes in its caller's SerializedKind as an argument. Another argument `assumeFragileCaller` is also added to ensure that the calle sites of this function know the caller is serialized unless it's called for SIL inlining optimization passes. The [serialized_for_package] attribute is allowed for SIL function, global var, v-table, and witness-table. Resolves rdar://128406520
36d7fb0
to
5ccc4cd
Compare
Making the arg non-optional requires passing in caller info to |
@swift-ci test |
@@ -384,7 +384,11 @@ struct SILDeclRef { | |||
/// True if the function should be treated as transparent. | |||
bool isTransparent() const; | |||
/// True if the function should have its body serialized. | |||
IsSerialized_t isSerialized() const; | |||
bool isSerialized() const; |
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.
In a follow-up PR we should also introduce a predicate: bool isAnySerializedKind()
.
The places where we now have to write double negation !isNotSerialized()
are really hard to read. At least for my senile brains.
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.
Already on it in an upcoming PR; I agree it's illegible for me too :)
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.
Some changes here are a regression in correctness running in package CMO mode until we follow up with a patch that properly passes the serialization kind around in all places where we now pass assumeFragileCaller.
That is fine with me in the interest of smaller changes, with the understanding that we will have to follow-up with those changes.
@@ -554,9 +553,6 @@ ResilienceExpansion SILFunction::getResilienceExpansion() const { | |||
// attribute is preserved if the current module is in | |||
// the same package, thus should be in the same resilience | |||
// domain. | |||
if (isSerializedForPackage() == IsSerializedForPackage) |
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.
Wait I don't understand why these lines were removed.
The resilience expansion inside of a [serialized_for_package] function is Maximal -- we allow loadable types.
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.
Right, in the line below, maximal is returned if [serialized_for_package].
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.
Oh, right isSerialized is only [serialized] not [serialized_for_package]
The |
SIL function can be serialized with different kinds: [serialized] or
[serialized_for_package] if Package CMO is enabled. The latter kind
allows a function to be serialized even if it contains loadable types,
if Package CMO is enabled.
The tri-state serialization kind requires validating inlinability
depending on the serialization kinds of callee vs caller; e.g. if the
callee is [serialized_for_package], the caller must be not [serialized].
Package CMO sets [serialized_for_package] to SIL function, global var,
v-table, and witness-table, if inlinable.
Renamed IsSerialized_t as SerializedKind_t and added IsSerializedForPackage.
Updated various call sites with getSerializedKind().
SILFunction::canBeSerializedIntoCaller handles inlinability checks b/t caller and callee.
Resolves rdar://128406520