Skip to content

ICE(?): LLVM ERROR: Broken module found, compilation aborted! #20544

Closed
@tikue

Description

@tikue

Sorry that this example isn't very minimal. I was basically just trying to use the Mul operator (*) as function composition.

#![feature(associated_types)]
#![feature(unboxed_closures)]
#![feature(default_type_params)]

use std::ops::Mul;

struct Fun<F: Fn(T) -> T, T>(F);

impl<F, T> Fn(T) -> T for Fun<F, T>
where 
    F: Fn(T) -> T {

    extern "rust-call" fn call(&self, (t,): (T,)) -> T {
        (self.0)(t)
    }
}

impl<T, F1, F2> Mul<Fun<F2, T>> for Fun<F1, T>
where 
    F1: Fn(T) -> T, 
    F2: Fn(T) -> T {

    type Output = Compose<Fun<F1, T>, Fun<F2, T>, T>;
    fn mul(self, rhs: Fun<F2, T>) -> Compose<Fun<F1, T>, Fun<F2, T>, T> {
        Compose{f1: self, f2: rhs}
    }
}


struct Compose<F1, F2, T> where F1: Fn(T) -> T, F2: Fn(T) -> T {
    f1: F1,
    f2: F2
}

impl<T, F1, F2> Fn(T) -> T for Compose<F1, F2, T> 
where
    F1: Fn(T) -> T,
    F2: Fn(T) -> T {

    extern "rust-call" fn call(&self, (t,): (T,)) -> T {
        (self.f1)((self.f2)(t))
    }
}

fn main() {
    let f1 = Fun(|i: int| i * 2);
    let f2 = Fun(|i: int| i - 1);
    let f3 = f1 * f2;
    println!("{}", f3(3));
}

The error when compiling:

Global is external, but doesn't have external or weak linkage!
i64 (%closure*, i64)* @_ZN4main20unboxed_closure.1371E
invalid linkage type for function declaration
i64 (%closure*, i64)* @_ZN4main20unboxed_closure.1371E
Global is external, but doesn't have external or weak linkage!
i64 (%closure.1*, i64)* @_ZN4main20unboxed_closure.1373E
invalid linkage type for function declaration
i64 (%closure.1*, i64)* @_ZN4main20unboxed_closure.1373E
LLVM ERROR: Broken module found, compilation aborted!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions