luaur_analysis/methods/
subtyping_cache.rs1use crate::records::subtyping::Subtyping;
2use crate::records::subtyping_environment::SubtypingEnvironment;
3use crate::records::subtyping_result::SubtypingResult;
4use crate::records::type_pair_hash::TypePairHash;
5use crate::type_aliases::type_id::TypeId;
6use crate::type_aliases::type_pack_id::TypePackId;
7use luaur_common::records::dense_hash_table::DenseHasher;
8
9impl DenseHasher<(TypeId, TypeId)> for TypePairHash {
10 fn hash(&self, x: &(TypeId, TypeId)) -> usize {
11 self.operator_call(*x)
12 }
13}
14
15impl DenseHasher<(TypePackId, TypePackId)> for TypePairHash {
18 fn hash(&self, x: &(TypePackId, TypePackId)) -> usize {
19 self.operator_call_2(*x)
20 }
21}
22
23impl Subtyping {
24 pub fn cache(
25 &mut self,
26 _env: &mut SubtypingEnvironment,
27 result: SubtypingResult,
28 sub_ty: TypeId,
29 super_ty: TypeId,
30 ) -> SubtypingResult {
31 let p = (sub_ty, super_ty);
32
33 if result.is_cacheable {
34 *self.result_cache.get_or_insert(p) = result.clone();
35 }
36
37 result
38 }
39}