mirror of
https://github.com/roc-lang/roc.git
synced 2025-10-01 15:51:12 +00:00
keep track of pending phases, so we don't repeat work
This commit is contained in:
parent
e9ee9704f1
commit
04cdc2a276
2 changed files with 70 additions and 11 deletions
|
@ -80,10 +80,18 @@ const PHASES: [Phase; 6] = [
|
||||||
Phase::MakeSpecializations,
|
Phase::MakeSpecializations,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
enum Status {
|
||||||
|
NotStarted,
|
||||||
|
Pending,
|
||||||
|
Done,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
struct Dependencies {
|
struct Dependencies {
|
||||||
waiting_for: MutMap<(ModuleId, Phase), MutSet<(ModuleId, Phase)>>,
|
waiting_for: MutMap<(ModuleId, Phase), MutSet<(ModuleId, Phase)>>,
|
||||||
notifies: MutMap<(ModuleId, Phase), MutSet<(ModuleId, Phase)>>,
|
notifies: MutMap<(ModuleId, Phase), MutSet<(ModuleId, Phase)>>,
|
||||||
|
status: MutMap<(ModuleId, Phase), Status>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dependencies {
|
impl Dependencies {
|
||||||
|
@ -126,6 +134,8 @@ impl Dependencies {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.add_to_status(module_id, goal_phase);
|
||||||
|
|
||||||
let mut output = MutSet::default();
|
let mut output = MutSet::default();
|
||||||
|
|
||||||
// all the dependencies can be loaded
|
// all the dependencies can be loaded
|
||||||
|
@ -158,6 +168,8 @@ impl Dependencies {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.add_to_status(module_id, goal_phase);
|
||||||
|
|
||||||
let mut output = MutSet::default();
|
let mut output = MutSet::default();
|
||||||
|
|
||||||
// all the dependencies can be loaded
|
// all the dependencies can be loaded
|
||||||
|
@ -168,8 +180,22 @@ impl Dependencies {
|
||||||
output
|
output
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn add_to_status(&mut self, module_id: ModuleId, goal_phase: Phase) {
|
||||||
|
for phase in PHASES.iter() {
|
||||||
|
if *phase > goal_phase {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Vacant(entry) = self.status.entry((module_id, *phase)) {
|
||||||
|
entry.insert(Status::NotStarted);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Propagate a notification, return (module, phase) pairs that can make progress
|
/// Propagate a notification, return (module, phase) pairs that can make progress
|
||||||
pub fn notify(&mut self, module_id: ModuleId, phase: Phase) -> MutSet<(ModuleId, Phase)> {
|
pub fn notify(&mut self, module_id: ModuleId, phase: Phase) -> MutSet<(ModuleId, Phase)> {
|
||||||
|
self.status.insert((module_id, phase), Status::Done);
|
||||||
|
|
||||||
let mut output = MutSet::default();
|
let mut output = MutSet::default();
|
||||||
|
|
||||||
let key = (module_id, phase);
|
let key = (module_id, phase);
|
||||||
|
@ -229,7 +255,18 @@ impl Dependencies {
|
||||||
fn solved_all(&self) -> bool {
|
fn solved_all(&self) -> bool {
|
||||||
debug_assert_eq!(self.notifies.is_empty(), self.waiting_for.is_empty());
|
debug_assert_eq!(self.notifies.is_empty(), self.waiting_for.is_empty());
|
||||||
|
|
||||||
self.notifies.is_empty()
|
for status in self.status.values() {
|
||||||
|
match status {
|
||||||
|
Status::Done => {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -258,6 +295,32 @@ struct ModuleCache<'a> {
|
||||||
|
|
||||||
fn start_phase<'a>(module_id: ModuleId, phase: Phase, state: &mut State<'a>) -> BuildTask<'a> {
|
fn start_phase<'a>(module_id: ModuleId, phase: Phase, state: &mut State<'a>) -> BuildTask<'a> {
|
||||||
// we blindly assume all dependencies are met
|
// we blindly assume all dependencies are met
|
||||||
|
|
||||||
|
match state.dependencies.status.get_mut(&(module_id, phase)) {
|
||||||
|
Some(current @ Status::NotStarted) => {
|
||||||
|
// start this phase!
|
||||||
|
*current = Status::Pending;
|
||||||
|
}
|
||||||
|
Some(Status::Pending) | Some(Status::Done) => {
|
||||||
|
// don't start this task again!
|
||||||
|
todo!();
|
||||||
|
}
|
||||||
|
|
||||||
|
None => match phase {
|
||||||
|
Phase::LoadHeader => {
|
||||||
|
// this is fine, mark header loading as pending
|
||||||
|
state
|
||||||
|
.dependencies
|
||||||
|
.status
|
||||||
|
.insert((module_id, Phase::LoadHeader), Status::Pending);
|
||||||
|
}
|
||||||
|
_ => unreachable!(
|
||||||
|
"Pair {:?} is not in dependencies.status, that should never happen!",
|
||||||
|
(module_id, phase)
|
||||||
|
),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
match phase {
|
match phase {
|
||||||
Phase::LoadHeader => {
|
Phase::LoadHeader => {
|
||||||
let dep_name = state
|
let dep_name = state
|
||||||
|
@ -1604,6 +1667,10 @@ fn update<'a>(
|
||||||
|
|
||||||
state.module_cache.mono_problems.insert(module_id, problems);
|
state.module_cache.mono_problems.insert(module_id, problems);
|
||||||
|
|
||||||
|
state.procedures.extend(procedures);
|
||||||
|
state.constrained_ident_ids.insert(module_id, ident_ids);
|
||||||
|
state.timings.insert(module_id, module_timing);
|
||||||
|
|
||||||
for (module_id, requested) in external_specializations_requested {
|
for (module_id, requested) in external_specializations_requested {
|
||||||
let existing = match state
|
let existing = match state
|
||||||
.module_cache
|
.module_cache
|
||||||
|
@ -1617,20 +1684,12 @@ fn update<'a>(
|
||||||
existing.extend(requested);
|
existing.extend(requested);
|
||||||
}
|
}
|
||||||
|
|
||||||
state.procedures.extend(procedures);
|
|
||||||
|
|
||||||
let work = state
|
let work = state
|
||||||
.dependencies
|
.dependencies
|
||||||
.notify(module_id, Phase::MakeSpecializations);
|
.notify(module_id, Phase::MakeSpecializations);
|
||||||
|
|
||||||
state.constrained_ident_ids.insert(module_id, ident_ids);
|
if state.dependencies.solved_all() && state.goal_phase == Phase::MakeSpecializations {
|
||||||
|
debug_assert!(work.is_empty());
|
||||||
state.timings.insert(module_id, module_timing);
|
|
||||||
|
|
||||||
if work.is_empty()
|
|
||||||
&& state.dependencies.solved_all()
|
|
||||||
&& state.goal_phase == Phase::MakeSpecializations
|
|
||||||
{
|
|
||||||
// display the mono IR of the module, for debug purposes
|
// display the mono IR of the module, for debug purposes
|
||||||
if roc_mono::ir::PRETTY_PRINT_IR_SYMBOLS {
|
if roc_mono::ir::PRETTY_PRINT_IR_SYMBOLS {
|
||||||
let procs_string = state
|
let procs_string = state
|
||||||
|
|
0
examples/effect/ConsList.roc
Normal file
0
examples/effect/ConsList.roc
Normal file
Loading…
Add table
Add a link
Reference in a new issue