Skip to main content

luaur_analysis/functions/
get_tail.rs

1//! Node: `cxx:Function:Luau.Analysis:Analysis/src/TypePack.cpp:225:getTail`
2//! Source: `Analysis/src/TypePack.cpp` (TypePack.cpp:225-243, hand-ported)
3
4use crate::functions::follow_type_pack::follow_type_pack_id;
5use crate::functions::get_type_pack::get_type_pack_id;
6use crate::records::type_pack::TypePack;
7use crate::type_aliases::type_pack_id::TypePackId;
8use luaur_common::records::dense_hash_set::DenseHashSet;
9
10pub fn get_tail(mut tp: TypePackId) -> TypePackId {
11    let mut seen: DenseHashSet<TypePackId> = DenseHashSet::new(core::ptr::null());
12    unsafe {
13        while !tp.is_null() {
14            tp = follow_type_pack_id(tp);
15
16            if seen.contains(&tp) {
17                break;
18            }
19            seen.insert(tp);
20
21            let pack = get_type_pack_id::<TypePack>(tp);
22            if !pack.is_null() {
23                if let Some(tail) = (*pack).tail {
24                    tp = tail;
25                    continue;
26                }
27            }
28            break;
29        }
30
31        follow_type_pack_id(tp)
32    }
33}