Skip to content

Commit 4cba8aa

Browse files
committed
Revert "fix: active_callback_triggers"
This reverts commit bc18577.
1 parent bc18577 commit 4cba8aa

5 files changed

Lines changed: 25 additions & 85 deletions

File tree

crates/jsshaker/src/analyzer/exhaustive.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
use std::{
2-
cell::RefCell,
32
hash::{Hash, Hasher},
43
mem,
54
rc::Rc,
65
};
76

87
use oxc::allocator;
9-
use rustc_hash::FxHashSet;
108

119
use crate::{
1210
analyzer::{Analyzer, rw_tracking::ReadWriteTarget},
@@ -28,7 +26,6 @@ pub struct ExhaustiveData<'a> {
2826
pub struct ExhaustiveCallback<'a> {
2927
pub handler: Rc<dyn Fn(&mut Analyzer<'a>) -> Entity<'a> + 'a>,
3028
pub drain: bool,
31-
pub triggered: Rc<RefCell<FxHashSet<ReadWriteTarget<'a>>>>,
3229
}
3330
impl PartialEq for ExhaustiveCallback<'_> {
3431
fn eq(&self, other: &Self) -> bool {
@@ -136,11 +133,11 @@ impl<'a> Analyzer<'a> {
136133
deps: allocator::HashSet<ReadWriteTarget<'a>>,
137134
) {
138135
for id in deps {
139-
self.exhaustive_callbacks.entry(id).or_default().insert(ExhaustiveCallback {
140-
handler: handler.clone(),
141-
drain,
142-
triggered: Default::default(),
143-
});
136+
self
137+
.exhaustive_callbacks
138+
.entry(id)
139+
.or_default()
140+
.insert(ExhaustiveCallback { handler: handler.clone(), drain });
144141
}
145142
}
146143

@@ -150,10 +147,7 @@ impl<'a> Analyzer<'a> {
150147
if let Some(callbacks) = self.exhaustive_callbacks.get_mut(&id)
151148
&& !callbacks.is_empty()
152149
{
153-
for callback in callbacks.drain() {
154-
callback.triggered.borrow_mut().insert(id);
155-
self.pending_callbacks.insert(callback);
156-
}
150+
self.pending_deps.extend(callbacks.drain());
157151
found = true;
158152
}
159153
};
@@ -163,17 +157,15 @@ impl<'a> Analyzer<'a> {
163157
}
164158

165159
pub fn call_exhaustive_callbacks(&mut self) -> bool {
166-
if self.pending_callbacks.is_empty() {
160+
if self.pending_deps.is_empty() {
167161
return false;
168162
}
169163
let old_try_catch_depth = self.scoping.try_catch_depth.take();
170164
loop {
171-
for callback in mem::take(&mut self.pending_callbacks) {
172-
self.active_callback_triggers.extend(&callback.triggered.borrow());
173-
self.exec_exhaustively("dep", callback.drain, true, callback.handler.clone());
174-
self.active_callback_triggers.unextend(&callback.triggered.borrow());
165+
for ExhaustiveCallback { drain, handler } in mem::take(&mut self.pending_deps) {
166+
self.exec_exhaustively("dep", drain, true, handler.clone());
175167
}
176-
if self.pending_callbacks.is_empty() {
168+
if self.pending_deps.is_empty() {
177169
self.scoping.try_catch_depth = old_try_catch_depth;
178170
return true;
179171
}

crates/jsshaker/src/analyzer/mod.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::{
2828
mangling::Mangler,
2929
module::{ModuleId, Modules},
3030
scope::Scoping,
31-
utils::{ExtraData, counter::Counter},
31+
utils::ExtraData,
3232
value::{FnStats, literal::symbol::SymbolRegistry},
3333
vfs::Vfs,
3434
};
@@ -55,8 +55,7 @@ pub struct Analyzer<'a> {
5555
// pub loop_data: LoopDataMap<'a>,
5656
pub folder: ConstantFolder<'a>,
5757
pub mangler: Mangler<'a>,
58-
pub pending_callbacks: FxHashSet<ExhaustiveCallback<'a>>,
59-
pub active_callback_triggers: Counter<ReadWriteTarget<'a>>,
58+
pub pending_deps: FxHashSet<ExhaustiveCallback<'a>>,
6059
pub diagnostics: BTreeSet<String>,
6160
pub fn_stats: Option<RefCell<FnStats>>,
6261
pub symbol_registry: SymbolRegistry<'a>,
@@ -90,8 +89,7 @@ impl<'a> Analyzer<'a> {
9089
// loop_data: Default::default(),
9190
folder: ConstantFolder::new(allocator),
9291
mangler,
93-
pending_callbacks: Default::default(),
94-
active_callback_triggers: Default::default(),
92+
pending_deps: Default::default(),
9593
diagnostics: Default::default(),
9694
fn_stats: config.enable_fn_stats.then(|| RefCell::new(FnStats::new())),
9795
}

crates/jsshaker/src/scope/variable_scope.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -201,20 +201,19 @@ impl<'a> Analyzer<'a> {
201201
!self.is_readonly_symbol(symbol)
202202
};
203203
drop(variable);
204-
205-
if self.active_callback_triggers.has(ReadWriteTarget::Variable(scope, symbol)) {
206-
value.map(|v| self.factory.computed_unknown(v))
204+
let tracker_dep = self.track_read(
205+
cf_scope,
206+
ReadWriteTarget::Variable(scope, symbol),
207+
Some(if may_change {
208+
TrackReadCacheable::Mutable(value)
209+
} else {
210+
TrackReadCacheable::Immutable
211+
}),
212+
);
213+
if let (Some(value), Some(tracker_dep)) = (value, tracker_dep) {
214+
Some(self.factory.computed(value, tracker_dep))
207215
} else {
208-
let tracker_dep = self.track_read(
209-
cf_scope,
210-
ReadWriteTarget::Variable(scope, symbol),
211-
Some(if may_change {
212-
TrackReadCacheable::Mutable(value)
213-
} else {
214-
TrackReadCacheable::Immutable
215-
}),
216-
);
217-
value.map(|v| self.factory.optional_computed(v, tracker_dep))
216+
value
218217
}
219218
};
220219

crates/jsshaker/src/utils/counter.rs

Lines changed: 0 additions & 48 deletions
This file was deleted.

crates/jsshaker/src/utils/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ mod annotation;
22
pub mod ast;
33
pub mod box_bump;
44
mod callee_info;
5-
pub mod counter;
65
mod data;
76
pub mod effect_builder;
87
mod escape_template_element_value;

0 commit comments

Comments
 (0)