Skip to content

Commit

Permalink
deps: patch V8 to 12.8.374.22
Browse files Browse the repository at this point in the history
Refs: v8/v8@12.8.374.13...12.8.374.22

PR-URL: #54435
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
  • Loading branch information
nodejs-github-bot authored and targos committed Sep 1, 2024
1 parent 71b36b3 commit 0c771c3
Show file tree
Hide file tree
Showing 16 changed files with 71 additions and 211 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 13
#define V8_PATCH_LEVEL 22

// Use 1 for candidates and 0 otherwise.
// (Boolean macro values are not supported by all preprocessors.)
Expand Down
22 changes: 8 additions & 14 deletions deps/v8/src/ast/scopes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2607,8 +2607,7 @@ void ModuleScope::AllocateModuleVariables() {
}
}

// Needs to be kept in sync with ScopeInfo::UniqueIdInScript and
// SharedFunctionInfo::UniqueIdInScript.
// 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.
Expand Down Expand Up @@ -2801,25 +2800,20 @@ void DeclarationScope::AllocateScopeInfos(ParseInfo* info,
Tagged<ScopeInfo> outer = sfi->HasOuterScopeInfo()
? sfi->GetOuterScopeInfo()
: Tagged<ScopeInfo>();
// Look at all inner functions whether they have scope infos that we should
// reuse. Also look at the compiled function itself, and reuse its function
// scope info if it exists.
for (int i = info->literal()->function_literal_id();
// 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);
if (!sfi->scope_info()->IsEmpty() &&
sfi->scope_info()->HasContext()) {
scope_info = sfi->scope_info();
} else if (sfi->HasOuterScopeInfo()) {
scope_info = sfi->GetOuterScopeInfo();
} else {
continue;
}
// 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);
}
Expand Down
150 changes: 16 additions & 134 deletions deps/v8/src/codegen/compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2022,39 +2022,18 @@ class ConstantPoolPointerForwarder {
}

void RecordScopeInfos(Tagged<MaybeObject> maybe_old_info) {
RecordScopeInfos(maybe_old_info.GetHeapObjectAssumeWeak());
}

// Record all scope infos relevant for a shared function info or scope info
// (recorded for eval).
void RecordScopeInfos(Tagged<HeapObject> info) {
Tagged<ScopeInfo> scope_info;
Tagged<HeapObject> info = maybe_old_info.GetHeapObjectAssumeWeak();
if (Is<SharedFunctionInfo>(info)) {
Tagged<SharedFunctionInfo> old_sfi = Cast<SharedFunctionInfo>(info);
// Also record context-having own scope infos for SFIs.
if (!old_sfi->scope_info()->IsEmpty() &&
old_sfi->scope_info()->HasContext()) {
scope_info = old_sfi->scope_info();
} else if (old_sfi->HasOuterScopeInfo()) {
scope_info = old_sfi->GetOuterScopeInfo();
} else {
return;
}
if (!old_sfi->HasOuterScopeInfo()) return;
scope_info = old_sfi->GetOuterScopeInfo();
} else {
scope_info = Cast<ScopeInfo>(info);
}

while (true) {
auto it = scope_infos_to_update_.find(scope_info->UniqueIdInScript());
if (it != scope_infos_to_update_.end()) {
// Once we find an already recorded scope info, it need to match the one
// on the chain.
if (V8_UNLIKELY(*it->second != scope_info)) {
info->Print();
(*it->second)->Print();
scope_info->Print();
UNREACHABLE();
}
if (scope_infos_to_update_.find(scope_info->UniqueIdInScript()) !=
scope_infos_to_update_.end()) {
return;
}
scope_infos_to_update_[scope_info->UniqueIdInScript()] =
Expand Down Expand Up @@ -2083,51 +2062,17 @@ class ConstantPoolPointerForwarder {
!scope_infos_to_update_.empty();
}

// Find an own scope info for the sfi based on the UniqueIdInScript that the
// own scope info would have. This works even if the SFI doesn't yet have a
// scope info attached by computing UniqueIdInScript from the SFI position.
//
// This should only directly be used for SFIs that already existed on the
// script. Their outer scope info will already be correct.
bool InstallOwnScopeInfo(Tagged<SharedFunctionInfo> sfi) {
auto it = scope_infos_to_update_.find(sfi->UniqueIdInScript());
if (it == scope_infos_to_update_.end()) return false;
sfi->SetScopeInfo(*it->second);
return true;
}

// Either replace the own scope info of the sfi, or the first outer scope info
// that was recorded.
//
// This has to be used for all newly created SFIs since their outer scope info
// also may need to be reattached.
void UpdateScopeInfo(Tagged<SharedFunctionInfo> sfi) {
// This should not be called on already existing SFIs. Their scope infos are
// already correct.
DCHECK_NE(MakeWeak(sfi),
old_script_->infos()->get(sfi->function_literal_id()));
if (InstallOwnScopeInfo(sfi)) return;
void UpdateOuterScopeInfo(Tagged<SharedFunctionInfo> sfi) {
if (!sfi->HasOuterScopeInfo()) return;

Tagged<ScopeInfo> parent =
sfi->scope_info()->IsEmpty() ? Tagged<ScopeInfo>() : sfi->scope_info();
Tagged<ScopeInfo> outer_info = sfi->GetOuterScopeInfo();

auto it = scope_infos_to_update_.find(outer_info->UniqueIdInScript());
while (it == scope_infos_to_update_.end()) {
if (!outer_info->HasOuterScopeInfo()) return;
parent = outer_info;
outer_info = outer_info->OuterScopeInfo();
it = scope_infos_to_update_.find(outer_info->UniqueIdInScript());
}
if (it == scope_infos_to_update_.end()) return;
if (outer_info == *it->second) return;

VerifyScopeInfo(outer_info, *it->second);

if (parent.is_null()) {
sfi->set_raw_outer_scope_info_or_feedback_metadata(*it->second);
if (sfi->is_compiled()) {
sfi->scope_info()->set_outer_scope_info(*it->second);
} else {
parent->set_outer_scope_info(*it->second);
sfi->set_raw_outer_scope_info_or_feedback_metadata(*it->second);
}
}

Expand Down Expand Up @@ -2309,16 +2254,6 @@ void BackgroundMergeTask::BeginMergeInBackground(
new_compiled_data_for_cached_sfis_.push_back(
{local_heap->NewPersistentHandle(old_sfi),
local_heap->NewPersistentHandle(new_sfi)});
// Pick up existing scope infos from the old sfi. The new sfi will be
// copied over the old sfi later. This will ensure that we'll keep
// using the old sfis. This will also allow us check later whether new
// scope infos have appeared that need to be reused.
if (!old_sfi->scope_info()->IsEmpty()) {
new_sfi->SetScopeInfo(old_sfi->scope_info());
} else if (old_sfi->HasOuterScopeInfo()) {
new_sfi->scope_info()->set_outer_scope_info(
old_sfi->GetOuterScopeInfo());
}
forwarder.AddBytecodeArray(new_sfi->GetBytecodeArray(isolate));
}
} else {
Expand All @@ -2343,23 +2278,13 @@ void BackgroundMergeTask::BeginMergeInBackground(

if (forwarder.HasAnythingToForward()) {
for (DirectHandle<SharedFunctionInfo> new_sfi : used_new_sfis_) {
forwarder.UpdateScopeInfo(*new_sfi);
}
for (const auto& new_compiled_data : new_compiled_data_for_cached_sfis_) {
// It's possible that new_compiled_data.cached_sfi had
// scope_info()->IsEmpty() while an inner function has scope info if the
// cached_sfi was recreated when an outer function was recompiled. If so,
// new_compiled_data.new_sfi does not have a reused scope info yet, and
// we'll have found it when we visited the inner function. Try to pick it
// up here.
forwarder.InstallOwnScopeInfo(*new_compiled_data.new_sfi);
forwarder.UpdateOuterScopeInfo(*new_sfi);
}
forwarder.IterateAndForwardPointers();
}
persistent_handles_ = local_heap->DetachPersistentHandles();
state_ = kPendingForegroundWork;
}

Handle<SharedFunctionInfo> BackgroundMergeTask::CompleteMergeInForeground(
Isolate* isolate, DirectHandle<Script> new_script) {
DCHECK_EQ(state_, kPendingForegroundWork);
Expand All @@ -2370,8 +2295,8 @@ Handle<SharedFunctionInfo> BackgroundMergeTask::CompleteMergeInForeground(
isolate, isolate->main_thread_local_heap(), old_script);

for (const auto& new_compiled_data : new_compiled_data_for_cached_sfis_) {
Tagged<SharedFunctionInfo> sfi = *new_compiled_data.cached_sfi;
if (!sfi->is_compiled() && new_compiled_data.new_sfi->is_compiled()) {
if (!new_compiled_data.cached_sfi->is_compiled() &&
new_compiled_data.new_sfi->is_compiled()) {
// Updating existing DebugInfos is not supported, but we don't expect
// uncompiled SharedFunctionInfos to contain DebugInfos.
DCHECK(!new_compiled_data.cached_sfi->HasDebugInfo(isolate));
Expand All @@ -2381,7 +2306,8 @@ Handle<SharedFunctionInfo> BackgroundMergeTask::CompleteMergeInForeground(
// cached_sfi to new_sfi, and then copy every field using CopyFrom.
new_compiled_data.new_sfi->set_script(
new_compiled_data.cached_sfi->script(kAcquireLoad), kReleaseStore);
sfi->CopyFrom(*new_compiled_data.new_sfi, isolate);
new_compiled_data.cached_sfi->CopyFrom(*new_compiled_data.new_sfi,
isolate);
}
}

Expand Down Expand Up @@ -2410,17 +2336,12 @@ Handle<SharedFunctionInfo> BackgroundMergeTask::CompleteMergeInForeground(
// pools is required.
if (forwarder.HasAnythingToForward()) {
for (DirectHandle<SharedFunctionInfo> new_sfi : used_new_sfis_) {
forwarder.UpdateScopeInfo(*new_sfi);
forwarder.UpdateOuterScopeInfo(*new_sfi);
if (new_sfi->HasBytecodeArray(isolate)) {
forwarder.AddBytecodeArray(new_sfi->GetBytecodeArray(isolate));
}
}
for (const auto& new_compiled_data : new_compiled_data_for_cached_sfis_) {
// It's possible that cached_sfi wasn't compiled, but an inner function
// existed that didn't exist when be background merged. In that case, pick
// up the relevant scope infos.
Tagged<SharedFunctionInfo> sfi = *new_compiled_data.cached_sfi;
forwarder.InstallOwnScopeInfo(sfi);
if (new_compiled_data.cached_sfi->HasBytecodeArray(isolate)) {
forwarder.AddBytecodeArray(
new_compiled_data.cached_sfi->GetBytecodeArray(isolate));
Expand All @@ -2443,45 +2364,6 @@ Handle<SharedFunctionInfo> BackgroundMergeTask::CompleteMergeInForeground(
SharedFunctionInfo::EnsureSourcePositionsAvailable(isolate, result);
}

if (v8_flags.verify_code_merge) {
// Check that there aren't any duplicate scope infos. Every scope/context
// should correspond to at most one scope info.
std::unordered_map<int, Tagged<ScopeInfo>> scope_infos;
for (int i = 0; i < old_script->infos()->length(); i++) {
Tagged<ScopeInfo> scope_info;
if (!old_script->infos()->get(i).IsWeak()) continue;
Tagged<HeapObject> info =
old_script->infos()->get(i).GetHeapObjectAssumeWeak();
if (Is<SharedFunctionInfo>(info)) {
Tagged<SharedFunctionInfo> old_sfi = Cast<SharedFunctionInfo>(info);
if (!old_sfi->scope_info()->IsEmpty()) {
scope_info = old_sfi->scope_info();
} else if (old_sfi->HasOuterScopeInfo()) {
scope_info = old_sfi->GetOuterScopeInfo();
} else {
continue;
}
} else {
scope_info = Cast<ScopeInfo>(info);
}
while (true) {
auto it = scope_infos.find(scope_info->UniqueIdInScript());
if (it != scope_infos.end()) {
if (*it->second != scope_info) {
old_script->infos()->get(i).GetHeapObjectAssumeWeak()->Print();
(*it->second)->Print();
scope_info->Print();
UNREACHABLE();
}
break;
}
scope_infos[scope_info->UniqueIdInScript()] = scope_info;
if (!scope_info->HasOuterScopeInfo()) break;
scope_info = scope_info->OuterScopeInfo();
}
}
}

return handle_scope.CloseAndEscape(result);
}

Expand Down
1 change: 1 addition & 0 deletions deps/v8/src/compiler/operation-typer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1259,6 +1259,7 @@ Type JSType(Type type) {
} // namespace

Type OperationTyper::SameValue(Type lhs, Type rhs) {
if (lhs.IsNone() || rhs.IsNone()) return Type::None();
if (!JSType(lhs).Maybe(JSType(rhs))) return singleton_false();
if (lhs.Is(Type::NaN())) {
if (rhs.Is(Type::NaN())) return singleton_true();
Expand Down
1 change: 0 additions & 1 deletion deps/v8/src/flags/flag-definitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2217,7 +2217,6 @@ DEFINE_BOOL(
merge_background_deserialized_script_with_compilation_cache, true,
"After deserializing code cache data on a background thread, merge it into "
"an existing Script if one is found in the Isolate compilation cache")
DEFINE_BOOL(verify_code_merge, false, "Verify scope infos after merge")
DEFINE_BOOL(
embedder_instance_types, false,
"enable type checks based on instance types provided by the embedder")
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/objects/js-date-time-format.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1845,7 +1845,7 @@ std::unique_ptr<icu::SimpleDateFormat> CreateICUDateFormat(
// has to be discussed. Revisit once the spec is clarified/revised.
icu::UnicodeString pattern;
UErrorCode status = U_ZERO_ERROR;
pattern = generator->getBestPattern(skeleton, UDATPG_MATCH_ALL_FIELDS_LENGTH,
pattern = generator->getBestPattern(skeleton, UDATPG_MATCH_HOUR_FIELD_LENGTH,
status);
pattern = ReplaceHourCycleInPattern(pattern, hc);
DCHECK(U_SUCCESS(status));
Expand Down
3 changes: 1 addition & 2 deletions deps/v8/src/objects/scope-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,7 @@ int ScopeInfo::ContextLength() const {
(function_name_context_slot ? 1 : 0);
}

// Needs to be kept in sync with Scope::UniqueIdInScript and
// SharedFunctionInfo::UniqueIdInScript.
// Needs to be kept in sync with Scope::UniqueIdInScript.
int ScopeInfo::UniqueIdInScript() const {
// Script scopes start "before" the script to avoid clashing with a scope that
// starts on character 0.
Expand Down
10 changes: 4 additions & 6 deletions deps/v8/src/objects/shared-function-info-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -613,11 +613,11 @@ DEF_GETTER(SharedFunctionInfo, outer_scope_info, Tagged<HeapObject>) {

bool SharedFunctionInfo::HasOuterScopeInfo() const {
Tagged<ScopeInfo> outer_info;
Tagged<ScopeInfo> info = scope_info(kAcquireLoad);
if (info->IsEmpty()) {
if (!is_compiled()) {
if (!IsScopeInfo(outer_scope_info())) return false;
outer_info = Cast<ScopeInfo>(outer_scope_info());
} else {
Tagged<ScopeInfo> info = scope_info(kAcquireLoad);
if (!info->HasOuterScopeInfo()) return false;
outer_info = info->OuterScopeInfo();
}
Expand All @@ -626,17 +626,15 @@ bool SharedFunctionInfo::HasOuterScopeInfo() const {

Tagged<ScopeInfo> SharedFunctionInfo::GetOuterScopeInfo() const {
DCHECK(HasOuterScopeInfo());
Tagged<ScopeInfo> info = scope_info(kAcquireLoad);
if (info->IsEmpty()) return Cast<ScopeInfo>(outer_scope_info());
return info->OuterScopeInfo();
if (!is_compiled()) return Cast<ScopeInfo>(outer_scope_info());
return scope_info(kAcquireLoad)->OuterScopeInfo();
}

void SharedFunctionInfo::set_outer_scope_info(Tagged<HeapObject> value,
WriteBarrierMode mode) {
DCHECK(!is_compiled());
DCHECK(IsTheHole(raw_outer_scope_info_or_feedback_metadata()));
DCHECK(IsScopeInfo(value) || IsTheHole(value));
DCHECK(scope_info()->IsEmpty());
set_raw_outer_scope_info_or_feedback_metadata(value, mode);
}

Expand Down
11 changes: 0 additions & 11 deletions deps/v8/src/objects/shared-function-info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,17 +265,6 @@ bool SharedFunctionInfo::HasDebugInfo(Isolate* isolate) const {
return isolate->debug()->HasDebugInfo(*this);
}

// Needs to be kept in sync with Scope::UniqueIdInScript and
// ScopeInfo::UniqueIdInScript.
int SharedFunctionInfo::UniqueIdInScript() const {
// Script scopes start "before" the script to avoid clashing with a scope that
// starts on character 0.
if (function_literal_id() == kFunctionLiteralIdTopLevel) return -1;
// Default constructors have the same start position as their parent class
// scope. Use the next char position to distinguish this scope.
return StartPosition() + IsDefaultConstructor(kind());
}

Tagged<DebugInfo> SharedFunctionInfo::GetDebugInfo(Isolate* isolate) const {
return isolate->debug()->TryGetDebugInfo(*this).value();
}
Expand Down
2 changes: 0 additions & 2 deletions deps/v8/src/objects/shared-function-info.h
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,6 @@ class SharedFunctionInfo

inline FunctionKind kind() const;

int UniqueIdInScript() const;

// Defines the index in a native context of closure's map instantiated using
// this shared function info.
DECL_INT_ACCESSORS(function_map_index)
Expand Down
Loading

0 comments on commit 0c771c3

Please sign in to comment.