2018-05-13 10:10:44 +00:00
|
|
|
// Copyright 2018 the V8 project authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2020-04-07 11:20:38 +00:00
|
|
|
// Test line comment
|
|
|
|
/* Test mulitline
|
|
|
|
comment
|
|
|
|
*/
|
|
|
|
|
2018-11-13 13:00:34 +00:00
|
|
|
namespace test {
|
2018-05-16 09:45:07 +00:00
|
|
|
macro ElementsKindTestHelper1(kind: constexpr ElementsKind): bool {
|
2019-12-18 15:33:16 +00:00
|
|
|
if constexpr (
|
|
|
|
(kind == ElementsKind::UINT8_ELEMENTS) ||
|
|
|
|
(kind == ElementsKind::UINT16_ELEMENTS)) {
|
2018-09-24 09:28:48 +00:00
|
|
|
return true;
|
|
|
|
} else {
|
2018-05-16 09:45:07 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-05-13 10:10:44 +00:00
|
|
|
|
2019-06-11 12:26:32 +00:00
|
|
|
macro ElementsKindTestHelper2(kind: constexpr ElementsKind): constexpr bool {
|
2019-12-18 15:33:16 +00:00
|
|
|
return (
|
|
|
|
(kind == ElementsKind::UINT8_ELEMENTS) ||
|
|
|
|
(kind == ElementsKind::UINT16_ELEMENTS));
|
2018-05-16 09:45:07 +00:00
|
|
|
}
|
2018-05-13 10:10:44 +00:00
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
macro LabelTestHelper1(): never
|
2018-09-24 09:28:48 +00:00
|
|
|
labels Label1 {
|
2018-05-16 09:45:07 +00:00
|
|
|
goto Label1;
|
|
|
|
}
|
2018-05-13 10:10:44 +00:00
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
macro LabelTestHelper2(): never
|
2018-09-24 09:28:48 +00:00
|
|
|
labels Label2(Smi) {
|
2018-05-16 09:45:07 +00:00
|
|
|
goto Label2(42);
|
|
|
|
}
|
2018-05-13 14:24:08 +00:00
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
macro LabelTestHelper3(): never
|
2019-02-06 16:26:36 +00:00
|
|
|
labels Label3(Oddball, Smi) {
|
|
|
|
goto Label3(Null, 7);
|
2018-05-16 09:45:07 +00:00
|
|
|
}
|
2018-05-13 14:24:08 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-05-16 09:45:07 +00:00
|
|
|
macro TestConstexpr1() {
|
2019-12-18 15:33:16 +00:00
|
|
|
check(FromConstexpr<bool>(
|
|
|
|
IsFastElementsKind(ElementsKind::PACKED_SMI_ELEMENTS)));
|
2018-05-16 09:45:07 +00:00
|
|
|
}
|
2018-05-13 14:24:08 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-05-16 09:45:07 +00:00
|
|
|
macro TestConstexprIf() {
|
2019-12-18 15:33:16 +00:00
|
|
|
check(ElementsKindTestHelper1(ElementsKind::UINT8_ELEMENTS));
|
|
|
|
check(ElementsKindTestHelper1(ElementsKind::UINT16_ELEMENTS));
|
|
|
|
check(!ElementsKindTestHelper1(ElementsKind::UINT32_ELEMENTS));
|
2018-05-16 09:45:07 +00:00
|
|
|
}
|
2018-05-13 10:10:44 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-05-16 09:45:07 +00:00
|
|
|
macro TestConstexprReturn() {
|
2019-12-18 15:33:16 +00:00
|
|
|
check(FromConstexpr<bool>(
|
|
|
|
ElementsKindTestHelper2(ElementsKind::UINT8_ELEMENTS)));
|
|
|
|
check(FromConstexpr<bool>(
|
|
|
|
ElementsKindTestHelper2(ElementsKind::UINT16_ELEMENTS)));
|
|
|
|
check(!FromConstexpr<bool>(
|
|
|
|
ElementsKindTestHelper2(ElementsKind::UINT32_ELEMENTS)));
|
|
|
|
check(FromConstexpr<bool>(
|
|
|
|
!ElementsKindTestHelper2(ElementsKind::UINT32_ELEMENTS)));
|
2018-05-16 09:45:07 +00:00
|
|
|
}
|
2018-05-13 10:10:44 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-05-16 09:45:07 +00:00
|
|
|
macro TestGotoLabel(): Boolean {
|
|
|
|
try {
|
|
|
|
LabelTestHelper1() otherwise Label1;
|
|
|
|
}
|
|
|
|
label Label1 {
|
|
|
|
return True;
|
|
|
|
}
|
|
|
|
}
|
2018-05-13 10:10:44 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-05-16 09:45:07 +00:00
|
|
|
macro TestGotoLabelWithOneParameter(): Boolean {
|
|
|
|
try {
|
|
|
|
LabelTestHelper2() otherwise Label2;
|
|
|
|
}
|
|
|
|
label Label2(smi: Smi) {
|
2018-05-24 14:09:12 +00:00
|
|
|
check(smi == 42);
|
2018-05-16 09:45:07 +00:00
|
|
|
return True;
|
|
|
|
}
|
2018-05-13 14:24:08 +00:00
|
|
|
}
|
2018-05-16 09:45:07 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-05-16 09:45:07 +00:00
|
|
|
macro TestGotoLabelWithTwoParameters(): Boolean {
|
|
|
|
try {
|
|
|
|
LabelTestHelper3() otherwise Label3;
|
|
|
|
}
|
2019-02-06 16:26:36 +00:00
|
|
|
label Label3(o: Oddball, smi: Smi) {
|
|
|
|
check(o == Null);
|
2018-05-24 14:09:12 +00:00
|
|
|
check(smi == 7);
|
2018-05-16 09:45:07 +00:00
|
|
|
return True;
|
|
|
|
}
|
2018-05-13 14:24:08 +00:00
|
|
|
}
|
|
|
|
|
Reland "[torque] introduce JSAny type for user-accessible JavaScript values"
Changes in the reland: Rebased and added a check that JavaScript-linkage
builtins use JSAny in parameters and return type, plus the necessary
cleanups for this test to pass.
Design Doc: https://docs.google.com/document/d/1z6j0pWHnNIfId0v00uWN2HBrGRDJxJfYuCr5K7Kr1xA
This reverts commit 4418a7b96afdf8278577211ab0ed555c41ee269e.
Original change's description:
> Revert "[torque] introduce JSAny type for user-accessible JavaScript values"
>
> This reverts commit 79b00555eac939bf4a00177ec59e21b856d7301c.
>
> Reason for revert: needs more discussion
>
> Original change's description:
> > [torque] introduce JSAny type for user-accessible JavaScript values
> >
> > This CL introduces a JSAny type for user-exposed JavaScript values and
> > a few new types to define it. Especially, it splits Symbol into
> > PrivateSymbol (not exposed) and PublicSymbol (JavaScript exposed
> > symbols).
> >
> > The change is mostly mechanical, but a few things are interesting:
> > - PropertyKey and JSPrimitive were designed to coincide with the spec
> > notions of IsPropertyKey() and primitive value, respectively.
> > - Since Name is an open type, we define AnyName to be the known
> > subtypes of Name. This is not too elegant, but by using AnyName
> > instead of Name, typeswitch can properly conclude something if a
> > subtype of Name is excluded.
> >
> > Small drive-by changes, which were necessary:
> > - Allow subtyping on label parameters.
> > - Fix the formatting of typeswitch, it was broken with union types
> > in case types.
> >
> > Bug: v8:7793
> > Change-Id: I14b10507f8cf316ad85e048fe8d53d1df5e0bb13
> > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1735322
> > Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> > Reviewed-by: Jakob Gruber <jgruber@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#63114}
>
> TBR=neis@chromium.org,jgruber@chromium.org,tebbi@chromium.org
>
> Change-Id: Ifde7881d74afe407628f40047997339d54cb2424
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: v8:7793
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1741652
> Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
> Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#63115}
TBR=neis@chromium.org,jgruber@chromium.org,tebbi@chromium.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: v8:7793
Change-Id: Icca34e3824f55009b984d9348fd21884400f0081
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1769316
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63395}
2019-08-26 12:07:01 +00:00
|
|
|
builtin GenericBuiltinTest<T: type>(_c: Context, _param: T): JSAny {
|
2018-05-16 09:45:07 +00:00
|
|
|
return Null;
|
2018-05-13 14:24:08 +00:00
|
|
|
}
|
2018-05-16 09:45:07 +00:00
|
|
|
|
Reland "[torque] introduce JSAny type for user-accessible JavaScript values"
Changes in the reland: Rebased and added a check that JavaScript-linkage
builtins use JSAny in parameters and return type, plus the necessary
cleanups for this test to pass.
Design Doc: https://docs.google.com/document/d/1z6j0pWHnNIfId0v00uWN2HBrGRDJxJfYuCr5K7Kr1xA
This reverts commit 4418a7b96afdf8278577211ab0ed555c41ee269e.
Original change's description:
> Revert "[torque] introduce JSAny type for user-accessible JavaScript values"
>
> This reverts commit 79b00555eac939bf4a00177ec59e21b856d7301c.
>
> Reason for revert: needs more discussion
>
> Original change's description:
> > [torque] introduce JSAny type for user-accessible JavaScript values
> >
> > This CL introduces a JSAny type for user-exposed JavaScript values and
> > a few new types to define it. Especially, it splits Symbol into
> > PrivateSymbol (not exposed) and PublicSymbol (JavaScript exposed
> > symbols).
> >
> > The change is mostly mechanical, but a few things are interesting:
> > - PropertyKey and JSPrimitive were designed to coincide with the spec
> > notions of IsPropertyKey() and primitive value, respectively.
> > - Since Name is an open type, we define AnyName to be the known
> > subtypes of Name. This is not too elegant, but by using AnyName
> > instead of Name, typeswitch can properly conclude something if a
> > subtype of Name is excluded.
> >
> > Small drive-by changes, which were necessary:
> > - Allow subtyping on label parameters.
> > - Fix the formatting of typeswitch, it was broken with union types
> > in case types.
> >
> > Bug: v8:7793
> > Change-Id: I14b10507f8cf316ad85e048fe8d53d1df5e0bb13
> > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1735322
> > Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> > Reviewed-by: Jakob Gruber <jgruber@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#63114}
>
> TBR=neis@chromium.org,jgruber@chromium.org,tebbi@chromium.org
>
> Change-Id: Ifde7881d74afe407628f40047997339d54cb2424
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: v8:7793
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1741652
> Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
> Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#63115}
TBR=neis@chromium.org,jgruber@chromium.org,tebbi@chromium.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: v8:7793
Change-Id: Icca34e3824f55009b984d9348fd21884400f0081
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1769316
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63395}
2019-08-26 12:07:01 +00:00
|
|
|
GenericBuiltinTest<JSAny>(_c: Context, param: JSAny): JSAny {
|
2018-05-16 09:45:07 +00:00
|
|
|
return param;
|
2018-05-13 14:24:08 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-05-16 09:45:07 +00:00
|
|
|
macro TestBuiltinSpecialization(c: Context) {
|
2018-05-24 14:09:12 +00:00
|
|
|
check(GenericBuiltinTest<Smi>(c, 0) == Null);
|
|
|
|
check(GenericBuiltinTest<Smi>(c, 1) == Null);
|
Reland "[torque] introduce JSAny type for user-accessible JavaScript values"
Changes in the reland: Rebased and added a check that JavaScript-linkage
builtins use JSAny in parameters and return type, plus the necessary
cleanups for this test to pass.
Design Doc: https://docs.google.com/document/d/1z6j0pWHnNIfId0v00uWN2HBrGRDJxJfYuCr5K7Kr1xA
This reverts commit 4418a7b96afdf8278577211ab0ed555c41ee269e.
Original change's description:
> Revert "[torque] introduce JSAny type for user-accessible JavaScript values"
>
> This reverts commit 79b00555eac939bf4a00177ec59e21b856d7301c.
>
> Reason for revert: needs more discussion
>
> Original change's description:
> > [torque] introduce JSAny type for user-accessible JavaScript values
> >
> > This CL introduces a JSAny type for user-exposed JavaScript values and
> > a few new types to define it. Especially, it splits Symbol into
> > PrivateSymbol (not exposed) and PublicSymbol (JavaScript exposed
> > symbols).
> >
> > The change is mostly mechanical, but a few things are interesting:
> > - PropertyKey and JSPrimitive were designed to coincide with the spec
> > notions of IsPropertyKey() and primitive value, respectively.
> > - Since Name is an open type, we define AnyName to be the known
> > subtypes of Name. This is not too elegant, but by using AnyName
> > instead of Name, typeswitch can properly conclude something if a
> > subtype of Name is excluded.
> >
> > Small drive-by changes, which were necessary:
> > - Allow subtyping on label parameters.
> > - Fix the formatting of typeswitch, it was broken with union types
> > in case types.
> >
> > Bug: v8:7793
> > Change-Id: I14b10507f8cf316ad85e048fe8d53d1df5e0bb13
> > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1735322
> > Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> > Reviewed-by: Jakob Gruber <jgruber@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#63114}
>
> TBR=neis@chromium.org,jgruber@chromium.org,tebbi@chromium.org
>
> Change-Id: Ifde7881d74afe407628f40047997339d54cb2424
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: v8:7793
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1741652
> Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
> Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#63115}
TBR=neis@chromium.org,jgruber@chromium.org,tebbi@chromium.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: v8:7793
Change-Id: Icca34e3824f55009b984d9348fd21884400f0081
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1769316
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63395}
2019-08-26 12:07:01 +00:00
|
|
|
check(GenericBuiltinTest<JSAny>(c, Undefined) == Undefined);
|
|
|
|
check(GenericBuiltinTest<JSAny>(c, Undefined) == Undefined);
|
2018-05-13 14:24:08 +00:00
|
|
|
}
|
2018-05-16 09:45:07 +00:00
|
|
|
|
2018-09-24 09:28:48 +00:00
|
|
|
macro LabelTestHelper4(flag: constexpr bool): never
|
|
|
|
labels Label4, Label5 {
|
|
|
|
if constexpr (flag) {
|
2018-08-02 15:10:24 +00:00
|
|
|
goto Label4;
|
|
|
|
} else {
|
2018-05-16 09:45:07 +00:00
|
|
|
goto Label5;
|
2018-08-02 15:10:24 +00:00
|
|
|
}
|
2018-05-13 14:24:08 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 09:45:07 +00:00
|
|
|
macro CallLabelTestHelper4(flag: constexpr bool): bool {
|
|
|
|
try {
|
|
|
|
LabelTestHelper4(flag) otherwise Label4, Label5;
|
|
|
|
}
|
|
|
|
label Label4 {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
label Label5 {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-05-14 10:53:04 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-05-16 09:45:07 +00:00
|
|
|
macro TestPartiallyUnusedLabel(): Boolean {
|
2019-06-11 10:56:10 +00:00
|
|
|
const r1: bool = CallLabelTestHelper4(true);
|
|
|
|
const r2: bool = CallLabelTestHelper4(false);
|
2018-05-16 09:45:07 +00:00
|
|
|
|
2018-08-02 15:10:24 +00:00
|
|
|
if (r1 && !r2) {
|
2018-05-16 09:45:07 +00:00
|
|
|
return True;
|
2018-08-02 15:10:24 +00:00
|
|
|
} else {
|
2018-05-16 09:45:07 +00:00
|
|
|
return False;
|
2018-08-02 15:10:24 +00:00
|
|
|
}
|
2018-05-14 10:53:04 +00:00
|
|
|
}
|
2018-05-16 09:45:07 +00:00
|
|
|
|
2019-06-06 12:41:27 +00:00
|
|
|
macro GenericMacroTest<T: type>(_param: T): Object {
|
2018-05-16 09:45:07 +00:00
|
|
|
return Undefined;
|
2018-05-14 10:53:04 +00:00
|
|
|
}
|
2018-05-16 09:45:07 +00:00
|
|
|
|
|
|
|
GenericMacroTest<Object>(param2: Object): Object {
|
|
|
|
return param2;
|
2018-05-14 10:53:04 +00:00
|
|
|
}
|
|
|
|
|
2019-06-06 12:41:27 +00:00
|
|
|
macro GenericMacroTestWithLabels<T: type>(_param: T): Object
|
|
|
|
labels _X {
|
2018-05-16 09:45:07 +00:00
|
|
|
return Undefined;
|
|
|
|
}
|
2018-05-14 10:53:04 +00:00
|
|
|
|
2018-09-24 09:28:48 +00:00
|
|
|
GenericMacroTestWithLabels<Object>(param2: Object): Object
|
|
|
|
labels Y {
|
2018-10-04 20:45:31 +00:00
|
|
|
return Cast<Smi>(param2) otherwise Y;
|
2018-05-16 09:45:07 +00:00
|
|
|
}
|
2018-05-14 10:53:04 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-05-16 09:45:07 +00:00
|
|
|
macro TestMacroSpecialization() {
|
|
|
|
try {
|
2019-06-06 12:41:27 +00:00
|
|
|
const _smi0: Smi = 0;
|
2018-05-24 14:09:12 +00:00
|
|
|
check(GenericMacroTest<Smi>(0) == Undefined);
|
|
|
|
check(GenericMacroTest<Smi>(1) == Undefined);
|
|
|
|
check(GenericMacroTest<Object>(Null) == Null);
|
|
|
|
check(GenericMacroTest<Object>(False) == False);
|
|
|
|
check(GenericMacroTest<Object>(True) == True);
|
2018-10-08 13:50:46 +00:00
|
|
|
check((GenericMacroTestWithLabels<Smi>(0) otherwise Fail) == Undefined);
|
|
|
|
check((GenericMacroTestWithLabels<Smi>(0) otherwise Fail) == Undefined);
|
2018-10-04 20:45:31 +00:00
|
|
|
try {
|
|
|
|
GenericMacroTestWithLabels<Object>(False) otherwise Expected;
|
|
|
|
}
|
|
|
|
label Expected {}
|
2018-05-16 09:45:07 +00:00
|
|
|
}
|
|
|
|
label Fail {
|
|
|
|
unreachable;
|
|
|
|
}
|
|
|
|
}
|
2018-05-16 14:00:35 +00:00
|
|
|
|
2019-06-06 12:41:27 +00:00
|
|
|
builtin TestHelperPlus1(_context: Context, x: Smi): Smi {
|
2018-05-16 14:00:35 +00:00
|
|
|
return x + 1;
|
|
|
|
}
|
2019-06-06 12:41:27 +00:00
|
|
|
builtin TestHelperPlus2(_context: Context, x: Smi): Smi {
|
2018-05-16 14:00:35 +00:00
|
|
|
return x + 2;
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-11-26 15:14:25 +00:00
|
|
|
macro TestFunctionPointers(implicit context: Context)(): Boolean {
|
2018-07-17 16:20:53 +00:00
|
|
|
let fptr: builtin(Context, Smi) => Smi = TestHelperPlus1;
|
2018-05-24 14:09:12 +00:00
|
|
|
check(fptr(context, 42) == 43);
|
2018-05-16 14:00:35 +00:00
|
|
|
fptr = TestHelperPlus2;
|
2018-05-24 14:09:12 +00:00
|
|
|
check(fptr(context, 42) == 44);
|
2018-05-16 14:00:35 +00:00
|
|
|
return True;
|
|
|
|
}
|
2018-05-18 08:33:36 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-11-26 15:14:25 +00:00
|
|
|
macro TestVariableRedeclaration(implicit context: Context)(): Boolean {
|
2019-06-06 12:41:27 +00:00
|
|
|
let _var1: int31 = FromConstexpr<bool>(42 == 0) ? 0 : 1;
|
|
|
|
let _var2: int31 = FromConstexpr<bool>(42 == 0) ? 1 : 0;
|
2018-05-18 08:33:36 +00:00
|
|
|
return True;
|
|
|
|
}
|
2018-05-22 12:48:29 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-07-17 16:20:53 +00:00
|
|
|
macro TestTernaryOperator(x: Smi): Smi {
|
2019-06-11 10:56:10 +00:00
|
|
|
const b: bool = x < 0 ? true : false;
|
2018-07-03 12:02:05 +00:00
|
|
|
return b ? x - 10 : x + 100;
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-05-22 12:48:29 +00:00
|
|
|
macro TestFunctionPointerToGeneric(c: Context) {
|
Reland "[torque] introduce JSAny type for user-accessible JavaScript values"
Changes in the reland: Rebased and added a check that JavaScript-linkage
builtins use JSAny in parameters and return type, plus the necessary
cleanups for this test to pass.
Design Doc: https://docs.google.com/document/d/1z6j0pWHnNIfId0v00uWN2HBrGRDJxJfYuCr5K7Kr1xA
This reverts commit 4418a7b96afdf8278577211ab0ed555c41ee269e.
Original change's description:
> Revert "[torque] introduce JSAny type for user-accessible JavaScript values"
>
> This reverts commit 79b00555eac939bf4a00177ec59e21b856d7301c.
>
> Reason for revert: needs more discussion
>
> Original change's description:
> > [torque] introduce JSAny type for user-accessible JavaScript values
> >
> > This CL introduces a JSAny type for user-exposed JavaScript values and
> > a few new types to define it. Especially, it splits Symbol into
> > PrivateSymbol (not exposed) and PublicSymbol (JavaScript exposed
> > symbols).
> >
> > The change is mostly mechanical, but a few things are interesting:
> > - PropertyKey and JSPrimitive were designed to coincide with the spec
> > notions of IsPropertyKey() and primitive value, respectively.
> > - Since Name is an open type, we define AnyName to be the known
> > subtypes of Name. This is not too elegant, but by using AnyName
> > instead of Name, typeswitch can properly conclude something if a
> > subtype of Name is excluded.
> >
> > Small drive-by changes, which were necessary:
> > - Allow subtyping on label parameters.
> > - Fix the formatting of typeswitch, it was broken with union types
> > in case types.
> >
> > Bug: v8:7793
> > Change-Id: I14b10507f8cf316ad85e048fe8d53d1df5e0bb13
> > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1735322
> > Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> > Reviewed-by: Jakob Gruber <jgruber@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#63114}
>
> TBR=neis@chromium.org,jgruber@chromium.org,tebbi@chromium.org
>
> Change-Id: Ifde7881d74afe407628f40047997339d54cb2424
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: v8:7793
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1741652
> Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
> Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#63115}
TBR=neis@chromium.org,jgruber@chromium.org,tebbi@chromium.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: v8:7793
Change-Id: Icca34e3824f55009b984d9348fd21884400f0081
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1769316
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63395}
2019-08-26 12:07:01 +00:00
|
|
|
const fptr1: builtin(Context, Smi) => JSAny = GenericBuiltinTest<Smi>;
|
|
|
|
const fptr2: builtin(Context, JSAny) => JSAny = GenericBuiltinTest<JSAny>;
|
2018-05-22 12:48:29 +00:00
|
|
|
|
2018-05-24 14:09:12 +00:00
|
|
|
check(fptr1(c, 0) == Null);
|
|
|
|
check(fptr1(c, 1) == Null);
|
|
|
|
check(fptr2(c, Undefined) == Undefined);
|
|
|
|
check(fptr2(c, Undefined) == Undefined);
|
2018-05-22 12:48:29 +00:00
|
|
|
}
|
2018-05-22 21:11:39 +00:00
|
|
|
|
Reland "[torque] introduce JSAny type for user-accessible JavaScript values"
Changes in the reland: Rebased and added a check that JavaScript-linkage
builtins use JSAny in parameters and return type, plus the necessary
cleanups for this test to pass.
Design Doc: https://docs.google.com/document/d/1z6j0pWHnNIfId0v00uWN2HBrGRDJxJfYuCr5K7Kr1xA
This reverts commit 4418a7b96afdf8278577211ab0ed555c41ee269e.
Original change's description:
> Revert "[torque] introduce JSAny type for user-accessible JavaScript values"
>
> This reverts commit 79b00555eac939bf4a00177ec59e21b856d7301c.
>
> Reason for revert: needs more discussion
>
> Original change's description:
> > [torque] introduce JSAny type for user-accessible JavaScript values
> >
> > This CL introduces a JSAny type for user-exposed JavaScript values and
> > a few new types to define it. Especially, it splits Symbol into
> > PrivateSymbol (not exposed) and PublicSymbol (JavaScript exposed
> > symbols).
> >
> > The change is mostly mechanical, but a few things are interesting:
> > - PropertyKey and JSPrimitive were designed to coincide with the spec
> > notions of IsPropertyKey() and primitive value, respectively.
> > - Since Name is an open type, we define AnyName to be the known
> > subtypes of Name. This is not too elegant, but by using AnyName
> > instead of Name, typeswitch can properly conclude something if a
> > subtype of Name is excluded.
> >
> > Small drive-by changes, which were necessary:
> > - Allow subtyping on label parameters.
> > - Fix the formatting of typeswitch, it was broken with union types
> > in case types.
> >
> > Bug: v8:7793
> > Change-Id: I14b10507f8cf316ad85e048fe8d53d1df5e0bb13
> > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1735322
> > Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> > Reviewed-by: Jakob Gruber <jgruber@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#63114}
>
> TBR=neis@chromium.org,jgruber@chromium.org,tebbi@chromium.org
>
> Change-Id: Ifde7881d74afe407628f40047997339d54cb2424
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: v8:7793
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1741652
> Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
> Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#63115}
TBR=neis@chromium.org,jgruber@chromium.org,tebbi@chromium.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: v8:7793
Change-Id: Icca34e3824f55009b984d9348fd21884400f0081
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1769316
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63395}
2019-08-26 12:07:01 +00:00
|
|
|
type ObjectToObject = builtin(Context, JSAny) => JSAny;
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-12-17 13:41:53 +00:00
|
|
|
macro TestTypeAlias(x: ObjectToObject): BuiltinPtr {
|
2018-05-22 21:11:39 +00:00
|
|
|
return x;
|
|
|
|
}
|
2018-05-29 14:18:39 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-11-26 15:14:25 +00:00
|
|
|
macro TestUnsafeCast(implicit context: Context)(n: Number): Boolean {
|
2018-05-29 14:18:39 +00:00
|
|
|
if (TaggedIsSmi(n)) {
|
2019-06-11 10:56:10 +00:00
|
|
|
const m: Smi = UnsafeCast<Smi>(n);
|
2018-05-29 14:18:39 +00:00
|
|
|
|
2018-11-26 15:14:25 +00:00
|
|
|
check(TestHelperPlus1(context, m) == 11);
|
2018-05-29 14:18:39 +00:00
|
|
|
return True;
|
|
|
|
}
|
|
|
|
return False;
|
|
|
|
}
|
2018-06-05 08:49:05 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-06-05 08:49:05 +00:00
|
|
|
macro TestHexLiteral() {
|
2018-09-11 13:15:02 +00:00
|
|
|
check(Convert<intptr>(0xffff) + 1 == 0x10000);
|
|
|
|
check(Convert<intptr>(-0xffff) == -65535);
|
2018-06-05 08:49:05 +00:00
|
|
|
}
|
2018-06-05 11:54:38 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-11-26 15:14:25 +00:00
|
|
|
macro TestLargeIntegerLiterals(implicit c: Context)() {
|
2019-06-06 12:41:27 +00:00
|
|
|
let _x: int32 = 0x40000000;
|
|
|
|
let _y: int32 = 0x7fffffff;
|
2018-06-05 11:54:38 +00:00
|
|
|
}
|
2018-06-13 08:25:17 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-06-13 08:25:17 +00:00
|
|
|
macro TestMultilineAssert() {
|
2019-06-11 10:56:10 +00:00
|
|
|
const someVeryLongVariableNameThatWillCauseLineBreaks: Smi = 5;
|
2018-07-17 16:20:53 +00:00
|
|
|
check(
|
|
|
|
someVeryLongVariableNameThatWillCauseLineBreaks > 0 &&
|
|
|
|
someVeryLongVariableNameThatWillCauseLineBreaks < 10);
|
2018-06-13 08:25:17 +00:00
|
|
|
}
|
2018-06-28 12:15:37 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-06-28 12:15:37 +00:00
|
|
|
macro TestNewlineInString() {
|
|
|
|
Print('Hello, World!\n');
|
|
|
|
}
|
2018-07-13 08:50:22 +00:00
|
|
|
|
|
|
|
const kConstexprConst: constexpr int31 = 5;
|
|
|
|
const kIntptrConst: intptr = 4;
|
|
|
|
const kSmiConst: Smi = 3;
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-07-13 08:50:22 +00:00
|
|
|
macro TestModuleConstBindings() {
|
|
|
|
check(kConstexprConst == Int32Constant(5));
|
|
|
|
check(kIntptrConst == 4);
|
|
|
|
check(kSmiConst == 3);
|
|
|
|
}
|
2018-07-17 06:39:07 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-07-17 06:39:07 +00:00
|
|
|
macro TestLocalConstBindings() {
|
2018-09-24 09:28:48 +00:00
|
|
|
const x: constexpr int31 = 3;
|
|
|
|
const xSmi: Smi = x;
|
2018-07-27 13:56:57 +00:00
|
|
|
{
|
2018-09-24 09:28:48 +00:00
|
|
|
const x: Smi = x + FromConstexpr<Smi>(1);
|
2018-09-11 13:15:02 +00:00
|
|
|
check(x == xSmi + 1);
|
2018-09-24 09:28:48 +00:00
|
|
|
const xSmi: Smi = x;
|
2018-09-11 13:15:02 +00:00
|
|
|
check(x == xSmi);
|
2018-07-27 13:56:57 +00:00
|
|
|
check(x == 4);
|
|
|
|
}
|
2018-09-11 13:15:02 +00:00
|
|
|
check(xSmi == 3);
|
|
|
|
check(x == xSmi);
|
2018-07-17 06:39:07 +00:00
|
|
|
}
|
2018-07-17 16:20:53 +00:00
|
|
|
|
|
|
|
struct TestStructA {
|
|
|
|
indexes: FixedArray;
|
|
|
|
i: Smi;
|
|
|
|
k: Number;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TestStructB {
|
|
|
|
x: TestStructA;
|
|
|
|
y: Smi;
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-07-17 16:20:53 +00:00
|
|
|
macro TestStruct1(i: TestStructA): Smi {
|
|
|
|
return i.i;
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-11-26 15:14:25 +00:00
|
|
|
macro TestStruct2(implicit context: Context)(): TestStructA {
|
2019-04-03 21:14:06 +00:00
|
|
|
return TestStructA{
|
|
|
|
indexes: UnsafeCast<FixedArray>(kEmptyFixedArray),
|
|
|
|
i: 27,
|
|
|
|
k: 31
|
|
|
|
};
|
2018-07-17 16:20:53 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-11-26 15:14:25 +00:00
|
|
|
macro TestStruct3(implicit context: Context)(): TestStructA {
|
2018-07-17 16:20:53 +00:00
|
|
|
let a: TestStructA =
|
2019-04-03 21:14:06 +00:00
|
|
|
TestStructA{indexes: UnsafeCast<FixedArray>(kEmptyFixedArray), i: 13, k: 5};
|
2019-06-06 12:41:27 +00:00
|
|
|
let _b: TestStructA = a;
|
2019-06-11 10:56:10 +00:00
|
|
|
const c: TestStructA = TestStruct2();
|
2018-07-17 16:20:53 +00:00
|
|
|
a.i = TestStruct1(c);
|
|
|
|
a.k = a.i;
|
|
|
|
let d: TestStructB;
|
|
|
|
d.x = a;
|
2019-04-03 21:14:06 +00:00
|
|
|
d = TestStructB{x: a, y: 7};
|
2019-06-06 12:41:27 +00:00
|
|
|
let _e: TestStructA = d.x;
|
2019-04-03 21:14:06 +00:00
|
|
|
let f: Smi = TestStructA{
|
|
|
|
indexes: UnsafeCast<FixedArray>(kEmptyFixedArray),
|
|
|
|
i: 27,
|
|
|
|
k: 31
|
|
|
|
}.i;
|
2018-07-17 16:20:53 +00:00
|
|
|
f = TestStruct2().i;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TestStructC {
|
2018-09-24 09:28:48 +00:00
|
|
|
x: TestStructA;
|
|
|
|
y: TestStructA;
|
2018-07-17 16:20:53 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-11-26 15:14:25 +00:00
|
|
|
macro TestStruct4(implicit context: Context)(): TestStructC {
|
2019-04-03 21:14:06 +00:00
|
|
|
return TestStructC{x: TestStruct2(), y: TestStruct2()};
|
2018-07-17 16:20:53 +00:00
|
|
|
}
|
2018-07-27 10:32:14 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
macro TestStructInLabel(implicit context: Context)(): never labels
|
2019-05-27 19:25:38 +00:00
|
|
|
Foo(TestStructA) {
|
2019-01-17 13:25:11 +00:00
|
|
|
goto Foo(TestStruct2());
|
|
|
|
}
|
2019-06-11 12:26:32 +00:00
|
|
|
@export // Silence unused warning.
|
2019-01-17 13:25:11 +00:00
|
|
|
macro CallTestStructInLabel(implicit context: Context)() {
|
|
|
|
try {
|
|
|
|
TestStructInLabel() otherwise Foo;
|
|
|
|
}
|
2019-06-06 12:41:27 +00:00
|
|
|
label Foo(_s: TestStructA) {}
|
2019-01-17 13:25:11 +00:00
|
|
|
}
|
|
|
|
|
2018-07-27 10:32:14 +00:00
|
|
|
// This macro tests different versions of the for-loop where some parts
|
|
|
|
// are (not) present.
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-07-27 10:32:14 +00:00
|
|
|
macro TestForLoop() {
|
|
|
|
let sum: Smi = 0;
|
2018-07-31 18:24:02 +00:00
|
|
|
for (let i: Smi = 0; i < 5; ++i) sum += i;
|
2018-07-27 10:32:14 +00:00
|
|
|
check(sum == 10);
|
|
|
|
|
|
|
|
sum = 0;
|
|
|
|
let j: Smi = 0;
|
2018-07-31 18:24:02 +00:00
|
|
|
for (; j < 5; ++j) sum += j;
|
2018-07-27 10:32:14 +00:00
|
|
|
check(sum == 10);
|
|
|
|
|
|
|
|
sum = 0;
|
|
|
|
j = 0;
|
2018-07-31 18:24:02 +00:00
|
|
|
for (; j < 5;) sum += j++;
|
2018-07-27 10:32:14 +00:00
|
|
|
check(sum == 10);
|
|
|
|
|
|
|
|
// Check that break works. No test expression.
|
|
|
|
sum = 0;
|
|
|
|
for (let i: Smi = 0;; ++i) {
|
|
|
|
if (i == 5) break;
|
2018-07-31 18:24:02 +00:00
|
|
|
sum += i;
|
2018-07-27 10:32:14 +00:00
|
|
|
}
|
|
|
|
check(sum == 10);
|
|
|
|
|
|
|
|
sum = 0;
|
|
|
|
j = 0;
|
|
|
|
for (;;) {
|
|
|
|
if (j == 5) break;
|
2018-07-31 18:24:02 +00:00
|
|
|
sum += j;
|
2018-07-27 10:32:14 +00:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
check(sum == 10);
|
|
|
|
|
|
|
|
// The following tests are the same as above, but use continue to skip
|
|
|
|
// index 3.
|
|
|
|
sum = 0;
|
|
|
|
for (let i: Smi = 0; i < 5; ++i) {
|
|
|
|
if (i == 3) continue;
|
2018-07-31 18:24:02 +00:00
|
|
|
sum += i;
|
2018-07-27 10:32:14 +00:00
|
|
|
}
|
|
|
|
check(sum == 7);
|
|
|
|
|
|
|
|
sum = 0;
|
|
|
|
j = 0;
|
|
|
|
for (; j < 5; ++j) {
|
|
|
|
if (j == 3) continue;
|
2018-07-31 18:24:02 +00:00
|
|
|
sum += j;
|
2018-07-27 10:32:14 +00:00
|
|
|
}
|
|
|
|
check(sum == 7);
|
|
|
|
|
|
|
|
sum = 0;
|
|
|
|
j = 0;
|
|
|
|
for (; j < 5;) {
|
|
|
|
if (j == 3) {
|
|
|
|
j++;
|
|
|
|
continue;
|
|
|
|
}
|
2018-07-31 18:24:02 +00:00
|
|
|
sum += j;
|
2018-07-27 10:32:14 +00:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
check(sum == 7);
|
|
|
|
|
|
|
|
sum = 0;
|
|
|
|
for (let i: Smi = 0;; ++i) {
|
|
|
|
if (i == 3) continue;
|
|
|
|
if (i == 5) break;
|
2018-07-31 18:24:02 +00:00
|
|
|
sum += i;
|
2018-07-27 10:32:14 +00:00
|
|
|
}
|
|
|
|
check(sum == 7);
|
|
|
|
|
|
|
|
sum = 0;
|
|
|
|
j = 0;
|
|
|
|
for (;;) {
|
|
|
|
if (j == 3) {
|
|
|
|
j++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (j == 5) break;
|
2018-07-31 18:24:02 +00:00
|
|
|
sum += j;
|
2018-07-27 10:32:14 +00:00
|
|
|
j++;
|
|
|
|
}
|
|
|
|
check(sum == 7);
|
2018-10-24 09:18:30 +00:00
|
|
|
|
|
|
|
j = 0;
|
|
|
|
try {
|
|
|
|
for (;;) {
|
|
|
|
if (++j == 10) goto Exit;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
label Exit {
|
|
|
|
check(j == 10);
|
|
|
|
}
|
2019-02-06 12:35:58 +00:00
|
|
|
|
|
|
|
// Test if we can handle uninitialized values on the stack.
|
2019-06-06 12:41:27 +00:00
|
|
|
let _i: Smi;
|
2019-02-06 12:35:58 +00:00
|
|
|
for (let j: Smi = 0; j < 10; ++j) {
|
|
|
|
}
|
2018-07-27 10:32:14 +00:00
|
|
|
}
|
2018-08-07 14:06:18 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-09-24 09:28:48 +00:00
|
|
|
macro TestSubtyping(x: Smi) {
|
Reland "[torque] introduce JSAny type for user-accessible JavaScript values"
Changes in the reland: Rebased and added a check that JavaScript-linkage
builtins use JSAny in parameters and return type, plus the necessary
cleanups for this test to pass.
Design Doc: https://docs.google.com/document/d/1z6j0pWHnNIfId0v00uWN2HBrGRDJxJfYuCr5K7Kr1xA
This reverts commit 4418a7b96afdf8278577211ab0ed555c41ee269e.
Original change's description:
> Revert "[torque] introduce JSAny type for user-accessible JavaScript values"
>
> This reverts commit 79b00555eac939bf4a00177ec59e21b856d7301c.
>
> Reason for revert: needs more discussion
>
> Original change's description:
> > [torque] introduce JSAny type for user-accessible JavaScript values
> >
> > This CL introduces a JSAny type for user-exposed JavaScript values and
> > a few new types to define it. Especially, it splits Symbol into
> > PrivateSymbol (not exposed) and PublicSymbol (JavaScript exposed
> > symbols).
> >
> > The change is mostly mechanical, but a few things are interesting:
> > - PropertyKey and JSPrimitive were designed to coincide with the spec
> > notions of IsPropertyKey() and primitive value, respectively.
> > - Since Name is an open type, we define AnyName to be the known
> > subtypes of Name. This is not too elegant, but by using AnyName
> > instead of Name, typeswitch can properly conclude something if a
> > subtype of Name is excluded.
> >
> > Small drive-by changes, which were necessary:
> > - Allow subtyping on label parameters.
> > - Fix the formatting of typeswitch, it was broken with union types
> > in case types.
> >
> > Bug: v8:7793
> > Change-Id: I14b10507f8cf316ad85e048fe8d53d1df5e0bb13
> > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1735322
> > Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> > Reviewed-by: Jakob Gruber <jgruber@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#63114}
>
> TBR=neis@chromium.org,jgruber@chromium.org,tebbi@chromium.org
>
> Change-Id: Ifde7881d74afe407628f40047997339d54cb2424
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: v8:7793
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1741652
> Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
> Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#63115}
TBR=neis@chromium.org,jgruber@chromium.org,tebbi@chromium.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: v8:7793
Change-Id: Icca34e3824f55009b984d9348fd21884400f0081
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1769316
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63395}
2019-08-26 12:07:01 +00:00
|
|
|
const _foo: JSAny = x;
|
2018-08-07 21:57:19 +00:00
|
|
|
}
|
|
|
|
|
2018-09-24 09:28:48 +00:00
|
|
|
macro IncrementIfSmi<A: type>(x: A): A {
|
2018-08-07 21:57:19 +00:00
|
|
|
typeswitch (x) {
|
2018-09-24 09:28:48 +00:00
|
|
|
case (x: Smi): {
|
2018-08-07 21:57:19 +00:00
|
|
|
return x + 1;
|
2018-09-24 09:28:48 +00:00
|
|
|
}
|
|
|
|
case (o: A): {
|
2018-08-07 21:57:19 +00:00
|
|
|
return o;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-24 09:22:15 +00:00
|
|
|
type NumberOrFixedArray = Number|FixedArray;
|
2018-11-26 15:14:25 +00:00
|
|
|
macro TypeswitchExample(implicit context: Context)(x: NumberOrFixedArray):
|
|
|
|
int32 {
|
2018-09-24 09:28:48 +00:00
|
|
|
let result: int32 = 0;
|
2018-11-14 15:38:50 +00:00
|
|
|
typeswitch (IncrementIfSmi(x)) {
|
2019-06-06 12:41:27 +00:00
|
|
|
case (_x: FixedArray): {
|
2018-08-07 21:57:19 +00:00
|
|
|
result = result + 1;
|
2018-09-24 09:28:48 +00:00
|
|
|
}
|
|
|
|
case (Number): {
|
2018-08-07 21:57:19 +00:00
|
|
|
result = result + 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = result * 10;
|
|
|
|
|
2018-11-14 15:38:50 +00:00
|
|
|
typeswitch (IncrementIfSmi(x)) {
|
2018-09-24 09:28:48 +00:00
|
|
|
case (x: Smi): {
|
2018-09-11 13:15:02 +00:00
|
|
|
result = result + Convert<int32>(x);
|
2018-09-24 09:28:48 +00:00
|
|
|
}
|
|
|
|
case (a: FixedArray): {
|
2018-09-11 13:15:02 +00:00
|
|
|
result = result + Convert<int32>(a.length);
|
2018-09-24 09:28:48 +00:00
|
|
|
}
|
2019-06-06 12:41:27 +00:00
|
|
|
case (_x: HeapNumber): {
|
2018-08-07 21:57:19 +00:00
|
|
|
result = result + 7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-11-26 15:14:25 +00:00
|
|
|
macro TestTypeswitch(implicit context: Context)() {
|
2018-09-11 13:15:02 +00:00
|
|
|
check(TypeswitchExample(FromConstexpr<Smi>(5)) == 26);
|
2018-09-24 09:28:48 +00:00
|
|
|
const a: FixedArray = AllocateZeroedFixedArray(3);
|
2018-08-07 21:57:19 +00:00
|
|
|
check(TypeswitchExample(a) == 13);
|
2018-09-11 13:15:02 +00:00
|
|
|
check(TypeswitchExample(FromConstexpr<Number>(0.5)) == 27);
|
2018-08-07 21:57:19 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2019-01-17 13:58:02 +00:00
|
|
|
macro TestTypeswitchAsanLsanFailure(implicit context: Context)(obj: Object) {
|
|
|
|
typeswitch (obj) {
|
2019-06-06 12:41:27 +00:00
|
|
|
case (_o: Smi): {
|
2019-01-17 13:58:02 +00:00
|
|
|
}
|
2019-06-06 12:41:27 +00:00
|
|
|
case (_o: JSTypedArray): {
|
2019-01-17 13:58:02 +00:00
|
|
|
}
|
2019-06-06 12:41:27 +00:00
|
|
|
case (_o: JSReceiver): {
|
2019-01-17 13:58:02 +00:00
|
|
|
}
|
2019-06-06 12:41:27 +00:00
|
|
|
case (_o: HeapObject): {
|
2019-01-17 13:58:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-24 09:28:48 +00:00
|
|
|
macro ExampleGenericOverload<A: type>(o: Object): A {
|
2018-08-07 14:06:18 +00:00
|
|
|
return o;
|
|
|
|
}
|
2018-09-24 09:28:48 +00:00
|
|
|
macro ExampleGenericOverload<A: type>(o: Smi): A {
|
2018-08-07 14:06:18 +00:00
|
|
|
return o + 1;
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-11-26 15:14:25 +00:00
|
|
|
macro TestGenericOverload(implicit context: Context)() {
|
2018-09-24 09:28:48 +00:00
|
|
|
const xSmi: Smi = 5;
|
|
|
|
const xObject: Object = xSmi;
|
2018-09-11 13:15:02 +00:00
|
|
|
check(ExampleGenericOverload<Smi>(xSmi) == 6);
|
|
|
|
check(UnsafeCast<Smi>(ExampleGenericOverload<Object>(xObject)) == 5);
|
2018-08-07 14:06:18 +00:00
|
|
|
}
|
[torque] disallow using logical operators in value contexts
This CL makes sure, that logical operators (||, &&) always have return
type never. Together with a check that never is never passed as a
function argument, this prevents faulty evaluation as in !(x || y).
Before, the logical operators had a behavior similar to
(bool labels Taken, NotTaken), with a fast exit if the left-hand side
allowed shor-circuit evaluation, but returning the right-hand side
otherwise. Since we want to allow existing (a || b || c) patterns in
the codebase, this requires weakening the restriction that the left-
and right-hand side need to have the same type. Now the possibilites
are:
bool, never
never, bool
never, never
bool, bool
constexpr bool, constexpr bool
Bug: v8:8137
Change-Id: I9576b337dc4008ac58b4625e77fef4e73bcdd6e3
Reviewed-on: https://chromium-review.googlesource.com/1215162
Reviewed-by: Daniel Clifford <danno@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55750}
2018-09-08 16:16:08 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2019-02-06 15:17:35 +00:00
|
|
|
macro TestEquality(implicit context: Context)() {
|
|
|
|
const notEqual: bool =
|
|
|
|
AllocateHeapNumberWithValue(0.5) != AllocateHeapNumberWithValue(0.5);
|
|
|
|
check(!notEqual);
|
|
|
|
const equal: bool =
|
|
|
|
AllocateHeapNumberWithValue(0.5) == AllocateHeapNumberWithValue(0.5);
|
|
|
|
check(equal);
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2019-08-05 13:28:02 +00:00
|
|
|
macro TestOrAnd(x: bool, y: bool, z: bool): bool {
|
|
|
|
return x || y && z ? true : false;
|
[torque] disallow using logical operators in value contexts
This CL makes sure, that logical operators (||, &&) always have return
type never. Together with a check that never is never passed as a
function argument, this prevents faulty evaluation as in !(x || y).
Before, the logical operators had a behavior similar to
(bool labels Taken, NotTaken), with a fast exit if the left-hand side
allowed shor-circuit evaluation, but returning the right-hand side
otherwise. Since we want to allow existing (a || b || c) patterns in
the codebase, this requires weakening the restriction that the left-
and right-hand side need to have the same type. Now the possibilites
are:
bool, never
never, bool
never, never
bool, bool
constexpr bool, constexpr bool
Bug: v8:8137
Change-Id: I9576b337dc4008ac58b4625e77fef4e73bcdd6e3
Reviewed-on: https://chromium-review.googlesource.com/1215162
Reviewed-by: Daniel Clifford <danno@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55750}
2018-09-08 16:16:08 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2019-08-05 13:28:02 +00:00
|
|
|
macro TestAndOr(x: bool, y: bool, z: bool): bool {
|
|
|
|
return x && y || z ? true : false;
|
[torque] disallow using logical operators in value contexts
This CL makes sure, that logical operators (||, &&) always have return
type never. Together with a check that never is never passed as a
function argument, this prevents faulty evaluation as in !(x || y).
Before, the logical operators had a behavior similar to
(bool labels Taken, NotTaken), with a fast exit if the left-hand side
allowed shor-circuit evaluation, but returning the right-hand side
otherwise. Since we want to allow existing (a || b || c) patterns in
the codebase, this requires weakening the restriction that the left-
and right-hand side need to have the same type. Now the possibilites
are:
bool, never
never, bool
never, never
bool, bool
constexpr bool, constexpr bool
Bug: v8:8137
Change-Id: I9576b337dc4008ac58b4625e77fef4e73bcdd6e3
Reviewed-on: https://chromium-review.googlesource.com/1215162
Reviewed-by: Daniel Clifford <danno@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55750}
2018-09-08 16:16:08 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
[torque] disallow using logical operators in value contexts
This CL makes sure, that logical operators (||, &&) always have return
type never. Together with a check that never is never passed as a
function argument, this prevents faulty evaluation as in !(x || y).
Before, the logical operators had a behavior similar to
(bool labels Taken, NotTaken), with a fast exit if the left-hand side
allowed shor-circuit evaluation, but returning the right-hand side
otherwise. Since we want to allow existing (a || b || c) patterns in
the codebase, this requires weakening the restriction that the left-
and right-hand side need to have the same type. Now the possibilites
are:
bool, never
never, bool
never, never
bool, bool
constexpr bool, constexpr bool
Bug: v8:8137
Change-Id: I9576b337dc4008ac58b4625e77fef4e73bcdd6e3
Reviewed-on: https://chromium-review.googlesource.com/1215162
Reviewed-by: Daniel Clifford <danno@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55750}
2018-09-08 16:16:08 +00:00
|
|
|
macro TestLogicalOperators() {
|
2019-08-05 13:28:02 +00:00
|
|
|
check(TestAndOr(true, true, true));
|
|
|
|
check(TestAndOr(true, true, false));
|
|
|
|
check(TestAndOr(true, false, true));
|
|
|
|
check(!TestAndOr(true, false, false));
|
|
|
|
check(TestAndOr(false, true, true));
|
|
|
|
check(!TestAndOr(false, true, false));
|
|
|
|
check(TestAndOr(false, false, true));
|
|
|
|
check(!TestAndOr(false, false, false));
|
|
|
|
check(TestOrAnd(true, true, true));
|
|
|
|
check(TestOrAnd(true, true, false));
|
|
|
|
check(TestOrAnd(true, false, true));
|
|
|
|
check(TestOrAnd(true, false, false));
|
|
|
|
check(TestOrAnd(false, true, true));
|
|
|
|
check(!TestOrAnd(false, true, false));
|
|
|
|
check(!TestOrAnd(false, false, true));
|
|
|
|
check(!TestOrAnd(false, false, false));
|
[torque] disallow using logical operators in value contexts
This CL makes sure, that logical operators (||, &&) always have return
type never. Together with a check that never is never passed as a
function argument, this prevents faulty evaluation as in !(x || y).
Before, the logical operators had a behavior similar to
(bool labels Taken, NotTaken), with a fast exit if the left-hand side
allowed shor-circuit evaluation, but returning the right-hand side
otherwise. Since we want to allow existing (a || b || c) patterns in
the codebase, this requires weakening the restriction that the left-
and right-hand side need to have the same type. Now the possibilites
are:
bool, never
never, bool
never, never
bool, bool
constexpr bool, constexpr bool
Bug: v8:8137
Change-Id: I9576b337dc4008ac58b4625e77fef4e73bcdd6e3
Reviewed-on: https://chromium-review.googlesource.com/1215162
Reviewed-by: Daniel Clifford <danno@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55750}
2018-09-08 16:16:08 +00:00
|
|
|
}
|
2018-10-08 13:50:46 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
|
|
|
macro TestCall(i: Smi): Smi labels A {
|
2018-10-08 13:50:46 +00:00
|
|
|
if (i < 5) return i;
|
|
|
|
goto A;
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-10-08 13:50:46 +00:00
|
|
|
macro TestOtherwiseWithCode1() {
|
|
|
|
let v: Smi = 0;
|
|
|
|
let s: Smi = 1;
|
|
|
|
try {
|
|
|
|
TestCall(10) otherwise goto B(++s);
|
|
|
|
}
|
|
|
|
label B(v1: Smi) {
|
|
|
|
v = v1;
|
|
|
|
}
|
|
|
|
assert(v == 2);
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-10-08 13:50:46 +00:00
|
|
|
macro TestOtherwiseWithCode2() {
|
|
|
|
let s: Smi = 0;
|
|
|
|
for (let i: Smi = 0; i < 10; ++i) {
|
|
|
|
TestCall(i) otherwise break;
|
|
|
|
++s;
|
|
|
|
}
|
|
|
|
assert(s == 5);
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-10-08 13:50:46 +00:00
|
|
|
macro TestOtherwiseWithCode3() {
|
|
|
|
let s: Smi = 0;
|
|
|
|
for (let i: Smi = 0; i < 10; ++i) {
|
|
|
|
s += TestCall(i) otherwise break;
|
|
|
|
}
|
|
|
|
assert(s == 10);
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-10-08 13:50:46 +00:00
|
|
|
macro TestForwardLabel() {
|
|
|
|
try {
|
|
|
|
goto A;
|
|
|
|
}
|
|
|
|
label A {
|
|
|
|
goto B(5);
|
|
|
|
}
|
|
|
|
label B(b: Smi) {
|
|
|
|
assert(b == 5);
|
|
|
|
}
|
|
|
|
}
|
2018-10-31 13:00:51 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-11-26 15:14:25 +00:00
|
|
|
macro TestQualifiedAccess(implicit context: Context)() {
|
2019-06-11 10:56:10 +00:00
|
|
|
const s: Smi = 0;
|
Reland "[torque] introduce JSAny type for user-accessible JavaScript values"
Changes in the reland: Rebased and added a check that JavaScript-linkage
builtins use JSAny in parameters and return type, plus the necessary
cleanups for this test to pass.
Design Doc: https://docs.google.com/document/d/1z6j0pWHnNIfId0v00uWN2HBrGRDJxJfYuCr5K7Kr1xA
This reverts commit 4418a7b96afdf8278577211ab0ed555c41ee269e.
Original change's description:
> Revert "[torque] introduce JSAny type for user-accessible JavaScript values"
>
> This reverts commit 79b00555eac939bf4a00177ec59e21b856d7301c.
>
> Reason for revert: needs more discussion
>
> Original change's description:
> > [torque] introduce JSAny type for user-accessible JavaScript values
> >
> > This CL introduces a JSAny type for user-exposed JavaScript values and
> > a few new types to define it. Especially, it splits Symbol into
> > PrivateSymbol (not exposed) and PublicSymbol (JavaScript exposed
> > symbols).
> >
> > The change is mostly mechanical, but a few things are interesting:
> > - PropertyKey and JSPrimitive were designed to coincide with the spec
> > notions of IsPropertyKey() and primitive value, respectively.
> > - Since Name is an open type, we define AnyName to be the known
> > subtypes of Name. This is not too elegant, but by using AnyName
> > instead of Name, typeswitch can properly conclude something if a
> > subtype of Name is excluded.
> >
> > Small drive-by changes, which were necessary:
> > - Allow subtyping on label parameters.
> > - Fix the formatting of typeswitch, it was broken with union types
> > in case types.
> >
> > Bug: v8:7793
> > Change-Id: I14b10507f8cf316ad85e048fe8d53d1df5e0bb13
> > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1735322
> > Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> > Reviewed-by: Jakob Gruber <jgruber@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#63114}
>
> TBR=neis@chromium.org,jgruber@chromium.org,tebbi@chromium.org
>
> Change-Id: Ifde7881d74afe407628f40047997339d54cb2424
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: v8:7793
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1741652
> Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
> Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#63115}
TBR=neis@chromium.org,jgruber@chromium.org,tebbi@chromium.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: v8:7793
Change-Id: Icca34e3824f55009b984d9348fd21884400f0081
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1769316
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63395}
2019-08-26 12:07:01 +00:00
|
|
|
check(!Is<JSArray>(s));
|
2018-11-02 12:40:31 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-11-26 15:14:25 +00:00
|
|
|
macro TestCatch1(implicit context: Context)(): Smi {
|
2018-10-31 13:00:51 +00:00
|
|
|
let r: Smi = 0;
|
|
|
|
try {
|
2019-12-18 15:33:16 +00:00
|
|
|
ThrowTypeError(MessageTemplate::kInvalidArrayLength);
|
2019-06-06 12:41:27 +00:00
|
|
|
} catch (_e) {
|
2018-10-31 13:00:51 +00:00
|
|
|
r = 1;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-11-26 15:14:25 +00:00
|
|
|
macro TestCatch2Wrapper(implicit context: Context)(): never {
|
2019-12-18 15:33:16 +00:00
|
|
|
ThrowTypeError(MessageTemplate::kInvalidArrayLength);
|
2018-10-31 13:00:51 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-11-26 15:14:25 +00:00
|
|
|
macro TestCatch2(implicit context: Context)(): Smi {
|
2018-10-31 13:00:51 +00:00
|
|
|
let r: Smi = 0;
|
|
|
|
try {
|
2018-11-26 15:14:25 +00:00
|
|
|
TestCatch2Wrapper();
|
2019-06-06 12:41:27 +00:00
|
|
|
} catch (_e) {
|
2018-10-31 13:00:51 +00:00
|
|
|
r = 2;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
|
|
|
macro TestCatch3WrapperWithLabel(implicit context: Context)():
|
2019-06-06 12:41:27 +00:00
|
|
|
never labels _Abort {
|
2019-12-18 15:33:16 +00:00
|
|
|
ThrowTypeError(MessageTemplate::kInvalidArrayLength);
|
2018-10-31 13:00:51 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-11-26 15:14:25 +00:00
|
|
|
macro TestCatch3(implicit context: Context)(): Smi {
|
2018-10-31 13:00:51 +00:00
|
|
|
let r: Smi = 0;
|
|
|
|
try {
|
2018-11-26 15:14:25 +00:00
|
|
|
TestCatch3WrapperWithLabel() otherwise Abort;
|
2018-10-31 13:00:51 +00:00
|
|
|
}
|
|
|
|
label Abort {
|
|
|
|
return -1;
|
|
|
|
}
|
2019-06-06 12:41:27 +00:00
|
|
|
catch (_e) {
|
2018-10-31 13:00:51 +00:00
|
|
|
r = 2;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
2018-10-31 14:59:13 +00:00
|
|
|
|
|
|
|
// This test doesn't actually test the functionality of iterators,
|
|
|
|
// it's only purpose is to make sure tha the CSA macros in the
|
|
|
|
// IteratorBuiltinsAssembler match the signatures provided in
|
|
|
|
// iterator.tq.
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2019-06-19 15:06:53 +00:00
|
|
|
macro TestIterator(implicit context: Context)(o: JSReceiver, map: Map) {
|
2018-10-31 14:59:13 +00:00
|
|
|
try {
|
Reland "[torque] introduce JSAny type for user-accessible JavaScript values"
Changes in the reland: Rebased and added a check that JavaScript-linkage
builtins use JSAny in parameters and return type, plus the necessary
cleanups for this test to pass.
Design Doc: https://docs.google.com/document/d/1z6j0pWHnNIfId0v00uWN2HBrGRDJxJfYuCr5K7Kr1xA
This reverts commit 4418a7b96afdf8278577211ab0ed555c41ee269e.
Original change's description:
> Revert "[torque] introduce JSAny type for user-accessible JavaScript values"
>
> This reverts commit 79b00555eac939bf4a00177ec59e21b856d7301c.
>
> Reason for revert: needs more discussion
>
> Original change's description:
> > [torque] introduce JSAny type for user-accessible JavaScript values
> >
> > This CL introduces a JSAny type for user-exposed JavaScript values and
> > a few new types to define it. Especially, it splits Symbol into
> > PrivateSymbol (not exposed) and PublicSymbol (JavaScript exposed
> > symbols).
> >
> > The change is mostly mechanical, but a few things are interesting:
> > - PropertyKey and JSPrimitive were designed to coincide with the spec
> > notions of IsPropertyKey() and primitive value, respectively.
> > - Since Name is an open type, we define AnyName to be the known
> > subtypes of Name. This is not too elegant, but by using AnyName
> > instead of Name, typeswitch can properly conclude something if a
> > subtype of Name is excluded.
> >
> > Small drive-by changes, which were necessary:
> > - Allow subtyping on label parameters.
> > - Fix the formatting of typeswitch, it was broken with union types
> > in case types.
> >
> > Bug: v8:7793
> > Change-Id: I14b10507f8cf316ad85e048fe8d53d1df5e0bb13
> > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1735322
> > Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> > Reviewed-by: Jakob Gruber <jgruber@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#63114}
>
> TBR=neis@chromium.org,jgruber@chromium.org,tebbi@chromium.org
>
> Change-Id: Ifde7881d74afe407628f40047997339d54cb2424
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: v8:7793
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1741652
> Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
> Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#63115}
TBR=neis@chromium.org,jgruber@chromium.org,tebbi@chromium.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: v8:7793
Change-Id: Icca34e3824f55009b984d9348fd21884400f0081
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1769316
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63395}
2019-08-26 12:07:01 +00:00
|
|
|
const t1: JSAny = iterator::GetIteratorMethod(o);
|
2018-11-19 12:45:02 +00:00
|
|
|
const t2: iterator::IteratorRecord = iterator::GetIterator(o);
|
2018-10-31 14:59:13 +00:00
|
|
|
|
Reland "[torque] introduce JSAny type for user-accessible JavaScript values"
Changes in the reland: Rebased and added a check that JavaScript-linkage
builtins use JSAny in parameters and return type, plus the necessary
cleanups for this test to pass.
Design Doc: https://docs.google.com/document/d/1z6j0pWHnNIfId0v00uWN2HBrGRDJxJfYuCr5K7Kr1xA
This reverts commit 4418a7b96afdf8278577211ab0ed555c41ee269e.
Original change's description:
> Revert "[torque] introduce JSAny type for user-accessible JavaScript values"
>
> This reverts commit 79b00555eac939bf4a00177ec59e21b856d7301c.
>
> Reason for revert: needs more discussion
>
> Original change's description:
> > [torque] introduce JSAny type for user-accessible JavaScript values
> >
> > This CL introduces a JSAny type for user-exposed JavaScript values and
> > a few new types to define it. Especially, it splits Symbol into
> > PrivateSymbol (not exposed) and PublicSymbol (JavaScript exposed
> > symbols).
> >
> > The change is mostly mechanical, but a few things are interesting:
> > - PropertyKey and JSPrimitive were designed to coincide with the spec
> > notions of IsPropertyKey() and primitive value, respectively.
> > - Since Name is an open type, we define AnyName to be the known
> > subtypes of Name. This is not too elegant, but by using AnyName
> > instead of Name, typeswitch can properly conclude something if a
> > subtype of Name is excluded.
> >
> > Small drive-by changes, which were necessary:
> > - Allow subtyping on label parameters.
> > - Fix the formatting of typeswitch, it was broken with union types
> > in case types.
> >
> > Bug: v8:7793
> > Change-Id: I14b10507f8cf316ad85e048fe8d53d1df5e0bb13
> > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1735322
> > Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> > Reviewed-by: Jakob Gruber <jgruber@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#63114}
>
> TBR=neis@chromium.org,jgruber@chromium.org,tebbi@chromium.org
>
> Change-Id: Ifde7881d74afe407628f40047997339d54cb2424
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: v8:7793
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1741652
> Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
> Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#63115}
TBR=neis@chromium.org,jgruber@chromium.org,tebbi@chromium.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: v8:7793
Change-Id: Icca34e3824f55009b984d9348fd21884400f0081
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1769316
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63395}
2019-08-26 12:07:01 +00:00
|
|
|
const _t3: JSAny = iterator::IteratorStep(t2) otherwise Fail;
|
|
|
|
const _t4: JSAny = iterator::IteratorStep(t2, map) otherwise Fail;
|
2018-10-31 14:59:13 +00:00
|
|
|
|
Reland "[torque] introduce JSAny type for user-accessible JavaScript values"
Changes in the reland: Rebased and added a check that JavaScript-linkage
builtins use JSAny in parameters and return type, plus the necessary
cleanups for this test to pass.
Design Doc: https://docs.google.com/document/d/1z6j0pWHnNIfId0v00uWN2HBrGRDJxJfYuCr5K7Kr1xA
This reverts commit 4418a7b96afdf8278577211ab0ed555c41ee269e.
Original change's description:
> Revert "[torque] introduce JSAny type for user-accessible JavaScript values"
>
> This reverts commit 79b00555eac939bf4a00177ec59e21b856d7301c.
>
> Reason for revert: needs more discussion
>
> Original change's description:
> > [torque] introduce JSAny type for user-accessible JavaScript values
> >
> > This CL introduces a JSAny type for user-exposed JavaScript values and
> > a few new types to define it. Especially, it splits Symbol into
> > PrivateSymbol (not exposed) and PublicSymbol (JavaScript exposed
> > symbols).
> >
> > The change is mostly mechanical, but a few things are interesting:
> > - PropertyKey and JSPrimitive were designed to coincide with the spec
> > notions of IsPropertyKey() and primitive value, respectively.
> > - Since Name is an open type, we define AnyName to be the known
> > subtypes of Name. This is not too elegant, but by using AnyName
> > instead of Name, typeswitch can properly conclude something if a
> > subtype of Name is excluded.
> >
> > Small drive-by changes, which were necessary:
> > - Allow subtyping on label parameters.
> > - Fix the formatting of typeswitch, it was broken with union types
> > in case types.
> >
> > Bug: v8:7793
> > Change-Id: I14b10507f8cf316ad85e048fe8d53d1df5e0bb13
> > Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1735322
> > Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> > Reviewed-by: Jakob Gruber <jgruber@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#63114}
>
> TBR=neis@chromium.org,jgruber@chromium.org,tebbi@chromium.org
>
> Change-Id: Ifde7881d74afe407628f40047997339d54cb2424
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: v8:7793
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1741652
> Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
> Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#63115}
TBR=neis@chromium.org,jgruber@chromium.org,tebbi@chromium.org
# Not skipping CQ checks because original CL landed > 1 day ago.
Bug: v8:7793
Change-Id: Icca34e3824f55009b984d9348fd21884400f0081
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1769316
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63395}
2019-08-26 12:07:01 +00:00
|
|
|
const t5: JSAny = iterator::IteratorValue(o);
|
|
|
|
const _t6: JSAny = iterator::IteratorValue(o, map);
|
2018-10-31 14:59:13 +00:00
|
|
|
|
2019-06-06 12:41:27 +00:00
|
|
|
const _t7: JSArray = iterator::IterableToList(t1, t1);
|
2018-11-09 14:34:54 +00:00
|
|
|
|
|
|
|
iterator::IteratorCloseOnException(t2, t5);
|
2018-10-31 14:59:13 +00:00
|
|
|
}
|
|
|
|
label Fail {}
|
|
|
|
}
|
2018-12-07 16:29:49 +00:00
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2018-12-07 16:29:49 +00:00
|
|
|
macro TestFrame1(implicit context: Context)() {
|
|
|
|
const f: Frame = LoadFramePointer();
|
|
|
|
const frameType: FrameType =
|
|
|
|
Cast<FrameType>(f.context_or_frame_type) otherwise unreachable;
|
|
|
|
assert(frameType == STUB_FRAME);
|
|
|
|
assert(f.caller == LoadParentFramePointer());
|
|
|
|
typeswitch (f) {
|
2019-06-06 12:41:27 +00:00
|
|
|
case (_f: StandardFrame): {
|
2018-12-07 16:29:49 +00:00
|
|
|
unreachable;
|
|
|
|
}
|
2019-06-06 12:41:27 +00:00
|
|
|
case (_f: ArgumentsAdaptorFrame): {
|
2018-12-07 16:29:49 +00:00
|
|
|
unreachable;
|
|
|
|
}
|
2019-06-06 12:41:27 +00:00
|
|
|
case (_f: StubFrame): {
|
2018-12-07 16:29:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
[torque] Implement methods and constructors for structs and classes
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: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58860}
2019-01-16 16:25:29 +00:00
|
|
|
macro TestNew(implicit context: Context)() {
|
2019-02-27 16:42:45 +00:00
|
|
|
const f: JSArray = NewJSArray();
|
2019-06-11 12:26:32 +00:00
|
|
|
check(f.IsEmpty());
|
[torque] Implement methods and constructors for structs and classes
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: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58860}
2019-01-16 16:25:29 +00:00
|
|
|
f.length = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TestInner {
|
2019-12-14 22:25:51 +00:00
|
|
|
macro SetX(newValue: int32) {
|
[torque] Implement methods and constructors for structs and classes
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: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58860}
2019-01-16 16:25:29 +00:00
|
|
|
this.x = newValue;
|
|
|
|
}
|
2019-12-14 22:25:51 +00:00
|
|
|
macro GetX(): int32 {
|
[torque] Implement methods and constructors for structs and classes
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: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58860}
2019-01-16 16:25:29 +00:00
|
|
|
return this.x;
|
|
|
|
}
|
|
|
|
x: int32;
|
|
|
|
y: int32;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TestOuter {
|
|
|
|
a: int32;
|
|
|
|
b: TestInner;
|
|
|
|
c: int32;
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
[torque] Implement methods and constructors for structs and classes
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: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58860}
2019-01-16 16:25:29 +00:00
|
|
|
macro TestStructConstructor(implicit context: Context)() {
|
2019-01-22 16:18:15 +00:00
|
|
|
// Test default constructor
|
2019-04-03 21:14:06 +00:00
|
|
|
let a: TestOuter = TestOuter{a: 5, b: TestInner{x: 6, y: 7}, c: 8};
|
2019-06-11 12:26:32 +00:00
|
|
|
check(a.a == 5);
|
|
|
|
check(a.b.x == 6);
|
|
|
|
check(a.b.y == 7);
|
|
|
|
check(a.c == 8);
|
2019-01-22 16:18:15 +00:00
|
|
|
a.b.x = 1;
|
2019-06-11 12:26:32 +00:00
|
|
|
check(a.b.x == 1);
|
[torque] Implement methods and constructors for structs and classes
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: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58860}
2019-01-16 16:25:29 +00:00
|
|
|
a.b.SetX(2);
|
2019-06-11 12:26:32 +00:00
|
|
|
check(a.b.x == 2);
|
|
|
|
check(a.b.GetX() == 2);
|
[torque] Implement methods and constructors for structs and classes
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: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58860}
2019-01-16 16:25:29 +00:00
|
|
|
}
|
2019-02-01 16:59:50 +00:00
|
|
|
|
2020-03-03 15:53:40 +00:00
|
|
|
class InternalClass extends HeapObject {
|
2019-12-14 22:25:51 +00:00
|
|
|
macro Flip() labels NotASmi {
|
2019-02-05 12:39:44 +00:00
|
|
|
const tmp = Cast<Smi>(this.b) otherwise NotASmi;
|
|
|
|
this.b = this.a;
|
|
|
|
this.a = tmp;
|
|
|
|
}
|
|
|
|
a: Smi;
|
|
|
|
b: Number;
|
|
|
|
}
|
|
|
|
|
2019-02-27 16:42:45 +00:00
|
|
|
macro NewInternalClass(x: Smi): InternalClass {
|
2019-04-03 21:14:06 +00:00
|
|
|
return new InternalClass{a: x, b: x + 1};
|
2019-02-27 16:42:45 +00:00
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2019-02-05 12:39:44 +00:00
|
|
|
macro TestInternalClass(implicit context: Context)() {
|
2019-02-27 16:42:45 +00:00
|
|
|
const o = NewInternalClass(5);
|
2019-02-05 12:39:44 +00:00
|
|
|
o.Flip() otherwise unreachable;
|
|
|
|
check(o.a == 6);
|
|
|
|
check(o.b == 5);
|
|
|
|
}
|
2019-04-03 10:22:54 +00:00
|
|
|
|
|
|
|
struct StructWithConst {
|
2019-12-14 22:25:51 +00:00
|
|
|
macro TestMethod1(): int32 {
|
2019-04-03 10:22:54 +00:00
|
|
|
return this.b;
|
|
|
|
}
|
2019-12-14 22:25:51 +00:00
|
|
|
macro TestMethod2(): Object {
|
2019-04-03 10:22:54 +00:00
|
|
|
return this.a;
|
|
|
|
}
|
|
|
|
a: Object;
|
|
|
|
const b: int32;
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2019-04-03 10:22:54 +00:00
|
|
|
macro TestConstInStructs() {
|
2019-04-03 21:14:06 +00:00
|
|
|
const x = StructWithConst{a: Null, b: 1};
|
|
|
|
let y = StructWithConst{a: Null, b: 1};
|
2019-04-03 10:22:54 +00:00
|
|
|
y.a = Undefined;
|
2019-06-06 12:41:27 +00:00
|
|
|
const _copy = x;
|
2019-06-11 12:26:32 +00:00
|
|
|
|
|
|
|
check(x.TestMethod1() == 1);
|
|
|
|
check(x.TestMethod2() == Null);
|
2019-04-03 10:22:54 +00:00
|
|
|
}
|
2019-04-04 17:23:05 +00:00
|
|
|
|
2019-12-19 08:55:02 +00:00
|
|
|
@export
|
|
|
|
macro TestParentFrameArguments(implicit context: Context)() {
|
|
|
|
const parentFrame = LoadParentFramePointer();
|
|
|
|
const castFrame = Cast<StandardFrame>(parentFrame) otherwise unreachable;
|
|
|
|
const arguments = GetFrameArguments(castFrame, 1);
|
|
|
|
ArgumentsIterator{arguments, current: 0};
|
|
|
|
}
|
|
|
|
|
2019-04-04 17:23:05 +00:00
|
|
|
struct TestIterator {
|
2019-12-14 22:25:51 +00:00
|
|
|
macro Next(): Object labels NoMore {
|
2019-04-04 17:23:05 +00:00
|
|
|
if (this.count-- == 0) goto NoMore;
|
2019-06-17 19:37:46 +00:00
|
|
|
return TheHole;
|
2019-04-04 17:23:05 +00:00
|
|
|
}
|
|
|
|
count: Smi;
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2019-04-04 17:23:05 +00:00
|
|
|
macro TestNewFixedArrayFromSpread(implicit context: Context)(): Object {
|
2019-06-11 10:56:10 +00:00
|
|
|
let i = TestIterator{count: 5};
|
2019-04-04 17:23:05 +00:00
|
|
|
return new FixedArray{map: kFixedArrayMap, length: 5, objects: ...i};
|
|
|
|
}
|
2019-04-11 13:36:05 +00:00
|
|
|
|
2020-03-03 15:53:40 +00:00
|
|
|
class SmiPair extends HeapObject {
|
2019-12-14 22:25:51 +00:00
|
|
|
macro GetA():&Smi {
|
2019-04-11 13:36:05 +00:00
|
|
|
return & this.a;
|
|
|
|
}
|
|
|
|
a: Smi;
|
|
|
|
b: Smi;
|
|
|
|
}
|
|
|
|
|
|
|
|
macro Swap<T: type>(a:&T, b:&T) {
|
|
|
|
const tmp = * a;
|
|
|
|
* a = * b;
|
|
|
|
* b = tmp;
|
|
|
|
}
|
|
|
|
|
2019-05-20 22:14:46 +00:00
|
|
|
@export
|
2019-04-11 13:36:05 +00:00
|
|
|
macro TestReferences() {
|
|
|
|
const array = new SmiPair{a: 7, b: 2};
|
|
|
|
const ref:&Smi = & array.a;
|
|
|
|
* ref = 3 + * ref;
|
|
|
|
-- * ref;
|
2019-07-31 12:01:55 +00:00
|
|
|
Swap(& array.b, array.GetA());
|
2019-04-11 13:36:05 +00:00
|
|
|
check(array.a == 2);
|
|
|
|
check(array.b == 9);
|
|
|
|
}
|
2019-05-07 08:38:44 +00:00
|
|
|
|
[torque] Add user-defined Slice struct
This CL consists of several preparatory steps for slices in Torque. Above all, it introduces a user-defined struct, torque_internal::Slice<T>, that performs bounds checking and returns references to elements in arrays. To enable this, several smaller changes were also made:
- Constructors of internal classes such as torque_internal::Reference<T> now require a special 'Unsafe' argument, making it clear that there be dragons.
- Struct methods are now declared during finalization. This allows instances of generic structs to have methods referring to the same struct. Previously, methods would be declared before the instance had been fully registered, leading to errors during type resolution. Furthermore, such methods were declared in a temporary namespace, that would then erroneously escape and lead to use-after-free issues.
- Instances of TypeArgumentInference were not running in the correct (Torque) scopes, leading to type resolution errors.
- The chain of ContextualVariable::Scope for any given ContextualVariable (such as CurrentScope) can now be walked, simplifying debugging.
R=jgruber@chromium.org, tebbi@chromium.org
Bug: v8:7793
Change-Id: I36f808f63cc3ce441062dfc56f511f24f1e3121e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1758322
Commit-Queue: Georg Schmid <gsps@google.com>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63314}
2019-08-21 11:47:44 +00:00
|
|
|
@export
|
|
|
|
macro TestSlices() {
|
2019-08-29 15:30:47 +00:00
|
|
|
const it = TestIterator{count: 3};
|
|
|
|
const a = new FixedArray{map: kFixedArrayMap, length: 3, objects: ...it};
|
|
|
|
check(a.length == 3);
|
|
|
|
|
|
|
|
const oneTwoThree = Convert<Smi>(123);
|
|
|
|
a.objects[0] = oneTwoThree;
|
|
|
|
const firstRef:&Object = & a.objects[0];
|
|
|
|
check(TaggedEqual(* firstRef, oneTwoThree));
|
|
|
|
|
|
|
|
const slice: torque_internal::Slice<Object> = & a.objects;
|
|
|
|
const firstRefAgain:&Object = slice.TryAtIndex(0) otherwise unreachable;
|
|
|
|
check(TaggedEqual(* firstRefAgain, oneTwoThree));
|
|
|
|
|
|
|
|
const threeTwoOne = Convert<Smi>(321);
|
|
|
|
* firstRefAgain = threeTwoOne;
|
|
|
|
check(TaggedEqual(a.objects[0], threeTwoOne));
|
|
|
|
|
|
|
|
// *slice; // error, not allowed
|
|
|
|
// a.objects; // error, not allowed
|
|
|
|
// a.objects = slice; // error, not allowed
|
|
|
|
|
|
|
|
// TODO(gsps): Currently errors, but should be allowed:
|
|
|
|
// const _sameSlice: torque_internal::Slice<Object> = &(*slice);
|
|
|
|
// (*slice)[0] : Smi
|
|
|
|
}
|
|
|
|
|
|
|
|
@export
|
|
|
|
macro TestSliceEnumeration(implicit context: Context)(): Undefined {
|
[torque] Add user-defined Slice struct
This CL consists of several preparatory steps for slices in Torque. Above all, it introduces a user-defined struct, torque_internal::Slice<T>, that performs bounds checking and returns references to elements in arrays. To enable this, several smaller changes were also made:
- Constructors of internal classes such as torque_internal::Reference<T> now require a special 'Unsafe' argument, making it clear that there be dragons.
- Struct methods are now declared during finalization. This allows instances of generic structs to have methods referring to the same struct. Previously, methods would be declared before the instance had been fully registered, leading to errors during type resolution. Furthermore, such methods were declared in a temporary namespace, that would then erroneously escape and lead to use-after-free issues.
- Instances of TypeArgumentInference were not running in the correct (Torque) scopes, leading to type resolution errors.
- The chain of ContextualVariable::Scope for any given ContextualVariable (such as CurrentScope) can now be walked, simplifying debugging.
R=jgruber@chromium.org, tebbi@chromium.org
Bug: v8:7793
Change-Id: I36f808f63cc3ce441062dfc56f511f24f1e3121e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1758322
Commit-Queue: Georg Schmid <gsps@google.com>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63314}
2019-08-21 11:47:44 +00:00
|
|
|
const fixedArray: FixedArray = AllocateZeroedFixedArray(3);
|
2019-08-29 15:30:47 +00:00
|
|
|
for (let i: intptr = 0; i < 3; i++) {
|
|
|
|
check(UnsafeCast<Smi>(fixedArray.objects[i]) == 0);
|
|
|
|
fixedArray.objects[i] = Convert<Smi>(i) + 3;
|
|
|
|
}
|
[torque] Add user-defined Slice struct
This CL consists of several preparatory steps for slices in Torque. Above all, it introduces a user-defined struct, torque_internal::Slice<T>, that performs bounds checking and returns references to elements in arrays. To enable this, several smaller changes were also made:
- Constructors of internal classes such as torque_internal::Reference<T> now require a special 'Unsafe' argument, making it clear that there be dragons.
- Struct methods are now declared during finalization. This allows instances of generic structs to have methods referring to the same struct. Previously, methods would be declared before the instance had been fully registered, leading to errors during type resolution. Furthermore, such methods were declared in a temporary namespace, that would then erroneously escape and lead to use-after-free issues.
- Instances of TypeArgumentInference were not running in the correct (Torque) scopes, leading to type resolution errors.
- The chain of ContextualVariable::Scope for any given ContextualVariable (such as CurrentScope) can now be walked, simplifying debugging.
R=jgruber@chromium.org, tebbi@chromium.org
Bug: v8:7793
Change-Id: I36f808f63cc3ce441062dfc56f511f24f1e3121e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1758322
Commit-Queue: Georg Schmid <gsps@google.com>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63314}
2019-08-21 11:47:44 +00:00
|
|
|
|
2019-08-29 15:30:47 +00:00
|
|
|
let slice = & fixedArray.objects;
|
[torque] Add user-defined Slice struct
This CL consists of several preparatory steps for slices in Torque. Above all, it introduces a user-defined struct, torque_internal::Slice<T>, that performs bounds checking and returns references to elements in arrays. To enable this, several smaller changes were also made:
- Constructors of internal classes such as torque_internal::Reference<T> now require a special 'Unsafe' argument, making it clear that there be dragons.
- Struct methods are now declared during finalization. This allows instances of generic structs to have methods referring to the same struct. Previously, methods would be declared before the instance had been fully registered, leading to errors during type resolution. Furthermore, such methods were declared in a temporary namespace, that would then erroneously escape and lead to use-after-free issues.
- Instances of TypeArgumentInference were not running in the correct (Torque) scopes, leading to type resolution errors.
- The chain of ContextualVariable::Scope for any given ContextualVariable (such as CurrentScope) can now be walked, simplifying debugging.
R=jgruber@chromium.org, tebbi@chromium.org
Bug: v8:7793
Change-Id: I36f808f63cc3ce441062dfc56f511f24f1e3121e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1758322
Commit-Queue: Georg Schmid <gsps@google.com>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63314}
2019-08-21 11:47:44 +00:00
|
|
|
for (let i: intptr = 0; i < slice.length; i++) {
|
2019-08-29 15:30:47 +00:00
|
|
|
let ref = slice.TryAtIndex(i) otherwise unreachable;
|
|
|
|
const value = UnsafeCast<Smi>(* ref);
|
|
|
|
check(value == Convert<Smi>(i) + 3);
|
|
|
|
* ref = value + 4;
|
[torque] Add user-defined Slice struct
This CL consists of several preparatory steps for slices in Torque. Above all, it introduces a user-defined struct, torque_internal::Slice<T>, that performs bounds checking and returns references to elements in arrays. To enable this, several smaller changes were also made:
- Constructors of internal classes such as torque_internal::Reference<T> now require a special 'Unsafe' argument, making it clear that there be dragons.
- Struct methods are now declared during finalization. This allows instances of generic structs to have methods referring to the same struct. Previously, methods would be declared before the instance had been fully registered, leading to errors during type resolution. Furthermore, such methods were declared in a temporary namespace, that would then erroneously escape and lead to use-after-free issues.
- Instances of TypeArgumentInference were not running in the correct (Torque) scopes, leading to type resolution errors.
- The chain of ContextualVariable::Scope for any given ContextualVariable (such as CurrentScope) can now be walked, simplifying debugging.
R=jgruber@chromium.org, tebbi@chromium.org
Bug: v8:7793
Change-Id: I36f808f63cc3ce441062dfc56f511f24f1e3121e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1758322
Commit-Queue: Georg Schmid <gsps@google.com>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63314}
2019-08-21 11:47:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let it = slice.Iterator();
|
|
|
|
let count: Smi = 0;
|
|
|
|
while (true) {
|
2020-01-13 15:30:51 +00:00
|
|
|
const value = UnsafeCast<Smi>(it.Next() otherwise break);
|
2019-08-29 15:30:47 +00:00
|
|
|
check(value == count + 7);
|
[torque] Add user-defined Slice struct
This CL consists of several preparatory steps for slices in Torque. Above all, it introduces a user-defined struct, torque_internal::Slice<T>, that performs bounds checking and returns references to elements in arrays. To enable this, several smaller changes were also made:
- Constructors of internal classes such as torque_internal::Reference<T> now require a special 'Unsafe' argument, making it clear that there be dragons.
- Struct methods are now declared during finalization. This allows instances of generic structs to have methods referring to the same struct. Previously, methods would be declared before the instance had been fully registered, leading to errors during type resolution. Furthermore, such methods were declared in a temporary namespace, that would then erroneously escape and lead to use-after-free issues.
- Instances of TypeArgumentInference were not running in the correct (Torque) scopes, leading to type resolution errors.
- The chain of ContextualVariable::Scope for any given ContextualVariable (such as CurrentScope) can now be walked, simplifying debugging.
R=jgruber@chromium.org, tebbi@chromium.org
Bug: v8:7793
Change-Id: I36f808f63cc3ce441062dfc56f511f24f1e3121e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1758322
Commit-Queue: Georg Schmid <gsps@google.com>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63314}
2019-08-21 11:47:44 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
check(count == 3);
|
|
|
|
check(it.Empty());
|
2019-08-29 15:30:47 +00:00
|
|
|
|
|
|
|
return Undefined;
|
[torque] Add user-defined Slice struct
This CL consists of several preparatory steps for slices in Torque. Above all, it introduces a user-defined struct, torque_internal::Slice<T>, that performs bounds checking and returns references to elements in arrays. To enable this, several smaller changes were also made:
- Constructors of internal classes such as torque_internal::Reference<T> now require a special 'Unsafe' argument, making it clear that there be dragons.
- Struct methods are now declared during finalization. This allows instances of generic structs to have methods referring to the same struct. Previously, methods would be declared before the instance had been fully registered, leading to errors during type resolution. Furthermore, such methods were declared in a temporary namespace, that would then erroneously escape and lead to use-after-free issues.
- Instances of TypeArgumentInference were not running in the correct (Torque) scopes, leading to type resolution errors.
- The chain of ContextualVariable::Scope for any given ContextualVariable (such as CurrentScope) can now be walked, simplifying debugging.
R=jgruber@chromium.org, tebbi@chromium.org
Bug: v8:7793
Change-Id: I36f808f63cc3ce441062dfc56f511f24f1e3121e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1758322
Commit-Queue: Georg Schmid <gsps@google.com>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63314}
2019-08-21 11:47:44 +00:00
|
|
|
}
|
|
|
|
|
2019-05-21 14:59:31 +00:00
|
|
|
@export
|
|
|
|
macro TestStaticAssert() {
|
|
|
|
StaticAssert(1 + 2 == 3);
|
|
|
|
}
|
|
|
|
|
2020-03-03 15:53:40 +00:00
|
|
|
class SmiBox extends HeapObject {
|
2019-06-04 14:19:40 +00:00
|
|
|
value: Smi;
|
|
|
|
unrelated: Smi;
|
|
|
|
}
|
|
|
|
|
2019-06-12 11:30:05 +00:00
|
|
|
builtin NewSmiBox(implicit context: Context)(value: Smi): SmiBox {
|
2019-06-04 14:19:40 +00:00
|
|
|
return new SmiBox{value, unrelated: 0};
|
|
|
|
}
|
|
|
|
|
|
|
|
@export
|
2019-06-17 15:10:03 +00:00
|
|
|
macro TestLoadEliminationFixed(implicit context: Context)() {
|
2019-06-04 14:19:40 +00:00
|
|
|
const box = NewSmiBox(123);
|
|
|
|
const v1 = box.value;
|
2019-06-17 15:10:03 +00:00
|
|
|
box.unrelated = 999;
|
2019-06-04 14:19:40 +00:00
|
|
|
const v2 = (box.unrelated == 0) ? box.value : box.value;
|
2019-08-23 12:40:12 +00:00
|
|
|
StaticAssert(TaggedEqual(v1, v2));
|
2019-06-17 15:10:03 +00:00
|
|
|
|
|
|
|
box.value = 11;
|
|
|
|
const v3 = box.value;
|
|
|
|
const eleven: Smi = 11;
|
2019-08-23 12:40:12 +00:00
|
|
|
StaticAssert(TaggedEqual(v3, eleven));
|
2019-06-04 14:19:40 +00:00
|
|
|
}
|
2019-06-12 11:30:05 +00:00
|
|
|
|
|
|
|
@export
|
2019-06-17 15:10:03 +00:00
|
|
|
macro TestLoadEliminationVariable(implicit context: Context)() {
|
2019-06-12 11:30:05 +00:00
|
|
|
const a = UnsafeCast<FixedArray>(kEmptyFixedArray);
|
|
|
|
const box = NewSmiBox(1);
|
|
|
|
const v1 = a.objects[box.value];
|
|
|
|
const u1 = a.objects[box.value + 2];
|
|
|
|
const v2 = a.objects[box.value];
|
|
|
|
const u2 = a.objects[box.value + 2];
|
2019-08-23 12:40:12 +00:00
|
|
|
StaticAssert(TaggedEqual(v1, v2));
|
|
|
|
StaticAssert(TaggedEqual(u1, u2));
|
2019-06-12 11:30:05 +00:00
|
|
|
}
|
|
|
|
|
2019-06-17 08:18:27 +00:00
|
|
|
@export
|
|
|
|
macro TestRedundantArrayElementCheck(implicit context: Context)(): Smi {
|
|
|
|
const a = kEmptyFixedArray;
|
|
|
|
for (let i: Smi = 0; i < a.length; i++) {
|
2019-06-17 19:37:46 +00:00
|
|
|
if (a.objects[i] == TheHole) {
|
|
|
|
if (a.objects[i] == TheHole) {
|
2019-06-17 08:18:27 +00:00
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
StaticAssert(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@export
|
|
|
|
macro TestRedundantSmiCheck(implicit context: Context)(): Smi {
|
|
|
|
const a = kEmptyFixedArray;
|
|
|
|
const x = a.objects[1];
|
|
|
|
typeswitch (x) {
|
|
|
|
case (Smi): {
|
|
|
|
Cast<Smi>(x) otherwise VerifiedUnreachable();
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
case (Object): {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
[torque] Add Generic Structs
This CL introduces generic Torque structs. Generics are grounded early in the Torque compilation pipeline, meaning that every instantiation of a generic struct with concrete types will be turned into a distinct StructType.
As an example, consider a Tuple of types T1, T2:
struct Tuple<T1: type, T2: type> {
const fst: T1;
const snd: T2;
}
which can be manipulated using generic macros, such as
macro Swap<T1: type, T2: type>(tuple: Tuple<T1, T2>): Tuple<T2, T1> {
return Tuple<T2, T1>{fst: tuple.snd, snd: tuple.fst};
}
Currently there is no type inference for struct instantiation sites, so type arguments have to be provided explicitly:
const intptrAndSmi = Tuple<intptr, Smi>{fst: 1, snd: 2};
R=sigurds@chromium.org, tebbi@chromium.org
Change-Id: I43111561cbe53144db473dc844a478045644ef6c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1714868
Commit-Queue: Georg Schmid <gsps@google.com>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62878}
2019-07-23 14:55:01 +00:00
|
|
|
struct SBox<T: type> {
|
|
|
|
value: T;
|
|
|
|
}
|
|
|
|
|
|
|
|
@export
|
|
|
|
macro TestGenericStruct1(): intptr {
|
|
|
|
const i: intptr = 123;
|
2019-08-01 16:41:26 +00:00
|
|
|
let box = SBox{value: i};
|
|
|
|
let boxbox: SBox<SBox<intptr>> = SBox{value: box};
|
[torque] Add Generic Structs
This CL introduces generic Torque structs. Generics are grounded early in the Torque compilation pipeline, meaning that every instantiation of a generic struct with concrete types will be turned into a distinct StructType.
As an example, consider a Tuple of types T1, T2:
struct Tuple<T1: type, T2: type> {
const fst: T1;
const snd: T2;
}
which can be manipulated using generic macros, such as
macro Swap<T1: type, T2: type>(tuple: Tuple<T1, T2>): Tuple<T2, T1> {
return Tuple<T2, T1>{fst: tuple.snd, snd: tuple.fst};
}
Currently there is no type inference for struct instantiation sites, so type arguments have to be provided explicitly:
const intptrAndSmi = Tuple<intptr, Smi>{fst: 1, snd: 2};
R=sigurds@chromium.org, tebbi@chromium.org
Change-Id: I43111561cbe53144db473dc844a478045644ef6c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1714868
Commit-Queue: Georg Schmid <gsps@google.com>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62878}
2019-07-23 14:55:01 +00:00
|
|
|
check(box.value == 123);
|
|
|
|
boxbox.value.value *= 2;
|
|
|
|
check(boxbox.value.value == 246);
|
|
|
|
return boxbox.value.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct TestTuple<T1: type, T2: type> {
|
|
|
|
const fst: T1;
|
|
|
|
const snd: T2;
|
|
|
|
}
|
|
|
|
|
2019-07-26 13:30:02 +00:00
|
|
|
macro TupleSwap<T1: type, T2: type>(tuple: TestTuple<T1, T2>):
|
[torque] Add Generic Structs
This CL introduces generic Torque structs. Generics are grounded early in the Torque compilation pipeline, meaning that every instantiation of a generic struct with concrete types will be turned into a distinct StructType.
As an example, consider a Tuple of types T1, T2:
struct Tuple<T1: type, T2: type> {
const fst: T1;
const snd: T2;
}
which can be manipulated using generic macros, such as
macro Swap<T1: type, T2: type>(tuple: Tuple<T1, T2>): Tuple<T2, T1> {
return Tuple<T2, T1>{fst: tuple.snd, snd: tuple.fst};
}
Currently there is no type inference for struct instantiation sites, so type arguments have to be provided explicitly:
const intptrAndSmi = Tuple<intptr, Smi>{fst: 1, snd: 2};
R=sigurds@chromium.org, tebbi@chromium.org
Change-Id: I43111561cbe53144db473dc844a478045644ef6c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1714868
Commit-Queue: Georg Schmid <gsps@google.com>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62878}
2019-07-23 14:55:01 +00:00
|
|
|
TestTuple<T2, T1> {
|
2019-08-01 16:41:26 +00:00
|
|
|
return TestTuple{fst: tuple.snd, snd: tuple.fst};
|
[torque] Add Generic Structs
This CL introduces generic Torque structs. Generics are grounded early in the Torque compilation pipeline, meaning that every instantiation of a generic struct with concrete types will be turned into a distinct StructType.
As an example, consider a Tuple of types T1, T2:
struct Tuple<T1: type, T2: type> {
const fst: T1;
const snd: T2;
}
which can be manipulated using generic macros, such as
macro Swap<T1: type, T2: type>(tuple: Tuple<T1, T2>): Tuple<T2, T1> {
return Tuple<T2, T1>{fst: tuple.snd, snd: tuple.fst};
}
Currently there is no type inference for struct instantiation sites, so type arguments have to be provided explicitly:
const intptrAndSmi = Tuple<intptr, Smi>{fst: 1, snd: 2};
R=sigurds@chromium.org, tebbi@chromium.org
Change-Id: I43111561cbe53144db473dc844a478045644ef6c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1714868
Commit-Queue: Georg Schmid <gsps@google.com>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62878}
2019-07-23 14:55:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@export
|
2019-08-01 16:41:26 +00:00
|
|
|
macro TestGenericStruct2():
|
|
|
|
TestTuple<TestTuple<intptr, Smi>, TestTuple<Smi, intptr>> {
|
[torque] Add Generic Structs
This CL introduces generic Torque structs. Generics are grounded early in the Torque compilation pipeline, meaning that every instantiation of a generic struct with concrete types will be turned into a distinct StructType.
As an example, consider a Tuple of types T1, T2:
struct Tuple<T1: type, T2: type> {
const fst: T1;
const snd: T2;
}
which can be manipulated using generic macros, such as
macro Swap<T1: type, T2: type>(tuple: Tuple<T1, T2>): Tuple<T2, T1> {
return Tuple<T2, T1>{fst: tuple.snd, snd: tuple.fst};
}
Currently there is no type inference for struct instantiation sites, so type arguments have to be provided explicitly:
const intptrAndSmi = Tuple<intptr, Smi>{fst: 1, snd: 2};
R=sigurds@chromium.org, tebbi@chromium.org
Change-Id: I43111561cbe53144db473dc844a478045644ef6c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1714868
Commit-Queue: Georg Schmid <gsps@google.com>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62878}
2019-07-23 14:55:01 +00:00
|
|
|
const intptrAndSmi = TestTuple<intptr, Smi>{fst: 1, snd: 2};
|
2019-07-31 12:01:55 +00:00
|
|
|
const smiAndIntptr = TupleSwap(intptrAndSmi);
|
[torque] Add Generic Structs
This CL introduces generic Torque structs. Generics are grounded early in the Torque compilation pipeline, meaning that every instantiation of a generic struct with concrete types will be turned into a distinct StructType.
As an example, consider a Tuple of types T1, T2:
struct Tuple<T1: type, T2: type> {
const fst: T1;
const snd: T2;
}
which can be manipulated using generic macros, such as
macro Swap<T1: type, T2: type>(tuple: Tuple<T1, T2>): Tuple<T2, T1> {
return Tuple<T2, T1>{fst: tuple.snd, snd: tuple.fst};
}
Currently there is no type inference for struct instantiation sites, so type arguments have to be provided explicitly:
const intptrAndSmi = Tuple<intptr, Smi>{fst: 1, snd: 2};
R=sigurds@chromium.org, tebbi@chromium.org
Change-Id: I43111561cbe53144db473dc844a478045644ef6c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1714868
Commit-Queue: Georg Schmid <gsps@google.com>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62878}
2019-07-23 14:55:01 +00:00
|
|
|
check(intptrAndSmi.fst == smiAndIntptr.snd);
|
|
|
|
check(intptrAndSmi.snd == smiAndIntptr.fst);
|
2019-08-01 16:41:26 +00:00
|
|
|
const tupleTuple =
|
|
|
|
TestTuple<TestTuple<intptr, Smi>>{fst: intptrAndSmi, snd: smiAndIntptr};
|
|
|
|
return tupleTuple;
|
[torque] Add Generic Structs
This CL introduces generic Torque structs. Generics are grounded early in the Torque compilation pipeline, meaning that every instantiation of a generic struct with concrete types will be turned into a distinct StructType.
As an example, consider a Tuple of types T1, T2:
struct Tuple<T1: type, T2: type> {
const fst: T1;
const snd: T2;
}
which can be manipulated using generic macros, such as
macro Swap<T1: type, T2: type>(tuple: Tuple<T1, T2>): Tuple<T2, T1> {
return Tuple<T2, T1>{fst: tuple.snd, snd: tuple.fst};
}
Currently there is no type inference for struct instantiation sites, so type arguments have to be provided explicitly:
const intptrAndSmi = Tuple<intptr, Smi>{fst: 1, snd: 2};
R=sigurds@chromium.org, tebbi@chromium.org
Change-Id: I43111561cbe53144db473dc844a478045644ef6c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1714868
Commit-Queue: Georg Schmid <gsps@google.com>
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#62878}
2019-07-23 14:55:01 +00:00
|
|
|
}
|
|
|
|
|
2019-07-29 17:29:29 +00:00
|
|
|
macro BranchAndWriteResult(x: Smi, box: SmiBox): bool {
|
|
|
|
if (x > 5 || x < 0) {
|
|
|
|
box.value = 1;
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
box.value = 2;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@export
|
|
|
|
macro TestBranchOnBoolOptimization(implicit context: Context)(input: Smi) {
|
|
|
|
const box = NewSmiBox(1);
|
|
|
|
// If the two branches get combined into one, we should be able to determine
|
|
|
|
// the value of {box} statically.
|
|
|
|
if (BranchAndWriteResult(input, box)) {
|
|
|
|
StaticAssert(box.value == 1);
|
|
|
|
} else {
|
|
|
|
StaticAssert(box.value == 2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-12 20:49:36 +00:00
|
|
|
bitfield struct TestBitFieldStruct extends uint8 {
|
|
|
|
a: bool: 1 bit;
|
|
|
|
b: uint16: 3 bit;
|
|
|
|
c: uint32: 3 bit;
|
|
|
|
d: bool: 1 bit;
|
|
|
|
}
|
|
|
|
|
|
|
|
@export
|
|
|
|
macro TestBitFieldLoad(
|
|
|
|
val: TestBitFieldStruct, expectedA: bool, expectedB: uint16,
|
|
|
|
expectedC: uint32, expectedD: bool) {
|
|
|
|
check(val.a == expectedA);
|
|
|
|
check(val.b == expectedB);
|
|
|
|
check(val.c == expectedC);
|
|
|
|
check(val.d == expectedD);
|
|
|
|
}
|
|
|
|
|
|
|
|
@export
|
|
|
|
macro TestBitFieldStore(val: TestBitFieldStruct) {
|
|
|
|
let val: TestBitFieldStruct = val; // Get a mutable local copy.
|
|
|
|
const a: bool = val.a;
|
|
|
|
const b: uint16 = val.b;
|
|
|
|
let c: uint32 = val.c;
|
|
|
|
const d: bool = val.d;
|
|
|
|
|
|
|
|
val.a = !a;
|
|
|
|
TestBitFieldLoad(val, !a, b, c, d);
|
|
|
|
|
|
|
|
c = Unsigned(7 - Signed(val.c));
|
|
|
|
val.c = c;
|
|
|
|
TestBitFieldLoad(val, !a, b, c, d);
|
|
|
|
|
|
|
|
val.d = val.b == val.c;
|
|
|
|
TestBitFieldLoad(val, !a, b, c, b == c);
|
|
|
|
}
|
|
|
|
|
2020-04-22 17:05:44 +00:00
|
|
|
@export
|
|
|
|
macro TestBitFieldInit(a: bool, b: uint16, c: uint32, d: bool) {
|
|
|
|
const val: TestBitFieldStruct = TestBitFieldStruct{a: a, b: b, c: c, d: d};
|
|
|
|
TestBitFieldLoad(val, a, b, c, d);
|
|
|
|
}
|
|
|
|
|
2019-12-12 20:49:36 +00:00
|
|
|
// Some other bitfield structs, to verify getting uintptr values out of word32
|
|
|
|
// structs and vice versa.
|
|
|
|
bitfield struct TestBitFieldStruct2 extends uint32 {
|
|
|
|
a: uintptr: 5 bit;
|
|
|
|
b: uintptr: 6 bit;
|
|
|
|
}
|
|
|
|
bitfield struct TestBitFieldStruct3 extends uintptr {
|
|
|
|
c: bool: 1 bit;
|
|
|
|
d: uint32: 9 bit;
|
|
|
|
e: uintptr: 17 bit;
|
|
|
|
}
|
|
|
|
|
|
|
|
@export
|
|
|
|
macro TestBitFieldUintptrOps(
|
|
|
|
val2: TestBitFieldStruct2, val3: TestBitFieldStruct3) {
|
|
|
|
let val2: TestBitFieldStruct2 = val2; // Get a mutable local copy.
|
|
|
|
let val3: TestBitFieldStruct3 = val3; // Get a mutable local copy.
|
|
|
|
|
|
|
|
// Caller is expected to provide these exact values, so we can verify
|
|
|
|
// reading values before starting to write anything.
|
|
|
|
check(val2.a == 3);
|
|
|
|
check(val2.b == 61);
|
|
|
|
check(val3.c);
|
|
|
|
check(val3.d == 500);
|
|
|
|
check(val3.e == 0x1cc);
|
|
|
|
|
|
|
|
val2.b = 16;
|
|
|
|
check(val2.a == 3);
|
|
|
|
check(val2.b == 16);
|
|
|
|
|
|
|
|
val2.b++;
|
|
|
|
check(val2.a == 3);
|
|
|
|
check(val2.b == 17);
|
|
|
|
|
|
|
|
val3.d = 99;
|
|
|
|
val3.e = 1234;
|
|
|
|
check(val3.c);
|
|
|
|
check(val3.d == 99);
|
|
|
|
check(val3.e == 1234);
|
|
|
|
}
|
2020-03-03 15:53:40 +00:00
|
|
|
|
|
|
|
@export
|
|
|
|
class ExportedSubClass extends ExportedSubClassBase {
|
|
|
|
c_field: int32;
|
|
|
|
d_field: int32;
|
|
|
|
e_field: Smi;
|
|
|
|
}
|
|
|
|
|
|
|
|
@export
|
|
|
|
class ExportedSubClassBase extends HeapObject {
|
|
|
|
a: HeapObject;
|
|
|
|
b: HeapObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
class InternalClassWithSmiElements extends FixedArrayBase {
|
|
|
|
data: Smi;
|
|
|
|
object: Oddball;
|
|
|
|
entries[length]: Smi;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct InternalClassStructElement {
|
|
|
|
a: Smi;
|
|
|
|
b: Smi;
|
|
|
|
}
|
|
|
|
|
|
|
|
class InternalClassWithStructElements extends HeapObject {
|
|
|
|
dummy1: int32;
|
|
|
|
dummy2: int32;
|
2020-03-18 08:54:07 +00:00
|
|
|
const count: Smi;
|
2020-03-03 15:53:40 +00:00
|
|
|
data: Smi;
|
|
|
|
object: Object;
|
|
|
|
entries[count]: Smi;
|
|
|
|
more_entries[count]: InternalClassStructElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct SmiGeneratorIterator {
|
|
|
|
macro Next(): Smi labels _NoMore {
|
|
|
|
return this.value++;
|
|
|
|
}
|
|
|
|
value: Smi;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct InternalClassStructElementGeneratorIterator {
|
|
|
|
macro Next(): InternalClassStructElement labels _NoMore {
|
|
|
|
return InternalClassStructElement{a: this.value++, b: this.value++};
|
|
|
|
}
|
|
|
|
value: Smi;
|
|
|
|
}
|
|
|
|
|
|
|
|
@export
|
|
|
|
macro TestFullyGeneratedClassWithElements() {
|
|
|
|
// Test creation, initialization and access of a fully generated class with
|
|
|
|
// simple (Smi) elements
|
|
|
|
const length: Smi = Convert<Smi>(3);
|
|
|
|
const object1 = new InternalClassWithSmiElements{
|
|
|
|
length,
|
|
|
|
data: 0,
|
|
|
|
object: Undefined,
|
|
|
|
entries: ...SmiGeneratorIterator {
|
|
|
|
value: 11
|
|
|
|
}
|
|
|
|
};
|
|
|
|
assert(object1.length == 3);
|
|
|
|
assert(object1.data == 0);
|
|
|
|
assert(object1.object == Undefined);
|
|
|
|
assert(object1.entries[0] == 11);
|
|
|
|
assert(object1.entries[1] == 12);
|
|
|
|
assert(object1.entries[2] == 13);
|
|
|
|
|
|
|
|
// Test creation, initialization and access of a fully generated class
|
|
|
|
// with elements that are a struct.
|
|
|
|
const object2 = new InternalClassWithStructElements{
|
|
|
|
dummy1: 44,
|
|
|
|
dummy2: 45,
|
|
|
|
count: length,
|
|
|
|
data: 55,
|
|
|
|
object: Undefined,
|
|
|
|
entries: ...SmiGeneratorIterator{value: 3},
|
|
|
|
more_entries: ...InternalClassStructElementGeneratorIterator {
|
|
|
|
value: 1
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
assert(object2.dummy1 == 44);
|
|
|
|
assert(object2.dummy2 == 45);
|
|
|
|
assert(object2.count == 3);
|
|
|
|
assert(object2.data == 55);
|
|
|
|
assert(object2.object == Undefined);
|
|
|
|
assert(object2.entries[0] == 3);
|
|
|
|
assert(object2.entries[1] == 4);
|
|
|
|
assert(object2.entries[2] == 5);
|
|
|
|
assert(object2.more_entries[0].a == 1);
|
|
|
|
assert(object2.more_entries[0].b == 2);
|
|
|
|
assert(object2.more_entries[1].a == 3);
|
|
|
|
assert(object2.more_entries[1].b == 4);
|
|
|
|
assert(object2.more_entries[2].a == 5);
|
|
|
|
assert(object2.more_entries[2].b == 6);
|
|
|
|
}
|
|
|
|
|
|
|
|
@export
|
|
|
|
macro TestFullyGeneratedClassFromCpp(): ExportedSubClass {
|
|
|
|
return new
|
|
|
|
ExportedSubClass{a: Null, b: Null, c_field: 7, d_field: 8, e_field: 9};
|
|
|
|
}
|
2018-10-31 14:59:13 +00:00
|
|
|
}
|