mod convenience_operators {
use crate::{Op, Relation};
use std::ops::AddAssign;
use std::ops::Mul;
impl<C: Op> Relation<C> {
pub fn map<F: Fn(C::D) -> D2 + 'static, D2: 'static>(
self,
f: F,
) -> Relation<impl Op<D = D2, R = C::R>> {
self.map_dr(move |x, r| (f(x), r))
}
}
impl<K: 'static, V: 'static, C: Op<D = (K, V)>> Relation<C> {
pub fn semijoin<C2: Op<D = K, R = R2>, R2, R3: AddAssign<R3>>(
self,
other: Relation<C2>,
) -> Relation<impl Op<D = C::D, R = R3>>
where
C::R: Mul<R2, Output = R3>,
{
self.join(other.map(|x| (x, ()))).map(|(k, x, ())| (k, x))
}
}
}
mod core {
mod operator {
mod join {
use super::Op;
use crate::core::Relation;
use std::ops::{AddAssign, Mul};
struct Join<LC, RC> {
_left: LC,
_right: RC,
}
impl<
LC: Op<D = (K, LD), R = LR>,
RC: Op<D = (K, RD), R = RR>,
K: 'static,
LD: 'static,
LR: AddAssign<LR> + Mul<RR, Output = OR>,
RD: 'static,
RR: AddAssign<RR>,
OR: AddAssign<OR>,
> Op for Join<LC, RC>
{
type D = (K, LD, RD);
type R = OR;
}
impl<K: 'static, D: 'static, C: Op<D = (K, D)>> Relation<C> {
pub fn join<C2: Op<D = (K, D2)>, D2: 'static, OR: AddAssign<OR>>(
self,
other: Relation<C2>,
) -> Relation<impl Op<D = (K, D, D2), R = OR>>
where
C::R: Mul<C2::R, Output = OR>,
{
Relation {
inner: Join {
_left: self.inner,
_right: other.inner,
},
}
}
}
}
mod map {
use super::Op;
use crate::core::Relation;
use std::ops::AddAssign;
struct Map<C, MF> {
_inner: C,
_op: MF,
}
impl<
D1,
R1,
D2: 'static,
R2: AddAssign<R2>,
C: Op<D = D1, R = R1>,
MF: Fn(D1, R1) -> (D2, R2),
> Op for Map<C, MF>
{
type D = D2;
type R = R2;
}
impl<C: Op> Relation<C> {
pub fn map_dr<F: Fn(C::D, C::R) -> (D2, R2), D2: 'static, R2: AddAssign<R2>>(
self,
f: F,
) -> Relation<impl Op<D = D2, R = R2>> {
Relation {
inner: Map {
_inner: self.inner,
_op: f,
},
}
}
}
}
use std::ops::AddAssign;
pub trait Op {
type D: 'static;
type R: AddAssign<Self::R>;
}
}
pub use self::operator::Op;
#[derive(Clone)]
pub struct Relation<C> {
inner: C,
}
}
use self::core::Op;
pub use self::core::Relation;
rustc 1.52.0-nightly (07194ffcd 2021-02-10)
binary: rustc
commit-hash: 07194ffcd25b0871ce560b9f702e52db27ac9f77
commit-date: 2021-02-10
host: x86_64-unknown-linux-gnu
release: 1.52.0-nightly
LLVM version: 11.0.1
Compiling dc2 v0.1.0 (/home/david/projects/dc2)
error: internal compiler error: compiler/rustc_traits/src/normalize_erasing_regions.rs:43:32: could not fully normalize `core::Relation<impl core::operator::Op>`
thread 'rustc' panicked at 'Box<Any>', /rustc/07194ffcd25b0871ce560b9f702e52db27ac9f77/library/std/src/panic.rs:59:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
note: the compiler unexpectedly panicked. this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md
note: rustc 1.52.0-nightly (07194ffcd 2021-02-10) running on x86_64-unknown-linux-gnu
note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental --crate-type lib
note: some of the compiler flags provided by cargo are hidden
query stack during panic:
#0 [normalize_generic_arg_after_erasing_regions] normalizing `core::Relation<impl core::operator::Op>`
#1 [optimized_mir] optimizing MIR for `convenience_operators::<impl core::Relation<C>>::semijoin`
end of query stack
error: aborting due to previous error
error: could not compile `dc2`
To learn more, run the command again with --verbose.
Note that adding the (redundant) constraint
R2: AddAssign<R2>at line 16 makes the error go away.Inlining the call to
other.mapat line 23 results in the compile-time message "cannot add-assignR2toR2". Inlining the second call tomapat line 23 makes the error go away.Code
Meta
rustc --version --verbose:Error output
Backtrace