Skip to content

Commit

Permalink
fix: self module FinishDeps bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrykingxyz committed Apr 30, 2024
1 parent d9ddb35 commit 2ffdf97
Showing 1 changed file with 20 additions and 30 deletions.
50 changes: 20 additions & 30 deletions crates/rspack_core/src/compiler/module_executor/ctrl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ pub enum Event {
pub struct CtrlTask {
pub event_receiver: UnboundedReceiver<Event>,
execute_task_map: HashMap<DependencyId, ExecuteTask>,
finish_module_map: HashMap<ModuleIdentifier, UnfinishCounter>,
running_module_map: HashMap<ModuleIdentifier, UnfinishCounter>,
}

impl CtrlTask {
pub fn new(event_receiver: UnboundedReceiver<Event>) -> Self {
Self {
event_receiver,
execute_task_map: Default::default(),
finish_module_map: Default::default(),
running_module_map: Default::default(),
}
}
}
Expand All @@ -87,33 +87,30 @@ impl Task<MakeTaskContext> for CtrlTask {
match event {
Event::StartBuild(module_identifier) => {
self
.as_mut()
.finish_module_map
.running_module_map
.insert(module_identifier, UnfinishCounter::new());
}
Event::FinishDeps(origin_module_identifier, dep_id, target_module_graph) => {
if let Some(target_module_graph) = target_module_graph {
if let Some(value) = self.as_ref().finish_module_map.get(&target_module_graph) {
if !value.is_finished() {
continue;
}
if self.running_module_map.contains_key(&target_module_graph)
&& Some(target_module_graph) != origin_module_identifier
{
continue;
}
}

// target module finished
let Some(origin_module_identifier) = origin_module_identifier else {
// origin_module_identifier is none means entry dep
let execute_task = self
.as_mut()
.execute_task_map
.remove(&dep_id)
.expect("should have execute task");
return Ok(vec![Box::new(execute_task), self]);
};

let value = self
.as_mut()
.finish_module_map
.running_module_map
.get_mut(&origin_module_identifier)
.expect("should have counter");
value.minus_one();
Expand All @@ -126,8 +123,7 @@ impl Task<MakeTaskContext> for CtrlTask {
}
Event::FinishModule(mid, size) => {
let value = self
.as_mut()
.finish_module_map
.running_module_map
.get_mut(&mid)
.expect("should have counter");
value.set_unfinished_child_module_count(size);
Expand Down Expand Up @@ -191,28 +187,24 @@ impl Task<MakeTaskContext> for FinishModuleTask {
match event {
Event::StartBuild(module_identifier) => {
ctrl_task
.as_mut()
.finish_module_map
.running_module_map
.insert(module_identifier, UnfinishCounter::new());
}
Event::FinishDeps(origin_module_identifier, dep_id, target_module_graph) => {
if let Some(target_module_graph) = target_module_graph {
if let Some(value) = ctrl_task
.as_ref()
.finish_module_map
.get(&target_module_graph)
if ctrl_task
.running_module_map
.contains_key(&target_module_graph)
&& Some(target_module_graph) != origin_module_identifier
{
if !value.is_finished() {
continue;
}
continue;
}
}

// target module finished
let Some(origin_module_identifier) = origin_module_identifier else {
// origin_module_identifier is none means entry dep
let execute_task = ctrl_task
.as_mut()
.execute_task_map
.remove(&dep_id)
.expect("should have execute task");
Expand All @@ -221,8 +213,7 @@ impl Task<MakeTaskContext> for FinishModuleTask {
};

let value = ctrl_task
.as_mut()
.finish_module_map
.running_module_map
.get_mut(&origin_module_identifier)
.expect("should have counter");
value.minus_one();
Expand All @@ -232,8 +223,7 @@ impl Task<MakeTaskContext> for FinishModuleTask {
}
Event::FinishModule(mid, size) => {
let value = ctrl_task
.as_mut()
.finish_module_map
.running_module_map
.get_mut(&mid)
.expect("should have counter");
value.set_unfinished_child_module_count(size);
Expand All @@ -256,6 +246,8 @@ impl Task<MakeTaskContext> for FinishModuleTask {
}

while let Some(module_identifier) = queue.pop_front() {
ctrl_task.running_module_map.remove(&module_identifier);

let mgm = module_graph
.module_graph_module_by_identifier(&module_identifier)
.expect("should have mgm");
Expand All @@ -270,7 +262,6 @@ impl Task<MakeTaskContext> for FinishModuleTask {
} else {
// entry
let execute_task = ctrl_task
.as_mut()
.execute_task_map
.remove(&connection.dependency_id)
.expect("should have execute task");
Expand All @@ -280,8 +271,7 @@ impl Task<MakeTaskContext> for FinishModuleTask {

for id in original_module_identifiers {
let value = ctrl_task
.as_mut()
.finish_module_map
.running_module_map
.get_mut(&id)
.expect("should have counter");
value.minus_one();
Expand Down

0 comments on commit 2ffdf97

Please sign in to comment.