-
Notifications
You must be signed in to change notification settings - Fork 10.5k
SE-0309: SILOptimizer fixes & reenable executable tests #58513
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
…'apply' involves associated types This optimization rewrites only the 'self' argument, and does not know how to substitute types in the users of the given apply instruction in case the underlying protocol method returns a `Self`-dependent type. With SE-0309 in motion, the bail-out logic must be generalized to `Self`-rooted type parameters.
@swift-ci please smoke test macOS |
@swift-ci please smoke test linux |
@swift-ci please smoke test Windows |
lib/AST/Type.cpp
Outdated
@@ -54,6 +54,12 @@ using namespace swift; | |||
#include "swift/AST/TypeNodes.def" | |||
|
|||
Type QueryTypeSubstitutionMap::operator()(SubstitutableType *type) const { | |||
if (auto *archetype = dyn_cast<ArchetypeType>(type)) { |
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 is this necessary? When do non-root archetypes appear in the map?
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.
They don't, well, hopefully. It's Type::subst
that queries the map with non-root archetypes, and it probably has been since the dinosaurs. Do you reckon we should fix that instead?
SubstitutionMap::lookupSubstitution
has this early return as well btw.
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.
Let's remove this part then, or change it to an assertion.
Type::subst() passing in non-root archetypes is something that I believe only associated type inference relies on. You can try taking it out and see what breaks.
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 still need this tweak, otherwise QueryTypeSubstitutionMapOrIdentity
won't work with non-root opened archetypes, and that makes the SIL cloner crash. I can use a custom substitution fn instead, WDYT?
P.S. This is about getASTTypeInClonedContext
.
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.
Would it not be safer to leave this part as is and add a FIXME
, rather than propagate the check to clients? Associated type inference itself does not appear to be using these function objects.
CC @atrick |
@AnthonyLatsis I was actually looking at this disabled test the other day and when I reduced the failure it did not involve non-root opened archetypes. What I had was this: protocol P {
var covariantSelfPropClosure: ((Self) -> Void) -> Void { get }
}
extension P {
var covariantSelfPropClosure: ((Self) -> Void) -> Void { { $0(self) } }
}
struct S: P {}
let p: P = S()
p.covariantSelfPropClosure { _ in } It was crashing because IRGen was trying to allocate a zero-sized heap context for the closure. Is this a different bug? |
Interesting, I will take a look in a minute. For me it stopped crashing the moment I switched from strings to integers, which made me think whatever issue was unrelated.
The issues with non-root archetypes were revealed after adding more tests for methods with covariant associated types. |
@slavapestov How do I reproduce the crash? |
@slavapestov It is a different issue. How did you manage to dig out the root cause? |
Simplified the crasher a bit more: protocol P {
var prop: () -> Self { get }
}
extension P {
var prop: () -> Self {
{ self }
}
}
struct S: P {}
let p: P = S()
let y = p.prop() |
Thanks for the link. I definitely lack domain knowledge to fully understand why this happens with this specific closure and not others, but I have a rough idea of what's going on now. Interestingly, the crash won't manifest if |
Can you be sure to push this through full testing rather than smoke testing? |
…meters and `Self`-rooted type parameters
…tutionMapOrIdentity` This makes `SILCloner::getASTTypeInClonedContext` and `getTypeInClonedContext`, which use `QueryTypeSubstitutionMapOrIdentity`, work for nested opened archetypes and consequently fixes inlining of instructions involving these archetypes.
0af30e4
to
5dc4834
Compare
@swift-ci please test |
@slavapestov is there anyone else we need an approval from? |
I think it's fine, but let's re-run tests since it's been more than 2 weeks now. |
@swift-ci Please test |
May I ask you to sign it off then? |
Thanks. |
Note
The executable test was XFAILed in #39334 due to a crash on builds with optimizations enabled. The issue turned out to be unrelated to the feature and may have had something to do with usage of strings in the test.