pub struct SoaAst {
pub tags: Vec<NodeTag>,
pub data: Vec<NodeData>,
pub extra: Vec<u32>,
pub items: Vec<NodeIndex>,
}Expand description
Struct-of-Arrays AST representation.
This is the new SOA-based AST that will replace the tree-based Ast.
During migration (Phases 2-3), both representations will coexist.
Design principles:
- All nodes stored in parallel arrays (tags, data, extra)
- Nodes reference children by index, not pointers
- Single allocation for entire AST (better cache locality)
- Cheap cloning (just clone Arc, not deep copy)
See docs/designs/soa-ast-layout.md for full design.
Fields§
Node tags (what kind of node is at each index).
Index i contains the tag for node NodeIndex(i). Length of this vec == number of nodes in the AST.
data: Vec<NodeData>Node data (main_token + lhs + rhs for each node).
Parallel array to tags - tags[i] and data[i] together describe node i.
extra: Vec<u32>Extra data storage for nodes with >2 children.
Nodes that can’t fit their data in lhs+rhs store additional data here. The lhs or rhs field contains an index into this array.
Layout is node-type specific - see NodeTag documentation.
items: Vec<NodeIndex>Root nodes (top-level items in the source file).
These are the entry points for traversing the AST. Each element is a NodeIndex pointing to a Function, StructDecl, etc.
Implementations§
Source§impl SoaAst
impl SoaAst
Sourcepub fn with_capacity(nodes: usize, extra: usize) -> Self
pub fn with_capacity(nodes: usize, extra: usize) -> Self
Create a new SOA AST with pre-allocated capacity.
Sourcepub fn main_token(&self, idx: NodeIndex) -> u32
pub fn main_token(&self, idx: NodeIndex) -> u32
Get the main token for a node.
Sourcepub fn node_count(&self) -> usize
pub fn node_count(&self) -> usize
Get the number of nodes in the AST.
Sourcepub fn extra_slice(&self, start: usize, len: usize) -> &[u32]
pub fn extra_slice(&self, start: usize, len: usize) -> &[u32]
Get a slice of the extra data array.
Sourcepub fn bool_value(&self, idx: NodeIndex) -> bool
pub fn bool_value(&self, idx: NodeIndex) -> bool
Get the boolean value of a boolean literal.
Sourcepub fn string_spur(&self, idx: NodeIndex) -> Spur
pub fn string_spur(&self, idx: NodeIndex) -> Spur
Get the string spur of a string literal.
Sourcepub fn ident_spur(&self, idx: NodeIndex) -> Spur
pub fn ident_spur(&self, idx: NodeIndex) -> Spur
Get the identifier spur.
Sourcepub fn binary_operands(&self, idx: NodeIndex) -> (NodeIndex, NodeIndex)
pub fn binary_operands(&self, idx: NodeIndex) -> (NodeIndex, NodeIndex)
Get the operands of a binary expression.
Sourcepub fn unary_operand(&self, idx: NodeIndex) -> NodeIndex
pub fn unary_operand(&self, idx: NodeIndex) -> NodeIndex
Get the operand of a unary expression.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SoaAst
impl RefUnwindSafe for SoaAst
impl Send for SoaAst
impl Sync for SoaAst
impl Unpin for SoaAst
impl UnwindSafe for SoaAst
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
impl<'src, T> IntoMaybe<'src, T> for Twhere
T: 'src,
§impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
§type Iter<'a> = Once<&'a T>
where
T: 'a
type Iter<'a> = Once<&'a T> where T: 'a
§fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
fn contains(&self, val: &T) -> boolwhere
T: PartialEq,
§fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>where
'p: 'b,
MaybeRef].