Skip to main content

luaur_analysis/functions/
make_table_shared_normalize.rs

1use crate::functions::follow_type::follow_type_id;
2use crate::functions::get_mutable_type::get_mutable_type_id;
3use crate::functions::get_type_alt_j::get_type_id;
4use crate::records::metatable_type::MetatableType;
5use crate::records::table_type::TableType;
6use crate::type_aliases::type_id::TypeId;
7use luaur_common::records::dense_hash_set::DenseHashSet;
8
9pub fn make_table_shared_type_id_dense_hash_set_type_id(
10    ty: TypeId,
11    seen: &mut DenseHashSet<TypeId>,
12) {
13    let mut ty = unsafe { follow_type_id(ty) };
14
15    if seen.contains(&ty) {
16        return;
17    }
18
19    seen.insert(ty);
20
21    let table_ty_ptr = unsafe { get_mutable_type_id::<TableType>(ty) };
22    if !table_ty_ptr.is_null() {
23        let table_ty = unsafe { &mut *table_ty_ptr };
24        for (_, prop) in &mut table_ty.props {
25            if prop.write_ty.is_some() {
26                prop.write_ty = prop.read_ty;
27            }
28        }
29        return;
30    }
31
32    let metatable_ty_ptr = unsafe { get_type_id::<MetatableType>(ty) };
33    if !metatable_ty_ptr.is_null() {
34        let metatable_ty = unsafe { &*metatable_ty_ptr };
35        make_table_shared_type_id_dense_hash_set_type_id(metatable_ty.metatable(), seen);
36        make_table_shared_type_id_dense_hash_set_type_id(metatable_ty.table(), seen);
37    }
38}