Skip to main content

luaur_analysis/methods/
constraint_solver_is_blocked_constraint_solver.rs

1use crate::enums::type_function_instance_state::TypeFunctionInstanceState;
2use crate::functions::follow_type::follow_type_id;
3use crate::functions::get_type_alt_j::get_type_id;
4use crate::records::blocked_type::BlockedType;
5use crate::records::constraint_solver::ConstraintSolver;
6use crate::records::pending_expansion_type::PendingExpansionType;
7use crate::records::type_function_instance_type::TypeFunctionInstanceType;
8use crate::type_aliases::type_id::TypeId;
9
10impl ConstraintSolver {
11    pub fn is_blocked_type_id(&self, ty: TypeId) -> bool {
12        // FIXME CLI-180636: Eventually this should use the same logic as
13        // `SubtypingUnifier`, which is that blocked types are only based
14        // on their type and any additional state, rather than looking at
15        // `uninhabitedTypeFunctions`.
16        let ty = unsafe { follow_type_id(ty) };
17
18        let tfit = unsafe { get_type_id::<TypeFunctionInstanceType>(ty) };
19        if !tfit.is_null() {
20            if unsafe { (*tfit).state } != TypeFunctionInstanceState::Unsolved {
21                return false;
22            }
23
24            return !self
25                .uninhabited_type_functions
26                .contains(&(ty as *const core::ffi::c_void));
27        }
28
29        !unsafe { get_type_id::<BlockedType>(ty) }.is_null()
30            || !unsafe { get_type_id::<PendingExpansionType>(ty) }.is_null()
31    }
32}