Skip to content

Commit dbeb60d

Browse files
committedMar 18, 2025·
Revert "chore: cleanup object_id"
This reverts commit c5aec4b.
1 parent c5aec4b commit dbeb60d

File tree

4 files changed

+23
-10
lines changed

4 files changed

+23
-10
lines changed
 

‎crates/tree_shaker/src/entity/array.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{
2-
consumed_object, object::alloc_object_id, Entity, EntityTrait, EnumeratedProperties,
3-
IteratedElements, LiteralEntity, ObjectId, TypeofResult,
2+
consumed_object, Entity, EntityTrait, EnumeratedProperties, IteratedElements, LiteralEntity,
3+
ObjectId, TypeofResult,
44
};
55
use crate::{
66
analyzer::Analyzer,
@@ -382,6 +382,6 @@ impl<'a> ArrayEntity<'a> {
382382

383383
impl<'a> Analyzer<'a> {
384384
pub fn new_empty_array(&mut self) -> &'a mut ArrayEntity<'a> {
385-
self.factory.array(self.scoping.cf.current_id(), alloc_object_id())
385+
self.factory.array(self.scoping.cf.current_id(), self.scoping.alloc_object_id())
386386
}
387387
}

‎crates/tree_shaker/src/entity/object/mod.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,6 @@ define_index_type! {
4949
pub struct ObjectId = u32;
5050
}
5151

52-
pub fn alloc_object_id<'a>() -> ObjectId {
53-
static COUNTER: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(128);
54-
ObjectId::from(COUNTER.fetch_add(1, std::sync::atomic::Ordering::Relaxed))
55-
}
56-
5752
#[derive(Debug)]
5853
pub struct ObjectEntity<'a> {
5954
/// A built-in object is usually non-consumable
@@ -314,7 +309,7 @@ impl<'a> Analyzer<'a> {
314309
consumed_as_prototype: Cell::new(false),
315310
// deps: Default::default(),
316311
cf_scope: self.scoping.cf.current_id(),
317-
object_id: alloc_object_id(),
312+
object_id: self.scoping.alloc_object_id(),
318313
string_keyed: RefCell::new(FxHashMap::default()),
319314
unknown_keyed: RefCell::new(ObjectProperty::default()),
320315
rest: RefCell::new(None),

‎crates/tree_shaker/src/scope/mod.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use crate::{
1212
analyzer::Analyzer,
1313
consumable::{Consumable, ConsumableTrait, ConsumableVec},
1414
dep::DepId,
15-
entity::{Entity, EntityFactory},
15+
entity::{Entity, EntityFactory, ObjectId},
1616
module::ModuleId,
1717
utils::{CalleeInfo, CalleeNode},
1818
};
@@ -29,12 +29,16 @@ pub struct Scoping<'a> {
2929
pub variable: ScopeTree<VariableScopeId, VariableScope<'a>>,
3030
pub cf: ScopeTree<CfScopeId, CfScope<'a>>,
3131
pub pure: usize,
32+
33+
pub object_scope_id: VariableScopeId,
34+
pub object_symbol_counter: usize,
3235
}
3336

3437
impl<'a> Scoping<'a> {
3538
pub fn new(factory: &EntityFactory<'a>) -> Self {
3639
let mut variable = ScopeTree::new();
3740
variable.push(VariableScope::new_with_this(factory.unknown()));
41+
let object_scope_id = variable.add_special(VariableScope::new());
3842
let mut cf = ScopeTree::new();
3943
cf.push(CfScope::new(CfScopeKind::Root, vec![], Some(false)));
4044
Scoping {
@@ -56,6 +60,9 @@ impl<'a> Scoping<'a> {
5660
variable,
5761
cf,
5862
pure: 0,
63+
64+
object_scope_id,
65+
object_symbol_counter: 128,
5966
}
6067
}
6168

@@ -74,6 +81,11 @@ impl<'a> Scoping<'a> {
7481
#[cfg(feature = "flame")]
7582
self.call.pop().unwrap().scope_guard.end();
7683
}
84+
85+
pub fn alloc_object_id(&mut self) -> ObjectId {
86+
self.object_symbol_counter += 1;
87+
ObjectId::from_usize(self.object_symbol_counter)
88+
}
7789
}
7890

7991
impl<'a> Analyzer<'a> {

‎crates/tree_shaker/src/scope/scope_tree.rs

+6
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ impl<I: Idx, T> ScopeTree<I, T> {
7676
self.nodes.get(id).unwrap().parent
7777
}
7878

79+
pub fn add_special(&mut self, data: T) -> I {
80+
let id = I::from_usize(self.nodes.len());
81+
self.nodes.push(NodeInfo { data, depth: 0, parent: None });
82+
id
83+
}
84+
7985
pub fn push(&mut self, data: T) -> I {
8086
let id = I::from_usize(self.nodes.len());
8187
self.nodes.push(NodeInfo { data, depth: self.stack.len(), parent: self.stack.last().copied() });

1 commit comments

Comments
 (1)

github-actions[bot] commented on Mar 18, 2025

@github-actions[bot]

Test262 Result

  • Failed: 0
  • Total: 43706
  • Passed: 37344
  • Ignored: 3276
  • Treeshaked: 28547, Skipped: 15159
  • Treeshaked sized/Minified size = 81.44%
Please sign in to comment.