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) {
if (coverage_info.slot_count() == 0) return result;
for (int i = 0; i < coverage_info.slot_count(); i++) {
const int start_pos = coverage_info.StartSourcePosition(i);
const int until_pos = coverage_info.EndSourcePosition(i);
const int count = coverage_info.BlockCount(i);
const int start_pos = coverage_info.slots_start_source_position(i);
const int until_pos = coverage_info.slots_end_source_position(i);
const int count = coverage_info.slots_block_count(i);
DCHECK_NE(kNoSourcePosition, start_pos);
result.emplace_back(start_pos, until_pos, count);
......
......@@ -356,38 +356,15 @@ int BreakPointInfo::GetBreakPointCount(Isolate* isolate) {
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) {
WriteField<int32_t>(
SlotFieldOffset(slot_index, Slot::kStartSourcePositionOffset), from_pos);
WriteField<int32_t>(
SlotFieldOffset(slot_index, Slot::kEndSourcePositionOffset), to_pos);
set_slots_start_source_position(slot_index, from_pos);
set_slots_end_source_position(slot_index, to_pos);
ResetBlockCount(slot_index);
WriteField<int32_t>(SlotFieldOffset(slot_index, Slot::kPaddingOffset), 0);
set_slots_padding(slot_index, 0);
}
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,
......@@ -406,8 +383,8 @@ void CoverageInfo::CoverageInfoPrint(std::ostream& os,
os << "):" << std::endl;
for (int i = 0; i < slot_count(); i++) {
os << "{" << StartSourcePosition(i) << "," << EndSourcePosition(i) << "}"
<< std::endl;
os << "{" << slots_start_source_position(i) << ","
<< slots_end_source_position(i) << "}" << std::endl;
}
}
......
......@@ -170,10 +170,6 @@ class BreakPointInfo
class CoverageInfo
: public TorqueGeneratedCoverageInfo<CoverageInfo, HeapObject> {
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 ResetBlockCount(int slot_index);
......@@ -191,9 +187,6 @@ class CoverageInfo
// Description of layout within each slot.
using Slot = TorqueGeneratedCoverageInfoSlotOffsets;
private:
int SlotFieldOffset(int slot_index, int field_offset) const;
TQ_OBJECT_CONSTRUCTORS(CoverageInfo)
};
......
......@@ -333,7 +333,7 @@ Handle<ScopeInfo> ScopeInfo::Create(LocalIsolate* isolate, Zone* zone,
}
// 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) {
Variable* var = scope->AsDeclarationScope()->function_var();
int var_index = -1;
......@@ -428,7 +428,7 @@ Handle<ScopeInfo> ScopeInfo::CreateForWithScope(
int index = kVariablePartIndex;
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->PositionInfoIndex());
DCHECK(index == scope_info->OuterScopeInfoIndex());
......@@ -530,7 +530,7 @@ Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate,
scope_info->set(index++, Smi::FromInt(receiver_index));
}
DCHECK_EQ(index, scope_info->FunctionNameInfoIndex());
DCHECK_EQ(index, scope_info->FunctionVariableInfoIndex());
if (is_empty_function) {
scope_info->set(index++, *isolate->factory()->empty_string());
scope_info->set(index++, Smi::zero());
......@@ -700,7 +700,7 @@ bool ScopeInfo::HasSharedFunctionName() const {
void ScopeInfo::SetFunctionName(Object name) {
DCHECK(HasFunctionName());
DCHECK(name.IsString() || name == SharedFunctionInfo::kNoSharedNameSentinel);
set(FunctionNameInfoIndex(), name);
set_function_variable_info_name(0, name);
}
void ScopeInfo::SetInferredFunctionName(String name) {
......@@ -743,7 +743,7 @@ bool ScopeInfo::HasContext() const { return ContextLength() > 0; }
Object ScopeInfo::FunctionName() const {
DCHECK(HasFunctionName());
return get(FunctionNameInfoIndex());
return function_variable_info_name(0);
}
Object ScopeInfo::InferredFunctionName() const {
......@@ -766,19 +766,19 @@ String ScopeInfo::FunctionDebugName() const {
int ScopeInfo::StartPosition() const {
DCHECK(HasPositionInfo());
return Smi::ToInt(get(PositionInfoIndex()));
return position_info_start(0);
}
int ScopeInfo::EndPosition() const {
DCHECK(HasPositionInfo());
return Smi::ToInt(get(PositionInfoIndex() + 1));
return position_info_end(0);
}
void ScopeInfo::SetPositionInfo(int start, int end) {
DCHECK(HasPositionInfo());
DCHECK_LE(start, end);
set(PositionInfoIndex(), Smi::FromInt(start));
set(PositionInfoIndex() + 1, Smi::FromInt(end));
set_position_info_start(0, start);
set_position_info_end(0, end);
}
ScopeInfo ScopeInfo::OuterScopeInfo() const {
......@@ -914,7 +914,7 @@ int ScopeInfo::FunctionContextSlotIndex(String name) const {
if (FunctionVariableBits::decode(Flags()) ==
VariableAllocationInfo::CONTEXT &&
FunctionName() == name) {
return Smi::ToInt(get(FunctionNameInfoIndex() + 1));
return function_variable_info_context_or_stack_slot_index(0);
}
return -1;
}
......@@ -939,8 +939,8 @@ int ScopeInfo::ReceiverInfoIndex() const {
return ConvertOffsetToIndex(ReceiverInfoOffset());
}
int ScopeInfo::FunctionNameInfoIndex() const {
return ConvertOffsetToIndex(FunctionNameInfoOffset());
int ScopeInfo::FunctionVariableInfoIndex() const {
return ConvertOffsetToIndex(FunctionVariableInfoOffset());
}
int ScopeInfo::InferredFunctionNameIndex() const {
......@@ -975,17 +975,13 @@ void ScopeInfo::ModuleVariable(int i, String* name, int* index,
VariableMode* mode,
InitializationFlag* init_flag,
MaybeAssignedFlag* maybe_assigned_flag) {
DCHECK_LE(0, i);
DCHECK_LT(i, module_variable_count(0));
int entry = ModuleVariablesIndex() + i * kModuleVariableEntryLength;
int properties = Smi::ToInt(get(entry + kModuleVariablePropertiesOffset));
int properties = module_variables_properties(i);
if (name != nullptr) {
*name = String::cast(get(entry + kModuleVariableNameOffset));
*name = module_variables_name(i);
}
if (index != nullptr) {
*index = Smi::ToInt(get(entry + kModuleVariableIndexOffset));
*index = module_variables_index(i);
DCHECK_NE(*index, 0);
}
if (mode != nullptr) {
......
......@@ -288,7 +288,7 @@ class ScopeInfo : public TorqueGeneratedScopeInfo<ScopeInfo, FixedArrayBase> {
int ContextLocalInfosIndex() const;
int SavedClassVariableInfoIndex() const;
int ReceiverInfoIndex() const;
int FunctionNameInfoIndex() const;
int FunctionVariableInfoIndex() const;
int InferredFunctionNameIndex() const;
int PositionInfoIndex() const;
int OuterScopeInfoIndex() const;
......
......@@ -78,9 +78,9 @@ struct PositionInfo {
end: Smi;
}
struct FunctionNameInfo {
function_variable_name: String|Zero;
function_variable_context_or_stack_slot_index: Smi;
struct FunctionVariableInfo {
name: String|Zero;
context_or_stack_slot_index: Smi;
}
bitfield struct VariableProperties extends uint31 {
......@@ -136,8 +136,8 @@ extern class ScopeInfo extends FixedArrayBase {
// information about the function variable. It always occupies two array
// slots: a. The name of the function variable.
// b. The context or stack slot index for the variable.
function_name_info[flags.function_variable != FromConstexpr<VariableAllocationInfo>(VariableAllocationInfo::NONE) ? 1 : 0]:
FunctionNameInfo;
function_variable_info[flags.function_variable != FromConstexpr<VariableAllocationInfo>(VariableAllocationInfo::NONE) ? 1 : 0]:
FunctionVariableInfo;
inferred_function_name[flags.has_inferred_function_name ? 1 : 0]: String|
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