1. 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
  2. 07 Aug, 2018 1 commit
    • Tobias Tebbi's avatar
      [torque] generate implicit_cast according to VisitResult types · 46952216
      Tobias Tebbi authored
      In the generated CSA, we called overloaded macros while relying on CSA
      subtyping of TNodes. This doesn't work well with overloads, because
      for C++ any TNode subtyping is treated as an implicit conversion, which
      makes these calls ambiguous for C++.
      As a solution, we insert implicit_cast conversions for arguments
      according to the type predicted by Torque. This way, a CSA overload is always
      called with exactly the signature declared in base.tq.
      This has the additional benefit that it validates the signatures declared in
      base.tq, which could previously be too permissive.
      Also, this triggered a bug in structs, where VisitResult's were
      carrying the wrong type.
      
      Bug: v8:7793
      TBR: danno@chromium.org
      Change-Id: I8ed4bfd04793c8a8805a4a3dd5cf2a85c20ce786
      Reviewed-on: https://chromium-review.googlesource.com/1165237
      Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
      Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#54948}
      46952216
  3. 24 Jul, 2018 1 commit
  4. 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
  5. 13 Jul, 2018 1 commit
  6. 05 Jul, 2018 1 commit
    • Daniel Clifford's avatar
      [torque] Simplify handling of VisitResults · 1813e3d5
      Daniel Clifford authored
      Only pass around the unadulterated value identifier in the VisitResult class
      until the very last moment before code generation, at which point the
      declaration that was used to originally define the value is used to generate the
      correct final source code string in the context of a l-value or r-value.
      
      Bug: v8:7793
      Change-Id: Ifd0c0d245b2eb65c7f3ddb1ad4c87ee235c54a82
      Reviewed-on: https://chromium-review.googlesource.com/1125063
      Commit-Queue: Daniel Clifford <danno@chromium.org>
      Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#54229}
      1813e3d5
  7. 03 Jul, 2018 1 commit
    • Tobias Tebbi's avatar
      [torque] fix variables, returns and conditionals with constexpr · 81186ff4
      Tobias Tebbi authored
      Variables/return values with constexpr type cannot have multiple
      assignments. We check this now.
      For conditionals, it is important to always infer a non-constexpr type.
      This CL adds the ability to map any type (including union types) to be
      mapped to their non-constexpr variant. Conditionals infer their type as
      the non-constexpr version of a combination of the two branch types.
      
      In addition, this improves subtyping for constexpr types:
      If A extends B, then constexpr A extends constexpr B.
      This makes it necessary to clean up "constexpr String", which has nothing
      to do with tagged values.
      
      Bug: v8:7793
      Change-Id: Ia4d3cd5dc98f45b0ec89adf05c5c6111a0e51cc6
      Reviewed-on: https://chromium-review.googlesource.com/1122864
      Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
      Reviewed-by: 's avatarDaniel Clifford <danno@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#54167}
      81186ff4
  8. 26 Jun, 2018 1 commit
  9. 19 Jun, 2018 1 commit
  10. 15 Jun, 2018 1 commit
  11. 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
  12. 30 May, 2018 1 commit
  13. 29 May, 2018 2 commits
    • 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
    • Tobias Tebbi's avatar
      [cleanup] improve types in base.tq and use LoadTypedArrayLength everywhere · 54f77c42
      Tobias Tebbi authored
      Bug: v8:7754
      Change-Id: I8548d0e07fabc23bb5f65b1f91683c756195ae1b
      Reviewed-on: https://chromium-review.googlesource.com/1071654Reviewed-by: 's avatarMichael Stanton <mvstanton@chromium.org>
      Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
      Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#53398}
      54f77c42
  14. 22 May, 2018 1 commit
  15. 18 May, 2018 1 commit
  16. 16 May, 2018 1 commit
  17. 08 May, 2018 1 commit
  18. 04 May, 2018 1 commit
    • 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
  19. 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
  20. 24 Apr, 2018 1 commit
  21. 16 Apr, 2018 1 commit
    • Daniel Clifford's avatar
      Torque: Implement a DSL for CSA · a3353da8
      Daniel Clifford authored
      An overview of motivation behind Torque and some of its principles
      can be found here: https://bit.ly/2qAI5Ep
      
      Note that there is quite a bit of work left to do in order to get
      Torque production-ready for any non-trivial amount of code, but
      landing the prototype as-is will allow for much faster iteration.
      
      Bugs will be filed for all of the big-ticket items that are not
      landing blockers but called out in this patch as important to fix.
      
      Cq-Include-Trybots: luci.v8.try:v8_linux_nosnap_rel;luci.v8.try:v8_linux_noi18n_rel_ng
      Change-Id: Ib07af70966d5133dc57344928885478b9c6b8b73
      Reviewed-on: https://chromium-review.googlesource.com/845682
      Commit-Queue: Daniel Clifford <danno@chromium.org>
      Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
      Cr-Commit-Position: refs/heads/master@{#52618}
      a3353da8