65 lines
1.9 KiB
Rust
65 lines
1.9 KiB
Rust
|
|
//! Carrier variable metadata for JoinIR loop lowering
|
||
|
|
//!
|
||
|
|
//! This module defines metadata structures for tracking carrier variables
|
||
|
|
//! in loop lowering. This enables dynamic generation of exit bindings
|
||
|
|
//! without hardcoded variable names or ValueIds.
|
||
|
|
|
||
|
|
use crate::mir::ValueId;
|
||
|
|
|
||
|
|
/// Information about a single carrier variable
|
||
|
|
#[derive(Debug, Clone)]
|
||
|
|
pub struct CarrierVar {
|
||
|
|
/// Variable name (e.g., "sum", "printed")
|
||
|
|
pub name: String,
|
||
|
|
/// Host ValueId for this variable
|
||
|
|
pub host_id: ValueId,
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Complete carrier information for a loop
|
||
|
|
#[derive(Debug, Clone)]
|
||
|
|
pub struct CarrierInfo {
|
||
|
|
/// Loop control variable name (e.g., "i")
|
||
|
|
pub loop_var_name: String,
|
||
|
|
/// Loop control variable ValueId in host
|
||
|
|
pub loop_var_id: ValueId,
|
||
|
|
/// Additional carrier variables (e.g., sum, printed)
|
||
|
|
pub carriers: Vec<CarrierVar>,
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Exit metadata returned by lowerers
|
||
|
|
///
|
||
|
|
/// This structure captures the mapping from JoinIR exit values to
|
||
|
|
/// carrier variable names, enabling dynamic binding generation.
|
||
|
|
#[derive(Debug, Clone)]
|
||
|
|
pub struct ExitMeta {
|
||
|
|
/// Exit value bindings: (carrier_name, join_exit_value_id)
|
||
|
|
///
|
||
|
|
/// Example for Pattern 4:
|
||
|
|
/// ```
|
||
|
|
/// vec![("sum".to_string(), ValueId(15))]
|
||
|
|
/// ```
|
||
|
|
/// where ValueId(15) is the k_exit parameter in JoinIR-local space.
|
||
|
|
pub exit_values: Vec<(String, ValueId)>,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl ExitMeta {
|
||
|
|
/// Create new ExitMeta with no exit values
|
||
|
|
pub fn empty() -> Self {
|
||
|
|
Self {
|
||
|
|
exit_values: vec![],
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Create ExitMeta with a single exit value
|
||
|
|
pub fn single(carrier_name: String, join_value: ValueId) -> Self {
|
||
|
|
Self {
|
||
|
|
exit_values: vec![(carrier_name, join_value)],
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Create ExitMeta with multiple exit values
|
||
|
|
pub fn multiple(exit_values: Vec<(String, ValueId)>) -> Self {
|
||
|
|
Self { exit_values }
|
||
|
|
}
|
||
|
|
}
|