@@ -2607,23 +2607,6 @@ void ModuleScope::AllocateModuleVariables() {
26072607 }
26082608}
26092609
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-
26272610void Scope::AllocateVariablesRecursively () {
26282611 this ->ForEach ([](Scope* scope) -> Iteration {
26292612 DCHECK (!scope->already_resolved_ );
@@ -2675,63 +2658,33 @@ void Scope::AllocateVariablesRecursively() {
26752658}
26762659
26772660template <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) {
26812663 DCHECK (scope_info_.is_null ());
26822664 MaybeHandle<ScopeInfo> next_outer_scope = outer_scope;
26832665
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 ()) {
27072667 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.
27112670 if (NeedsContext ()) next_outer_scope = scope_info_;
27122671 }
27132672
27142673 // Allocate ScopeInfos for inner scopes.
27152674 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 ());
27192675 if (!scope->is_function_scope () ||
27202676 scope->AsDeclarationScope ()->ShouldEagerCompile ()) {
2721- scope->AllocateScopeInfosRecursively (isolate, next_outer_scope,
2722- scope_infos_to_reuse);
2677+ scope->AllocateScopeInfosRecursively (isolate, next_outer_scope);
27232678 }
27242679 }
27252680}
27262681
27272682template 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);
27312685template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) void Scope::
27322686 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);
27352688
27362689void DeclarationScope::RecalcPrivateNameContextChain () {
27372690 // The outermost scope in a class heritage expression is marked to skip the
@@ -2776,9 +2729,7 @@ void DeclarationScope::RecordNeedsPrivateNameContextChainRecalc() {
27762729
27772730// static
27782731template <typename IsolateT>
2779- void DeclarationScope::AllocateScopeInfos (ParseInfo* info,
2780- Handle<Script> script,
2781- IsolateT* isolate) {
2732+ void DeclarationScope::AllocateScopeInfos (ParseInfo* info, IsolateT* isolate) {
27822733 DeclarationScope* scope = info->literal ()->scope ();
27832734
27842735 // No one else should have allocated a scope info for this scope yet.
@@ -2793,49 +2744,7 @@ void DeclarationScope::AllocateScopeInfos(ParseInfo* info,
27932744 if (scope->needs_private_name_context_chain_recalc ()) {
27942745 scope->RecalcPrivateNameContextChain ();
27952746 }
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);
28392748
28402749 // The debugger expects all shared function infos to contain a scope info.
28412750 // Since the top-most scope will end up in a shared function info, make sure
@@ -2854,9 +2763,9 @@ void DeclarationScope::AllocateScopeInfos(ParseInfo* info,
28542763}
28552764
28562765template V8_EXPORT_PRIVATE void DeclarationScope::AllocateScopeInfos (
2857- ParseInfo* info, Handle<Script> script, Isolate* isolate);
2766+ ParseInfo* info, Isolate* isolate);
28582767template V8_EXPORT_PRIVATE void DeclarationScope::AllocateScopeInfos (
2859- ParseInfo* info, Handle<Script> script, LocalIsolate* isolate);
2768+ ParseInfo* info, LocalIsolate* isolate);
28602769
28612770int Scope::ContextLocalCount () const {
28622771 if (num_heap_slots () == 0 ) return 0 ;
0 commit comments