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

Recursive generics #118449

Open
notdanilo opened this issue Nov 29, 2023 · 3 comments
Open

Recursive generics #118449

notdanilo opened this issue Nov 29, 2023 · 3 comments
Labels
A-type-system Area: Type system C-bug Category: This is a bug. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. P-low Low priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@notdanilo
Copy link

I tried this code alone:

trait HasParent {
    type Parent: HasParent;
}

struct Visitor<'a, Type>
where Type: HasParent
{
    parent: &'a Visitor<'a, Type::Parent>,
    current: &'a Type
}

I expected to see this happen: Being able to compile OR error message.

I also expect the following evaluation to be possible, breaking the recursion, because no further monomorphization is necessary:

struct Library;
struct Module;

impl HasParent for Module {
    type Parent = Library;
}

impl HasParent for Library {
    type Parent = ();
}

impl HasParent for () {
    type Parent = ();
}

which would produce

struct Visitor<'a, ()> {
    parent: &'a Visitor<'a, ()>,
    current: &'a ()
}

struct Visitor<'a, Library> {
    parent: &'a Visitor<'a, ()>,
    current: &'a Library
}

struct Visitor<'a, Module> {
    parent: &'a Visitor<'a, Library>,
    current: &'a Module
}

Instead, this happened: The compiler freezes.

Meta

rustc --version --verbose:

rustc 1.74.0 (79e9716c9 2023-11-13)
binary: rustc
commit-hash: 79e9716c980570bfd1f666e3b16ac583f0168962
commit-date: 2023-11-13
host: x86_64-pc-windows-msvc
release: 1.74.0
LLVM version: 17.0.4
Backtrace

No backtrace available

@notdanilo notdanilo added the C-bug Category: This is a bug. label Nov 29, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 29, 2023
@DaniPopes
Copy link
Contributor

searched toolchains nightly-2017-07-17 through nightly-2023-11-29

Regression in nightly-2018-09-13

found 7 bors merge commits in the specified range
commit[0] 2018-09-11: Auto merge of #53873 - nikomatsakis:nll-universe-subtyping-and-pattern-ascription, r=pnkfelix
commit[1] 2018-09-11: Auto merge of #53913 - petrochenkov:biattr4, r=alexcrichton
commit[2] 2018-09-12: Auto merge of #51159 - pacman82:master, r=oli-obk
commit[3] 2018-09-12: Auto merge of #54146 - kennytm:rollup, r=kennytm
commit[4] 2018-09-12: Auto merge of #53793 - toidiu:ak-stabalize, r=nikomatsakis
commit[5] 2018-09-12: Auto merge of #54152 - michaelwoerister:cgu-name-fix, r=alexcrichton
commit[6] 2018-09-12: Auto merge of #53409 - GuillaumeGomez:associated-const-value, r=QuietMisdreavus

Script:

#!/usr/bin/env bash

timeout 3s rustc --crate-type lib src/lib.rs
code=$?
echo "code=$code"
test $code -ne 124

@jieyouxu jieyouxu added A-type-system Area: Type system 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. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Feb 18, 2024
@arHSM
Copy link

arHSM commented Mar 19, 2024

Albeit a workaround but modifying the Visitor struct to be as so fixes this issue

trait ParentVisitor<'a>: HasParent {
    type Visitor;
}

impl<'a, T> ParentVisitor<'a> for T
where
    T: HasParent,
    T::Parent: 'a,
{
    type Visitor = Visitor<'a, T::Parent>;
}

struct Visitor<'a, Type>
where
    Type: HasParent,
{
    parent: &'a <Type as ParentVisitor<'a>>::Visitor,
    current: &'a Type,
}

@lolbinarycat lolbinarycat added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Sep 8, 2024
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Sep 8, 2024
@lolbinarycat
Copy link
Contributor

triage: still hangs in the latest stable and nightly

@BoxyUwU BoxyUwU added P-low Low priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Sep 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system C-bug Category: This is a bug. I-hang Issue: The compiler never terminates, due to infinite loops, deadlock, livelock, etc. P-low Low priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. S-has-mcve Status: A Minimal Complete and Verifiable Example has been found for this issue 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

7 participants