rust-lang / rust-lang/rust

Manual auto trait impl can be more work for the trait solver, including higher recursion depth

Open
#162,850 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-auto-traits C-bug E-needs-mcve needs-triage T-types WG-trait-system-refactor
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

I accidentally hit this in https://github.com/rust-lang/rust/pull/162804#issuecomment-5686193024.

Essentially, replacing Unique<u8> with NonNull<u8> in RawVecInner<A> meant that I had to rewrite the Send, Sync, and UnwindSafe impls for it.
I initially chose to do this on RawVec<T, A> using impl<T: AuTr, A: Allocator + AuTr> AuTr for RawVec<T, A>.
This caused slight compile time regressions, as well as a compile error due to the trait solver now exceeding the recursion limit on a complex rayon iterator, likely due to the Send supertrait bound on ParallelIterator.

The benchmark that failed to compile can be found in src/tools/rustc-perf/collector/runtime-benchmarks/css/, and the failure reproduced with cargo +b67dca92df005a4ebbe8c3b45e6cfe97925fff26 check, using kennytm/rustup-toolchain-install-master.

This is dangerous especially for std, because it risks introducing regressions when refactoring the internals of commonly used types.

Note that the old impls were auto-derived from the A and PhantomData<T> fields, because Unique<u8> implemented all the relevant traits.
Now that I've pulled the manual impls back to impl<A: Allocator + AuTr> AuTr for RawVecInner<A>, it seems to no longer be regressing.
All these impls should be equivalent (if anything, I'd expect the auto impl to be more work than the manual one).

@rustbot label WG-trait-system-refactor A-auto-traits E-needs-mcve T-types

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure in src/tools/rustc-perf/collector/runtime-benchmarks/css/ with cargo +b67dca92df005a4ebbe8c3b45e6cfe97925fff26 check. Compare the manual and auto-trait implementations for RawVecInner and RawVec, focusing on the rayon iterator recursion-limit failure and compile-time regression. Done means identifying a minimal reproduction and resolving or clearly characterizing the solver regression.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.