Repository navigation
Description
I was playing with the next generation trait solver (which is said to stabilize soon: rust-lang/goals#113) on Bevy. Bevy has a notoriously slow to compile subcrate called bevy_pbr and was hoping to see some improvements.
The good new is that the improvement is real and substantial:
| Solver | bevy_pbr total |
Frontend | Codegen |
|---|---|---|---|
Legacy (-Znext-solver=coherence) |
40.8s | 33.9s | 6.9s |
Next (-Znext-solver=globally) |
32.9s | 25.5s | 7.4s |
The bad news is that it became less equipped to deal with ambiguity. In this case the patch is relatively simple and acceptable: bevyengine/bevy#25533. That said, stabilization of the next generation trait solver would technique constitute a regression.
If the answer is, "the next generation solver can only be this performant because it chooses to reject ambiguity" then I'm also relatively satisfied, just wanted to make sure this is a conscious decision.
Tested using rustc 1.100.0-nightly (c656540d6 2026-08-21)
Activity
HugoPeters1024 commentedon Aug 24, 2026
While trying to make a minimal, dependency-free reproducer, I've come to wonder if it's not actually the current
coherencesolver that is at fault. Because I don't see how it is able to resolve the following ambiguity without simply discarding the possibility that the opaqueimpl Sizedreturn type could beu32, making both Schedule::run_if and the blanket Observer::run_if applicable.lcnr commentedon Aug 24, 2026
can you try the current main branch with https://github.com/kennytm/rustup-toolchain-install-master (or nightly tomorrow)
I think this should be fixed by #161552 which has been merged today. I think the bevy regression was bevyengine/bevy#25511?
lcnr commentedon Aug 24, 2026
jup,
bevy_pbralso compiles with after that changetheemathas commentedon Aug 24, 2026
@lcnr Does that PR change how method resolution works? That sounds odd to me.
HugoPeters1024 commentedon Aug 24, 2026
@lcnr it looks like the
bevy_pbrproblem itself was already discovered and root caused some extent: bevyengine/bevy#25511. It confusingly was the result of some Send/Sync shenanigans.However, the reproducer I posted above still fails on the latest main (
04a3cad16c5) withgloballysolver but notcoherence🤔lcnr commentedon Aug 24, 2026
that PR causes method selection to discard candidates if they depend on a goal which only evaluates to
NoSolutionwith double the recursion limit.👍 that is not required for
bevy_pbr, is it? I don't have a strong opinion on whether this example should compile. We don#t know the fact thatimpl Sizedisi32at the point of doing method selection here.What is your expected behavior for
HugoPeters1024 commentedon Aug 25, 2026
Having now understood the issue better, it's clear that my reproducer was not representative of the
bevy_pbrissue.In fact, I'd say that throwing an error on that file is in fact the desired behavior! In the case of
System(42_u32)there really are 2 equivalently valid choices. So in hindsight, I thinkgloballyactually improves uponcoherencehere 🥳