@@ -2607,23 +2607,6 @@ void ModuleScope::AllocateModuleVariables() {
2607
2607
}
2608
2608
}
2609
2609
2610
- // Needs to be kept in sync with ScopeInfo::UniqueIdInScript.
2611
- int Scope::UniqueIdInScript () const {
2612
- // Script scopes start "before" the script to avoid clashing with a scope that
2613
- // starts on character 0.
2614
- if (is_script_scope () || scope_type () == EVAL_SCOPE ||
2615
- scope_type () == MODULE_SCOPE) {
2616
- return -1 ;
2617
- }
2618
- if (is_declaration_scope ()) {
2619
- // Default constructors have the same start position as their parent class
2620
- // scope. Use the next char position to distinguish this scope.
2621
- return start_position () +
2622
- IsDefaultConstructor (AsDeclarationScope ()->function_kind ());
2623
- }
2624
- return start_position ();
2625
- }
2626
-
2627
2610
void Scope::AllocateVariablesRecursively () {
2628
2611
this ->ForEach ([](Scope* scope) -> Iteration {
2629
2612
DCHECK (!scope->already_resolved_ );
@@ -2675,63 +2658,33 @@ void Scope::AllocateVariablesRecursively() {
2675
2658
}
2676
2659
2677
2660
template <typename IsolateT>
2678
- void Scope::AllocateScopeInfosRecursively (
2679
- IsolateT* isolate, MaybeHandle<ScopeInfo> outer_scope,
2680
- std::unordered_map<int , Handle <ScopeInfo>>& scope_infos_to_reuse) {
2661
+ void Scope::AllocateScopeInfosRecursively (IsolateT* isolate,
2662
+ MaybeHandle<ScopeInfo> outer_scope) {
2681
2663
DCHECK (scope_info_.is_null ());
2682
2664
MaybeHandle<ScopeInfo> next_outer_scope = outer_scope;
2683
2665
2684
- auto it = scope_infos_to_reuse.find (UniqueIdInScript ());
2685
- if (it != scope_infos_to_reuse.end ()) {
2686
- scope_info_ = it->second ;
2687
- CHECK (NeedsContext ());
2688
- // The ScopeInfo chain mirrors the context chain, so we only link to the
2689
- // next outer scope that needs a context.
2690
- next_outer_scope = scope_info_;
2691
- DCHECK (!scope_info_.is_null ());
2692
- DCHECK (!is_hidden_catch_scope ());
2693
- CHECK_EQ (scope_info_->scope_type (), scope_type_);
2694
- CHECK_EQ (scope_info_->ContextLength (), num_heap_slots_);
2695
- #ifdef DEBUG
2696
- // Consume the scope info.
2697
- it->second = {};
2698
- #endif
2699
- } else if (NeedsScopeInfo ()) {
2700
- #ifdef DEBUG
2701
- // Mark this ID as being used. Skip hidden scopes because they are
2702
- // synthetic, unreusable, but hard to make unique.
2703
- if (v8_flags.reuse_scope_infos && !is_hidden_catch_scope ()) {
2704
- scope_infos_to_reuse[UniqueIdInScript ()] = {};
2705
- }
2706
- #endif
2666
+ if (NeedsScopeInfo ()) {
2707
2667
scope_info_ = ScopeInfo::Create (isolate, zone (), this , outer_scope);
2708
- DCHECK_EQ (UniqueIdInScript (), scope_info_->UniqueIdInScript ());
2709
- // The ScopeInfo chain mirrors the context chain, so we only link to the
2710
- // next outer scope that needs a context.
2668
+ // The ScopeInfo chain should mirror the context chain, so we only link to
2669
+ // the next outer scope that needs a context.
2711
2670
if (NeedsContext ()) next_outer_scope = scope_info_;
2712
2671
}
2713
2672
2714
2673
// Allocate ScopeInfos for inner scopes.
2715
2674
for (Scope* scope = inner_scope_; scope != nullptr ; scope = scope->sibling_ ) {
2716
- DCHECK_GT (scope->UniqueIdInScript (), UniqueIdInScript ());
2717
- DCHECK_IMPLIES (scope->sibling_ , scope->sibling_ ->UniqueIdInScript () !=
2718
- scope->UniqueIdInScript ());
2719
2675
if (!scope->is_function_scope () ||
2720
2676
scope->AsDeclarationScope ()->ShouldEagerCompile ()) {
2721
- scope->AllocateScopeInfosRecursively (isolate, next_outer_scope,
2722
- scope_infos_to_reuse);
2677
+ scope->AllocateScopeInfosRecursively (isolate, next_outer_scope);
2723
2678
}
2724
2679
}
2725
2680
}
2726
2681
2727
2682
template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) void Scope::
2728
- AllocateScopeInfosRecursively<Isolate>(
2729
- Isolate* isolate, MaybeHandle<ScopeInfo> outer_scope,
2730
- std::unordered_map<int , Handle <ScopeInfo>>& scope_infos_to_reuse);
2683
+ AllocateScopeInfosRecursively<Isolate>(Isolate* isolate,
2684
+ MaybeHandle<ScopeInfo> outer_scope);
2731
2685
template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) void Scope::
2732
2686
AllocateScopeInfosRecursively<LocalIsolate>(
2733
- LocalIsolate* isolate, MaybeHandle<ScopeInfo> outer_scope,
2734
- std::unordered_map<int , Handle <ScopeInfo>>& scope_infos_to_reuse);
2687
+ LocalIsolate* isolate, MaybeHandle<ScopeInfo> outer_scope);
2735
2688
2736
2689
void DeclarationScope::RecalcPrivateNameContextChain () {
2737
2690
// The outermost scope in a class heritage expression is marked to skip the
@@ -2776,9 +2729,7 @@ void DeclarationScope::RecordNeedsPrivateNameContextChainRecalc() {
2776
2729
2777
2730
// static
2778
2731
template <typename IsolateT>
2779
- void DeclarationScope::AllocateScopeInfos (ParseInfo* info,
2780
- Handle <Script> script,
2781
- IsolateT* isolate) {
2732
+ void DeclarationScope::AllocateScopeInfos (ParseInfo* info, IsolateT* isolate) {
2782
2733
DeclarationScope* scope = info->literal ()->scope ();
2783
2734
2784
2735
// No one else should have allocated a scope info for this scope yet.
@@ -2793,49 +2744,7 @@ void DeclarationScope::AllocateScopeInfos(ParseInfo* info,
2793
2744
if (scope->needs_private_name_context_chain_recalc ()) {
2794
2745
scope->RecalcPrivateNameContextChain ();
2795
2746
}
2796
-
2797
- Tagged<WeakFixedArray> infos = script->infos ();
2798
- std::unordered_map<int , Handle <ScopeInfo>> scope_infos_to_reuse;
2799
- if (v8_flags.reuse_scope_infos && infos->length () != 0 ) {
2800
- Tagged<SharedFunctionInfo> sfi = *info->literal ()->shared_function_info ();
2801
- Tagged<ScopeInfo> outer = sfi->HasOuterScopeInfo ()
2802
- ? sfi->GetOuterScopeInfo ()
2803
- : Tagged<ScopeInfo>();
2804
- // Look at all the existing inner functions (they are numbered id+1 until
2805
- // max_id+1) to reattach their outer scope infos to corresponding scopes.
2806
- for (int i = info->literal ()->function_literal_id () + 1 ;
2807
- i < info->max_info_id () + 1 ; ++i) {
2808
- Tagged<MaybeObject> maybe_info = infos->get (i);
2809
- if (maybe_info.IsWeak ()) {
2810
- Tagged<Object> info = maybe_info.GetHeapObjectAssumeWeak ();
2811
- Tagged<ScopeInfo> scope_info;
2812
- if (Is<SharedFunctionInfo>(info)) {
2813
- Tagged<SharedFunctionInfo> sfi = Cast<SharedFunctionInfo>(info);
2814
- // Reuse outer scope infos. Don't look at sfi->scope_info() because
2815
- // that might be empty if the sfi isn't compiled yet.
2816
- if (!sfi->HasOuterScopeInfo ()) continue ;
2817
- scope_info = sfi->GetOuterScopeInfo ();
2818
- } else {
2819
- scope_info = Cast<ScopeInfo>(info);
2820
- }
2821
- while (true ) {
2822
- if (scope_info == outer) break ;
2823
- int id = scope_info->UniqueIdInScript ();
2824
- auto it = scope_infos_to_reuse.find (id);
2825
- if (it != scope_infos_to_reuse.end ()) {
2826
- CHECK_EQ (*it->second , scope_info);
2827
- break ;
2828
- }
2829
- scope_infos_to_reuse[id] = handle (scope_info, isolate);
2830
- if (!scope_info->HasOuterScopeInfo ()) break ;
2831
- scope_info = scope_info->OuterScopeInfo ();
2832
- }
2833
- }
2834
- }
2835
- }
2836
-
2837
- scope->AllocateScopeInfosRecursively (isolate, outer_scope,
2838
- scope_infos_to_reuse);
2747
+ scope->AllocateScopeInfosRecursively (isolate, outer_scope);
2839
2748
2840
2749
// The debugger expects all shared function infos to contain a scope info.
2841
2750
// Since the top-most scope will end up in a shared function info, make sure
@@ -2854,9 +2763,9 @@ void DeclarationScope::AllocateScopeInfos(ParseInfo* info,
2854
2763
}
2855
2764
2856
2765
template V8_EXPORT_PRIVATE void DeclarationScope::AllocateScopeInfos (
2857
- ParseInfo* info, Handle <Script> script, Isolate* isolate);
2766
+ ParseInfo* info, Isolate* isolate);
2858
2767
template V8_EXPORT_PRIVATE void DeclarationScope::AllocateScopeInfos (
2859
- ParseInfo* info, Handle <Script> script, LocalIsolate* isolate);
2768
+ ParseInfo* info, LocalIsolate* isolate);
2860
2769
2861
2770
int Scope::ContextLocalCount () const {
2862
2771
if (num_heap_slots () == 0 ) return 0 ;
0 commit comments