Commit 8cb5dea9 authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[torque] generate int accessors for Smi fields

In the runtime, we always had a convention to use int-typed accessors
for Smi fields. For Torque-generated classes, we kept them Smi-typed
but then added int wrappers around that.
This CL makes Torque generate int-typed accessors directly, removing the
need for these wrappers.

TBR=hpayer@chromium.org

Bug: v8:7793
Change-Id: I348e1d96295c9676fafda32b7d49088848527f89
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2106210
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66760}
parent d7e02ea4
......@@ -505,7 +505,7 @@ Handle<PropertyDescriptorObject> Factory::NewPropertyDescriptorObject() {
Handle<PropertyDescriptorObject> object =
Handle<PropertyDescriptorObject>::cast(
NewStruct(PROPERTY_DESCRIPTOR_OBJECT_TYPE, AllocationType::kYoung));
object->set_flags(Smi::zero());
object->set_flags(0);
object->set_value(*the_hole_value(), SKIP_WRITE_BARRIER);
object->set_get(*the_hole_value(), SKIP_WRITE_BARRIER);
object->set_set(*the_hole_value(), SKIP_WRITE_BARRIER);
......
......@@ -96,7 +96,6 @@ bool AccessorInfo::HasExpectedReceiverType() {
return expected_receiver_type().IsFunctionTemplateInfo();
}
TQ_SMI_ACCESSORS(InterceptorInfo, flags)
BOOL_ACCESSORS(InterceptorInfo, flags, can_intercept_symbols,
kCanInterceptSymbolsBit)
BOOL_ACCESSORS(InterceptorInfo, flags, all_can_read, kAllCanReadBit)
......
......@@ -111,9 +111,6 @@ class InterceptorInfo
DECL_BOOLEAN_ACCESSORS(is_named)
DECL_BOOLEAN_ACCESSORS(has_no_side_effect)
inline int flags() const;
inline void set_flags(int flags);
// Dispatched behavior.
DECL_PRINTER(InterceptorInfo)
......
......@@ -24,8 +24,6 @@ TQ_OBJECT_CONSTRUCTORS_IMPL(AliasedArgumentsEntry)
CAST_ACCESSOR(SloppyArgumentsElements)
TQ_SMI_ACCESSORS(AliasedArgumentsEntry, aliased_context_slot)
DEF_GETTER(SloppyArgumentsElements, context, Context) {
return TaggedField<Context>::load(isolate, *this,
OffsetOfElementAt(kContextIndex));
......
......@@ -113,9 +113,6 @@ class AliasedArgumentsEntry
: public TorqueGeneratedAliasedArgumentsEntry<AliasedArgumentsEntry,
Struct> {
public:
inline int aliased_context_slot() const;
inline void set_aliased_context_slot(int count);
// Dispatched behavior.
DECL_PRINTER(AliasedArgumentsEntry)
......
......@@ -25,9 +25,6 @@ TQ_OBJECT_CONSTRUCTORS_IMPL(DebugInfo)
NEVER_READ_ONLY_SPACE_IMPL(DebugInfo)
TQ_SMI_ACCESSORS(DebugInfo, flags)
TQ_SMI_ACCESSORS(DebugInfo, debugger_hints)
BIT_FIELD_ACCESSORS(DebugInfo, debugger_hints, side_effect_state,
DebugInfo::SideEffectStateBits)
BIT_FIELD_ACCESSORS(DebugInfo, debugger_hints, debug_is_blackboxed,
......@@ -37,10 +34,6 @@ BIT_FIELD_ACCESSORS(DebugInfo, debugger_hints, computed_debug_is_blackboxed,
BIT_FIELD_ACCESSORS(DebugInfo, debugger_hints, debugging_id,
DebugInfo::DebuggingIdBits)
TQ_SMI_ACCESSORS(BreakPointInfo, source_position)
TQ_SMI_ACCESSORS(BreakPoint, id)
bool DebugInfo::HasInstrumentedBytecodeArray() {
DCHECK_EQ(debug_bytecode_array().IsBytecodeArray(),
original_bytecode_array().IsBytecodeArray());
......
......@@ -30,12 +30,6 @@ class DebugInfo : public TorqueGeneratedDebugInfo<DebugInfo, Struct> {
DEFINE_TORQUE_GENERATED_DEBUG_INFO_FLAGS()
using Flags = base::Flags<Flag>;
// A bitfield that lists uses of the current instance.
DECL_INT_ACCESSORS(flags)
// Bit field containing various information collected for debugging.
DECL_INT_ACCESSORS(debugger_hints)
// DebugInfo can be detached from the SharedFunctionInfo iff it is empty.
bool IsEmpty() const;
......@@ -150,9 +144,6 @@ class DebugInfo : public TorqueGeneratedDebugInfo<DebugInfo, Struct> {
class BreakPointInfo
: public TorqueGeneratedBreakPointInfo<BreakPointInfo, Struct> {
public:
// The position in the source for the break position.
DECL_INT_ACCESSORS(source_position)
// Removes a break point.
static void ClearBreakPoint(Isolate* isolate, Handle<BreakPointInfo> info,
Handle<BreakPoint> break_point);
......@@ -208,8 +199,6 @@ class CoverageInfo
// Holds breakpoint related information. This object is used by inspector.
class BreakPoint : public TorqueGeneratedBreakPoint<BreakPoint, Struct> {
public:
DECL_INT_ACCESSORS(id)
TQ_OBJECT_CONSTRUCTORS(BreakPoint)
};
......
......@@ -37,6 +37,7 @@ bitfield struct DebuggerHints extends uint31 {
@generateCppClass
extern class DebugInfo extends Struct {
shared: SharedFunctionInfo;
// Bit field containing various information collected for debugging.
debugger_hints: SmiTagged<DebuggerHints>;
// Script field from shared function info.
script: Undefined|Script;
......@@ -48,6 +49,7 @@ extern class DebugInfo extends Struct {
debug_bytecode_array: Undefined|BytecodeArray;
// Fixed array holding status information for each active break point.
break_points: FixedArray;
// A bitfield that lists uses of the current instance.
flags: SmiTagged<DebugInfoFlags>;
coverage_info: CoverageInfo|Undefined;
}
......
......@@ -16,7 +16,6 @@
namespace v8 {
namespace internal {
TQ_SMI_ACCESSORS(EmbedderDataArray, length)
TQ_OBJECT_CONSTRUCTORS_IMPL(EmbedderDataArray)
......
......@@ -23,10 +23,6 @@ namespace internal {
class EmbedderDataArray
: public TorqueGeneratedEmbedderDataArray<EmbedderDataArray, HeapObject> {
public:
// [length]: length of the array in an embedder data slots.
V8_INLINE int length() const;
V8_INLINE void set_length(int value);
// TODO(v8:8989): [torque] Support marker constants.
static const int kHeaderSize = kSize;
......
......@@ -4,5 +4,6 @@
@generateCppClass
extern class EmbedderDataArray extends HeapObject {
// length of the array in an embedder data slots.
length: Smi;
}
......@@ -21,11 +21,6 @@ TQ_OBJECT_CONSTRUCTORS_IMPL(JSAsyncFunctionObject)
TQ_OBJECT_CONSTRUCTORS_IMPL(JSAsyncGeneratorObject)
TQ_OBJECT_CONSTRUCTORS_IMPL(AsyncGeneratorRequest)
TQ_SMI_ACCESSORS(JSGeneratorObject, resume_mode)
TQ_SMI_ACCESSORS(JSGeneratorObject, continuation)
TQ_SMI_ACCESSORS(AsyncGeneratorRequest, resume_mode)
bool JSGeneratorObject::is_suspended() const {
DCHECK_LT(kGeneratorExecuting, 0);
DCHECK_LT(kGeneratorClosed, 0);
......@@ -40,8 +35,6 @@ bool JSGeneratorObject::is_executing() const {
return continuation() == kGeneratorExecuting;
}
TQ_SMI_ACCESSORS(JSAsyncGeneratorObject, is_awaiting)
} // namespace internal
} // namespace v8
......
......@@ -20,17 +20,8 @@ class JSPromise;
class JSGeneratorObject
: public TorqueGeneratedJSGeneratorObject<JSGeneratorObject, JSObject> {
public:
// [resume_mode]: The most recent resume mode.
enum ResumeMode { kNext, kReturn, kThrow };
DECL_INT_ACCESSORS(resume_mode)
// [continuation]
//
// A positive value indicates a suspended generator. The special
// kGeneratorExecuting and kGeneratorClosed values indicate that a generator
// cannot be resumed.
inline int continuation() const;
inline void set_continuation(int continuation);
inline bool is_closed() const;
inline bool is_executing() const;
inline bool is_suspended() const;
......@@ -68,10 +59,6 @@ class JSAsyncGeneratorObject
DECL_VERIFIER(JSAsyncGeneratorObject)
DECL_PRINTER(JSAsyncGeneratorObject)
// [is_awaiting]
// Whether or not the generator is currently awaiting.
DECL_INT_ACCESSORS(is_awaiting)
TQ_OBJECT_CONSTRUCTORS(JSAsyncGeneratorObject)
};
......@@ -79,8 +66,6 @@ class AsyncGeneratorRequest
: public TorqueGeneratedAsyncGeneratorRequest<AsyncGeneratorRequest,
Struct> {
public:
DECL_INT_ACCESSORS(resume_mode)
DECL_PRINTER(AsyncGeneratorRequest)
DECL_VERIFIER(AsyncGeneratorRequest)
......
......@@ -14,7 +14,12 @@ extern class JSGeneratorObject extends JSObject {
// suspended generator.
input_or_debug_pos: Object;
// The most recent resume mode.
resume_mode: Smi;
// A positive value indicates a suspended generator. The special
// kGeneratorExecuting and kGeneratorClosed values indicate that a generator
// cannot be resumed.
continuation: Smi;
// Saved interpreter register file.
......@@ -31,6 +36,7 @@ extern class JSAsyncGeneratorObject extends JSGeneratorObject {
// Pointer to the head of a singly linked list of AsyncGeneratorRequest, or
// undefined.
queue: HeapObject;
// Whether or not the generator is currently awaiting.
is_awaiting: Smi;
}
......
......@@ -1026,8 +1026,6 @@ inline int JSGlobalProxy::SizeWithEmbedderFields(int embedder_field_count) {
ACCESSORS(JSIteratorResult, value, Object, kValueOffset)
ACCESSORS(JSIteratorResult, done, Object, kDoneOffset)
TQ_SMI_ACCESSORS(JSStringIterator, index)
// If the fast-case backing storage takes up much more memory than a dictionary
// backing storage would, the object should have slow elements.
// static
......
......@@ -1443,10 +1443,6 @@ class JSStringIterator
DECL_PRINTER(JSStringIterator)
DECL_VERIFIER(JSStringIterator)
// [index]: The [[StringIteratorNextIndex]] slot.
inline int index() const;
inline void set_index(int value);
TQ_OBJECT_CONSTRUCTORS(JSStringIterator)
};
......
......@@ -18,7 +18,6 @@ namespace internal {
TQ_OBJECT_CONSTRUCTORS_IMPL(JSPromise)
TQ_SMI_ACCESSORS(JSPromise, flags)
BOOL_ACCESSORS(JSPromise, flags, has_handler, kHasHandlerBit)
BOOL_ACCESSORS(JSPromise, flags, handled_hint, kHandledHintBit)
......
......@@ -32,8 +32,6 @@ class JSPromise : public TorqueGeneratedJSPromise<JSPromise, JSObject> {
// [reactions]: Checks that the promise is pending and returns the reactions.
inline Object reactions() const;
DECL_INT_ACCESSORS(flags)
// [has_handler]: Whether this promise has a reject handler or not.
DECL_BOOLEAN_ACCESSORS(has_handler)
......
......@@ -17,7 +17,6 @@ namespace internal {
TQ_OBJECT_CONSTRUCTORS_IMPL(JSRegExpStringIterator)
TQ_SMI_ACCESSORS(JSRegExpStringIterator, flags)
BOOL_ACCESSORS(JSRegExpStringIterator, flags, done, kDoneBit)
BOOL_ACCESSORS(JSRegExpStringIterator, flags, global, kGlobalBit)
BOOL_ACCESSORS(JSRegExpStringIterator, flags, unicode, kUnicodeBit)
......
......@@ -17,8 +17,6 @@ class JSRegExpStringIterator
: public TorqueGeneratedJSRegExpStringIterator<JSRegExpStringIterator,
JSObject> {
public:
DECL_INT_ACCESSORS(flags)
// [boolean]: The [[Done]] internal property.
DECL_BOOLEAN_ACCESSORS(done)
......
......@@ -128,8 +128,6 @@ ACCESSORS(ClassBoilerplate, instance_computed_properties, FixedArray,
TQ_OBJECT_CONSTRUCTORS_IMPL(ArrayBoilerplateDescription)
TQ_SMI_ACCESSORS(ArrayBoilerplateDescription, flags)
ElementsKind ArrayBoilerplateDescription::elements_kind() const {
return static_cast<ElementsKind>(flags());
}
......
......@@ -70,7 +70,6 @@ class ArrayBoilerplateDescription
void BriefPrintDetails(std::ostream& os);
private:
DECL_INT_ACCESSORS(flags)
TQ_OBJECT_CONSTRUCTORS(ArrayBoilerplateDescription)
};
......
......@@ -36,12 +36,8 @@ ACCESSORS(Module, exception, Object, kExceptionOffset)
SMI_ACCESSORS(Module, status, kStatusOffset)
SMI_ACCESSORS(Module, hash, kHashOffset)
TQ_SMI_ACCESSORS(SourceTextModule, dfs_index)
TQ_SMI_ACCESSORS(SourceTextModule, dfs_ancestor_index)
TQ_SMI_ACCESSORS(SourceTextModule, flags)
BOOL_ACCESSORS(SourceTextModule, flags, async, kAsyncBit)
BOOL_ACCESSORS(SourceTextModule, flags, async_evaluating, kAsyncEvaluatingBit)
TQ_SMI_ACCESSORS(SourceTextModule, pending_async_dependencies)
ACCESSORS(SourceTextModule, async_parent_modules, ArrayList,
kAsyncParentModulesOffset)
ACCESSORS(SourceTextModule, top_level_capability, HeapObject,
......@@ -53,11 +49,6 @@ SourceTextModuleInfo SourceTextModule::info() const {
: GetSharedFunctionInfo().scope_info().ModuleDescriptorInfo();
}
TQ_SMI_ACCESSORS(SourceTextModuleInfoEntry, module_request)
TQ_SMI_ACCESSORS(SourceTextModuleInfoEntry, cell_index)
TQ_SMI_ACCESSORS(SourceTextModuleInfoEntry, beg_pos)
TQ_SMI_ACCESSORS(SourceTextModuleInfoEntry, end_pos)
OBJECT_CONSTRUCTORS_IMPL(SourceTextModuleInfo, FixedArray)
CAST_ACCESSOR(SourceTextModuleInfo)
......
......@@ -229,14 +229,6 @@
TaggedField<Smi, offset>::Relaxed_Store(*this, Smi::FromInt(value)); \
}
#define TQ_SMI_ACCESSORS(holder, name) \
int holder::name() const { \
return TorqueGenerated##holder<holder, Super>::name().value(); \
} \
void holder::set_##name(int value) { \
TorqueGenerated##holder<holder, Super>::set_##name(Smi::FromInt(value)); \
}
#define BOOL_GETTER(holder, field, name, offset) \
bool holder::name() const { return BooleanBit::get(field(), offset); }
......
......@@ -25,13 +25,9 @@ void Oddball::set_to_number_raw_as_bits(uint64_t bits) {
base::WriteUnalignedValue<uint64_t>(field_address(kToNumberRawOffset), bits);
}
byte Oddball::kind() const {
return Smi::ToInt(TorqueGeneratedOddball::kind());
}
byte Oddball::kind() const { return TorqueGeneratedOddball::kind(); }
void Oddball::set_kind(byte value) {
TorqueGeneratedOddball::set_kind(Smi::FromInt(value));
}
void Oddball::set_kind(byte value) { TorqueGeneratedOddball::set_kind(value); }
// static
Handle<Object> Oddball::ToNumber(Isolate* isolate, Handle<Oddball> input) {
......
......@@ -355,7 +355,7 @@ Handle<PropertyDescriptorObject> PropertyDescriptor::ToPropertyDescriptorObject(
PropertyDescriptorObject::HasGetBit::encode(has_get()) |
PropertyDescriptorObject::HasSetBit::encode(has_set());
obj->set_flags(Smi::FromInt(flags));
obj->set_flags(flags);
if (has_value()) obj->set_value(*value_);
if (has_get()) obj->set_get(*get_);
......
......@@ -85,13 +85,6 @@ class SourceTextModule
inline void IncrementPendingAsyncDependencies();
inline void DecrementPendingAsyncDependencies();
// TODO(neis): Don't store those in the module object?
DECL_INT_ACCESSORS(dfs_index)
DECL_INT_ACCESSORS(dfs_ancestor_index)
// Storage for boolean flags.
DECL_INT_ACCESSORS(flags)
// Bits for flags.
static const int kAsyncBit = 0;
static const int kAsyncEvaluatingBit = 1;
......@@ -108,9 +101,6 @@ class SourceTextModule
// for cycle roots.
DECL_ACCESSORS(top_level_capability, HeapObject)
// The number of currently evaluating async dependencies of this module.
DECL_INT_ACCESSORS(pending_async_dependencies)
// The parent modules of a given async dependency, use async_parent_modules()
// to retrieve the ArrayList representation.
DECL_ACCESSORS(async_parent_modules, ArrayList)
......@@ -248,11 +238,6 @@ class SourceTextModuleInfoEntry
DECL_PRINTER(SourceTextModuleInfoEntry)
DECL_VERIFIER(SourceTextModuleInfoEntry)
DECL_INT_ACCESSORS(module_request)
DECL_INT_ACCESSORS(cell_index)
DECL_INT_ACCESSORS(beg_pos)
DECL_INT_ACCESSORS(end_pos)
template <typename LocalIsolate>
static Handle<SourceTextModuleInfoEntry> New(
LocalIsolate* isolate, Handle<PrimitiveHeapObject> export_name,
......
......@@ -28,11 +28,17 @@ extern class SourceTextModule extends Module {
// Lazily initialized on first access. It's the hole before first access and
// a JSObject afterwards.
import_meta: TheHole|JSObject;
async_parent_modules: ArrayList;
top_level_capability: JSPromise|Undefined;
// TODO(neis): Don't store those in the module object?
dfs_index: Smi;
dfs_ancestor_index: Smi;
// The number of currently evaluating async dependencies of this module.
pending_async_dependencies: Smi;
flags: Smi;
}
......
......@@ -53,9 +53,6 @@ BOOL_ACCESSORS(StackFrameInfo, flag, is_promise_all, kIsPromiseAllBit)
TQ_OBJECT_CONSTRUCTORS_IMPL(StackTraceFrame)
NEVER_READ_ONLY_SPACE_IMPL(StackTraceFrame)
TQ_SMI_ACCESSORS(StackTraceFrame, frame_index)
TQ_SMI_ACCESSORS(StackTraceFrame, id)
} // namespace internal
} // namespace v8
......
......@@ -76,8 +76,6 @@ class StackTraceFrame
: public TorqueGeneratedStackTraceFrame<StackTraceFrame, Struct> {
public:
NEVER_READ_ONLY_SPACE
DECL_INT_ACCESSORS(frame_index)
DECL_INT_ACCESSORS(id)
// Dispatched behavior.
DECL_PRINTER(StackTraceFrame)
......
......@@ -582,8 +582,6 @@ void SlicedString::set_parent(String parent, WriteBarrierMode mode) {
TorqueGeneratedSlicedString<SlicedString, Super>::set_parent(parent, mode);
}
TQ_SMI_ACCESSORS(SlicedString, offset)
Object ConsString::unchecked_first() {
return TaggedField<Object, kFirstOffset>::load(*this);
}
......
......@@ -682,7 +682,6 @@ class SlicedString : public TorqueGeneratedSlicedString<SlicedString, String> {
public:
inline void set_parent(String parent,
WriteBarrierMode mode = UPDATE_WRITE_BARRIER);
DECL_INT_ACCESSORS(offset)
// Dispatched behavior.
V8_EXPORT_PRIVATE uint16_t Get(int index);
......
......@@ -34,9 +34,6 @@ void Struct::InitializeBody(int object_size) {
}
}
TQ_SMI_ACCESSORS(ClassPositions, start)
TQ_SMI_ACCESSORS(ClassPositions, end)
Object AccessorPair::get(AccessorComponent component) {
return component == ACCESSOR_GETTER ? getter() : setter();
}
......
......@@ -68,9 +68,6 @@ class AccessorPair : public TorqueGeneratedAccessorPair<AccessorPair, Struct> {
class ClassPositions
: public TorqueGeneratedClassPositions<ClassPositions, Struct> {
public:
DECL_INT_ACCESSORS(start)
DECL_INT_ACCESSORS(end)
// Dispatched behavior.
DECL_PRINTER(ClassPositions)
void BriefPrintDetails(std::ostream& os);
......
......@@ -18,8 +18,6 @@ namespace internal {
TQ_OBJECT_CONSTRUCTORS_IMPL(TemplateObjectDescription)
TQ_OBJECT_CONSTRUCTORS_IMPL(CachedTemplateObject)
TQ_SMI_ACCESSORS(CachedTemplateObject, slot_id)
} // namespace internal
} // namespace v8
......
......@@ -20,8 +20,6 @@ namespace internal {
class CachedTemplateObject final
: public TorqueGeneratedCachedTemplateObject<CachedTemplateObject, Struct> {
public:
DECL_INT_ACCESSORS(slot_id)
static Handle<CachedTemplateObject> New(Isolate* isolate, int slot_id,
Handle<JSArray> template_object,
Handle<HeapObject> next);
......
......@@ -43,7 +43,9 @@ extern class FunctionTemplateInfo extends TemplateInfo {
// undefined.
rare_data: HeapObject;
shared_function_info: Object;
// Internal field to store a flag bitfield.
flag: Smi;
// "length" property of the final JSFunction.
length: Smi;
// Either the_hole or a private symbol. Used to cache the result on
// the receiver under the the cached_property_name when this
......
......@@ -24,9 +24,6 @@ TQ_OBJECT_CONSTRUCTORS_IMPL(FunctionTemplateRareData)
NEVER_READ_ONLY_SPACE_IMPL(TemplateInfo)
TQ_SMI_ACCESSORS(TemplateInfo, number_of_properties)
TQ_SMI_ACCESSORS(FunctionTemplateInfo, length)
BOOL_ACCESSORS(FunctionTemplateInfo, flag, undetectable, kUndetectableBit)
BOOL_ACCESSORS(FunctionTemplateInfo, flag, needs_access_check,
kNeedsAccessCheckBit)
......@@ -37,7 +34,6 @@ BOOL_ACCESSORS(FunctionTemplateInfo, flag, remove_prototype,
BOOL_ACCESSORS(FunctionTemplateInfo, flag, do_not_cache, kDoNotCacheBit)
BOOL_ACCESSORS(FunctionTemplateInfo, flag, accept_any_receiver,
kAcceptAnyReceiver)
TQ_SMI_ACCESSORS(FunctionTemplateInfo, flag)
// static
FunctionTemplateRareData FunctionTemplateInfo::EnsureFunctionTemplateRareData(
......
......@@ -16,7 +16,6 @@ namespace internal {
class TemplateInfo : public TorqueGeneratedTemplateInfo<TemplateInfo, Struct> {
public:
NEVER_READ_ONLY_SPACE
DECL_INT_ACCESSORS(number_of_properties)
static const int kFastTemplateInstantiationsCacheSize = 1 * KB;
......@@ -87,12 +86,6 @@ class FunctionTemplateInfo
DECL_RARE_ACCESSORS(c_signature, CSignature, Object)
#undef DECL_RARE_ACCESSORS
// Internal field to store a flag bitfield.
DECL_INT_ACCESSORS(flag)
// "length" property of the final JSFunction.
DECL_INT_ACCESSORS(length)
// Begin flag bits ---------------------
DECL_BOOLEAN_ACCESSORS(undetectable)
......
......@@ -3,15 +3,19 @@
// found in the LICENSE file.
#include <algorithm>
#include <string>
#include "src/base/optional.h"
#include "src/common/globals.h"
#include "src/torque/csa-generator.h"
#include "src/torque/declaration-visitor.h"
#include "src/torque/global-context.h"
#include "src/torque/implementation-visitor.h"
#include "src/torque/parameter-difference.h"
#include "src/torque/server-data.h"
#include "src/torque/type-inference.h"
#include "src/torque/type-visitor.h"
#include "src/torque/types.h"
namespace v8 {
namespace internal {
......@@ -3446,8 +3450,7 @@ void CppClassGenerator::GenerateClass() {
bool first = true;
for (const Field& field : *index_fields) {
if (!first) hdr_ << ", ";
hdr_ << field.name_and_type.type->HandlifiedCppTypeName() << " "
<< field.name_and_type.name;
hdr_ << "int " << field.name_and_type.name;
first = false;
}
hdr_ << ") {\n";
......@@ -3462,19 +3465,8 @@ void CppClassGenerator::GenerateClass() {
*ExtractSimpleFieldArraySize(*type_, *field.index);
size_t field_size = 0;
std::tie(field_size, std::ignore) = field.GetFieldSizeInformation();
hdr_ << " size += ";
auto index_field = std::find_if(
index_fields->begin(), index_fields->end(),
[&](const Field& field) {
return field.name_and_type.name == index_name_and_type.name;
});
if (index_field->name_and_type.type->IsSubtypeOf(
TypeOracle::GetSmiType())) {
hdr_ << "Smi::ToInt(" << index_name_and_type.name << ")";
} else {
hdr_ << index_name_and_type.name;
}
hdr_ << " * " << field_size << ";\n";
hdr_ << " size += " << index_name_and_type.name << " * "
<< field_size << ";\n";
}
}
hdr_ << " return size;\n";
......@@ -3492,7 +3484,7 @@ void CppClassGenerator::GenerateClass() {
// int-based.
if (field.aggregate == TypeOracle::GetFixedArrayBaseType() &&
field.name_and_type.name == "length") {
hdr_ << "Smi::FromInt(o.synchronized_length())";
hdr_ << "o.synchronized_length()";
} else {
hdr_ << "o." << field.name_and_type.name << "()";
}
......@@ -3634,7 +3626,8 @@ void CppClassGenerator::GenerateFieldAccessorForUntagged(const Field& f) {
void CppClassGenerator::GenerateFieldAccessorForSmi(const Field& f) {
DCHECK(f.name_and_type.type->IsSubtypeOf(TypeOracle::GetSmiType()));
const std::string type = "Smi";
// Follow the convention to create Smi accessors with type int.
const std::string type = "int";
const std::string& name = f.name_and_type.name;
const std::string offset = "k" + CamelifyString(name) + "Offset";
......@@ -3656,10 +3649,11 @@ void CppClassGenerator::GenerateFieldAccessorForSmi(const Field& f) {
inl_ << ") const {\n";
if (f.index) {
inl_ << " int offset = " << offset << " + i * kTaggedSize;\n";
inl_ << " return this->template ReadField<Smi>(offset);\n";
inl_ << " return this->template ReadField<Smi>(offset).value();\n";
inl_ << "}\n";
} else {
inl_ << " return TaggedField<Smi, " << offset << ">::load(*this);\n";
inl_ << " return TaggedField<Smi, " << offset
<< ">::load(*this).value();\n";
inl_ << "}\n";
}
......@@ -3669,12 +3663,11 @@ void CppClassGenerator::GenerateFieldAccessorForSmi(const Field& f) {
inl_ << "int i, ";
}
inl_ << type << " value) {\n";
inl_ << " DCHECK(value.IsSmi());\n";
if (f.index) {
inl_ << " int offset = " << offset << " + i * kTaggedSize;\n";
inl_ << " WRITE_FIELD(*this, offset, value);\n";
inl_ << " WRITE_FIELD(*this, offset, Smi::FromInt(value));\n";
} else {
inl_ << " WRITE_FIELD(*this, " << offset << ", value);\n";
inl_ << " WRITE_FIELD(*this, " << offset << ", Smi::FromInt(value));\n";
}
inl_ << "}\n\n";
}
......@@ -4023,8 +4016,7 @@ void GeneratePrintDefinitionsForClass(std::ostream& impl, const ClassType* type,
for (const Field& f : aggregate_type->fields()) {
if (f.name_and_type.name == "map") continue;
if (!f.index.has_value()) {
if ((aggregate_type == TypeOracle::GetFixedArrayBaseType() &&
f.name_and_type.name == "length") ||
if (f.name_and_type.type->IsSubtypeOf(TypeOracle::GetSmiType()) ||
!f.name_and_type.type->IsSubtypeOf(TypeOracle::GetTaggedType())) {
impl << " os << \"\\n - " << f.name_and_type.name << ": \" << ";
if (f.name_and_type.type->StructSupertype()) {
......
......@@ -70,8 +70,8 @@ std::string Type::SimpleName() const {
// TODO(danno): HandlifiedCppTypeName should be used universally in Torque
// where the C++ type of a Torque object is required.
std::string Type::HandlifiedCppTypeName() const {
if (IsSubtypeOf(TypeOracle::GetTaggedType()) &&
!IsSubtypeOf(TypeOracle::GetSmiType())) {
if (IsSubtypeOf(TypeOracle::GetSmiType())) return "int";
if (IsSubtypeOf(TypeOracle::GetTaggedType())) {
base::Optional<const ClassType*> class_type = ClassSupertype();
std::string type =
class_type ? (*class_type)->GetGeneratedTNodeTypeName() : "Object";
......
......@@ -404,9 +404,6 @@ wasm::ValueType WasmTableObject::type() {
bool WasmMemoryObject::has_maximum_pages() { return maximum_pages() >= 0; }
// WasmExceptionTag
TQ_SMI_ACCESSORS(WasmExceptionTag, index)
// AsmWasmData
ACCESSORS(AsmWasmData, managed_native_module, Managed<wasm::NativeModule>,
kManagedNativeModuleOffset)
......
......@@ -949,11 +949,6 @@ class WasmExceptionTag
V8_EXPORT_PRIVATE static Handle<WasmExceptionTag> New(Isolate* isolate,
int index);
// Note that this index is only useful for debugging purposes and it is not
// unique across modules. The GC however does not allow objects without at
// least one field, hence this also serves as a padding field for now.
DECL_INT_ACCESSORS(index)
DECL_PRINTER(WasmExceptionTag)
TQ_OBJECT_CONSTRUCTORS(WasmExceptionTag)
......
......@@ -51,6 +51,9 @@ extern class WasmDebugInfo extends Struct {
@generateCppClass
extern class WasmExceptionTag extends Struct {
// Note that this index is only useful for debugging purposes and it is not
// unique across modules. The GC however does not allow objects without at
// least one field, hence this also serves as a padding field for now.
index: Smi;
}
......
......@@ -748,7 +748,7 @@ TEST(TestFullyGeneratedClassFromCpp) {
Handle<ExportedSubClass>::cast(ft.Call().ToHandleChecked());
CHECK_EQ(result->c_field(), 7);
CHECK_EQ(result->d_field(), 8);
CHECK_EQ(Smi::ToInt(result->e_field()), 9);
CHECK_EQ(result->e_field(), 9);
}
TEST(TestFullyGeneratedClassWithElements) {
......
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