Skip to content

Commit

Permalink
Allow Relation<T> to be joined with Variable<(T, S)>
Browse files Browse the repository at this point in the history
This case occurred in `Polonius`, where we had to create a separate
`Relation<(T, ())>` to make things work.
  • Loading branch information
ecstatic-morse committed Aug 12, 2021
1 parent 25c7774 commit 675b629
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,24 @@ impl<'me, Tuple: Ord> JoinInput<'me, Tuple> for &'me Relation<Tuple> {
&[]
}
}

impl<'me, Tuple: Ord> JoinInput<'me, (Tuple, ())> for &'me Relation<Tuple> {
type RecentTuples = &'me [(Tuple, ())];
type StableTuples = &'me [Relation<(Tuple, ())>];

fn recent(self) -> Self::RecentTuples {
use std::mem;
assert_eq!(mem::size_of::<(Tuple, ())>(), mem::size_of::<Tuple>());
assert_eq!(mem::align_of::<(Tuple, ())>(), mem::align_of::<Tuple>());

// SAFETY: https://rust-lang.github.io/unsafe-code-guidelines/layout/structs-and-tuples.html#structs-with-1-zst-fields
// guarantees that `T` is layout compatible with `(T, ())`, since `()` is a 1-ZST.
let elements: &'me [Tuple] = self.elements.as_slice();
let elements: &'me [(Tuple, ())] = unsafe { std::mem::transmute(elements) };
elements
}

fn stable(self) -> Self::StableTuples {
&[]
}
}

0 comments on commit 675b629

Please sign in to comment.