Skip to content
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

Endless Compilation when Successive Calling to map #116780

Closed
iamanonymouscs opened this issue Oct 16, 2023 · 2 comments · Fixed by #116826
Closed

Endless Compilation when Successive Calling to map #116780

iamanonymouscs opened this issue Oct 16, 2023 · 2 comments · Fixed by #116826
Assignees
Labels
C-bug Category: This is a bug. I-compiletime Issue: Problems and improvements with respect to compile times. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@iamanonymouscs
Copy link

iamanonymouscs commented Oct 16, 2023

cat hang.rs

#![crate_type = "lib"]
#[no_mangle]
pub fn get_len() -> usize {
    [1, 2, 3].iter(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map().collect::<Vec<_>>().len()
}

I expected to see this happen: The compiler compiles successfully or outputs an error message.

Instead, this happened: The code, as provided below, appears to encounter a hang

Command

rustc -C opt-level=0 hang.rs

Meta

rustc --version --verbose:

rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2

The same problem is reproduced on the nightly version(2023-10-15;42b1224e9eb37177f608d3f6a6f2be2ee13902e4)

Backtrace

error[E0061]: this method takes 0 arguments but 1 argument was supplied
 --> hang.rs:4:15
  |
4 |     [1, 2, 3].iter(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| x).map(|x| ...
  |               ^^^^ -----
  |                    |
  |                    unexpected argument of type `[closure@hang.rs:4:20: 4:23]`
  |                    help: remove the extra argument
  |
note: method defined here
 --> /rustc/cc66ad468955717ab92600c770da8c1601a4ff33/library/core/src/slice/mod.rs:1001:12

@iamanonymouscs iamanonymouscs added the C-bug Category: This is a bug. label Oct 16, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 16, 2023
@eminence
Copy link
Contributor

This seems to be a type of quadratic blowup that changed in 1.73. I did some tests by altering the number of map(|x| x) calls:

Number off map() calls Time in 1.72 Time in 1.73
1 19.6 ms ± 1.6 ms 36.1 ms ± 1.6 ms
5 20.3 ms ± 1.4 ms 35.8 ms ± 1.8 ms
10 22.5 ms ± 1.4 ms 47.4 ms ± 1.5 ms
11 23.5 ms ± 1.5 ms 55.2 ms ± 1.3 ms
12 24.0 ms ± 1.3 ms 72.0 ms ± 1.2 ms
13 24.8 ms ± 1.3 ms 104.9 ms ± 1.7 ms
14 26.0 ms ± 1.4 ms 175.4 ms ± 2.3 ms
15 27.0 ms ± 1.6 ms 324.9 ms ± 7.5 ms
16 28.3 ms ± 1.7 ms 646.9 ms ± 9.8 ms
17 29.6 ms ± 1.5 ms 1.290 s ± 0.027 s
18 30.4 ms ± 1.4 ms 2.600 s ± 0.056 s
19 31.9 ms ± 1.7 ms 5.054 s ± 0.079 s
20 33.1 ms ± 1.6 ms 10.136 s ± 0.157 s

@DaniPopes
Copy link
Contributor

searched nightlies: from nightly-2023-08-01 to nightly-2023-10-16
regressed nightly: nightly-2023-08-19
searched commit range: 0768872...d06ca0f
regressed commit: a1e1dba

bisected with cargo-bisect-rustc v0.6.7

Host triple: x86_64-unknown-linux-gnu
Reproduce with:

cargo bisect-rustc --start 2023-08-01 --timeout 2 

#114611 cc @nnethercote

@saethlin saethlin added I-compiletime Issue: Problems and improvements with respect to compile times. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 16, 2023
@nnethercote nnethercote self-assigned this Oct 16, 2023
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 17, 2023
…piler-errors

Fix a performance regression in obligation deduplication.

Commit 8378487 from rust-lang#114611 changed the location of an obligation deduplication step in `opt_normalize_projection_type`. This meant that deduplication stopped happening on one path where it was still necessary, causing a couple of drastic performance regressions.

This commit moves the deduplication back to the old location. The good news is that rust-lang#114611 had four commits and 8378487 was of minimal importance, so the perf benefits from that PR remain.

Fixes rust-lang#116780, rust-lang#116797.

r? `@compiler-errors`
@bors bors closed this as completed in 91f2fbc Oct 17, 2023
cuviper pushed a commit to cuviper/rust that referenced this issue Oct 21, 2023
Commit 8378487 from rust-lang#114611 changed the location of an obligation
deduplication step in `opt_normalize_projection_type`. This meant that
deduplication stopped happening on one path where it was still
necessary, causing a couple of drastic performance regressions.

This commit moves the deduplication back to the old location. The good
news is that rust-lang#114611 had four commits and 8378487 was of minimal
importance, so the perf benefits from that PR remain.

Fixes rust-lang#116780, rust-lang#116797.

(cherry picked from commit 91f2fbc)
xobs pushed a commit to betrusted-io/rust that referenced this issue Nov 7, 2023
Commit 8378487 from rust-lang#114611 changed the location of an obligation
deduplication step in `opt_normalize_projection_type`. This meant that
deduplication stopped happening on one path where it was still
necessary, causing a couple of drastic performance regressions.

This commit moves the deduplication back to the old location. The good
news is that rust-lang#114611 had four commits and 8378487 was of minimal
importance, so the perf benefits from that PR remain.

Fixes rust-lang#116780, rust-lang#116797.

(cherry picked from commit 91f2fbc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-compiletime Issue: Problems and improvements with respect to compile times. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants