I'm seeing weirdly high compilation times with specifically tailored traits.
If I define a trait like so (full-gist):
macro_rules! assoc {
($e : ident, $f :ident) => {
type $e: Send + Sync + std::fmt::Debug + std::fmt::Display;
fn $f ();
}
}
trait FooTrait {
assoc!(A, get_a);
assoc!(B, get_b);
assoc!(C, get_c);
// ...
assoc!(Z, get_z);
}
I get very high compilation times that are seemingly very sensitive to the number of bounds on the associated types and the number of pairs of fn+type.
At ~50 fn+type pairs and 4 type bounds it takes just over 1min to build with rustc 1.47.0-nightly (e5e33ebd2 2020-08-11).
Summarize output (full-gist) shows that most of the time spent is in check_trait_item_well_formed.
| Item | Self time | % of total time | Time | Item count |
+--------------------------------------------------+-----------+-----------------+----------+------------+
| check_trait_item_well_formed | 63.07s | 97.565 | 63.10s | 104 |
+--------------------------------------------------+-----------+-----------------+----------+------------+
| check_item_well_formed | 1.25s | 1.938 | 1.26s | 4 |
+--------------------------------------------------+-----------+-----------------+----------+------------+
| run_linker | 194.61ms | 0.301 | 194.61ms | 1 |
Weirdly enough, if we modify the macro to just generate the associated types or just generate the methods, we don't get the high compilation times.
Originally found this with a pattern where each fn returns one of the associated types: fn get_a() -> Self::A, which is how I stumbled upon the problem. Though it doesn't seem like the fns need to reference the associated types to trigger it.
This will probably be fixed by https://github.com/rust-lang/rust/pull/73905
This will probably be fixed by #73905
Tried it locally and can confirm it fixes the problem.
Finally got around to testing with a version of rustc including #73905. Confirming all works much better now. Closing this issue.
Most helpful comment
Tried it locally and can confirm it fixes the problem.