v8/test
Tobias Tebbi 91ef86f9d1 [torque] add typeswitch statement
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: Daniel Clifford <danno@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54958}
2018-08-08 07:49:42 +00:00
..
benchmarks Reland "[build] Remove legacy isolate configurations" 2018-03-28 12:36:55 +00:00
cctest [torque] add typeswitch statement 2018-08-08 07:49:42 +00:00
common [wasm] Support concurrent patching of jump table. 2018-08-07 11:20:09 +00:00
debugger [tests] Mark debug/es6/debug-scope-default-param-with-eval as CRASH 2018-07-24 09:45:57 +00:00
fuzzer [wasm][fuzzer] Generate more and longer sequences 2018-08-06 14:58:05 +00:00
inspector [utils] Change ReadFile interface 2018-07-31 08:59:00 +00:00
intl Accept Etc/GMT* as a valid time zone id. 2018-08-02 23:23:56 +00:00
js-perf-test Add benchmarks for comparing spread literal with copying schemes for arrays 2018-08-06 13:32:57 +00:00
memory [builtins] Add embedded stats to --serialization-statistics 2018-07-05 12:33:26 +00:00
message [wasm] Make the output of --wasm-trace-memory more understandable 2018-07-19 09:49:36 +00:00
mjsunit [wasm] During instantiation, pending_exceptions dominate new exceptions 2018-08-07 10:44:12 +00:00
mkgrokdump [explicit isolates] Move remaining roots to ReadOnyRoots 2018-07-03 15:26:04 +00:00
mozilla Roll ICU to ICU 62.1 2018-07-11 10:24:26 +00:00
preparser Reland "[build] Remove legacy isolate configurations" 2018-03-28 12:36:55 +00:00
test262 Fix Array lastIndexOf to call [[HasProperty]] before [[Get]] 2018-08-03 08:45:55 +00:00
torque [torque] add typeswitch statement 2018-08-08 07:49:42 +00:00
unittests [wasm] Support concurrent patching of jump table. 2018-08-07 11:20:09 +00:00
wasm-spec-tests [wasm] Update spec tests 2018-07-26 09:54:02 +00:00
webkit [test] Skip slow tests 2018-05-23 14:14:34 +00:00
BUILD.gn Reland "Update GN configs for v8_perf target to allow running perf tests in swarming" 2018-07-17 08:40:17 +00:00