mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
Add LayoutInterner to LayoutCache
Adds a thread-local interner of layouts to LayoutCache, and updates all references appropriately. This is a bit suboptimal for single-threaded workloads that will look at creating layout caches again, like the REPL, but I think that's okay for now - since the global interner will be uncontested for those workloads, it should still be plenty fast to access the interner, even behind a lock.
This commit is contained in:
parent
9d170be5c7
commit
c5466810a4
19 changed files with 177 additions and 86 deletions
|
@ -4,6 +4,7 @@ use bumpalo::Bump;
|
|||
use roc_builtins::bitcode::{FloatWidth, IntWidth};
|
||||
use roc_collections::all::{default_hasher, FnvMap, MutMap};
|
||||
use roc_error_macros::{internal_error, todo_abilities};
|
||||
use roc_intern::ThreadLocalInterner;
|
||||
use roc_module::ident::{Lowercase, TagName};
|
||||
use roc_module::symbol::{Interns, Symbol};
|
||||
use roc_problem::can::RuntimeError;
|
||||
|
@ -95,6 +96,8 @@ macro_rules! inc_stat {
|
|||
};
|
||||
}
|
||||
|
||||
pub type LayoutInterner<'a> = ThreadLocalInterner<'a, Layout<'a>>;
|
||||
|
||||
/// Layout cache to avoid recomputing [Layout] from a [Variable] multiple times.
|
||||
#[derive(Debug)]
|
||||
pub struct LayoutCache<'a> {
|
||||
|
@ -102,6 +105,9 @@ pub struct LayoutCache<'a> {
|
|||
cache: std::vec::Vec<CacheLayer<LayoutResult<'a>>>,
|
||||
raw_function_cache: std::vec::Vec<CacheLayer<RawFunctionLayoutResult<'a>>>,
|
||||
|
||||
#[allow(unused)] // TODO remove me
|
||||
interner: LayoutInterner<'a>,
|
||||
|
||||
/// Statistics on the usage of the layout cache.
|
||||
#[cfg(debug_assertions)]
|
||||
stats: CacheStatistics,
|
||||
|
@ -110,7 +116,7 @@ pub struct LayoutCache<'a> {
|
|||
}
|
||||
|
||||
impl<'a> LayoutCache<'a> {
|
||||
pub fn new(target_info: TargetInfo) -> Self {
|
||||
pub fn new(interner: LayoutInterner<'a>, target_info: TargetInfo) -> Self {
|
||||
let mut cache = std::vec::Vec::with_capacity(4);
|
||||
cache.push(CacheLayer::default());
|
||||
let mut raw_cache = std::vec::Vec::with_capacity(4);
|
||||
|
@ -120,6 +126,8 @@ impl<'a> LayoutCache<'a> {
|
|||
cache,
|
||||
raw_function_cache: raw_cache,
|
||||
|
||||
interner,
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
stats: CacheStatistics::default(),
|
||||
#[cfg(debug_assertions)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue