diff options
| author | Thomas Voss <mail@thomasvoss.com> | 2026-03-15 23:07:01 +0100 |
|---|---|---|
| committer | Thomas Voss <mail@thomasvoss.com> | 2026-03-15 23:07:25 +0100 |
| commit | bb4d0a8b49aed021fe8f13893d2e651923368c23 (patch) | |
| tree | c80e4c63581cac95f5998daa11b8e477c1f07a28 /oryxc | |
| parent | 72b874a081fed4788378e16b0bfb3a0ed7e5725f (diff) | |
New DepMap type
Diffstat (limited to 'oryxc')
| -rw-r--r-- | oryxc/src/compiler.rs | 19 | ||||
| -rw-r--r-- | oryxc/src/depmap.rs | 31 |
2 files changed, 37 insertions, 13 deletions
diff --git a/oryxc/src/compiler.rs b/oryxc/src/compiler.rs index 1c1240e..123475e 100644 --- a/oryxc/src/compiler.rs +++ b/oryxc/src/compiler.rs @@ -27,13 +27,13 @@ use crossbeam_deque::{ Stealer, Worker, }; -use dashmap::DashMap; use soa_rs::Soa; use crate::arena::{ GlobalArena, LocalArena, }; +use crate::depmap::DepMap; use crate::errors::OryxError; use crate::hashtrie::HTrie; use crate::intern::Interner; @@ -85,6 +85,7 @@ impl FileData { } #[allow(dead_code)] +#[derive(Clone)] pub enum JobType { Lex { file: FileId, @@ -107,6 +108,8 @@ pub enum JobType { } mkidtype!(JobId); + +#[derive(Clone)] pub struct Job { id: JobId, kind: JobType, @@ -125,7 +128,7 @@ struct CompilerState<'a> { * order to avoid any potential undefined behaviour. */ interner: Interner<UniStr<'a>, SymbolId>, files: Vec<Arc<FileData>>, - deps: DashMap<usize, boxcar::Vec<Job>>, + deps: DepMap, next_id: AtomicU32, types: boxcar::Vec<OryxType>, } @@ -168,15 +171,6 @@ impl<'a> CompilerState<'a> { fn job_complete(&self) -> usize { return self.njobs.fetch_sub(1, Ordering::Release) - 1; } - - /// Push all jobs that depend on JOB to QUEUE, clearing the dep list. - fn job_push_deps(&self, job: JobId, queue: &Worker<Job>) { - if let Some((_, deps)) = self.deps.remove(&(job.0 as usize)) { - for x in deps { - self.job_push(&queue, x); - } - } - } } /// Initialize compiler state and drive all source files through the @@ -214,7 +208,7 @@ where flags, worker_threads: OnceLock::new(), interner: Interner::new(), - deps: DashMap::new(), + deps: DepMap::with_capacity(256), next_id: AtomicU32::new(njobs as u32), /* Temporary solution */ types: boxcar::vec![ @@ -451,7 +445,6 @@ fn worker_loop( ok = false; } - c_state.job_push_deps(job.id, &queue); if c_state.job_complete() == 0 { c_state.wake_all(); return ok; diff --git a/oryxc/src/depmap.rs b/oryxc/src/depmap.rs new file mode 100644 index 0000000..60e358e --- /dev/null +++ b/oryxc/src/depmap.rs @@ -0,0 +1,31 @@ +use boxcar; +use dashmap::DashMap; + +use crate::compiler::Job; +use crate::prelude::*; + +pub struct DepMap(DashMap<Dependency, boxcar::Vec<Job>>); + +#[derive(Eq, Hash, PartialEq)] +pub enum Dependency { + Symbol(SymbolId), +} + +impl DepMap { + pub fn with_capacity(n: usize) -> Self { + return Self(DashMap::with_capacity(n)); + } + + pub fn add(&self, d: Dependency, j: Job) { + self.0 + .entry(d) + .and_modify(|v| { + v.push(j.clone()); + }) + .or_insert_with(|| boxcar::vec![j]); + } + + pub fn pop(&self, d: Dependency) -> Option<boxcar::Vec<Job>> { + return self.0.remove(&d).map(|(_, v)| v); + } +} |