Skip to content

Commit ecaac32

Browse files
sethbrenithCommit Bot
authored andcommitted
[torque] Begin porting ScopeInfo to Torque
This change adds Torque field definitions for ScopeInfo and begins to use the Torque-generated accessors in some places. It does not change the in-memory layout of ScopeInfo. Torque compiler changes: - Fix an issue where the parser created constexpr types for classes based on the class name rather than the `generates` clause. This meant that generated accessors referred to the imaginary type HashTable rather than the real C++ type FixedArray. - Don't pass Isolate* through the generated runtime functions that implement Torque macros. Maybe we'll need it eventually, but we don't right now and it complicates a lot of things. - Don't emit `kSomeFieldOffset` if some_field has an unknown offset. Instead, emit a member function `SomeFieldOffset()` which fetches the slice for some_field and returns its offset. - Emit an `AllocatedSize()` member function for classes which have complex length expressions. It fetches the slice for the last field and performs the multiply&add to compute the total object size. - Emit field accessors for fields with complex length expressions, using the new offset functions. - Fix a few minor bugs where Torque can write uncompilable code. With this change, most code still treats ScopeInfo like a FixedArray, so I would like to follow up with some additional changes: 1. Generate a GC visitor for ScopeInfo and use it 2. Generate accessors for struct-typed fields (indexed or otherwise), and use them 3. Get rid of the FixedArray-style get and set accessors; use TaggedField::load and similar instead 4. Inherit from HeapObject rather than FixedArrayBase to remove the unnecessary `length` field After that, there will only be one ugly part left: initialization. I think it's possible to generate a factory function that takes a bunch of iterator parameters and returns a fully-formed, verifiably correct ScopeInfo instance, but doing so is more complicated than the four mostly-mechanical changes listed above. Bug: v8:7793 Change-Id: I55fcfe9189e4d1613c68d49e378da5dc02597b36 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2357758 Reviewed-by: Toon Verwaest <verwaest@chromium.org> Reviewed-by: Peter Marshall <petermarshall@chromium.org> Reviewed-by: Dominik Inführ <dinfuehr@chromium.org> Reviewed-by: Tobias Tebbi <tebbi@chromium.org> Commit-Queue: Seth Brenith <seth.brenith@microsoft.com> Cr-Commit-Position: refs/heads/master@{#72187}
1 parent 1dd3e29 commit ecaac32

30 files changed

Lines changed: 659 additions & 366 deletions

BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,7 @@ action("postmortem-metadata") {
11921192
"src/objects/primitive-heap-object.h",
11931193
"src/objects/primitive-heap-object-inl.h",
11941194
"src/objects/scope-info.h",
1195+
"src/objects/scope-info-inl.h",
11951196
"src/objects/script.h",
11961197
"src/objects/script-inl.h",
11971198
"src/objects/shared-function-info.cc",
@@ -3184,6 +3185,7 @@ v8_source_set("v8_base_without_compiler") {
31843185
"src/objects/prototype-info.h",
31853186
"src/objects/prototype.h",
31863187
"src/objects/regexp-match-info.h",
3188+
"src/objects/scope-info-inl.h",
31873189
"src/objects/scope-info.cc",
31883190
"src/objects/scope-info.h",
31893191
"src/objects/script-inl.h",

src/codegen/code-stub-assembler.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2013,6 +2013,11 @@ TNode<IntPtrT> CodeStubAssembler::LoadArrayLength(
20132013
return LoadAndUntagWeakFixedArrayLength(array);
20142014
}
20152015

2016+
template <>
2017+
TNode<IntPtrT> CodeStubAssembler::LoadArrayLength(TNode<ScopeInfo> array) {
2018+
return LoadAndUntagFixedArrayBaseLength(array);
2019+
}
2020+
20162021
template <typename Array, typename TIndex, typename TValue>
20172022
TNode<TValue> CodeStubAssembler::LoadArrayElement(
20182023
TNode<Array> array, int array_header_size, TNode<TIndex> index_node,
@@ -2043,6 +2048,10 @@ TNode<TValue> CodeStubAssembler::LoadArrayElement(
20432048
template V8_EXPORT_PRIVATE TNode<MaybeObject>
20442049
CodeStubAssembler::LoadArrayElement<TransitionArray, IntPtrT>(
20452050
TNode<TransitionArray>, int, TNode<IntPtrT>, int, LoadSensitivity);
2051+
template V8_EXPORT_PRIVATE TNode<MaybeObject>
2052+
CodeStubAssembler::LoadArrayElement<ScopeInfo, IntPtrT>(TNode<ScopeInfo>, int,
2053+
TNode<IntPtrT>, int,
2054+
LoadSensitivity);
20462055

20472056
template <typename TIndex>
20482057
TNode<Object> CodeStubAssembler::LoadFixedArrayElement(

src/diagnostics/objects-debug.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,6 @@ void HeapObject::HeapObjectVerify(Isolate* isolate) {
182182
case NUMBER_DICTIONARY_TYPE:
183183
case SIMPLE_NUMBER_DICTIONARY_TYPE:
184184
case EPHEMERON_HASH_TABLE_TYPE:
185-
case SCOPE_INFO_TYPE:
186185
case SCRIPT_CONTEXT_TABLE_TYPE:
187186
FixedArray::cast(*this).FixedArrayVerify(isolate);
188187
break;
@@ -581,6 +580,20 @@ void Context::ContextVerify(Isolate* isolate) {
581580
}
582581
}
583582

583+
void ScopeInfo::ScopeInfoVerify(Isolate* isolate) {
584+
TorqueGeneratedClassVerifiers::ScopeInfoVerify(*this, isolate);
585+
586+
// Make sure that the FixedArray-style length matches the length that we would
587+
// compute based on the Torque indexed fields.
588+
CHECK_EQ(FixedArray::SizeFor(length()), AllocatedSize());
589+
590+
// Code that treats ScopeInfo like a FixedArray expects all values to be
591+
// tagged.
592+
for (int i = 0; i < length(); ++i) {
593+
Object::VerifyPointer(isolate, get(isolate, i));
594+
}
595+
}
596+
584597
void NativeContext::NativeContextVerify(Isolate* isolate) {
585598
ContextVerify(isolate);
586599
CHECK_EQ(length(), NativeContext::NATIVE_CONTEXT_SLOTS);

src/diagnostics/objects-printer.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,6 @@ void HeapObject::HeapObjectPrint(std::ostream& os) { // NOLINT
209209
case STORE_HANDLER_TYPE:
210210
StoreHandler::cast(*this).StoreHandlerPrint(os);
211211
break;
212-
case SCOPE_INFO_TYPE:
213-
ScopeInfo::cast(*this).ScopeInfoPrint(os);
214-
break;
215212
case FEEDBACK_METADATA_TYPE:
216213
FeedbackMetadata::cast(*this).FeedbackMetadataPrint(os);
217214
break;

src/heap/factory-base.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,8 +676,11 @@ template <typename Impl>
676676
Handle<ScopeInfo> FactoryBase<Impl>::NewScopeInfo(int length,
677677
AllocationType type) {
678678
DCHECK(type == AllocationType::kOld || type == AllocationType::kReadOnly);
679-
return Handle<ScopeInfo>::cast(NewFixedArrayWithMap(
680-
read_only_roots().scope_info_map_handle(), length, type));
679+
Handle<HeapObject> result =
680+
Handle<HeapObject>::cast(NewFixedArray(length, type));
681+
result->set_map_after_allocation(*read_only_roots().scope_info_map_handle(),
682+
SKIP_WRITE_BARRIER);
683+
return Handle<ScopeInfo>::cast(result);
681684
}
682685

683686
template <typename Impl>

src/heap/objects-visiting.h

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,47 @@
1414
namespace v8 {
1515
namespace internal {
1616

17-
#define TYPED_VISITOR_ID_LIST(V) \
18-
V(AllocationSite) \
19-
V(BigInt) \
20-
V(ByteArray) \
21-
V(BytecodeArray) \
22-
V(Cell) \
23-
V(Code) \
24-
V(CodeDataContainer) \
25-
V(CoverageInfo) \
26-
V(DataHandler) \
27-
V(EmbedderDataArray) \
28-
V(EphemeronHashTable) \
29-
V(FeedbackCell) \
30-
V(FeedbackMetadata) \
31-
V(FixedDoubleArray) \
32-
V(JSArrayBuffer) \
33-
V(JSDataView) \
34-
V(JSFunction) \
35-
V(JSObject) \
36-
V(JSTypedArray) \
37-
V(WeakCell) \
38-
V(JSWeakCollection) \
39-
V(JSWeakRef) \
40-
V(Map) \
41-
V(NativeContext) \
42-
V(PreparseData) \
43-
V(PropertyArray) \
44-
V(PropertyCell) \
45-
V(PrototypeInfo) \
46-
V(SmallOrderedHashMap) \
47-
V(SmallOrderedHashSet) \
48-
V(SmallOrderedNameDictionary) \
49-
V(SourceTextModule) \
50-
V(Symbol) \
51-
V(SyntheticModule) \
52-
V(TransitionArray) \
53-
V(WasmArray) \
54-
V(WasmIndirectFunctionTable) \
55-
V(WasmInstanceObject) \
56-
V(WasmStruct) \
17+
#define TYPED_VISITOR_ID_LIST(V) \
18+
V(AllocationSite) \
19+
V(BigInt) \
20+
V(ByteArray) \
21+
V(BytecodeArray) \
22+
V(Cell) \
23+
V(Code) \
24+
V(CodeDataContainer) \
25+
V(CoverageInfo) \
26+
V(DataHandler) \
27+
V(EmbedderDataArray) \
28+
V(EphemeronHashTable) \
29+
V(FeedbackCell) \
30+
V(FeedbackMetadata) \
31+
V(FixedDoubleArray) \
32+
V(JSArrayBuffer) \
33+
V(JSDataView) \
34+
V(JSFunction) \
35+
V(JSObject) \
36+
V(JSTypedArray) \
37+
V(WeakCell) \
38+
V(JSWeakCollection) \
39+
V(JSWeakRef) \
40+
V(Map) \
41+
V(NativeContext) \
42+
V(PreparseData) \
43+
V(PropertyArray) \
44+
V(PropertyCell) \
45+
V(PrototypeInfo) \
46+
V(ScopeInfo) \
47+
V(SmallOrderedHashMap) \
48+
V(SmallOrderedHashSet) \
49+
V(SmallOrderedNameDictionary) \
50+
V(SourceTextModule) \
51+
V(Symbol) \
52+
V(SyntheticModule) \
53+
V(TransitionArray) \
54+
V(WasmArray) \
55+
V(WasmIndirectFunctionTable) \
56+
V(WasmInstanceObject) \
57+
V(WasmStruct) \
5758
V(WasmTypeInfo)
5859

5960
#define FORWARD_DECLARE(TypeName) class TypeName;

src/heap/setup-heap-internal.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -532,16 +532,16 @@ bool Heap::CreateInitialMaps() {
532532
AllocationType::kReadOnly);
533533
if (!alloc.To(&obj)) return false;
534534
obj.set_map_after_allocation(roots.scope_info_map(), SKIP_WRITE_BARRIER);
535-
FixedArray::cast(obj).set_length(ScopeInfo::kVariablePartIndex);
535+
ScopeInfo::cast(obj).set_length(ScopeInfo::kVariablePartIndex);
536536
int flags = ScopeInfo::IsEmptyBit::encode(true);
537537
DCHECK_EQ(ScopeInfo::LanguageModeBit::decode(flags), LanguageMode::kSloppy);
538538
DCHECK_EQ(ScopeInfo::ReceiverVariableBits::decode(flags),
539539
VariableAllocationInfo::NONE);
540540
DCHECK_EQ(ScopeInfo::FunctionVariableBits::decode(flags),
541541
VariableAllocationInfo::NONE);
542-
ScopeInfo::cast(obj).SetFlags(flags);
543-
ScopeInfo::cast(obj).SetContextLocalCount(0);
544-
ScopeInfo::cast(obj).SetParameterCount(0);
542+
ScopeInfo::cast(obj).set_flags(flags);
543+
ScopeInfo::cast(obj).set_context_local_count(0);
544+
ScopeInfo::cast(obj).set_parameter_count(0);
545545
}
546546
set_empty_scope_info(ScopeInfo::cast(obj));
547547

src/ic/accessor-assembler.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3067,13 +3067,11 @@ void AccessorAssembler::ScriptContextTableLookup(
30673067
ScriptContextTable::kFirstContextSlotIndex * kTaggedSize));
30683068
TNode<ScopeInfo> scope_info =
30693069
CAST(LoadContextElement(script_context, Context::SCOPE_INFO_INDEX));
3070-
TNode<IntPtrT> length = LoadAndUntagFixedArrayBaseLength(scope_info);
3071-
GotoIf(IntPtrLessThanOrEqual(length, IntPtrConstant(0)), &loop);
30723070

30733071
TVARIABLE(IntPtrT, scope_var_index,
30743072
IntPtrConstant(ScopeInfo::kVariablePartIndex - 1));
3075-
TNode<IntPtrT> num_scope_vars = SmiUntag(CAST(LoadFixedArrayElement(
3076-
scope_info, IntPtrConstant(ScopeInfo::Fields::kContextLocalCount))));
3073+
TNode<IntPtrT> num_scope_vars = SmiUntag(
3074+
CAST(LoadObjectField(scope_info, ScopeInfo::kContextLocalCountOffset)));
30773075
TNode<IntPtrT> end_index = IntPtrAdd(
30783076
num_scope_vars, IntPtrConstant(ScopeInfo::kVariablePartIndex));
30793077
Label loop_scope_info(this, &scope_var_index);
@@ -3085,8 +3083,9 @@ void AccessorAssembler::ScriptContextTableLookup(
30853083
GotoIf(IntPtrGreaterThanOrEqual(scope_var_index.value(), end_index),
30863084
&loop);
30873085

3088-
TNode<Object> var_name =
3089-
LoadFixedArrayElement(scope_info, scope_var_index.value(), 0);
3086+
FixedArrayBoundsCheck(scope_info, scope_var_index.value(), 0);
3087+
TNode<Object> var_name = CAST(LoadArrayElement(
3088+
scope_info, FixedArray::kHeaderSize, scope_var_index.value()));
30903089
GotoIf(TaggedNotEqual(var_name, name), &loop_scope_info);
30913090

30923091
TNode<IntPtrT> var_index =

src/objects/all-objects-inl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
#include "src/objects/property-cell-inl.h"
6969
#include "src/objects/property-descriptor-object-inl.h"
7070
#include "src/objects/prototype-info-inl.h"
71+
#include "src/objects/scope-info-inl.h"
7172
#include "src/objects/script-inl.h"
7273
#include "src/objects/shared-function-info-inl.h"
7374
#include "src/objects/slots-atomic-inl.h"

src/objects/heap-object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "src/objects/tagged-field.h"
1212
#include "src/roots/roots.h"
1313
#include "src/torque/runtime-macro-shims.h"
14+
#include "src/torque/runtime-support.h"
1415

1516
// Has to be the last include (doesn't have include guards):
1617
#include "src/objects/object-macros.h"

0 commit comments

Comments
 (0)