Skip to content

Recursive trait constraints crash compiler with exit code 3221225501 #51296

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
bergus opened this issue Jun 2, 2018 · 1 comment
Open

Recursive trait constraints crash compiler with exit code 3221225501 #51296

bergus opened this issue Jun 2, 2018 · 1 comment
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. 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

@bergus
Copy link

bergus commented Jun 2, 2018

I've got a crate that doesn't compile, it just starts eating memory until it stops without an error message. Only passing the --verbose flag to cargo build tells me

error: Could not compile `the-crate`.

Caused by:
  process didn't exit successfully: `rustc …` (exit code: 3221225501)

Seems to be the same exit code as in #42544.

Here's the (not exactly minimal) example to reproduce the issue:

pub struct Example<A, B, D>
where
    A: StrategyA<Example<A, B, D>>,
    B: StrategyB<Example<A, B, D>> {
    pub a: A,
    pub b: B,
    pub element: B::Element,
    pub data: D,
}
pub trait StrategyA<T: HasData> {
    fn do_a(&self, &T::Data);
}
pub trait StrategyB<T> {
    type Element;
    fn do_b(&self, &T);
}
impl<A: StrategyA<Self>, B: StrategyB<Self>, D> Example<A, B, D> {
    pub fn do_it(&self, args: bool) {
        if args {
            self.a.do_a(self.get_data());
        } else {
            self.b.do_b(self);
        }
    }
}
pub trait HasData {
    type Data;
    fn get_data(&self) -> &Self::Data;
}
impl<A: StrategyA<Self>, B: StrategyB<Self>, D> HasData for Example<A, B, D> {
    type Data = D;
    fn get_data(&self) -> &D {
        &self.data
    }
}

pub struct ExampleA;
pub struct ExampleB;
pub struct ExampleData;

impl<E: HasData<Data=ExampleData>> StrategyA<E> for ExampleA {
    fn do_a(&self, e: &ExampleData) {
        e; // using ExampleData here
    }
}
impl<E: HasData<Data=ExampleData>> StrategyB<E> for ExampleB {
    type Element = ExampleData;
    fn do_b(&self, e: &E) { /* same */}
}

fn x() {
    let example = Example { a: ExampleA, b: ExampleB, data: ExampleData };
    example.sized.do_it(true);
    example.sized.do_it(false);
}

Removing the StrategyA parts causes it to produce an "overflow evaluating the requirement …" error, not sure whether related.

@bergus bergus changed the title Recursive trait contraints crash compiler with exit code 3221225501 Recursive trait constraints crash compiler with exit code 3221225501 Jun 2, 2018
@ishitatsuyuki ishitatsuyuki added A-trait-system Area: Trait system I-compiletime Issue: Problems and improvements with respect to compile times. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. C-bug Category: This is a bug. labels Jun 3, 2018
@ishitatsuyuki
Copy link
Contributor

This looks like a case of the type checker taking exponential amount of computation + memory to reason about the type.

@jonas-schievink jonas-schievink added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 14, 2020
@fmease fmease added A-trait-system Area: Trait system and removed A-trait-system Area: Trait system labels Dec 21, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-trait-system Area: Trait system C-bug Category: This is a bug. I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. 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

No branches or pull requests

4 participants