-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
ICE(?): LLVM ERROR: Broken module found, compilation aborted! #20544
Comments
probably a dup of #20174 |
@tikue as a workaround, your code works if you change |
Thank you @pfalabella! |
That last struct abstraction does not work anymore : how can we express it now ? |
Here is a working version. #![feature(unboxed_closures)]
#![feature(core)]
use std::ops::Mul;
struct Fun<F: Fn(T) -> T, T>(F, std::marker::PhantomData<T>);
impl<F, T> FnOnce<(T,)> for Fun<F, T> where F: Fn(T) -> T {
type Output = T;
extern "rust-call" fn call_once(self, args: (T,)) -> T {
self.call(args)
}
}
impl<F, T> FnMut<(T,)> for Fun<F, T> where F: Fn(T) -> T {
extern "rust-call" fn call_mut(&mut self, args: (T,)) -> T {
self.call(args)
}
}
impl<F, T> Fn<(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, _ph: std::marker::PhantomData}
}
}
struct Compose<F1, F2, T> where F1: Fn(T) -> T, F2: Fn(T) -> T {
f1: F1,
f2: F2,
_ph: std::marker::PhantomData<T>,
}
impl<T, F1, F2> FnOnce<(T,)> for Compose<F1, F2, T> where F1: Fn(T) -> T, F2: Fn(T) -> T {
type Output = T;
extern "rust-call" fn call_once(self, args: (T,)) -> T {
self.call(args)
}
}
impl<T, F1, F2> FnMut<(T,)> for Compose<F1, F2, T> where F1: Fn(T) -> T, F2: Fn(T) -> T {
extern "rust-call" fn call_mut(&mut self, args: (T,)) -> T {
self.call(args)
}
}
impl<T, F1, F2> Fn<(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: isize| i * 2, std::marker::PhantomData::<isize>);
let f2 = Fun(|i: isize| i - 1, std::marker::PhantomData::<isize>);
let f3 = f1 * f2;
println!("{}", f3(3));
} |
And a minimal example: #![feature(unboxed_closures)]
#![feature(core)]
struct Fun<F>(F);
impl<F, T> FnOnce<(T,)> for Fun<F> where F: Fn(T) -> T {
type Output = T;
extern "rust-call" fn call_once(self, (t,): (T,)) -> T {
(self.0)(t)
}
}
fn main() {
let fun = Fun(|i: isize| i * 2);
println!("{}", fun(3));
} |
@Stebalien both examples compile and run on my machine with the latest nightly. |
@pmarcelll yes they do. This can probably be closed. |
Sorry that this example isn't very minimal. I was basically just trying to use the Mul operator (*) as function composition.
The error when compiling:
The text was updated successfully, but these errors were encountered: