1. 16 Jan, 2019 1 commit
    • Daniel Clifford's avatar
      [torque] Implement methods and constructors for structs and classes · b615dfa5
      Daniel Clifford authored
      With the changes in this patch,	it is now possible to add methods to
      both Torque's class and struct types. As a special case, "constructor"
      methods are used to initialize the values of classes and structs when
      they are constructed.
      
      The functionality in this patch	includes:
      
      - The refactoring of class- and struct-handling code to share field
        and method declaration code between both.
      
      - Addition of the "%Allocate" intrinsic that allocates raw bytes to be
        allocated from the V8 GC's NewSpace heap as the basis for freshly
        created, initialized class objects.
      
      - An implementation of a CallMethodExpression AST node that enables
        calling methods and constructors, including special handling of
        passing through the "this" pointer for method calls on structs by
        reference. The syntax for struct construction using "{}" remains as
        before, but now calls the struct's matching constructor rather than
        implicitly initializing the struct fields with the initialization
        arguments. A new syntax for allocation classes is introduced: "new
        ClassName{constructor_param1, constructor_param1, ...}", which
        de-sugars to an %Allocate call followed by a call to the matching
        constructor.
      
      - class	constructors can use the "super" keyword to initialize	their
        super class.
      
      - If classes and struct do not have a constructor, Torque creates a
        default constructor for them based on their field declarations,
        where each field's initial value is assigned to a same-typed
        parameter to the the default constructor. The default constructor's
        parameters are in field-declaration order, and for derived classes,
        the default constructor automatically uses a "super" initialization
        call to initialize inherited fields.
      
      - Class field declarations now automatically create ".field" and
        ".field=" operators that create CSA-compatible object accessors.
      
      - Addition of a no-argument constructor for JSArrays that creates an
        empty, PACKED_SMI_ELEMENTS JSArray using the machinery added
        elsewhere in this patch.
      
      Bug: v8:7793
      Change-Id: I31ce5f4b444656ab999555d780aeeba605666bfa
      Reviewed-on: https://chromium-review.googlesource.com/c/1392192
      Commit-Queue: Daniel Clifford <danno@chromium.org>
      Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#58860}
      b615dfa5
  2. 10 Jan, 2019 1 commit
    • Daniel Clifford's avatar
      [torque]: Class declarations · d0e95c7a
      Daniel Clifford authored
      Class declarations support structured heap data that is a subtype of
      HeapObject. Only fields of Object subtypes (both strong and weak)
      are currently supported (no scalar fields yet).
      
      With this CL, both the field list macro used with the C++
      DEFINE_FIELD_OFFSET_CONSTANTS macro (to make field offset constants) as
      well as the Torque "operator '.field'" macros are generated for the
      classes declared in Torque. This is a first step to removing the
      substantial amount of duplication and boilerplate code
      needed to declare heap object classes.
      
      As a proof of concept, and handful of class field definitions,
      including those for non trivial classes like JSFunction, have been
      moved to Torque.
      
      Bug: v8:7793
      Change-Id: I2fa0b53db65fa6f5fe078fb94e1db3418f908753
      Reviewed-on: https://chromium-review.googlesource.com/c/1373971
      Commit-Queue: Daniel Clifford <danno@chromium.org>
      Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#58704}
      d0e95c7a
  3. 05 Dec, 2018 1 commit
  4. 22 Nov, 2018 1 commit
  5. 21 Nov, 2018 2 commits
  6. 13 Nov, 2018 1 commit
  7. 05 Nov, 2018 3 commits
    • Tobias Tebbi's avatar
      [torque] allow qualified access to different modules/namespaces · ece9156c
      Tobias Tebbi authored
      This introduces a new syntax for identifiers and calls: modulename::foo.
      Such a name is resolved by trying to find a module modulename in one of
      the parent scopes and looking for foo there. So this roughly corresponds
      to C++ qualified namespace lookup.
      
      Bug: v8:7793
      Change-Id: Iedc43e6ebe125cd74575cbbcbf990bbcc0155a1f
      Reviewed-on: https://chromium-review.googlesource.com/c/1309818
      Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
      Reviewed-by: 's avatarDaniel Clifford <danno@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#57238}
      ece9156c
    • Tobias Tebbi's avatar
      [torque] qualified access to CSA assemblers · 23b48920
      Tobias Tebbi authored
      No longer use inheritance to associate Torque-generated assemblers
      with corresponding CSA subclasses. Instead, all references to CSA
      and CSA-derived assemblers are now explicitly qualified, by generating
      a short-lived assembler instance in-place. As a consequence, Torque
      files have to mention the assembler external macros live in.
      The CodeStubAssembler is the default for this and can be omitted.
      As a drive-by cleanup, also distinguish between names that are emitted
      in C++ and names that are intended to be read in error messages. This
      is relevant for generic instantiations, where the generated names are
      rather unreadably mangled.
      
      As a follow-up, it will be easy to allow for qualified access to
      different modules, thus implementing full namespace semantics for
      modules.
      
      Bug: v8:7793
      Change-Id: Ie6f1b6b549b510fb49be2442393d898d5f130950
      Reviewed-on: https://chromium-review.googlesource.com/c/1309636
      Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
      Reviewed-by: 's avatarDaniel Clifford <danno@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#57235}
      23b48920
    • Tobias Tebbi's avatar
      [torque] cleanup generics and scopes · 06c8ce59
      Tobias Tebbi authored
      - Name lookup in module scopes has namespace semantics now: All
        overloads from all parent modules are combined before overload
        resolution.
      - Allow overloads of different callables: runtime-functions,
        macros, builtins, and generics.
      - The duplication between the DeclarationVisitor and the
        ImplementationVisitor is removed: The DeclarationVisitor creates
        declarables for everything except for implicit generic specializations.
        The ImplementationVisitor iterates over declarables.
        The DeclarationVisitor only looks at the header of declarations, not
        at the body.
      - Modules become Declarable's, which will enable them to be nested.
      - Modules replace the existing Scope chain mechanism, which will make it
        easier to inline macros.
      - The DeclarationVisitor and Declarations become stateless. All state is
        moved to contextual variables and the GlobalContext.
      - Implicit specializations are created directly from the
        ImplementationVisitor. This will enable template parameter inference.
      - As a consequence, the list of all builtins is only available after the
        ImplementationVisitor has run. Thus GenerateBuiltinDefinitions has to
        move to the ImplementationVisitor. Also, this makes it necessary to
        resolve the link from function pointer types to example builtins only
        at this point.
      
      
      Bug: v8:7793
      Change-Id: I61cef2fd3e954ab148c252974344a6e38ee2d01d
      Reviewed-on: https://chromium-review.googlesource.com/c/1304294
      Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
      Reviewed-by: 's avatarDaniel Clifford <danno@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#57231}
      06c8ce59
  8. 15 Oct, 2018 1 commit
  9. 08 Oct, 2018 1 commit
    • Daniel Clifford's avatar
      [torque] Allow atomarStatements in otherwise statements · 6f5600e2
      Daniel Clifford authored
      In the process:
      - Convert TryLabelStatements into TryLabelExpressions
      - Change TryLabelExpressions to support only single label blocks and de-sugar
        try/labels into nested try/label statements. This allows the code in a label
        block to goto subsequent labels in the same try/label statement.
      - Make otherwise expressions either take IdentifierExpressions which get
        converted into simple label names OR atomarStatements, which make useful
        non-label operations, like 'break' and 'continue', useful together with
        otherwise. Non-label otherwise statements get de-sugared into try/label
        blocks.
      
      Bug: v8:7793
      Change-Id: Ie56ede6306e2a3182f6aa1bb8750ed418bda01db
      Reviewed-on: https://chromium-review.googlesource.com/c/1266997
      Commit-Queue: Daniel Clifford <danno@chromium.org>
      Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#56447}
      6f5600e2
  10. 04 Oct, 2018 1 commit
  11. 21 Sep, 2018 1 commit
  12. 08 Aug, 2018 1 commit
    • Tobias Tebbi's avatar
      [torque] add typeswitch statement · 91ef86f9
      Tobias Tebbi authored
      This adds a typeswitch statement
      
      typeswitch (e)
      case (x1 : Type1) {
        ...
      } case (x2 : Type2) {
      
      } ...
      ... case (xn : TypeN) {
        ...
      }
      
      This checks to which of the given types the result of evaluating e can
      be cast, in the order in which they are listed. So if an earlier
      type matches, a value of this type won't reach a later case.
      
      The type-checks are performed by calling the cast<T>() macro.
      The type of the argument passed to the cast macro is dependent on the
      case and excludes all types checked earlier. For example, in
      
      const x : Object = ...
      typeswitch (x)
      case (x : Smi) {
        ...
      } case (x : HeapNumber) {
        ...
      } case (x : HeapObject) {
        ...
      }
      
      there will be calls to cast<Smi>(Object) and
      cast<HeapNumber>(HeapObject), because after the Smi check we know that
      x has to be a HeapObject. With the refactored base.tq definition of
      cast, this will generate efficient code and avoid repeating the Smi
      check in the second case.
      
      The type system ensures that all cases are reachable and that the type
      given to the last case is safe without a runtime check (in other words,
      the union of all checked types covers the type of e).
      
      The cases can also be written as
      case (Type) { ... }
      , in which case the switched value is not re-bound with the checked
      type.
      
      Bug: v8:7793
      Change-Id: Iea4aed7465d62b445e3ae0d33f52921912e095e3
      Reviewed-on: https://chromium-review.googlesource.com/1156506
      Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
      Reviewed-by: 's avatarDaniel Clifford <danno@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#54958}
      91ef86f9
  13. 17 Jul, 2018 1 commit
    • Daniel Clifford's avatar
      [torque]: Implement structs · 1062ffb9
      Daniel Clifford authored
      Struct are bundles of value types. They are essentially just shorthand
      for passing around a group of individually defined values.
      
      Struct types are declared like this:
      
        struct A {
          x: Smi;
          y: int32;
        }
      
      and can be constructed explicitly like this:
      
        A{0, 0}
      
      Structs can be used wherever other types are used (e.g. variables,
      parameters, return values) except for parameter/return types of
      builtins and runtime functions.
      
      Struct use field access notation to set/get their values like this:
      
        let a: A = A{0, 0};
        let b: Smi = a.x;
        a.y = 0;
      
      Change-Id: I9fd36a6514c37882831256a49a50809c5db75b56
      Reviewed-on: https://chromium-review.googlesource.com/1122133
      Commit-Queue: Daniel Clifford <danno@chromium.org>
      Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#54501}
      1062ffb9
  14. 16 Jul, 2018 1 commit
  15. 13 Jul, 2018 1 commit
  16. 02 Jul, 2018 1 commit
  17. 22 Jun, 2018 2 commits
  18. 18 Jun, 2018 1 commit
  19. 12 Jun, 2018 1 commit
    • Daniel Clifford's avatar
      [torque] Turn implicit converts/unsafe_casts into generics · bbbfd81c
      Daniel Clifford authored
      In the process:
        - Add strict ordering of Types so that name mangling is consistent
          and build time. Previously, the UnionType stored the union's
          types in a std::set<const Type*>, which did not have a consistent
          ordering of the types in the set.
        - Add a int31 type to enable consistency and correctness of
          handling of 'constexpr int31' values on the C++ side.
        - By removing the "implicit" keyword for operators, there is now
          one less difference between operators and calls, another
          incremental step in unifying operators and calls.
        - Enable external (i.e. C++-defined) generic specializations
        - Add CSA support for checking double ElementsKinds, including
          tests.
        - Clean up some constexpr/non-constexpr handling of ElementsKinds.
      
      Bug: v8:7793
      Change-Id: I27699aba70b98ebf5466e5b62b045d7b1dad62c8
      Reviewed-on: https://chromium-review.googlesource.com/1091155
      Commit-Queue: Daniel Clifford <danno@chromium.org>
      Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#53664}
      bbbfd81c
  20. 06 Jun, 2018 1 commit
    • Daniel Clifford's avatar
      [torque] Implement parameter overloading in generics · 06f2a5c2
      Daniel Clifford authored
      This allows redifinitions of generics with the same name but differing parameter
      type lists, e.g.
      
        macro coerce<Dest: type>(from: HeapObject): Dest;
        coerce<int32>(from: HeapObject): int32 {...}
        macro coerce<Dest: type>(from: Smi): Dest;
        coerce<int32>(from: Smi): int32 {...}
      
      In order to allow multiple overloads of generic macros with the same name,
      a more nuanced lookup of calls has been implemented using the
      ParameterDifference utility class. There is still work to be done to unify
      when ParameterDifference is used for lookup (e.g. removing it from operator
      lookup when operators become simple aliases for macro names), but that work
      will be done in a separate CL.
      
      As part of this CL, the custom handling of "cast<>" operator in the .g4
      grammar has been removed and replaced by a handful of equivalent overloads of
      a generic "cast" macro.
      
      Bug: v8:7793
      Change-Id: Ibb2cdd3d58632b7f7f7ba683499f9688ae07f4f8
      Reviewed-on: https://chromium-review.googlesource.com/1087873
      Commit-Queue: Daniel Clifford <danno@chromium.org>
      Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#53562}
      06f2a5c2
  21. 04 Jun, 2018 1 commit
  22. 29 May, 2018 2 commits
    • Simon Zünd's avatar
      [torque] Add unsafe cast to Torque. · 9ef4df2f
      Simon Zünd authored
      This CL is a proposal to add "checked" casts (CAST in CSA) to the Torque language.
      The CL adds the "unsafe_cast<>" operator that emits a "CAST".
      
      Example:
      
      let n: Number = ...;
      ...
      if (TaggedIsSmi(n)) {
        let m: Smi = unsafe_cast<Smi>(n);
        ...
      }
      
      The cast wont incur a runtime overhead now.
      
      R=tebbi@chromium.org
      
      Change-Id: I9fca90d1d11e61617ba0270e5022fd66200e2195
      Reviewed-on: https://chromium-review.googlesource.com/1070151
      Commit-Queue: Simon Zünd <szuend@google.com>
      Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#53416}
      9ef4df2f
    • Tobias Tebbi's avatar
      [torque] add union types · bf9d2893
      Tobias Tebbi authored
      This adds support for union types to Torque.
      
      There is a new type expression
      A | B
      to form the union of the type expressions A and B.
      This is only possible if A and B have a common supertype, to prevent
      nonsensical unions of types with different representations.
      
      Union types are normalized:
      A | B == B | A
      A | (B | C) == (A | B) | C
      A | A == A
      
      The subtyping rules are defined recursively:
      (A | B) <: C  if  A <: C and B <: C
      A <: (B | C)  if  A <: B or A <: C
      
      This allows to define Object as a union type:
      
      type Tagged generates 'TNode<Object>';
      type Smi extends Tagged generates 'TNode<Smi>';
      type HeapObject extends Tagged generates 'TNode<HeapObject>';
      type Object = Smi | HeapObject;
      
      The type {Tagged} is introduced to have a common supertype of all
      tagged values, but we should not use it directly, because {Object}
      contains the additional information that there is nothing but {Smi}
      and {HeapObject} values.
      
      When mapping union types to CSA types, we select the most specific
      common supertype. For Number and Numeric, we already use union types
      on the CSA side. Since it is not possible to map to CSA union types
      in general, we special-case these two union types to map them to
      the CSA union types we already use.
      
      Bug: v8:7793
      Change-Id: I7a4e466436f55d04012f29ef17acfdb957653908
      Reviewed-on: https://chromium-review.googlesource.com/1076132Reviewed-by: 's avatarMichael Stanton <mvstanton@chromium.org>
      Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#53411}
      bf9d2893
  23. 24 May, 2018 1 commit
  24. 22 May, 2018 2 commits
  25. 18 May, 2018 1 commit
  26. 16 May, 2018 3 commits
  27. 13 May, 2018 1 commit
  28. 08 May, 2018 1 commit
  29. 04 May, 2018 3 commits
    • Daniel Clifford's avatar
      [torque]: Add constexpr keyword/types for compile-time evaluation · aeb86d57
      Daniel Clifford authored
      Torque expressions of type constexpr are evaluated at compile-time
      rather than runtime. They are backed by C++ types rather than
      TNode<X> types, so the macro functions that are called by generated
      C++ code expect values to be computed when the snapshot is generated
      rather than by TurboFan-generated code.
      
      Specifically, "if" statements can have a constexpr modifier. With this
      modifier, a type of "constexpr bool" is expected rather than "bool",
      and in that case instead of generating a CSA BranchIf, it generates
      a C++ "if (<bool expression>)" that generates code for only the true or
      false path based on the bool value at torque-execution (compile time)
      rather than generating both paths (including inserting phi nodes
      for variables modified on either branch at the re-merge at the end
      of the if) and dynamically dispatching to the true or false path
      during d8/Chrome/node.js execution (runtime) using a CSA BranchIf.
      
      Change-Id: I8238e25aaadbfc618847e04556e96a3949ea5a8d
      Reviewed-on: https://chromium-review.googlesource.com/1042085
      Commit-Queue: Daniel Clifford <danno@chromium.org>
      Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#53001}
      aeb86d57
    • Clemens Hammacher's avatar
      [base] Move implicit_cast to macros.h · 1a6cf58b
      Clemens Hammacher authored
      macros.h already not only defines macros, but also templatized helpers
      like {bit_cast} and {arraysize}. Thus {implicit_cast} also belongs
      there.
      
      R=tebbi@chromium.org
      
      Bug: v8:7570
      Change-Id: Iaea6075dad359d62498453575f22d73ca84e2323
      Reviewed-on: https://chromium-review.googlesource.com/1042401
      Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
      Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#52991}
      1a6cf58b
    • Daniel Clifford's avatar
      [Torque]: add assert(), unreachable and debug statements · 9cd8995f
      Daniel Clifford authored
      - In debug builds, 'assert(<expr>)' evaluates and aborts execution
        if the provided Torque expression is false at runtime.
        assert(<expr>) supports the same set of expressions protocols
        as Toruqe's if statement, i.e. both bool values and BranchIf-
        style tests. Upon failure, the assertion prints the Torque
        source code of the failed expression, not the generated CSA
        code.
      - 'unreachable' calls CSA's Unreachable() and signals to Torque
        that code execution cannot continue (i.e. its statement
        returns the 'never' type). In debug builds, the line number
        and position of the statement are printed before breaking.
      - 'debug' calls CSA's DebugBreak(). In debug builds, the line
        number and position of the 'debug' are printed before breaking.
      
      Change-Id: I4efd052536bb402c097a0d5f7be56e154b5b3676
      Reviewed-on: https://chromium-review.googlesource.com/1042570
      Commit-Queue: Daniel Clifford <danno@chromium.org>
      Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#52984}
      9cd8995f
  30. 03 May, 2018 1 commit
    • Daniel Clifford's avatar
      Refactor/cleanup various Torque classes, inclduing making Type a Declarable · 90415437
      Daniel Clifford authored
      This is a preparatory step for implementing generics. Along the way, clean up
      and encapsulate a bunch of code, including:
      
      * Fully encapsulate Scope by adding the new class ScopeChain that provide an
        abstraction for creating and activating scopes.
      * Untangle Modules and Scopes.
      * Unify scope activation so that it is always associated with an AST node
        and triggered by a RAII helper class.
      * Unify (somewhat) how builtins and macros are created, fixing a few
        inconsistencies with when and how parameters and their types are declared.
      * Create a new Declarations class that brokers between the visitor classes and
        the ScopeChain. This moves handling of declaration-related errors out of the
        visitors but also makes it possible to do so without polluting Scope and
        ScopeChain with details about resolving SourcePositions in error cases.
      
      Change-Id: I180017d4cf39ccf5ef1d20b84f53284c252f8d87
      Reviewed-on: https://chromium-review.googlesource.com/1038504
      Commit-Queue: Daniel Clifford <danno@chromium.org>
      Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#52947}
      90415437