[parser] Allocate the receiver before parameters

This guarantees that if it's context-allocated, it'll be the first
slot in the context. That in turn allows us to drop a special index on
scope-info pointing at the receiver entry; once we update arguments
object handling to take the receiver possibly being there into
account.

Change-Id: Idfd06cf172e6905b02c8d17a962382e2a9ea0874
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3211999
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Reviewed-by: Maya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77360}
This commit is contained in:
Toon Verwaest 2021-10-12 16:54:00 +02:00 committed by V8 LUCI CQ
parent d02005f463
commit 177d09fc10
11 changed files with 92 additions and 108 deletions

View File

@ -2488,10 +2488,10 @@ void Scope::AllocateVariablesRecursively() {
// Allocate variables for this scope.
// Parameters must be allocated first, if any.
if (scope->is_declaration_scope()) {
scope->AsDeclarationScope()->AllocateReceiver();
if (scope->is_function_scope()) {
scope->AsDeclarationScope()->AllocateParameterLocals();
}
scope->AsDeclarationScope()->AllocateReceiver();
}
scope->AllocateNonParameterLocalsAndDeclaredGlobals();

View File

@ -2778,6 +2778,10 @@ int SharedFunctionInfoRef::context_header_size() const {
return object()->scope_info().ContextHeaderLength();
}
int SharedFunctionInfoRef::context_parameters_start() const {
return object()->scope_info().ParametersStartIndex();
}
ScopeInfoRef SharedFunctionInfoRef::scope_info() const {
return MakeRefAssumeMemoryFence(broker(), object()->scope_info(kAcquireLoad));
}

View File

@ -911,6 +911,7 @@ class V8_EXPORT_PRIVATE SharedFunctionInfoRef : public HeapObjectRef {
Builtin builtin_id() const;
int context_header_size() const;
int context_parameters_start() const;
BytecodeArrayRef GetBytecodeArray() const;
SharedFunctionInfo::Inlineability GetInlineability() const;
base::Optional<FunctionTemplateInfoRef> function_template_info() const;

View File

@ -1540,7 +1540,7 @@ Node* JSCreateLowering::TryAllocateAliasedArguments(
a.Store(AccessBuilder::ForSloppyArgumentsElementsContext(), context);
a.Store(AccessBuilder::ForSloppyArgumentsElementsArguments(), arguments);
for (int i = 0; i < mapped_count; ++i) {
int idx = shared.context_header_size() + parameter_count - 1 - i;
int idx = shared.context_parameters_start() + parameter_count - 1 - i;
a.Store(AccessBuilder::ForSloppyArgumentsElementsMappedEntry(),
jsgraph()->Constant(i), jsgraph()->Constant(idx));
}
@ -1597,7 +1597,7 @@ Node* JSCreateLowering::TryAllocateAliasedArguments(
a.Store(AccessBuilder::ForSloppyArgumentsElementsContext(), context);
a.Store(AccessBuilder::ForSloppyArgumentsElementsArguments(), arguments);
for (int i = 0; i < mapped_count; ++i) {
int idx = shared.context_header_size() + parameter_count - 1 - i;
int idx = shared.context_parameters_start() + parameter_count - 1 - i;
Node* value = graph()->NewNode(
common()->Select(MachineRepresentation::kTagged),
graph()->NewNode(simplified()->NumberLessThan(), jsgraph()->Constant(i),

View File

@ -146,6 +146,10 @@ macro NewParameterMapIterator(
const flags = context.GetScopeInfo().flags;
let contextHeaderSize: intptr = ContextSlot::MIN_CONTEXT_SLOTS;
if (flags.has_context_extension_slot) ++contextHeaderSize;
if (flags.receiver_variable ==
FromConstexpr<VariableAllocationInfo>(VariableAllocationInfo::CONTEXT)) {
++contextHeaderSize;
}
// Copy the parameter slots and the holes in the arguments.
// We need to fill in mapped_count slots. They index the context,
// where parameters are stored in reverse order, at

View File

@ -1445,8 +1445,8 @@ void FeedbackNexus::ResetTypeProfile() {
FeedbackIterator::FeedbackIterator(const FeedbackNexus* nexus)
: done_(false), index_(-1), state_(kOther) {
DCHECK(IsLoadICKind(nexus->kind()) ||
IsStoreICKind(nexus->kind()) || IsKeyedLoadICKind(nexus->kind()) ||
DCHECK(IsLoadICKind(nexus->kind()) || IsStoreICKind(nexus->kind()) ||
IsKeyedLoadICKind(nexus->kind()) ||
IsKeyedStoreICKind(nexus->kind()) || IsStoreOwnICKind(nexus->kind()) ||
IsStoreDataPropertyInLiteralKind(nexus->kind()) ||
IsStoreInArrayLiteralICKind(nexus->kind()) ||

View File

@ -143,8 +143,6 @@ Handle<ScopeInfo> ScopeInfo::Create(IsolateT* isolate, Zone* zone, Scope* scope,
const bool has_function_name =
function_name_info != VariableAllocationInfo::NONE;
const bool has_position_info = NeedsPositionInfo(scope->scope_type());
const bool has_receiver = receiver_info == VariableAllocationInfo::STACK ||
receiver_info == VariableAllocationInfo::CONTEXT;
const int parameter_count =
scope->is_declaration_scope()
? scope->AsDeclarationScope()->num_parameters()
@ -165,7 +163,6 @@ Handle<ScopeInfo> ScopeInfo::Create(IsolateT* isolate, Zone* zone, Scope* scope,
const int length = kVariablePartIndex + 2 * context_local_count +
(should_save_class_variable_index ? 1 : 0) +
(has_receiver ? 1 : 0) +
(has_function_name ? kFunctionNameEntries : 0) +
(has_inferred_function_name ? 1 : 0) +
(has_position_info ? kPositionInfoEntries : 0) +
@ -321,15 +318,6 @@ Handle<ScopeInfo> ScopeInfo::Create(IsolateT* isolate, Zone* zone, Scope* scope,
scope_info.set(index++, Smi::FromInt(class_variable->index()));
}
// If the receiver is allocated, add its index.
DCHECK_EQ(index, scope_info.ReceiverInfoIndex());
if (has_receiver) {
int var_index = scope->AsDeclarationScope()->receiver()->index();
scope_info.set(index++, Smi::FromInt(var_index));
// ?? DCHECK(receiver_info != CONTEXT || var_index ==
// scope_info->ContextLength() - 1);
}
// If present, add the function variable name and its index.
DCHECK_EQ(index, scope_info.FunctionVariableInfoIndex());
if (has_function_name) {
@ -426,7 +414,6 @@ Handle<ScopeInfo> ScopeInfo::CreateForWithScope(
scope_info->set_context_local_count(0);
int index = kVariablePartIndex;
DCHECK_EQ(index, scope_info->ReceiverInfoIndex());
DCHECK_EQ(index, scope_info->FunctionVariableInfoIndex());
DCHECK_EQ(index, scope_info->InferredFunctionNameIndex());
DCHECK_EQ(index, scope_info->PositionInfoIndex());
@ -464,11 +451,9 @@ Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate,
const bool is_script = type == BootstrappingType::kScript;
const int context_local_count =
is_empty_function || is_native_context ? 0 : 1;
const bool has_receiver = is_script;
const bool has_inferred_function_name = is_empty_function;
const bool has_position_info = true;
const int length = kVariablePartIndex + 2 * context_local_count +
(has_receiver ? 1 : 0) +
(is_empty_function ? kFunctionNameEntries : 0) +
(has_inferred_function_name ? 1 : 0) +
(has_position_info ? kPositionInfoEntries : 0);
@ -522,13 +507,6 @@ Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate,
scope_info->set(index++, Smi::FromInt(value));
}
// And here we record that this scopeinfo binds a receiver.
DCHECK_EQ(index, scope_info->ReceiverInfoIndex());
if (has_receiver) {
const int receiver_index = scope_info->ContextHeaderLength();
scope_info->set(index++, Smi::FromInt(receiver_index));
}
DCHECK_EQ(index, scope_info->FunctionVariableInfoIndex());
if (is_empty_function) {
scope_info->set(index++, *isolate->factory()->empty_string());
@ -949,11 +927,19 @@ int ScopeInfo::SavedClassVariableContextLocalIndex() const {
int ScopeInfo::ReceiverContextSlotIndex() const {
if (ReceiverVariableBits::decode(Flags()) ==
VariableAllocationInfo::CONTEXT) {
return receiver_info();
return ContextHeaderLength();
}
return -1;
}
int ScopeInfo::ParametersStartIndex() const {
if (ReceiverVariableBits::decode(Flags()) ==
VariableAllocationInfo::CONTEXT) {
return ContextHeaderLength() + 1;
}
return ContextHeaderLength();
}
int ScopeInfo::FunctionContextSlotIndex(String name) const {
DCHECK(name.IsInternalizedString());
if (FunctionVariableBits::decode(Flags()) ==
@ -980,10 +966,6 @@ int ScopeInfo::SavedClassVariableInfoIndex() const {
return ConvertOffsetToIndex(SavedClassVariableInfoOffset());
}
int ScopeInfo::ReceiverInfoIndex() const {
return ConvertOffsetToIndex(ReceiverInfoOffset());
}
int ScopeInfo::FunctionVariableInfoIndex() const {
return ConvertOffsetToIndex(FunctionVariableInfoOffset());
}

View File

@ -188,6 +188,9 @@ class ScopeInfo : public TorqueGeneratedScopeInfo<ScopeInfo, HeapObject> {
// context-allocated. Otherwise returns a value < 0.
int ReceiverContextSlotIndex() const;
// Returns the first parameter context slot index.
int ParametersStartIndex() const;
// Lookup support for serialized scope info. Returns the index of the
// saved class variable in context local slots if scope is a class scope
// and it contains static private methods that may be accessed.
@ -285,7 +288,6 @@ class ScopeInfo : public TorqueGeneratedScopeInfo<ScopeInfo, HeapObject> {
int ContextLocalNamesIndex() const;
int ContextLocalInfosIndex() const;
int SavedClassVariableInfoIndex() const;
int ReceiverInfoIndex() const;
int FunctionVariableInfoIndex() const;
int InferredFunctionNameIndex() const;
int PositionInfoIndex() const;

View File

@ -122,15 +122,6 @@ extern class ScopeInfo extends HeapObject {
// the context slot index for the class variable.
saved_class_variable_info?[flags.has_saved_class_variable_index]: Smi;
// If the scope binds a "this" value, one slot is reserved to hold the
// context or stack slot index for the variable.
receiver_info?[
flags.receiver_variable ==
FromConstexpr<VariableAllocationInfo>(VariableAllocationInfo::STACK) ||
flags.receiver_variable ==
FromConstexpr<VariableAllocationInfo>(VariableAllocationInfo::CONTEXT)
]: Smi;
// If the scope belongs to a named function expression this part contains
// information about the function variable. It always occupies two array
// slots: a. The name of the function variable.

View File

@ -105,9 +105,9 @@ bytecodes: [
/* 10 E> */ B(CreateFunctionContext), U8(0), U8(5),
B(PushContext), R(2),
B(Ldar), R(this),
B(StaCurrentContextSlot), U8(4),
B(Ldar), R(arg0),
B(StaCurrentContextSlot), U8(3),
B(Ldar), R(arg0),
B(StaCurrentContextSlot), U8(4),
B(CreateMappedArguments),
B(StaCurrentContextSlot), U8(6),
B(Ldar), R(1),
@ -116,7 +116,7 @@ bytecodes: [
B(PushContext), R(3),
B(LdaTheHole),
B(StaCurrentContextSlot), U8(2),
/* 34 S> */ B(LdaContextSlot), R(3), U8(3), U8(0),
/* 34 S> */ B(LdaContextSlot), R(3), U8(4), U8(0),
B(Star6),
B(GetIterator), R(6), U8(0), U8(2),
B(JumpIfJSReceiver), U8(7),

View File

@ -341,66 +341,66 @@ KNOWN_MAPS = {
("read_only_space", 0x03215): (67, "BasicBlockCountersMarkerMap"),
("read_only_space", 0x03259): (91, "ArrayBoilerplateDescriptionMap"),
("read_only_space", 0x03359): (103, "InterceptorInfoMap"),
("read_only_space", 0x05bf1): (76, "PromiseFulfillReactionJobTaskMap"),
("read_only_space", 0x05c19): (77, "PromiseRejectReactionJobTaskMap"),
("read_only_space", 0x05c41): (78, "CallableTaskMap"),
("read_only_space", 0x05c69): (79, "CallbackTaskMap"),
("read_only_space", 0x05c91): (80, "PromiseResolveThenableJobTaskMap"),
("read_only_space", 0x05cb9): (83, "FunctionTemplateInfoMap"),
("read_only_space", 0x05ce1): (84, "ObjectTemplateInfoMap"),
("read_only_space", 0x05d09): (85, "AccessCheckInfoMap"),
("read_only_space", 0x05d31): (86, "AccessorInfoMap"),
("read_only_space", 0x05d59): (87, "AccessorPairMap"),
("read_only_space", 0x05d81): (88, "AliasedArgumentsEntryMap"),
("read_only_space", 0x05da9): (89, "AllocationMementoMap"),
("read_only_space", 0x05dd1): (92, "AsmWasmDataMap"),
("read_only_space", 0x05df9): (93, "AsyncGeneratorRequestMap"),
("read_only_space", 0x05e21): (94, "BreakPointMap"),
("read_only_space", 0x05e49): (95, "BreakPointInfoMap"),
("read_only_space", 0x05e71): (96, "CachedTemplateObjectMap"),
("read_only_space", 0x05e99): (98, "ClassPositionsMap"),
("read_only_space", 0x05ec1): (99, "DebugInfoMap"),
("read_only_space", 0x05ee9): (102, "FunctionTemplateRareDataMap"),
("read_only_space", 0x05f11): (104, "InterpreterDataMap"),
("read_only_space", 0x05f39): (105, "ModuleRequestMap"),
("read_only_space", 0x05f61): (106, "PromiseCapabilityMap"),
("read_only_space", 0x05f89): (107, "PromiseReactionMap"),
("read_only_space", 0x05fb1): (108, "PropertyDescriptorObjectMap"),
("read_only_space", 0x05fd9): (109, "PrototypeInfoMap"),
("read_only_space", 0x06001): (110, "RegExpBoilerplateDescriptionMap"),
("read_only_space", 0x06029): (111, "ScriptMap"),
("read_only_space", 0x06051): (112, "SourceTextModuleInfoEntryMap"),
("read_only_space", 0x06079): (113, "StackFrameInfoMap"),
("read_only_space", 0x060a1): (114, "TemplateObjectDescriptionMap"),
("read_only_space", 0x060c9): (115, "Tuple2Map"),
("read_only_space", 0x060f1): (116, "WasmExceptionTagMap"),
("read_only_space", 0x06119): (117, "WasmIndirectFunctionTableMap"),
("read_only_space", 0x06141): (135, "SloppyArgumentsElementsMap"),
("read_only_space", 0x06169): (152, "DescriptorArrayMap"),
("read_only_space", 0x06191): (157, "UncompiledDataWithoutPreparseDataMap"),
("read_only_space", 0x061b9): (156, "UncompiledDataWithPreparseDataMap"),
("read_only_space", 0x061e1): (174, "OnHeapBasicBlockProfilerDataMap"),
("read_only_space", 0x06209): (170, "InternalClassMap"),
("read_only_space", 0x06231): (181, "SmiPairMap"),
("read_only_space", 0x06259): (180, "SmiBoxMap"),
("read_only_space", 0x06281): (146, "ExportedSubClassBaseMap"),
("read_only_space", 0x062a9): (147, "ExportedSubClassMap"),
("read_only_space", 0x062d1): (68, "AbstractInternalClassSubclass1Map"),
("read_only_space", 0x062f9): (69, "AbstractInternalClassSubclass2Map"),
("read_only_space", 0x06321): (134, "InternalClassWithSmiElementsMap"),
("read_only_space", 0x06349): (171, "InternalClassWithStructElementsMap"),
("read_only_space", 0x06371): (148, "ExportedSubClass2Map"),
("read_only_space", 0x06399): (182, "SortStateMap"),
("read_only_space", 0x063c1): (160, "CallRefDataMap"),
("read_only_space", 0x063e9): (90, "AllocationSiteWithWeakNextMap"),
("read_only_space", 0x06411): (90, "AllocationSiteWithoutWeakNextMap"),
("read_only_space", 0x06439): (81, "LoadHandler1Map"),
("read_only_space", 0x06461): (81, "LoadHandler2Map"),
("read_only_space", 0x06489): (81, "LoadHandler3Map"),
("read_only_space", 0x064b1): (82, "StoreHandler0Map"),
("read_only_space", 0x064d9): (82, "StoreHandler1Map"),
("read_only_space", 0x06501): (82, "StoreHandler2Map"),
("read_only_space", 0x06529): (82, "StoreHandler3Map"),
("read_only_space", 0x05bed): (76, "PromiseFulfillReactionJobTaskMap"),
("read_only_space", 0x05c15): (77, "PromiseRejectReactionJobTaskMap"),
("read_only_space", 0x05c3d): (78, "CallableTaskMap"),
("read_only_space", 0x05c65): (79, "CallbackTaskMap"),
("read_only_space", 0x05c8d): (80, "PromiseResolveThenableJobTaskMap"),
("read_only_space", 0x05cb5): (83, "FunctionTemplateInfoMap"),
("read_only_space", 0x05cdd): (84, "ObjectTemplateInfoMap"),
("read_only_space", 0x05d05): (85, "AccessCheckInfoMap"),
("read_only_space", 0x05d2d): (86, "AccessorInfoMap"),
("read_only_space", 0x05d55): (87, "AccessorPairMap"),
("read_only_space", 0x05d7d): (88, "AliasedArgumentsEntryMap"),
("read_only_space", 0x05da5): (89, "AllocationMementoMap"),
("read_only_space", 0x05dcd): (92, "AsmWasmDataMap"),
("read_only_space", 0x05df5): (93, "AsyncGeneratorRequestMap"),
("read_only_space", 0x05e1d): (94, "BreakPointMap"),
("read_only_space", 0x05e45): (95, "BreakPointInfoMap"),
("read_only_space", 0x05e6d): (96, "CachedTemplateObjectMap"),
("read_only_space", 0x05e95): (98, "ClassPositionsMap"),
("read_only_space", 0x05ebd): (99, "DebugInfoMap"),
("read_only_space", 0x05ee5): (102, "FunctionTemplateRareDataMap"),
("read_only_space", 0x05f0d): (104, "InterpreterDataMap"),
("read_only_space", 0x05f35): (105, "ModuleRequestMap"),
("read_only_space", 0x05f5d): (106, "PromiseCapabilityMap"),
("read_only_space", 0x05f85): (107, "PromiseReactionMap"),
("read_only_space", 0x05fad): (108, "PropertyDescriptorObjectMap"),
("read_only_space", 0x05fd5): (109, "PrototypeInfoMap"),
("read_only_space", 0x05ffd): (110, "RegExpBoilerplateDescriptionMap"),
("read_only_space", 0x06025): (111, "ScriptMap"),
("read_only_space", 0x0604d): (112, "SourceTextModuleInfoEntryMap"),
("read_only_space", 0x06075): (113, "StackFrameInfoMap"),
("read_only_space", 0x0609d): (114, "TemplateObjectDescriptionMap"),
("read_only_space", 0x060c5): (115, "Tuple2Map"),
("read_only_space", 0x060ed): (116, "WasmExceptionTagMap"),
("read_only_space", 0x06115): (117, "WasmIndirectFunctionTableMap"),
("read_only_space", 0x0613d): (135, "SloppyArgumentsElementsMap"),
("read_only_space", 0x06165): (152, "DescriptorArrayMap"),
("read_only_space", 0x0618d): (157, "UncompiledDataWithoutPreparseDataMap"),
("read_only_space", 0x061b5): (156, "UncompiledDataWithPreparseDataMap"),
("read_only_space", 0x061dd): (174, "OnHeapBasicBlockProfilerDataMap"),
("read_only_space", 0x06205): (170, "InternalClassMap"),
("read_only_space", 0x0622d): (181, "SmiPairMap"),
("read_only_space", 0x06255): (180, "SmiBoxMap"),
("read_only_space", 0x0627d): (146, "ExportedSubClassBaseMap"),
("read_only_space", 0x062a5): (147, "ExportedSubClassMap"),
("read_only_space", 0x062cd): (68, "AbstractInternalClassSubclass1Map"),
("read_only_space", 0x062f5): (69, "AbstractInternalClassSubclass2Map"),
("read_only_space", 0x0631d): (134, "InternalClassWithSmiElementsMap"),
("read_only_space", 0x06345): (171, "InternalClassWithStructElementsMap"),
("read_only_space", 0x0636d): (148, "ExportedSubClass2Map"),
("read_only_space", 0x06395): (182, "SortStateMap"),
("read_only_space", 0x063bd): (160, "CallRefDataMap"),
("read_only_space", 0x063e5): (90, "AllocationSiteWithWeakNextMap"),
("read_only_space", 0x0640d): (90, "AllocationSiteWithoutWeakNextMap"),
("read_only_space", 0x06435): (81, "LoadHandler1Map"),
("read_only_space", 0x0645d): (81, "LoadHandler2Map"),
("read_only_space", 0x06485): (81, "LoadHandler3Map"),
("read_only_space", 0x064ad): (82, "StoreHandler0Map"),
("read_only_space", 0x064d5): (82, "StoreHandler1Map"),
("read_only_space", 0x064fd): (82, "StoreHandler2Map"),
("read_only_space", 0x06525): (82, "StoreHandler3Map"),
("map_space", 0x02119): (1057, "ExternalMap"),
("map_space", 0x02141): (2114, "JSMessageObjectMap"),
}
@ -449,9 +449,9 @@ KNOWN_OBJECTS = {
("read_only_space", 0x03469): "TrampolineTrivialCodeDataContainer",
("read_only_space", 0x03475): "TrampolinePromiseRejectionCodeDataContainer",
("read_only_space", 0x03481): "GlobalThisBindingScopeInfo",
("read_only_space", 0x034b5): "EmptyFunctionScopeInfo",
("read_only_space", 0x034d9): "NativeScopeInfo",
("read_only_space", 0x034f1): "HashSeed",
("read_only_space", 0x034b1): "EmptyFunctionScopeInfo",
("read_only_space", 0x034d5): "NativeScopeInfo",
("read_only_space", 0x034ed): "HashSeed",
("old_space", 0x04aa1): "ArgumentsIteratorAccessor",
("old_space", 0x04ae5): "ArrayLengthAccessor",
("old_space", 0x04b29): "BoundFunctionLengthAccessor",