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

Rustc builds forever due to infinite recursion error #74201

Closed
myQwil opened this issue Jul 9, 2020 · 3 comments
Closed

Rustc builds forever due to infinite recursion error #74201

myQwil opened this issue Jul 9, 2020 · 3 comments
Labels
C-bug Category: This is a bug. 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

@myQwil
Copy link

myQwil commented Jul 9, 2020

I tried this code:

struct Recurse {
    recurse: Recurse
}

enum AType {
    ARecurse(Recurse),
}

struct MyStruct {
    atype: AType,
}

fn main() {
    let x = MyStruct { atype: AType::ARecurse(Recurse{}) };
}

I expected to see this happen:

error[E0072]: recursive type `Recurse` has infinite size
 --> main.rs:1:1
  |
1 | struct Recurse {
  | ^^^^^^^^^^^^^^ recursive type has infinite size
2 |     next: Recurse
  |     ------------- recursive without indirection
  |
  = help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `Recurse` representable

error: aborting due to previous error

For more information about this error, try `rustc --explain E0072`.

Instead, this happened:

error[E0072]: recursive type `Recurse` has infinite size
 --> main.rs:1:1
  |
1 | struct Recurse {
  | ^^^^^^^^^^^^^^ recursive type has infinite size
2 |     next: Recurse
  |     ------------- recursive without indirection
  |
  = help: insert indirection (e.g., a `Box`, `Rc`, or `&`) at some point to make `Recurse` representable

Rustc never aborts. It gets stuck in compilation limbo.

Meta

rustc --version --verbose:

rustc 1.44.1 (c7087fe00 2020-06-17)
binary: rustc
commit-hash: c7087fe00d2ba919df1d813c040a5d47e43b0fe7
commit-date: 2020-06-17
host: x86_64-unknown-linux-gnu
release: 1.44.1
LLVM version: 9.0

No backtrace summary available as compilation never ends.

@myQwil myQwil added the C-bug Category: This is a bug. label Jul 9, 2020
@jonas-schievink jonas-schievink added 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. labels Jul 9, 2020
@lcnr
Copy link
Contributor

lcnr commented Jul 10, 2020

Looks like this happens during DefPath printing

section from running this test with RUSTC_LOG=debug:

[DEBUG rustc_query_system::query::plumbing] ty::query::get_query<type_of>(key=DefId(0:5 ~ fk[317d]::Recurse[0]::0[0]), span=src/test/ui/__check/fk.rs:1:1: 1:1 (#0))
[DEBUG rustc_hir::definitions] DefPath::make: krate=crate0 index=Some(DefIndex(3))
[DEBUG rustc_hir::definitions] DefPath::make: key=DefKey { parent: Some(DefIndex(0)), disambiguated_data: DisambiguatedDefPathData { data: TypeNs("Recurse"), disambiguator: 0 } }
[DEBUG rustc_hir::definitions] DefPath::make: krate=crate0 index=Some(DefIndex(0))
[DEBUG rustc_hir::definitions] DefPath::make: key=DefKey { parent: None, disambiguated_data: DisambiguatedDefPathData { data: CrateRoot, disambiguator: 0 } }
[DEBUG rustc_middle::ty::print::pretty] try_print_visible_def_path: def_id=DefId(0:3 ~ fk[317d]::Recurse[0])
[DEBUG rustc_hir::definitions] DefPath::make: krate=crate0 index=Some(DefIndex(3))
[DEBUG rustc_hir::definitions] DefPath::make: key=DefKey { parent: Some(DefIndex(0)), disambiguated_data: DisambiguatedDefPathData { data: TypeNs("Recurse"), disambiguator: 0 } }
[DEBUG rustc_hir::definitions] DefPath::make: krate=crate0 index=Some(DefIndex(0))
[DEBUG rustc_hir::definitions] DefPath::make: key=DefKey { parent: None, disambiguated_data: DisambiguatedDefPathData { data: CrateRoot, disambiguator: 0 } }
[DEBUG rustc_middle::ty::print] default_print_def_path: def_id=DefId(0:3 ~ fk[317d]::Recurse[0]), substs=[]
[DEBUG rustc_middle::ty::print] default_print_def_path: key=DefKey { parent: Some(DefIndex(0)), disambiguated_data: DisambiguatedDefPathData { data: TypeNs("Recurse"), disambiguator: 0 } }
[DEBUG rustc_hir::definitions] DefPath::make: krate=crate0 index=Some(DefIndex(0))
[DEBUG rustc_hir::definitions] DefPath::make: key=DefKey { parent: None, disambiguated_data: DisambiguatedDefPathData { data: CrateRoot, disambiguator: 0 } }
[DEBUG rustc_middle::ty::print::pretty] try_print_visible_def_path: def_id=DefId(0:0 ~ fk[317d])
[DEBUG rustc_middle::ty::fold] HasTypeFlagsVisitor: t=Recurse t.flags=(empty) self.flags=HAS_TY_PARAM | HAS_RE_PARAM | HAS_CT_PARAM | NEEDS_SUBST
[DEBUG rustc_hir::definitions] DefPath::make: krate=crate0 index=Some(DefIndex(5))
[DEBUG rustc_hir::definitions] DefPath::make: key=DefKey { parent: Some(DefIndex(3)), disambiguated_data: DisambiguatedDefPathData { data: ValueNs("0"), disambiguator: 0 } }
[DEBUG rustc_hir::definitions] DefPath::make: krate=crate0 index=Some(DefIndex(3))
[DEBUG rustc_hir::definitions] DefPath::make: key=DefKey { parent: Some(DefIndex(0)), disambiguated_data: DisambiguatedDefPathData { data: TypeNs("Recurse"), disambiguator: 0 } }
[DEBUG rustc_hir::definitions] DefPath::make: krate=crate0 index=Some(DefIndex(0))
[DEBUG rustc_hir::definitions] DefPath::make: key=DefKey { parent: None, disambiguated_data: DisambiguatedDefPathData { data: CrateRoot, disambiguator: 0 } }
[DEBUG rustc_span::source_map] byte pos BytePos(0) is on the line at byte pos BytePos(0)
[DEBUG rustc_span::source_map] char pos CharPos(0) is on the line at char pos CharPos(0)
[DEBUG rustc_span::source_map] byte is on line: 1
[DEBUG rustc_span::source_map] byte pos BytePos(0) is on the line at byte pos BytePos(0)
[DEBUG rustc_span::source_map] char pos CharPos(0) is on the line at char pos CharPos(0)
[DEBUG rustc_span::source_map] byte is on line: 1

@tmiasko
Copy link
Contributor

tmiasko commented Jul 10, 2020

The TyCtx::struct_tail_with_normalize loops forever trying to find the deeply last tail of a struct.

Returning early after detecting a cycle or when type is non-representable avoids reported issue, although I am not sure if any of those would be a right solution.

@camelid
Copy link
Member

camelid commented Dec 5, 2020

This is the same as #79437 (as mentioned in #79437 (comment)), which is now fixed. I confirmed that the particular case in this issue is fixed now too.

EDIT: This isn't a duplicate: the other one was!

@camelid camelid closed this as completed Dec 5, 2020
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. 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

5 participants