Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2ffdf97

Browse files
committedApr 30, 2024·
fix: self module FinishDeps bug
1 parent d9ddb35 commit 2ffdf97

File tree

1 file changed

+20
-30
lines changed
  • crates/rspack_core/src/compiler/module_executor

1 file changed

+20
-30
lines changed
 

‎crates/rspack_core/src/compiler/module_executor/ctrl.rs

+20-30
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ pub enum Event {
6363
pub struct CtrlTask {
6464
pub event_receiver: UnboundedReceiver<Event>,
6565
execute_task_map: HashMap<DependencyId, ExecuteTask>,
66-
finish_module_map: HashMap<ModuleIdentifier, UnfinishCounter>,
66+
running_module_map: HashMap<ModuleIdentifier, UnfinishCounter>,
6767
}
6868

6969
impl CtrlTask {
7070
pub fn new(event_receiver: UnboundedReceiver<Event>) -> Self {
7171
Self {
7272
event_receiver,
7373
execute_task_map: Default::default(),
74-
finish_module_map: Default::default(),
74+
running_module_map: Default::default(),
7575
}
7676
}
7777
}
@@ -87,33 +87,30 @@ impl Task<MakeTaskContext> for CtrlTask {
8787
match event {
8888
Event::StartBuild(module_identifier) => {
8989
self
90-
.as_mut()
91-
.finish_module_map
90+
.running_module_map
9291
.insert(module_identifier, UnfinishCounter::new());
9392
}
9493
Event::FinishDeps(origin_module_identifier, dep_id, target_module_graph) => {
9594
if let Some(target_module_graph) = target_module_graph {
96-
if let Some(value) = self.as_ref().finish_module_map.get(&target_module_graph) {
97-
if !value.is_finished() {
98-
continue;
99-
}
95+
if self.running_module_map.contains_key(&target_module_graph)
96+
&& Some(target_module_graph) != origin_module_identifier
97+
{
98+
continue;
10099
}
101100
}
102101

103102
// target module finished
104103
let Some(origin_module_identifier) = origin_module_identifier else {
105104
// origin_module_identifier is none means entry dep
106105
let execute_task = self
107-
.as_mut()
108106
.execute_task_map
109107
.remove(&dep_id)
110108
.expect("should have execute task");
111109
return Ok(vec![Box::new(execute_task), self]);
112110
};
113111

114112
let value = self
115-
.as_mut()
116-
.finish_module_map
113+
.running_module_map
117114
.get_mut(&origin_module_identifier)
118115
.expect("should have counter");
119116
value.minus_one();
@@ -126,8 +123,7 @@ impl Task<MakeTaskContext> for CtrlTask {
126123
}
127124
Event::FinishModule(mid, size) => {
128125
let value = self
129-
.as_mut()
130-
.finish_module_map
126+
.running_module_map
131127
.get_mut(&mid)
132128
.expect("should have counter");
133129
value.set_unfinished_child_module_count(size);
@@ -191,28 +187,24 @@ impl Task<MakeTaskContext> for FinishModuleTask {
191187
match event {
192188
Event::StartBuild(module_identifier) => {
193189
ctrl_task
194-
.as_mut()
195-
.finish_module_map
190+
.running_module_map
196191
.insert(module_identifier, UnfinishCounter::new());
197192
}
198193
Event::FinishDeps(origin_module_identifier, dep_id, target_module_graph) => {
199194
if let Some(target_module_graph) = target_module_graph {
200-
if let Some(value) = ctrl_task
201-
.as_ref()
202-
.finish_module_map
203-
.get(&target_module_graph)
195+
if ctrl_task
196+
.running_module_map
197+
.contains_key(&target_module_graph)
198+
&& Some(target_module_graph) != origin_module_identifier
204199
{
205-
if !value.is_finished() {
206-
continue;
207-
}
200+
continue;
208201
}
209202
}
210203

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

223215
let value = ctrl_task
224-
.as_mut()
225-
.finish_module_map
216+
.running_module_map
226217
.get_mut(&origin_module_identifier)
227218
.expect("should have counter");
228219
value.minus_one();
@@ -232,8 +223,7 @@ impl Task<MakeTaskContext> for FinishModuleTask {
232223
}
233224
Event::FinishModule(mid, size) => {
234225
let value = ctrl_task
235-
.as_mut()
236-
.finish_module_map
226+
.running_module_map
237227
.get_mut(&mid)
238228
.expect("should have counter");
239229
value.set_unfinished_child_module_count(size);
@@ -256,6 +246,8 @@ impl Task<MakeTaskContext> for FinishModuleTask {
256246
}
257247

258248
while let Some(module_identifier) = queue.pop_front() {
249+
ctrl_task.running_module_map.remove(&module_identifier);
250+
259251
let mgm = module_graph
260252
.module_graph_module_by_identifier(&module_identifier)
261253
.expect("should have mgm");
@@ -270,7 +262,6 @@ impl Task<MakeTaskContext> for FinishModuleTask {
270262
} else {
271263
// entry
272264
let execute_task = ctrl_task
273-
.as_mut()
274265
.execute_task_map
275266
.remove(&connection.dependency_id)
276267
.expect("should have execute task");
@@ -280,8 +271,7 @@ impl Task<MakeTaskContext> for FinishModuleTask {
280271

281272
for id in original_module_identifiers {
282273
let value = ctrl_task
283-
.as_mut()
284-
.finish_module_map
274+
.running_module_map
285275
.get_mut(&id)
286276
.expect("should have counter");
287277
value.minus_one();

0 commit comments

Comments
 (0)
Please sign in to comment.