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

LLVM Segmentation fault - destructuring newtype with closure #20174

Closed
pfalabella opened this issue Dec 23, 2014 · 4 comments
Closed

LLVM Segmentation fault - destructuring newtype with closure #20174

pfalabella opened this issue Dec 23, 2014 · 4 comments
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@pfalabella
Copy link
Contributor

this code:

struct GradFn<F: Fn() -> uint>(F);

fn main() {
    let GradFn(x_squared) : GradFn<_> = GradFn(|| -> uint { 2u });
    let _  = x_squared();
}

ICEs with:

Global is external, but doesn't have external or weak linkage!
i64 (%closure*)* @_ZN4main19unboxed_closure.944E
invalid linkage type for function declaration
i64 (%closure*)* @_ZN4main19unboxed_closure.944E
LLVM ERROR: Broken module found, compilation aborted!
Segmentation fault
$ rustc --version --verbose
rustc 0.13.0-nightly (34d680009 2014-12-22 00:12:47 +0000)
binary: rustc
commit-hash: 34d680009205de2302b902d8f9f5f7ae7a042f1a
commit-date: 2014-12-22 00:12:47 +0000
host: x86_64-pc-windows-gnu
release: 0.13.0-nightly
@pfalabella pfalabella changed the title ICE destructuring newtype with closure LLVM Segmentation fault - destructuring newtype with closure Dec 23, 2014
@pfalabella
Copy link
Contributor Author

I thought this was due to what @japaric says in this comment, but it's not.
Even changing the declaration of the closure to use |&: |, to make sure the compiler sees it as an unboxed closure, like this:

#![feature(unboxed_closures)]
struct GradFn<F: Fn() -> uint>(F);

fn main() {
    let g = GradFn(|&:| 2u);
    let GradFn(f) = g; // LLVM error
    println!("{}", f.call(()));
}

I get the same LLVM error.
Note that a struct with one named element, instead of the newtype, works as expected:

#![feature(unboxed_closures)]
struct GradFn<F: Fn() -> uint> {f: F} // just named the element

fn main() {
    let g = GradFn{f: |&:| 2u };
    let GradFn { f } = g; // destructuring instead of accessing the element by name
                                   // to keep code as similar as possible as the previous one 
    println!("{}", f.call(())); // compiles and prints 2   
}

@kmcallister kmcallister added I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. labels Jan 6, 2015
@zslayton
Copy link
Contributor

zslayton commented Feb 8, 2015

I'm running into this issue as well. As an additional data point, I wanted to mention that the destructuring appears to work fine if the closure that's supplied to the struct is declared in advance.

For example:

struct GradFn<F: Fn() -> usize>(F);

fn main() {
    let grad_fn = || -> usize { 2us };
    let GradFn(x_squared) : GradFn<_> = GradFn(grad_fn);
    let _  = x_squared();
}

Playpen

Version information:

$ rustc --version --verbose
rustc 1.0.0-nightly (74b874071 2015-02-08 00:24:03 +0000)
binary: rustc
commit-hash: 74b8740719c1b427f79b67d6bc51e9d448dd9c49
commit-date: 2015-02-08 00:24:03 +0000
host: x86_64-unknown-linux-gnu
release: 1.0.0-nightly

@pfalabella
Copy link
Contributor Author

this is now working correctly for me (on c4fe7d6 2015-02-23)

@ghost ghost added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Apr 20, 2015
@frewsxcv
Copy link
Member

All of the codeblocks in this issue are working for me with 1.0 beta2. Can this be closed?

@bors bors closed this as completed in 341fb57 May 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

4 participants