-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SILGen] Fall back to module lookup on invalid conformance when building subst. maps for vtable thunks #30470
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
cc @slavapestov, @jckarter Could you take a look at this please? |
Can you try to come up with fixes that don't break these existing invariants? If you want to pursue the second fix further, you should finish off my old PR that removes the assertion: #23291 The hard part was that we lose performance because existing optimizations are currently disabled for generics (such as inlining) but we still want them to take place in the fully-concrete case. So some optimization passes will need changes to handle this. |
I see, so we do lose performance.. I take it whatever eventually causes the performance regression does not check if the generic signature is at all useful.
I did try something, but hit another one saying ≈
Optimization passes are interesting, but I'm hesitant about the idea of making the optimizer responsible for collecting unused generic signatures (unused because the function type is already fully substituted through canonicalization) just because we need that signature in another place within the SILGen library. Does this make sense to you? |
I am going to rip out the second fix so that we can proceed with the first one. If it looks sane, that is. I have no idea how often the module lookup fallback is going to be hit in the wild though, and this does fix an edge case, so maybe we should test compiler performance? |
…ing subst. maps for vtable thunks
5e005df
to
4848aaa
Compare
FWIW, I refactored the first part into a (hopefully temporary) targeted fix to make sure we don't end up getting performance regressions elsewhere. |
It would be more correct if we could capture the conformance for |
Do you have an example of such a scenario? I'm curious. |
If |
Yeah, I think @jckarter's answer is right. We need to record 'override substitutions' when we check the override, just like we record substitutions for protocol witnesses. |
Here, as usual, we combine the override substitutions
T := Int
with the invocation generic signature<T where T: Protocol>
to form a new substitution map for the reabstraction thunk, only to realize that we cannot recover theInt : Protocol
conformance from just the original substitution map. As a consequence, we end up with an invalid conformance, and a crash later on once we actually emit the thunk. As ugly as it is, falling back to module lookup inSubstitutionMap::get
fixes the issue.### FIX 2Now that we allow purely contextual where clauses, we can face non-generic methods
with generic signatures that constrain all outer params to concrete types. E.g.
Remove the assertion guarding against these generic signatures on SILFunctionTypeso that we always retain the override substitutions needed to transform the derived
method's formal type when we emit a reabstraction thunk.