air_mir/ir/nodes/ops/
vector.rs1use crate::ir::{BackLink, Builder, Child, Link, Node, Op, Owner, Parent, Singleton};
2use miden_diagnostics::{SourceSpan, Spanned};
3
4#[derive(Default, Clone, PartialEq, Eq, Debug, Hash, Builder, Spanned)]
7#[enum_wrapper(Op)]
8pub struct Vector {
9 pub parents: Vec<BackLink<Owner>>,
10 pub size: usize,
11 pub elements: Link<Vec<Link<Op>>>,
12 pub _node: Singleton<Node>,
13 pub _owner: Singleton<Owner>,
14 #[span]
15 pub span: SourceSpan,
16}
17
18impl Vector {
19 pub fn create(elements: Vec<Link<Op>>, span: SourceSpan) -> Link<Op> {
20 let size = elements.len();
21 Op::Vector(Self {
22 size,
23 elements: Link::new(elements),
24 span,
25 ..Default::default()
26 })
27 .into()
28 }
29}
30
31impl Parent for Vector {
32 type Child = Op;
33 fn children(&self) -> Link<Vec<Link<Self::Child>>> {
34 self.elements.clone()
35 }
36}
37
38impl Child for Vector {
39 type Parent = Owner;
40 fn get_parents(&self) -> Vec<BackLink<Self::Parent>> {
41 self.parents.clone()
42 }
43 fn add_parent(&mut self, parent: Link<Self::Parent>) {
44 self.parents.push(parent.into());
45 }
46 fn remove_parent(&mut self, parent: Link<Self::Parent>) {
47 self.parents.retain(|p| *p != parent.clone().into());
48 }
49}