more basic infra

This commit is contained in:
Folkert 2021-08-03 22:59:24 +02:00
parent e1fc9322d9
commit ad12e1e509

View file

@ -13,6 +13,7 @@ use ven_ena::unify::{InPlace, Snapshot, UnificationTable, UnifyKey};
static_assertions::assert_eq_size!([u8; 104], Descriptor); static_assertions::assert_eq_size!([u8; 104], Descriptor);
static_assertions::assert_eq_size!([u8; 88], Content); static_assertions::assert_eq_size!([u8; 88], Content);
static_assertions::assert_eq_size!([u8; 80], FlatType); static_assertions::assert_eq_size!([u8; 80], FlatType);
static_assertions::assert_eq_size!([u8; 48], Problem);
#[derive(Clone, Copy, Hash, PartialEq, Eq)] #[derive(Clone, Copy, Hash, PartialEq, Eq)]
pub struct Mark(i32); pub struct Mark(i32);
@ -52,9 +53,10 @@ struct ErrorTypeState {
#[derive(Default, Clone)] #[derive(Default, Clone)]
pub struct Subs { pub struct Subs {
utable: UnificationTable<InPlace<Variable>>, utable: UnificationTable<InPlace<Variable>>,
// variables: Vec<Variable>, variables: Vec<Variable>,
// tag_names: Vec<TagName>, tag_names: Vec<TagName>,
// field_names: Vec<Lowercase>, field_names: Vec<Lowercase>,
record_fields: Vec<RecordField<()>>,
} }
#[repr(packed(2))] #[repr(packed(2))]
@ -86,8 +88,22 @@ impl<T> Default for SubsSlice<T> {
} }
} }
pub trait GetSubsSlice<T> { impl<T> SubsSlice<T> {
fn get_subs_slice(subs: &Subs, subs_slice: SubsSlice<T>) -> &[T]; pub fn get_slice<'a>(&self, slice: &'a [T]) -> &'a [T] {
&slice[..self.start as usize][..self.length as usize]
}
}
pub trait GetSubsSlice {
fn get_subs_slice(subs: &Subs, subs_slice: SubsSlice<Self>) -> &[Self]
where
Self: Sized;
}
impl GetSubsSlice for Variable {
fn get_subs_slice(subs: &Subs, subs_slice: SubsSlice<Self>) -> &[Self] {
subs_slice.get_slice(&subs.variables)
}
} }
impl fmt::Debug for Subs { impl fmt::Debug for Subs {
@ -299,6 +315,7 @@ impl Subs {
let mut subs = Subs { let mut subs = Subs {
utable: UnificationTable::default(), utable: UnificationTable::default(),
..Default::default()
}; };
// NOTE the utable does not (currently) have a with_capacity; using this as the next-best thing // NOTE the utable does not (currently) have a with_capacity; using this as the next-best thing