rust-lang / rust-lang/rust

Exponential compile time with nested closures and missing binop

Open
#117,798 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-compiletime T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Found by fuzzing and probably only affects fuzzing

Code
struct S;

fn main() {
    (|| S +
    (|| S +
    (|| S +
    (|| S +
    (|| S +
    (|| S +
    (|| S +
    (|| S +
    (|| S +
    (|| S +
    (|| S +
    (|| S +
    (|| S +
    (|| S +
    (|| S +
    (|| S +
    (|| S +
    S
    )()
    )()
    )()
    )()
    )()
    )()
    )()
    )()
    )()
    )()
    )()
    )()
    )()
    )()
    )()
    )()
    )();
}
Error output

Multiple instances of this error, which seems reasonable:

error[E0369]: cannot add S to S

Error details
error[E0369]: cannot add `S` to `S`
  --> tq.rs:10:11
   |
10 |       (|| S +
   |           - ^
   |           |
   |           S
11 | /     (|| S +
12 | |     (|| S +
13 | |     (|| S +
14 | |     (|| S +
...  |
30 | |     )()
31 | |     )()
   | |_______- S
   |
note: an implementation of `Add` might be missing for `S`
  --> tq.rs:1:1
   |
1  | struct S;
   | ^^^^^^^^ must implement `Add`
note: the trait `Add` must be implemented
  --> /rustc/fdaaaf9f923281ab98b865259aa40fbf93d72c7a/library/core/src/ops/arith.rs:76:1
Where it's slow

With -Z time-passes: the slowness is in type_check_crate

check_expr_coercible_to_type is on the stack multiple times (sample head)

Regression

Regression in nightly-2023-04-18

Commits in range
  commit[0] 2023-04-16UTC: Auto merge of #109133 - weihanglo:make-cargo-a-workspace, r=ehuss
  commit[1] 2023-04-17UTC: Auto merge of #109061 - saethlin:leak-backtraces, r=oli-obk
  commit[2] 2023-04-17UTC: Auto merge of #109247 - saethlin:inline-without-inline, r=oli-obk
  commit[3] 2023-04-17UTC: Auto merge of #109588 - Nilstrieb:dropless-expr, r=compiler-errors
  commit[4] 2023-04-17UTC: Auto merge of #110440 - matthiaskrgr:rollup-eit19vi, r=matthiaskrgr
  commit[5] 2023-04-17UTC: Auto merge of #110367 - saethlin:no-truncations, r=oli-obk
  commit[6] 2023-04-17UTC: Auto merge of #110458 - matthiaskrgr:rollup-1xcxmgc, r=matthiaskrgr
  commit[7] 2023-04-17UTC: Auto merge of #110343 - saethlin:encode-initmask, r=lqd
  commit[8] 2023-04-17UTC: Auto merge of #110243 - WaffleLapkin:bless_tagged_pointers🙏, r=Nilstrieb
Version
rustc 1.75.0-nightly (fdaaaf9f9 2023-11-08)
binary: rustc
commit-hash: fdaaaf9f923281ab98b865259aa40fbf93d72c7a
commit-date: 2023-11-08
host: x86_64-apple-darwin
release: 1.75.0-nightly
LLVM version: 17.0.4

@rustbot label +I-compiletime

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 compiling the nested-closure reproducer with -Z time-passes and inspect the reported type_check_crate cost, especially repeated check_expr_coercible_to_type frames. Use the nightly-2023-04-18 regression range to compare behavior. Done means this input no longer exhibits exponential compile-time growth while retaining the expected E0369 diagnostics.

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
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.