Skip to main content

luaur_analysis/methods/
constraint_graph_dump_with.rs

1use crate::functions::to_string_to_string_alt_m::to_string_type_id_to_string_options;
2use crate::functions::to_string_to_string_alt_n::to_string_type_pack_id_to_string_options;
3use crate::functions::to_string_to_string_alt_q::to_string_constraint_to_string_options;
4use crate::records::constraint::Constraint;
5use crate::records::constraint_graph::ConstraintGraph;
6use crate::records::to_string_options::ToStringOptions;
7use crate::type_aliases::constraint_vertex::ConstraintVertex;
8use alloc::vec::Vec;
9use core::ptr::NonNull;
10
11impl ConstraintGraph {
12    pub fn dump_with(
13        &mut self,
14        unsolved_constraints: &Vec<NonNull<Constraint>>,
15        opts: &mut ToStringOptions,
16    ) {
17        // TODO: It might be nice to *also* dump the types here.
18        std::print!("constraints:\n");
19        for c in unsolved_constraints.iter() {
20            let c_ptr = c.as_ptr() as *const Constraint;
21            let deps = self.find_dependency_list(ConstraintVertex::V2(c_ptr));
22            let deps_ref = unsafe { deps.as_ref() };
23            std::print!(
24                "\t{}\t{}\n",
25                deps_ref.size(),
26                to_string_constraint_to_string_options(unsafe { &*c_ptr }, opts)
27            );
28
29            for dep in deps_ref.order.iter() {
30                // The C++ `for (auto dep : *deps)` iterates only present entries.
31                if !deps_ref.contains(dep.clone()) {
32                    continue;
33                }
34
35                if let Some(ty) = dep.get_if_0() {
36                    std::print!(
37                        "\t\t|\tType {}\n",
38                        to_string_type_id_to_string_options(*ty, opts)
39                    );
40                } else if let Some(tp) = dep.get_if_1() {
41                    std::print!(
42                        "\t\t|\tPack {}\n",
43                        to_string_type_pack_id_to_string_options(*tp, opts)
44                    );
45                } else if let Some(cons) = dep.get_if_2() {
46                    std::print!(
47                        "\t\t|\tCons {}\n",
48                        to_string_constraint_to_string_options(unsafe { &**cons }, opts)
49                    );
50                }
51            }
52        }
53    }
54}