Skip to main content

luaur_analysis/methods/
normalizer_union_functions.rs

1use crate::records::normalized_function_type::NormalizedFunctionType;
2use crate::records::normalizer::Normalizer;
3use crate::records::type_ids::TypeIds;
4use crate::type_aliases::type_id::TypeId;
5
6impl Normalizer {
7    pub fn union_functions(
8        &mut self,
9        heres: &mut NormalizedFunctionType,
10        theres: &NormalizedFunctionType,
11    ) {
12        self.consume_fuel();
13
14        if heres.is_top {
15            return;
16        }
17        if theres.is_top {
18            heres.reset_to_top();
19        }
20
21        if theres.is_never() {
22            return;
23        }
24
25        let mut tmps = TypeIds::type_ids();
26
27        if heres.is_never() {
28            tmps = theres.parts.clone();
29            heres.parts = tmps;
30            return;
31        }
32
33        let heres_parts = heres.parts.clone();
34        let theres_parts = theres.parts.clone();
35
36        for here in heres_parts.order {
37            for there in theres_parts.order.iter() {
38                let there = *there;
39                if let Some(fun) = self.union_of_functions(here, there) {
40                    tmps.insert_type_id(fun);
41                } else {
42                    let builtin_types = unsafe { &*self.builtin_types };
43                    tmps.insert_type_id(builtin_types.error_recovery_type(there));
44                }
45            }
46        }
47
48        heres.parts = tmps;
49    }
50}