Skip to content

Commit

Permalink
[torque] generate C++ class definitions per Torque file
Browse files Browse the repository at this point in the history
This CL splits the class definitions per .tq file, to realize the
following relationship:
A class defined in src/objects/foo.tq has a C++ definition in
src/objects/foo.h. Torque then generates:

- torque-generated/src/objects/foo-tq.inc
  An include file (no proper header) to be included in src/objects/foo.h
  containing the Torque-generated C++ class definition.

- torque-generated/src/objects/foo-tq-inl.inc
  An include file (no proper header) to be included in
  src/objects/foo-inl.h containing inline function definitions.

- torque-generated/src/objects/foo-tq.cc
  A source file including src/objects/foo-inl.h that contains non-inline
  function definitions.

Advantages of this approach:
- Avoid big monolithic headers and preserve the work that went into
  splitting objects.h
- Moving a definition to Torque keeps everything in the same place
  from a C++ viewpoint, including a fully Torque-generated C++ class
  definition.
- The Torque-generated include files do not need to be independent
  headers, necessary includes or forward declarations can just be added
  to the headers that include them.

Drive-by changes:
A bunch of definitions and files had to be moved or created to realize
a consistent 1:1 relationship between .tq files and C++ headers.


Bug: v8:7793
TBR: hpayer@chromium.org
Change-Id: I239a89a16d0bc856a8669d7c92aeafe24a7c7663
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2470571
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Nico Hartmann <nicohartmann@chromium.org>
Reviewed-by: Seth Brenith <seth.brenith@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#70853}
  • Loading branch information
tebbi authored and Commit Bot committed Oct 28, 2020
1 parent a308d3f commit 03f6029
Show file tree
Hide file tree
Showing 173 changed files with 1,078 additions and 649 deletions.
69 changes: 50 additions & 19 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -1153,8 +1153,8 @@ torque_files = [
"src/builtins/array.tq",
"src/builtins/arraybuffer.tq",
"src/builtins/base.tq",
"src/builtins/bigint.tq",
"src/builtins/boolean.tq",
"src/builtins/builtins-bigint.tq",
"src/builtins/builtins-string.tq",
"src/builtins/cast.tq",
"src/builtins/collections.tq",
Expand Down Expand Up @@ -1249,6 +1249,7 @@ torque_files = [
"src/objects/allocation-site.tq",
"src/objects/api-callbacks.tq",
"src/objects/arguments.tq",
"src/objects/bigint.tq",
"src/objects/cell.tq",
"src/objects/code.tq",
"src/objects/contexts.tq",
Expand All @@ -1263,11 +1264,11 @@ torque_files = [
"src/objects/free-space.tq",
"src/objects/heap-number.tq",
"src/objects/heap-object.tq",
"src/objects/intl-objects.tq",
"src/objects/js-array-buffer.tq",
"src/objects/js-array.tq",
"src/objects/js-collection-iterator.tq",
"src/objects/js-collection.tq",
"src/objects/js-function.tq",
"src/objects/js-generator.tq",
"src/objects/js-objects.tq",
"src/objects/js-promise.tq",
Expand Down Expand Up @@ -1298,14 +1299,29 @@ torque_files = [
"src/objects/struct.tq",
"src/objects/synthetic-module.tq",
"src/objects/template-objects.tq",
"src/objects/template.tq",
"src/objects/templates.tq",
"src/objects/torque-defined-classes.tq",
"src/wasm/wasm-objects.tq",
"test/torque/test-torque.tq",
"third_party/v8/builtins/array-sort.tq",
]

if (!v8_enable_i18n_support) {
torque_files -= [ "src/objects/intl-objects.tq" ]
if (v8_enable_i18n_support) {
torque_files += [
"src/objects/intl-objects.tq",
"src/objects/js-break-iterator.tq",
"src/objects/js-collator.tq",
"src/objects/js-date-time-format.tq",
"src/objects/js-display-names.tq",
"src/objects/js-list-format.tq",
"src/objects/js-locale.tq",
"src/objects/js-number-format.tq",
"src/objects/js-plural-rules.tq",
"src/objects/js-relative-time-format.tq",
"src/objects/js-segment-iterator.tq",
"src/objects/js-segmenter.tq",
"src/objects/js-segments.tq",
]
}

# Template for running torque
Expand Down Expand Up @@ -1348,21 +1364,15 @@ template("run_torque") {
"$target_gen_dir/torque-generated/enum-verifiers.cc",
"$target_gen_dir/torque-generated/objects-printer.cc",
"$target_gen_dir/torque-generated/objects-body-descriptors-inl.inc",
"$target_gen_dir/torque-generated/class-definitions.cc",
"$target_gen_dir/torque-generated/class-definitions-inl.h",
"$target_gen_dir/torque-generated/class-definitions.h",
"$target_gen_dir/torque-generated/class-debug-readers.cc",
"$target_gen_dir/torque-generated/class-debug-readers.h",
"$target_gen_dir/torque-generated/exported-macros-assembler.cc",
"$target_gen_dir/torque-generated/exported-macros-assembler.h",
"$target_gen_dir/torque-generated/csa-types.h",
"$target_gen_dir/torque-generated/instance-types.h",
"$target_gen_dir/torque-generated/internal-class-definitions.h",
"$target_gen_dir/torque-generated/internal-class-definitions-inl.h",
"$target_gen_dir/torque-generated/exported-class-definitions.h",
"$target_gen_dir/torque-generated/exported-class-definitions-inl.h",
"$target_gen_dir/torque-generated/runtime-macros.cc",
"$target_gen_dir/torque-generated/runtime-macros.h",
"$target_gen_dir/torque-generated/class-forward-declarations.h",
]

outputs = []
Expand All @@ -1373,10 +1383,13 @@ template("run_torque") {
}

foreach(file, torque_files) {
filetq = string_replace(file, ".tq", "-tq-csa")
filetq = string_replace(file, ".tq", "-tq")
outputs += [
"$destination_folder/$filetq.cc",
"$destination_folder/$filetq.h",
"$target_gen_dir/torque-generated/$filetq-csa.cc",
"$target_gen_dir/torque-generated/$filetq-csa.h",
"$target_gen_dir/torque-generated/$filetq-inl.inc",
"$target_gen_dir/torque-generated/$filetq.cc",
"$target_gen_dir/torque-generated/$filetq.inc",
]
}

Expand Down Expand Up @@ -1452,10 +1465,10 @@ v8_source_set("torque_generated_initializers") {
"src/torque/runtime-support.h",
]
foreach(file, torque_files) {
filetq = string_replace(file, ".tq", "-tq-csa")
filetq = string_replace(file, ".tq", "-tq")
sources += [
"$target_gen_dir/torque-generated/$filetq.cc",
"$target_gen_dir/torque-generated/$filetq.h",
"$target_gen_dir/torque-generated/$filetq-csa.cc",
"$target_gen_dir/torque-generated/$filetq-csa.h",
]
}

Expand All @@ -1474,13 +1487,21 @@ v8_source_set("torque_generated_definitions") {
public_deps = [ ":v8_maybe_icu" ]

sources = [
"$target_gen_dir/torque-generated/class-definitions.cc",
"$target_gen_dir/torque-generated/class-forward-declarations.h",
"$target_gen_dir/torque-generated/class-verifiers.cc",
"$target_gen_dir/torque-generated/class-verifiers.h",
"$target_gen_dir/torque-generated/factory.cc",
"$target_gen_dir/torque-generated/objects-printer.cc",
"$target_gen_dir/torque-generated/runtime-macros.cc",
]
foreach(file, torque_files) {
filetq = string_replace(file, ".tq", "-tq")
sources += [
"$target_gen_dir/torque-generated/$filetq-inl.inc",
"$target_gen_dir/torque-generated/$filetq.cc",
"$target_gen_dir/torque-generated/$filetq.inc",
]
}

configs = [ ":internal_config" ]
}
Expand Down Expand Up @@ -2825,6 +2846,7 @@ v8_source_set("v8_base_without_compiler") {
"src/numbers/math-random.h",
"src/numbers/strtod.cc",
"src/numbers/strtod.h",
"src/objects/all-objects-inl.h",
"src/objects/allocation-site-inl.h",
"src/objects/allocation-site-scopes-inl.h",
"src/objects/allocation-site-scopes.h",
Expand All @@ -2835,6 +2857,7 @@ v8_source_set("v8_base_without_compiler") {
"src/objects/arguments.h",
"src/objects/backing-store.cc",
"src/objects/backing-store.h",
"src/objects/bigint-inl.h",
"src/objects/bigint.cc",
"src/objects/bigint.h",
"src/objects/cell-inl.h",
Expand All @@ -2851,6 +2874,7 @@ v8_source_set("v8_base_without_compiler") {
"src/objects/contexts-inl.h",
"src/objects/contexts.cc",
"src/objects/contexts.h",
"src/objects/data-handler-inl.h",
"src/objects/data-handler.h",
"src/objects/debug-objects-inl.h",
"src/objects/debug-objects.cc",
Expand Down Expand Up @@ -2880,8 +2904,12 @@ v8_source_set("v8_base_without_compiler") {
"src/objects/field-type.h",
"src/objects/fixed-array-inl.h",
"src/objects/fixed-array.h",
"src/objects/foreign-inl.h",
"src/objects/foreign.h",
"src/objects/frame-array-inl.h",
"src/objects/frame-array.h",
"src/objects/free-space-inl.h",
"src/objects/free-space.h",
"src/objects/function-kind.h",
"src/objects/hash-table-inl.h",
"src/objects/hash-table.h",
Expand Down Expand Up @@ -3049,6 +3077,7 @@ v8_source_set("v8_base_without_compiler") {
"src/objects/string.h",
"src/objects/struct-inl.h",
"src/objects/struct.h",
"src/objects/synthetic-module-inl.h",
"src/objects/synthetic-module.cc",
"src/objects/synthetic-module.h",
"src/objects/tagged-field-inl.h",
Expand All @@ -3064,6 +3093,8 @@ v8_source_set("v8_base_without_compiler") {
"src/objects/template-objects.h",
"src/objects/templates-inl.h",
"src/objects/templates.h",
"src/objects/torque-defined-classes-inl.h",
"src/objects/torque-defined-classes.h",
"src/objects/transitions-inl.h",
"src/objects/transitions.cc",
"src/objects/transitions.h",
Expand Down
1 change: 1 addition & 0 deletions src/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@
#include "src/objects/slots.h"
#include "src/objects/smi.h"
#include "src/objects/stack-frame-info-inl.h"
#include "src/objects/synthetic-module-inl.h"
#include "src/objects/templates.h"
#include "src/objects/value-serializer.h"
#include "src/parsing/parse-info.h"
Expand Down
18 changes: 0 additions & 18 deletions src/builtins/bigint.tq → src/builtins/builtins-bigint.tq
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,6 @@

#include 'src/builtins/builtins-bigint-gen.h'

// TODO(nicohartmann): Discuss whether types used by multiple builtins should be
// in global namespace
extern class BigIntBase extends PrimitiveHeapObject
generates 'TNode<BigInt>' {}

type BigInt extends BigIntBase;

@noVerifier
@hasSameInstanceTypeAsParent
@doNotGenerateCast
extern class MutableBigInt extends BigIntBase generates 'TNode<BigInt>' {
}

Convert<BigInt, MutableBigInt>(i: MutableBigInt): BigInt {
assert(bigint::IsCanonicalized(i));
return %RawDownCast<BigInt>(Convert<BigIntBase>(i));
}

namespace bigint {

const kPositiveSign: uint32 = 0;
Expand Down
1 change: 0 additions & 1 deletion src/compiler/access-builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "src/objects/objects-inl.h"
#include "src/objects/ordered-hash-table.h"
#include "src/objects/source-text-module.h"
#include "torque-generated/exported-class-definitions.h"

namespace v8 {
namespace internal {
Expand Down
3 changes: 1 addition & 2 deletions src/compiler/allocation-builder-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

#include "src/compiler/access-builder.h"
#include "src/compiler/allocation-builder.h"
#include "src/objects/arguments-inl.h"
#include "src/objects/map-inl.h"
#include "torque-generated/exported-class-definitions-inl.h"
#include "torque-generated/exported-class-definitions.h"

namespace v8 {
namespace internal {
Expand Down
1 change: 0 additions & 1 deletion src/compiler/js-create-lowering.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include "src/objects/js-regexp-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/template-objects.h"
#include "torque-generated/exported-class-definitions.h"

namespace v8 {
namespace internal {
Expand Down
2 changes: 1 addition & 1 deletion src/deoptimizer/deoptimizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
#include "src/interpreter/interpreter.h"
#include "src/logging/counters.h"
#include "src/logging/log.h"
#include "src/objects/arguments.h"
#include "src/objects/debug-objects-inl.h"
#include "src/objects/heap-number-inl.h"
#include "src/objects/smi.h"
#include "src/snapshot/embedded/embedded-data.h"
#include "src/tracing/trace-event.h"
#include "torque-generated/exported-class-definitions.h"

// Has to be the last include (doesn't have include guards)
#include "src/objects/object-macros.h"
Expand Down
2 changes: 1 addition & 1 deletion src/diagnostics/basic-block-profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include "src/base/lazy-instance.h"
#include "src/heap/heap-inl.h"
#include "torque-generated/exported-class-definitions-inl.h"
#include "src/objects/shared-function-info-inl.h"

namespace v8 {
namespace internal {
Expand Down
4 changes: 3 additions & 1 deletion src/diagnostics/basic-block-profiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@
#include "src/base/macros.h"
#include "src/base/platform/mutex.h"
#include "src/common/globals.h"
#include "torque-generated/exported-class-definitions.h"
#include "src/objects/shared-function-info.h"

namespace v8 {
namespace internal {

class OnHeapBasicBlockProfilerData;

class BasicBlockProfilerData {
public:
explicit BasicBlockProfilerData(size_t n_blocks);
Expand Down
4 changes: 2 additions & 2 deletions src/diagnostics/objects-debug.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@
#include "src/objects/property-descriptor-object-inl.h"
#include "src/objects/stack-frame-info-inl.h"
#include "src/objects/struct-inl.h"
#include "src/objects/synthetic-module-inl.h"
#include "src/objects/template-objects-inl.h"
#include "src/objects/torque-defined-classes-inl.h"
#include "src/objects/transitions-inl.h"
#include "src/regexp/regexp.h"
#include "src/utils/ostreams.h"
#include "src/wasm/wasm-objects-inl.h"
#include "torque-generated/class-verifiers.h"
#include "torque-generated/exported-class-definitions-inl.h"
#include "torque-generated/internal-class-definitions-inl.h"
#include "torque-generated/runtime-macros.h"

namespace v8 {
Expand Down
59 changes: 3 additions & 56 deletions src/diagnostics/objects-printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,74 +5,21 @@
#include <iomanip>
#include <memory>

#include "src/compiler/node.h"
#include "src/diagnostics/disasm.h"
#include "src/diagnostics/disassembler.h"
#include "src/heap/heap-inl.h" // For InOldSpace.
#include "src/heap/heap-write-barrier-inl.h" // For GetIsolateFromWritableObj.
#include "src/init/bootstrapper.h"
#include "src/interpreter/bytecodes.h"
#include "src/objects/arguments-inl.h"
#include "src/objects/cell-inl.h"
#include "src/objects/all-objects-inl.h"
#include "src/objects/code-kind.h"
#include "src/objects/data-handler-inl.h"
#include "src/objects/debug-objects-inl.h"
#include "src/objects/embedder-data-array-inl.h"
#include "src/objects/embedder-data-slot-inl.h"
#include "src/objects/feedback-cell-inl.h"
#include "src/objects/foreign-inl.h"
#include "src/objects/free-space-inl.h"
#include "src/objects/hash-table-inl.h"
#include "src/objects/heap-number-inl.h"
#include "src/objects/js-array-buffer-inl.h"
#include "src/objects/js-array-inl.h"
#include "src/objects/objects-inl.h"
#include "src/objects/objects.h"
#include "src/snapshot/embedded/embedded-data.h"
#ifdef V8_INTL_SUPPORT
#include "src/objects/js-break-iterator-inl.h"
#include "src/objects/js-collator-inl.h"
#endif // V8_INTL_SUPPORT
#include "src/objects/js-collection-inl.h"
#ifdef V8_INTL_SUPPORT
#include "src/objects/js-date-time-format-inl.h"
#include "src/objects/js-display-names-inl.h"
#endif // V8_INTL_SUPPORT
#include "src/objects/js-generator-inl.h"
#ifdef V8_INTL_SUPPORT
#include "src/objects/js-list-format-inl.h"
#include "src/objects/js-locale-inl.h"
#include "src/objects/js-number-format-inl.h"
#include "src/objects/js-plural-rules-inl.h"
#endif // V8_INTL_SUPPORT
#include "src/objects/js-regexp-inl.h"
#include "src/objects/js-regexp-string-iterator-inl.h"
#ifdef V8_INTL_SUPPORT
#include "src/objects/js-relative-time-format-inl.h"
#include "src/objects/js-segment-iterator-inl.h"
#include "src/objects/js-segmenter-inl.h"
#include "src/objects/js-segments-inl.h"
#endif // V8_INTL_SUPPORT
#include "src/compiler/node.h"
#include "src/objects/js-weak-refs-inl.h"
#include "src/objects/literal-objects-inl.h"
#include "src/objects/microtask-inl.h"
#include "src/objects/module-inl.h"
#include "src/objects/oddball-inl.h"
#include "src/objects/promise-inl.h"
#include "src/objects/property-descriptor-object-inl.h"
#include "src/objects/stack-frame-info-inl.h"
#include "src/objects/string-set-inl.h"
#include "src/objects/struct-inl.h"
#include "src/objects/template-objects-inl.h"
#include "src/objects/transitions-inl.h"
#include "src/regexp/regexp.h"
#include "src/snapshot/embedded/embedded-data.h"
#include "src/utils/ostreams.h"
#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-inl.h"
#include "torque-generated/exported-class-definitions-inl.h"
#include "torque-generated/internal-class-definitions-inl.h"

namespace v8 {
namespace internal {
Expand Down
1 change: 1 addition & 0 deletions src/heap/factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#include "src/objects/stack-frame-info-inl.h"
#include "src/objects/string-set-inl.h"
#include "src/objects/struct-inl.h"
#include "src/objects/synthetic-module-inl.h"
#include "src/objects/template-objects-inl.h"
#include "src/objects/transitions-inl.h"
#include "src/roots/roots.h"
Expand Down
Loading

0 comments on commit 03f6029

Please sign in to comment.