-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
instance: polymorphize upvar closures/generators #75255
instance: polymorphize upvar closures/generators #75255
Conversation
a6535d2
to
c6f361b
Compare
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 may want to add a type flag like MAY_POLYMORPHIZE
which checks if the ty is or contains a Closure
or Generator
so we don't have to always looking into the subst.
But apart from that this looks good to me, I don't think @eddyb also needs to look over this 🤔
r=me
I've addressed those comments, including adding the type flag. r? @lcnr |
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.
r=me after the nit is fixed
This commit modifies how instances are polymorphized so that closures and generators have any closures or generators captured within their upvars also polymorphized - this avoids symbol clashes with the new symbol mangling scheme. Signed-off-by: David Wood <david@davidtw.co>
By always polymorphizing substitutions, functions which take closures as arguments (e.g. `impl Fn()`) can have fewer mono items when some of the argument closures can be polymorphized. Signed-off-by: David Wood <david@davidtw.co>
This commit adds a `MAY_POLYMORPHIZE` which checks for closures and generators so that polymorphization of substs does not need to traverse every substs. Signed-off-by: David Wood <david@davidtw.co>
This commit avoids unnecessary calls to `mk_closure` and `mk_generator` by checking if the polymorphized substs match the original substs. Signed-off-by: David Wood <david@davidtw.co>
This commit extends previous polymorphization of substs to polymorphize `FnDef`. Signed-off-by: David Wood <david@davidtw.co>
e9cab0c
to
ac50d61
Compare
@bors r=lcnr |
📌 Commit ac50d61 has been approved by |
☀️ Test successful - checks-actions, checks-azure |
This commit restricts the substitution polymorphization added in rust-lang#75255 to only apply to the tupled upvar substitution, rather than all substitutions, fixing a bunch of regressions when polymorphization is enabled. Signed-off-by: David Wood <david@davidtw.co>
…xes, r=eddyb instance: only polymorphize upvar substs This PR restricts the substitution polymorphization added in rust-lang#75255 to only apply to the tupled upvar substitution, rather than all substitutions, fixing a bunch of regressions when polymorphization is enabled. Due to an oversight on my part, when landing rust-lang#75260 and rust-lang#75255, some tests started failing when polymorphization was enabled that I didn't notice until after landing - this PR fixes the regressions from rust-lang#75255. rust-lang#75336 has been filed to make sure that we don't forget to try make this change again in future, as it does enable some optimisations. r? @lcnr
…xes, r=lcnr polymorphize: constrain unevaluated const handling This PR constrains the support added for handling unevaluated consts in polymorphization (introduced in rust-lang#75260) by: - Skipping associated constants as this causes cycle errors. - Skipping promoted constants when they contain `Self` as this ensures `T` is used in constants of the form `<Self as Foo<T>>`. Due to an oversight on my part, when landing rust-lang#75260 and rust-lang#75255, some tests started failing when polymorphization was enabled that I didn't notice until after landing - this PR fixes the regressions from rust-lang#75260. r? @lcnr
This PR modifies how instances are polymorphized so that closures and generators have any closures or generators captured within their upvars also polymorphized.
With the new symbol mangling, a fully polymorphised closure will produce the same symbol regardless of what it was instantiated with. However, when that polymorphised closure captures another closure as an upvar, then the type of that other closure in the upvar substitution wouldn't have been polymorphised. The other closure will still refer to the initial substitutions. Therefore, the polymorphised closure will end up hashing differently but producing the same symbol - triggering
assert_symbols_are_distinct
in MIR partitioning. The old mangling scheme had a hash at the end that meant this didn't happen (this would still have been an issue, we just didn't have a way to notice).See this Zulip discussion for further elaboration.
r? @eddyb
cc @lcnr