Commit 6160a767 authored by Seth Brenith's avatar Seth Brenith Committed by Commit Bot

[torque] Generate accessors for struct-typed class fields

Torque generates runtime accessor member functions for most class fields
that are defined in .tq files, but fields with struct types are
currently omitted. This change adds those accessors. As an example, if a
.tq file defines the following:

  struct InternalClassStructElement {
    a: Smi;
    b: Smi;
  }

  class InternalClassWithStructElements extends HeapObject {
    const count: Smi;
    entries[count]: InternalClassStructElement;
  }

Then the following accessors are generated to get and set each struct
field within the 'entries' field:

  inline int entries_a(int i) const;
  inline void set_entries_a(int i, int value);

  inline int entries_b(int i) const;
  inline void set_entries_b(int i, int value);

Bug: v8:7793
Change-Id: Ia40b5918e9d09f53ad8e78bc33f8629b8d6a79fe
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2676926Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#72662}
parent 44054826
...@@ -77,9 +77,9 @@ std::vector<CoverageBlock> GetSortedBlockData(SharedFunctionInfo shared) { ...@@ -77,9 +77,9 @@ std::vector<CoverageBlock> GetSortedBlockData(SharedFunctionInfo shared) {
if (coverage_info.slot_count() == 0) return result; if (coverage_info.slot_count() == 0) return result;
for (int i = 0; i < coverage_info.slot_count(); i++) { for (int i = 0; i < coverage_info.slot_count(); i++) {
const int start_pos = coverage_info.StartSourcePosition(i); const int start_pos = coverage_info.slots_start_source_position(i);
const int until_pos = coverage_info.EndSourcePosition(i); const int until_pos = coverage_info.slots_end_source_position(i);
const int count = coverage_info.BlockCount(i); const int count = coverage_info.slots_block_count(i);
DCHECK_NE(kNoSourcePosition, start_pos); DCHECK_NE(kNoSourcePosition, start_pos);
result.emplace_back(start_pos, until_pos, count); result.emplace_back(start_pos, until_pos, count);
......
...@@ -356,38 +356,15 @@ int BreakPointInfo::GetBreakPointCount(Isolate* isolate) { ...@@ -356,38 +356,15 @@ int BreakPointInfo::GetBreakPointCount(Isolate* isolate) {
return FixedArray::cast(break_points()).length(); return FixedArray::cast(break_points()).length();
} }
int CoverageInfo::SlotFieldOffset(int slot_index, int field_offset) const {
DCHECK_LT(field_offset, Slot::kSize);
DCHECK_LT(slot_index, slot_count());
return kSlotsOffset + slot_index * Slot::kSize + field_offset;
}
int CoverageInfo::StartSourcePosition(int slot_index) const {
return ReadField<int32_t>(
SlotFieldOffset(slot_index, Slot::kStartSourcePositionOffset));
}
int CoverageInfo::EndSourcePosition(int slot_index) const {
return ReadField<int32_t>(
SlotFieldOffset(slot_index, Slot::kEndSourcePositionOffset));
}
int CoverageInfo::BlockCount(int slot_index) const {
return ReadField<int32_t>(
SlotFieldOffset(slot_index, Slot::kBlockCountOffset));
}
void CoverageInfo::InitializeSlot(int slot_index, int from_pos, int to_pos) { void CoverageInfo::InitializeSlot(int slot_index, int from_pos, int to_pos) {
WriteField<int32_t>( set_slots_start_source_position(slot_index, from_pos);
SlotFieldOffset(slot_index, Slot::kStartSourcePositionOffset), from_pos); set_slots_end_source_position(slot_index, to_pos);
WriteField<int32_t>(
SlotFieldOffset(slot_index, Slot::kEndSourcePositionOffset), to_pos);
ResetBlockCount(slot_index); ResetBlockCount(slot_index);
WriteField<int32_t>(SlotFieldOffset(slot_index, Slot::kPaddingOffset), 0); set_slots_padding(slot_index, 0);
} }
void CoverageInfo::ResetBlockCount(int slot_index) { void CoverageInfo::ResetBlockCount(int slot_index) {
WriteField<int32_t>(SlotFieldOffset(slot_index, Slot::kBlockCountOffset), 0); set_slots_block_count(slot_index, 0);
} }
void CoverageInfo::CoverageInfoPrint(std::ostream& os, void CoverageInfo::CoverageInfoPrint(std::ostream& os,
...@@ -406,8 +383,8 @@ void CoverageInfo::CoverageInfoPrint(std::ostream& os, ...@@ -406,8 +383,8 @@ void CoverageInfo::CoverageInfoPrint(std::ostream& os,
os << "):" << std::endl; os << "):" << std::endl;
for (int i = 0; i < slot_count(); i++) { for (int i = 0; i < slot_count(); i++) {
os << "{" << StartSourcePosition(i) << "," << EndSourcePosition(i) << "}" os << "{" << slots_start_source_position(i) << ","
<< std::endl; << slots_end_source_position(i) << "}" << std::endl;
} }
} }
......
...@@ -170,10 +170,6 @@ class BreakPointInfo ...@@ -170,10 +170,6 @@ class BreakPointInfo
class CoverageInfo class CoverageInfo
: public TorqueGeneratedCoverageInfo<CoverageInfo, HeapObject> { : public TorqueGeneratedCoverageInfo<CoverageInfo, HeapObject> {
public: public:
int StartSourcePosition(int slot_index) const;
int EndSourcePosition(int slot_index) const;
int BlockCount(int slot_index) const;
void InitializeSlot(int slot_index, int start_pos, int end_pos); void InitializeSlot(int slot_index, int start_pos, int end_pos);
void ResetBlockCount(int slot_index); void ResetBlockCount(int slot_index);
...@@ -191,9 +187,6 @@ class CoverageInfo ...@@ -191,9 +187,6 @@ class CoverageInfo
// Description of layout within each slot. // Description of layout within each slot.
using Slot = TorqueGeneratedCoverageInfoSlotOffsets; using Slot = TorqueGeneratedCoverageInfoSlotOffsets;
private:
int SlotFieldOffset(int slot_index, int field_offset) const;
TQ_OBJECT_CONSTRUCTORS(CoverageInfo) TQ_OBJECT_CONSTRUCTORS(CoverageInfo)
}; };
......
...@@ -333,7 +333,7 @@ Handle<ScopeInfo> ScopeInfo::Create(LocalIsolate* isolate, Zone* zone, ...@@ -333,7 +333,7 @@ Handle<ScopeInfo> ScopeInfo::Create(LocalIsolate* isolate, Zone* zone,
} }
// If present, add the function variable name and its index. // If present, add the function variable name and its index.
DCHECK_EQ(index, scope_info.FunctionNameInfoIndex()); DCHECK_EQ(index, scope_info.FunctionVariableInfoIndex());
if (has_function_name) { if (has_function_name) {
Variable* var = scope->AsDeclarationScope()->function_var(); Variable* var = scope->AsDeclarationScope()->function_var();
int var_index = -1; int var_index = -1;
...@@ -428,7 +428,7 @@ Handle<ScopeInfo> ScopeInfo::CreateForWithScope( ...@@ -428,7 +428,7 @@ Handle<ScopeInfo> ScopeInfo::CreateForWithScope(
int index = kVariablePartIndex; int index = kVariablePartIndex;
DCHECK_EQ(index, scope_info->ReceiverInfoIndex()); DCHECK_EQ(index, scope_info->ReceiverInfoIndex());
DCHECK_EQ(index, scope_info->FunctionNameInfoIndex()); DCHECK_EQ(index, scope_info->FunctionVariableInfoIndex());
DCHECK_EQ(index, scope_info->InferredFunctionNameIndex()); DCHECK_EQ(index, scope_info->InferredFunctionNameIndex());
DCHECK_EQ(index, scope_info->PositionInfoIndex()); DCHECK_EQ(index, scope_info->PositionInfoIndex());
DCHECK(index == scope_info->OuterScopeInfoIndex()); DCHECK(index == scope_info->OuterScopeInfoIndex());
...@@ -530,7 +530,7 @@ Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate, ...@@ -530,7 +530,7 @@ Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate,
scope_info->set(index++, Smi::FromInt(receiver_index)); scope_info->set(index++, Smi::FromInt(receiver_index));
} }
DCHECK_EQ(index, scope_info->FunctionNameInfoIndex()); DCHECK_EQ(index, scope_info->FunctionVariableInfoIndex());
if (is_empty_function) { if (is_empty_function) {
scope_info->set(index++, *isolate->factory()->empty_string()); scope_info->set(index++, *isolate->factory()->empty_string());
scope_info->set(index++, Smi::zero()); scope_info->set(index++, Smi::zero());
...@@ -700,7 +700,7 @@ bool ScopeInfo::HasSharedFunctionName() const { ...@@ -700,7 +700,7 @@ bool ScopeInfo::HasSharedFunctionName() const {
void ScopeInfo::SetFunctionName(Object name) { void ScopeInfo::SetFunctionName(Object name) {
DCHECK(HasFunctionName()); DCHECK(HasFunctionName());
DCHECK(name.IsString() || name == SharedFunctionInfo::kNoSharedNameSentinel); DCHECK(name.IsString() || name == SharedFunctionInfo::kNoSharedNameSentinel);
set(FunctionNameInfoIndex(), name); set_function_variable_info_name(0, name);
} }
void ScopeInfo::SetInferredFunctionName(String name) { void ScopeInfo::SetInferredFunctionName(String name) {
...@@ -743,7 +743,7 @@ bool ScopeInfo::HasContext() const { return ContextLength() > 0; } ...@@ -743,7 +743,7 @@ bool ScopeInfo::HasContext() const { return ContextLength() > 0; }
Object ScopeInfo::FunctionName() const { Object ScopeInfo::FunctionName() const {
DCHECK(HasFunctionName()); DCHECK(HasFunctionName());
return get(FunctionNameInfoIndex()); return function_variable_info_name(0);
} }
Object ScopeInfo::InferredFunctionName() const { Object ScopeInfo::InferredFunctionName() const {
...@@ -766,19 +766,19 @@ String ScopeInfo::FunctionDebugName() const { ...@@ -766,19 +766,19 @@ String ScopeInfo::FunctionDebugName() const {
int ScopeInfo::StartPosition() const { int ScopeInfo::StartPosition() const {
DCHECK(HasPositionInfo()); DCHECK(HasPositionInfo());
return Smi::ToInt(get(PositionInfoIndex())); return position_info_start(0);
} }
int ScopeInfo::EndPosition() const { int ScopeInfo::EndPosition() const {
DCHECK(HasPositionInfo()); DCHECK(HasPositionInfo());
return Smi::ToInt(get(PositionInfoIndex() + 1)); return position_info_end(0);
} }
void ScopeInfo::SetPositionInfo(int start, int end) { void ScopeInfo::SetPositionInfo(int start, int end) {
DCHECK(HasPositionInfo()); DCHECK(HasPositionInfo());
DCHECK_LE(start, end); DCHECK_LE(start, end);
set(PositionInfoIndex(), Smi::FromInt(start)); set_position_info_start(0, start);
set(PositionInfoIndex() + 1, Smi::FromInt(end)); set_position_info_end(0, end);
} }
ScopeInfo ScopeInfo::OuterScopeInfo() const { ScopeInfo ScopeInfo::OuterScopeInfo() const {
...@@ -914,7 +914,7 @@ int ScopeInfo::FunctionContextSlotIndex(String name) const { ...@@ -914,7 +914,7 @@ int ScopeInfo::FunctionContextSlotIndex(String name) const {
if (FunctionVariableBits::decode(Flags()) == if (FunctionVariableBits::decode(Flags()) ==
VariableAllocationInfo::CONTEXT && VariableAllocationInfo::CONTEXT &&
FunctionName() == name) { FunctionName() == name) {
return Smi::ToInt(get(FunctionNameInfoIndex() + 1)); return function_variable_info_context_or_stack_slot_index(0);
} }
return -1; return -1;
} }
...@@ -939,8 +939,8 @@ int ScopeInfo::ReceiverInfoIndex() const { ...@@ -939,8 +939,8 @@ int ScopeInfo::ReceiverInfoIndex() const {
return ConvertOffsetToIndex(ReceiverInfoOffset()); return ConvertOffsetToIndex(ReceiverInfoOffset());
} }
int ScopeInfo::FunctionNameInfoIndex() const { int ScopeInfo::FunctionVariableInfoIndex() const {
return ConvertOffsetToIndex(FunctionNameInfoOffset()); return ConvertOffsetToIndex(FunctionVariableInfoOffset());
} }
int ScopeInfo::InferredFunctionNameIndex() const { int ScopeInfo::InferredFunctionNameIndex() const {
...@@ -975,17 +975,13 @@ void ScopeInfo::ModuleVariable(int i, String* name, int* index, ...@@ -975,17 +975,13 @@ void ScopeInfo::ModuleVariable(int i, String* name, int* index,
VariableMode* mode, VariableMode* mode,
InitializationFlag* init_flag, InitializationFlag* init_flag,
MaybeAssignedFlag* maybe_assigned_flag) { MaybeAssignedFlag* maybe_assigned_flag) {
DCHECK_LE(0, i); int properties = module_variables_properties(i);
DCHECK_LT(i, module_variable_count(0));
int entry = ModuleVariablesIndex() + i * kModuleVariableEntryLength;
int properties = Smi::ToInt(get(entry + kModuleVariablePropertiesOffset));
if (name != nullptr) { if (name != nullptr) {
*name = String::cast(get(entry + kModuleVariableNameOffset)); *name = module_variables_name(i);
} }
if (index != nullptr) { if (index != nullptr) {
*index = Smi::ToInt(get(entry + kModuleVariableIndexOffset)); *index = module_variables_index(i);
DCHECK_NE(*index, 0); DCHECK_NE(*index, 0);
} }
if (mode != nullptr) { if (mode != nullptr) {
......
...@@ -288,7 +288,7 @@ class ScopeInfo : public TorqueGeneratedScopeInfo<ScopeInfo, FixedArrayBase> { ...@@ -288,7 +288,7 @@ class ScopeInfo : public TorqueGeneratedScopeInfo<ScopeInfo, FixedArrayBase> {
int ContextLocalInfosIndex() const; int ContextLocalInfosIndex() const;
int SavedClassVariableInfoIndex() const; int SavedClassVariableInfoIndex() const;
int ReceiverInfoIndex() const; int ReceiverInfoIndex() const;
int FunctionNameInfoIndex() const; int FunctionVariableInfoIndex() const;
int InferredFunctionNameIndex() const; int InferredFunctionNameIndex() const;
int PositionInfoIndex() const; int PositionInfoIndex() const;
int OuterScopeInfoIndex() const; int OuterScopeInfoIndex() const;
......
...@@ -78,9 +78,9 @@ struct PositionInfo { ...@@ -78,9 +78,9 @@ struct PositionInfo {
end: Smi; end: Smi;
} }
struct FunctionNameInfo { struct FunctionVariableInfo {
function_variable_name: String|Zero; name: String|Zero;
function_variable_context_or_stack_slot_index: Smi; context_or_stack_slot_index: Smi;
} }
bitfield struct VariableProperties extends uint31 { bitfield struct VariableProperties extends uint31 {
...@@ -136,8 +136,8 @@ extern class ScopeInfo extends FixedArrayBase { ...@@ -136,8 +136,8 @@ extern class ScopeInfo extends FixedArrayBase {
// information about the function variable. It always occupies two array // information about the function variable. It always occupies two array
// slots: a. The name of the function variable. // slots: a. The name of the function variable.
// b. The context or stack slot index for the variable. // b. The context or stack slot index for the variable.
function_name_info[flags.function_variable != FromConstexpr<VariableAllocationInfo>(VariableAllocationInfo::NONE) ? 1 : 0]: function_variable_info[flags.function_variable != FromConstexpr<VariableAllocationInfo>(VariableAllocationInfo::NONE) ? 1 : 0]:
FunctionNameInfo; FunctionVariableInfo;
inferred_function_name[flags.has_inferred_function_name ? 1 : 0]: String| inferred_function_name[flags.has_inferred_function_name ? 1 : 0]: String|
Undefined; Undefined;
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment