xir/
context.rs

1use crate::span::Span;
2use bumpalo::Bump;
3use core::cell::RefCell;
4use std::collections::HashSet;
5
6/// An allocator.
7pub type Allocator<'a> = &'a Bump;
8
9/// A context.
10#[derive(Debug, Default)]
11pub struct Context<'a> {
12    allocator: Bump,
13    spans: RefCell<HashSet<Span<'a>>>,
14}
15
16impl<'a> Context<'a> {
17    /// Creates a context.
18    pub fn new() -> Self {
19        Self {
20            allocator: Bump::new(),
21            spans: Default::default(),
22        }
23    }
24
25    /// Returns an allocator.
26    pub const fn allocator(&self) -> &Bump {
27        &self.allocator
28    }
29
30    pub(crate) const fn spans(&self) -> &RefCell<HashSet<Span<'a>>> {
31        &self.spans
32    }
33}