Skip to content

Commit ea2a08b

Browse files
committed
chore: update
1 parent 4d22e95 commit ea2a08b

File tree

3 files changed

+14
-23
lines changed

3 files changed

+14
-23
lines changed

crates/tree_shaker/src/consumable/mod.rs

+9-18
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod impls;
33
mod lazy;
44
mod once;
55

6-
use crate::analyzer::Analyzer;
6+
use crate::{analyzer::Analyzer, entity::Entity};
77
pub use collector::*;
88
pub use lazy::*;
99
pub use once::*;
@@ -14,39 +14,30 @@ pub trait ConsumableTrait<'a>: Debug {
1414
fn consume(&self, analyzer: &mut Analyzer<'a>);
1515
}
1616

17-
pub trait IntoConsumable<'a> {
18-
fn into_consumable(self, allocator: &'a Allocator) -> Consumable<'a>;
19-
}
20-
21-
pub trait ConsumeTrait<'a>: Debug + IntoConsumable<'a> {
17+
pub trait ConsumeTrait<'a>: Debug {
2218
fn consume(&self, analyzer: &mut Analyzer<'a>);
23-
}
24-
25-
impl<'a, T: ConsumableTrait<'a> + 'a> IntoConsumable<'a> for T {
26-
fn into_consumable(self, allocator: &'a Allocator) -> Consumable<'a> {
27-
Consumable(allocator.alloc(self))
28-
}
19+
fn uniform(self, allocator: &'a Allocator) -> Consumable<'a>;
2920
}
3021

3122
impl<'a, T: ConsumableTrait<'a> + 'a> ConsumeTrait<'a> for T {
3223
fn consume(&self, analyzer: &mut Analyzer<'a>) {
3324
self.consume(analyzer);
3425
}
26+
fn uniform(self, allocator: &'a Allocator) -> Consumable<'a> {
27+
Consumable(allocator.alloc(self))
28+
}
3529
}
3630

3731
#[derive(Debug, Clone, Copy)]
3832
pub struct Consumable<'a>(pub &'a (dyn ConsumableTrait<'a> + 'a));
3933

40-
impl<'a> IntoConsumable<'a> for Consumable<'a> {
41-
fn into_consumable(self, _allocator: &'a Allocator) -> Consumable<'a> {
42-
self
43-
}
44-
}
45-
4634
impl<'a> ConsumeTrait<'a> for Consumable<'a> {
4735
fn consume(&self, analyzer: &mut Analyzer<'a>) {
4836
self.0.consume(analyzer);
4937
}
38+
fn uniform(self, _: &'a Allocator) -> Consumable<'a> {
39+
self
40+
}
5041
}
5142

5243
pub type ConsumableVec<'a> = Vec<Consumable<'a>>;

crates/tree_shaker/src/entity/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ impl<'a> Entity<'a> {
223223
if let Some(d) = self.dep {
224224
analyzer.factory.consumable((d, dep))
225225
} else {
226-
dep.into_consumable(analyzer.factory.allocator)
226+
dep.uniform(analyzer.factory.allocator)
227227
}
228228
}
229229

@@ -440,7 +440,7 @@ impl<'a> EntityFactory<'a> {
440440
dep: if let Some(d) = entity.dep {
441441
Some(self.consumable((d, dep)))
442442
} else {
443-
Some(dep.into_consumable(self.allocator))
443+
Some(dep.uniform(self.allocator))
444444
},
445445
}
446446
}

crates/tree_shaker/src/scope/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub mod variable_scope;
1010

1111
use crate::{
1212
analyzer::Analyzer,
13-
consumable::{Consumable, ConsumableVec, IntoConsumable},
13+
consumable::{Consumable, ConsumableVec, ConsumeTrait},
1414
dep::DepId,
1515
entity::{Entity, EntityFactory, ObjectId},
1616
module::ModuleId,
@@ -208,10 +208,10 @@ impl<'a> Analyzer<'a> {
208208
self.push_cf_scope(CfScopeKind::Indeterminate, None);
209209
}
210210

211-
pub fn push_dependent_cf_scope(&mut self, dep: impl IntoConsumable<'a> + 'a) {
211+
pub fn push_dependent_cf_scope(&mut self, dep: impl ConsumeTrait<'a> + 'a) {
212212
self.push_cf_scope_with_deps(
213213
CfScopeKind::Dependent,
214-
vec![dep.into_consumable(self.allocator)],
214+
vec![dep.uniform(self.allocator)],
215215
Some(false),
216216
);
217217
}

0 commit comments

Comments
 (0)