• 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
Name
Last commit
Last update
..
Torque.g4 Loading commit data...
TorqueBaseListener.cpp Loading commit data...
TorqueBaseListener.h Loading commit data...
TorqueBaseVisitor.cpp Loading commit data...
TorqueBaseVisitor.h Loading commit data...
TorqueLexer.cpp Loading commit data...
TorqueLexer.h Loading commit data...
TorqueListener.cpp Loading commit data...
TorqueListener.h Loading commit data...
TorqueParser.cpp Loading commit data...
TorqueParser.h Loading commit data...
TorqueVisitor.cpp Loading commit data...
TorqueVisitor.h Loading commit data...
ast-generator.cc Loading commit data...
ast-generator.h Loading commit data...
ast.h Loading commit data...
contextual.h Loading commit data...
declarable.cc Loading commit data...
declarable.h Loading commit data...
declaration-visitor.cc Loading commit data...
declaration-visitor.h Loading commit data...
declarations.cc Loading commit data...
declarations.h Loading commit data...
file-visitor.cc Loading commit data...
file-visitor.h Loading commit data...
global-context.h Loading commit data...
implementation-visitor.cc Loading commit data...
implementation-visitor.h Loading commit data...
scope.cc Loading commit data...
scope.h Loading commit data...
torque.cc Loading commit data...
type-oracle.h Loading commit data...
types.cc Loading commit data...
types.h Loading commit data...
utils.cc Loading commit data...
utils.h Loading commit data...