Commit 267b067b authored by Seth Brenith's avatar Seth Brenith Committed by V8 LUCI CQ

[torque] Get rid of @generatePrint annotation

I'm trying to remove annotations and make behavior more consistent. For
@generatePrint, there are two options: either generate printers for
every extern class, or never generate printers for extern classes. This
change implements the option of always generating printers. Classes that
require custom printing can easily hide the generated printer by using
DECL_PRINTER. This causes the generated file
gen/torque-generated/objects-printer.cc to grow to 1600 lines, including
many functions that are never used, but I think the consistency benefit
outweighs a little more compilation time on one file. This change also
removes custom printers in cases where the generated printer includes
all of the same content.

If folks would prefer the option to never generate printers, I'm open to
doing that instead. I like the notion that generating more code could
reduce the friction of adding new classes and thereby encourage people
to define precise types rather than using FixedArrays, but the current
implementation of generated printers is limited, and many printers have
been customized to show the data that matters the most. Unlike verifiers
and body descriptors, there are no correctness or safety concerns with
hand-written printers.

Some bugs showed up once we start generating printers for everything,
and this change fixes them:
- Printers incorrectly included ungettable fields like padding
- Printers called getters which might be hidden by hand-written classes
- The generated getter for Map::instance_type used
  ReadField<InstanceType>, which is not an arithmetic type since it's an
  enum

One more tiny drive-by fix: added a missing newline in the printers for
JSMap and JSSet.

Bug: v8:7793
Change-Id: Ib9e9575fbcb57879935ff18bf4db49fe276d2966
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3172190Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/main@{#77152}
parent d5625e35
......@@ -1342,24 +1342,15 @@ void JSDate::JSDatePrint(std::ostream& os) {
JSObjectPrintBody(os, *this);
}
void JSProxy::JSProxyPrint(std::ostream& os) {
PrintHeader(os, "JSProxy");
os << "\n - target: ";
target().ShortPrint(os);
os << "\n - handler: ";
handler().ShortPrint(os);
os << "\n";
}
void JSSet::JSSetPrint(std::ostream& os) {
JSObjectPrintHeader(os, *this, "JSSet");
os << " - table: " << Brief(table());
os << "\n - table: " << Brief(table());
JSObjectPrintBody(os, *this);
}
void JSMap::JSMapPrint(std::ostream& os) {
JSObjectPrintHeader(os, *this, "JSMap");
os << " - table: " << Brief(table());
os << "\n - table: " << Brief(table());
JSObjectPrintBody(os, *this);
}
......@@ -1379,18 +1370,6 @@ void JSMapIterator::JSMapIteratorPrint(std::ostream& os) {
JSCollectionIteratorPrint(os, "JSMapIterator");
}
void WeakCell::WeakCellPrint(std::ostream& os) {
PrintHeader(os, "WeakCell");
os << "\n - finalization_registry: " << Brief(finalization_registry());
os << "\n - target: " << Brief(target());
os << "\n - holdings: " << Brief(holdings());
os << "\n - prev: " << Brief(prev());
os << "\n - next: " << Brief(next());
os << "\n - unregister_token: " << Brief(unregister_token());
os << "\n - key_list_prev: " << Brief(key_list_prev());
os << "\n - key_list_next: " << Brief(key_list_next());
}
void JSWeakRef::JSWeakRefPrint(std::ostream& os) {
JSObjectPrintHeader(os, *this, "JSWeakRef");
os << "\n - target: " << Brief(target());
......@@ -1680,67 +1659,6 @@ void Foreign::ForeignPrint(std::ostream& os) {
os << "\n";
}
void CallbackTask::CallbackTaskPrint(std::ostream& os) {
PrintHeader(os, "CallbackTask");
os << "\n - callback: " << Brief(callback());
os << "\n - data: " << Brief(data());
os << "\n";
}
void CallableTask::CallableTaskPrint(std::ostream& os) {
PrintHeader(os, "CallableTask");
os << "\n - context: " << Brief(context());
os << "\n - callable: " << Brief(callable());
os << "\n";
}
void PromiseFulfillReactionJobTask::PromiseFulfillReactionJobTaskPrint(
std::ostream& os) {
PrintHeader(os, "PromiseFulfillReactionJobTask");
os << "\n - argument: " << Brief(argument());
os << "\n - context: " << Brief(context());
os << "\n - handler: " << Brief(handler());
os << "\n - promise_or_capability: " << Brief(promise_or_capability());
os << "\n";
}
void PromiseRejectReactionJobTask::PromiseRejectReactionJobTaskPrint(
std::ostream& os) {
PrintHeader(os, "PromiseRejectReactionJobTask");
os << "\n - argument: " << Brief(argument());
os << "\n - context: " << Brief(context());
os << "\n - handler: " << Brief(handler());
os << "\n - promise_or_capability: " << Brief(promise_or_capability());
os << "\n";
}
void PromiseResolveThenableJobTask::PromiseResolveThenableJobTaskPrint(
std::ostream& os) {
PrintHeader(os, "PromiseResolveThenableJobTask");
os << "\n - context: " << Brief(context());
os << "\n - promise_to_resolve: " << Brief(promise_to_resolve());
os << "\n - then: " << Brief(then());
os << "\n - thenable: " << Brief(thenable());
os << "\n";
}
void PromiseCapability::PromiseCapabilityPrint(std::ostream& os) {
PrintHeader(os, "PromiseCapability");
os << "\n - promise: " << Brief(promise());
os << "\n - resolve: " << Brief(resolve());
os << "\n - reject: " << Brief(reject());
os << "\n";
}
void PromiseReaction::PromiseReactionPrint(std::ostream& os) {
PrintHeader(os, "PromiseReaction");
os << "\n - next: " << Brief(next());
os << "\n - reject_handler: " << Brief(reject_handler());
os << "\n - fulfill_handler: " << Brief(fulfill_handler());
os << "\n - promise_or_capability: " << Brief(promise_or_capability());
os << "\n";
}
void AsyncGeneratorRequest::AsyncGeneratorRequestPrint(std::ostream& os) {
PrintHeader(os, "AsyncGeneratorRequest");
const char* mode = "Invalid!";
......@@ -1761,19 +1679,6 @@ void AsyncGeneratorRequest::AsyncGeneratorRequestPrint(std::ostream& os) {
os << "\n";
}
void SourceTextModuleInfoEntry::SourceTextModuleInfoEntryPrint(
std::ostream& os) {
PrintHeader(os, "SourceTextModuleInfoEntry");
os << "\n - export_name: " << Brief(export_name());
os << "\n - local_name: " << Brief(local_name());
os << "\n - import_name: " << Brief(import_name());
os << "\n - module_request: " << module_request();
os << "\n - cell_index: " << cell_index();
os << "\n - beg_pos: " << beg_pos();
os << "\n - end_pos: " << end_pos();
os << "\n";
}
static void PrintModuleFields(Module module, std::ostream& os) {
os << "\n - exports: " << Brief(module.exports());
os << "\n - status: " << module.status();
......@@ -1804,14 +1709,6 @@ void SourceTextModule::SourceTextModulePrint(std::ostream& os) {
os << "\n";
}
void SyntheticModule::SyntheticModulePrint(std::ostream& os) {
PrintHeader(os, "SyntheticModule");
PrintModuleFields(*this, os);
os << "\n - export_names: " << Brief(export_names());
os << "\n - name: " << Brief(name());
os << "\n";
}
void JSModuleNamespace::JSModuleNamespacePrint(std::ostream& os) {
JSObjectPrintHeader(os, *this, "JSModuleNamespace");
os << "\n - module: " << Brief(module());
......@@ -1828,13 +1725,6 @@ void PrototypeInfo::PrototypeInfoPrint(std::ostream& os) {
os << "\n";
}
void ClassPositions::ClassPositionsPrint(std::ostream& os) {
PrintHeader(os, "ClassPositions");
os << "\n - start position: " << start();
os << "\n - end position: " << end();
os << "\n";
}
void ArrayBoilerplateDescription::ArrayBoilerplateDescriptionPrint(
std::ostream& os) {
PrintHeader(os, "ArrayBoilerplateDescription");
......@@ -1843,15 +1733,6 @@ void ArrayBoilerplateDescription::ArrayBoilerplateDescriptionPrint(
os << "\n";
}
void RegExpBoilerplateDescription::RegExpBoilerplateDescriptionPrint(
std::ostream& os) {
PrintHeader(os, "RegExpBoilerplateDescription");
os << "\n - data: " << Brief(data());
os << "\n - source: " << Brief(source());
os << "\n - flags: " << flags();
os << "\n";
}
#if V8_ENABLE_WEBASSEMBLY
void AsmWasmData::AsmWasmDataPrint(std::ostream& os) {
PrintHeader(os, "AsmWasmData");
......@@ -1955,12 +1836,6 @@ void WasmArray::WasmArrayPrint(std::ostream& os) {
os << "\n";
}
void WasmExceptionTag::WasmExceptionTagPrint(std::ostream& os) {
PrintHeader(os, "WasmExceptionTag");
os << "\n - index: " << index();
os << "\n";
}
void WasmInstanceObject::WasmInstanceObjectPrint(std::ostream& os) {
JSObjectPrintHeader(os, *this, "WasmInstanceObject");
os << "\n - module_object: " << Brief(module_object());
......@@ -2052,15 +1927,6 @@ void WasmModuleObject::WasmModuleObjectPrint(std::ostream& os) {
os << "\n";
}
void WasmTableObject::WasmTableObjectPrint(std::ostream& os) {
PrintHeader(os, "WasmTableObject");
os << "\n - elements: " << Brief(elements());
os << "\n - maximum_length: " << Brief(maximum_length());
os << "\n - dispatch_tables: " << Brief(dispatch_tables());
os << "\n - raw_type: " << raw_type();
os << "\n";
}
void WasmGlobalObject::WasmGlobalObjectPrint(std::ostream& os) {
PrintHeader(os, "WasmGlobalObject");
if (type().is_reference()) {
......@@ -2076,21 +1942,6 @@ void WasmGlobalObject::WasmGlobalObjectPrint(std::ostream& os) {
os << "\n";
}
void WasmMemoryObject::WasmMemoryObjectPrint(std::ostream& os) {
PrintHeader(os, "WasmMemoryObject");
os << "\n - array_buffer: " << Brief(array_buffer());
os << "\n - maximum_pages: " << maximum_pages();
os << "\n - instances: " << Brief(instances());
os << "\n";
}
void WasmTagObject::WasmTagObjectPrint(std::ostream& os) {
PrintHeader(os, "WasmTagObject");
os << "\n - serialized_signature: " << Brief(serialized_signature());
os << "\n - tag: " << Brief(tag());
os << "\n";
}
void WasmIndirectFunctionTable::WasmIndirectFunctionTablePrint(
std::ostream& os) {
PrintHeader(os, "WasmIndirectFunctionTable");
......@@ -2148,13 +1999,6 @@ void StoreHandler::StoreHandlerPrint(std::ostream& os) {
os << "\n";
}
void AccessorPair::AccessorPairPrint(std::ostream& os) {
PrintHeader(os, "AccessorPair");
os << "\n - getter: " << Brief(getter());
os << "\n - setter: " << Brief(setter());
os << "\n";
}
void CallHandlerInfo::CallHandlerInfoPrint(std::ostream& os) {
PrintHeader(os, "CallHandlerInfo");
os << "\n - callback: " << Brief(callback());
......@@ -2438,18 +2282,6 @@ void ScopeInfo::ScopeInfoPrint(std::ostream& os) {
os << "\n";
}
void StackFrameInfo::StackFrameInfoPrint(std::ostream& os) {
PrintHeader(os, "StackFrameInfo");
os << "\n - receiver_or_instance: " << Brief(receiver_or_instance());
os << "\n - function: " << Brief(function());
os << "\n - code_object: " << Brief(TorqueGeneratedClass::code_object());
os << "\n - code_offset_or_source_position: "
<< code_offset_or_source_position();
os << "\n - flags: " << flags();
os << "\n - parameters: " << Brief(parameters());
os << "\n";
}
void PreparseData::PreparseDataPrint(std::ostream& os) {
PrintHeader(os, "PreparseData");
os << "\n - data_length: " << data_length();
......@@ -2466,13 +2298,6 @@ void PreparseData::PreparseDataPrint(std::ostream& os) {
os << "\n";
}
void InterpreterData::InterpreterDataPrint(std::ostream& os) {
PrintHeader(os, "InterpreterData");
os << "\n - bytecode_array: " << Brief(bytecode_array());
os << "\n - interpreter_trampoline: " << Brief(interpreter_trampoline());
os << "\n";
}
template <HeapObjectReferenceType kRefType, typename StorageType>
void TaggedImpl<kRefType, StorageType>::Print() {
StdoutStream os;
......
......@@ -16,7 +16,6 @@ bitfield struct InterceptorInfoFlags extends uint31 {
has_no_side_effect: bool: 1 bit;
}
@generatePrint
extern class InterceptorInfo extends Struct {
getter: NonNullForeign|Zero|Undefined;
setter: NonNullForeign|Zero|Undefined;
......@@ -29,7 +28,6 @@ extern class InterceptorInfo extends Struct {
flags: SmiTagged<InterceptorInfoFlags>;
}
@generatePrint
extern class AccessCheckInfo extends Struct {
callback: Foreign|Zero|Undefined;
named_interceptor: InterceptorInfo|Zero|Undefined;
......@@ -50,7 +48,6 @@ bitfield struct AccessorInfoFlags extends uint31 {
initial_attributes: PropertyAttributes: 3 bit;
}
@generatePrint
extern class AccessorInfo extends Struct {
name: Name;
flags: SmiTagged<AccessorInfoFlags>;
......
......@@ -88,10 +88,7 @@ macro NewSloppyArgumentsElements<Iterator: type>(
SloppyArgumentsElements{length, context, arguments, mapped_entries: ...it};
}
@generatePrint
extern class AliasedArgumentsEntry extends Struct {
aliased_context_slot: Smi;
}
extern class AliasedArgumentsEntry extends Struct { aliased_context_slot: Smi; }
// TODO(danno): This should be a namespace {} once supported
namespace arguments {
......
......@@ -2,7 +2,4 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@generatePrint
extern class Cell extends HeapObject {
value: Object;
}
extern class Cell extends HeapObject { value: Object; }
......@@ -2,13 +2,11 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@generatePrint
extern class BreakPoint extends Struct {
id: Smi;
condition: String;
}
@generatePrint
extern class BreakPointInfo extends Struct {
// The position in the source for the break position.
source_position: Smi;
......@@ -32,7 +30,6 @@ bitfield struct DebuggerHints extends uint31 {
debugging_id: int32: 20 bit;
}
@generatePrint
extern class DebugInfo extends Struct {
shared: SharedFunctionInfo;
// Bit field containing various information collected for debugging.
......
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@generatePrint
extern class EnumCache extends Struct {
keys: FixedArray;
indices: FixedArray;
......
......@@ -98,7 +98,6 @@ class JSProxy : public TorqueGeneratedJSProxy<JSProxy, JSReceiver> {
LookupIterator* it);
// Dispatched behavior.
DECL_PRINTER(JSProxy)
DECL_VERIFIER(JSProxy)
static const int kMaxIterationLimit = 100 * 1024;
......
......@@ -71,7 +71,6 @@ class JSFinalizationRegistry
// Internal object for storing weak references in JSFinalizationRegistry.
class WeakCell : public TorqueGeneratedWeakCell<WeakCell, HeapObject> {
public:
DECL_PRINTER(WeakCell)
EXPORT_DECL_VERIFIER(WeakCell)
class BodyDescriptor;
......
......@@ -80,7 +80,6 @@ class RegExpBoilerplateDescription
RegExpBoilerplateDescription, Struct> {
public:
// Dispatched behavior.
DECL_PRINTER(RegExpBoilerplateDescription)
void BriefPrintDetails(std::ostream& os);
private:
......
......@@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@generatePrint
@generateBodyDescriptor
extern class MegaDomHandler extends HeapObject {
accessor: MaybeObject;
......
......@@ -30,9 +30,6 @@ class Microtask : public TorqueGeneratedMicrotask<Microtask, Struct> {
class CallbackTask
: public TorqueGeneratedCallbackTask<CallbackTask, Microtask> {
public:
// Dispatched behavior.
DECL_PRINTER(CallbackTask)
TQ_OBJECT_CONSTRUCTORS(CallbackTask)
};
......@@ -43,7 +40,6 @@ class CallableTask
: public TorqueGeneratedCallableTask<CallableTask, Microtask> {
public:
// Dispatched behavior.
DECL_PRINTER(CallableTask)
DECL_VERIFIER(CallableTask)
void BriefPrintDetails(std::ostream& os);
......
......@@ -646,7 +646,8 @@ class Object : public TaggedImpl<HeapObjectReferenceType::STRONG, Address> {
bool operator()(const Object a, const Object b) const { return a < b; }
};
template <class T, typename std::enable_if<std::is_arithmetic<T>::value,
template <class T, typename std::enable_if<std::is_arithmetic<T>::value ||
std::is_enum<T>::value,
int>::type = 0>
inline T ReadField(size_t offset) const {
// Pointer compression causes types larger than kTaggedSize to be unaligned.
......@@ -663,7 +664,8 @@ class Object : public TaggedImpl<HeapObjectReferenceType::STRONG, Address> {
}
}
template <class T, typename std::enable_if<std::is_arithmetic<T>::value,
template <class T, typename std::enable_if<std::is_arithmetic<T>::value ||
std::is_enum<T>::value,
int>::type = 0>
inline void WriteField(size_t offset, T value) const {
// Pointer compression causes types larger than kTaggedSize to be unaligned.
......
......@@ -39,9 +39,6 @@ class PromiseFulfillReactionJobTask
: public TorqueGeneratedPromiseFulfillReactionJobTask<
PromiseFulfillReactionJobTask, PromiseReactionJobTask> {
public:
// Dispatched behavior.
DECL_PRINTER(PromiseFulfillReactionJobTask)
STATIC_ASSERT(kSize == kSizeOfAllPromiseReactionJobTasks);
TQ_OBJECT_CONSTRUCTORS(PromiseFulfillReactionJobTask)
......@@ -52,9 +49,6 @@ class PromiseRejectReactionJobTask
: public TorqueGeneratedPromiseRejectReactionJobTask<
PromiseRejectReactionJobTask, PromiseReactionJobTask> {
public:
// Dispatched behavior.
DECL_PRINTER(PromiseRejectReactionJobTask)
STATIC_ASSERT(kSize == kSizeOfAllPromiseReactionJobTasks);
TQ_OBJECT_CONSTRUCTORS(PromiseRejectReactionJobTask)
......@@ -65,9 +59,6 @@ class PromiseResolveThenableJobTask
: public TorqueGeneratedPromiseResolveThenableJobTask<
PromiseResolveThenableJobTask, Microtask> {
public:
// Dispatched behavior.
DECL_PRINTER(PromiseResolveThenableJobTask)
TQ_OBJECT_CONSTRUCTORS(PromiseResolveThenableJobTask)
};
......@@ -75,9 +66,6 @@ class PromiseResolveThenableJobTask
class PromiseCapability
: public TorqueGeneratedPromiseCapability<PromiseCapability, Struct> {
public:
// Dispatched behavior.
DECL_PRINTER(PromiseCapability)
TQ_OBJECT_CONSTRUCTORS(PromiseCapability)
};
......@@ -103,9 +91,6 @@ class PromiseReaction
public:
enum Type { kFulfill, kReject };
// Dispatched behavior.
DECL_PRINTER(PromiseReaction)
TQ_OBJECT_CONSTRUCTORS(PromiseReaction)
};
......
......@@ -16,7 +16,6 @@ bitfield struct PropertyDescriptorObjectFlags extends uint31 {
has_set: bool: 1 bit;
}
@generatePrint
extern class PropertyDescriptorObject extends Struct {
flags: SmiTagged<PropertyDescriptorObjectFlags>;
value: JSAny|TheHole;
......
......@@ -146,8 +146,6 @@ class InterpreterData
public:
DECL_ACCESSORS(interpreter_trampoline, Code)
DECL_PRINTER(InterpreterData)
private:
DECL_ACCESSORS(raw_interpreter_trampoline, CodeT)
......
......@@ -283,7 +283,6 @@ class SourceTextModuleInfoEntry
: public TorqueGeneratedSourceTextModuleInfoEntry<SourceTextModuleInfoEntry,
Struct> {
public:
DECL_PRINTER(SourceTextModuleInfoEntry)
DECL_VERIFIER(SourceTextModuleInfoEntry)
template <typename IsolateT>
......
......@@ -47,7 +47,6 @@ extern class SourceTextModule extends Module {
flags: SmiTagged<SourceTextModuleFlags>;
}
@generatePrint
extern class ModuleRequest extends Struct {
specifier: String;
......
......@@ -44,7 +44,6 @@ class StackFrameInfo
DECL_ACCESSORS(code_object, HeapObject)
// Dispatched behavior.
DECL_PRINTER(StackFrameInfo)
DECL_VERIFIER(StackFrameInfo)
// Used to signal that the requested field is unknown.
......
......@@ -69,9 +69,6 @@ class AccessorPair : public TorqueGeneratedAccessorPair<AccessorPair, Struct> {
inline bool Equals(Object getter_value, Object setter_value);
// Dispatched behavior.
DECL_PRINTER(AccessorPair)
TQ_OBJECT_CONSTRUCTORS(AccessorPair)
};
......@@ -79,7 +76,6 @@ class ClassPositions
: public TorqueGeneratedClassPositions<ClassPositions, Struct> {
public:
// Dispatched behavior.
DECL_PRINTER(ClassPositions)
void BriefPrintDetails(std::ostream& os);
TQ_OBJECT_CONSTRUCTORS(ClassPositions)
......
......@@ -3,11 +3,9 @@
// found in the LICENSE file.
@abstract
@generatePrint
extern class Struct extends HeapObject {
}
@generatePrint
extern class Tuple2 extends Struct {
value1: Object;
value2: Object;
......
......@@ -24,7 +24,6 @@ class SyntheticModule
public:
NEVER_READ_ONLY_SPACE
DECL_VERIFIER(SyntheticModule)
DECL_PRINTER(SyntheticModule)
// Set module's exported value for the specified export_name to the specified
// export_value. An error will be thrown if export_name is not one
......
......@@ -2,14 +2,12 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@generatePrint
extern class CachedTemplateObject extends Struct {
slot_id: Smi;
template_object: JSArray;
next: CachedTemplateObject|TheHole;
}
@generatePrint
extern class TemplateObjectDescription extends Struct {
raw_strings: FixedArray;
cooked_strings: FixedArray;
......
......@@ -11,7 +11,6 @@ extern class TemplateInfo extends Struct {
property_accessors: TemplateList|Undefined;
}
@generatePrint
extern class FunctionTemplateRareData extends Struct {
// See DECL_RARE_ACCESSORS in FunctionTemplateInfo.
prototype_template: ObjectTemplateInfo|Undefined;
......
......@@ -83,7 +83,6 @@ static const char* const FIXED_ARRAY_BASE_TYPE_STRING = "FixedArrayBase";
static const char* const WEAK_HEAP_OBJECT = "WeakHeapObject";
static const char* const STATIC_ASSERT_MACRO_STRING = "StaticAssert";
static const char* const ANNOTATION_GENERATE_PRINT = "@generatePrint";
static const char* const ANNOTATION_NO_VERIFIER = "@noVerifier";
static const char* const ANNOTATION_ABSTRACT = "@abstract";
static const char* const ANNOTATION_HAS_SAME_INSTANCE_TYPE_AS_PARENT =
......@@ -144,21 +143,20 @@ using AbstractTypeFlags = base::Flags<AbstractTypeFlag>;
enum class ClassFlag {
kNone = 0,
kExtern = 1 << 0,
kGeneratePrint = 1 << 1,
kGenerateVerify = 1 << 2,
kTransient = 1 << 3,
kAbstract = 1 << 4,
kIsShape = 1 << 5,
kHasSameInstanceTypeAsParent = 1 << 6,
kGenerateCppClassDefinitions = 1 << 7,
kCustomCppClass = 1 << 8,
kHighestInstanceTypeWithinParent = 1 << 9,
kLowestInstanceTypeWithinParent = 1 << 10,
kUndefinedLayout = 1 << 11,
kGenerateBodyDescriptor = 1 << 12,
kExport = 1 << 13,
kDoNotGenerateCast = 1 << 14,
kCustomMap = 1 << 15,
kGenerateVerify = 1 << 1,
kTransient = 1 << 2,
kAbstract = 1 << 3,
kIsShape = 1 << 4,
kHasSameInstanceTypeAsParent = 1 << 5,
kGenerateCppClassDefinitions = 1 << 6,
kCustomCppClass = 1 << 7,
kHighestInstanceTypeWithinParent = 1 << 8,
kLowestInstanceTypeWithinParent = 1 << 9,
kUndefinedLayout = 1 << 10,
kGenerateBodyDescriptor = 1 << 11,
kExport = 1 << 12,
kDoNotGenerateCast = 1 << 13,
kCustomMap = 1 << 14,
};
using ClassFlags = base::Flags<ClassFlag>;
......
......@@ -4297,6 +4297,14 @@ void GenerateBoundsDCheck(std::ostream& os, const std::string& index,
}
os << " DCHECK_LT(" << index << ", " << length_expression << ");\n";
}
bool CanGenerateFieldAccessors(const Type* field_type) {
// float64_or_hole should be treated like float64. For now, we don't need it.
// TODO(v8:10391) Generate accessors for external pointers.
return field_type != TypeOracle::GetVoidType() &&
field_type != TypeOracle::GetFloat64OrHoleType() &&
!field_type->IsSubtypeOf(TypeOracle::GetExternalPointerType());
}
} // namespace
// TODO(sigurds): Keep in sync with DECL_ACCESSORS and ACCESSORS macro.
......@@ -4305,12 +4313,7 @@ void CppClassGenerator::GenerateFieldAccessors(
const Field& innermost_field =
struct_fields.empty() ? class_field : *struct_fields.back();
const Type* field_type = innermost_field.name_and_type.type;
if (field_type == TypeOracle::GetVoidType()) return;
// float64_or_hole should be treated like float64. For now, we don't need it.
if (field_type == TypeOracle::GetFloat64OrHoleType()) {
return;
}
if (!CanGenerateFieldAccessors(field_type)) return;
if (const StructType* struct_type = StructType::DynamicCast(field_type)) {
struct_fields.resize(struct_fields.size() + 1);
......@@ -4322,11 +4325,6 @@ void CppClassGenerator::GenerateFieldAccessors(
return;
}
// TODO(v8:10391) Generate accessors for external pointers
if (field_type->IsSubtypeOf(TypeOracle::GetExternalPointerType())) {
return;
}
bool indexed = class_field.index && !class_field.index->optional;
std::string type_name = GetTypeNameForAccessor(innermost_field);
bool can_contain_heap_objects = CanContainHeapObjects(field_type);
......@@ -4783,43 +4781,50 @@ void GeneratePrintDefinitionsForClass(std::ostream& impl, const ClassType* type,
std::map<std::string, const AggregateType*> field_names;
for (const AggregateType* aggregate_type : hierarchy) {
for (const Field& f : aggregate_type->fields()) {
if (f.name_and_type.name == "map") continue;
if (!f.index.has_value()) {
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()) {
// TODO(turbofan): Print struct fields too.
impl << "\" <struct field printing still unimplemented>\";\n";
} else {
impl << "this->" << f.name_and_type.name;
switch (f.read_synchronization) {
case FieldSynchronization::kNone:
impl << "();\n";
break;
case FieldSynchronization::kRelaxed:
impl << "(kRelaxedLoad);\n";
break;
case FieldSynchronization::kAcquireRelease:
impl << "(kAcquireLoad);\n";
break;
}
}
if (f.name_and_type.name == "map" || f.index.has_value() ||
!CanGenerateFieldAccessors(f.name_and_type.type)) {
continue;
}
std::string getter = f.name_and_type.name;
if (aggregate_type != type) {
// We must call getters directly on the class that provided them,
// because a subclass could have hidden them.
getter = aggregate_type->name() + "::TorqueGeneratedClass::" + getter;
}
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()) {
// TODO(turbofan): Print struct fields too.
impl << "\" <struct field printing still unimplemented>\";\n";
} else {
impl << " os << \"\\n - " << f.name_and_type.name << ": \" << "
<< "Brief(this->" << f.name_and_type.name;
impl << "this->" << getter;
switch (f.read_synchronization) {
case FieldSynchronization::kNone:
impl << "());\n";
impl << "();\n";
break;
case FieldSynchronization::kRelaxed:
impl << "(kRelaxedLoad));\n";
impl << "(kRelaxedLoad);\n";
break;
case FieldSynchronization::kAcquireRelease:
impl << "(kAcquireLoad));\n";
impl << "(kAcquireLoad);\n";
break;
}
}
} else {
impl << " os << \"\\n - " << f.name_and_type.name << ": \" << "
<< "Brief(this->" << getter;
switch (f.read_synchronization) {
case FieldSynchronization::kNone:
impl << "());\n";
break;
case FieldSynchronization::kRelaxed:
impl << "(kRelaxedLoad));\n";
break;
case FieldSynchronization::kAcquireRelease:
impl << "(kAcquireLoad));\n";
break;
}
}
}
}
......@@ -4842,19 +4847,14 @@ void ImplementationVisitor::GeneratePrintDefinitions(
for (const ClassType* type : TypeOracle::GetClasses()) {
if (!type->ShouldGeneratePrint()) continue;
if (type->GenerateCppClassDefinitions()) {
const ClassType* super = type->GetSuperClass();
std::string gen_name = "TorqueGenerated" + type->name();
std::string gen_name_T =
gen_name + "<" + type->name() + ", " + super->name() + ">";
std::string template_decl = "template <>";
GeneratePrintDefinitionsForClass(impl, type, gen_name, gen_name_T,
template_decl);
} else {
GeneratePrintDefinitionsForClass(impl, type, type->name(), type->name(),
"");
}
DCHECK(type->GenerateCppClassDefinitions());
const ClassType* super = type->GetSuperClass();
std::string gen_name = "TorqueGenerated" + type->name();
std::string gen_name_T =
gen_name + "<" + type->name() + ", " + super->name() + ">";
std::string template_decl = "template <>";
GeneratePrintDefinitionsForClass(impl, type, gen_name, gen_name_T,
template_decl);
}
}
......
......@@ -888,7 +888,7 @@ base::Optional<ParseResult> MakeClassDeclaration(
ParseResultIterator* child_results) {
AnnotationSet annotations(
child_results,
{ANNOTATION_GENERATE_PRINT, ANNOTATION_NO_VERIFIER, ANNOTATION_ABSTRACT,
{ANNOTATION_NO_VERIFIER, ANNOTATION_ABSTRACT,
ANNOTATION_HAS_SAME_INSTANCE_TYPE_AS_PARENT,
ANNOTATION_DO_NOT_GENERATE_CPP_CLASS, ANNOTATION_CUSTOM_CPP_CLASS,
ANNOTATION_CUSTOM_MAP, ANNOTATION_GENERATE_BODY_DESCRIPTOR,
......@@ -898,8 +898,6 @@ base::Optional<ParseResult> MakeClassDeclaration(
{ANNOTATION_RESERVE_BITS_IN_INSTANCE_TYPE,
ANNOTATION_INSTANCE_TYPE_VALUE});
ClassFlags flags = ClassFlag::kNone;
bool generate_print = annotations.Contains(ANNOTATION_GENERATE_PRINT);
if (generate_print) flags |= ClassFlag::kGeneratePrint;
bool generate_verify = !annotations.Contains(ANNOTATION_NO_VERIFIER);
if (generate_verify) flags |= ClassFlag::kGenerateVerify;
if (annotations.Contains(ANNOTATION_ABSTRACT)) {
......
......@@ -319,7 +319,7 @@ const ClassType* TypeVisitor::ComputeType(
Error("non-external classes must have defined layouts");
}
}
flags = flags | ClassFlag::kGeneratePrint | ClassFlag::kGenerateVerify;
flags = flags | ClassFlag::kGenerateVerify;
}
if (!(flags & ClassFlag::kExtern) &&
(flags & ClassFlag::kHasSameInstanceTypeAsParent)) {
......
......@@ -670,8 +670,8 @@ class ClassType final : public AggregateType {
std::string GetGeneratedTNodeTypeNameImpl() const override;
bool IsExtern() const { return flags_ & ClassFlag::kExtern; }
bool ShouldGeneratePrint() const {
return !IsExtern() ||
((flags_ & ClassFlag::kGeneratePrint) && !HasUndefinedLayout());
return !IsExtern() || (GenerateCppClassDefinitions() && !IsAbstract() &&
!HasUndefinedLayout());
}
bool ShouldGenerateVerify() const {
return !IsExtern() || ((flags_ & ClassFlag::kGenerateVerify) &&
......
......@@ -182,9 +182,6 @@ class WasmModuleObject
class WasmTableObject
: public TorqueGeneratedWasmTableObject<WasmTableObject, JSObject> {
public:
// Dispatched behavior.
DECL_PRINTER(WasmTableObject)
inline wasm::ValueType type();
V8_EXPORT_PRIVATE static int Grow(Isolate* isolate,
......@@ -267,9 +264,6 @@ class WasmMemoryObject
public:
DECL_OPTIONAL_ACCESSORS(instances, WeakArrayList)
// Dispatched behavior.
DECL_PRINTER(WasmMemoryObject)
// Add an instance to the internal (weak) list.
V8_EXPORT_PRIVATE static void AddInstance(Isolate* isolate,
Handle<WasmMemoryObject> memory,
......@@ -554,9 +548,6 @@ class V8_EXPORT_PRIVATE WasmInstanceObject : public JSObject {
class WasmTagObject
: public TorqueGeneratedWasmTagObject<WasmTagObject, JSObject> {
public:
// Dispatched behavior.
DECL_PRINTER(WasmTagObject)
// Checks whether the given {sig} has the same parameter types as the
// serialized signature stored within this tag object.
bool MatchesSignature(const wasm::FunctionSig* sig);
......@@ -841,8 +832,6 @@ class WasmExceptionTag
V8_EXPORT_PRIVATE static Handle<WasmExceptionTag> New(Isolate* isolate,
int index);
DECL_PRINTER(WasmExceptionTag)
TQ_OBJECT_CONSTRUCTORS(WasmExceptionTag)
};
......
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