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

Missing occurs check leads to an infinite loop in the type checker #134921

Open
Innf107 opened this issue Dec 30, 2024 · 1 comment
Open

Missing occurs check leads to an infinite loop in the type checker #134921

Innf107 opened this issue Dec 30, 2024 · 1 comment
Labels
C-bug Category: This is a bug. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged.

Comments

@Innf107
Copy link

Innf107 commented Dec 30, 2024

Running the following code with rustc leads to an infinite loop, presumably because the type checker tries to unify the type of x (let's call it ?a) with (?a, ?a)

fn same_type<A>(x : A, y : A) -> A {
    x
}

fn main() {
    let x = panic!();
    let _ = same_type(x, (x,x));
}

It also fills the source directory with megabytes of increasingly massive files containing the types it is trying to unify, for example (this is one of the smaller ones):

(((((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _)))), ((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _))))), (((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _)))), ((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _)))))), ((((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _)))), ((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _))))), (((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _)))), ((((_, _), (_, _)), ((_, _), (_, _))), (((_, _), (_, _)), ((_, _), (_, _)))))))

I would have expected rustc to catch this with an occurs check and produce an error message instead.

Meta

rustc --version --verbose:

rustc 1.85.0-nightly (14ee63a3c 2024-12-29)
binary: rustc
commit-hash: 14ee63a3c651bb7a243c8b07333749ab4b152e13
commit-date: 2024-12-29
host: x86_64-unknown-linux-gnu
release: 1.85.0-nightly
LLVM version: 19.1.6
@Innf107 Innf107 added the C-bug Category: This is a bug. label Dec 30, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 30, 2024
@theemathas
Copy link
Contributor

Duplicate of #132673

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. needs-triage This issue may need triage. Remove it if it has been sufficiently triaged.
Projects
None yet
Development

No branches or pull requests

3 participants