Skip to main content

luaur_analysis/methods/
normalizer_is_intersection_inhabited_normalize.rs

1//! Source: `Analysis/src/Normalize.cpp:542-555` (hand-ported)
2use crate::enums::normalization_result::NormalizationResult;
3use crate::records::fuel_initializer::FuelInitializer;
4use crate::records::normalizer::Normalizer;
5use crate::records::normalizer_hit_limits::NormalizerHitLimits;
6use crate::type_aliases::seen_table_prop_pairs::SeenTablePropPairs;
7use crate::type_aliases::type_id::TypeId;
8use luaur_common::records::dense_hash_set::DenseHashSet;
9
10impl Normalizer {
11    /// C++ `NormalizationResult Normalizer::isIntersectionInhabited(TypeId left, TypeId right)`.
12    /// Builds the seen sets, initializes normalization fuel, and delegates to the
13    /// seen-set overload. The Rust port does not model C++ exceptions; the
14    /// `NormalizerHitLimits` path surfaces through the delegate's return value.
15    pub fn is_intersection_inhabited_type_id_type_id(
16        &mut self,
17        left: TypeId,
18        right: TypeId,
19    ) -> NormalizationResult {
20        match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
21            let mut seen: DenseHashSet<TypeId> = DenseHashSet::new(core::ptr::null());
22            let mut seen_table_prop_pairs: SeenTablePropPairs =
23                SeenTablePropPairs::new((core::ptr::null(), core::ptr::null()));
24
25            let mut fi = FuelInitializer {
26                normalizer: self as *mut Normalizer,
27                initialized_fuel: false,
28            };
29            fi.fuel_initializer_not_null_normalizer(self as *mut Normalizer);
30            let _fi = fi;
31
32            self.is_intersection_inhabited_type_id_type_id_seen_table_prop_pairs_set_type_id(
33                left,
34                right,
35                &mut seen_table_prop_pairs,
36                &mut seen,
37            )
38        })) {
39            Ok(result) => result,
40            Err(payload) if payload.downcast_ref::<NormalizerHitLimits>().is_some() => {
41                NormalizationResult::HitLimits
42            }
43            Err(payload) => std::panic::resume_unwind(payload),
44        }
45    }
46}