core: Add PrimitiveStore into Unifier

This will be used during unification between a const generic variable
and a `Literal`.
This commit is contained in:
David Mak 2023-12-13 18:23:32 +08:00
parent 8d47d6d4dd
commit 875d08e9bb
4 changed files with 19 additions and 1 deletions

View File

@ -580,6 +580,7 @@ pub fn gen_func_impl<'ctx, G: CodeGenerator, F: FnOnce(&mut G, &mut CodeGenConte
let (unifier, primitives) = &top_level_ctx.unifiers.read()[task.unifier_index];
(Unifier::from_shared_unifier(unifier), *primitives)
};
unifier.put_primitive_store(&primitives);
unifier.top_level = Some(top_level_ctx.clone());
let mut cache = HashMap::new();

View File

@ -145,6 +145,7 @@ impl TopLevelComposer {
exception,
option,
};
unifier.put_primitive_store(&primitives);
crate::typecheck::magic_methods::set_primitives_magic_methods(&primitives, &mut unifier);
(primitives, unifier)
}

View File

@ -148,6 +148,7 @@ impl TestEnvironment {
uint64,
option,
};
unifier.put_primitive_store(&primitives);
set_primitives_magic_methods(&primitives, &mut unifier);
let id_to_name = [
@ -296,6 +297,8 @@ impl TestEnvironment {
option,
};
unifier.put_primitive_store(&primitives);
let (v0, id) = unifier.get_dummy_var();
let foo_ty = unifier.add_ty(TypeEnum::TObj {

View File

@ -13,6 +13,7 @@ use super::type_error::{TypeError, TypeErrorKind};
use super::unification_table::{UnificationKey, UnificationTable};
use crate::symbol_resolver::SymbolValue;
use crate::toplevel::{DefinitionId, TopLevelContext, TopLevelDef};
use crate::typecheck::type_inferencer::PrimitiveStore;
#[cfg(test)]
mod test;
@ -211,7 +212,8 @@ pub struct Unifier {
pub(crate) calls: Vec<Rc<Call>>,
var_id: u32,
unify_cache: HashSet<(Type, Type)>,
snapshot: Option<(usize, u32)>
snapshot: Option<(usize, u32)>,
primitive_store: Option<PrimitiveStore>,
}
impl Default for Unifier {
@ -231,9 +233,19 @@ impl Unifier {
unify_cache: HashSet::new(),
top_level: None,
snapshot: None,
primitive_store: None,
}
}
/// Sets the [PrimitiveStore] instance within this `Unifier`.
///
/// This function can only be invoked once. Any subsequent invocations will result in an
/// assertion error..
pub fn put_primitive_store(&mut self, primitives: &PrimitiveStore) {
assert!(self.primitive_store.is_none());
self.primitive_store.replace(primitives.clone());
}
pub unsafe fn get_unification_table(&mut self) -> &mut UnificationTable<Rc<TypeEnum>> {
&mut self.unification_table
}
@ -252,6 +264,7 @@ impl Unifier {
top_level: None,
unify_cache: HashSet::new(),
snapshot: None,
primitive_store: None,
}
}