Skip to main content

luaur_analysis/methods/
constraint_solver_deprecate_d_shift_references.rs

1use crate::records::constraint_solver::ConstraintSolver;
2use crate::type_aliases::type_id::TypeId;
3use luaur_common::macros::luau_assert::LUAU_ASSERT;
4use luaur_common::FFlag;
5use std::collections::HashSet;
6
7impl ConstraintSolver {
8    pub fn deprecate_d_shift_references(&mut self, source: TypeId, target: TypeId) {
9        LUAU_ASSERT!(!FFlag::LuauConstraintGraph.get());
10        let target = unsafe { crate::functions::follow_type::follow_type_id(target) };
11
12        // if the target isn't a reference counted type, there's nothing to do.
13        // this stops us from keeping unnecessary counts for e.g. primitive types.
14        if !crate::functions::is_reference_counted_type::is_reference_counted_type(target) {
15            return;
16        }
17
18        if source == target {
19            return;
20        }
21
22        if let Some(sourcerefs) = self.deprecated_type_to_constraint_set.get(&source).cloned() {
23            for constraint in sourcerefs.iter() {
24                // For every constraint that the source might be modified by,
25                // add that constraint to the set of constraints the target
26                // might be modified by.
27                let targetrefs = self
28                    .deprecated_type_to_constraint_set
29                    .entry(target)
30                    .or_insert_with(HashSet::new);
31                targetrefs.insert(*constraint);
32
33                // Additionally, note that said constraint now may modify the target.
34                let (it, _) = self
35                    .deprecated_constraint_to_mutated_types
36                    .try_insert(*constraint, crate::records::type_ids::TypeIds::type_ids());
37                it.insert_type_id(target);
38            }
39        }
40    }
41}