[torque] Support 'real' internal classes

Rework the implementation of non-external Torque classes to use
Struct machinery rather than FixedArray machinery. This allows
Torque-only defined 'internal' classes to the automatically generate
class verifiers and printers.

As part of this change, generate C++ boilerplate accessors for
internal Torque classes, since this is a pre-requisite for the
verifiers, printers and other Struct-based functionality.

Moreover, augment the header-generating functionality in Torque
to create separate header files for field offset definitions,
internal class C++ definitions and instance types.

Bug: v8:7793
Change-Id: I47d5f1570040c2b44d378f23b6cf95d3d132dacc
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1607645
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62317}
This commit is contained in:
Sigurd Schneider 2019-06-21 17:30:13 +02:00 committed by Commit Bot
parent 4965a34e0f
commit 76c1e829e3
29 changed files with 358 additions and 190 deletions

View File

@ -1024,6 +1024,7 @@ action("run_torque") {
"$target_gen_dir/torque-generated/exported-macros-assembler-tq.cc",
"$target_gen_dir/torque-generated/exported-macros-assembler-tq.h",
"$target_gen_dir/torque-generated/csa-types-tq.h",
"$target_gen_dir/torque-generated/instance-types-tq.h",
]
foreach(file, torque_files) {
filetq = string_replace(file, ".tq", "-tq-csa")

View File

@ -247,8 +247,7 @@ extern class DescriptorArray extends HeapObject {
// than building the definition from C++.
intrinsic %GetAllocationBaseSize<Class: type>(map: Map): intptr;
intrinsic %Allocate<Class: type>(size: intptr): Class;
intrinsic %AllocateInternalClass<Class: type>(slotCount: constexpr intptr):
Class;
intrinsic %GetStructMap(instanceKind: constexpr InstanceType): Map;
intrinsic %AddIndexedFieldSizeToObjectSize<T: type>(
baseSize: intptr, indexSize: T, fieldSize: int32): intptr {

View File

@ -1473,6 +1473,12 @@ TNode<Float64T> CodeStubAssembler::LoadHeapNumberValue(
object, HeapNumber::kValueOffset, MachineType::Float64()));
}
TNode<Map> CodeStubAssembler::GetStructMap(InstanceType instance_type) {
Handle<Map> map_handle(Map::GetStructMap(isolate(), instance_type),
isolate());
return HeapConstant(map_handle);
}
TNode<Map> CodeStubAssembler::LoadMap(SloppyTNode<HeapObject> object) {
return UncheckedCast<Map>(LoadObjectField(object, HeapObject::kMapOffset,
MachineType::TaggedPointer()));

View File

@ -1717,6 +1717,8 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
fixed_array_map);
}
TNode<Map> GetStructMap(InstanceType instance_type);
TNode<FixedArray> AllocateUninitializedFixedArray(intptr_t capacity) {
return UncheckedCast<FixedArray>(AllocateFixedArray(
PACKED_ELEMENTS, IntPtrConstant(capacity), AllocationFlag::kNone));

View File

@ -73,6 +73,9 @@ class PromiseReactionJobTask;
class PromiseRejectReactionJobTask;
class WasmDebugInfo;
class Zone;
#define MAKE_FORWARD_DECLARATION(V, NAME, Name, name) class Name;
TORQUE_STRUCT_LIST_GENERATOR(MAKE_FORWARD_DECLARATION, UNUSED)
#undef MAKE_FORWARD_DECLARATION
template <typename T>
class Signature;

View File

@ -363,6 +363,9 @@ Type::bitset BitsetType::Lub(const MapRefLike& map) {
case PROMISE_REJECT_REACTION_JOB_TASK_TYPE:
case PROMISE_RESOLVE_THENABLE_JOB_TASK_TYPE:
case FINALIZATION_GROUP_CLEANUP_JOB_TASK_TYPE:
#define MAKE_TORQUE_CLASS_TYPE(V) case V:
TORQUE_DEFINED_INSTANCE_TYPES(MAKE_TORQUE_CLASS_TYPE)
#undef MAKE_TORQUE_CLASS_TYPE
UNREACHABLE();
}
UNREACHABLE();

View File

@ -67,6 +67,7 @@
#include "src/utils/ostreams.h"
#include "src/wasm/wasm-objects-inl.h"
#include "torque-generated/class-verifiers-tq.h"
#include "torque-generated/internal-class-definitions-tq-inl.h"
namespace v8 {
namespace internal {

View File

@ -65,6 +65,8 @@
#include "src/wasm/wasm-code-manager.h"
#include "src/wasm/wasm-engine.h"
#include "src/wasm/wasm-objects-inl.h"
#include "torque-generated/class-definitions-tq-inl.h"
#include "torque-generated/internal-class-definitions-tq-inl.h"
namespace v8 {
namespace internal {

View File

@ -1611,17 +1611,7 @@ Handle<Context> Factory::NewBuiltinContext(Handle<NativeContext> native_context,
Handle<Struct> Factory::NewStruct(InstanceType type,
AllocationType allocation) {
Map map;
switch (type) {
#define MAKE_CASE(TYPE, Name, name) \
case TYPE: \
map = *name##_map(); \
break;
STRUCT_LIST(MAKE_CASE)
#undef MAKE_CASE
default:
UNREACHABLE();
}
Map map = Map::GetStructMap(isolate(), type);
int size = map.instance_size();
HeapObject result = AllocateRawWithImmortalMap(size, allocation, map);
Handle<Struct> str(Struct::cast(result), isolate());

View File

@ -42,6 +42,8 @@
#include "src/objects/template-objects-inl.h"
#include "src/regexp/regexp.h"
#include "src/wasm/wasm-objects.h"
#include "torque-generated/class-definitions-tq.h"
#include "torque-generated/internal-class-definitions-tq-inl.h"
namespace v8 {
namespace internal {

View File

@ -11,6 +11,8 @@
// Has to be the last include (doesn't have include guards):
#include "src/objects/object-macros.h"
#include "torque-generated/instance-types-tq.h"
namespace v8 {
namespace internal {
@ -176,7 +178,11 @@ enum InstanceType : uint16_t {
PROMISE_RESOLVE_THENABLE_JOB_TASK_TYPE,
FINALIZATION_GROUP_CLEANUP_JOB_TASK_TYPE, // LAST_MICROTASK_TYPE
ALLOCATION_SITE_TYPE,
#define MAKE_TORQUE_INSTANCE_TYPE(V) V,
TORQUE_DEFINED_INSTANCE_TYPES(MAKE_TORQUE_INSTANCE_TYPE)
#undef MAKE_TORQUE_INSTANCE_TYPE
ALLOCATION_SITE_TYPE,
EMBEDDER_DATA_ARRAY_TYPE,
// FixedArrays.
FIXED_ARRAY_TYPE, // FIRST_FIXED_ARRAY_TYPE

View File

@ -85,6 +85,21 @@ void Map::PrintReconfiguration(Isolate* isolate, FILE* file, int modify_index,
os << "]\n";
}
Map Map::GetStructMap(Isolate* isolate, InstanceType type) {
Map map;
switch (type) {
#define MAKE_CASE(TYPE, Name, name) \
case TYPE: \
map = ReadOnlyRoots(isolate).name##_map(); \
break;
STRUCT_LIST(MAKE_CASE)
#undef MAKE_CASE
default:
UNREACHABLE();
}
return map;
}
VisitorId Map::GetVisitorId(Map map) {
STATIC_ASSERT(kVisitorIdCount <= 256);

View File

@ -797,6 +797,8 @@ class Map : public HeapObject {
inline bool CanTransition() const;
static Map GetStructMap(Isolate* isolate, InstanceType type);
#define DECL_TESTER(Type, ...) inline bool Is##Type##Map() const;
INSTANCE_TYPE_CHECKERS(DECL_TESTER)
#undef DECL_TESTER

View File

@ -7,6 +7,8 @@
#include "src/init/heap-symbols.h"
#include "torque-generated/instance-types-tq.h"
namespace v8 {
namespace internal {
@ -115,6 +117,8 @@ namespace internal {
V(PROMISE_RESOLVE_THENABLE_JOB_TASK_TYPE) \
V(FINALIZATION_GROUP_CLEANUP_JOB_TASK_TYPE) \
\
TORQUE_DEFINED_INSTANCE_TYPES(V) \
\
V(ALLOCATION_SITE_TYPE) \
V(EMBEDDER_DATA_ARRAY_TYPE) \
\
@ -347,14 +351,18 @@ namespace internal {
#define STRUCT_LIST_ADAPTER(V, NAME, Name, name) V(NAME, Name, name)
// Produces (NAME, Name, name) entries.
#define STRUCT_LIST(V) STRUCT_LIST_GENERATOR(STRUCT_LIST_ADAPTER, V)
#define STRUCT_LIST(V) \
STRUCT_LIST_GENERATOR(STRUCT_LIST_ADAPTER, V) \
TORQUE_STRUCT_LIST_GENERATOR(STRUCT_LIST_ADAPTER, V)
// Adapts one STRUCT_LIST_GENERATOR entry to the STRUCT_MAPS_LIST entry
#define STRUCT_MAPS_LIST_ADAPTER(V, NAME, Name, name) \
V(Map, name##_map, Name##Map)
// Produces (Map, struct_name_map, StructNameMap) entries
#define STRUCT_MAPS_LIST(V) STRUCT_LIST_GENERATOR(STRUCT_MAPS_LIST_ADAPTER, V)
#define STRUCT_MAPS_LIST(V) \
STRUCT_LIST_GENERATOR(STRUCT_MAPS_LIST_ADAPTER, V) \
TORQUE_STRUCT_LIST_GENERATOR(STRUCT_MAPS_LIST_ADAPTER, V)
//
// The following macros define list of allocation size objects and list of

View File

@ -116,6 +116,9 @@
#include "src/wasm/wasm-objects.h"
#include "src/zone/zone.h"
#include "torque-generated/class-definitions-tq-inl.h"
#include "torque-generated/internal-class-definitions-tq-inl.h"
namespace v8 {
namespace internal {

View File

@ -18,6 +18,8 @@ static const char* const CONSTEXPR_TYPE_PREFIX = "constexpr ";
static const char* const NEVER_TYPE_STRING = "never";
static const char* const CONSTEXPR_BOOL_TYPE_STRING = "constexpr bool";
static const char* const CONSTEXPR_INTPTR_TYPE_STRING = "constexpr intptr";
static const char* const CONSTEXPR_INSTANCE_TYPE_TYPE_STRING =
"constexpr InstanceType";
static const char* const BOOL_TYPE_STRING = "bool";
static const char* const VOID_TYPE_STRING = "void";
static const char* const ARGUMENTS_TYPE_STRING = "Arguments";

View File

@ -256,9 +256,8 @@ void CSAGenerator::EmitInstruction(const CallIntrinsicInstruction& instruction,
} else if (instruction.intrinsic->ExternalName() == "%Allocate") {
out_ << "ca_.UncheckedCast<" << return_type->GetGeneratedTNodeTypeName()
<< ">(CodeStubAssembler(state_).Allocate";
} else if (instruction.intrinsic->ExternalName() ==
"%AllocateInternalClass") {
out_ << "CodeStubAssembler(state_).AllocateUninitializedFixedArray";
} else if (instruction.intrinsic->ExternalName() == "%GetStructMap") {
out_ << "CodeStubAssembler(state_).GetStructMap";
} else {
ReportError("no built in intrinsic with name " +
instruction.intrinsic->ExternalName());
@ -717,12 +716,8 @@ void CSAGenerator::EmitInstruction(
out_ << " compiler::TNode<IntPtrT> " << offset_name
<< " = ca_.IntPtrConstant(";
if (instruction.class_type->IsExtern()) {
out_ << field.aggregate->GetGeneratedTNodeTypeName() << "::k"
<< CamelifyString(field.name_and_type.name) << "Offset";
} else {
out_ << "FixedArray::kHeaderSize + " << field.offset;
}
out_ << ");\n"
<< " USE(" << stack->Top() << ");\n";
}

View File

@ -1365,43 +1365,51 @@ VisitResult ImplementationVisitor::Visit(NewExpression* expr) {
InitializerResults initializer_results =
VisitInitializerResults(class_type, expr->initializers);
// Output the code to generate an uninitialized object of the class size in
// the GC heap.
VisitResult allocate_result;
VisitResult object_map;
const Field& map_field = class_type->LookupField("map");
if (map_field.offset != 0) {
ReportError("class initializers must have a map as first parameter");
}
const std::map<std::string, VisitResult>& initializer_fields =
initializer_results.field_value_map;
auto it_object_map = initializer_fields.find(map_field.name_and_type.name);
if (class_type->IsExtern()) {
const Field& map_field = class_type->LookupField("map");
if (map_field.offset != 0) {
ReportError(
"external classes initializers must have a map as first parameter");
}
NameValueMap initializer_fields = initializer_results.field_value_map;
if (initializer_fields.find(map_field.name_and_type.name) ==
initializer_fields.end()) {
if (it_object_map == initializer_fields.end()) {
ReportError("Constructor for ", class_type->name(),
" needs Map argument!");
}
VisitResult object_map = initializer_fields[map_field.name_and_type.name];
Arguments size_arguments;
size_arguments.parameters.push_back(object_map);
VisitResult object_size = GenerateCall("%GetAllocationBaseSize",
size_arguments, {class_type}, false);
object_size =
AddVariableObjectSize(object_size, class_type, initializer_results);
Arguments allocate_arguments;
allocate_arguments.parameters.push_back(object_size);
allocate_result =
GenerateCall("%Allocate", allocate_arguments, {class_type}, false);
DCHECK(allocate_result.IsOnStack());
object_map = it_object_map->second;
} else {
Arguments allocate_arguments;
allocate_arguments.parameters.push_back(
VisitResult(TypeOracle::GetConstexprIntPtrType(),
std::to_string(class_type->size() / kTaggedSize)));
allocate_result = GenerateCall("%AllocateInternalClass", allocate_arguments,
{class_type}, false);
if (it_object_map != initializer_fields.end()) {
ReportError(
"Constructor for ", class_type->name(),
" must not specify Map argument; it is automatically inserted.");
}
Arguments get_struct_map_arguments;
get_struct_map_arguments.parameters.push_back(
VisitResult(TypeOracle::GetConstexprInstanceTypeType(),
CapifyStringWithUnderscores(class_type->name()) + "_TYPE"));
object_map =
GenerateCall("%GetStructMap", get_struct_map_arguments, {}, false);
CurrentSourcePosition::Scope current_pos(expr->pos);
initializer_results.names.insert(initializer_results.names.begin(),
MakeNode<Identifier>("map"));
initializer_results.field_value_map[map_field.name_and_type.name] =
object_map;
}
Arguments size_arguments;
size_arguments.parameters.push_back(object_map);
VisitResult object_size = GenerateCall("%GetAllocationBaseSize",
size_arguments, {class_type}, false);
object_size =
AddVariableObjectSize(object_size, class_type, initializer_results);
Arguments allocate_arguments;
allocate_arguments.parameters.push_back(object_size);
VisitResult allocate_result =
GenerateCall("%Allocate", allocate_arguments, {class_type}, false);
DCHECK(allocate_result.IsOnStack());
InitializeAggregate(class_type, allocate_result, initializer_results);
@ -2929,9 +2937,81 @@ class MacroFieldOffsetsGenerator : public FieldOffsetsGenerator {
private:
std::ostream& out_;
};
} // namespace
void ImplementationVisitor::GenerateInstanceTypes(
const std::string& output_directory) {
std::stringstream header;
std::string file_name = "instance-types-tq.h";
{
IncludeGuardScope(header, file_name);
header << "#define TORQUE_DEFINED_INSTANCE_TYPES(V) \\\n";
for (const TypeAlias* alias : GlobalContext::GetClasses()) {
const ClassType* type = ClassType::DynamicCast(alias->type());
if (type->IsExtern()) continue;
std::string type_name =
CapifyStringWithUnderscores(type->name()) + "_TYPE";
header << " V(" << type_name << ") \\\n";
}
header << "\n\n";
header << "#define TORQUE_STRUCT_LIST_GENERATOR(V, _) \\\n";
for (const TypeAlias* alias : GlobalContext::GetClasses()) {
const ClassType* type = ClassType::DynamicCast(alias->type());
if (type->IsExtern()) continue;
std::string type_name =
CapifyStringWithUnderscores(type->name()) + "_TYPE";
std::string variable_name = SnakeifyString(type->name());
header << " V(_, " << type_name << ", " << type->name() << ", "
<< variable_name << ") \\\n";
}
header << "\n";
}
std::string output_header_path = output_directory + "/" + file_name;
WriteFile(output_header_path, header.str());
}
void ImplementationVisitor::GenerateCppForInternalClasses(
const std::string& output_directory) {
std::stringstream header;
std::stringstream inl;
std::string base_name = "internal-class-definitions-tq";
{
IncludeGuardScope header_guard(header, base_name + ".h");
header << "#include \"src/objects/objects.h\"\n";
header << "#include \"src/objects/struct.h\"\n";
header << "#include \"src/objects/js-objects.h\"\n";
header << "#include \"src/utils/utils.h\"\n";
header << "#include \"torque-generated/class-definitions-tq.h\"\n";
IncludeObjectMacrosScope header_macros(header);
NamespaceScope header_namespaces(header, {"v8", "internal"});
IncludeGuardScope inl_guard(inl, base_name + "-inl.h");
inl << "#include \"torque-generated/" << base_name << ".h\"\n";
inl << "#include \"torque-generated/class-definitions-tq-inl.h\"\n";
IncludeObjectMacrosScope inl_macros(inl);
NamespaceScope inl_namespaces(inl, {"v8", "internal"});
for (const TypeAlias* alias : GlobalContext::GetClasses()) {
const ClassType* type = ClassType::DynamicCast(alias->type());
if (type->IsExtern()) continue;
const ClassType* super = type->GetSuperClass();
std::string parent = "TorqueGenerated" + type->name() + "<" +
type->name() + ", " + super->name() + ">";
header << "class " << type->name() << ": public " << parent << " {\n";
header << " public:\n";
header << " TQ_OBJECT_CONSTRUCTORS(" << type->name() << ")\n";
header << "};\n\n";
inl << "TQ_OBJECT_CONSTRUCTORS_IMPL(" << type->name() << ")\n";
}
}
std::string dir_basename = output_directory + "/" + base_name;
WriteFile(dir_basename + ".h", header.str());
WriteFile(dir_basename + "-inl.h", inl.str());
}
void ImplementationVisitor::GenerateClassFieldOffsets(
const std::string& output_directory) {
std::stringstream header;
@ -2941,7 +3021,6 @@ void ImplementationVisitor::GenerateClassFieldOffsets(
for (const TypeAlias* alias : GlobalContext::GetClasses()) {
const ClassType* type = ClassType::DynamicCast(alias->type());
if (!type->IsExtern()) continue;
// TODO(danno): Remove this once all classes use ClassFieldOffsetGenerator
// to generate field offsets without the use of macros.
@ -3273,14 +3352,18 @@ void ImplementationVisitor::GenerateClassDefinitions(
<< "#include \"torque-generated/class-definitions-tq.h\"\n\n";
implementation << "#include \"torque-generated/class-verifiers-tq.h\"\n\n";
implementation << "#include \"src/objects/struct-inl.h\"\n\n";
implementation
<< "#include "
"\"torque-generated/internal-class-definitions-tq-inl.h\"\n\n";
NamespaceScope implementation_namespaces(implementation,
{"v8", "internal"});
for (const TypeAlias* alias : GlobalContext::GetClasses()) {
const ClassType* type = ClassType::DynamicCast(alias->type());
if (!type->GenerateCppClassDefinitions()) continue;
CppClassGenerator g(type, header, inline_header, implementation);
g.GenerateClass();
if (type->GenerateCppClassDefinitions()) {
CppClassGenerator g(type, header, inline_header, implementation);
g.GenerateClass();
}
}
}
WriteFile(file_basename + ".h", header.str());
@ -3320,6 +3403,8 @@ void ImplementationVisitor::GeneratePrintDefinitions(
impl << "#include \"src/objects/objects.h\"\n\n";
impl << "#include <iosfwd>\n\n";
impl << "#include "
"\"torque-generated/internal-class-definitions-tq-inl.h\"\n";
impl << "#include \"src/objects/struct-inl.h\"\n\n";
impl << "#include \"src/objects/template-objects-inl.h\"\n\n";
@ -3329,7 +3414,7 @@ void ImplementationVisitor::GeneratePrintDefinitions(
const ClassType* type = ClassType::DynamicCast(alias->type());
if (!type->ShouldGeneratePrint()) continue;
if (type->IsExtern() && type->GenerateCppClassDefinitions()) {
if (type->GenerateCppClassDefinitions()) {
const ClassType* super = type->GetSuperClass();
std::string gen_name = "TorqueGenerated" + type->name();
std::string gen_name_T =
@ -3428,6 +3513,8 @@ void ImplementationVisitor::GenerateClassVerifiers(
cc_contents << "#include " << StringLiteralQuote(include_path) << "\n";
}
cc_contents << "#include \"torque-generated/" << file_name << ".h\"\n";
cc_contents << "#include "
"\"torque-generated/internal-class-definitions-tq-inl.h\"\n";
IncludeObjectMacrosScope object_macros(cc_contents);
@ -3438,7 +3525,7 @@ void ImplementationVisitor::GenerateClassVerifiers(
h_contents << "class Isolate;\n";
for (const TypeAlias* alias : GlobalContext::GetClasses()) {
const ClassType* type = ClassType::DynamicCast(alias->type());
if (!type->IsExtern() || !type->ShouldGenerateVerify()) continue;
if (!type->ShouldGenerateVerify()) continue;
h_contents << "class " << type->name() << ";\n";
}
@ -3450,7 +3537,7 @@ void ImplementationVisitor::GenerateClassVerifiers(
for (const TypeAlias* alias : GlobalContext::GetClasses()) {
const ClassType* type = ClassType::DynamicCast(alias->type());
std::string name = type->name();
if (!type->IsExtern() || !type->ShouldGenerateVerify()) continue;
if (!type->ShouldGenerateVerify()) continue;
std::string method_name = name + "Verify";
@ -3513,6 +3600,8 @@ void ImplementationVisitor::GenerateExportedMacrosAssembler(
h_contents << "#include \"src/compiler/code-assembler.h\"\n";
h_contents << "#include \"src/execution/frames.h\"\n";
h_contents << "#include \"torque-generated/csa-types-tq.h\"\n";
h_contents
<< "#include \"torque-generated/internal-class-definitions-tq.h\"\n";
cc_contents << "#include \"torque-generated/" << file_name << ".h\"\n";
for (SourceId file : SourceFileMap::AllSources()) {

View File

@ -174,7 +174,7 @@ class LocationReference {
struct InitializerResults {
std::vector<Identifier*> names;
NameValueMap field_value_map;
std::map<std::string, VisitResult> field_value_map;
};
template <class T>
@ -352,9 +352,11 @@ class ImplementationVisitor {
void GenerateClassFieldOffsets(const std::string& output_directory);
void GeneratePrintDefinitions(const std::string& output_directory);
void GenerateClassDefinitions(const std::string& output_directory);
void GenerateInstanceTypes(const std::string& output_directory);
void GenerateClassVerifiers(const std::string& output_directory);
void GenerateExportedMacrosAssembler(const std::string& output_directory);
void GenerateCSATypes(const std::string& output_directory);
void GenerateCppForInternalClasses(const std::string& output_directory);
VisitResult Visit(Expression* expr);
const Type* Visit(Statement* stmt);

View File

@ -85,6 +85,8 @@ void CompileCurrentAst(TorqueCompilerOptions options) {
implementation_visitor.GenerateClassVerifiers(output_directory);
implementation_visitor.GenerateExportedMacrosAssembler(output_directory);
implementation_visitor.GenerateCSATypes(output_directory);
implementation_visitor.GenerateInstanceTypes(output_directory);
implementation_visitor.GenerateCppForInternalClasses(output_directory);
implementation_visitor.EndCSAFiles();
implementation_visitor.GenerateImplementation(output_directory);

View File

@ -107,6 +107,10 @@ class TypeOracle : public ContextualClass<TypeOracle> {
return Get().GetBuiltinType(CONSTEXPR_INTPTR_TYPE_STRING);
}
static const Type* GetConstexprInstanceTypeType() {
return Get().GetBuiltinType(CONSTEXPR_INSTANCE_TYPE_TYPE_STRING);
}
static const Type* GetVoidType() {
return Get().GetBuiltinType(VOID_TYPE_STRING);
}

View File

@ -162,15 +162,24 @@ const ClassType* TypeVisitor::ComputeType(ClassDeclaration* decl) {
new_class = TypeOracle::GetClassType(super_type, decl->name->value,
decl->flags, generates, decl, alias);
} else {
if (decl->super) {
ReportError("Only extern classes can inherit.");
if (!decl->super) {
ReportError("Intern class ", decl->name->value,
" must extend class Struct.");
}
const Type* super_type = TypeVisitor::ComputeType(*decl->super);
const ClassType* super_class = ClassType::DynamicCast(super_type);
const Type* struct_type = Declarations::LookupGlobalType("Struct");
if (!super_class || super_class != struct_type) {
ReportError("Intern class ", decl->name->value,
" must extend class Struct.");
}
if (decl->generates) {
ReportError("Only extern classes can specify a generated type.");
}
new_class =
TypeOracle::GetClassType(TypeOracle::GetTaggedType(), decl->name->value,
decl->flags, "FixedArray", decl, alias);
new_class = TypeOracle::GetClassType(
super_type, decl->name->value,
decl->flags | ClassFlag::kGeneratePrint | ClassFlag::kGenerateVerify,
decl->name->value, decl, alias);
}
return new_class;
}

View File

@ -349,7 +349,7 @@ void ClassType::Finalize() const {
TypeVisitor::VisitClassFieldsAndMethods(const_cast<ClassType*>(this),
this->decl_);
is_finalized_ = true;
if (GenerateCppClassDefinitions()) {
if (GenerateCppClassDefinitions() || !IsExtern()) {
for (const Field& f : fields()) {
if (f.is_weak) {
Error("Generation of C++ class for Torque class ", name(),

View File

@ -282,6 +282,8 @@ class V8_EXPORT_PRIVATE BuiltinPointerType final : public Type {
}
size_t function_pointer_type_id() const { return function_pointer_type_id_; }
std::vector<std::string> GetRuntimeTypes() const override { return {"Smi"}; }
private:
friend class TypeOracle;
BuiltinPointerType(const Type* parent, TypeVector parameter_types,
@ -526,10 +528,10 @@ class ClassType final : public AggregateType {
std::string GetGeneratedTNodeTypeNameImpl() const override;
bool IsExtern() const { return flags_ & ClassFlag::kExtern; }
bool ShouldGeneratePrint() const {
return flags_ & ClassFlag::kGeneratePrint;
return flags_ & ClassFlag::kGeneratePrint || !IsExtern();
}
bool ShouldGenerateVerify() const {
return flags_ & ClassFlag::kGenerateVerify;
return flags_ & ClassFlag::kGenerateVerify || !IsExtern();
}
bool IsTransient() const override { return flags_ & ClassFlag::kTransient; }
bool IsAbstract() const { return flags_ & ClassFlag::kAbstract; }
@ -540,7 +542,7 @@ class ClassType final : public AggregateType {
return flags_ & ClassFlag::kHasSameInstanceTypeAsParent;
}
bool GenerateCppClassDefinitions() const {
return flags_ & ClassFlag::kGenerateCppClassDefinitions;
return flags_ & ClassFlag::kGenerateCppClassDefinitions || !IsExtern();
}
bool HasIndexedField() const override;
size_t size() const { return size_; }
@ -606,8 +608,6 @@ class VisitResult {
base::Optional<StackRange> stack_range_;
};
using NameValueMap = std::map<std::string, VisitResult>;
VisitResult ProjectStructField(VisitResult structure,
const std::string& fieldname);

View File

@ -246,6 +246,19 @@ std::string CamelifyString(const std::string& underscore_string) {
return result;
}
std::string SnakeifyString(const std::string& camel_string) {
std::string result;
bool previousWasLower = false;
for (auto current : camel_string) {
if (previousWasLower && isupper(current)) {
result += "_";
}
result += tolower(current);
previousWasLower = (islower(current));
}
return result;
}
std::string DashifyString(const std::string& underscore_string) {
std::string result = underscore_string;
std::replace(result.begin(), result.end(), '_', '-');

View File

@ -94,6 +94,7 @@ template <class... Args>
std::string CapifyStringWithUnderscores(const std::string& camellified_string);
std::string CamelifyString(const std::string& underscore_string);
std::string SnakeifyString(const std::string& camel_string);
std::string DashifyString(const std::string& underscore_string);
std::string UnderlinifyPath(std::string path);

View File

@ -820,7 +820,7 @@ namespace test {
check(a.b.GetX() == 2);
}
class InternalClass {
class InternalClass extends Struct {
Flip() labels NotASmi {
const tmp = Cast<Smi>(this.b) otherwise NotASmi;
this.b = this.a;
@ -878,7 +878,7 @@ namespace test {
return new FixedArray{map: kFixedArrayMap, length: 5, objects: ...i};
}
class SmiPair {
class SmiPair extends Struct {
GetA():&Smi {
return & this.a;
}
@ -908,7 +908,7 @@ namespace test {
StaticAssert(1 + 2 == 3);
}
class SmiBox {
class SmiBox extends Struct {
value: Smi;
unrelated: Smi;
}

View File

@ -14,7 +14,7 @@
// https://github.com/python/cpython/blob/master/Objects/listsort.txt
namespace array {
class SortState {
class SortState extends Struct {
Compare(implicit context: Context)(x: Object, y: Object): Number {
const sortCompare: CompareBuiltinFn = this.sortComparePtr;
return sortCompare(context, this.userCmpFn, x, y);

View File

@ -77,55 +77,59 @@ INSTANCE_TYPES = {
113: "PROMISE_REJECT_REACTION_JOB_TASK_TYPE",
114: "PROMISE_RESOLVE_THENABLE_JOB_TASK_TYPE",
115: "FINALIZATION_GROUP_CLEANUP_JOB_TASK_TYPE",
116: "ALLOCATION_SITE_TYPE",
117: "EMBEDDER_DATA_ARRAY_TYPE",
118: "FIXED_ARRAY_TYPE",
119: "OBJECT_BOILERPLATE_DESCRIPTION_TYPE",
120: "CLOSURE_FEEDBACK_CELL_ARRAY_TYPE",
121: "HASH_TABLE_TYPE",
122: "ORDERED_HASH_MAP_TYPE",
123: "ORDERED_HASH_SET_TYPE",
124: "ORDERED_NAME_DICTIONARY_TYPE",
125: "NAME_DICTIONARY_TYPE",
126: "GLOBAL_DICTIONARY_TYPE",
127: "NUMBER_DICTIONARY_TYPE",
128: "SIMPLE_NUMBER_DICTIONARY_TYPE",
129: "STRING_TABLE_TYPE",
130: "EPHEMERON_HASH_TABLE_TYPE",
131: "SCOPE_INFO_TYPE",
132: "SCRIPT_CONTEXT_TABLE_TYPE",
133: "AWAIT_CONTEXT_TYPE",
134: "BLOCK_CONTEXT_TYPE",
135: "CATCH_CONTEXT_TYPE",
136: "DEBUG_EVALUATE_CONTEXT_TYPE",
137: "EVAL_CONTEXT_TYPE",
138: "FUNCTION_CONTEXT_TYPE",
139: "MODULE_CONTEXT_TYPE",
140: "NATIVE_CONTEXT_TYPE",
141: "SCRIPT_CONTEXT_TYPE",
142: "WITH_CONTEXT_TYPE",
143: "WEAK_FIXED_ARRAY_TYPE",
144: "TRANSITION_ARRAY_TYPE",
145: "CALL_HANDLER_INFO_TYPE",
146: "CELL_TYPE",
147: "CODE_DATA_CONTAINER_TYPE",
148: "DESCRIPTOR_ARRAY_TYPE",
149: "FEEDBACK_CELL_TYPE",
150: "FEEDBACK_VECTOR_TYPE",
151: "LOAD_HANDLER_TYPE",
152: "PREPARSE_DATA_TYPE",
153: "PROPERTY_ARRAY_TYPE",
154: "PROPERTY_CELL_TYPE",
155: "SHARED_FUNCTION_INFO_TYPE",
156: "SMALL_ORDERED_HASH_MAP_TYPE",
157: "SMALL_ORDERED_HASH_SET_TYPE",
158: "SMALL_ORDERED_NAME_DICTIONARY_TYPE",
159: "SOURCE_TEXT_MODULE_TYPE",
160: "STORE_HANDLER_TYPE",
161: "UNCOMPILED_DATA_WITHOUT_PREPARSE_DATA_TYPE",
162: "UNCOMPILED_DATA_WITH_PREPARSE_DATA_TYPE",
163: "WEAK_ARRAY_LIST_TYPE",
164: "WEAK_CELL_TYPE",
116: "INTERNAL_CLASS_TYPE",
117: "SMI_PAIR_TYPE",
118: "SMI_BOX_TYPE",
119: "SORT_STATE_TYPE",
120: "ALLOCATION_SITE_TYPE",
121: "EMBEDDER_DATA_ARRAY_TYPE",
122: "FIXED_ARRAY_TYPE",
123: "OBJECT_BOILERPLATE_DESCRIPTION_TYPE",
124: "CLOSURE_FEEDBACK_CELL_ARRAY_TYPE",
125: "HASH_TABLE_TYPE",
126: "ORDERED_HASH_MAP_TYPE",
127: "ORDERED_HASH_SET_TYPE",
128: "ORDERED_NAME_DICTIONARY_TYPE",
129: "NAME_DICTIONARY_TYPE",
130: "GLOBAL_DICTIONARY_TYPE",
131: "NUMBER_DICTIONARY_TYPE",
132: "SIMPLE_NUMBER_DICTIONARY_TYPE",
133: "STRING_TABLE_TYPE",
134: "EPHEMERON_HASH_TABLE_TYPE",
135: "SCOPE_INFO_TYPE",
136: "SCRIPT_CONTEXT_TABLE_TYPE",
137: "AWAIT_CONTEXT_TYPE",
138: "BLOCK_CONTEXT_TYPE",
139: "CATCH_CONTEXT_TYPE",
140: "DEBUG_EVALUATE_CONTEXT_TYPE",
141: "EVAL_CONTEXT_TYPE",
142: "FUNCTION_CONTEXT_TYPE",
143: "MODULE_CONTEXT_TYPE",
144: "NATIVE_CONTEXT_TYPE",
145: "SCRIPT_CONTEXT_TYPE",
146: "WITH_CONTEXT_TYPE",
147: "WEAK_FIXED_ARRAY_TYPE",
148: "TRANSITION_ARRAY_TYPE",
149: "CALL_HANDLER_INFO_TYPE",
150: "CELL_TYPE",
151: "CODE_DATA_CONTAINER_TYPE",
152: "DESCRIPTOR_ARRAY_TYPE",
153: "FEEDBACK_CELL_TYPE",
154: "FEEDBACK_VECTOR_TYPE",
155: "LOAD_HANDLER_TYPE",
156: "PREPARSE_DATA_TYPE",
157: "PROPERTY_ARRAY_TYPE",
158: "PROPERTY_CELL_TYPE",
159: "SHARED_FUNCTION_INFO_TYPE",
160: "SMALL_ORDERED_HASH_MAP_TYPE",
161: "SMALL_ORDERED_HASH_SET_TYPE",
162: "SMALL_ORDERED_NAME_DICTIONARY_TYPE",
163: "SOURCE_TEXT_MODULE_TYPE",
164: "STORE_HANDLER_TYPE",
165: "UNCOMPILED_DATA_WITHOUT_PREPARSE_DATA_TYPE",
166: "UNCOMPILED_DATA_WITH_PREPARSE_DATA_TYPE",
167: "WEAK_ARRAY_LIST_TYPE",
168: "WEAK_CELL_TYPE",
1024: "JS_PROXY_TYPE",
1025: "JS_GLOBAL_OBJECT_TYPE",
1026: "JS_GLOBAL_PROXY_TYPE",
@ -189,8 +193,8 @@ KNOWN_MAPS = {
("read_only_space", 0x00139): (74, "FreeSpaceMap"),
("read_only_space", 0x00189): (68, "MetaMap"),
("read_only_space", 0x00209): (67, "NullMap"),
("read_only_space", 0x00271): (148, "DescriptorArrayMap"),
("read_only_space", 0x002d1): (143, "WeakFixedArrayMap"),
("read_only_space", 0x00271): (152, "DescriptorArrayMap"),
("read_only_space", 0x002d1): (147, "WeakFixedArrayMap"),
("read_only_space", 0x00321): (77, "OnePointerFillerMap"),
("read_only_space", 0x00371): (77, "TwoPointerFillerMap"),
("read_only_space", 0x003f1): (67, "UninitializedMap"),
@ -200,72 +204,72 @@ KNOWN_MAPS = {
("read_only_space", 0x005e1): (67, "TheHoleMap"),
("read_only_space", 0x00689): (67, "BooleanMap"),
("read_only_space", 0x00761): (72, "ByteArrayMap"),
("read_only_space", 0x007b1): (118, "FixedArrayMap"),
("read_only_space", 0x00801): (118, "FixedCOWArrayMap"),
("read_only_space", 0x00851): (121, "HashTableMap"),
("read_only_space", 0x007b1): (122, "FixedArrayMap"),
("read_only_space", 0x00801): (122, "FixedCOWArrayMap"),
("read_only_space", 0x00851): (125, "HashTableMap"),
("read_only_space", 0x008a1): (64, "SymbolMap"),
("read_only_space", 0x008f1): (40, "OneByteStringMap"),
("read_only_space", 0x00941): (131, "ScopeInfoMap"),
("read_only_space", 0x00991): (155, "SharedFunctionInfoMap"),
("read_only_space", 0x00941): (135, "ScopeInfoMap"),
("read_only_space", 0x00991): (159, "SharedFunctionInfoMap"),
("read_only_space", 0x009e1): (69, "CodeMap"),
("read_only_space", 0x00a31): (138, "FunctionContextMap"),
("read_only_space", 0x00a81): (146, "CellMap"),
("read_only_space", 0x00ad1): (154, "GlobalPropertyCellMap"),
("read_only_space", 0x00a31): (142, "FunctionContextMap"),
("read_only_space", 0x00a81): (150, "CellMap"),
("read_only_space", 0x00ad1): (158, "GlobalPropertyCellMap"),
("read_only_space", 0x00b21): (71, "ForeignMap"),
("read_only_space", 0x00b71): (144, "TransitionArrayMap"),
("read_only_space", 0x00bc1): (150, "FeedbackVectorMap"),
("read_only_space", 0x00b71): (148, "TransitionArrayMap"),
("read_only_space", 0x00bc1): (154, "FeedbackVectorMap"),
("read_only_space", 0x00c61): (67, "ArgumentsMarkerMap"),
("read_only_space", 0x00d01): (67, "ExceptionMap"),
("read_only_space", 0x00da1): (67, "TerminationExceptionMap"),
("read_only_space", 0x00e49): (67, "OptimizedOutMap"),
("read_only_space", 0x00ee9): (67, "StaleRegisterMap"),
("read_only_space", 0x00f59): (140, "NativeContextMap"),
("read_only_space", 0x00fa9): (139, "ModuleContextMap"),
("read_only_space", 0x00ff9): (137, "EvalContextMap"),
("read_only_space", 0x01049): (141, "ScriptContextMap"),
("read_only_space", 0x01099): (133, "AwaitContextMap"),
("read_only_space", 0x010e9): (134, "BlockContextMap"),
("read_only_space", 0x01139): (135, "CatchContextMap"),
("read_only_space", 0x01189): (142, "WithContextMap"),
("read_only_space", 0x011d9): (136, "DebugEvaluateContextMap"),
("read_only_space", 0x01229): (132, "ScriptContextTableMap"),
("read_only_space", 0x01279): (120, "ClosureFeedbackCellArrayMap"),
("read_only_space", 0x00f59): (144, "NativeContextMap"),
("read_only_space", 0x00fa9): (143, "ModuleContextMap"),
("read_only_space", 0x00ff9): (141, "EvalContextMap"),
("read_only_space", 0x01049): (145, "ScriptContextMap"),
("read_only_space", 0x01099): (137, "AwaitContextMap"),
("read_only_space", 0x010e9): (138, "BlockContextMap"),
("read_only_space", 0x01139): (139, "CatchContextMap"),
("read_only_space", 0x01189): (146, "WithContextMap"),
("read_only_space", 0x011d9): (140, "DebugEvaluateContextMap"),
("read_only_space", 0x01229): (136, "ScriptContextTableMap"),
("read_only_space", 0x01279): (124, "ClosureFeedbackCellArrayMap"),
("read_only_space", 0x012c9): (76, "FeedbackMetadataArrayMap"),
("read_only_space", 0x01319): (118, "ArrayListMap"),
("read_only_space", 0x01319): (122, "ArrayListMap"),
("read_only_space", 0x01369): (66, "BigIntMap"),
("read_only_space", 0x013b9): (119, "ObjectBoilerplateDescriptionMap"),
("read_only_space", 0x013b9): (123, "ObjectBoilerplateDescriptionMap"),
("read_only_space", 0x01409): (73, "BytecodeArrayMap"),
("read_only_space", 0x01459): (147, "CodeDataContainerMap"),
("read_only_space", 0x01459): (151, "CodeDataContainerMap"),
("read_only_space", 0x014a9): (75, "FixedDoubleArrayMap"),
("read_only_space", 0x014f9): (126, "GlobalDictionaryMap"),
("read_only_space", 0x01549): (149, "ManyClosuresCellMap"),
("read_only_space", 0x01599): (118, "ModuleInfoMap"),
("read_only_space", 0x014f9): (130, "GlobalDictionaryMap"),
("read_only_space", 0x01549): (153, "ManyClosuresCellMap"),
("read_only_space", 0x01599): (122, "ModuleInfoMap"),
("read_only_space", 0x015e9): (70, "MutableHeapNumberMap"),
("read_only_space", 0x01639): (159, "SourceTextModuleMap"),
("read_only_space", 0x01689): (125, "NameDictionaryMap"),
("read_only_space", 0x016d9): (149, "NoClosuresCellMap"),
("read_only_space", 0x01729): (127, "NumberDictionaryMap"),
("read_only_space", 0x01779): (149, "OneClosureCellMap"),
("read_only_space", 0x017c9): (122, "OrderedHashMapMap"),
("read_only_space", 0x01819): (123, "OrderedHashSetMap"),
("read_only_space", 0x01869): (124, "OrderedNameDictionaryMap"),
("read_only_space", 0x018b9): (152, "PreparseDataMap"),
("read_only_space", 0x01909): (153, "PropertyArrayMap"),
("read_only_space", 0x01959): (145, "SideEffectCallHandlerInfoMap"),
("read_only_space", 0x019a9): (145, "SideEffectFreeCallHandlerInfoMap"),
("read_only_space", 0x019f9): (145, "NextCallSideEffectFreeCallHandlerInfoMap"),
("read_only_space", 0x01a49): (128, "SimpleNumberDictionaryMap"),
("read_only_space", 0x01a99): (118, "SloppyArgumentsElementsMap"),
("read_only_space", 0x01ae9): (156, "SmallOrderedHashMapMap"),
("read_only_space", 0x01b39): (157, "SmallOrderedHashSetMap"),
("read_only_space", 0x01b89): (158, "SmallOrderedNameDictionaryMap"),
("read_only_space", 0x01bd9): (129, "StringTableMap"),
("read_only_space", 0x01c29): (161, "UncompiledDataWithoutPreparseDataMap"),
("read_only_space", 0x01c79): (162, "UncompiledDataWithPreparseDataMap"),
("read_only_space", 0x01cc9): (163, "WeakArrayListMap"),
("read_only_space", 0x01d19): (130, "EphemeronHashTableMap"),
("read_only_space", 0x01d69): (117, "EmbedderDataArrayMap"),
("read_only_space", 0x01db9): (164, "WeakCellMap"),
("read_only_space", 0x01639): (163, "SourceTextModuleMap"),
("read_only_space", 0x01689): (129, "NameDictionaryMap"),
("read_only_space", 0x016d9): (153, "NoClosuresCellMap"),
("read_only_space", 0x01729): (131, "NumberDictionaryMap"),
("read_only_space", 0x01779): (153, "OneClosureCellMap"),
("read_only_space", 0x017c9): (126, "OrderedHashMapMap"),
("read_only_space", 0x01819): (127, "OrderedHashSetMap"),
("read_only_space", 0x01869): (128, "OrderedNameDictionaryMap"),
("read_only_space", 0x018b9): (156, "PreparseDataMap"),
("read_only_space", 0x01909): (157, "PropertyArrayMap"),
("read_only_space", 0x01959): (149, "SideEffectCallHandlerInfoMap"),
("read_only_space", 0x019a9): (149, "SideEffectFreeCallHandlerInfoMap"),
("read_only_space", 0x019f9): (149, "NextCallSideEffectFreeCallHandlerInfoMap"),
("read_only_space", 0x01a49): (132, "SimpleNumberDictionaryMap"),
("read_only_space", 0x01a99): (122, "SloppyArgumentsElementsMap"),
("read_only_space", 0x01ae9): (160, "SmallOrderedHashMapMap"),
("read_only_space", 0x01b39): (161, "SmallOrderedHashSetMap"),
("read_only_space", 0x01b89): (162, "SmallOrderedNameDictionaryMap"),
("read_only_space", 0x01bd9): (133, "StringTableMap"),
("read_only_space", 0x01c29): (165, "UncompiledDataWithoutPreparseDataMap"),
("read_only_space", 0x01c79): (166, "UncompiledDataWithPreparseDataMap"),
("read_only_space", 0x01cc9): (167, "WeakArrayListMap"),
("read_only_space", 0x01d19): (134, "EphemeronHashTableMap"),
("read_only_space", 0x01d69): (121, "EmbedderDataArrayMap"),
("read_only_space", 0x01db9): (168, "WeakCellMap"),
("read_only_space", 0x01e09): (58, "NativeSourceStringMap"),
("read_only_space", 0x01e59): (32, "StringMap"),
("read_only_space", 0x01ea9): (41, "ConsOneByteStringMap"),
@ -322,15 +326,19 @@ KNOWN_MAPS = {
("read_only_space", 0x05831): (113, "PromiseRejectReactionJobTaskMap"),
("read_only_space", 0x05881): (114, "PromiseResolveThenableJobTaskMap"),
("read_only_space", 0x058d1): (115, "FinalizationGroupCleanupJobTaskMap"),
("read_only_space", 0x05921): (116, "AllocationSiteWithWeakNextMap"),
("read_only_space", 0x05971): (116, "AllocationSiteWithoutWeakNextMap"),
("read_only_space", 0x059c1): (151, "LoadHandler1Map"),
("read_only_space", 0x05a11): (151, "LoadHandler2Map"),
("read_only_space", 0x05a61): (151, "LoadHandler3Map"),
("read_only_space", 0x05ab1): (160, "StoreHandler0Map"),
("read_only_space", 0x05b01): (160, "StoreHandler1Map"),
("read_only_space", 0x05b51): (160, "StoreHandler2Map"),
("read_only_space", 0x05ba1): (160, "StoreHandler3Map"),
("read_only_space", 0x05921): (116, "InternalClassMap"),
("read_only_space", 0x05971): (117, "SmiPairMap"),
("read_only_space", 0x059c1): (118, "SmiBoxMap"),
("read_only_space", 0x05a11): (119, "SortStateMap"),
("read_only_space", 0x05a61): (120, "AllocationSiteWithWeakNextMap"),
("read_only_space", 0x05ab1): (120, "AllocationSiteWithoutWeakNextMap"),
("read_only_space", 0x05b01): (155, "LoadHandler1Map"),
("read_only_space", 0x05b51): (155, "LoadHandler2Map"),
("read_only_space", 0x05ba1): (155, "LoadHandler3Map"),
("read_only_space", 0x05bf1): (164, "StoreHandler0Map"),
("read_only_space", 0x05c41): (164, "StoreHandler1Map"),
("read_only_space", 0x05c91): (164, "StoreHandler2Map"),
("read_only_space", 0x05ce1): (164, "StoreHandler3Map"),
("map_space", 0x00139): (1057, "ExternalMap"),
("map_space", 0x00189): (1073, "JSMessageObjectMap"),
}