Skip to content

Compilation Exhausts Memory Instead of Detecting Potential Syntax Error #117080

Closed

Description

@iamanonymouscs

I tried this code():

trait Mul<T> {
    type Output;
}
trait Matrix: Mul<<Self as Matrix>::Row, Output = ()> {
    type Row;
    type Transpose: Matrix<Row = Self::Row>;
}
fn is_mul<S, T: Mul<S, Output = ()>>() {}
fn f<T: Matrix>() {
    is_mul::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<f::<>();
}

I expected to see this happen: the compiler to recognize a potential syntax error and provide an error report.

Instead, this happened: the compiler consumes all available memory and exits.

This code contains obvious syntax errors, so it doesn't seem reasonable for it to be compiled for a long time.

Meta

rustc --version --verbose:

commit-hash: 1c05d50c8403c56d9a8b6fb871f15aaa26fb5d07
commit-date: 2023-10-21
host: x86_64-unknown-linux-gnu
release: 1.75.0-nightly
LLVM version: 17.0.3

The same problem is reproduced on the stable version(1.73 cc66ad4 2023-10-03)

Backtrace

<backtrace>

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 23, 2023
  2. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    I-compilememIssue: Problems and improvements with respect to memory usage during compilation.
    I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.
    A-parserArea: The lexing & parsing of Rust source code to an AST
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 23, 2023
  3. estebank commented on Oct 24, 2023

    @estebank
    Contributor

    The problem is introduced by parse_angle_args_with_leading_angle_bracket_recovery. We need to take a look to add a further check to avoid falling into this pathological case.

  4. added a commit that references this issue on Oct 24, 2023
    54dffa1
  5. added a commit that references this issue on Oct 24, 2023
  6. added 2 commits that reference this issue on Oct 24, 2023
    7bce646
    2dec1bc
  7. added a commit that references this issue on Oct 26, 2023
  8. added a commit that references this issue on Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parserArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.I-compilememIssue: Problems and improvements with respect to memory usage during compilation.I-hangIssue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions