plotnik_lib/ir/
ref_transition.rs

1//! Definition call/return markers for recursive transition network.
2//!
3//! See ADR-0005 for semantics of Enter/Exit transitions.
4
5use super::RefId;
6
7/// Marks a transition as entering or exiting a definition reference.
8///
9/// A transition can hold at most one `RefTransition`. Sequences like
10/// `Enter(A) → Enter(B)` require epsilon chains.
11///
12/// Layout: 1-byte discriminant + 1-byte padding + 2-byte RefId = 4 bytes, align 2.
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
14#[repr(C, u8)]
15pub enum RefTransition {
16    /// No definition boundary crossing.
17    #[default]
18    None,
19
20    /// Push call frame with return transitions.
21    ///
22    /// For `Enter(ref_id)` transitions, successors have special structure:
23    /// - `successors()[0]`: definition entry point (where to jump)
24    /// - `successors()[1..]`: return transitions (stored in call frame)
25    Enter(RefId),
26
27    /// Pop frame, continue with stored return transitions.
28    ///
29    /// Successors are ignored—returns come from the call frame pushed at `Enter`.
30    Exit(RefId),
31}
32
33impl RefTransition {
34    /// Returns `true` if this is `None`.
35    #[inline]
36    pub fn is_none(self) -> bool {
37        matches!(self, Self::None)
38    }
39
40    /// Returns the ref ID if this is `Enter` or `Exit`.
41    #[inline]
42    pub fn ref_id(self) -> Option<RefId> {
43        match self {
44            Self::None => None,
45            Self::Enter(id) | Self::Exit(id) => Some(id),
46        }
47    }
48}