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

Hang: type_alias_impl_trait #132797

Open
wxie7 opened this issue Nov 9, 2024 · 3 comments
Open

Hang: type_alias_impl_trait #132797

wxie7 opened this issue Nov 9, 2024 · 3 comments
Labels
C-bug Category: This is a bug. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@wxie7
Copy link

wxie7 commented Nov 9, 2024

I tried this code:

rustc file.rs
#![feature(type_alias_impl_trait)]
trait Id {
    type Assoc;
}
impl<T> *const u8 {
    type Assoc = T;
}
type Ty
where
    Ty: Id<Assoc = Ty>,
= impl Sized;
fn define() -> Ty {}
fn main() {}

This file causes rustc to hang and is derived from mutant #109387. #109387 can terminate successfully.

Meta

rustc --version --verbose:

rustc 1.84.0-nightly (b91a3a056 2024-11-07)
binary: rustc
commit-hash: b91a3a05609a46f73d23e0995ae7ebb4a4f429a5
commit-date: 2024-11-07
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.3
Compiler Output (before the hang)
error[E0658]: inherent associated types are unstable
 --> file.rs:6:5
  |
6 |     type Assoc = T;
  |     ^^^^^^^^^^^^^^^
  |
  = note: see issue #8995 <https://github.com/rust-lang/rust/issues/8995> for more information
  = help: add `#![feature(inherent_associated_types)]` to the crate attributes to enable
  = note: this compiler was built on 2024-11-04; consider upgrading it if it is out of date

error[E0207]: the type parameter `T` is not constrained by the impl trait, self type, or predicates
 --> file.rs:5:6
  |
5 | impl<T> *const u8 {
  |      ^ unconstrained type parameter

error[E0277]: the trait bound `Ty: Id` is not satisfied
  --> file.rs:8:1
   |
8  | type Ty
   | ^^^^^^^ the trait `Id` is not implemented for `Ty`
   |
help: this trait has no implementations, consider adding one
  --> file.rs:2:1
   |
2  | trait Id {
   | ^^^^^^^^
note: required by a bound on the type alias `Ty`
  --> file.rs:10:9
   |
10 |     Ty: Id<Assoc = Ty>,
   |         ^^^^^^^^^^^^^^ required by this bound

error[E0277]: the trait bound `Ty: Id` is not satisfied
  --> file.rs:10:5
   |
10 |     Ty: Id<Assoc = Ty>,
   |     ^^^^^^^^^^^^^^^^^^ the trait `Id` is not implemented for `Ty`
   |
help: this trait has no implementations, consider adding one
  --> file.rs:2:1
   |
2  | trait Id {
   | ^^^^^^^^
   = help: see issue #48214
help: add `#![feature(trivial_bounds)]` to the crate attributes to enable
   |
2  + #![feature(trivial_bounds)]
   |

error[E0277]: the trait bound `Ty: Id` is not satisfied
  --> file.rs:11:3
   |
11 | = impl Sized;
   |   ^^^^^^^^^^ the trait `Id` is not implemented for `Ty`
   |
help: this trait has no implementations, consider adding one
  --> file.rs:2:1
   |
2  | trait Id {
   | ^^^^^^^^
note: required by a bound on the type alias `Ty`
  --> file.rs:10:9
   |
10 |     Ty: Id<Assoc = Ty>,
   |         ^^^^^^^^^^^^^^ required by this bound

error[E0277]: the trait bound `Ty: Id` is not satisfied
  --> file.rs:12:16
   |
12 | fn define() -> Ty {}
   |                ^^ the trait `Id` is not implemented for `Ty`
   |
help: this trait has no implementations, consider adding one
  --> file.rs:2:1
   |
2  | trait Id {
   | ^^^^^^^^
note: required by a bound on the type alias `Ty`
  --> file.rs:10:9
   |
10 |     Ty: Id<Assoc = Ty>,
   |         ^^^^^^^^^^^^^^ required by this bound

error[E0277]: the trait bound `Ty: Id` is not satisfied
  --> file.rs:12:19
   |
12 | fn define() -> Ty {}
   |                   ^^ the trait `Id` is not implemented for `Ty`
   |
help: this trait has no implementations, consider adding one
  --> file.rs:2:1
   |
2  | trait Id {
   | ^^^^^^^^
note: required by a bound on the type alias `Ty`
  --> file.rs:10:9
   |
10 |     Ty: Id<Assoc = Ty>,
   |         ^^^^^^^^^^^^^^ required by this bound

error[E0390]: cannot define inherent `impl` for primitive types
 --> file.rs:5:1
  |
5 | impl<T> *const u8 {
  | ^^^^^^^^^^^^^^^^^
  |
  = help: consider using an extension trait instead
@wxie7 wxie7 added the C-bug Category: This is a bug. label Nov 9, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 9, 2024
@kadenlnelson
Copy link
Contributor

How long does it hang for? Are you able to provide a profile that shows where the time is being spent?

If you may as well, provide the full output that is shown when you execute rustc.

@wxie7
Copy link
Author

wxie7 commented Nov 9, 2024

How long does it hang for? Are you able to provide a profile that shows where the time is being spent?

If you may as well, provide the full output that is shown when you execute rustc.

I used the command timeout 60 rustc file.rs, and when it timed out, the partial output was as follows:

1211900:     0x7f27970b56e9 - <rustc_trait_selection[c0f45c4e16f8dab6]::traits::select::SelectionContext>::evaluate_trait_predicate_recursively
1211901:     0x7f2796f3d463 - <rustc_trait_selection[c0f45c4e16f8dab6]::traits::select::SelectionContext>::evaluate_predicate_recursively
1211902:     0x7f27970b56e9 - <rustc_trait_selection[c0f45c4e16f8dab6]::traits::select::SelectionContext>::evaluate_trait_predicate_recursively
1211903:     0x7f2796f3d463 - <rustc_trait_selection[c0f45c4e16f8dab6]::traits::select::SelectionContext>::evaluate_predicate_recursively
1211904:     0x7f27970b56e9 - <rustc_trait_selection[c0f45c4e16f8dab6]::traits::select::SelectionContext>::evaluate_trait_predicate_recursively

@fmease fmease added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. labels Nov 10, 2024
@fmease
Copy link
Member

fmease commented Nov 10, 2024

The IAT (inherent associated type) isn't needed; the hang also occurs without it:

#![feature(type_alias_impl_trait)]
trait Id {
    type Assoc;
}
type Ty
where
    Ty: Id<Assoc = Ty>,
= impl Sized;
fn define() -> Ty {}
fn main() {}

I'd also like to note the extreme growth in memory use apart from the hang (e.g., I'm getting jumps from roughly 6GiB (baseline) to 9GiB to 12GiB RAM use).

@fmease fmease removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 10, 2024
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. F-type_alias_impl_trait `#[feature(type_alias_impl_trait)]` I-compilemem Issue: Problems and improvements with respect to memory usage during compilation. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. 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