[liveedit] Check that ScopeInfos for unchanged functions are equivalent

This CL adds a DCHECK to SFI::UpdateFromFunctionLiteralForLiveEdit
making sure that when we update the ScopeInfo object on an SFI that
they are equivalent modulo position info.

We also skip checking the `SourceTextModuleInfo` as it's `Equals`
implementation checks that different `SourceTextModuleInfo` instances
point to the same FixedArrays. This does not hold for live edited
modules.

The CL also adds the missing handling for Oddballs in
ScopeInfo::Equals. The inferred function name can be `undefined`.

R=leszeks@chromium.org

Bug: chromium:1363561
Change-Id: Ie28272f2fed149921c0acc8e37d9bbdfb1c92aed
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3937963
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83591}
This commit is contained in:
Simon Zünd 2022-10-06 13:02:16 +02:00 committed by V8 LUCI CQ
parent 9978b7f285
commit 5eb3d4b2de
3 changed files with 17 additions and 6 deletions

View File

@ -22,9 +22,14 @@ namespace v8 {
namespace internal {
#ifdef DEBUG
bool ScopeInfo::Equals(ScopeInfo other) const {
bool ScopeInfo::Equals(ScopeInfo other,
bool ignore_position_and_module_info) const {
if (length() != other.length()) return false;
for (int index = 0; index < length(); ++index) {
if (ignore_position_and_module_info && HasPositionInfo() &&
index >= PositionInfoIndex() && index <= PositionInfoIndex() + 1) {
continue;
}
Object entry = get(index);
Object other_entry = other.get(index);
if (entry.IsSmi()) {
@ -39,14 +44,20 @@ bool ScopeInfo::Equals(ScopeInfo other) const {
return false;
}
} else if (entry.IsScopeInfo()) {
if (!ScopeInfo::cast(entry).Equals(ScopeInfo::cast(other_entry))) {
if (!ScopeInfo::cast(entry).Equals(ScopeInfo::cast(other_entry),
ignore_position_and_module_info)) {
return false;
}
} else if (entry.IsSourceTextModuleInfo()) {
if (!SourceTextModuleInfo::cast(entry).Equals(
if (!ignore_position_and_module_info &&
!SourceTextModuleInfo::cast(entry).Equals(
SourceTextModuleInfo::cast(other_entry))) {
return false;
}
} else if (entry.IsOddball()) {
if (Oddball::cast(entry).kind() != Oddball::cast(other_entry).kind()) {
return false;
}
} else {
UNREACHABLE();
}

View File

@ -253,7 +253,8 @@ class ScopeInfo : public TorqueGeneratedScopeInfo<ScopeInfo, HeapObject> {
bool IsReplModeScope() const;
#ifdef DEBUG
bool Equals(ScopeInfo other) const;
bool Equals(ScopeInfo other,
bool ignore_position_and_module_info = false) const;
#endif
template <typename IsolateT>

View File

@ -722,9 +722,8 @@ void SharedFunctionInfo::UpdateFromFunctionLiteralForLiveEdit(
if (maybe_scope_info.IsScopeInfo()) {
// Updating the ScopeInfo is safe since they are identical modulo
// source positions.
// TODO(crbug.com/1363561): Add DCHECK with ScopeInfo::Equals that ignores
// position info.
ScopeInfo new_scope_info = *lit->scope()->scope_info();
DCHECK(new_scope_info.Equals(ScopeInfo::cast(maybe_scope_info), true));
SetScopeInfo(new_scope_info);
} else if (!is_compiled()) {
CHECK(HasUncompiledData());