Skip to content

Commit

Permalink
deps: patch V8 to 12.8.374.31
Browse files Browse the repository at this point in the history
Refs: v8/v8@12.8.374.22...12.8.374.31
PR-URL: #54682
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
targos authored and nodejs-github-bot committed Sep 11, 2024
1 parent 6bce6f6 commit 9087056
Show file tree
Hide file tree
Showing 86 changed files with 673 additions and 774 deletions.
2 changes: 1 addition & 1 deletion deps/v8/include/v8-version.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define V8_MAJOR_VERSION 12
#define V8_MINOR_VERSION 8
#define V8_BUILD_NUMBER 374
#define V8_PATCH_LEVEL 22
#define V8_PATCH_LEVEL 31

// Use 1 for candidates and 0 otherwise.
// (Boolean macro values are not supported by all preprocessors.)
Expand Down
7 changes: 0 additions & 7 deletions deps/v8/src/ast/ast-function-literal-id-reindexer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ void AstFunctionLiteralIdReindexer::VisitFunctionLiteral(FunctionLiteral* lit) {
lit->set_function_literal_id(lit->function_literal_id() + delta_);
}

void AstFunctionLiteralIdReindexer::VisitCall(Call* expr) {
AstTraversalVisitor::VisitCall(expr);
if (expr->is_possibly_eval()) {
expr->adjust_eval_scope_info_index(delta_);
}
}

void AstFunctionLiteralIdReindexer::VisitClassLiteral(ClassLiteral* expr) {
// Manually visit the class literal so that we can change the property walk.
// This should be kept in-sync with AstTraversalVisitor::VisitClassLiteral.
Expand Down
1 change: 0 additions & 1 deletion deps/v8/src/ast/ast-function-literal-id-reindexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class AstFunctionLiteralIdReindexer final
// AstTraversalVisitor implementation.
void VisitFunctionLiteral(FunctionLiteral* lit);
void VisitClassLiteral(ClassLiteral* lit);
void VisitCall(Call* lit);

private:
int delta_;
Expand Down
43 changes: 20 additions & 23 deletions deps/v8/src/ast/ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,7 @@ class CallBase : public Expression {
class Call final : public CallBase {
public:
bool is_possibly_eval() const {
return EvalScopeInfoIndexField::decode(bit_field_) > 0;
return IsPossiblyEvalField::decode(bit_field_);
}

bool is_tagged_template() const {
Expand All @@ -1742,15 +1742,6 @@ class Call final : public CallBase {
return IsOptionalChainLinkField::decode(bit_field_);
}

uint32_t eval_scope_info_index() const {
return EvalScopeInfoIndexField::decode(bit_field_);
}

void adjust_eval_scope_info_index(int delta) {
bit_field_ = EvalScopeInfoIndexField::update(
bit_field_, eval_scope_info_index() + delta);
}

enum CallType {
GLOBAL_CALL,
WITH_CALL,
Expand All @@ -1766,6 +1757,11 @@ class Call final : public CallBase {
OTHER_CALL,
};

enum PossiblyEval {
IS_POSSIBLY_EVAL,
NOT_EVAL,
};

// Helpers to determine how to handle the call.
CallType GetCallType() const;

Expand All @@ -1777,26 +1773,26 @@ class Call final : public CallBase {

Call(Zone* zone, Expression* expression,
const ScopedPtrList<Expression>& arguments, int pos, bool has_spread,
int eval_scope_info_index, bool optional_chain)
PossiblyEval possibly_eval, bool optional_chain)
: CallBase(zone, kCall, expression, arguments, pos, has_spread) {
bit_field_ |= IsTaggedTemplateField::encode(false) |
IsOptionalChainLinkField::encode(optional_chain) |
EvalScopeInfoIndexField::encode(eval_scope_info_index);
DCHECK_EQ(eval_scope_info_index > 0, is_possibly_eval());
bit_field_ |=
IsPossiblyEvalField::encode(possibly_eval == IS_POSSIBLY_EVAL) |
IsTaggedTemplateField::encode(false) |
IsOptionalChainLinkField::encode(optional_chain);
}

Call(Zone* zone, Expression* expression,
const ScopedPtrList<Expression>& arguments, int pos,
TaggedTemplateTag tag)
: CallBase(zone, kCall, expression, arguments, pos, false) {
bit_field_ |= IsTaggedTemplateField::encode(true) |
IsOptionalChainLinkField::encode(false) |
EvalScopeInfoIndexField::encode(0);
bit_field_ |= IsPossiblyEvalField::encode(false) |
IsTaggedTemplateField::encode(true) |
IsOptionalChainLinkField::encode(false);
}

using IsTaggedTemplateField = CallBase::NextBitField<bool, 1>;
using IsPossiblyEvalField = CallBase::NextBitField<bool, 1>;
using IsTaggedTemplateField = IsPossiblyEvalField::Next<bool, 1>;
using IsOptionalChainLinkField = IsTaggedTemplateField::Next<bool, 1>;
using EvalScopeInfoIndexField = IsOptionalChainLinkField::Next<uint32_t, 20>;
};

class CallNew final : public CallBase {
Expand Down Expand Up @@ -3188,11 +3184,12 @@ class AstNodeFactory final {

Call* NewCall(Expression* expression,
const ScopedPtrList<Expression>& arguments, int pos,
bool has_spread, int eval_scope_info_index = 0,
bool has_spread,
Call::PossiblyEval possibly_eval = Call::NOT_EVAL,
bool optional_chain = false) {
DCHECK_IMPLIES(eval_scope_info_index > 0, !optional_chain);
DCHECK_IMPLIES(possibly_eval == Call::IS_POSSIBLY_EVAL, !optional_chain);
return zone_->New<Call>(zone_, expression, arguments, pos, has_spread,
eval_scope_info_index, optional_chain);
possibly_eval, optional_chain);
}

SuperCallForwardArgs* NewSuperCallForwardArgs(SuperCallReference* expression,
Expand Down
117 changes: 13 additions & 104 deletions deps/v8/src/ast/scopes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2607,23 +2607,6 @@ void ModuleScope::AllocateModuleVariables() {
}
}

// Needs to be kept in sync with ScopeInfo::UniqueIdInScript.
int Scope::UniqueIdInScript() const {
// Script scopes start "before" the script to avoid clashing with a scope that
// starts on character 0.
if (is_script_scope() || scope_type() == EVAL_SCOPE ||
scope_type() == MODULE_SCOPE) {
return -1;
}
if (is_declaration_scope()) {
// Default constructors have the same start position as their parent class
// scope. Use the next char position to distinguish this scope.
return start_position() +
IsDefaultConstructor(AsDeclarationScope()->function_kind());
}
return start_position();
}

void Scope::AllocateVariablesRecursively() {
this->ForEach([](Scope* scope) -> Iteration {
DCHECK(!scope->already_resolved_);
Expand Down Expand Up @@ -2675,63 +2658,33 @@ void Scope::AllocateVariablesRecursively() {
}

template <typename IsolateT>
void Scope::AllocateScopeInfosRecursively(
IsolateT* isolate, MaybeHandle<ScopeInfo> outer_scope,
std::unordered_map<int, Handle<ScopeInfo>>& scope_infos_to_reuse) {
void Scope::AllocateScopeInfosRecursively(IsolateT* isolate,
MaybeHandle<ScopeInfo> outer_scope) {
DCHECK(scope_info_.is_null());
MaybeHandle<ScopeInfo> next_outer_scope = outer_scope;

auto it = scope_infos_to_reuse.find(UniqueIdInScript());
if (it != scope_infos_to_reuse.end()) {
scope_info_ = it->second;
CHECK(NeedsContext());
// The ScopeInfo chain mirrors the context chain, so we only link to the
// next outer scope that needs a context.
next_outer_scope = scope_info_;
DCHECK(!scope_info_.is_null());
DCHECK(!is_hidden_catch_scope());
CHECK_EQ(scope_info_->scope_type(), scope_type_);
CHECK_EQ(scope_info_->ContextLength(), num_heap_slots_);
#ifdef DEBUG
// Consume the scope info.
it->second = {};
#endif
} else if (NeedsScopeInfo()) {
#ifdef DEBUG
// Mark this ID as being used. Skip hidden scopes because they are
// synthetic, unreusable, but hard to make unique.
if (v8_flags.reuse_scope_infos && !is_hidden_catch_scope()) {
scope_infos_to_reuse[UniqueIdInScript()] = {};
}
#endif
if (NeedsScopeInfo()) {
scope_info_ = ScopeInfo::Create(isolate, zone(), this, outer_scope);
DCHECK_EQ(UniqueIdInScript(), scope_info_->UniqueIdInScript());
// The ScopeInfo chain mirrors the context chain, so we only link to the
// next outer scope that needs a context.
// The ScopeInfo chain should mirror the context chain, so we only link to
// the next outer scope that needs a context.
if (NeedsContext()) next_outer_scope = scope_info_;
}

// Allocate ScopeInfos for inner scopes.
for (Scope* scope = inner_scope_; scope != nullptr; scope = scope->sibling_) {
DCHECK_GT(scope->UniqueIdInScript(), UniqueIdInScript());
DCHECK_IMPLIES(scope->sibling_, scope->sibling_->UniqueIdInScript() !=
scope->UniqueIdInScript());
if (!scope->is_function_scope() ||
scope->AsDeclarationScope()->ShouldEagerCompile()) {
scope->AllocateScopeInfosRecursively(isolate, next_outer_scope,
scope_infos_to_reuse);
scope->AllocateScopeInfosRecursively(isolate, next_outer_scope);
}
}
}

template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) void Scope::
AllocateScopeInfosRecursively<Isolate>(
Isolate* isolate, MaybeHandle<ScopeInfo> outer_scope,
std::unordered_map<int, Handle<ScopeInfo>>& scope_infos_to_reuse);
AllocateScopeInfosRecursively<Isolate>(Isolate* isolate,
MaybeHandle<ScopeInfo> outer_scope);
template EXPORT_TEMPLATE_DEFINE(V8_EXPORT_PRIVATE) void Scope::
AllocateScopeInfosRecursively<LocalIsolate>(
LocalIsolate* isolate, MaybeHandle<ScopeInfo> outer_scope,
std::unordered_map<int, Handle<ScopeInfo>>& scope_infos_to_reuse);
LocalIsolate* isolate, MaybeHandle<ScopeInfo> outer_scope);

void DeclarationScope::RecalcPrivateNameContextChain() {
// The outermost scope in a class heritage expression is marked to skip the
Expand Down Expand Up @@ -2776,9 +2729,7 @@ void DeclarationScope::RecordNeedsPrivateNameContextChainRecalc() {

// static
template <typename IsolateT>
void DeclarationScope::AllocateScopeInfos(ParseInfo* info,
Handle<Script> script,
IsolateT* isolate) {
void DeclarationScope::AllocateScopeInfos(ParseInfo* info, IsolateT* isolate) {
DeclarationScope* scope = info->literal()->scope();

// No one else should have allocated a scope info for this scope yet.
Expand All @@ -2793,49 +2744,7 @@ void DeclarationScope::AllocateScopeInfos(ParseInfo* info,
if (scope->needs_private_name_context_chain_recalc()) {
scope->RecalcPrivateNameContextChain();
}

Tagged<WeakFixedArray> infos = script->infos();
std::unordered_map<int, Handle<ScopeInfo>> scope_infos_to_reuse;
if (v8_flags.reuse_scope_infos && infos->length() != 0) {
Tagged<SharedFunctionInfo> sfi = *info->literal()->shared_function_info();
Tagged<ScopeInfo> outer = sfi->HasOuterScopeInfo()
? sfi->GetOuterScopeInfo()
: Tagged<ScopeInfo>();
// Look at all the existing inner functions (they are numbered id+1 until
// max_id+1) to reattach their outer scope infos to corresponding scopes.
for (int i = info->literal()->function_literal_id() + 1;
i < info->max_info_id() + 1; ++i) {
Tagged<MaybeObject> maybe_info = infos->get(i);
if (maybe_info.IsWeak()) {
Tagged<Object> info = maybe_info.GetHeapObjectAssumeWeak();
Tagged<ScopeInfo> scope_info;
if (Is<SharedFunctionInfo>(info)) {
Tagged<SharedFunctionInfo> sfi = Cast<SharedFunctionInfo>(info);
// Reuse outer scope infos. Don't look at sfi->scope_info() because
// that might be empty if the sfi isn't compiled yet.
if (!sfi->HasOuterScopeInfo()) continue;
scope_info = sfi->GetOuterScopeInfo();
} else {
scope_info = Cast<ScopeInfo>(info);
}
while (true) {
if (scope_info == outer) break;
int id = scope_info->UniqueIdInScript();
auto it = scope_infos_to_reuse.find(id);
if (it != scope_infos_to_reuse.end()) {
CHECK_EQ(*it->second, scope_info);
break;
}
scope_infos_to_reuse[id] = handle(scope_info, isolate);
if (!scope_info->HasOuterScopeInfo()) break;
scope_info = scope_info->OuterScopeInfo();
}
}
}
}

scope->AllocateScopeInfosRecursively(isolate, outer_scope,
scope_infos_to_reuse);
scope->AllocateScopeInfosRecursively(isolate, outer_scope);

// The debugger expects all shared function infos to contain a scope info.
// Since the top-most scope will end up in a shared function info, make sure
Expand All @@ -2854,9 +2763,9 @@ void DeclarationScope::AllocateScopeInfos(ParseInfo* info,
}

template V8_EXPORT_PRIVATE void DeclarationScope::AllocateScopeInfos(
ParseInfo* info, Handle<Script> script, Isolate* isolate);
ParseInfo* info, Isolate* isolate);
template V8_EXPORT_PRIVATE void DeclarationScope::AllocateScopeInfos(
ParseInfo* info, Handle<Script> script, LocalIsolate* isolate);
ParseInfo* info, LocalIsolate* isolate);

int Scope::ContextLocalCount() const {
if (num_heap_slots() == 0) return 0;
Expand Down
22 changes: 9 additions & 13 deletions deps/v8/src/ast/scopes.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
}
#endif

// An ID that uniquely identifies this scope within the script. Inner scopes
// have a higher ID than their outer scopes. ScopeInfo created from a scope
// has the same ID as the scope.
int UniqueIdInScript() const;

DeclarationScope* AsDeclarationScope();
const DeclarationScope* AsDeclarationScope() const;
ModuleScope* AsModuleScope();
Expand Down Expand Up @@ -339,10 +334,6 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
bool is_hidden() const { return is_hidden_; }
void set_is_hidden() { is_hidden_ = true; }

bool is_hidden_catch_scope() const {
return is_hidden() && scope_type() == CATCH_SCOPE;
}

void ForceContextAllocationForParameters() {
DCHECK(!already_resolved_);
force_context_allocation_for_parameters_ = true;
Expand Down Expand Up @@ -728,9 +719,11 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {
void AllocateVariablesRecursively();

template <typename IsolateT>
void AllocateScopeInfosRecursively(
IsolateT* isolate, MaybeHandle<ScopeInfo> outer_scope,
std::unordered_map<int, Handle<ScopeInfo>>& scope_infos_to_reuse);
void AllocateScopeInfosRecursively(IsolateT* isolate,
MaybeHandle<ScopeInfo> outer_scope);

void AllocateDebuggerScopeInfos(Isolate* isolate,
MaybeHandle<ScopeInfo> outer_scope);

// Construct a scope based on the scope info.
Scope(Zone* zone, ScopeType type, AstValueFactory* ast_value_factory,
Expand Down Expand Up @@ -830,6 +823,10 @@ class V8_EXPORT_PRIVATE Scope : public NON_EXPORTED_BASE(ZoneObject) {

bool must_use_preparsed_scope_data_ : 1;

// True if this is a script scope that originated from
// DebugEvaluate::GlobalREPL().
bool is_repl_mode_scope_ : 1;

// True if this is a deserialized scope which caches its lookups on another
// Scope's variable map. This will be true for every scope above the first
// non-eval declaration scope above the compilation entry point, e.g. for
Expand Down Expand Up @@ -1164,7 +1161,6 @@ class V8_EXPORT_PRIVATE DeclarationScope : public Scope {
// Does nothing if ScopeInfo is already allocated.
template <typename IsolateT>
V8_EXPORT_PRIVATE static void AllocateScopeInfos(ParseInfo* info,
Handle<Script> script,
IsolateT* isolate);

// Determine if we can use lazy compilation for this scope.
Expand Down
9 changes: 5 additions & 4 deletions deps/v8/src/builtins/builtins-function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,11 @@ MaybeHandle<Object> CreateDynamicFunction(Isolate* isolate,
// come from here.
Handle<JSFunction> function;
{
ASSIGN_RETURN_ON_EXCEPTION(isolate, function,
Compiler::GetFunctionFromString(
handle(target->native_context(), isolate),
source, parameters_end_pos, is_code_like));
ASSIGN_RETURN_ON_EXCEPTION(
isolate, function,
Compiler::GetFunctionFromString(
handle(target->native_context(), isolate), source,
ONLY_SINGLE_FUNCTION_LITERAL, parameters_end_pos, is_code_like));
Handle<Object> result;
ASSIGN_RETURN_ON_EXCEPTION(
isolate, result,
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/codegen/background-merge-task.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class V8_EXPORT_PRIVATE BackgroundMergeTask {
// SharedFunctionInfo in the cached script. The main thread must:
// 1. Check whether the cached script gained corresponding SharedFunctionInfos
// for any of these, and if so, redo the merge.
// 2. Update the cached script's infos list to refer to these.
// 2. Update the cached script's shared_function_infos list to refer to these.
std::vector<Handle<SharedFunctionInfo>> used_new_sfis_;

// SharedFunctionInfos from the cached script which were not compiled, with
Expand Down
Loading

0 comments on commit 9087056

Please sign in to comment.