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

Compilation does not end. #38335

Closed
kriw opened this issue Dec 13, 2016 · 5 comments
Closed

Compilation does not end. #38335

kriw opened this issue Dec 13, 2016 · 5 comments
Labels
T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@kriw
Copy link

kriw commented Dec 13, 2016

I tried a recursive function like Continuation-passing style.

I tried this code

use std::ops::Fn;

fn fact<F>(n: i64, f: F) -> i64 
    where F: Fn(i64) -> i64 {

    match n {
        1 => f(1),
        _ => fact(n-1, |x|{f(n * x)}),
    }
}
fn main(){
    let v = fact(5, |x|{x});
    println!("{:?}", v);
}

I expected the compilation would end or to see some compilation error, but the compilation is never finished without any error.
I made it simpler.

use std::ops::Fn;

fn rec<F>(f: F) -> i64 
    where F: Fn(i64) -> i64 {
    rec(|x|{f(x)})
}
fn main(){
    let _ = rec(|x|{x});
}

It also happened same problem.
Would you tell me why this problem has occured ?

Meta

rustc 1.13.0
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-apple-darwin
release: 1.13.0

@ghost
Copy link

ghost commented Dec 13, 2016

I was able to reproduce this on linux64, with same rustc version.

I had this output and then the process just used up 100% CPU until killed.

[xor@localhost rust]$ rustc test.rs
warning: function cannot return without recurring, #[warn(unconditional_recursion)] on by default
--> test.rs:3:1
|
3 | fn rec(f: F) -> i64
| ^
|
note: recursive call site
--> test.rs:5:5
|
5 | rec(|x|{f(x)})
| ^^^^^^^^^^^^^^
= help: a loop may express intention better if this is on purpose

Also: strace rustc test.rs 2> out.txt
out.txt

@aturon
Copy link
Member

aturon commented Dec 13, 2016

cc @eddyb

@eddyb
Copy link
Member

eddyb commented Dec 13, 2016

I think this is a duplicate. cc @rust-lang/compiler

@Mark-Simulacrum
Copy link
Member

Possibly fixed? I get the following when trying to compile:

warning: function cannot return without recurring, #[warn(unconditional_recursion)] on by default
 --> <anon>:3:1
  |
3 |   fn rec<F>(f: F) -> i64
  |  _^ starting here...
4 | |     where F: Fn(i64) -> i64 {
5 | |     rec(|x|{f(x)})
6 | | }
  | |_^ ...ending here
  |
note: recursive call site
 --> <anon>:5:5
  |
5 |     rec(|x|{f(x)})
  |     ^^^^^^^^^^^^^^
  = help: a `loop` may express intention better if this is on purpose

error: reached the type-length limit while instantiating `rec::<[closure@<anon>:5:9: 5:18 f:&[closure@<anon>:5:9: 5:18 f:&...`
 --> <anon>:3:1
  |
3 |   fn rec<F>(f: F) -> i64
  |  _^ starting here...
4 | |     where F: Fn(i64) -> i64 {
5 | |     rec(|x|{f(x)})
6 | | }
  | |_^ ...ending here
  |
  = note: consider adding a `#![type_length_limit="2097152"]` attribute to your crate

error: aborting due to previous error

@nikomatsakis
Copy link
Contributor

The latter error (reached the type-limit) was the fix to this problem. Closing.

@steveklabnik steveklabnik added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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

6 participants