use crate::records::conjunction_control_flow_graph::Conjunction;
use crate::records::disjunction_control_flow_graph::Disjunction;
use crate::records::negation_control_flow_graph::Negation;
use crate::records::proposition_control_flow_graph::Proposition;
use crate::records::refinement_arena_control_flow_graph::RefinementArena;
use crate::type_aliases::refinement_control_flow_graph::{Refinement, RefinementMember};
use crate::type_aliases::refinement_id_control_flow_graph::RefinementId;
use luaur_common::macros::luau_assert::LUAU_ASSERT;
impl RefinementArena {
pub fn negation_mut(&mut self, r: RefinementId) -> RefinementId {
let refinement: &Refinement = unsafe { &*r };
if let Some(conj) = <Conjunction as RefinementMember>::get_if(refinement) {
let (lhs, rhs) = (conj.lhs, conj.rhs);
let nl = self.negation_mut(lhs);
let nr = self.negation_mut(rhs);
return self.disjunction_mut(nl, nr);
}
if let Some(disj) = <Disjunction as RefinementMember>::get_if(refinement) {
let (lhs, rhs) = (disj.lhs, disj.rhs);
let nl = self.negation_mut(lhs);
let nr = self.negation_mut(rhs);
return self.conjunction_mut(nl, nr);
}
if let Some(neg) = <Negation as RefinementMember>::get_if(refinement) {
return neg.refinement;
}
LUAU_ASSERT!(<Proposition as RefinementMember>::get_if(refinement).is_some());
self.allocator
.allocate(Refinement::Negation(Negation { refinement: r }))
}
}