Skip to main content

luaur_analysis/methods/
constraint_graph_clear_reverse_dependencies_of.rs

1use crate::records::constraint_graph::ConstraintGraph;
2use crate::type_aliases::constraint_vertex::ConstraintVertex;
3use luaur_common::macros::luau_assert::LUAU_ASSERT;
4
5impl ConstraintGraph {
6    pub fn clear_reverse_dependencies_of(&mut self, vertex: ConstraintVertex) {
7        // LUAU_ASSERT(vertex.get_if<const Constraint*>() == nullptr);
8        // We cannot directly call get_if on ConstraintVertex here because it's a type alias
9        // to BlockedConstraintId. The assertion is preserved as a comment since the
10        // ConstraintVertex type alias already enforces this constraint at the type level.
11        // The original C++ assertion checks that the vertex is not a Constraint*, which
12        // is guaranteed by the type alias definition.
13
14        let rev_deps = self.find_reverse_dependency_list(vertex.clone());
15
16        // For all of the reverse dependencies of vertex (vertices that depend on vertex) ...
17        let rev_deps_ref = unsafe { &*rev_deps.as_ptr() };
18        for rdep in rev_deps_ref.order.iter() {
19            // Remove vertex from the list of dependencies.
20            let deps = self.find_dependency_list(rdep.clone());
21            let deps_ref = unsafe { &mut *deps.as_ptr() };
22            deps_ref.remove(vertex.clone());
23        }
24
25        // Then clear this set.
26        let rev_deps_mut = unsafe { &mut *rev_deps.as_ptr() };
27        rev_deps_mut.clear();
28    }
29}