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

Compiler Hang Issue when Using the iso_un_option Function #117151

Closed
iamanonymouscs opened this issue Oct 25, 2023 · 1 comment · Fixed by #117754
Closed

Compiler Hang Issue when Using the iso_un_option Function #117151

iamanonymouscs opened this issue Oct 25, 2023 · 1 comment · Fixed by #117754
Assignees
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

@iamanonymouscs
Copy link

cat hang.rs

pub type ISO<A: 'static, B: 'static> = (Box<dyn Fn(A) -> B>, Box<dyn Fn(B) -> A>);
pub fn iso<A: 'static, B: 'static, F1, F2>(a: F1, b: F2) -> ISO<A, B>
where
    F1: 'static + Fn(A) -> B,
    F2: 'static + Fn(B) -> A,
{
    (Box::new(a), Box::new(b))
}
pub fn iso_un_option<A: 'static, B: 'static>(i: ISO<Option<A>, Option<B>>) -> ISO<A, B> {
    let (ab, ba) = (i.ab, i.ba);
    let left = move |o_a| match o_a {
        None => panic!("absured"),
        Some(a) => a,
    };
    let right = move |o_b| match o_b {
        None => panic!("absurd"),
        Some(b) => b,
    };
    iso(left, right)
}
pub fn iso_un_option<A: 'static, B: 'static>(i: ISO<Option<A>, B>) -> ISO<A, B> {
    let (ab, ba) = (i.ab, i.ba);
    let left = move |o_a| match o_a {
        None => panic!("absured"),
        Some(a) => a,
    };
    let right = move |o_b| match o_b {
        None => panic!("absurd"),
        Some(b) => b,
    };
    iso(left, right)
}

I expected to see this happen: The compiler compiles successfully or outputs an error message.

Instead, this happened: The code, as provided below, appears to encounter a hang

Command

rustc hang.rs

Meta

rustc --version --verbose:

rustc 1.73.0 (cc66ad468 2023-10-03)
binary: rustc
commit-hash: cc66ad468955717ab92600c770da8c1601a4ff33
commit-date: 2023-10-03
host: x86_64-unknown-linux-gnu
release: 1.73.0
LLVM version: 17.0.2

The same problem is reproduced on the nightly version(1.75.0-nightly 1c05d50c8 2023-10-21)

what's more, to get more information,I also tried '-Z time-passes' (using nighly version):

Output

time:   0.001; rss:   28MB ->   31MB (   +2MB)  parse_crate
error[E0428]: the name `iso_un_option` is defined multiple times
  --> hang.rs:21:1
   |
9  | pub fn iso_un_option<A: 'static, B: 'static>(i: ISO<Option<A>, Option<B>>) -> ISO<A, B> {
   | --------------------------------------------------------------------------------------- previous definition of the value `iso_un_option` here
...
21 | pub fn iso_un_option<A: 'static, B: 'static>(i: ISO<Option<A>, B>) -> ISO<A, B> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `iso_un_option` redefined here
   |
   = note: `iso_un_option` must be defined only once in the value namespace of this module

time:   0.008; rss:   34MB ->   50MB (  +16MB)  expand_crate
time:   0.008; rss:   34MB ->   50MB (  +16MB)  macro_expand_crate
time:   0.001; rss:   50MB ->   53MB (   +3MB)  late_resolve_crate
time:   0.002; rss:   50MB ->   53MB (   +3MB)  resolve_crate
error[E0601]: `main` function not found in crate `hang`
  --> hang.rs:32:2
   |
32 | }
   |  ^ consider adding a `main` function to `hang.rs`

time:   0.007; rss:   53MB ->   59MB (   +6MB)  looking_for_entry_point
time:   0.007; rss:   53MB ->   60MB (   +7MB)  misc_checking_1
time:   0.002; rss:   60MB ->   66MB (   +6MB)  wf_checking
error[E0609]: no field `ab` on type `(Box<(dyn Fn(Option<A>) -> Option<B> + 'static)>, Box<(dyn Fn(Option<B>) -> Option<A> + 'static)>)`
  --> hang.rs:10:23
   |
10 |     let (ab, ba) = (i.ab, i.ba);
   |                       ^^

error[E0609]: no field `ba` on type `(Box<(dyn Fn(Option<A>) -> Option<B> + 'static)>, Box<(dyn Fn(Option<B>) -> Option<A> + 'static)>)`
  --> hang.rs:10:29
   |
10 |     let (ab, ba) = (i.ab, i.ba);
   |                     

@iamanonymouscs iamanonymouscs added the C-bug Category: This is a bug. label Oct 25, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 25, 2023
@saethlin saethlin 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. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 25, 2023
@matthewjasper matthewjasper self-assigned this Oct 25, 2023
@matthewjasper
Copy link
Contributor

Smaller version that should only have a cycle/overflow error, but instead hangs

use std::ptr;

pub type ISO<A, B> = (Box<dyn Fn(A) -> B>, Box<dyn Fn(B) -> A>);
pub fn iso<A: 'static, B: 'static, F1, F2>(a: F1, b: F2) -> ISO<A, B>
where
    F1: 'static + Fn(A) -> B,
    F2: 'static + Fn(B) -> A,
{
    (Box::new(a), Box::new(b))
}

pub fn iso_un_option<A: 'static, B: 'static>() {
    let left = |o_a| unsafe { ptr::read(o_a) };
    let right = |o_b| unsafe { ptr::read(o_b) };
    //~^ ERROR mismatched types
    iso(left, right);
}

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

Successfully merging a pull request may close this issue.

4 participants