Skip to main content

luaur_analysis/methods/
instance_collector_cycle.rs

1use crate::functions::follow_type::follow_type_id;
2use crate::functions::get_type_alt_j::get_type_id;
3use crate::records::instance_collector::InstanceCollector;
4use crate::records::type_function_instance_type::TypeFunctionInstanceType;
5use crate::type_aliases::type_id::TypeId;
6
7impl InstanceCollector {
8    pub fn cycle(&mut self, ty: TypeId) {
9        let t = unsafe { follow_type_id(ty) };
10
11        let it = unsafe { get_type_id::<TypeFunctionInstanceType>(t) };
12        if !it.is_null() {
13            // If we see a type a second time and it's in the type function stack, it's a real cycle
14            if self
15                .type_function_instance_stack
16                .iter()
17                .any(|&x| x == t as *const core::ffi::c_void)
18            {
19                self.cyclic_instance.push(t);
20            }
21        }
22    }
23}