Skip to content

Fix trait constraint type checking order for supertraits. #7022

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

Merged
merged 3 commits into from
Mar 18, 2025

Conversation

tritao
Copy link
Contributor

@tritao tritao commented Mar 17, 2025

This fixes a stack overflow caused by interaction between type checking order for trait constraits for supertraits.

trait MyTrait {
    fn f(self) -> bool;
} {
    fn f2(self) -> bool {
        self.f()
    }
}

trait MyTrait2: MyTrait {
}

impl<T1> MyTrait for (T1,)
where
    T1: MyTrait2,
{
    fn f(self) -> bool { self.0.f() }
}

fn main() -> bool {
    true
}

Fixes #6898.

@tritao tritao added the compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen label Mar 17, 2025
@tritao tritao self-assigned this Mar 17, 2025
@tritao tritao temporarily deployed to fuel-sway-bot March 17, 2025 02:42 — with GitHub Actions Inactive
Copy link

codspeed-hq bot commented Mar 17, 2025

CodSpeed Performance Report

Merging #7022 will not alter performance

Comparing tritao:fix-trait-constraint-type-check-order (805bc3d) with master (f46a2dc)

Summary

✅ 22 untouched benchmarks

@tritao tritao marked this pull request as ready for review March 17, 2025 11:00
@tritao tritao requested a review from a team as a code owner March 17, 2025 11:00
This fixes a stack overflow caused by interaction between type checking
order for trait constraits for supertraits.

```
trait MyTrait {
    fn f(self) -> bool;
} {
    fn f2(self) -> bool {
        self.f()
    }
}

trait MyTrait2: MyTrait {
}

impl<T1> MyTrait for (T1,)
where
    T1: MyTrait2,
{
    fn f(self) -> bool { self.0.f() }
}

fn main() -> bool {
    true
}
```
@tritao tritao force-pushed the fix-trait-constraint-type-check-order branch from 315cc92 to 0a26815 Compare March 17, 2025 11:05
@tritao tritao temporarily deployed to fuel-sway-bot March 17, 2025 11:06 — with GitHub Actions Inactive
@tritao tritao enabled auto-merge (squash) March 18, 2025 01:06
@tritao tritao temporarily deployed to fuel-sway-bot March 18, 2025 01:07 — with GitHub Actions Inactive
@tritao tritao merged commit 77364f0 into FuelLabs:master Mar 18, 2025
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler: frontend Everything to do with type checking, control flow analysis, and everything between parsing and IRgen
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix compiler stack overflow when compiling code with PartialEq and Eq in trait constraints
3 participants