mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Push wrapped layout interners through
This commit is contained in:
parent
947158b17e
commit
b60d5c0251
7 changed files with 86 additions and 40 deletions
|
@ -23,7 +23,7 @@ use std::hash::{Hash, Hasher};
|
|||
use ven_pretty::{DocAllocator, DocBuilder};
|
||||
|
||||
mod intern;
|
||||
pub use intern::{STLayoutInterner, TLLayoutInterner};
|
||||
pub use intern::{GlobalLayoutInterner, LayoutInterner, STLayoutInterner, TLLayoutInterner};
|
||||
|
||||
// if your changes cause this number to go down, great!
|
||||
// please change it to the lower number.
|
||||
|
|
|
@ -1,6 +1,60 @@
|
|||
use roc_intern::{SingleThreadedInterner, ThreadLocalInterner};
|
||||
use std::sync::Arc;
|
||||
|
||||
use roc_intern::{GlobalInterner, Interned, Interner, SingleThreadedInterner, ThreadLocalInterner};
|
||||
|
||||
use super::Layout;
|
||||
|
||||
pub type TLLayoutInterner<'a> = ThreadLocalInterner<'a, Layout<'a>>;
|
||||
pub type STLayoutInterner<'a> = SingleThreadedInterner<'a, Layout<'a>>;
|
||||
pub trait LayoutInterner<'a>: Interner<'a, Layout<'a>> {}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GlobalLayoutInterner<'a>(Arc<GlobalInterner<'a, Layout<'a>>>);
|
||||
#[derive(Debug)]
|
||||
pub struct TLLayoutInterner<'a>(ThreadLocalInterner<'a, Layout<'a>>);
|
||||
#[derive(Debug)]
|
||||
pub struct STLayoutInterner<'a>(SingleThreadedInterner<'a, Layout<'a>>);
|
||||
|
||||
impl<'a> GlobalLayoutInterner<'a> {
|
||||
pub fn with_capacity(capacity: usize) -> Self {
|
||||
Self(GlobalInterner::with_capacity(capacity))
|
||||
}
|
||||
pub fn fork(&self) -> TLLayoutInterner<'a> {
|
||||
TLLayoutInterner(self.0.fork())
|
||||
}
|
||||
pub fn unwrap(self) -> Result<STLayoutInterner<'a>, Self> {
|
||||
match self.0.unwrap() {
|
||||
Ok(st) => Ok(STLayoutInterner(st)),
|
||||
Err(global) => Err(Self(global)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> STLayoutInterner<'a> {
|
||||
pub fn with_capacity(capacity: usize) -> Self {
|
||||
Self(SingleThreadedInterner::with_capacity(capacity))
|
||||
}
|
||||
pub fn into_global(self) -> GlobalLayoutInterner<'a> {
|
||||
GlobalLayoutInterner(self.0.into_global())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Interner<'a, Layout<'a>> for TLLayoutInterner<'a> {
|
||||
fn insert(&mut self, value: &'a Layout<'a>) -> Interned<Layout<'a>> {
|
||||
self.0.insert(value)
|
||||
}
|
||||
|
||||
fn get(&self, key: Interned<Layout<'a>>) -> &'a Layout<'a> {
|
||||
self.0.get(key)
|
||||
}
|
||||
}
|
||||
impl<'a> LayoutInterner<'a> for TLLayoutInterner<'a> {}
|
||||
|
||||
impl<'a> Interner<'a, Layout<'a>> for STLayoutInterner<'a> {
|
||||
fn insert(&mut self, value: &'a Layout<'a>) -> Interned<Layout<'a>> {
|
||||
self.0.insert(value)
|
||||
}
|
||||
|
||||
fn get(&self, key: Interned<Layout<'a>>) -> &'a Layout<'a> {
|
||||
self.0.get(key)
|
||||
}
|
||||
}
|
||||
impl<'a> LayoutInterner<'a> for STLayoutInterner<'a> {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue