Rust-GCC / gccrs

GCC Front-End for Rust
https://rust-gcc.github.io/
GNU General Public License v2.0
2.44k stars 157 forks source link

(Mutual) recursive type aliases cause ICE #3165

Open tamaroning opened 1 month ago

tamaroning commented 1 month ago

Summary

might be related to https://github.com/Rust-GCC/gccrs/issues/1178 and https://github.com/Rust-GCC/gccrs/issues/2757 But the name resolver is the cause

Reproducer

I tried this code:

type C = crate::C;

type A = crate::B;
type B = crate::A;

Does the code make use of any (1.49) nightly feature ?

Godbolt link

https://godbolt.org/z/dP6vb8Yf3

Actual behavior

The current behavior is...

crab1: internal compiler error: Segmentation fault
0x27a7a8c internal_error(char const*, ...)
    ???:0
0xde47f4 Rust::TyTy::BaseType::get_kind() const
    ???:0
0xe2fe91 Rust::Resolver::TypeCheckType::visit(Rust::HIR::TypePath&)
    ???:0
0xe2dea5 Rust::Resolver::TypeCheckType::Resolve(Rust::HIR::Type*)
    ???:0
0xe1f2df Rust::Resolver::TypeCheckItem::visit(Rust::HIR::TypeAlias&)
    ???:0
0xe1f950 Rust::Resolver::TypeCheckItem::Resolve(Rust::HIR::Item&)
    ???:0
0xe74553 Rust::Resolver::query_type(unsigned int, Rust::TyTy::BaseType**)
    ???:0
0xe2ef48 Rust::Resolver::TypeCheckType::resolve_root_path(Rust::HIR::TypePath&, unsigned long*, unsigned int*)
    ???:0
0xe2fe86 Rust::Resolver::TypeCheckType::visit(Rust::HIR::TypePath&)
    ???:0
0xe2dea5 Rust::Resolver::TypeCheckType::Resolve(Rust::HIR::Type*)
    ???:0
0xe1f2df Rust::Resolver::TypeCheckItem::visit(Rust::HIR::TypeAlias&)
    ???:0
0xe1f950 Rust::Resolver::TypeCheckItem::Resolve(Rust::HIR::Item&)
    ???:0
0xddbb9b Rust::Resolver::TypeResolution::Resolve(Rust::HIR::Crate&)
    ???:0
0xc35907 Rust::Session::compile_crate(char const*)
    ???:0
Please submit a full bug report, with preprocessed source (by using -freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Compiler returned: 1

Expected behavior

I expected to see...

error[E0391]: cycle detected when computing type of `C`
 --> <source>:1:10
  |
1 | type C = crate::C;
  |          ^^^^^^^^
  |
  = note: ...which again requires computing type of `C`, completing the cycle
note: cycle used when collecting item types in top-level module
 --> <source>:1:1
  |
1 | / type C = crate::C;
2 | |
3 | | type A = crate::B;
4 | | type B = crate::A;
  | |__________________^

error[E0391]: cycle detected when computing type of `A`
 --> <source>:3:10
  |
3 | type A = crate::B;
  |          ^^^^^^^^
  |
note: ...which requires computing type of `B`...
 --> <source>:4:10
  |
4 | type B = crate::A;
  |          ^^^^^^^^
  = note: ...which again requires computing type of `A`, completing the cycle
note: cycle used when collecting item types in top-level module
 --> <source>:1:1
  |
1 | / type C = crate::C;
2 | |
3 | | type A = crate::B;
4 | | type B = crate::A;
  | |__________________^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0391`.
Compiler returned: 1

GCC Version

master

philberty commented 1 month ago

I think this is something that needs fixed during type checking there are a few variations of this issue now

philberty commented 1 month ago

We actually don't have any handling for recursive types because its complicated for both typechecking and code generation. I am holding off fixing it until i am more confident after we fix more bugs in generics and method resolution first.