Move VM-specific tests out of tests/{language,corelib}.

Change-Id: Iaeae638d2e3fb46409f04982975e78ad4c4eebe5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/472865
Auto-Submit: Lasse Nielsen <lrn@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
This commit is contained in:
Lasse R.H. Nielsen
2026-01-19 04:17:22 -08:00
committed by Commit Queue
parent a02596b28f
commit 8d1ed4b750
181 changed files with 0 additions and 0 deletions
@@ -0,0 +1,142 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Formatting can break multitests, so don't format them.
// dart format off
// Testing integers with and without intrinsics.
// VMOptions=
// VMOptions=--no_intrinsify
// VMOptions=--optimization_counter_threshold=10 --no-background_compilation
library integer_arithmetic_test;
import "package:expect/expect.dart";
foo() => 1234567890123456789;
testSmiOverflow() {
var a = 1073741823;
var b = 1073741822;
Expect.equals(2147483645, a + b);
a = -1000000000;
b = 1000000001;
Expect.equals(-2000000001, a - b);
Expect.equals(-1000000001000000000, a * b);
}
testModPow() {
var x, e, m;
x = 1234567890;
e = 1000000001;
m = 19;
Expect.equals(11, x.modPow(e, m));
x = 1234567890;
e = 19;
m = 1000000001;
Expect.equals(122998977, x.modPow(e, m));
x = 19;
e = 1234567890;
m = 1000000001;
Expect.equals(619059596, x.modPow(e, m));
x = 19;
e = 1000000001;
m = 1234567890;
Expect.equals(84910879, x.modPow(e, m));
x = 1000000001;
e = 19;
m = 1234567890;
Expect.equals(872984351, x.modPow(e, m));
x = 1000000001;
e = 1234567890;
m = 19;
Expect.equals(0, x.modPow(e, m));
}
testModInverse() {
var x, m;
x = 1;
m = 1;
Expect.equals(0, x.modInverse(m));
x = 0;
m = 1000000001;
Expect.throws(() => x.modInverse(m), (e) => e is Exception); // Not coprime.
x = 1234567890;
m = 19;
Expect.equals(11, x.modInverse(m));
x = 1234567890;
m = 1000000001;
Expect.equals(189108911, x.modInverse(m));
x = 19;
m = 1000000001;
Expect.throws(() => x.modInverse(m), (e) => e is Exception); // Not coprime.
x = 19;
m = 1234567890;
Expect.equals(519818059, x.modInverse(m));
x = 1000000001;
m = 1234567890;
Expect.equals(1001100101, x.modInverse(m));
x = 1000000001;
m = 19;
Expect.throws(() => x.modInverse(m), (e) => e is Exception); // Not coprime.
}
testGcd() {
var x, m;
x = 1;
m = 1;
Expect.equals(1, x.gcd(m));
x = 693;
m = 609;
Expect.equals(21, x.gcd(m));
x = 693 << 40;
m = 609 << 40;
Expect.equals(21 << 40, x.gcd(m));
x = 609 << 40;
m = 693 << 40;
Expect.equals(21 << 40, x.gcd(m));
x = 0;
m = 1000000001;
Expect.equals(m, x.gcd(m));
x = 1000000001;
m = 0;
Expect.equals(x, x.gcd(m));
x = 0;
m = -1000000001;
Expect.equals(-m, x.gcd(m));
x = -1000000001;
m = 0;
Expect.equals(-x, x.gcd(m));
x = 0;
m = 0;
Expect.equals(0, x.gcd(m));
x = 1234567890;
m = 19;
Expect.equals(1, x.gcd(m));
x = 1234567890;
m = 1000000001;
Expect.equals(1, x.gcd(m));
x = 19;
m = 1000000001;
Expect.equals(19, x.gcd(m));
x = 19;
m = 1234567890;
Expect.equals(1, x.gcd(m));
x = 1000000001;
m = 1234567890;
Expect.equals(1, x.gcd(m));
x = 1000000001;
m = 19;
Expect.equals(19, x.gcd(m));
}
main() {
for (int i = 0; i < 10; i++) {
Expect.equals(1234567890123456789, foo());
testSmiOverflow();
testModPow(); // //# modPow: ok
testModInverse();
testGcd();
}
}
@@ -0,0 +1,535 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Testing integers with and without intrinsics.
// VMOptions=
// VMOptions=--no_intrinsify
library integer_arithmetic_test;
import "package:expect/expect.dart";
String toHexString(int value) => value >= 0
? "0x${value.toRadixString(16)}"
: "-0x${value.toRadixString(16).substring(1)}";
addSubParsed(String a, String b, String sum) {
int int_a = int.parse(a);
int int_b = int.parse(b);
int int_sum = int.parse(sum);
int computed_sum = int_a + int_b;
Expect.equals(int_sum, computed_sum);
String str_sum = toHexString(computed_sum);
Expect.equals(sum.toLowerCase(), str_sum);
int computed_difference1 = int_sum - int_a;
Expect.equals(int_b, computed_difference1);
String str_difference1 = toHexString(computed_difference1);
Expect.equals(b.toLowerCase(), str_difference1);
int computed_difference2 = int_sum - int_b;
Expect.equals(int_a, computed_difference2);
String str_difference2 = toHexString(computed_difference2);
Expect.equals(a.toLowerCase(), str_difference2);
}
testAddSub() {
String zero = "0x0";
String one = "0x1";
String minus_one = "-0x1";
addSubParsed(zero, zero, zero);
addSubParsed(zero, one, one);
addSubParsed(one, zero, one);
addSubParsed(one, one, "0x2");
addSubParsed(minus_one, minus_one, "-0x2");
addSubParsed("0x123", zero, "0x123");
addSubParsed(zero, "0x123", "0x123");
addSubParsed("0x123", one, "0x124");
addSubParsed(one, "0x123", "0x124");
addSubParsed(
"0xFFFFFFF",
one, // 28 bit overflow.
"0x10000000",
);
addSubParsed(
"0xFFFFFFFF",
one, // 32 bit overflow.
"0x100000000",
);
addSubParsed(
"0xFFFFFFFFFFFFFF",
one, // 56 bit overflow.
"0x100000000000000",
);
addSubParsed(
"0x7FFFFFFFFFFFFFFF",
one, // 64 bit overflow.
"-0x8000000000000000",
);
addSubParsed(
minus_one,
one, // 64 bit overflow.
zero,
);
addSubParsed(
"0x8000000", // 28 bit overflow.
"0x8000000",
"0x10000000",
);
addSubParsed(
"0x80000000", // 32 bit overflow.
"0x80000000",
"0x100000000",
);
addSubParsed(
"0x80000000000000", // 56 bit overflow.
"0x80000000000000",
"0x100000000000000",
);
addSubParsed(
"-0x8000000000000000", // 64 bit overflow.
"-0x8000000000000000",
zero,
);
addSubParsed("-0x123", minus_one, "-0x124");
addSubParsed(minus_one, "-0x123", "-0x124");
addSubParsed(
"-0xFFFFFFF",
minus_one, // 28 bit overflow.
"-0x10000000",
);
addSubParsed(
"-0xFFFFFFFF",
minus_one, // 32 bit overflow.
"-0x100000000",
);
addSubParsed(
"-0xFFFFFFFFFFFFFF",
minus_one, // 56 bit overflow.
"-0x100000000000000",
);
addSubParsed(
"-0x8000000000000000",
minus_one, // 64 bit overflow.
"0x7FFFFFFFFFFFFFFF",
);
addSubParsed(
"-0x8000000", // 28 bit overflow.
"-0x8000000",
"-0x10000000",
);
addSubParsed(
"-0x80000000", // 32 bit overflow.
"-0x80000000",
"-0x100000000",
);
addSubParsed(
"-0x80000000000000", // 56 bit overflow.
"-0x80000000000000",
"-0x100000000000000",
);
addSubParsed(
"-0x8000000000000000", // 64 bit overflow.
"-0x8000000000000000",
"0x0",
);
addSubParsed("0xB", "-0x7", "0x4");
addSubParsed("-0xB", "-0x7", "-0x12");
addSubParsed("0xB", "0x7", "0x12");
addSubParsed("-0xB", "0x7", "-0x4");
addSubParsed("-0x7", "0xB", "0x4");
addSubParsed("-0x7", "-0xB", "-0x12");
addSubParsed("0x7", "0xB", "0x12");
addSubParsed("0x7", "-0xB", "-0x4");
}
shiftLeftParsed(
String a,
int amount,
String result, {
String? result_back_shifted,
}) {
result_back_shifted ??= a;
int int_a = int.parse(a);
int int_result = int.parse(result);
int int_result_back_shifted = int.parse(result_back_shifted);
int shifted = int_a << amount;
Expect.equals(int_result, shifted);
String str_shifted = toHexString(shifted);
Expect.equals(result.toLowerCase(), str_shifted);
int back_shifted = shifted >> amount;
Expect.equals(int_result_back_shifted, back_shifted);
String str_back_shifted = toHexString(back_shifted);
Expect.equals(result_back_shifted.toLowerCase(), str_back_shifted);
}
testLeftShift() {
String zero = "0x0";
String one = "0x1";
String minus_one = "-0x1";
shiftLeftParsed(zero, 0, zero);
shiftLeftParsed(one, 0, one);
shiftLeftParsed("0x1234", 0, "0x1234");
shiftLeftParsed(zero, 100000, zero);
shiftLeftParsed(one, 1, "0x2");
shiftLeftParsed(one, 28, "0x10000000");
shiftLeftParsed(one, 32, "0x100000000");
shiftLeftParsed(one, 64, zero, result_back_shifted: zero);
shiftLeftParsed("0x5", 28, "0x50000000");
shiftLeftParsed("0x5", 32, "0x500000000");
shiftLeftParsed("0x5", 56, "0x500000000000000");
shiftLeftParsed("0x5", 64, zero, result_back_shifted: zero);
shiftLeftParsed("0x5", 128, zero, result_back_shifted: zero);
shiftLeftParsed("0x5", 27, "0x28000000");
shiftLeftParsed("0x5", 31, "0x280000000");
shiftLeftParsed("0x5", 55, "0x280000000000000");
shiftLeftParsed(
"0x5",
63,
"-0x8000000000000000",
result_back_shifted: "-0x1",
);
shiftLeftParsed("0x5", 127, zero, result_back_shifted: zero);
shiftLeftParsed("0x8000001", 1, "0x10000002");
shiftLeftParsed("0x80000001", 1, "0x100000002");
shiftLeftParsed("0x8000000000000001", 1, "0x2", result_back_shifted: "0x1");
shiftLeftParsed("0x8000001", 29, "0x100000020000000");
shiftLeftParsed("0x80000001", 33, "0x200000000", result_back_shifted: "0x1");
shiftLeftParsed("0x8000000000000001", 65, zero, result_back_shifted: zero);
shiftLeftParsed("0x7fffffffffffffff", 1, "-0x2", result_back_shifted: "-0x1");
shiftLeftParsed(
"0x7fffffffffffffff",
29,
"-0x20000000",
result_back_shifted: "-0x1",
);
shiftLeftParsed(minus_one, 0, minus_one);
shiftLeftParsed("-0x1234", 0, "-0x1234");
shiftLeftParsed(minus_one, 1, "-0x2");
shiftLeftParsed(minus_one, 28, "-0x10000000");
shiftLeftParsed(minus_one, 32, "-0x100000000");
shiftLeftParsed(minus_one, 64, zero, result_back_shifted: zero);
shiftLeftParsed("-0x5", 28, "-0x50000000");
shiftLeftParsed("-0x5", 32, "-0x500000000");
shiftLeftParsed("-0x5", 64, zero, result_back_shifted: zero);
shiftLeftParsed("-0x5", 27, "-0x28000000");
shiftLeftParsed("-0x5", 31, "-0x280000000");
shiftLeftParsed(
"-0x5",
63,
"-0x8000000000000000",
result_back_shifted: minus_one,
);
shiftLeftParsed("-0x8000001", 1, "-0x10000002");
shiftLeftParsed("-0x80000001", 1, "-0x100000002");
shiftLeftParsed("-0x8000001", 29, "-0x100000020000000");
shiftLeftParsed(
"-0x80000001",
33,
"-0x200000000",
result_back_shifted: "-0x1",
);
shiftLeftParsed("-0x7fffffffffffffff", 1, "0x2", result_back_shifted: "0x1");
shiftLeftParsed("-0x7fffffffffffffff", 65, zero, result_back_shifted: zero);
shiftLeftParsed("-0x8000000000000000", 1, zero, result_back_shifted: zero);
shiftLeftParsed("-0x8000000000000000", 29, zero, result_back_shifted: zero);
}
shiftRightParsed(String a, int amount, String result) {
int int_a = int.parse(a);
int int_result = int.parse(result);
int shifted = int_a >> amount;
Expect.equals(int_result, shifted);
String str_shifted = toHexString(shifted);
Expect.equals(result.toLowerCase(), str_shifted);
}
testRightShift() {
String zero = "0x0";
String one = "0x1";
String minus_one = "-0x1";
shiftRightParsed(one, 1, zero);
shiftRightParsed(minus_one, 1, minus_one);
shiftRightParsed("-0x2", 1, minus_one);
shiftRightParsed("0x12345678", 29, zero);
shiftRightParsed("-0x12345678", 29, minus_one);
shiftRightParsed("-0x12345678", 100, minus_one);
shiftRightParsed("0x5", 1, "0x2");
shiftRightParsed("0x5", 2, "0x1");
shiftRightParsed("-0x5", 1, "-0x3");
shiftRightParsed("-0x5", 2, "-0x2");
shiftRightParsed("0x10000001", 28, one);
shiftRightParsed("0x100000001", 32, one);
shiftRightParsed("0x1000000000000001", 60, one);
shiftRightParsed("0x1000000000000001", 64, zero);
shiftRightParsed("-0x10000001", 28, "-0x2");
shiftRightParsed("-0x100000001", 32, "-0x2");
shiftRightParsed("-0x1000000000000001", 64, minus_one);
shiftRightParsed("0x30000000", 29, one);
shiftRightParsed("0x300000000", 33, one);
shiftRightParsed("0x3000000000000000", 61, one);
shiftRightParsed("0x3000000000000000", 65, zero);
shiftRightParsed("-0x30000000", 29, "-0x2");
shiftRightParsed("-0x300000000", 33, "-0x2");
shiftRightParsed("-0x3000000000000000", 60, "-0x3");
shiftRightParsed("-0x3000000000000000", 65, minus_one);
}
bitAndParsed(String a, String b, String result) {
int int_a = int.parse(a);
int int_b = int.parse(b);
int int_result = int.parse(result);
int anded = int_a & int_b;
Expect.equals(int_result, anded);
String str_anded = toHexString(anded);
Expect.equals(result.toLowerCase(), str_anded);
int anded2 = int_b & int_a;
Expect.equals(int_result, anded2);
String str_anded2 = toHexString(anded2);
Expect.equals(result.toLowerCase(), str_anded2);
}
testBitAnd() {
String zero = "0x0";
String one = "0x1";
String minus_one = "-0x1";
bitAndParsed(one, zero, zero);
bitAndParsed(one, one, one);
bitAndParsed(minus_one, zero, zero);
bitAndParsed(minus_one, one, one);
bitAndParsed(minus_one, minus_one, minus_one);
bitAndParsed("0x5", "0x3", one);
bitAndParsed("0x5", minus_one, "0x5");
bitAndParsed("0x50000000", one, zero);
bitAndParsed("0x50000000", minus_one, "0x50000000");
bitAndParsed("0x500000000", one, zero);
bitAndParsed("0x500000000", minus_one, "0x500000000");
bitAndParsed("0x5000000000000000", one, zero);
bitAndParsed("0x5000000000000000", minus_one, "0x5000000000000000");
bitAndParsed("-0x50000000", "-0x50000000", "-0x50000000");
bitAndParsed("-0x500000000", "-0x500000000", "-0x500000000");
bitAndParsed("0x12345678", "0xFFFFFFF", "0x2345678");
bitAndParsed("0x123456789", "0xFFFFFFFF", "0x23456789");
bitAndParsed("-0x10000000", "0xFFFFFFF", "0x0");
bitAndParsed("-0x100000000", "0xFFFFFFFF", "0x0");
bitAndParsed("-0x10000001", "0xFFFFFFF", "0xFFFFFFF");
bitAndParsed("-0x100000001", "0xFFFFFFFF", "0xFFFFFFFF");
bitAndParsed("-0x10000001", "0x3FFFFFFF", "0x2FFFFFFF");
bitAndParsed("-0x100000001", "0x3FFFFFFFF", "0x2FFFFFFFF");
bitAndParsed("-0x100000000000000", "0xFFFFFFFFFFFFFF", "0x0");
bitAndParsed(
"-0x1000000000000000",
"0xFFFFFFFFFFFFFFFF",
"-0x1000000000000000",
);
bitAndParsed("-0x300000000000000", "0xFFFFFFFFFFFFFFF", "0xD00000000000000");
bitAndParsed(
"-0x3000000000000000",
"0xFFFFFFFFFFFFFFFF",
"-0x3000000000000000",
);
bitAndParsed("-0x10000000", "-0x10000000", "-0x10000000");
bitAndParsed("-0x100000000", "-0x100000000", "-0x100000000");
bitAndParsed(
"-0x100000000000000",
"-0x100000000000000",
"-0x100000000000000",
);
bitAndParsed(
"-0x1000000000000000",
"-0x1000000000000000",
"-0x1000000000000000",
);
bitAndParsed("-0x3", "-0x2", "-0x4");
bitAndParsed("-0x10000000", "-0x10000001", "-0x20000000");
bitAndParsed("-0x100000000", "-0x100000001", "-0x200000000");
bitAndParsed(
"-0x100000000000000",
"-0x100000000000001",
"-0x200000000000000",
);
bitAndParsed(
"-0x1000000000000000",
"-0x1000000000000001",
"-0x2000000000000000",
);
}
bitOrParsed(String a, String b, String result) {
int int_a = int.parse(a);
int int_b = int.parse(b);
int int_result = int.parse(result);
int ored = int_a | int_b;
Expect.equals(int_result, ored);
String str_ored = toHexString(ored);
Expect.equals(result.toLowerCase(), str_ored);
int ored2 = int_b | int_a;
Expect.equals(int_result, ored2);
String str_ored2 = toHexString(ored2);
Expect.equals(result.toLowerCase(), str_ored2);
}
testBitOr() {
String zero = "0x0";
String one = "0x1";
String minus_one = "-0x1";
bitOrParsed(one, zero, one);
bitOrParsed(one, one, one);
bitOrParsed(minus_one, zero, minus_one);
bitOrParsed(minus_one, one, minus_one);
bitOrParsed(minus_one, minus_one, minus_one);
bitOrParsed("-0x3", one, "-0x3");
bitOrParsed("0x5", "0x3", "0x7");
bitOrParsed("0x5", minus_one, minus_one);
bitOrParsed("0x5", zero, "0x5");
bitOrParsed("0x50000000", one, "0x50000001");
bitOrParsed("0x50000000", minus_one, minus_one);
bitOrParsed("0x500000000", one, "0x500000001");
bitOrParsed("0x500000000", minus_one, minus_one);
bitOrParsed("0x5000000000000000", one, "0x5000000000000001");
bitOrParsed("0x5000000000000000", minus_one, minus_one);
bitOrParsed("-0x50000000", "-0x50000000", "-0x50000000");
bitOrParsed("-0x500000000", "-0x500000000", "-0x500000000");
bitOrParsed("0x12345678", "0xFFFFFFF", "0x1FFFFFFF");
bitOrParsed("0x123456789", "0xFFFFFFFF", "0x1FFFFFFFF");
bitOrParsed("-0x10000000", "0xFFFFFFF", "-0x1");
bitOrParsed("-0x100000000", "0xFFFFFFFF", "-0x1");
bitOrParsed("-0x10000001", "0xFFFFFFF", "-0x10000001");
bitOrParsed("-0x100000001", "0xFFFFFFFF", "-0x100000001");
bitOrParsed("-0x10000001", "0x3FFFFFFF", "-0x1");
bitOrParsed("-0x100000001", "0x3FFFFFFFF", "-0x1");
bitOrParsed("-0x1000000000000001", "0x3FFFFFFFFFFFFFFF", "-0x1");
bitOrParsed("-0x100000000000000", "0xFFFFFFFFFFFFFF", "-0x1");
bitOrParsed("-0x1000000000000000", "0xFFFFFFFFFFFFFFF", "-0x1");
bitOrParsed("-0x300000000000000", "0xFFFFFFFFFFFFFFF", "-0x1");
bitOrParsed("-0x3000000000000000", "0xFFFFFFFFFFFFFFFF", "-0x1");
bitOrParsed("-0x10000000", "-0x10000000", "-0x10000000");
bitOrParsed("-0x100000000", "-0x100000000", "-0x100000000");
bitOrParsed("-0x100000000000000", "-0x100000000000000", "-0x100000000000000");
bitOrParsed(
"-0x1000000000000000",
"-0x1000000000000000",
"-0x1000000000000000",
);
bitOrParsed("-0x10000000", "-0x10000001", "-0x1");
bitOrParsed("-0x100000000", "-0x100000001", "-0x1");
bitOrParsed("-0x100000000000000", "-0x100000000000001", "-0x1");
bitOrParsed("-0x1000000000000000", "-0x1000000000000001", "-0x1");
bitOrParsed("-0x1000000000000000", "-0x1", "-0x1");
}
bitXorParsed(String a, String b, String result) {
int int_a = int.parse(a);
int int_b = int.parse(b);
int int_result = int.parse(result);
int xored = int_a ^ int_b;
Expect.equals(int_result, xored);
String str_xored = toHexString(xored);
Expect.equals(result.toLowerCase(), str_xored);
int xored2 = int_b ^ int_a;
Expect.equals(int_result, xored2);
String str_xored2 = toHexString(xored2);
Expect.equals(result.toLowerCase(), str_xored2);
int xored3 = int_a ^ xored2;
Expect.equals(int_b, xored3);
String str_xored3 = toHexString(xored3);
Expect.equals(b.toLowerCase(), str_xored3);
}
testBitXor() {
String zero = "0x0";
String one = "0x1";
String minus_one = "-0x1";
bitXorParsed(one, zero, one);
bitXorParsed(one, one, zero);
bitXorParsed(minus_one, zero, minus_one);
bitXorParsed(minus_one, one, "-0x2");
bitXorParsed(minus_one, minus_one, zero);
bitXorParsed("0x5", "0x3", "0x6");
bitXorParsed("0x5", minus_one, "-0x6");
bitXorParsed("0x5", zero, "0x5");
bitXorParsed(minus_one, "-0x8", "0x7");
bitXorParsed("0x50000000", one, "0x50000001");
bitXorParsed("0x50000000", minus_one, "-0x50000001");
bitXorParsed("0x500000000", one, "0x500000001");
bitXorParsed("0x500000000", minus_one, "-0x500000001");
bitXorParsed("0x5000000000000000", one, "0x5000000000000001");
bitXorParsed("0x5000000000000000", minus_one, "-0x5000000000000001");
bitXorParsed("-0x50000000", "-0x50000000", zero);
bitXorParsed("-0x500000000", "-0x500000000", zero);
bitXorParsed("0x12345678", "0xFFFFFFF", "0x1DCBA987");
bitXorParsed("0x123456789", "0xFFFFFFFF", "0x1DCBA9876");
bitXorParsed("-0x10000000", "0xFFFFFFF", "-0x1");
bitXorParsed("-0x100000000", "0xFFFFFFFF", "-0x1");
bitXorParsed("-0x10000001", "0xFFFFFFF", "-0x20000000");
bitXorParsed("-0x100000001", "0xFFFFFFFF", "-0x200000000");
bitXorParsed("-0x10000001", "0x3FFFFFFF", "-0x30000000");
bitXorParsed("-0x100000001", "0x3FFFFFFFF", "-0x300000000");
bitXorParsed(
"-0x1000000000000001",
"0x3FFFFFFFFFFFFFFF",
"-0x3000000000000000",
);
bitXorParsed("-0x100000000000000", "0xFFFFFFFFFFFFFF", "-0x1");
bitXorParsed("-0x1000000000000000", "0xFFFFFFFFFFFFFFF", "-0x1");
bitXorParsed("-0x300000000000000", "0xFFFFFFFFFFFFFFF", "-0xD00000000000001");
bitXorParsed("-0x3000000000000000", "-0x1", "0x2FFFFFFFFFFFFFFF");
bitXorParsed("-0x10000000", "-0x10000000", zero);
bitXorParsed("-0x100000000", "-0x100000000", zero);
bitXorParsed("-0x100000000000000", "-0x100000000000000", zero);
bitXorParsed("-0x1000000000000000", "-0x1000000000000000", zero);
bitXorParsed("-0x10000000", "-0x10000001", "0x1FFFFFFF");
bitXorParsed("-0x100000000", "-0x100000001", "0x1FFFFFFFF");
bitXorParsed("-0x100000000000000", "-0x100000000000001", "0x1FFFFFFFFFFFFFF");
bitXorParsed(
"-0x1000000000000000",
"-0x1000000000000001",
"0x1FFFFFFFFFFFFFFF",
);
}
bitNotParsed(String a, String result) {
int int_a = int.parse(a);
int int_result = int.parse(result);
int inverted = ~int_a;
Expect.equals(int_result, inverted);
String str_inverted = toHexString(inverted);
Expect.equals(result.toLowerCase(), str_inverted);
int back = ~inverted;
Expect.equals(int_a, back);
String str_back = toHexString(back);
Expect.equals(a.toLowerCase(), str_back);
}
testBitNot() {
String zero = "0x0";
String one = "0x1";
String minus_one = "-0x1";
bitNotParsed(zero, minus_one);
bitNotParsed(one, "-0x2");
bitNotParsed("0x5", "-0x6");
bitNotParsed("0x50000000", "-0x50000001");
bitNotParsed("0xFFFFFFF", "-0x10000000");
bitNotParsed("0xFFFFFFFF", "-0x100000000");
bitNotParsed("0xFFFFFFFFFFFFFF", "-0x100000000000000");
bitNotParsed("0x7FFFFFFFFFFFFFFF", "-0x8000000000000000");
bitNotParsed("-0x1", "0x0");
}
main() {
testAddSub();
testLeftShift();
testRightShift();
testBitAnd();
testBitOr();
testBitXor();
testBitNot();
}
@@ -0,0 +1,69 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Formatting can break multitests, so don't format them.
// dart format off
// Testing integers with and without intrinsics.
// VMOptions=
// VMOptions=--no_intrinsify
library integer_arithmetic_test;
import "package:expect/expect.dart";
divRemParsed(String a, String b, String quotient, String remainder) {
int int_a = int.parse(a);
int int_b = int.parse(b);
int int_quotient = int.parse(quotient);
int int_remainder = int.parse(remainder);
int computed_quotient = int_a ~/ int_b;
Expect.equals(int_quotient, computed_quotient);
String str_quotient = computed_quotient >= 0
? "0x${computed_quotient.toRadixString(16)}"
: "-0x${computed_quotient.toRadixString(16).substring(1)}";
Expect.equals(quotient.toLowerCase(), str_quotient);
int computed_remainder = int_a.remainder(int_b) as int;
Expect.equals(int_remainder, computed_remainder);
String str_remainder = computed_remainder >= 0
? "0x${computed_remainder.toRadixString(16)}"
: "-0x${computed_remainder.toRadixString(16).substring(1)}";
Expect.equals(remainder.toLowerCase(), str_remainder);
}
testDivideRemainder() {
String zero = "0x0";
String one = "0x1";
String minus_one = "-0x1";
divRemParsed(one, one, one, zero);
divRemParsed(zero, one, zero, zero);
divRemParsed(minus_one, one, minus_one, zero);
divRemParsed(one, "0x2", zero, one);
divRemParsed(minus_one, "0x7", zero, minus_one);
divRemParsed("0xB", "0x7", one, "0x4");
divRemParsed("0x12345678", "0x7", "0x299C335", "0x5");
divRemParsed("-0x12345678", "0x7", "-0x299C335", "-0x5");
divRemParsed("0x12345678", "-0x7", "-0x299C335", "0x5");
divRemParsed("-0x12345678", "-0x7", "0x299C335", "-0x5");
divRemParsed("0x7", "0x12345678", zero, "0x7");
divRemParsed("-0x7", "0x12345678", zero, "-0x7");
divRemParsed("-0x7", "-0x12345678", zero, "-0x7");
divRemParsed("0x7", "-0x12345678", zero, "0x7");
divRemParsed("0x12345678", "0x7", "0x299C335", "0x5");
divRemParsed("-0x12345678", "0x7", "-0x299C335", "-0x5");
divRemParsed("0x12345678", "-0x7", "-0x299C335", "0x5");
divRemParsed("-0x12345678", "-0x7", "0x299C335", "-0x5");
divRemParsed("9223372036854775807", "0x7", "0x1249249249249249", "0x0");
divRemParsed("9223372036854775807", "-0x7", "-0x1249249249249249", "0x0");
divRemParsed("-9223372036854775807", "0x7", "-0x1249249249249249", "0x0");
divRemParsed("-9223372036854775807", "-0x7", "0x1249249249249249", "0x0");
divRemParsed("-9223372036854775808", "-1", "-0x8000000000000000", "0x0"); //# 01: ok
divRemParsed("-9223372036854775808", "0x7", "-0x1249249249249249", "-0x1");
divRemParsed("-9223372036854775808", "-0x7", "0x1249249249249249", "-0x1");
}
main() {
testDivideRemainder();
}
@@ -0,0 +1,96 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Testing integers with and without intrinsics.
// VMOptions=
// VMOptions=--no_intrinsify
library integer_arithmetic_test;
import "package:expect/expect.dart";
mulDivParsed(
String a,
String b,
String product, {
String? expected_quotient1,
String? expected_quotient2,
}) {
int int_a = int.parse(a);
int int_b = int.parse(b);
int int_product = int.parse(product);
int computed_product = int_a * int_b;
Expect.equals(int_product, computed_product);
String str_product = computed_product >= 0
? "0x${computed_product.toRadixString(16)}"
: "-0x${(-computed_product).toRadixString(16)}";
Expect.equals(product.toLowerCase(), str_product);
int computed_product2 = int_b * int_a;
Expect.equals(int_product, computed_product2);
String str_product2 = computed_product2 >= 0
? "0x${computed_product2.toRadixString(16)}"
: "-0x${(-computed_product2).toRadixString(16)}";
Expect.equals(product.toLowerCase(), str_product2);
if (int_a != 0) {
expected_quotient1 ??= b;
int int_expected_quotient1 = int.parse(expected_quotient1);
int computed_quotient1 = int_product ~/ int_a;
Expect.equals(int_expected_quotient1, computed_quotient1);
String str_quotient1 = computed_quotient1 >= 0
? "0x${computed_quotient1.toRadixString(16)}"
: "-0x${(-computed_quotient1).toRadixString(16)}";
Expect.equals(expected_quotient1.toLowerCase(), str_quotient1);
}
if (int_b != 0) {
expected_quotient2 ??= a;
int int_expected_quotient2 = int.parse(expected_quotient2);
int computed_quotient2 = int_product ~/ int_b;
Expect.equals(int_expected_quotient2, computed_quotient2);
String str_quotient2 = computed_quotient2 >= 0
? "0x${computed_quotient2.toRadixString(16)}"
: "-0x${(-computed_quotient2).toRadixString(16)}";
Expect.equals(expected_quotient2.toLowerCase(), str_quotient2);
}
}
testMultiplyDivide() {
String zero = "0x0";
String one = "0x1";
String minus_one = "-0x1";
mulDivParsed(zero, zero, zero);
mulDivParsed(one, one, one);
mulDivParsed(one, zero, zero);
mulDivParsed(zero, one, zero);
mulDivParsed(one, minus_one, minus_one);
mulDivParsed(minus_one, minus_one, one);
mulDivParsed("0x42", one, "0x42");
mulDivParsed("0x42", "0x2", "0x84");
mulDivParsed("0xFFFF", "0x2", "0x1FFFE");
mulDivParsed("0x3", "0x5", "0xF");
mulDivParsed("0xFFFFF", "0x5", "0x4FFFFB");
mulDivParsed("0xFFFFFFF", "0x5", "0x4FFFFFFB");
mulDivParsed("0xFFFFFFFF", "0x5", "0x4FFFFFFFB");
mulDivParsed(
"0x7FFFFFFFFFFFFFFF",
"0x5",
"0x7FFFFFFFFFFFFFFB",
expected_quotient1: zero,
expected_quotient2: "0x1999999999999998",
);
mulDivParsed(
"0x7FFFFFFFFFFFFFFF",
"0x3039",
"0x7FFFFFFFFFFFCFC7",
expected_quotient1: zero,
expected_quotient2: "0x2A783BE38C73D",
);
mulDivParsed("0x10000001", "0x5", "0x50000005");
}
main() {
testMultiplyDivide();
}
@@ -0,0 +1,74 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Dart test program for testing class 'StringBase' (currently VM specific).
library string_base_test;
import "package:expect/expect.dart";
class StringBaseTest {
StringBaseTest() {}
toString() {
return "StringBase Tester";
}
static testInterpolation() {
var answer = 40 + 2;
var s = "The answer is $answer.";
Expect.equals("The answer is 42.", s);
int numBottles = 33;
String wall = "wall";
s = "${numBottles * 3} bottles of beer on the $wall.";
Expect.equals("99 bottles of beer on the wall.", s);
}
static testCreation() {
String s = "Hello";
List<int> a = new List<int>.filled(s.length, -1);
List<int> ga = [];
bool exception_caught = false;
for (int i = 0; i < a.length; i++) {
a[i] = s.codeUnitAt(i);
ga.add(s.codeUnitAt(i));
}
try {
String s4 = new String.fromCharCodes([-1]);
} on ArgumentError catch (ex) {
exception_caught = true;
}
Expect.equals(true, exception_caught);
}
static testSubstring() {
String s = "Hello World";
Expect.equals("World", s.substring(6, s.length));
Expect.equals("", s.substring(8, 8));
bool exception_caught = false;
try {
s.substring(5, 12);
} on RangeError catch (ex) {
exception_caught = true;
}
Expect.equals(true, exception_caught);
exception_caught = false;
try {
s.substring(5, 4);
} on RangeError catch (ex) {
exception_caught = true;
}
Expect.equals(true, exception_caught);
}
static void testMain() {
testInterpolation();
testCreation();
testSubstring();
}
}
main() {
StringBaseTest.testMain();
}
@@ -0,0 +1,36 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:expect/expect.dart';
const interestingLengths = <int>[
0x3FFFFFFF00000000,
0x3FFFFFFFFFFFF000,
0x3FFFFFFFFFFFFF00,
0x3FFFFFFFFFFFFFF0,
0x3FFFFFFFFFFFFFFE,
0x3FFFFFFFFFFFFFFF,
0x7FFFFFFF00000000,
0x7FFFFFFFFFFFF000,
0x7FFFFFFFFFFFFF00,
0x7FFFFFFFFFFFFFF0,
0x7FFFFFFFFFFFFFFE,
0x7FFFFFFFFFFFFFFF,
];
main() {
for (int interestingLength in interestingLengths) {
for (int elementLength in <int>[1, 2, 3, 4, 5, 6, 7, 8, 9]) {
print(interestingLength ~/ elementLength);
Expect.throws(() {
var array = new List<dynamic>.filled(
interestingLength ~/ elementLength,
null,
);
print(array.first);
}, (e) => e is OutOfMemoryError);
}
}
}
@@ -0,0 +1,49 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:typed_data';
import 'package:expect/expect.dart';
const interestingLengths = <int>[
0x3FFFFFFF00000000,
0x3FFFFFFFFFFFFFF0,
0x3FFFFFFFFFFFFFFE,
0x3FFFFFFFFFFFFFFF,
0x7FFFFFFF00000000,
0x7FFFFFFFFFFFFFF0,
0x7FFFFFFFFFFFFFFE,
0x7FFFFFFFFFFFFFFF,
];
main() {
for (int interestingLength in interestingLengths) {
bool exceptionCheck(e) {
// Allow RangeError as the range check may happen before the allocation.
return e is RangeError || e is OutOfMemoryError;
}
print(interestingLength);
Expect.throws(() {
var bytearray = new Uint8List(interestingLength);
print(bytearray.first);
}, exceptionCheck);
Expect.throws(() {
var bytearray = new Uint8ClampedList(interestingLength);
print(bytearray.first);
}, exceptionCheck);
Expect.throws(() {
var bytearray = new Int8List(interestingLength);
print(bytearray.first);
}, exceptionCheck);
Expect.throws(() {
var bytearray = new ByteData(interestingLength);
print(bytearray.getUint8(0));
}, exceptionCheck);
}
}
@@ -0,0 +1,37 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:expect/expect.dart';
const interestingLengths = <int>[
0x3FFFFFFF00000000,
0x3FFFFFFFFFFFFFF0,
0x3FFFFFFFFFFFFFFE,
0x3FFFFFFFFFFFFFFF,
0x7FFFFFFF00000000,
0x7FFFFFFFFFFFFFF0,
0x7FFFFFFFFFFFFFFE,
0x7FFFFFFFFFFFFFFF,
];
main() {
for (int interestingLength in interestingLengths) {
print(interestingLength);
Expect.throws(() {
var oneByteString = "v";
oneByteString *= interestingLength;
}, (e) => e is OutOfMemoryError);
Expect.throws(() {
var oneByteString = "v";
oneByteString = oneByteString.padLeft(interestingLength);
}, (e) => e is OutOfMemoryError);
Expect.throws(() {
var oneByteString = "v";
oneByteString = oneByteString.padRight(interestingLength);
}, (e) => e is OutOfMemoryError);
}
}
@@ -0,0 +1,92 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization-counter-threshold=100 --deterministic
// Tests allocation sinking of arrays and typed data objects.
import 'dart:typed_data';
import 'package:expect/expect.dart';
import 'dart:typed_data';
class Vector2 {
final Float64List _v2storage;
@pragma('vm:prefer-inline')
Vector2.zero() : _v2storage = Float64List(2);
@pragma('vm:prefer-inline')
factory Vector2(double x, double y) => Vector2.zero()..setValues(x, y);
@pragma('vm:prefer-inline')
factory Vector2.copy(Vector2 other) => Vector2.zero()..setFrom(other);
@pragma('vm:prefer-inline')
Vector2 clone() => Vector2.copy(this);
@pragma('vm:prefer-inline')
void setValues(double x_, double y_) {
_v2storage[0] = x_;
_v2storage[1] = y_;
}
@pragma('vm:prefer-inline')
void setFrom(Vector2 other) {
final otherStorage = other._v2storage;
_v2storage[1] = otherStorage[1];
_v2storage[0] = otherStorage[0];
}
@pragma('vm:prefer-inline')
Vector2 operator +(Vector2 other) => clone()..add(other);
@pragma('vm:prefer-inline')
void add(Vector2 arg) {
final argStorage = arg._v2storage;
_v2storage[0] = _v2storage[0] + argStorage[0];
_v2storage[1] = _v2storage[1] + argStorage[1];
}
@pragma('vm:prefer-inline')
double get x => _v2storage[0];
@pragma('vm:prefer-inline')
double get y => _v2storage[1];
}
@pragma('vm:never-inline')
String foo(double x, num doDeopt) {
// All allocations in this function are eliminated by the compiler,
// except array allocation for string interpolation at the end.
List v1 = List.filled(2, null);
v1[0] = 1;
v1[1] = 'hi';
Vector2 v2 = new Vector2(1.0, 2.0);
Vector2 v3 = v2 + Vector2(x, x);
double sum = v3.x + v3.y;
Float32List v4 = Float32List(2);
v4[0] = 11.0;
v4[1] = sum + 3;
print(v4[0]);
// Deoptimization is triggered here to materialize removed allocations.
doDeopt + 2;
return "v1: [${v1[0]},${v1[1]}], v2: [${v2.x},${v2.y}], v3: [${v3.x},${v3.y}], v4: [${v4[0]}, ${v4[1]}], sum: $sum";
}
main() {
// Due to '--optimization-counter-threshold=100 --deterministic'
// foo() is optimized during the first 100 iterations.
// After that, on iteration 120 deoptimization is triggered by changed
// type of 'doDeopt'. That forces materialization of all objects which
// allocations were removed by optimizer.
for (int i = 0; i < 130; ++i) {
final num doDeopt = (i < 120 ? 1 : 2.0);
final result = foo(3.0, doDeopt);
Expect.equals(
"v1: [1,hi], v2: [1.0,2.0], v3: [4.0,5.0], v4: [11.0, 12.0], sum: 9.0",
result,
);
}
}
@@ -0,0 +1,352 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test allocation sinking optimization.
// VMOptions=--optimization-counter-threshold=10 --no-use-osr --no-background-compilation
import 'dart:typed_data';
import 'package:expect/expect.dart';
class Point {
var x, y;
Point(this.x, this.y);
operator *(other) {
return x * other.x + y * other.y;
}
}
class C {
var p;
C(this.p);
}
class Pointx4 {
var x, y;
Pointx4(this.x, this.y);
operator *(other) {
return x * other.x + y * other.y;
}
}
class Cx4 {
var p;
Cx4(this.p);
}
class D {
var p;
D(this.p);
}
// Class that is used to capture materialized Point object with * operator.
class F {
var p;
var val;
F(this.p);
operator *(other) {
Expect.isTrue(other is Point);
Expect.equals(42.0, other.x);
Expect.equals(0.5, other.y);
if (val == null) {
val = other;
} else {
Expect.isTrue(identical(val, other));
}
return this.p * other;
}
}
test1(c, x, y) {
var a = new Point(x - 0.5, y + 0.5);
var b = new Point(x + 0.5, y + 0.8);
var d = new Point(c.p * a, c.p * b);
return d * d;
}
test1x4(c, x, y, z, w) {
var a = new Pointx4(x - z, y + w);
var b = new Pointx4(x + w, y + z);
var d = new Pointx4(c.p * a, c.p * b);
return d * d;
}
@pragma("vm:never-inline")
@pragma("vm:entry-point")
@pragma("dart2js:noInline")
effects() {
// This function should not be inlinable.
try {} catch (e) {}
}
testForwardingThroughEffects(c, x, y) {
var a = new Point(x - 0.5, y + 0.5);
var b = new Point(x - 0.5, y - 0.8);
var d = new Point(c.p * a, c.p * b);
// Effects can't affect neither a, b, nor d because they do not escape.
effects();
effects();
return ((a == null) ? 0.0 : 0.1) + (d * d);
}
testIdentity(x) {
var y = new Point(42.0, 0.5);
var z = y;
return x * y + x * z;
}
class PointP<T> {
var x, y;
PointP(this.x, this.y);
operator *(other) {
return x * other.x + y * other.y;
}
}
foo2() => new PointP<int>(1, 3) * new PointP<num>(5, 6);
class A<T> {
var x, y;
}
foo3(x) {
// Test materialization of type arguments.
var a = new A<int>();
a.x = x;
a.y = x;
if (x is int) return a.x + a.y;
Expect.isFalse(a is A<double>);
Expect.isTrue(a is A<int>);
Expect.isTrue(a is A);
return a.x - a.y;
}
class WithFinal {
final _x;
WithFinal(this._x);
}
testInitialValueForFinalField(x) {
new WithFinal(x);
}
testFinalField() {
for (var i = 0; i < 100; i++) {
testInitialValueForFinalField(1);
}
}
class V {
var x = 0;
}
test_vm_field() {
var obj;
inner() => obj.x = 42;
var a = new V();
obj = a;
var t1 = a.x;
var t2 = inner();
return a.x + t1 + t2;
}
testVMField() {
Expect.equals(84, test_vm_field());
for (var i = 0; i < 100; i++) test_vm_field();
Expect.equals(84, test_vm_field());
}
class CompoundA {
var b;
CompoundA(this.b);
}
class CompoundB {
var c;
CompoundB(this.c);
}
class CompoundC {
var d;
var root;
CompoundC(this.d);
}
class NoopSink {
const NoopSink();
call(val) {}
}
testCompound1() {
f(d, [sink = const NoopSink()]) {
var c = new CompoundC(d);
var a = new CompoundA(new CompoundB(c));
sink(a);
return c.d;
}
Expect.equals(0.1, f(0.1));
for (var i = 0; i < 100; i++) f(0.1);
Expect.equals(0.1, f(0.1));
Expect.equals(
0.1,
f(0.1, (val) {
Expect.isTrue(val is CompoundA);
Expect.isTrue(val.b is CompoundB);
Expect.isTrue(val.b.c is CompoundC);
Expect.isNull(val.b.c.root);
Expect.equals(0.1, val.b.c.d);
}),
);
}
testCompound2() {
f(d, [sink = const NoopSink()]) {
var c = new CompoundC(d);
var a = new CompoundA(new CompoundB(c));
c.root = a;
sink(a);
return c.d;
}
Expect.equals(0.1, f(0.1));
for (var i = 0; i < 100; i++) f(0.1);
Expect.equals(0.1, f(0.1));
Expect.equals(
0.1,
f(0.1, (val) {
Expect.isTrue(val is CompoundA);
Expect.isTrue(val.b is CompoundB);
Expect.isTrue(val.b.c is CompoundC);
Expect.equals(val, val.b.c.root);
Expect.equals(0.1, val.b.c.d);
}),
);
}
testCompound3() {
f(d, [sink = const NoopSink()]) {
var c = new CompoundC(d);
c.root = c;
sink(c);
return c.d;
}
Expect.equals(0.1, f(0.1));
for (var i = 0; i < 100; i++) f(0.1);
Expect.equals(0.1, f(0.1));
Expect.equals(
0.1,
f(0.1, (val) {
Expect.isTrue(val is CompoundC);
Expect.equals(val, val.root);
Expect.equals(0.1, val.d);
}),
);
}
testCompound4() {
f(d, [sink = const NoopSink()]) {
var c = new CompoundC(d);
c.root = c;
for (var i = 0; i < 10; i++) {
c.d += 1.0;
}
sink(c);
return c.d - 1.0 * 10;
}
Expect.equals(1.0, f(1.0));
for (var i = 0; i < 100; i++) f(1.0);
Expect.equals(1.0, f(1.0));
Expect.equals(
1.0,
f(1.0, (val) {
Expect.isTrue(val is CompoundC);
Expect.equals(val, val.root);
Expect.equals(11.0, val.d);
}),
);
}
main() {
var c = new C(new Point(0.1, 0.2));
// Compute initial values.
final x0 = test1(c, 11.11, 22.22);
var fc = new Cx4(
new Pointx4(
new Float32x4(1.0, 1.0, 1.0, 1.0),
new Float32x4(1.0, 1.0, 1.0, 1.0),
),
);
final fx0 = test1x4(
fc,
new Float32x4(1.0, 1.0, 1.0, 1.0),
new Float32x4(1.0, 1.0, 1.0, 1.0),
new Float32x4(1.0, 1.0, 1.0, 1.0),
new Float32x4(1.0, 1.0, 1.0, 1.0),
);
final y0 = testForwardingThroughEffects(c, 11.11, 22.22);
final z0 = testIdentity(c.p);
// Force optimization.
for (var i = 0; i < 100; i++) {
test1(c, i.toDouble(), i.toDouble());
test1x4(
fc,
new Float32x4(1.0, 1.0, 1.0, 1.0),
new Float32x4(1.0, 1.0, 1.0, 1.0),
new Float32x4(1.0, 1.0, 1.0, 1.0),
new Float32x4(1.0, 1.0, 1.0, 1.0),
);
testForwardingThroughEffects(c, i.toDouble(), i.toDouble());
testIdentity(c.p);
foo2();
Expect.equals(10, foo3(5));
}
Expect.equals(0.0, foo3(0.5));
// Test returned value after optimization.
final x1 = test1(c, 11.11, 22.22);
final y1 = testForwardingThroughEffects(c, 11.11, 22.22);
// Test returned value after deopt.
final x2 = test1(new D(c.p), 11.11, 22.22);
final y2 = testForwardingThroughEffects(new D(c.p), 11.11, 22.22);
Expect.equals(6465, (x0 * 100).floor());
Expect.equals(6465, (x1 * 100).floor());
Expect.equals(6465, (x2 * 100).floor());
Expect.equals(x0, x1);
Expect.equals(x0, x2);
Expect.equals(6008, (y0 * 100).floor());
Expect.equals(6008, (y1 * 100).floor());
Expect.equals(6008, (y2 * 100).floor());
Expect.equals(y0, y1);
Expect.equals(y0, y2);
// Test that identity of materialized objects is preserved correctly and
// no copies are materialized.
final z1 = testIdentity(c.p);
final z2 = testIdentity(new F(c.p));
Expect.equals(z0, z1);
Expect.equals(z0, z2);
testFinalField();
testVMField();
testCompound1();
testCompound2();
testCompound3();
testCompound4();
}
@@ -0,0 +1,56 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/async_helper.dart";
import "package:expect/expect.dart";
void main() {
x() async {
print("Starting!");
try {
await runAsync();
} catch (e, st) {
print("Got exception and stacktrace:");
var stText = st.toString();
print(e);
print(stText);
// Stacktrace should be something like
// #0 runAsync.<runAsync_async_body> (this file)
// #1 Future.Future.microtask.<anonymous closure> (dart:async/future.dart:184)
// #2 _microtaskLoop (dart:async/schedule_microtask.dart:41)
// #3 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50)
// #4 _runPendingImmediateCallback (dart:isolate-patch/isolate_patch.dart:96)
// #5 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:149)
// if exception and stacktrace is rethrown correctly, NOT
// #0 main.<anonymous closure>.async_op (this file)
// #1 _asyncErrorWrapperHelper.<anonymous closure> (dart:async:134:33)
// #2 _RootZone.runBinary (dart:async/zone.dart:1410:54)
// #3 _FutureListener.handleError (dart:async/future_impl.dart:146:20)
// #4 _Future._propagateToListeners.handleError (dart:async/future_impl.dart:649:47)
// #5 _Future._propagateToListeners (dart:async/future_impl.dart:671:13)
// #6 _Future._completeError (dart:async/future_impl.dart:485:5)
// #7 _SyncCompleter._completeError (dart:async/future_impl.dart:56:12)
// #8 _Completer.completeError (dart:async/future_impl.dart:27:5)
// #9 runAsync.async_op (this file)
// #10 Future.Future.microtask.<anonymous closure> (dart:async/future.dart:184:26)
// #11 _microtaskLoop (dart:async/schedule_microtask.dart:41:5)
// #12 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)
// #13 _runPendingImmediateCallback (dart:isolate:1054:5)
// #14 _RawReceivePortImpl._handleMessage (dart:isolate:1104:5)
Expect.isFalse(stText.contains("propagateToListeners"));
Expect.isFalse(stText.contains("_completeError"));
}
print("Ending!");
}
asyncStart();
x().then((_) => asyncEnd());
}
runAsync() async {
throw 'oh no!';
}
@@ -0,0 +1,48 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that async/await syntax works for synchronously completed futures.
// Such futures are used by Flutter (see http://dartbug.com/32098).
import 'dart:async';
import 'package:expect/async_helper.dart';
import 'package:expect/expect.dart';
class SynchronousFuture<T> implements Future<T> {
final T v;
SynchronousFuture(this.v);
Future<E> then<E>(FutureOr<E> f(T v), {Function? onError}) {
final u = f(v);
return u is Future<dynamic>
? (u as Future<dynamic>).then((v) => v as E)
: new SynchronousFuture<E>(u);
}
Stream<T> asStream() => throw 'unimplemented';
Future<T> catchError(Function onError, {bool test(Object error)?}) =>
throw 'unimplemented';
Future<T> timeout(Duration timeLimit, {dynamic onTimeout()?}) =>
throw 'unimplemented';
Future<T> whenComplete(dynamic action()) => throw 'unimplemented';
}
void main() {
var stage = 0;
asyncTest(() async {
int v;
Expect.equals(0, stage++);
v = await new SynchronousFuture<int>(stage);
Expect.equals(1, v);
Expect.equals(1, stage++);
v = await new SynchronousFuture<int>(stage);
Expect.equals(2, v);
Expect.equals(2, stage++);
v = await new SynchronousFuture<int>(stage);
Expect.equals(3, v);
Expect.equals(3, stage++);
});
}
@@ -0,0 +1,45 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--no_background_compilation --optimization_counter_threshold=10
import "package:expect/expect.dart";
// Tests for long bit-not under 64-bit arithmetic wrap-around semantics.
final int maxInt32 = 2147483647;
final int minInt32 = -2147483648;
final int maxInt64 = 0x7fffffffffffffff;
final int minInt64 = 0x8000000000000000;
int bitnot(int x) {
return ~x;
}
doConstant() {
Expect.equals(0, bitnot(-1));
Expect.equals(-1, bitnot(0));
Expect.equals(-2, bitnot(1));
Expect.equals(minInt32, bitnot(maxInt32));
Expect.equals(maxInt32, bitnot(minInt32));
Expect.equals(minInt64, bitnot(maxInt64));
Expect.equals(maxInt64, bitnot(minInt64)); // sic!
}
doVar() {
int d = 0;
for (int i = -88; i < 10; i++) {
d += bitnot(i);
}
Expect.equals(3773, d);
}
main() {
// Repeat tests to enter JIT (when applicable).
for (int i = 0; i < 20; i++) {
doConstant();
doVar();
}
}
@@ -0,0 +1,113 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Formatting can break multitests, so don't format them.
// dart format off
import "package:expect/expect.dart";
import "package:expect/variations.dart";
class Test1 {
void bar(dynamic condition) {
if (condition) {
Expect.fail('Should not reach here');
}
Expect.fail('Should throw earlier');
}
}
void test1(dynamic condition) {
Test1 obj = new Test1();
obj.bar(condition);
}
class Test2 {
dynamic condition;
Test2(this.condition);
void bar() {
if (!condition) {
Expect.fail('Should not reach here');
}
Expect.fail('Should throw earlier');
}
}
void test2(dynamic condition) {
Test2 obj = new Test2(condition);
obj.bar();
}
class Test3 {
dynamic condition;
Test3(this.condition);
bool bazz() => condition;
void bar() {
while (bazz() || bazz()) {
Expect.fail('Should not reach here');
}
Expect.fail('Should throw earlier');
}
}
void test3(dynamic condition) {
Test3 obj = new Test3(condition);
obj.bar();
}
const dynamic test4Condition = null;
void test4(dynamic condition) {
if (test4Condition) {
Expect.fail('Should not reach here');
}
Expect.fail('Should throw earlier');
}
void test5(dynamic condition) {
if (null as dynamic) {
Expect.fail('Should not reach here');
}
Expect.fail('Should throw earlier');
}
void testStackTrace(void testCase(dynamic condition), List<int> lineNumbers) {
try {
testCase(null);
Expect.fail("Using null in a bool condition should throw TypeError");
} catch (e, stacktrace) {
print('--------- exception ---------');
print(e);
print('-------- stack trace --------');
print(stacktrace);
print('-----------------------------');
if (!unsoundNullSafety) {
Expect.isTrue(e is TypeError);
Expect.equals(
"type 'Null' is not a subtype of type 'bool'", e.toString());
} else {
Expect.isTrue(e is AssertionError);
Expect.equals('Failed assertion: boolean expression must not be null',
e.toString());
}
final String st = stacktrace.toString();
for (int lineNum in lineNumbers) {
String item = '.dart:$lineNum';
Expect.isTrue(st.contains(item), "Stack trace doesn't contain $item");
}
print('OK');
}
}
main() {
testStackTrace(test1, [13, 22]);
testStackTrace(test2, [30, 39]);
testStackTrace(test3, [49, 58]);
testStackTrace(test4, [64]); //# 01: ok
testStackTrace(test5, [71]); //# 02: ok
}
@@ -0,0 +1,40 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization_counter_threshold=10 --no-use-osr --no-background_compilation
import "package:expect/expect.dart";
class X {
operator *(other) => "NaNNaNNaNNaNBatman";
}
foo(x) => (x * 1.0) is double;
bar(x) {
try {
int i = (x * 1);
return true;
} catch (e) {
return false;
}
}
baz(x) => (x * 1) == x;
main() {
for (var i = 0; i < 100; i++) {
Expect.isTrue(foo(1.0));
assert(() {
Expect.isTrue(bar(-1 << 63));
return true;
}());
Expect.isTrue(baz(-1 << 63));
}
Expect.isFalse(foo(new X()));
assert(() {
Expect.isFalse(bar(new X()));
return true;
}());
Expect.isFalse(baz(new X()));
}
@@ -0,0 +1,86 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=
// VMOptions=--use_slow_path
import "package:expect/expect.dart";
@pragma("vm:never-inline")
dynamic hiddenSmi() {
try {
throw 42;
} catch (e) {
return e;
}
return 0;
}
@pragma("vm:never-inline")
dynamic hiddenMint() {
try {
throw 0x8000000000000000;
} catch (e) {
return e;
}
return 0;
}
@pragma("vm:never-inline")
dynamic hiddenDouble() {
try {
throw 3.0;
} catch (e) {
return e;
}
return 0;
}
@pragma("vm:never-inline")
dynamic hiddenCustom() {
try {
throw new Custom();
} catch (e) {
return e;
}
return 0;
}
class Custom {
operator <(other) => "lt";
operator >(other) => "gt";
operator <=(other) => "le";
operator >=(other) => "ge";
operator ==(other) => false;
}
main() {
Expect.equals(false, hiddenSmi() < 2);
Expect.equals(true, hiddenSmi() > 2);
Expect.equals(false, hiddenSmi() <= 2);
Expect.equals(true, hiddenSmi() >= 2);
Expect.equals(false, hiddenSmi() == 2);
Expect.equals(true, hiddenSmi() != 2);
Expect.equals(true, hiddenMint() < 2);
Expect.equals(false, hiddenMint() > 2);
Expect.equals(true, hiddenMint() <= 2);
Expect.equals(false, hiddenMint() >= 2);
Expect.equals(false, hiddenMint() == 2);
Expect.equals(true, hiddenMint() != 2);
Expect.equals(false, hiddenDouble() < 2);
Expect.equals(true, hiddenDouble() > 2);
Expect.equals(false, hiddenDouble() <= 2);
Expect.equals(true, hiddenDouble() >= 2);
Expect.equals(false, hiddenDouble() == 2);
Expect.equals(true, hiddenDouble() != 2);
Expect.equals("lt", hiddenCustom() < 2);
Expect.equals("gt", hiddenCustom() > 2);
Expect.equals("le", hiddenCustom() <= 2);
Expect.equals("ge", hiddenCustom() >= 2);
Expect.equals(false, hiddenCustom() == 2);
Expect.equals(true, hiddenCustom() != 2);
}
@@ -0,0 +1,112 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=
// VMOptions=--use_slow_path
import "package:expect/expect.dart";
@pragma("vm:never-inline")
dynamic hiddenSmi() {
try {
throw 42;
} catch (e) {
return e;
}
return 0;
}
@pragma("vm:never-inline")
dynamic hiddenMint() {
try {
throw 0x8000000000000000;
} catch (e) {
return e;
}
return 0;
}
@pragma("vm:never-inline")
dynamic hiddenDouble() {
try {
throw 3.0;
} catch (e) {
return e;
}
return 0;
}
@pragma("vm:never-inline")
dynamic hiddenCustom() {
try {
throw new Custom();
} catch (e) {
return e;
}
return 0;
}
class Custom {
operator +(other) => "add";
operator -(other) => "sub";
operator *(other) => "mul";
operator ~/(other) => "div";
operator %(other) => "mod";
operator &(other) => "and";
operator |(other) => "or";
operator ^(other) => "xor";
operator <<(other) => "sll";
operator >>(other) => "sra";
operator >>>(other) => "srl";
}
main() {
Expect.equals(44, hiddenSmi() + 2);
Expect.equals(40, hiddenSmi() - 2);
Expect.equals(84, hiddenSmi() * 2);
Expect.equals(21, hiddenSmi() ~/ 2);
Expect.equals(0, hiddenSmi() % 2);
Expect.equals(2, hiddenSmi() & 2);
Expect.equals(42, hiddenSmi() | 2);
Expect.equals(40, hiddenSmi() ^ 2);
Expect.equals(168, hiddenSmi() << 2);
Expect.equals(10, hiddenSmi() >> 2);
Expect.equals(10, hiddenSmi() >>> 2);
Expect.equals(-9223372036854775806, hiddenMint() + 2);
Expect.equals(9223372036854775806, hiddenMint() - 2);
Expect.equals(0, hiddenMint() * 2);
Expect.equals(-4611686018427387904, hiddenMint() ~/ 2);
Expect.equals(0, hiddenMint() % 2);
Expect.equals(0, hiddenMint() & 2);
Expect.equals(-9223372036854775806, hiddenMint() | 2);
Expect.equals(-9223372036854775806, hiddenMint() ^ 2);
Expect.equals(0, hiddenMint() << 2);
Expect.equals(-2305843009213693952, hiddenMint() >> 2);
Expect.equals(2305843009213693952, hiddenMint() >>> 2);
Expect.equals(5.0, hiddenDouble() + 2);
Expect.equals(1.0, hiddenDouble() - 2);
Expect.equals(6.0, hiddenDouble() * 2);
Expect.equals(1, hiddenDouble() ~/ 2);
Expect.equals(1.0, hiddenDouble() % 2);
Expect.throws(() => hiddenDouble() & 2, (e) => e is NoSuchMethodError);
Expect.throws(() => hiddenDouble() | 2, (e) => e is NoSuchMethodError);
Expect.throws(() => hiddenDouble() ^ 2, (e) => e is NoSuchMethodError);
Expect.throws(() => hiddenDouble() << 2, (e) => e is NoSuchMethodError);
Expect.throws(() => hiddenDouble() >> 2, (e) => e is NoSuchMethodError);
Expect.throws(() => hiddenDouble() >>> 2, (e) => e is NoSuchMethodError);
Expect.equals("add", hiddenCustom() + 2);
Expect.equals("sub", hiddenCustom() - 2);
Expect.equals("mul", hiddenCustom() * 2);
Expect.equals("div", hiddenCustom() ~/ 2);
Expect.equals("mod", hiddenCustom() % 2);
Expect.equals("and", hiddenCustom() & 2);
Expect.equals("or", hiddenCustom() | 2);
Expect.equals("xor", hiddenCustom() ^ 2);
Expect.equals("sll", hiddenCustom() << 2);
Expect.equals("sra", hiddenCustom() >> 2);
Expect.equals("srl", hiddenCustom() >>> 2);
}
+99
View File
@@ -0,0 +1,99 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--deterministic
import "package:expect/expect.dart";
import 'dart:typed_data';
// Found by "value-guided" DartFuzzing: incorrect clamping.
// https://github.com/dart-lang/sdk/issues/37868
@pragma("vm:never-inline")
foo(List<int> x) => Uint8ClampedList.fromList(x);
@pragma("vm:never-inline")
bar(List<int> x) => Uint8List.fromList(x);
@pragma("vm:never-inline")
baz(List<int> x) => Int8List.fromList(x);
main() {
// Proper values.
final List<int> x = [
9223372036854775807,
-9223372036854775808,
9223372032559808513,
-9223372032559808513,
5000000000,
-5000000000,
2147483647,
-2147483648,
255,
-255,
11,
-11,
0,
-1,
];
Expect.listEquals([
255,
0,
255,
0,
255,
0,
255,
0,
255,
0,
11,
0,
0,
0,
], foo(x));
Expect.listEquals([
255,
0,
1,
255,
0,
0,
255,
0,
255,
1,
11,
245,
0,
255,
], bar(x));
Expect.listEquals([-1, 0, 1, -1, 0, 0, -1, 0, -1, 1, 11, -11, 0, -1], baz(x));
// Hidden null.
final List<int> a = [1, null, 2].cast<int>();
int num_exceptions = 0;
try {
foo(a);
} catch (e) {
// In strong mode, .cast() throws a TypeError when casting to int. In weak
// mode, that cast succeeds and then NoSuchMethod is thrown later when the
// null is used.
Expect.isTrue(e is TypeError || e is NoSuchMethodError);
num_exceptions++;
}
try {
bar(a);
} catch (e) {
Expect.isTrue(e is TypeError || e is NoSuchMethodError);
num_exceptions++;
}
try {
baz(a);
} catch (e) {
Expect.isTrue(e is TypeError || e is NoSuchMethodError);
num_exceptions++;
}
Expect.equals(3, num_exceptions);
}
@@ -0,0 +1,28 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--old_gen_heap_size=50
// Test that non-capturing closures don't retain unnecessary memory.
// It tests that the context of `f` allocated within `bar` not leaking and does
// not become the context of empty non-capturing closure allocated inside `foo`.
// If failing it crashes with an OOM error.
import "package:expect/expect.dart";
foo() {
return () {};
}
bar(a, b) {
f() => [a, b];
return foo();
}
main() {
var closure = null;
for (var i = 0; i < 100; i++) {
closure = bar(closure, new List<dynamic>.filled(1024 * 1024, null));
}
Expect.isTrue(closure is Function);
}
@@ -0,0 +1,22 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization-counter-threshold=10 --no-use-osr --no-background-compilation
foo(n) {
return new List<dynamic>.filled(n, null);
}
@pragma('vm:never-inline')
bar(n) {
try {
return foo(n);
} catch (e) {}
}
main() {
for (var i = 0; i < 20; i++) {
bar(5);
}
bar("");
}
@@ -0,0 +1,18 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization-counter-threshold=10 --no-use-osr --no-background-compilation
@pragma('vm:never-inline')
foo(n) {
try {
return new List<dynamic>.filled(n, null);
} catch (e) {}
}
main() {
for (var i = 0; i < 20; i++) {
foo(5);
}
foo("");
}
@@ -0,0 +1,245 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Don't try to fit in 80 columns with this much nesting.
// dart format width=300
import 'package:expect/expect.dart';
// Stress tests on loop nesting depth. Make sure loop and induction
// analysis do not break down (excessive compile-time or otherwise)
// when analyzing a deeply nested loop with dependent bounds.
@pragma("vm:never-inline")
foo(List<int?> a) {
for (int i0 = 100; i0 <= a.length - 101; i0++)
for (int i1 = i0 - 1; i1 <= i0 + 1; i1++)
for (int i2 = i1 - 1; i2 <= i1 + 1; i2++)
for (int i3 = i2 - 1; i3 <= i2 + 1; i3++)
for (int i4 = i3 - 1; i4 <= i3 + 1; i4++)
for (int i5 = i4 - 1; i5 <= i4 + 1; i5++)
for (int i6 = i5 - 1; i6 <= i5 + 1; i6++)
for (int i7 = i6 - 1; i7 <= i6 + 1; i7++)
for (int i8 = i7 - 1; i8 <= i7 + 1; i8++)
for (int i9 = i8 - 1; i9 <= i8 + 1; i9++)
for (int i10 = i9 - 1; i10 <= i9 + 1; i10++)
for (int i11 = i10 - 1; i11 <= i10 + 1; i11++)
for (int i12 = i11 - 1; i12 <= i11 + 1; i12++)
for (int i13 = i12 - 1; i13 <= i12 + 1; i13++)
for (int i14 = i13 - 1; i14 <= i13 + 1; i14++)
for (int i15 = i14 - 1; i15 <= i14 + 1; i15++)
for (int i16 = i15 - 1; i16 <= i15 + 1; i16++)
for (int i17 = i16 - 1; i17 <= i16 + 1; i17++)
for (int i18 = i17 - 1; i18 <= i17 + 1; i18++)
for (int i19 = i18 - 1; i19 <= i18 + 1; i19++)
for (int i20 = i19 - 1; i20 <= i19 + 1; i20++)
for (int i21 = i20 - 1; i21 <= i20 + 1; i21++)
for (int i22 = i21 - 1; i22 <= i21 + 1; i22++)
for (int i23 = i22 - 1; i23 <= i22 + 1; i23++)
for (int i24 = i23 - 1; i24 <= i23 + 1; i24++)
for (int i25 = i24 - 1; i25 <= i24 + 1; i25++)
for (int i26 = i25 - 1; i26 <= i25 + 1; i26++)
for (int i27 = i26 - 1; i27 <= i26 + 1; i27++)
for (int i28 = i27 - 1; i28 <= i27 + 1; i28++)
for (int i29 = i28 - 1; i29 <= i28 + 1; i29++)
for (int i30 = i29 - 1; i30 <= i29 + 1; i30++)
for (int i31 = i30 - 1; i31 <= i30 + 1; i31++)
for (int i32 = i31 - 1; i32 <= i31 + 1; i32++)
for (int i33 = i32 - 1; i33 <= i32 + 1; i33++)
for (int i34 = i33 - 1; i34 <= i33 + 1; i34++)
for (int i35 = i34 - 1; i35 <= i34 + 1; i35++)
for (int i36 = i35 - 1; i36 <= i35 + 1; i36++)
for (int i37 = i36 - 1; i37 <= i36 + 1; i37++)
for (int i38 = i37 - 1; i38 <= i37 + 1; i38++)
for (int i39 = i38 - 1; i39 <= i38 + 1; i39++)
for (int i40 = i39 - 1; i40 <= i39 + 1; i40++)
for (int i41 = i40 - 1; i41 <= i40 + 1; i41++)
for (int i42 = i41 - 1; i42 <= i41 + 1; i42++)
for (int i43 = i42 - 1; i43 <= i42 + 1; i43++)
for (int i44 = i43 - 1; i44 <= i43 + 1; i44++)
for (int i45 = i44 - 1; i45 <= i44 + 1; i45++)
for (int i46 = i45 - 1; i46 <= i45 + 1; i46++)
for (int i47 = i46 - 1; i47 <= i46 + 1; i47++)
for (int i48 = i47 - 1; i48 <= i47 + 1; i48++)
for (int i49 = i48 - 1; i49 <= i48 + 1; i49++)
for (int i50 = i49 - 1; i50 <= i49 + 1; i50++)
for (int i51 = i50 - 1; i51 <= i50 + 1; i51++)
for (int i52 = i51 - 1; i52 <= i51 + 1; i52++)
for (int i53 = i52 - 1; i53 <= i52 + 1; i53++)
for (int i54 = i53 - 1; i54 <= i53 + 1; i54++)
for (int i55 = i54 - 1; i55 <= i54 + 1; i55++)
for (int i56 = i55 - 1; i56 <= i55 + 1; i56++)
for (int i57 = i56 - 1; i57 <= i56 + 1; i57++)
for (int i58 = i57 - 1; i58 <= i57 + 1; i58++)
for (int i59 = i58 - 1; i59 <= i58 + 1; i59++)
for (int i60 = i59 - 1; i60 <= i59 + 1; i60++)
for (int i61 = i60 - 1; i61 <= i60 + 1; i61++)
for (int i62 = i61 - 1; i62 <= i61 + 1; i62++)
for (int i63 = i62 - 1; i63 <= i62 + 1; i63++)
for (int i64 = i63 - 1; i64 <= i63 + 1; i64++)
for (int i65 = i64 - 1; i65 <= i64 + 1; i65++)
for (int i66 = i65 - 1; i66 <= i65 + 1; i66++)
for (int i67 = i66 - 1; i67 <= i66 + 1; i67++)
for (int i68 = i67 - 1; i68 <= i67 + 1; i68++)
for (int i69 = i68 - 1; i69 <= i68 + 1; i69++)
for (int i70 = i69 - 1; i70 <= i69 + 1; i70++)
for (int i71 = i70 - 1; i71 <= i70 + 1; i71++)
for (int i72 = i71 - 1; i72 <= i71 + 1; i72++)
for (int i73 = i72 - 1; i73 <= i72 + 1; i73++)
for (int i74 = i73 - 1; i74 <= i73 + 1; i74++)
for (int i75 = i74 - 1; i75 <= i74 + 1; i75++)
for (int i76 = i75 - 1; i76 <= i75 + 1; i76++)
for (int i77 = i76 - 1; i77 <= i76 + 1; i77++)
for (int i78 = i77 - 1; i78 <= i77 + 1; i78++)
for (int i79 = i78 - 1; i79 <= i78 + 1; i79++)
for (int i80 = i79 - 1; i80 <= i79 + 1; i80++)
for (int i81 = i80 - 1; i81 <= i80 + 1; i81++)
for (int i82 = i81 - 1; i82 <= i81 + 1; i82++)
for (int i83 = i82 - 1; i83 <= i82 + 1; i83++)
for (int i84 = i83 - 1; i84 <= i83 + 1; i84++)
for (int i85 = i84 - 1; i85 <= i84 + 1; i85++)
for (int i86 = i85 - 1; i86 <= i85 + 1; i86++)
for (int i87 = i86 - 1; i87 <= i86 + 1; i87++)
for (int i88 = i87 - 1; i88 <= i87 + 1; i88++)
for (int i89 = i88 - 1; i89 <= i88 + 1; i89++)
for (int i90 = i89 - 1; i90 <= i89 + 1; i90++)
for (int i91 = i90 - 1; i91 <= i90 + 1; i91++)
for (int i92 = i91 - 1; i92 <= i91 + 1; i92++)
for (int i93 = i92 - 1; i93 <= i92 + 1; i93++)
for (int i94 = i93 - 1; i94 <= i93 + 1; i94++)
for (int i95 = i94 - 1; i95 <= i94 + 1; i95++)
for (int i96 = i95 - 1; i96 <= i95 + 1; i96++)
for (int i97 = i96 - 1; i97 <= i96 + 1; i97++)
for (int i98 = i97 - 1; i98 <= i97 + 1; i98++)
for (int i99 = i98 - 1; i99 <= i98 + 1; i99++)
for (int i100 = i99 - 1; i100 <= i99 + 1; i100++) {
// Range [0,a.length).
a[i100] = a[i100]! + 1;
}
}
@pragma("vm:never-inline")
bar(List<int?> a) {
for (int i0 = a.length - 101; i0 >= 100; i0--)
for (int i1 = i0 + 1; i1 >= i0 - 1; i1--)
for (int i2 = i1 + 1; i2 >= i1 - 1; i2--)
for (int i3 = i2 + 1; i3 >= i2 - 1; i3--)
for (int i4 = i3 + 1; i4 >= i3 - 1; i4--)
for (int i5 = i4 + 1; i5 >= i4 - 1; i5--)
for (int i6 = i5 + 1; i6 >= i5 - 1; i6--)
for (int i7 = i6 + 1; i7 >= i6 - 1; i7--)
for (int i8 = i7 + 1; i8 >= i7 - 1; i8--)
for (int i9 = i8 + 1; i9 >= i8 - 1; i9--)
for (int i10 = i9 + 1; i10 >= i9 - 1; i10--)
for (int i11 = i10 + 1; i11 >= i10 - 1; i11--)
for (int i12 = i11 + 1; i12 >= i11 - 1; i12--)
for (int i13 = i12 + 1; i13 >= i12 - 1; i13--)
for (int i14 = i13 + 1; i14 >= i13 - 1; i14--)
for (int i15 = i14 + 1; i15 >= i14 - 1; i15--)
for (int i16 = i15 + 1; i16 >= i15 - 1; i16--)
for (int i17 = i16 + 1; i17 >= i16 - 1; i17--)
for (int i18 = i17 + 1; i18 >= i17 - 1; i18--)
for (int i19 = i18 + 1; i19 >= i18 - 1; i19--)
for (int i20 = i19 + 1; i20 >= i19 - 1; i20--)
for (int i21 = i20 + 1; i21 >= i20 - 1; i21--)
for (int i22 = i21 + 1; i22 >= i21 - 1; i22--)
for (int i23 = i22 + 1; i23 >= i22 - 1; i23--)
for (int i24 = i23 + 1; i24 >= i23 - 1; i24--)
for (int i25 = i24 + 1; i25 >= i24 - 1; i25--)
for (int i26 = i25 + 1; i26 >= i25 - 1; i26--)
for (int i27 = i26 + 1; i27 >= i26 - 1; i27--)
for (int i28 = i27 + 1; i28 >= i27 - 1; i28--)
for (int i29 = i28 + 1; i29 >= i28 - 1; i29--)
for (int i30 = i29 + 1; i30 >= i29 - 1; i30--)
for (int i31 = i30 + 1; i31 >= i30 - 1; i31--)
for (int i32 = i31 + 1; i32 >= i31 - 1; i32--)
for (int i33 = i32 + 1; i33 >= i32 - 1; i33--)
for (int i34 = i33 + 1; i34 >= i33 - 1; i34--)
for (int i35 = i34 + 1; i35 >= i34 - 1; i35--)
for (int i36 = i35 + 1; i36 >= i35 - 1; i36--)
for (int i37 = i36 + 1; i37 >= i36 - 1; i37--)
for (int i38 = i37 + 1; i38 >= i37 - 1; i38--)
for (int i39 = i38 + 1; i39 >= i38 - 1; i39--)
for (int i40 = i39 + 1; i40 >= i39 - 1; i40--)
for (int i41 = i40 + 1; i41 >= i40 - 1; i41--)
for (int i42 = i41 + 1; i42 >= i41 - 1; i42--)
for (int i43 = i42 + 1; i43 >= i42 - 1; i43--)
for (int i44 = i43 + 1; i44 >= i43 - 1; i44--)
for (int i45 = i44 + 1; i45 >= i44 - 1; i45--)
for (int i46 = i45 + 1; i46 >= i45 - 1; i46--)
for (int i47 = i46 + 1; i47 >= i46 - 1; i47--)
for (int i48 = i47 + 1; i48 >= i47 - 1; i48--)
for (int i49 = i48 + 1; i49 >= i48 - 1; i49--)
for (int i50 = i49 + 1; i50 >= i49 - 1; i50--)
for (int i51 = i50 + 1; i51 >= i50 - 1; i51--)
for (int i52 = i51 + 1; i52 >= i51 - 1; i52--)
for (int i53 = i52 + 1; i53 >= i52 - 1; i53--)
for (int i54 = i53 + 1; i54 >= i53 - 1; i54--)
for (int i55 = i54 + 1; i55 >= i54 - 1; i55--)
for (int i56 = i55 + 1; i56 >= i55 - 1; i56--)
for (int i57 = i56 + 1; i57 >= i56 - 1; i57--)
for (int i58 = i57 + 1; i58 >= i57 - 1; i58--)
for (int i59 = i58 + 1; i59 >= i58 - 1; i59--)
for (int i60 = i59 + 1; i60 >= i59 - 1; i60--)
for (int i61 = i60 + 1; i61 >= i60 - 1; i61--)
for (int i62 = i61 + 1; i62 >= i61 - 1; i62--)
for (int i63 = i62 + 1; i63 >= i62 - 1; i63--)
for (int i64 = i63 + 1; i64 >= i63 - 1; i64--)
for (int i65 = i64 + 1; i65 >= i64 - 1; i65--)
for (int i66 = i65 + 1; i66 >= i65 - 1; i66--)
for (int i67 = i66 + 1; i67 >= i66 - 1; i67--)
for (int i68 = i67 + 1; i68 >= i67 - 1; i68--)
for (int i69 = i68 + 1; i69 >= i68 - 1; i69--)
for (int i70 = i69 + 1; i70 >= i69 - 1; i70--)
for (int i71 = i70 + 1; i71 >= i70 - 1; i71--)
for (int i72 = i71 + 1; i72 >= i71 - 1; i72--)
for (int i73 = i72 + 1; i73 >= i72 - 1; i73--)
for (int i74 = i73 + 1; i74 >= i73 - 1; i74--)
for (int i75 = i74 + 1; i75 >= i74 - 1; i75--)
for (int i76 = i75 + 1; i76 >= i75 - 1; i76--)
for (int i77 = i76 + 1; i77 >= i76 - 1; i77--)
for (int i78 = i77 + 1; i78 >= i77 - 1; i78--)
for (int i79 = i78 + 1; i79 >= i78 - 1; i79--)
for (int i80 = i79 + 1; i80 >= i79 - 1; i80--)
for (int i81 = i80 + 1; i81 >= i80 - 1; i81--)
for (int i82 = i81 + 1; i82 >= i81 - 1; i82--)
for (int i83 = i82 + 1; i83 >= i82 - 1; i83--)
for (int i84 = i83 + 1; i84 >= i83 - 1; i84--)
for (int i85 = i84 + 1; i85 >= i84 - 1; i85--)
for (int i86 = i85 + 1; i86 >= i85 - 1; i86--)
for (int i87 = i86 + 1; i87 >= i86 - 1; i87--)
for (int i88 = i87 + 1; i88 >= i87 - 1; i88--)
for (int i89 = i88 + 1; i89 >= i88 - 1; i89--)
for (int i90 = i89 + 1; i90 >= i89 - 1; i90--)
for (int i91 = i90 + 1; i91 >= i90 - 1; i91--)
for (int i92 = i91 + 1; i92 >= i91 - 1; i92--)
for (int i93 = i92 + 1; i93 >= i92 - 1; i93--)
for (int i94 = i93 + 1; i94 >= i93 - 1; i94--)
for (int i95 = i94 + 1; i95 >= i94 - 1; i95--)
for (int i96 = i95 + 1; i96 >= i95 - 1; i96--)
for (int i97 = i96 + 1; i97 >= i96 - 1; i97--)
for (int i98 = i97 + 1; i98 >= i97 - 1; i98--)
for (int i99 = i98 + 1; i99 >= i98 - 1; i99--)
for (int i100 = i99 + 1; i100 >= i99 - 1; i100--) {
// Range [0,a.length).
a[i100] = a[i100]! + 1;
}
}
main() {
// To avoid executing the deep loops completely, we pass in a list
// with null values, so that each first iteration throws an exception.
List<int?> a = new List<int?>.filled(300, null);
int tryCallingPlusOnNull = 0;
try {
foo(a);
} on TypeError catch (e) {
++tryCallingPlusOnNull;
}
try {
bar(a);
} on TypeError catch (e) {
++tryCallingPlusOnNull;
}
Expect.equals(2, tryCallingPlusOnNull);
}
@@ -0,0 +1,42 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that we don't hit unbalanced stack after deoptimization from LoadField
// back to getter call.
// VMOptions=--no-use-osr --optimization-counter-threshold=10 --no-background-compilation
int counter = 0;
class A {
late final Object field = init();
@pragma('vm:never-inline')
int init() {
counter++;
if (counter > 20) {
finalizeB();
}
return counter;
}
}
class B extends A {
final Object field = "Foo";
}
@pragma('vm:never-inline')
finalizeB() {
print(new B().field);
}
@pragma('vm:never-inline')
test(A a) {
print(a.field);
}
main() {
for (var i = 0; i < 100; i++) {
test(new A());
}
}
@@ -0,0 +1,35 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test deoptimization on an optimistically hoisted smi check.
// VMOptions=--optimization-counter-threshold=10 --no-background-compilation
import 'package:expect/expect.dart';
sum(a, b) {
var sum = 0;
for (var j = 1; j < 10; j++) {
for (var i = a; i < b; i++) {
sum++;
}
}
return sum;
}
mask(x) {
for (var i = 0; i < 10; i++) {
if (i == 1) {
return x;
}
x = x & 0xFF;
}
}
main() {
for (var i = 0; i < 20; i++) {
Expect.equals(9, sum(1, 2));
Expect.equals(0xAB, mask(0xAB));
}
Expect.equals(9, sum(1.0, 2.0)); // Passing double causes deoptimization.
Expect.equals(0xAB, mask(0x1000000AB));
}
@@ -0,0 +1,20 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test deoptimization on a smi check.
// VMOptions=--optimization-counter-threshold=10 --no-background-compilation
import 'package:expect/expect.dart';
hc(a) {
var r = a.hashCode;
return r;
}
main() {
for (var i = 0; i < 20; i++) {
Expect.equals((1).hashCode, hc(1));
}
// Passing double causes deoptimization.
Expect.equals((1.0).hashCode, hc(1.0));
}
+303
View File
@@ -0,0 +1,303 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--deterministic
// VMOptions=--deterministic --use_slow_path
// Unit tests on DIV and MOV operations by various constants.
import "package:expect/expect.dart";
import 'dart:core';
int kMin = 0x8000000000000000;
int kMax = 0x7fffffffffffffff;
// The basic DIV operation.
int divme(int? x, int c) {
return x! ~/ c;
}
// The basic MOD operation.
int modme(int? x, int c) {
return x! % c;
}
//
// Test several "hidden" DIV constants.
//
@pragma("vm:never-inline")
int div0(int x) {
return divme(x, 0);
}
@pragma("vm:never-inline")
int div1(int x) {
return divme(x, 1);
}
@pragma("vm:never-inline")
int divm1(int x) {
return divme(x, -1);
}
@pragma("vm:never-inline")
int div2(int? x) {
return divme(x, 2);
}
@pragma("vm:never-inline")
int divm2(int x) {
return divme(x, -2);
}
@pragma("vm:never-inline")
int div37(int x) {
return divme(x, 37);
}
@pragma("vm:never-inline")
int div131(int x) {
return divme(x, 131);
}
@pragma("vm:never-inline")
int divm333(int x) {
return divme(x, -333);
}
@pragma("vm:never-inline")
int divmin(int x) {
return divme(x, kMin);
}
@pragma("vm:never-inline")
int divmax(int x) {
return divme(x, kMax);
}
//
// Test several "hidden" MOD constants.
//
@pragma("vm:never-inline")
int mod0(int x) {
return modme(x, 0);
}
@pragma("vm:never-inline")
int mod1(int x) {
return modme(x, 1);
}
@pragma("vm:never-inline")
int modm1(int x) {
return modme(x, -1);
}
@pragma("vm:never-inline")
int mod2(int? x) {
return modme(x, 2);
}
@pragma("vm:never-inline")
int modm2(int x) {
return modme(x, -2);
}
@pragma("vm:never-inline")
int mod37(int x) {
return modme(x, 37);
}
@pragma("vm:never-inline")
int mod131(int x) {
return modme(x, 131);
}
@pragma("vm:never-inline")
int modm333(int x) {
return modme(x, -333);
}
@pragma("vm:never-inline")
int modmin(int x) {
return modme(x, kMin);
}
@pragma("vm:never-inline")
int modmax(int x) {
return modme(x, kMax);
}
main() {
// Exceptional case DIV.
for (int i = -1; i <= 1; i++) {
bool threw = false;
try {
div0(i);
} on UnsupportedError catch (e) {
threw = true;
}
Expect.isTrue(threw);
}
// Exceptional case MOD.
for (int i = -1; i <= 1; i++) {
bool threw = false;
try {
mod0(i);
} on UnsupportedError catch (e) {
threw = true;
}
Expect.isTrue(threw);
}
// DIV by +/- 1.
Expect.equals(kMin, div1(kMin));
Expect.equals(kMin, divm1(kMin));
for (int i = -999; i <= 999; i++) {
Expect.equals(i, div1(i));
Expect.equals(-i, divm1(i));
}
Expect.equals(kMax, div1(kMax));
Expect.equals(-kMax, divm1(kMax));
// MOD by +/- 1.
Expect.equals(0, mod1(kMin));
Expect.equals(0, modm1(kMin));
for (int i = -999; i <= 999; i++) {
Expect.equals(0, mod1(i));
Expect.equals(0, modm1(i));
}
Expect.equals(0, mod1(kMax));
Expect.equals(0, modm1(kMax));
// DIV by +/- 2.
Expect.equals(-4611686018427387904, div2(kMin));
Expect.equals(-4611686018427387903, div2(kMin + 1));
Expect.equals(-4611686018427387903, div2(kMin + 2));
Expect.equals(4611686018427387904, divm2(kMin));
Expect.equals(4611686018427387903, divm2(kMin + 1));
Expect.equals(4611686018427387903, divm2(kMin + 2));
for (int i = -999; i <= 999; i++) {
int e = (i + ((i < 0) ? 1 : 0)) >> 1;
Expect.equals(e, div2(i));
Expect.equals(-e, divm2(i));
}
Expect.equals(4611686018427387903, div2(kMax));
Expect.equals(4611686018427387903, div2(kMax - 1));
Expect.equals(4611686018427387902, div2(kMax - 2));
Expect.equals(-4611686018427387903, divm2(kMax));
Expect.equals(-4611686018427387903, divm2(kMax - 1));
Expect.equals(-4611686018427387902, divm2(kMax - 2));
// MOD by +/- 2.
Expect.equals(0, mod2(kMin));
Expect.equals(1, mod2(kMin + 1));
Expect.equals(0, mod2(kMin + 2));
Expect.equals(0, modm2(kMin));
Expect.equals(1, modm2(kMin + 1));
Expect.equals(0, modm2(kMin + 2));
for (int i = -999; i <= 999; i++) {
Expect.equals(i & 1, mod2(i));
Expect.equals(i & 1, modm2(i));
}
Expect.equals(1, mod2(kMax));
Expect.equals(0, mod2(kMax - 1));
Expect.equals(1, mod2(kMax - 2));
Expect.equals(1, modm2(kMax));
Expect.equals(0, modm2(kMax - 1));
Expect.equals(1, modm2(kMax - 2));
// DIV/MOD by 37.
Expect.equals(-249280325320399346, div37(kMin));
Expect.equals(31, mod37(kMin));
for (int i = -999; i <= 999; i++) {
Expect.equals(i, div37(37 * i));
Expect.equals(i, div37(37 * i + ((i >= 0) ? 36 : -36)));
Expect.equals(0, mod37(37 * i));
Expect.equals(1, mod37(37 * i + 1));
Expect.equals(36, mod37(37 * i + 36));
}
for (int i = 1; i < 37; i++) {
Expect.equals(0, div37(i));
Expect.equals(i, mod37(i));
Expect.equals(0, div37(-i));
Expect.equals(37 - i, mod37(-i));
}
Expect.equals(249280325320399346, div37(kMax));
Expect.equals(5, mod37(kMax));
// DIV/MOD by 131.
Expect.equals(-70407420128662410, div131(kMin));
Expect.equals(33, mod131(kMin));
for (int i = -999; i <= 999; i++) {
Expect.equals(i, div131(131 * i));
Expect.equals(i, div131(131 * i + ((i >= 0) ? 130 : -130)));
Expect.equals(0, mod131(131 * i));
Expect.equals(1, mod131(131 * i + 1));
Expect.equals(130, mod131(131 * i + 130));
}
for (int i = 1; i < 131; i++) {
Expect.equals(0, div131(i));
Expect.equals(i, mod131(i));
Expect.equals(0, div131(-i));
Expect.equals(131 - i, mod131(-i));
}
Expect.equals(70407420128662410, div131(kMax));
Expect.equals(97, mod131(kMax));
// DIV/MOD by -333.
Expect.equals(27697813924488816, divm333(kMin));
Expect.equals(253, modm333(kMin));
for (int i = -999; i <= 999; i++) {
Expect.equals(i, divm333(-333 * i));
Expect.equals(i, divm333(-333 * i + ((i < 0) ? 130 : -130)));
Expect.equals(0, modm333(-333 * i));
Expect.equals(1, modm333(-333 * i + 1));
Expect.equals(130, modm333(-333 * i + 130));
}
Expect.equals(-27697813924488816, divm333(kMax));
Expect.equals(79, modm333(kMax));
// DIV/MOD by Min.
Expect.equals(1, divmin(kMin));
Expect.equals(0, modmin(kMin));
for (int i = -999; i <= 999; i++) {
Expect.equals(0, divmin(i));
Expect.equals(i >= 0 ? i : 1 + kMax + i, modmin(i));
}
Expect.equals(0, divmin(kMax));
Expect.equals(kMax, modmin(kMax));
// DIV/MOD by Max.
Expect.equals(-1, divmax(kMin));
Expect.equals(kMax - 1, modmax(kMin));
for (int i = -999; i <= 999; i++) {
Expect.equals(0, divmax(i));
Expect.equals(i >= 0 ? i : kMax + i, modmax(i));
}
Expect.equals(1, divmax(kMax));
Expect.equals(0, modmax(kMax));
// Exceptional null value MOD.
bool threwDiv = false;
try {
div2(null);
} on TypeError catch (e) {
threwDiv = true;
}
Expect.isTrue(threwDiv);
// Exceptional null value MOD.
bool threwMod = false;
try {
mod2(null);
} on TypeError catch (e) {
threwMod = true;
}
Expect.isTrue(threwMod);
}
@@ -0,0 +1,14 @@
import 'dart:async';
class A {
FutureOr<int?> x;
}
Future<int> foo() async => 42;
main() {
var a = new A();
a.x = 33;
a.x = null;
a.x = foo();
}
@@ -0,0 +1,18 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test function equality with null.
import "package:expect/expect.dart";
class A {
foo() {}
}
main() {
var a = new A();
var f = a.foo;
Expect.isFalse(f == null);
Expect.isFalse(null == f);
}
@@ -0,0 +1,27 @@
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--deterministic
// The Dart Project Fuzz Tester (1.93).
// Program generated as:
// dart dartfuzz.dart --seed 316265767 --no-fp --no-ffi --flat
import 'dart:typed_data';
Int16List? foo0_0(int par4) {
if (par4 >= 36) {
return Int16List(40);
}
for (int loc0 = 0; loc0 < 31; loc0++) {
for (int loc1 in ((Uint8ClampedList.fromList(
Uint8List(26),
)).sublist((11 >>> loc0), null))) {}
}
return foo0_0(par4 + 1);
}
main() {
foo0_0(0);
}
@@ -0,0 +1,152 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test if-conversion pass in the optimizing compiler.
// VMOptions=--optimization-counter-threshold=10 --no-use-osr --no-background-compilation
import "package:expect/expect.dart";
f1(i) => (i == 0) ? 0 : 1;
f2(i) => (i == 0) ? 2 : 3;
f3(i) => (i == null) ? 0 : 1;
f4(i) => (i == null) ? 2 : 3;
f5(i) => (i != 0) ? 0 : 1;
f6(i) => (i != 0) ? 2 : 3;
f7(i) => (i != null) ? 0 : 1;
f8(i) => (i != null) ? 2 : 3;
f9(i) => identical(i, 0) ? 0 : 1;
f10(i) => identical(i, 0) ? 2 : 3;
f11(i) => identical(i, null) ? 0 : 1;
f12(i) => identical(i, null) ? 2 : 3;
f13(i) => !identical(i, 0) ? 0 : 1;
f14(i) => !identical(i, 0) ? 2 : 3;
f15(i) => !identical(i, null) ? 0 : 1;
f16(i) => !identical(i, null) ? 2 : 3;
const POWER_OF_2 = 0x1000000000;
bigPower(i) => (i == 11) ? 0 : POWER_OF_2;
cse(i) {
final a = i == 0 ? 0 : 1;
final b = i == 0 ? 2 : 3;
return a + b;
}
f17(b) => b ? 0 : 11;
f18(b) => b ? 2 : 0;
f19(i) => i == 0 ? 0 : 0;
f20(i) => i > 0 ? 0 : 1;
f21(i) => i > 0 ? 2 : 3;
f22(i) => i & 1 == 0 ? 0 : 1;
f23(i) => i & 1 != 0 ? 1 : 0;
f24(i) => i >= 0 ? 0 : 1;
f25(i) => i < 0 ? 0 : 1;
f26(i) => i <= 0 ? 0 : 1;
main() {
for (var i = 0; i < 20; i++) {
f1(i);
f2(i);
f3(i);
f4(i);
f5(i);
f6(i);
f7(i);
f8(i);
f9(i);
f10(i);
f11(i);
f12(i);
f13(i);
f14(i);
f15(i);
f16(i);
cse(i);
bigPower(i);
f17(true);
f18(true);
f19(i);
f20(i);
f21(i);
f22(i);
f23(i);
f24(i);
f25(i);
f26(i);
}
Expect.equals(0, f1(0));
Expect.equals(1, f1(44));
Expect.equals(2, f2(0));
Expect.equals(3, f2(44));
Expect.equals(0, f3(null));
Expect.equals(1, f3(44));
Expect.equals(2, f4(null));
Expect.equals(3, f4(44));
Expect.equals(1, f5(0));
Expect.equals(0, f5(44));
Expect.equals(3, f6(0));
Expect.equals(2, f6(44));
Expect.equals(1, f7(null));
Expect.equals(0, f7(44));
Expect.equals(3, f8(null));
Expect.equals(2, f8(44));
Expect.equals(0, f9(0));
Expect.equals(1, f9(44));
Expect.equals(2, f10(0));
Expect.equals(3, f10(44));
Expect.equals(0, f11(null));
Expect.equals(1, f11(44));
Expect.equals(2, f12(null));
Expect.equals(3, f12(44));
Expect.equals(1, f13(0));
Expect.equals(0, f13(44));
Expect.equals(3, f14(0));
Expect.equals(2, f14(44));
Expect.equals(1, f15(null));
Expect.equals(0, f15(44));
Expect.equals(3, f16(null));
Expect.equals(2, f16(44));
Expect.equals(0, bigPower(11));
Expect.equals(POWER_OF_2, bigPower(12));
Expect.equals(2, cse(0));
Expect.equals(4, cse(1));
Expect.equals(11, f17(false));
Expect.equals(0, f17(true));
Expect.equals(0, f18(false));
Expect.equals(2, f18(true));
Expect.equals(0, f19(0));
Expect.equals(0, f19(1));
Expect.equals(0, f20(123));
Expect.equals(2, f21(123));
Expect.equals(0, f22(122));
Expect.equals(1, f22(123));
Expect.equals(0, f23(122));
Expect.equals(1, f23(123));
Expect.equals(0, f24(0));
Expect.equals(1, f24(-1));
Expect.equals(0, f25(-1));
Expect.equals(1, f25(0));
Expect.equals(0, f26(0));
Expect.equals(1, f26(1));
}
+301
View File
@@ -0,0 +1,301 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--deterministic --optimization_counter_threshold=10
// Test on specialized vs non-specialized inlining.
import 'dart:core';
import "package:expect/expect.dart";
// To inline or not to inline, that is the question?
int foo(int k) {
switch (k) {
case 0:
return 1;
case 1:
return 2;
case 2:
return 3;
case 3:
return 4;
case 4:
return 5;
case 5:
return 6;
case 6:
return 7;
case 7:
return 8;
case 8:
return 9;
case 9:
return 10;
case 10:
return 11;
case 11:
return 12;
case 12:
return 13;
case 13:
return 14;
case 14:
return 15;
case 15:
return 16;
case 16:
return 17;
case 17:
return 18;
case 18:
return 19;
case 19:
return 20;
case 20:
return 21;
case 21:
return 22;
case 22:
return 23;
case 23:
return 24;
case 24:
return 25;
case 25:
return 26;
case 26:
return 27;
case 27:
return 28;
case 28:
return 29;
case 29:
return 30;
case 30:
return 31;
case 31:
return 32;
case 32:
return 33;
case 33:
return 34;
case 34:
return 35;
case 35:
return 36;
case 36:
return 37;
case 37:
return 38;
case 38:
return 39;
case 39:
return 40;
case 40:
return 41;
case 41:
return 42;
case 42:
return 43;
case 43:
return 44;
case 44:
return 45;
case 45:
return 46;
case 46:
return 47;
case 47:
return 48;
case 48:
return 49;
case 49:
return 50;
case 50:
return 51;
case 51:
return 52;
case 52:
return 53;
case 53:
return 54;
case 54:
return 55;
case 55:
return 56;
case 56:
return 57;
case 57:
return 58;
case 58:
return 59;
case 59:
return 60;
case 60:
return 61;
case 61:
return 62;
case 62:
return 63;
case 63:
return 64;
case 64:
return 65;
case 65:
return 66;
case 66:
return 67;
case 67:
return 68;
case 68:
return 69;
case 69:
return 70;
case 70:
return 71;
case 71:
return 72;
case 72:
return 73;
case 73:
return 74;
case 74:
return 75;
case 75:
return 76;
case 76:
return 77;
case 77:
return 78;
case 78:
return 79;
case 79:
return 80;
case 80:
return 81;
case 81:
return 82;
case 82:
return 83;
case 83:
return 84;
case 84:
return 85;
case 85:
return 86;
case 86:
return 87;
case 87:
return 88;
case 88:
return 89;
case 89:
return 90;
case 90:
return 91;
case 91:
return 92;
case 92:
return 93;
case 93:
return 94;
case 94:
return 95;
case 95:
return 96;
case 96:
return 97;
case 97:
return 98;
case 98:
return 99;
case 99:
return 100;
case 100:
return 101;
case 101:
return 102;
case 102:
return 103;
case 103:
return 104;
case 104:
return 105;
case 105:
return 106;
case 106:
return 107;
case 107:
return 108;
case 108:
return 109;
case 109:
return 110;
case 110:
return 111;
case 111:
return 112;
case 112:
return 113;
case 113:
return 114;
case 114:
return 115;
case 115:
return 116;
case 116:
return 117;
case 117:
return 118;
case 118:
return 119;
case 119:
return 120;
case 120:
return 121;
case 121:
return 122;
case 122:
return 123;
case 123:
return 124;
case 124:
return 125;
case 125:
return 126;
case 126:
return 127;
case 127:
return 128;
default:
return -1;
}
}
@pragma('vm:never-inline')
int bar() {
// Here we should inline! The inlined size is very small
// after specialization for the constant arguments.
return foo(1) + foo(12);
}
@pragma('vm:never-inline')
int baz(int i) {
// Here we should not inline! The inlined size is too large,
// just keep the original method. In fact, we can use the cached
// estimate of foo()'s size from the previous compilation at this
// point, which enables the "early" bail heuristic!
return foo(i);
}
main() {
// Repeat tests to enter JIT (when applicable).
for (int i = 0; i < 20; i++) {
Expect.equals(15, bar());
for (int i = -150; i <= 150; i++) {
int e = (i < 0 || i > 127) ? -1 : i + 1;
Expect.equals(e, baz(i));
}
}
}
@@ -0,0 +1,33 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test various optimizations and deoptimizations of optimizing compiler..
// VMOptions=--no-background-compilation --optimization-counter-threshold=1000
import "package:expect/expect.dart";
import "dart:typed_data";
var list = new Uint32List(1);
@pragma('vm:never-inline')
testuint32(bool b) {
var t;
if (b) {
t = list[0];
}
if (t != null) {
return t & 0x7fffffff;
}
return -1;
}
main() {
var s = 0;
testuint32(true);
testuint32(false);
for (int i = 0; i < 10000; ++i) {
testuint32(true);
}
Expect.equals(0, testuint32(true));
Expect.equals(-1, testuint32(false));
}
@@ -0,0 +1,25 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test various optimizations and deoptimizations of optimizing compiler..
// VMOptions=--no-background-compilation --optimization-counter-threshold=1000
import "package:expect/expect.dart";
@pragma('vm:never-inline')
testuint32(y) {
int x = y;
if (x != null) {
return x & 0xffff;
}
}
main() {
var s = 0;
testuint32(0x7fffffff);
for (int i = 0; i < 10000; ++i) {
testuint32(i);
}
Expect.equals(65535, testuint32(0x7fffffff));
Expect.equals(65535, testuint32(0x7f3452435245ffff));
}
@@ -0,0 +1,32 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--no_background_compilation --optimization_counter_threshold=10
import "package:expect/expect.dart";
// This method forms an infinite, irreducible loop. As long as we
// don't enter any of the branches, the method terminates. The test
// is included to ensure an irreducible loop does not break anything
// in the compiler.
int bar(int x) {
switch (x) {
case_1:
case 1:
continue case_2;
case_2:
case 2:
continue case_1;
}
return x;
}
main() {
for (var i = -50; i <= 0; i++) {
Expect.equals(i, bar(i));
}
for (var i = 3; i <= 50; i++) {
Expect.equals(i, bar(i));
}
}
@@ -0,0 +1,22 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Regression test for VM's IfConverted pass not keeping graph structure and
// use lists in sync.
// VMOptions=--optimization-counter-threshold=10 --no-background-compilation
class A {
late int x;
}
f() {
var a = new A();
a.x = (true ? 2 : 4);
return a.x;
}
main() {
for (var i = 0; i < 20; i++) f();
}
@@ -0,0 +1,16 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:typed_data';
import 'package:expect/expect.dart';
main() {
final val = (0xffb15062).toSigned(32);
final arr = new Int32x4List(1);
arr[0] = new Int32x4(val, val, val, val);
Expect.equals(val, arr[0].x);
Expect.equals(val, arr[0].y);
Expect.equals(val, arr[0].z);
Expect.equals(val, arr[0].w);
}
@@ -0,0 +1,82 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:expect/legacy/async_minitest.dart'; // ignore: deprecated_member_use
import 'lazy_async_exception_stack_helper.dart' as h;
foo3() async => throw "foo";
bar3() async => throw "bar";
foo2() async => foo3();
bar2() async => bar3();
foo() async => foo2();
bar() async => bar2();
test1() async {
// test1 -> foo -> foo2 -> foo3
// test1 -> bar -> bar2 -> bar3
// These run interleaved, check their stack traces don't become mixed.
var a = foo();
var b = bar();
try {
await a;
} catch (e, st) {
// st has foo,2,3 and not bar,2,3.
expect(
h.stringContainsInOrder(st.toString(), ['foo3', 'foo2', 'foo', 'test1']),
isTrue,
);
expect(st.toString().contains('bar'), isFalse);
}
try {
await b;
} catch (e, st) {
// st has bar,2,3 but not foo,2,3
expect(
h.stringContainsInOrder(st.toString(), ['bar3', 'bar2', 'bar', 'test1']),
isTrue,
);
expect(st.toString().contains('foo'), isFalse);
}
}
test2() async {
// test2 -> foo -> foo2 -> foo3
// test2 -> bar -> bar2 -> bar3
// These run sequentially, check the former stack trace didn't get linked to
// from the latter stack trace.
try {
await foo();
} catch (e, st) {
// st has foo,2,3 but not bar,2,3
expect(
h.stringContainsInOrder(st.toString(), ['foo3', 'foo2', 'foo', 'test2']),
isTrue,
);
expect(st.toString().contains('bar'), isFalse);
}
try {
await bar();
} catch (e, st) {
// st has bar,2,3 but not foo,2,3
expect(
h.stringContainsInOrder(st.toString(), ['bar3', 'bar2', 'bar', 'test2']),
isTrue,
);
expect(st.toString().contains('foo'), isFalse);
}
}
main() async {
test('lazy async exception stack', () async {
await test1();
await test2();
});
}
@@ -0,0 +1,14 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
bool stringContainsInOrder(String string, List<String> substrings) {
var fromIndex = 0;
for (var s in substrings) {
fromIndex = string.indexOf(s, fromIndex);
if (fromIndex < 0) {
return false;
}
}
return true;
}
@@ -0,0 +1,84 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:expect/legacy/async_minitest.dart'; // ignore: deprecated_member_use
import 'lazy_async_exception_stack_helper.dart' as h;
thrower() async {
throw 'oops';
}
number() async {
return 4;
}
generator() async* {
yield await number();
yield await thrower();
}
foo() async {
await for (var i in generator()) {
print(i);
}
}
main() async {
// Test async and async*.
test('lazy async exception stack', () async {
try {
await foo();
fail("Did not throw");
} catch (e, st) {
expect(
h.stringContainsInOrder(st.toString(), [
'thrower', '.dart:10', // no auto-format.
'generator', '.dart:19', // no auto-format.
'<asynchronous suspension>', // no auto-format.
'foo', '.dart', // no auto-format.
'main',
]),
isTrue,
);
}
inner() async {
deep() async {
await thrower();
}
await deep();
}
// Test inner functions.
try {
await inner();
} catch (e, st) {
expect(
h.stringContainsInOrder(st.toString(), [
'thrower',
'main.<anonymous closure>.inner.deep',
'main.<anonymous closure>.inner',
'main',
'<asynchronous suspension>',
]),
isTrue,
);
}
// Test for correct linkage.
try {
await thrower();
} catch (e, st) {
expect(
h.stringContainsInOrder(st.toString(), [
'thrower', '.dart:10', // no auto-format.
'main.<anonymous closure>', '.dart:73', // no auto-format.
]),
isTrue,
);
}
});
}
@@ -0,0 +1,35 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization-filter=foo --deoptimize_every=10 --optimization-counter-threshold=10 --no-background-compilation
// Test that lazy deoptimization on stack checks does not damage unoptimized
// frame.
import 'package:expect/expect.dart';
foo() {
var a = 0;
var b = 1;
var c = 2;
var d = 3;
var e = 4;
for (var i = 0; i < 10; i++) {
a++;
b++;
c++;
d++;
e++;
}
Expect.equals(10, a);
Expect.equals(11, b);
Expect.equals(12, c);
Expect.equals(13, d);
Expect.equals(14, e);
}
main() {
for (var i = 0; i < 10; ++i) {
foo();
}
}
@@ -0,0 +1,65 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test deoptimization on an optimistically hoisted smi check.
// VMOptions=--optimization-counter-threshold=10 --no-background-compilation
// Test that lazy deoptimization works if the program returns to a function
// that is scheduled for lazy deoptimization via an exception.
import 'package:expect/expect.dart';
class C {
dynamic x = 42;
}
@pragma('vm:never-inline')
AA(C c, bool b) {
if (b) {
c.x = 2.5;
throw 123;
}
}
@pragma('vm:never-inline')
T1(C c, bool b) {
try {
AA(c, b);
} on dynamic catch (e, st) {
print(e);
print(st);
Expect.isTrue(st is StackTrace, "is StackTrace");
}
return c.x + 1;
}
@pragma('vm:never-inline')
T2(C c, bool b) {
try {
AA(c, b);
} on String catch (e, st) {
print(e);
print(st);
Expect.isTrue(st is StackTrace, "is StackTrace");
Expect.isTrue(false);
} on int catch (e, st) {
Expect.equals(e, 123);
Expect.equals(b, true);
Expect.equals(c.x, 2.5);
print(st);
Expect.isTrue(st is StackTrace, "is StackTrace");
}
return c.x + 1;
}
main() {
var c = new C();
for (var i = 0; i < 10000; ++i) {
T1(c, false);
T2(c, false);
}
Expect.equals(43, T1(c, false));
Expect.equals(43, T2(c, false));
Expect.equals(3.5, T1(c, true));
Expect.equals(3.5, T2(c, true));
}
@@ -0,0 +1,81 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test deoptimization on an optimistically hoisted smi check.
// VMOptions=--optimization-counter-threshold=10 --no-background-compilation
// Test that lazy deoptimization works if the program returns to a function
// that is scheduled for lazy deoptimization via an exception, even under
// heavy concurrent load.
import 'dart:async';
import 'dart:isolate';
import 'package:expect/expect.dart';
class C {
dynamic x = 42;
}
@pragma('vm:never-inline')
AA(C c, bool b) {
if (b) {
c.x = 2.5;
throw 123;
}
}
@pragma('vm:never-inline')
T1(C c, bool b) {
try {
AA(c, b);
} on dynamic {}
return c.x + 1;
}
@pragma('vm:never-inline')
T2(C c, bool b) {
try {
AA(c, b);
} on String {
Expect.isTrue(false);
} on int catch (e) {
Expect.equals(e, 123);
Expect.equals(b, true);
Expect.equals(c.x, 2.5);
}
return c.x + 1;
}
main() async {
const count = 10;
final rp = ReceivePort();
for (int i = 0; i < count; ++i) {
Isolate.spawn(entry, i, onExit: rp.sendPort);
}
final si = StreamIterator(rp);
int j = 0;
while (await si.moveNext()) {
j++;
if (j == count) break;
}
print('done');
if (j != count) throw 'a';
si.cancel();
rp.close();
print('done');
}
void entry(_) {
var c = new C();
for (var i = 0; i < 100000; ++i) {
T1(c, false);
T2(c, false);
}
Expect.equals(43, T1(c, false));
Expect.equals(43, T2(c, false));
Expect.equals(3.5, T1(c, true));
Expect.equals(3.5, T2(c, true));
}
@@ -0,0 +1,56 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test deoptimization on an optimistically hoisted smi check.
// VMOptions=--optimization-counter-threshold=10 --no-background-compilation
// Test that lazy deoptimization works if the program returns to a function
// that is scheduled for lazy deoptimization via an exception.
import 'package:expect/expect.dart';
class C {
dynamic x = 42;
}
@pragma('vm:never-inline')
AA(C c, bool b) {
if (b) {
c.x = 2.5;
throw 123;
}
}
@pragma('vm:never-inline')
T1(C c, bool b) {
try {
AA(c, b);
} on dynamic {}
return c.x + 1;
}
@pragma('vm:never-inline')
T2(C c, bool b) {
try {
AA(c, b);
} on String {
Expect.isTrue(false);
} on int catch (e) {
Expect.equals(e, 123);
Expect.equals(b, true);
Expect.equals(c.x, 2.5);
}
return c.x + 1;
}
main() {
var c = new C();
for (var i = 0; i < 10000; ++i) {
T1(c, false);
T2(c, false);
}
Expect.equals(43, T1(c, false));
Expect.equals(43, T2(c, false));
Expect.equals(3.5, T1(c, true));
Expect.equals(3.5, T2(c, true));
}
@@ -0,0 +1,35 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization_counter_threshold=100 --no-use-osr --no-background_compilation
import "package:expect/expect.dart";
class X {
final nested = [];
get length => nested.length;
}
loop(val) {
var sum = 0;
for (var i = 0; i < 10; i++) {
sum += val.length as int;
}
return sum;
}
// LoadField(LoadField(",", nested), length) should not be hoisted.
// Otherwise it would crash.
testRedef() => loop(",");
main() {
// Provide polymorphic type feedback.
loop("");
loop(new X());
// Optimize loop with a constant argument.
for (var i = 0; i < 100; i++) {
testRedef();
}
}
@@ -0,0 +1,48 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test correctness of side effects tracking used by load to load forwarding.
// VMOptions=--no-use-osr --optimization-counter-threshold=10 --no-background-compilation
import "package:expect/expect.dart";
late B G;
@pragma('vm:never-inline')
modify() {
G.bval = 123;
}
class B {
@pragma('vm:prefer-inline')
poly() {
G = this;
modify();
return bval;
}
var bval = -1;
}
class C {
poly() => null;
}
@pragma('vm:prefer-inline')
foo(obj) => obj.poly();
@pragma('vm:never-inline')
test() {
var b = new B();
foo(b);
return b.bval;
}
main() {
foo(new C());
foo(new B());
for (var i = 0; i < 100; i++) test();
Expect.equals(123, test());
}
@@ -0,0 +1,55 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test correctness of side effects tracking used by load to load forwarding.
// VMOptions=--optimization-counter-threshold=10 --no-use-osr --no-background-compilation
// Tests correct handling of redefinitions in aliasing computation.
import "package:expect/expect.dart";
var H = true;
class A {
late B bb;
@pragma('vm:prefer-inline')
poly(p) {
if (H) {
bb = p;
}
B t = bb;
t.bval = 123;
return t.bval;
}
}
class B {
int bval = -1;
@pragma('vm:prefer-inline')
poly(p) {
return bval;
}
}
@pragma('vm:prefer-inline')
foo(obj, p) => obj.poly(p);
@pragma('vm:never-inline')
test() {
A a = new A();
B b = new B();
foo(a, b);
return b.bval;
}
main() {
// Prime foo with polymorphic type feedback.
foo(new B(), new A());
foo(new A(), new B());
for (var i = 0; i < 100; i++) test();
Expect.equals(123, test());
}
@@ -0,0 +1,60 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test correctness of side effects tracking used by load to load forwarding.
// VMOptions=--no-use-osr --optimization-counter-threshold=10 --no-background-compilation
// Tests correct handling of redefinitions in aliasing computation.
import "package:expect/expect.dart";
late B G;
class A {
int val = -1;
@pragma('vm:prefer-inline')
poly(p) {
p.aa = this;
}
}
@pragma('vm:never-inline')
modify() {
G.aa.val = 123;
}
class B {
late A aa;
@pragma('vm:prefer-inline')
poly(p) {
G = this;
foo2(p, this);
modify();
}
}
@pragma('vm:prefer-inline')
foo(obj, p) => obj.poly(p);
@pragma('vm:prefer-inline')
foo2(obj, p) => obj.poly(p);
@pragma('vm:never-inline')
testfunc() {
var a = new A();
var b = new B();
foo(b, a);
return a.val;
}
main() {
foo(new B(), new A());
foo(new A(), new B());
foo2(new B(), new A());
foo2(new A(), new B());
for (var i = 0; i < 100; i++) testfunc();
Expect.equals(123, testfunc());
}
@@ -0,0 +1,56 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test correctness of side effects tracking used by load to load forwarding.
// VMOptions=--optimization-counter-threshold=10 --no-use-osr --no-background-compilation
// Tests correct handling of redefinitions in aliasing computation.
import "package:expect/expect.dart";
var H = true;
class A {
late B bb;
@pragma('vm:prefer-inline')
poly(p) {
if (H) {
bb = p;
}
B t = bb;
t.bval = 123;
return t.bval;
}
}
class B {
int bval = -1;
@pragma('vm:prefer-inline')
poly(p) {
return bval;
}
}
@pragma('vm:prefer-inline')
foo(obj, p) => obj.poly(p);
@pragma('vm:never-inline')
test() {
A a = new A();
B b = new B();
foo(a, b);
foo(a, b);
return b.bval;
}
main() {
// Prime foo with polymorphic type feedback.
foo(new B(), new A());
foo(new A(), new B());
for (var i = 0; i < 100; i++) test();
Expect.equals(123, test());
}
@@ -0,0 +1,27 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test correctness of side effects tracking used by load to load forwarding.
// In this cutdown version of the load_to_load_forwarding_vm test, the function
// being compiled ends up in a single basic block, which tests load
// elimination when generating the initial sets.
// VMOptions=--optimization-counter-threshold=10 --no-background-compilation
import "package:expect/expect.dart";
import "dart:typed_data";
testViewAliasing1() {
final f64 = new Float64List(1);
final f32 = new Float32List.view(f64.buffer);
f64[0] = 1.0; // Should not be forwarded.
f32[1] = 2.0; // upper 32bits for 2.0f and 2.0 are the same
return f64[0];
}
main() {
for (var i = 0; i < 20; i++) {
Expect.equals(2.0, testViewAliasing1());
}
}
@@ -0,0 +1,592 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test correctness of side effects tracking used by load to load forwarding.
// VMOptions=--optimization-counter-threshold=10 --no-background-compilation
import "package:expect/expect.dart";
import "dart:typed_data";
class A {
var x, y;
A(this.x, this.y);
}
foo(a) {
var value1 = a.x;
var value2 = a.y;
for (var j = 1; j < 4; j++) {
value1 |= a.x << (j * 8);
a.y += 1;
a.x += 1;
value2 |= a.y << (j * 8);
}
return [value1, value2];
}
bar(a, mode) {
var value1 = a.x;
var value2 = a.y;
for (var j = 1; j < 4; j++) {
value1 |= a.x << (j * 8);
a.y += 1;
if (mode) a.x += 1;
a.x += 1;
value2 |= a.y << (j * 8);
}
return [value1, value2];
}
// Verify that immutable and mutable VM fields (array length in this case)
// are not confused by load forwarding even if the access the same offset
// in the object.
testImmutableVMFields(arr, immutable) {
if (immutable) {
return arr.length; // Immutable length load.
}
if (arr.length < 2) {
// Mutable length load, should not be forwarded.
arr.add(null);
}
return arr.length;
}
testPhiRepresentation(f, arr) {
if (f) {
arr[0] = arr[0] + arr[1];
} else {
arr[0] = arr[0] - arr[1];
}
return arr[0];
}
testPhiConversions(f, arr) {
if (f) {
arr[0] = arr[1];
} else {
arr[0] = arr[2];
}
return arr[0];
}
class M {
var x;
M(this.x);
}
fakeAliasing(arr) {
var a = new M(10);
var b = new M(10);
var c = arr.length;
if (c * c != c * c) {
arr[0] = a; // Escape.
arr[0] = b;
}
return c * c; // Deopt point.
}
class X {
var next;
X(this.next);
}
testPhiForwarding(obj) {
if (obj.next == null) {
return 1;
}
var len = 0;
while (obj != null) {
len++;
obj = obj.next; // This load should not be forwarded.
}
return len;
}
testPhiForwarding2(obj) {
if (obj.next == null) {
return 1;
}
var len = 0, next = null;
while ((obj != null) && len < 2) {
len++;
obj = obj.next; // This load should be forwarded.
next = obj.next;
}
return len;
}
class V {
final f;
V(this.f);
}
testPhiForwarding3() {
var a = new V(-0.1);
var c = new V(0.0);
var b = new V(0.1);
for (var i = 0; i < 3; i++) {
var af = a.f;
var bf = b.f;
var cf = c.f;
a = new V(cf);
b = new V(af);
c = new V(bf);
}
Expect.equals(-0.1, a.f);
Expect.equals(0.1, b.f);
Expect.equals(0.0, c.f);
}
testPhiForwarding4() {
var a = new V(-0.1);
var b = new V(0.1);
var c = new V(0.0);
var result = new List<dynamic>.filled(9, null);
for (var i = 0, j = 0; i < 3; i++) {
result[j++] = a.f;
result[j++] = b.f;
result[j++] = c.f;
var xa = a;
var xb = b;
a = c;
b = xa;
c = xb;
}
Expect.listEquals([-0.1, 0.1, 0.0, 0.0, -0.1, 0.1, 0.1, 0.0, -0.1], result);
}
class C {
C(this.box, this.parent);
final box;
final C? parent;
}
testPhiForwarding5(C c) {
var s = 0;
var tmp = c;
var a = c.parent;
if (a!.box + tmp.box != 1) throw "failed";
do {
s += (tmp.box + a!.box) as int;
tmp = a;
a = a.parent;
} while (a != null);
return s;
}
class U {
var x, y;
U() : x = 0, y = 0;
}
testEqualPhisElimination() {
var u = new U();
var v = new U();
var sum = 0;
for (var i = 0; i < 3; i++) {
u.x = i;
u.y = i;
if ((i & 1) == 1) {
v.x = i + 1;
v.y = i + 1;
} else {
v.x = i - 1;
v.y = i - 1;
}
sum += (v.x + v.y) as int;
}
Expect.equals(4, sum);
Expect.equals(2, u.x);
Expect.equals(2, u.y);
}
testPhiMultipleRepresentations(f, arr) {
var w;
if (f) {
w = arr[0] + arr[1];
} else {
w = arr[0] - arr[1];
}
var v;
if (f) {
v = arr[0];
} else {
v = arr[0];
}
return v + w;
}
testIndexedNoAlias(a) {
a[0] = 1;
a[1] = 2;
a[2] = 3;
return a[0] + a[1];
}
//
// Tests for indexed store aliases were autogenerated to have extensive
// coverage for all interesting aliasing combinations within the alias
// lattice (*[*], *[C], X[*], X[C])
//
testIndexedAliasedStore1(i) {
var a = new List<dynamic>.filled(2, null);
a[0] = 1; // X[C]
a[i] = 2; // X[*]
return a[0];
}
testIndexedAliasedStore2(f, c) {
var a = new List<dynamic>.filled(2, null);
var d = f ? a : c;
a[0] = 1; // X[C]
d[0] = 2; // *[C]
return a[0];
}
testIndexedAliasedStore3(f, c, i) {
var a = new List<dynamic>.filled(2, null);
var d = f ? a : c;
a[0] = 1; // X[C]
d[i] = 2; // *[*]
return a[0];
}
testIndexedAliasedStore4(i) {
var a = new List<dynamic>.filled(2, null);
a[i] = 1; // X[*]
a[0] = 2; // X[C]
return a[i];
}
testIndexedAliasedStore5(i, j) {
var a = new List<dynamic>.filled(2, null);
a[i] = 1; // X[*]
a[j] = 2; // X[*]
return a[i];
}
testIndexedAliasedStore6(i, f, c) {
var a = new List<dynamic>.filled(2, null);
var d = f ? a : c;
a[i] = 1; // X[*]
d[0] = 2; // *[C]
return a[i];
}
testIndexedAliasedStore7(i, f, c) {
var a = new List<dynamic>.filled(2, null);
var d = f ? a : c;
a[i] = 1; // X[*]
d[i] = 2; // *[*]
return a[i];
}
testIndexedAliasedStore8(c, i) {
c[0] = 1; // *[C]
c[i] = 2; // *[*]
return c[0];
}
testIndexedAliasedStore9(c, f) {
var a = new List<dynamic>.filled(2, null);
var d = f ? a : c;
c[0] = 1; // *[C]
d[0] = 2; // *[C]
return c[0];
}
testIndexedAliasedStore10(c, i) {
c[i] = 1; // *[*]
c[0] = 2; // *[C]
return c[i];
}
testIndexedAliasedStore11(c, i, j) {
c[i] = 1; // *[*]
c[j] = 2; // *[*]
return c[i];
}
testIndexedAliasedStore12(f, c) {
var a = new List<dynamic>.filled(2, null);
var d = f ? a : c;
d[0] = 1; // *[C]
a[0] = 2; // X[C]
return d[0];
}
testIndexedAliasedStore13(f, c, i) {
var a = new List<dynamic>.filled(2, null);
var d = f ? a : c;
d[0] = 1; // *[C]
a[i] = 2; // X[*]
return d[0];
}
testIndexedAliasedStore14(f, c, i) {
var a = new List<dynamic>.filled(2, null);
var d = f ? a : c;
d[i] = 1; // *[*]
a[0] = 2; // X[C]
return d[i];
}
testIndexedAliasedStore15(f, c, i) {
var a = new List<dynamic>.filled(2, null);
var d = f ? a : c;
d[i] = 1; // *[*]
a[i] = 2; // X[*]
return d[i];
}
testIndexedAliasedStores() {
var arr = new List<dynamic>.filled(2, null);
for (var i = 0; i < 50; i++) {
Expect.equals(2, testIndexedAliasedStore1(0));
Expect.equals(1, testIndexedAliasedStore1(1));
}
for (var i = 0; i < 50; i++) {
Expect.equals(1, testIndexedAliasedStore2(false, arr));
Expect.equals(2, testIndexedAliasedStore2(true, arr));
}
for (var i = 0; i < 50; i++) {
Expect.equals(1, testIndexedAliasedStore3(false, arr, 0));
Expect.equals(1, testIndexedAliasedStore3(false, arr, 1));
Expect.equals(2, testIndexedAliasedStore3(true, arr, 0));
Expect.equals(1, testIndexedAliasedStore3(true, arr, 1));
}
for (var i = 0; i < 50; i++) {
Expect.equals(2, testIndexedAliasedStore4(0));
Expect.equals(1, testIndexedAliasedStore4(1));
}
for (var i = 0; i < 50; i++) {
Expect.equals(2, testIndexedAliasedStore5(0, 0));
Expect.equals(1, testIndexedAliasedStore5(0, 1));
Expect.equals(1, testIndexedAliasedStore5(1, 0));
Expect.equals(2, testIndexedAliasedStore5(1, 1));
}
for (var i = 0; i < 50; i++) {
Expect.equals(1, testIndexedAliasedStore6(0, false, arr));
Expect.equals(2, testIndexedAliasedStore6(0, true, arr));
Expect.equals(1, testIndexedAliasedStore6(1, false, arr));
Expect.equals(1, testIndexedAliasedStore6(1, true, arr));
}
for (var i = 0; i < 50; i++) {
Expect.equals(1, testIndexedAliasedStore7(0, false, arr));
Expect.equals(2, testIndexedAliasedStore7(0, true, arr));
Expect.equals(1, testIndexedAliasedStore7(1, false, arr));
Expect.equals(2, testIndexedAliasedStore7(1, true, arr));
}
for (var i = 0; i < 50; i++) {
Expect.equals(2, testIndexedAliasedStore8(arr, 0));
Expect.equals(1, testIndexedAliasedStore8(arr, 1));
}
for (var i = 0; i < 50; i++) {
Expect.equals(2, testIndexedAliasedStore9(arr, false));
Expect.equals(1, testIndexedAliasedStore9(arr, true));
}
for (var i = 0; i < 50; i++) {
Expect.equals(2, testIndexedAliasedStore10(arr, 0));
Expect.equals(1, testIndexedAliasedStore10(arr, 1));
}
for (var i = 0; i < 50; i++) {
Expect.equals(2, testIndexedAliasedStore11(arr, 0, 0));
Expect.equals(1, testIndexedAliasedStore11(arr, 0, 1));
Expect.equals(1, testIndexedAliasedStore11(arr, 1, 0));
Expect.equals(2, testIndexedAliasedStore11(arr, 1, 1));
}
for (var i = 0; i < 50; i++) {
Expect.equals(1, testIndexedAliasedStore12(false, arr));
Expect.equals(2, testIndexedAliasedStore12(true, arr));
}
for (var i = 0; i < 50; i++) {
Expect.equals(1, testIndexedAliasedStore13(false, arr, 0));
Expect.equals(1, testIndexedAliasedStore13(false, arr, 1));
Expect.equals(2, testIndexedAliasedStore13(true, arr, 0));
Expect.equals(1, testIndexedAliasedStore13(true, arr, 1));
}
for (var i = 0; i < 50; i++) {
Expect.equals(1, testIndexedAliasedStore14(false, arr, 0));
Expect.equals(1, testIndexedAliasedStore14(false, arr, 1));
Expect.equals(2, testIndexedAliasedStore14(true, arr, 0));
Expect.equals(1, testIndexedAliasedStore14(true, arr, 1));
}
for (var i = 0; i < 50; i++) {
Expect.equals(1, testIndexedAliasedStore15(false, arr, 0));
Expect.equals(1, testIndexedAliasedStore15(false, arr, 1));
Expect.equals(2, testIndexedAliasedStore15(true, arr, 0));
Expect.equals(2, testIndexedAliasedStore15(true, arr, 1));
}
}
var indices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
class Z {
var x = 42;
}
var global_array = new List<Z?>.filled(1, null);
side_effect() {
global_array[0]!.x++;
}
testAliasingStoreIndexed(array) {
var z = new Z();
array[0] = z;
side_effect();
return z.x;
}
class ZZ {
var f;
}
var zz, f0 = 42;
testAliasesRefinement() {
zz = new ZZ();
var b = zz;
if (b.f == null) {
b.f = f0;
}
return b.f;
}
testViewAliasing1() {
final f64 = new Float64List(1);
final f32 = new Float32List.view(f64.buffer);
f64[0] = 1.0; // Should not be forwarded.
f32[1] = 2.0; // upper 32bits for 2.0f and 2.0 are the same
return f64[0];
}
testViewAliasing2() {
final f64 = new Float64List(2);
final f64v = new Float64List.view(f64.buffer, Float64List.bytesPerElement);
f64[1] = 1.0; // Should not be forwarded.
f64v[0] = 2.0;
return f64[1];
}
testViewAliasing3() {
final u8 = new Uint8List(Float64List.bytesPerElement * 2);
final f64 = new Float64List.view(u8.buffer, Float64List.bytesPerElement);
f64[0] = 1.0; // Should not be forwarded.
u8[15] = 0x40;
u8[14] = 0x00;
return f64[0];
}
testViewAliasing4() {
final u8 = new Uint8List(Float64List.bytesPerElement * 2);
final f64 = new Float64List.view(u8.buffer, Float64List.bytesPerElement);
f64[0] = 2.0; // Not aliased: should be forwarded.
u8[0] = 0x40;
u8[1] = 0x00;
return f64[0];
}
main() {
final fixed = new List<dynamic>.filled(10, null);
final growable = [];
testImmutableVMFields(fixed, true);
testImmutableVMFields(growable, false);
testImmutableVMFields(growable, false);
final f64List = new Float64List(2);
testPhiRepresentation(true, f64List);
testPhiRepresentation(false, f64List);
final obj = new X(new X(new X(null)));
final cs = new C(0, new C(1, new C(2, null)));
for (var i = 0; i < 20; i++) {
Expect.listEquals([0x02010000, 0x03020100], foo(new A(0, 0)));
Expect.listEquals([0x02010000, 0x03020100], bar(new A(0, 0), false));
Expect.listEquals([0x04020000, 0x03020100], bar(new A(0, 0), true));
testImmutableVMFields(fixed, true);
testPhiRepresentation(true, f64List);
testPhiForwarding(obj);
testPhiForwarding2(obj);
testPhiForwarding3();
testPhiForwarding4();
Expect.equals(4, testPhiForwarding5(cs));
testEqualPhisElimination();
Expect.equals(f0, testAliasesRefinement());
}
Expect.equals(1, testImmutableVMFields(<dynamic>[], false));
Expect.equals(2, testImmutableVMFields(<int?>[1], false));
Expect.equals(2, testImmutableVMFields(<int?>[1, 2], false));
Expect.equals(3, testImmutableVMFields(<int?>[1, 2, 3], false));
final u32List = new Uint32List(3);
u32List[0] = 0;
u32List[1] = 0x3FFFFFFF;
u32List[2] = 0x7FFFFFFF;
for (var i = 0; i < 20; i++) {
testPhiConversions(true, u32List);
testPhiConversions(false, u32List);
}
for (var i = 0; i < 20; i++) {
Expect.equals(0.0, testPhiMultipleRepresentations(true, f64List));
Expect.equals(0, testPhiMultipleRepresentations(false, const [1, 2]));
}
final escape = new List<dynamic>.filled(1, null);
for (var i = 0; i < 20; i++) {
fakeAliasing(escape);
}
final array = new List<dynamic>.filled(3, null);
for (var i = 0; i < 20; i++) {
Expect.equals(3, testIndexedNoAlias(array));
}
testIndexedAliasedStores();
var test_array = new List<dynamic>.filled(1, null);
for (var i = 0; i < 20; i++) {
Expect.equals(43, testAliasingStoreIndexed(global_array));
}
for (var i = 0; i < 20; i++) {
Expect.equals(2.0, testViewAliasing1());
Expect.equals(2.0, testViewAliasing2());
Expect.equals(2.0, testViewAliasing3());
Expect.equals(2.0, testViewAliasing4());
}
}
@@ -0,0 +1,24 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test correctness of side effects tracking used by load to load forwarding.
// Should be merged into load_to_load_forwarding once Issue 22151 is fixed.
// VMOptions=--optimization-counter-threshold=10 --no-background-compilation
import "package:expect/expect.dart";
import "dart:typed_data";
testViewAliasing5() {
final f32 = new Float32List(2);
final raw = f32.buffer.asByteData();
f32[0] = 1.5; // Aliased by unaligned write of the same size.
raw.setInt32(1, 0x00400000, Endian.little);
return f32[0];
}
main() {
for (var i = 0; i < 20; i++) {
Expect.equals(2.0, testViewAliasing5());
}
}
@@ -0,0 +1,61 @@
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Tests that the VM does not crash on weird corner cases of class Math.
// VMOptions=--optimization_counter_threshold=100 --no-background_compilation
library math_vm_test;
import "package:expect/expect.dart";
import 'dart:math';
class FakeNumber {
const FakeNumber();
void toDouble() {}
}
class MathTest {
static bool testParseInt(x) {
try {
int.parse(x); // Expects string.
return true;
} catch (e) {
return false;
}
}
static bool testSqrt(x) {
try {
sqrt(x); // Expects number.
return true;
} catch (e) {
return false;
}
}
static void testMain() {
Expect.equals(false, testParseInt(5));
Expect.equals(false, testSqrt(const FakeNumber()));
}
}
testDoublePow() {
Expect.equals((1 << 32).toDouble(), pow(2.0, 32));
}
testSinCos(a) {
double sVal = sin(a);
double cVal = cos(a);
return sVal + cVal;
}
main() {
const double value = 1.54;
final firstRes = testSinCos(value);
for (int i = 0; i < 200; i++) {
MathTest.testMain();
testDoublePow();
testSinCos(value);
}
Expect.equals(firstRes, testSinCos(value));
}
+37
View File
@@ -0,0 +1,37 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Illustrates inlining heuristic issue of
// https://github.com/dart-lang/sdk/issues/37126
// (mixins introduce one extra depth of inlining).
// VMOptions=--deterministic
import "package:expect/expect.dart";
class X {
const X();
int foo() {
return 1;
}
}
mixin YMixin {
int bar() {
return 2;
}
}
class Y with YMixin {
const Y();
}
@pragma("vm:never-inline")
int foobar() {
return new X().foo() + new Y().bar();
}
main() {
Expect.equals(3, foobar());
}
@@ -0,0 +1,309 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--no_background_compilation --optimization_counter_threshold=10
// VMOptions=--no_background_compilation --optimization_counter_threshold=10 --use_slow_path
import "package:expect/expect.dart";
// Tests for long trunc div and mod under
// 64-bit arithmetic wrap-around semantics.
final int maxInt32 = 2147483647;
final int minInt32 = -2147483648;
final int maxInt64 = 0x7fffffffffffffff;
final int minInt64 = 0x8000000000000000;
int mod(int x, int y) {
return x % y;
}
int truncdiv(int x, int y) {
return x ~/ y;
}
doModConstants() {
Expect.equals(0, mod(0, 1));
Expect.equals(0, mod(0, -1));
Expect.equals(1, mod(1, 2));
Expect.equals(1, mod(-1, 2));
Expect.equals(1, mod(1, -2));
Expect.equals(1, mod(-1, -2));
Expect.equals(2, mod(8, 3));
Expect.equals(1, mod(-8, 3));
Expect.equals(2, mod(8, -3));
Expect.equals(1, mod(-8, -3));
Expect.equals(0, mod(6, 3));
Expect.equals(1, mod(7, 3));
Expect.equals(2, mod(8, 3));
Expect.equals(0, mod(9, 3));
Expect.equals(1, mod(1, maxInt32));
Expect.equals(1, mod(1, maxInt64));
Expect.equals(1, mod(1, minInt32));
Expect.equals(1, mod(1, minInt64));
Expect.equals(maxInt32 - 1, mod(-1, maxInt32));
Expect.equals(maxInt64 - 1, mod(-1, maxInt64));
Expect.equals(maxInt32, mod(-1, minInt32));
Expect.equals(maxInt64, mod(-1, minInt64));
Expect.equals(0, mod(minInt32, -1));
Expect.equals(0, mod(maxInt32, -1));
Expect.equals(0, mod(minInt64, -1));
Expect.equals(0, mod(maxInt64, -1));
Expect.equals(0, mod(maxInt32, maxInt32));
Expect.equals(maxInt32, mod(maxInt32, minInt32));
Expect.equals(maxInt32, mod(maxInt32, maxInt64));
Expect.equals(maxInt32, mod(maxInt32, minInt64));
Expect.equals(maxInt32 - 1, mod(minInt32, maxInt32));
Expect.equals(0, mod(minInt32, minInt32));
Expect.equals(9223372034707292159, mod(minInt32, maxInt64));
Expect.equals(9223372034707292160, mod(minInt32, minInt64));
Expect.equals(1, mod(maxInt64, maxInt32));
Expect.equals(0, mod(maxInt64 - 1, maxInt32));
Expect.equals(maxInt32 - 1, mod(maxInt64 - 2, maxInt32));
Expect.equals(maxInt32, mod(maxInt64, minInt32));
Expect.equals(0, mod(maxInt64, maxInt64));
Expect.equals(maxInt64, mod(maxInt64, minInt64));
Expect.equals(maxInt32 - 2, mod(minInt64, maxInt32));
Expect.equals(0, mod(minInt64, minInt32));
Expect.equals(maxInt64 - 1, mod(minInt64, maxInt64));
Expect.equals(0, mod(minInt64, minInt64));
Expect.equals(maxInt32 - 1, mod(maxInt32 - 1, maxInt32));
Expect.equals(1, mod(maxInt32 + 1, maxInt32));
Expect.equals(maxInt32 - 2, mod(minInt32 - 1, maxInt32));
Expect.equals(0, mod(minInt32 + 1, maxInt32));
Expect.equals(15, mod(-1, 16));
Expect.equals(15, mod(-17, 16));
Expect.equals(15, mod(-1, -16));
Expect.equals(15, mod(-17, -16));
Expect.equals(100, mod(100, 1 << 32));
Expect.equals(100, mod(100, -(1 << 32)));
Expect.equals((1 << 32) - 1, mod((1 << 35) - 1, 1 << 32));
Expect.equals((1 << 32) - 1, mod((1 << 35) - 1, -(1 << 32)));
Expect.equals(maxInt64, mod(-1, 1 << 63));
Expect.equals(0, mod(minInt64, 1 << 63));
}
doModVarConstant() {
for (int i = -10; i < 10; i++) {
Expect.equals(i & maxInt64, mod(i, minInt64));
}
}
doTruncDivConstants() {
Expect.equals(0, truncdiv(0, 1));
Expect.equals(0, truncdiv(0, -1));
Expect.equals(0, truncdiv(1, 2));
Expect.equals(0, truncdiv(-1, 2));
Expect.equals(0, truncdiv(1, -2));
Expect.equals(0, truncdiv(-1, -2));
Expect.equals(2, truncdiv(8, 3));
Expect.equals(-2, truncdiv(-8, 3));
Expect.equals(-2, truncdiv(8, -3));
Expect.equals(2, truncdiv(-8, -3));
Expect.equals(2, truncdiv(6, 3));
Expect.equals(2, truncdiv(7, 3));
Expect.equals(2, truncdiv(8, 3));
Expect.equals(3, truncdiv(9, 3));
Expect.equals(0, truncdiv(1, maxInt32));
Expect.equals(0, truncdiv(1, maxInt64));
Expect.equals(0, truncdiv(1, minInt32));
Expect.equals(0, truncdiv(1, minInt64));
Expect.equals(0, truncdiv(-1, maxInt32));
Expect.equals(0, truncdiv(-1, maxInt64));
Expect.equals(0, truncdiv(-1, minInt32));
Expect.equals(0, truncdiv(-1, minInt64));
Expect.equals(-minInt32, truncdiv(minInt32, -1));
Expect.equals(-maxInt32, truncdiv(maxInt32, -1));
Expect.equals(minInt64, truncdiv(minInt64, -1));
Expect.equals(-maxInt64, truncdiv(maxInt64, -1));
Expect.equals(1, truncdiv(maxInt32, maxInt32));
Expect.equals(0, truncdiv(maxInt32, minInt32));
Expect.equals(0, truncdiv(maxInt32, maxInt64));
Expect.equals(0, truncdiv(maxInt32, minInt64));
Expect.equals(-1, truncdiv(minInt32, maxInt32));
Expect.equals(1, truncdiv(minInt32, minInt32));
Expect.equals(0, truncdiv(minInt32, maxInt64));
Expect.equals(0, truncdiv(minInt32, minInt64));
Expect.equals(4294967298, truncdiv(maxInt64, maxInt32));
Expect.equals(4294967298, truncdiv(maxInt64 - 1, maxInt32));
Expect.equals(4294967297, truncdiv(maxInt64 - 2, maxInt32));
Expect.equals(-4294967295, truncdiv(maxInt64, minInt32));
Expect.equals(1, truncdiv(maxInt64, maxInt64));
Expect.equals(0, truncdiv(maxInt64, minInt64));
Expect.equals(-4294967298, truncdiv(minInt64, maxInt32));
Expect.equals(4294967296, truncdiv(minInt64, minInt32));
Expect.equals(-1, truncdiv(minInt64, maxInt64));
Expect.equals(1, truncdiv(minInt64, minInt64));
Expect.equals(0, truncdiv(maxInt32 - 1, maxInt32));
Expect.equals(1, truncdiv(maxInt32 + 1, maxInt32));
Expect.equals(-1, truncdiv(minInt32 - 1, maxInt32));
Expect.equals(-1, truncdiv(minInt32 + 1, maxInt32));
// Regression test for dartbug.com/53801 on 32-bit architectures.
Expect.equals(0, truncdiv((maxInt32 + 1) - 1, maxInt32 + 1));
Expect.equals(1, truncdiv((maxInt32 + 1) + 0, maxInt32 + 1));
Expect.equals(1, truncdiv((maxInt32 + 1) + 1, maxInt32 + 1));
Expect.equals(0, truncdiv(((maxInt32 + 1) << 3) - 1, (maxInt32 + 1) << 3));
Expect.equals(1, truncdiv(((maxInt32 + 1) << 3) + 0, (maxInt32 + 1) << 3));
Expect.equals(1, truncdiv(((maxInt32 + 1) << 3) + 1, (maxInt32 + 1) << 3));
Expect.equals(0, truncdiv(((maxInt64 >> 1) + 1) - 1, (maxInt64 >> 1) + 1));
Expect.equals(1, truncdiv(((maxInt64 >> 1) + 1) + 0, (maxInt64 >> 1) + 1));
Expect.equals(1, truncdiv(((maxInt64 >> 1) + 1) + 1, (maxInt64 >> 1) + 1));
}
int acc = -1;
doModVars(int xlo, int xhi, int ylo, int yhi) {
for (int x = xlo; x <= xhi; x++) {
for (int y = ylo; y <= yhi; y++) {
acc += mod(x, y);
}
}
}
doTruncDivVars(int xlo, int xhi, int ylo, int yhi) {
for (int x = xlo; x <= xhi; x++) {
for (int y = ylo; y <= yhi; y++) {
acc += truncdiv(x, y);
}
}
}
main() {
// Repeat to enter JIT (when applicable).
for (int i = 0; i < 20; i++) {
// Constants.
doModConstants();
doModVarConstant();
doTruncDivConstants();
// Variable ranges.
acc = 0;
doModVars(3, 5, 2, 6);
Expect.equals(28, acc);
acc = 0;
doModVars((3 << 32) - 1, (3 << 32) + 1, (3 << 32) - 1, (3 << 32) + 1);
Expect.equals(38654705666, acc);
acc = 0;
doModVars(minInt32 - 4, minInt32 + 4, -11, -1);
Expect.equals(239, acc);
acc = 0;
doModVars(minInt32 - 4, minInt32 + 4, 2, 7);
Expect.equals(85, acc);
acc = 0;
doModVars(minInt32 - 4, minInt32 + 4, minInt32 - 4, minInt32 + 4);
Expect.equals(77309411268, acc);
acc = 0;
doModVars(minInt32 - 4, minInt32 + 4, maxInt32 - 4, maxInt32 + 4);
Expect.equals(96636763974, acc);
acc = 0;
doModVars(maxInt32 - 4, maxInt32 + 4, 2, 7);
Expect.equals(104, acc);
acc = 0;
doModVars(maxInt32 - 4, maxInt32 + 4, minInt32 - 4, minInt32 + 4);
Expect.equals(96636764139, acc);
acc = 0;
doModVars(maxInt32 - 4, maxInt32 + 4, maxInt32 - 4, maxInt32 + 4);
Expect.equals(77309411352, acc);
acc = 0;
doTruncDivVars(3, 5, 2, 6);
Expect.equals(11, acc);
acc = 0;
doTruncDivVars(-5, -3, 2, 6);
Expect.equals(-11, acc);
acc = 0;
doTruncDivVars(3, 5, -6, -2);
Expect.equals(-11, acc);
acc = 0;
doTruncDivVars(-5, -3, -6, -2);
Expect.equals(11, acc);
acc = 0;
doTruncDivVars((3 << 32) - 1, (3 << 32) + 1, 3, 6);
Expect.equals(36721970376, acc);
acc = 0;
doTruncDivVars(minInt64, minInt64, -1, -1);
Expect.equals(minInt64, acc);
acc = 0;
doTruncDivVars(minInt32 - 4, minInt32 + 4, -11, -1);
Expect.equals(58366234918, acc);
acc = 0;
doTruncDivVars(minInt32 - 4, minInt32 + 4, 2, 7);
Expect.equals(-30785711991, acc);
acc = 0;
doTruncDivVars(minInt32 - 4, minInt32 + 4, minInt32 - 4, minInt32 + 4);
Expect.equals(45, acc);
acc = 0;
doTruncDivVars(minInt32 - 4, minInt32 + 4, maxInt32 - 4, maxInt32 + 4);
Expect.equals(-53, acc);
acc = 0;
doTruncDivVars(maxInt32 - 4, maxInt32 + 4, 2, 7);
Expect.equals(30785711975, acc);
acc = 0;
doTruncDivVars(maxInt32 - 4, maxInt32 + 4, minInt32 - 4, minInt32 + 4);
Expect.equals(-36, acc);
acc = 0;
doTruncDivVars(maxInt32 - 4, maxInt32 + 4, maxInt32 - 4, maxInt32 + 4);
Expect.equals(45, acc);
acc = 0;
doTruncDivVars(maxInt32 - 4, maxInt32 + 4, 1, 7);
Expect.equals(50113064798, acc);
// Exceptions at the right time.
acc = 0;
try {
doModVars(9, 9, -9, 0);
acc = 0; // don't reach!
} on UnsupportedError catch (e, s) {}
Expect.equals(12, acc);
acc = 0;
try {
doTruncDivVars(9, 9, -9, 0);
acc = 0; // don't reach!
} on UnsupportedError catch (e, s) {}
Expect.equals(-23, acc);
}
}
@@ -0,0 +1,102 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--no_background_compilation --optimization_counter_threshold=10
// VMOptions=--no_background_compilation --optimization_counter_threshold=10 --use_slow_path
import "package:expect/expect.dart";
// Tests for long multiplication under
// 64-bit arithmetic wrap-around semantics.
final int maxInt32 = 2147483647;
final int minInt32 = -2147483648;
final int maxInt64 = 0x7fffffffffffffff;
final int minInt64 = 0x8000000000000000;
int mul(int x, int y) {
return x * y;
}
doConstants() {
Expect.equals(0, mul(0, 0));
Expect.equals(0, mul(0, 7));
Expect.equals(0, mul(7, 0));
Expect.equals(1, mul(1, 1));
Expect.equals(7, mul(1, 7));
Expect.equals(7, mul(7, 1));
Expect.equals(21, mul(7, 3));
Expect.equals(21, mul(3, 7));
Expect.equals(21 << 32, mul(3 << 32, 7));
Expect.equals(21 << 32, mul(3, 7 << 32));
Expect.equals(0, mul(3 << 32, 7 << 32));
Expect.equals(0, mul(0, maxInt32));
Expect.equals(0, mul(maxInt32, 0));
Expect.equals(maxInt32, mul(1, maxInt32));
Expect.equals(maxInt32, mul(maxInt32, 1));
Expect.equals(maxInt32 + maxInt32, mul(2, maxInt32));
Expect.equals(0, mul(0, maxInt64));
Expect.equals(0, mul(maxInt64, 0));
Expect.equals(maxInt64, mul(1, maxInt64));
Expect.equals(maxInt64, mul(maxInt64, 1));
Expect.equals(-2, mul(2, maxInt64));
Expect.equals(0, mul(0, minInt32));
Expect.equals(0, mul(minInt32, 0));
Expect.equals(minInt32, mul(1, minInt32));
Expect.equals(minInt32, mul(minInt32, 1));
Expect.equals(minInt32 + minInt32, mul(2, minInt32));
Expect.equals(0, mul(0, minInt64));
Expect.equals(0, mul(minInt64, 0));
Expect.equals(minInt64, mul(1, minInt64));
Expect.equals(minInt64, mul(minInt64, 1));
Expect.equals(0, mul(2, minInt64));
Expect.equals(4611686014132420609, mul(maxInt32, maxInt32));
Expect.equals(-4611686016279904256, mul(maxInt32, minInt32));
Expect.equals(9223372034707292161, mul(maxInt32, maxInt64));
Expect.equals(minInt64, mul(maxInt32, minInt64));
Expect.equals(-4611686016279904256, mul(minInt32, maxInt32));
Expect.equals(4611686018427387904, mul(minInt32, minInt32));
Expect.equals(2147483648, mul(minInt32, maxInt64));
Expect.equals(0, mul(minInt32, minInt64));
Expect.equals(9223372034707292161, mul(maxInt64, maxInt32));
Expect.equals(2147483648, mul(maxInt64, minInt32));
Expect.equals(1, mul(maxInt64, maxInt64));
Expect.equals(minInt64, mul(maxInt64, minInt64));
Expect.equals(minInt64, mul(minInt64, maxInt32));
Expect.equals(0, mul(minInt64, minInt32));
Expect.equals(minInt64, mul(minInt64, maxInt64));
Expect.equals(0, mul(minInt64, minInt64));
}
doVars(int v) {
int e = v;
for (int i = 1; i < 256; i++) {
Expect.equals(e, mul(i, v));
Expect.equals(e, mul(v, i));
e += v;
}
}
main() {
// Repeat tests to enter JIT (when applicable).
for (int i = 0; i < 20; i++) {
doConstants();
doVars(1);
doVars(maxInt32);
doVars(minInt32);
doVars(7 << 32);
doVars(-(7 << 32));
doVars(maxInt64);
doVars(minInt64);
}
}
@@ -0,0 +1,47 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--no_background_compilation --optimization_counter_threshold=10
// VMOptions=--no_background_compilation --optimization_counter_threshold=10 --use_slow_path
import "package:expect/expect.dart";
// Tests for long negations under
// 64-bit arithmetic wrap-around semantics.
final int maxInt32 = 2147483647;
final int minInt32 = -2147483648;
final int maxInt64 = 0x7fffffffffffffff;
final int minInt64 = 0x8000000000000000;
int negate(int x) {
return -x;
}
doConstant() {
Expect.equals(1, negate(-1));
Expect.equals(0, negate(0));
Expect.equals(-1, negate(1));
Expect.equals(-maxInt32, negate(maxInt32));
Expect.equals(-minInt32, negate(minInt32));
Expect.equals(-maxInt64, negate(maxInt64));
Expect.equals(minInt64, negate(minInt64)); // sic!
}
doVar() {
int d = 0;
for (int i = -88; i < 10; i++) {
d += negate(i);
}
Expect.equals(3871, d);
}
main() {
// Repeat tests to enter JIT (when applicable).
for (int i = 0; i < 20; i++) {
doConstant();
doVar();
}
}
@@ -0,0 +1,40 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization-counter-threshold=100 --no-use-osr --no-background-compilation
import "package:expect/expect.dart";
// Test error message with misusing Functions and Closures: wrong args
// should result in a message that reports the missing method.
call_with_bar(x) => x("bar");
testClosureMessage() {
try {
call_with_bar(() {});
} catch (e) {
// The latter may happen if in --dwarf-stack-traces mode.
final possibleNames = ['testClosureMessage', '<optimized out>'];
Expect.containsAny(
possibleNames.map((s) => s + '.<anonymous closure>("bar")').toList(),
e.toString(),
);
}
}
noargs() {}
testFunctionMessage() {
try {
call_with_bar(noargs);
} catch (e) {
final expectedStrings = ['Tried calling: noargs("bar")'];
Expect.containsInOrder(expectedStrings, e.toString());
}
}
main() {
for (var i = 0; i < 120; i++) testClosureMessage();
for (var i = 0; i < 120; i++) testFunctionMessage();
}
@@ -0,0 +1,37 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization-counter-threshold=10 --no-use-osr --no-background-compilation
import "package:expect/expect.dart";
// Test error message with noSuchMethodError: nonexistent names
// should result in a message that reports the missing method.
class Callable {
call() {}
}
call_bar(x) => x.bar();
call_with_bar(x) => x("bar");
testMessageProp() {
try {
call_bar(new Callable());
} catch (e) {
Expect.isTrue(e.toString().contains("has no instance method 'bar'"));
}
}
testMessageCall() {
try {
call_with_bar(new Callable());
} catch (e) {
Expect.isTrue(e.toString().contains("has no instance method 'call'"));
}
}
main() {
for (var i = 0; i < 20; i++) testMessageProp();
for (var i = 0; i < 20; i++) testMessageCall();
}
@@ -0,0 +1,23 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization-counter-threshold=10 --no-use-osr --no-background-compilation
import "package:expect/expect.dart";
// Test error message with noSuchMethodError: nonexistent names
// should result in a message that reports the missing method.
call_bar(x) => x.bar();
testMessage() {
try {
call_bar(5);
} catch (e) {
Expect.isTrue(e.toString().contains("has no instance method 'bar'"));
}
}
main() {
for (var i = 0; i < 20; i++) testMessage();
}
@@ -0,0 +1,13 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that optimized Object.hashCode works for the null receiver.
// VMOptions=--optimization_counter_threshold=10 --no-background_compilation
main() {
for (int i = 0; i < 20; i++) {
foo(null);
}
}
foo(a) => a.hashCode;
@@ -0,0 +1,100 @@
// Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test various optimizations and deoptimizations of optimizing compiler..
// VMOptions=--optimization-counter-threshold=10 --no-use-osr --no-background-compilation
import "package:expect/expect.dart";
addThem(a, b) {
return a + b;
}
isItInt(a) {
return a is int;
}
doNeg(a) {
return -a;
}
doNeg2(a) {
return -a;
}
doNot(a) {
return !a;
}
doBitNot(a) {
return ~a;
}
doStore1(a, v) {
a[1] = v;
}
doStore2(a, v) {
a[2] = v;
}
class StringPlus {
const StringPlus(String this._val);
operator +(right) => new StringPlus("${_val}${right}");
toString() => _val;
final String _val;
}
main() {
for (int i = 0; i < 20; i++) {
Expect.stringEquals("HI 5", addThem(const StringPlus("HI "), 5).toString());
Expect.equals(true, isItInt(5));
}
Expect.equals(8, addThem(3, 5));
for (int i = 0; i < 20; i++) {
Expect.stringEquals("HI 5", addThem(const StringPlus("HI "), 5).toString());
Expect.equals(8, addThem(3, 5));
}
for (int i = -10; i < 10; i++) {
var r = doNeg(i);
var p = doNeg(r);
Expect.equals(i, p);
}
var maxSmi = (1 << 30) - 1;
Expect.equals(maxSmi, doNeg(doNeg(maxSmi)));
// Deoptimize because of overflow.
var minInt = -(1 << 30);
Expect.equals(minInt, doNeg(doNeg(minInt)));
for (int i = 0; i < 20; i++) {
Expect.equals(false, doNot(true));
Expect.equals(true, doNot(doNot(true)));
}
for (int i = 0; i < 20; i++) {
Expect.equals(-57, doBitNot(56));
Expect.equals(55, doBitNot(-56));
}
for (int i = 0; i < 20; i++) {
Expect.equals(-2.2, doNeg2(2.2));
}
// Deoptimize.
Expect.equals(-5, doNeg2(5));
var fixed = new List<dynamic>.filled(10, null);
var growable = [1, 2, 3, 4, 5];
for (int i = 0; i < 20; i++) {
doStore1(fixed, 7);
Expect.equals(7, fixed[1]);
doStore2(growable, 12);
Expect.equals(12, growable[2]);
}
// Deoptimize.
doStore1(growable, 8);
Expect.equals(8, growable[1]);
doStore2(fixed, 101);
Expect.equals(101, fixed[2]);
}
@@ -0,0 +1,33 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization-counter-threshold=10 --no-background-compilation
// This tests that captured parameters (by the async-closure) are
// correctly treated in try-catch generated in the async function.
// They must be skipped when generating sync-code in the optimized
// try-block.
import 'package:expect/expect.dart';
import 'dart:async';
fail() {
try {
Expect.isTrue(false);
} finally {}
}
foo(i) async {
var k = await 77;
var a = "abc${k}";
if (a != "abc77") fail();
return k;
}
main() {
for (int i = 0; i < 20; i++) {
foo(i).then((value) => Expect.equals(77, value));
}
}
@@ -0,0 +1,99 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization-counter-threshold=10 --no-use-osr --no-background-compilation
import "package:expect/expect.dart";
// Test dense class-id checks. Regression test for issue 22104.
class A {
toString() => "an A";
}
class A1 extends A {}
class A2 extends A {}
class A3 extends A {}
class A4 extends A {
toString() => "ha";
}
class A5 extends A {}
class A6 extends A {}
class A7 extends A {}
class A8 extends A {}
class A9 extends A {}
class A10 extends A {}
class A11 extends A {}
class A12 extends A {}
class A13 extends A {}
class A14 extends A {}
class A15 extends A {}
class A16 extends A {}
class A17 extends A {}
class A18 extends A {}
class A19 extends A {}
class A20 extends A {}
class A21 extends A {}
class A22 extends A {}
class A23 extends A {}
class A24 extends A {}
class A25 extends A {}
class A26 extends A {}
class A27 extends A {}
class A28 extends A {}
class A29 extends A {}
class A30 extends A {}
class A31 extends A {}
class A32 extends A {}
class A33 extends A {}
class A34 extends A {}
class A35 extends A {}
class A36 extends A {}
test_class_check(e) => e.toString();
main() {
var list = [new A1(), new A2(), new A11(), new A36()];
for (var i = 0; i < list.length; i++) {
test_class_check(list[i]);
}
for (var i = 0; i < 100; i++) {
Expect.equals("an A", test_class_check(new A1()));
}
Expect.equals("ha", test_class_check(new A4()));
}
@@ -0,0 +1,80 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization_counter_threshold=100 --no-background_compilation
// Test field type tracking and field list-length tracking in the presence of
// multiple isolates.
import "dart:isolate";
import "dart:async";
import 'package:expect/async_helper.dart';
import "package:expect/expect.dart";
class A {
A(this.a);
var a;
}
class B extends A {
B(a, this.b) : super(a) {}
var b;
}
f1(Object send_port) {
(send_port as SendPort).send(new B("foo", "bar"));
}
test_b(B obj) => obj.a + obj.b;
test_field_type() {
var receive_port = new ReceivePort();
asyncStart();
Future<Isolate> isolate = Isolate.spawn(f1, receive_port.sendPort);
B b = new B(1, 2);
for (var i = 0; i < 200; i++) {
test_b(b);
}
Expect.equals(3, test_b(b));
Future item = receive_port.first;
item.then((value) {
Expect.equals("foobar", test_b(value as B));
receive_port.close();
asyncEnd();
});
}
class C {
C(this.list);
final List list;
}
f2(Object send_port) {
(send_port as SendPort).send(new C(new List.filled(1, null)));
}
test_c(C obj) => obj.list[9999];
test_list_length() {
var receive_port = new ReceivePort();
asyncStart();
Future<Isolate> isolate = Isolate.spawn(f2, receive_port.sendPort);
C c = new C(new List.filled(10000, null));
for (var i = 0; i < 200; i++) {
test_c(c);
}
Expect.equals(null, test_c(c));
Future item = receive_port.first;
item.then((value) {
Expect.throwsRangeError(() => test_c(value as C));
receive_port.close();
asyncEnd();
});
}
main() {
test_field_type();
test_list_length();
}
@@ -0,0 +1,100 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test correct handling of phis with only environment uses that were inserted
// by store to load forwarding.
// VMOptions=--optimization_counter_threshold=10 --no-background_compilation
import "package:expect/expect.dart";
import "dart:typed_data";
class A {
var foo;
}
class B {
get foo => null;
}
test(obj) => obj.foo == null ? "null" : "other";
class C {
C(this.x, this.y);
final x;
final y;
}
test_deopt(a, b) {
var c = new C(a, b);
return c.x + c.y;
}
create_error(x) {
return x as int;
}
check_stacktrace(e) {
var s = e.stackTrace;
if (identical(s, null)) throw "FAIL";
// s should never be null.
return "OK";
}
test_stacktrace() {
try {
create_error("bar");
} catch (e) {
Expect.equals("OK", check_stacktrace(e));
for (var i = 0; i < 20; i++) {
check_stacktrace(e);
}
Expect.equals("OK", check_stacktrace(e));
}
}
class D {
final List f;
final Uint8List g;
D(this.f, this.g);
D.named(this.f, this.g);
}
test_guarded_length() {
var a = new D(new List.filled(5, null), new Uint8List(5));
var b = new D.named(new List.filled(5, null), new Uint8List(5));
Expect.equals(5, a.f.length);
Expect.equals(5, b.f.length);
Expect.equals(5, a.g.length);
Expect.equals(5, b.g.length);
}
main() {
var a = new A();
var b = new B();
// Trigger optimization of test with a polymorphic load.
// The guarded type of foo is null.
test(a);
test(b);
for (var i = 0; i < 20; ++i) test(a);
Expect.equals("null", test(a));
Expect.equals("null", test(b));
// Store a non-null object into foo to trigger deoptimization of test.
a.foo = 123;
Expect.equals("other", test(a));
Expect.equals("null", test(b));
// Test guarded fields with allocation sinking and deoptimization.
Expect.equals(43, test_deopt(42, 1));
for (var i = 0; i < 20; i++) {
test_deopt(42, 1);
}
Expect.equals(43, test_deopt(42, 1));
Expect.equals("aaabbb", test_deopt("aaa", "bbb"));
// Regression test for fields initialized in native code (Error._stackTrace).
test_stacktrace();
// Test guarded list length.
for (var i = 0; i < 20; i++) test_guarded_length();
}
@@ -0,0 +1,32 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test various optimizations and deoptimizations of optimizing compiler..
// VMOptions=--optimization-counter-threshold=10 --no-constant-propagation --no-background-compilation
import "package:expect/expect.dart";
// Test canonicalization of identical with double input.
// Constant propagation is disabled so that canonicalization is run
// one time less than usual.
test(a) {
var dbl = a + 1.0;
if (!identical(dbl, true)) {
return "ok";
}
throw "fail";
}
Object Y = 1.0;
test_object_type(x) => identical(x, Y);
main() {
for (var i = 0; i < 20; i++) test(0);
Expect.equals("ok", test(0));
var x = 0.0 + 1.0;
for (var i = 0; i < 20; i++) test_object_type(x);
Expect.equals(true, test_object_type(x));
}
@@ -0,0 +1,25 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test various optimizations and deoptimizations of optimizing compiler..
// VMOptions=--optimization-counter-threshold=10 --no-background-compilation
import "package:expect/expect.dart";
// Test correct throwing of ArgumentError in optimized code.
test() {
try {
var r = new List<int>.filled(-1, 0);
Expect.isTrue(false); // Unreachable.
} on RangeError {
return true;
}
Expect.isTrue(false); // Unreachable.
}
main() {
for (var i = 0; i < 20; i++) {
Expect.isTrue(test());
}
}
@@ -0,0 +1,27 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization_counter_threshold=10 --no-background_compilation
import "package:expect/expect.dart";
// Test correct polymorphic inlining of recognized methods like list access.
test(arr) {
var r = 0;
for (var i = 0; i < 1; ++i) {
r += arr[0] as int;
}
return r;
}
main() {
var a = new List<int?>.filled(1, null);
a[0] = 0;
var b = <int>[0];
Expect.equals(0, test(a));
Expect.equals(0, test(b));
for (var i = 0; i < 20; ++i) test(a);
Expect.equals(0, test(a));
Expect.equals(0, test(b));
}
@@ -0,0 +1,19 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization-counter-threshold=10 --no-background-compilation
import "package:expect/expect.dart";
// Test truncating left-shift that can deoptimize.
// Regression test for issue 19330.
test_shl(w, x) {
x += 1;
return w << x & 0xff;
}
main() {
for (var i = 0; i < 20; i++) test_shl(i, i % 10);
Expect.equals(4, test_shl(1, 1));
}
@@ -0,0 +1,40 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--stacktrace-every=3 --optimization-counter-threshold=10 --no-background-compilation
// Test generating stacktraces with inlining and deferred code.
// Regression test for issue dartbug.com/22331
class A {
final N;
final inc;
var next;
A(this.N, this.inc) {
next = this;
}
}
foo(o, value) {
for (var i = 0; i < o.N; i += o.inc as int) {
if (value < i) {
throw "";
}
o = o.next;
}
return value;
}
@pragma('vm:never-inline')
baz(x, y, z) => z;
bar(o) {
var value = 0x100000000 + o.inc;
baz(0, 0, foo(o, value));
}
main() {
var o = new A(10, 1);
for (var i = 0; i < 100; i++) bar(o);
bar(new A(100000, 1));
}
@@ -0,0 +1,55 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization_counter_threshold=10 --no-background_compilation
// Test branch optimization for TestSmiInstr
import "package:expect/expect.dart";
test1(a, bool b) {
if (b) {
a++;
} else {
a += 2;
}
if (a & 1 == 0) {
return "even";
}
return "odd";
}
test2(a, bool b) {
if (b) {
a++;
} else {
a += 2;
}
if (a & 1 == 1) {
return "odd";
}
return "even";
}
test3(a, bool b) {
return test1(0, b);
}
test4(a, bool b) {
return test2(0, b);
}
run(test) {
Expect.equals("odd", test(0, true));
Expect.equals("even", test(0, false));
for (var i = 0; i < 20; i++) test(0, false);
Expect.equals("odd", test(0, true));
Expect.equals("even", test(0, false));
}
main() {
run(test1);
run(test2);
run(test3);
run(test4);
}
@@ -0,0 +1,39 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization_counter_threshold=100 --no-use-osr --no-background_compilation
// Test CHA-based optimizations in presence of try-catch.
import "package:expect/expect.dart";
bar(i) {
if (i == 11) throw 123;
}
class A {
var f = 42;
foo(i) {
do {
try {
bar(i);
} catch (e, s) {
Expect.equals(123, e);
}
} while (i < 0);
return f;
}
}
class B extends A {}
main() {
var result;
for (var i = 0; i < 200; i++) {
try {
result = new B().foo(i);
} catch (e) {}
}
Expect.equals(42, result);
}
@@ -0,0 +1,44 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
class A {
_uniqueSelector() {}
final uniqueField = 10;
}
test1(obj) {
var res = 0;
for (var i = 0; i < 2; i++) {
obj._uniqueSelector();
// This load must not be hoisted out of the loop.
res += obj.uniqueField as int;
}
return res;
}
test2(obj) {
final objAlias = obj;
closure() => objAlias;
var res = 0;
for (var i = 0; i < 2; i++) {
obj._uniqueSelector();
// This load must not be hoisted out of the loop.
res += objAlias.uniqueField as int;
}
return res;
}
var foofoo_ = test1;
main() {
Expect.equals(20, foofoo_(new A()));
Expect.throws(() => foofoo_(0));
foofoo_ = test2;
Expect.equals(20, foofoo_(new A()));
Expect.throws(() => foofoo_(0));
}
@@ -0,0 +1,155 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test with OSR on non-empty stack (block expression).
import 'dart:core';
import "package:expect/expect.dart";
class Z {
@pragma('vm:never-inline')
check(int a, int b, String c, List<int> d) {
Expect.equals(a, 42);
Expect.equals(b, global_bazz);
Expect.equals(c, 'abc');
return d;
}
}
Z z = new Z();
int global_bazz = 123;
int global_more_bazz = 456;
@pragma('vm:never-inline')
int bazz() {
return ++global_bazz;
}
@pragma('vm:never-inline')
int more_bazz() {
return ++global_more_bazz;
}
@pragma('vm:never-inline')
int bar(int i) {
return i - 1;
}
@pragma('vm:never-inline')
List<int> spread(int v, List<int> x) {
return [v, ...x];
}
// Long running control-flow collection (block expression),
// leaves the stack non-empty during a potential OSR.
@pragma('vm:never-inline')
List<int> test1(int n) {
return spread(more_bazz(), [for (int i = 0; i < n; i++) i]);
}
// Long running control-flow collection (block expression) inside outer
// loop, leaves the stack non-empty during a potential OSR.
List<int> test2(int n) {
List<int> x = [];
for (int k = 0; k < 10; k++) {
x += spread(more_bazz(), [for (int i = 0; i < n; i++) i]);
}
return x;
}
// Long running control-flow collection (block expression) inside two
// outer loops, leaves the stack non-empty during a potential OSR.
List<int> test3(int n) {
List<int> x = [];
for (int k = 0; k < 4; k++) {
for (int j = 0; j < 4; j++) {
x += spread(more_bazz(), [for (int i = 0; i < n; i++) i]);
}
}
return x;
}
// Long running control-flow collection (block expression),
// leaves the stack non-empty during a potential OSR.
@pragma('vm:never-inline')
List<int> test4(int n) {
var x =
[10] +
z.check(42, bazz(), 'abc', [
more_bazz(),
for (int i = 0; i < n; i++) bar(2 * i),
]);
return x;
}
// Long running control-flow collection (block expression) inside outer
// loop, also leaves the stack non-empty during a potential OSR.
@pragma('vm:never-inline')
List<int> test5(int m, int n) {
List<int> x = [];
for (int k = 0; k < m; k++) {
x +=
[10] +
z.check(42, bazz(), 'abc', [
more_bazz(),
for (int i = 0; i < n; i++) bar(2 * i),
]);
}
return x;
}
List<int> globalList = [
1,
for (int loc1 = 2; loc1 <= 100000; loc1++) loc1,
100001,
];
main() {
int n = 20000;
int g = 457;
var a = test1(n);
Expect.equals(a.length, n + 1);
for (int k = 0; k < n + 1; k++) {
int expect = (k == 0) ? g++ : k - 1;
Expect.equals(a[k], expect);
}
var b = test2(n);
Expect.equals(b.length, 10 * (n + 1));
for (int i = 0, k = 0; i < 10 * (n + 1); i++) {
int expect = (k == 0) ? g++ : k - 1;
Expect.equals(b[i], expect);
if (++k == (n + 1)) k = 0;
}
var c = test3(n);
Expect.equals(c.length, 16 * (n + 1));
for (int i = 0, k = 0; i < 16 * (n + 1); i++) {
int expect = (k == 0) ? g++ : k - 1;
Expect.equals(c[i], expect);
if (++k == (n + 1)) k = 0;
}
var d = test4(n);
Expect.equals(d.length, n + 2);
for (int k = 0; k < n + 2; k++) {
int expect = k <= 1 ? ((k == 0) ? 10 : g++) : -5 + 2 * k;
Expect.equals(d[k], expect);
}
var e = test5(10, n);
Expect.equals(e.length, 10 * (n + 2));
for (int i = 0, k = 0; i < 10 * (n + 2); i++) {
int expect = k <= 1 ? ((k == 0) ? 10 : g++) : -5 + 2 * k;
Expect.equals(e[i], expect);
if (++k == (n + 2)) k = 0;
}
Expect.isTrue(globalList != null);
Expect.equals(100001, globalList.length);
for (int i = 0; i < globalList.length; i++) {
Expect.equals(globalList[i], i + 1);
}
}
+57
View File
@@ -0,0 +1,57 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--deterministic
import "package:expect/expect.dart";
@pragma("vm:never-inline")
foo(List<int?> x) => x[1]! + x[0]!;
@pragma("vm:never-inline")
bar(List<int?> x) => 1 + x[0]!;
@pragma("vm:never-inline")
baz(List<int?> x) => x[0]! + 2;
main() {
var x = new List<int?>.filled(2, null);
// Only first is null.
x[0] = null;
x[1] = 123;
try {
foo(x);
} on TypeError catch (e) {
;
}
try {
bar(x);
} on TypeError catch (e) {
;
}
try {
baz(x);
} on TypeError catch (e) {
;
}
// Only second is null.
x[0] = 456;
x[1] = null;
try {
foo(x);
} on TypeError catch (e) {
;
}
Expect.equals(457, bar(x));
Expect.equals(458, baz(x));
// Neither is null.
x[0] = 789;
x[1] = -1;
Expect.equals(788, foo(x));
Expect.equals(790, bar(x));
Expect.equals(791, baz(x));
}
@@ -0,0 +1,191 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
import 'dart:math';
final int maxInt32 = 2147483647;
final int minInt32 = -2147483648;
doZeros() {
Expect.equals(1, pow(0, 0));
Expect.equals(0, pow(0, 1));
Expect.equals(0, pow(0, 2));
Expect.equals(0, pow(0, 3));
Expect.equals(0, pow(0, 4));
Expect.equals(0, pow(0, 5));
Expect.equals(0, pow(0, 45));
Expect.equals(0, pow(0, maxInt32 - 1));
Expect.equals(0, pow(0, maxInt32));
Expect.equals(double.infinity, pow(0, -1));
Expect.equals(double.infinity, pow(0, -2));
Expect.equals(double.infinity, pow(0, minInt32));
}
doOnes() {
Expect.equals(1, pow(1, 0));
Expect.equals(1, pow(1, 1));
Expect.equals(1, pow(1, 2));
Expect.equals(1, pow(1, 3));
Expect.equals(1, pow(1, 4));
Expect.equals(1, pow(1, 5));
Expect.equals(1, pow(1, 45));
Expect.equals(1, pow(1, maxInt32 - 1));
Expect.equals(1, pow(1, maxInt32));
Expect.equals(1.0, pow(1, -1));
Expect.equals(1.0, pow(1, -2));
Expect.equals(1.0, pow(1, minInt32));
}
doMinOnes() {
Expect.equals(1, pow(-1, 0));
Expect.equals(-1, pow(-1, 1));
Expect.equals(1, pow(-1, 2));
Expect.equals(-1, pow(-1, 3));
Expect.equals(1, pow(-1, 4));
Expect.equals(-1, pow(-1, 5));
Expect.equals(-1, pow(-1, 45));
Expect.equals(1, pow(-1, maxInt32 - 1));
Expect.equals(-1, pow(-1, maxInt32));
Expect.equals(-1.0, pow(-1, -1));
Expect.equals(1.0, pow(-1, -2));
Expect.equals(1.0, pow(-1, minInt32));
}
doTwos() {
Expect.equals(1, pow(2, 0));
Expect.equals(2, pow(2, 1));
Expect.equals(4, pow(2, 2));
Expect.equals(8, pow(2, 3));
Expect.equals(16, pow(2, 4));
Expect.equals(32, pow(2, 5));
Expect.equals(32768, pow(2, 15));
Expect.equals(65536, pow(2, 16));
Expect.equals(35184372088832, pow(2, 45));
Expect.equals(0, pow(2, maxInt32 - 1));
Expect.equals(0, pow(2, maxInt32));
Expect.equals(0.5, pow(2, -1));
Expect.equals(0.25, pow(2, -2));
Expect.equals(0.0, pow(2, minInt32));
}
doMinTwos() {
Expect.equals(1, pow(-2, 0));
Expect.equals(-2, pow(-2, 1));
Expect.equals(4, pow(-2, 2));
Expect.equals(-8, pow(-2, 3));
Expect.equals(16, pow(-2, 4));
Expect.equals(-32, pow(-2, 5));
Expect.equals(-32768, pow(-2, 15));
Expect.equals(65536, pow(-2, 16));
Expect.equals(-35184372088832, pow(-2, 45));
Expect.equals(0, pow(-2, maxInt32 - 1));
Expect.equals(0, pow(-2, maxInt32));
Expect.equals(-0.5, pow(-2, -1));
Expect.equals(0.25, pow(-2, -2));
Expect.equals(0.0, pow(-2, minInt32));
}
doVar0() {
int d = 0;
for (int i = -10; i < 10; i++) {
d += pow(i, 0) as int;
}
Expect.equals(20, d);
}
doVar1() {
int d = 0;
for (int i = -10; i < 10; i++) {
d += pow(i, 1) as int;
}
Expect.equals(-10, d);
}
doVar2() {
int d = 0;
for (int i = -10; i < 10; i++) {
d += pow(i, 2) as int;
}
Expect.equals(670, d);
}
doVar3() {
int d = 0;
for (int i = -10; i < 10; i++) {
d += pow(i, 3) as int;
}
Expect.equals(-1000, d);
}
doVar4() {
int d = 0;
for (int i = -10; i < 10; i++) {
d += pow(i, 4) as int;
}
Expect.equals(40666, d);
}
doVar5() {
int d = 0;
for (int i = -10; i < 10; i++) {
d += pow(i, 5) as int;
}
Expect.equals(-100000, d);
}
doVarMax() {
int d = 0;
for (int i = -5; i < 10; i++) {
d += pow(i, maxInt32) as int;
}
Expect.equals(1786231423019973616, d);
}
doVarZeroes() {
int d = 0;
for (int i = 0; i < 10; i++) {
d += pow(0, i) as int;
}
Expect.equals(1, d);
}
doVarOnes() {
int d = 0;
for (int i = 0; i < 10; i++) {
d += pow(1, i) as int;
}
Expect.equals(10, d);
}
doVarTwos() {
int d = 0;
for (int i = 0; i < 10; i++) {
d += pow(2, i) as int;
}
Expect.equals(1023, d);
}
main() {
doZeros();
doOnes();
doMinOnes();
doTwos();
doMinTwos();
doVar0();
doVar1();
doVar2();
doVar3();
doVar4();
doVar5();
doVarMax();
doVarZeroes();
doVarOnes();
doVarTwos();
}
@@ -0,0 +1,19 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test optimizations with static fields with precompilation.
// VMOptions=--inlining-hotness=0
import 'package:expect/expect.dart';
init() => 123;
final a = init();
main() {
var s = 0;
for (var i = 0; i < 10; i++) {
s += a as int;
}
Expect.equals(10 * 123, s);
}
@@ -0,0 +1,29 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization-counter-threshold=10 --no-background-compilation
import "package:expect/expect.dart";
// Test identical comparisons in optimized code. Registers must be preserved
// when calling the runtime.
cmp(a, b, c) {
var v = c + 1;
var w = v + 1;
var x = w + 1;
var y = x + 1;
var z = y + 1;
if (identical(a, b)) {
c++;
}
return c + v + w + x + y + z;
}
main() {
var str = "abc";
var before = cmp(str, str, 0);
Expect.equals(16, before);
for (var i = 0; i < 20; i++) cmp(str, str, 0);
Expect.equals(before, cmp(str, str, 0));
}
@@ -0,0 +1,22 @@
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--new_gen_semi_max_size=1 --no_inline_alloc
// Regression test for slow-path allocation in the allocation stub.
library map_test;
import 'dart:collection';
void testCollection(collection, n) {
for (int i = 0; i < n; i++) {
if (i % 1000 == 0) print(i);
collection.add(i);
}
}
main() {
const int N = 100000;
testCollection(new LinkedHashSet(), N);
}
@@ -0,0 +1,22 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization_counter_threshold=10 --no-use-osr --no-background_compilation
test(a) {
var e;
for (var i = 0; i < a.length; i++) {
e = a[i];
for (var j = 0; j < i; j++) {
e = a[j];
}
}
return e;
}
main() {
var a = [0, 1, 2, 3, 4, 5];
for (var i = 0; i < 20; i++) {
test(a);
}
}
@@ -0,0 +1,19 @@
// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization_counter_threshold=10 --no-background_compilation
import 'package:expect/expect.dart';
test(j) {
var result = true;
j++;
for (var i = 0; i < 100; i++) {
result = (i < 50 || j < (1 << 32)) && result;
}
return result;
}
main() {
Expect.isTrue(test(30));
}
@@ -0,0 +1,22 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test range inference for multiplication of two negative values.
// VMOptions=--optimization-counter-threshold=10 --no-use-osr --no-background-compilation
import 'package:expect/expect.dart';
test(a) {
var x = a ? -1 : -2;
if (0 < (x * x)) {
return "ok";
} else {
return "fail";
}
}
main() {
for (var j = 0; j < 20; j++) {
Expect.equals("ok", test(false));
}
}
@@ -0,0 +1,10 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test that BoxAllocationSlowPath for Mint emits stackmap in unoptimized code.
// VMOptions=--inline_alloc=false
main() {
var re = new RegExp(r"IsolateStubs (.*)");
return re.firstMatch("oooo");
}
@@ -0,0 +1,13 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test location summary for Uint32 multiplication.
// VMOptions=--optimization-counter-threshold=10 --no-use-osr --no-background-compilation
const MASK = 0xFFFFFFFF;
uint32Mul(x, y) => (x * y) & MASK;
main() {
for (var i = 0; i < 20; i++) uint32Mul((1 << 63) - 1, 1);
}
@@ -0,0 +1,21 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test location summary for Uint32 multiplication.
// VMOptions=--optimization-counter-threshold=20 --no-background-compilation
import 'package:expect/expect.dart';
mintLeftShift(x, y) => x << y;
mintRightShift(x, y) => x >> y;
main() {
for (var i = 0; i < 25; i++) {
var x = 1 + (1 << (i + 32));
Expect.equals(x, mintLeftShift(x, 0));
Expect.equals(x, mintRightShift(x, 0));
Expect.equals(2 * x, mintLeftShift(x, 1));
Expect.equals(x ~/ 2, mintRightShift(x, 1));
Expect.equals((i >= 16) ? 1 : x, mintRightShift(mintLeftShift(x, i), i));
}
}
@@ -0,0 +1,20 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import "package:expect/expect.dart";
void main() {
int x = 327680;
int r = 65536;
for (var i = 0; i < 200; i++) {
Expect.equals(r, x ~/ 5);
x *= 10;
r *= 10;
if (x < 0) {
// Overflow.
break;
}
}
}
@@ -0,0 +1,16 @@
// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--no-intrinsify
// Test that math runtime function (non-intrinsified) produce the expected
// result and don't deviate due to double-rounding when using 80-bit FP ops.
import "dart:math";
import "package:expect/expect.dart";
main() {
var x = 2.028240960366921e+31;
Expect.equals(4503599627372443.0, sqrt(x));
}
@@ -0,0 +1,10 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'regress_27671_test.dart';
@pragma('vm:prefer-inline')
void check(f, x) {
assert(f(x) && true);
}
@@ -0,0 +1,29 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
//
// VMOptions=--enable_asserts --optimization-counter-threshold=10 --no-background-compilation
import 'package:expect/expect.dart';
import 'regress_27671_other.dart';
@pragma('vm:prefer-inline')
bounce(x) {
for (int i = 0; i < 10; i++) {
check(f, x);
}
}
@pragma('vm:prefer-inline')
bool f(y) => y > 0;
main() {
for (int i = 0; i < 100; i++) {
bounce(1);
}
try {
bounce(-1);
} catch (e) {
Expect.isTrue(e.toString().contains('f(x) && true'));
}
}
@@ -0,0 +1,36 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
//
// Check that optimizer correctly handles (x << y) & MASK_32 pattern on 32-bit
// platforms: given the pattern
//
// v1 <- UnboxedIntConverter([tr] mint->uint32, v0)
// v2 <- UnboxedIntConverter(uint32->mint, v1)
//
// optimizer must *not* replace v2 with v0 because the first conversion is
// truncating and is erasing the high part of the mint value.
//
// VMOptions=--optimization-counter-threshold=90 --no-background-compilation
import "package:expect/expect.dart";
const _MASK_32 = 0xffffffff;
int _rotl32(int val, int shift) {
final mod_shift = shift & 31;
return ((val << mod_shift) & _MASK_32) |
((val & _MASK_32) >> (32 - mod_shift));
}
rot8(v) => _rotl32(v, 8);
main() {
// Note: value is selected in such a way that (value << 8) is not a smi - this
// triggers emission of BinaryMintOp instructions for shifts.
const value = 0xF0F00000;
const rotated = 0xF00000F0;
Expect.equals(rotated, rot8(value));
for (var i = 0; i < 100; i++) {
Expect.equals(rotated, rot8(value));
}
}
@@ -0,0 +1,30 @@
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--optimization-counter-threshold=-1 --stacktrace-filter=completeError --stress-async-stacks
// Stress test for async stack traces.
import 'dart:async';
import "package:expect/expect.dart";
class A {
Future<List<int>> read() => new Future.error(123);
}
Future<A> haha() => new Future.microtask(() => new A());
Future<List<int>> mm() async => (await haha()).read();
foo() async => await mm();
main() async {
var x;
try {
x = await foo();
} catch (e) {
Expect.equals(123, e);
return;
}
Expect.isTrue(false);
}
@@ -0,0 +1,32 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// VMOptions=--no_background_compilation --optimization_counter_threshold=10
import 'dart:async';
import 'package:expect/expect.dart';
var root = [];
var tests = <dynamic>[
() async {},
() async {
await new Future.value();
root.singleWhere((f) => f.name == 'optimizedFunction');
},
];
main(args) async {
for (int i = 0; i < 100; ++i) {
int exceptions = 0;
for (final test in tests) {
try {
await test();
} on StateError {
exceptions++;
}
}
Expect.isTrue(exceptions == 1);
}
}
@@ -0,0 +1,41 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Verify that local functions capture `this` if their arguments refer to
// type parameters from the enclosing class.
import "package:expect/expect.dart";
typedef void B<T>(T v);
class MyFisk {}
class MyHest {}
class A<T> {
var value;
A(B<T> x) {
// This function does not capture `this` explicitly, however it needs
// to capture it in order to access T. Verify that we do it correctly.
// If `this` is not captured then foo turns into (B<dynamic>) -> Null
// which means that foo(x) would throw if T != dynamic.
f(B<T> v) {}
f(x);
}
foo<U>(B<T> x, B<U> y) {
// This function does not capture `this` explicitly, verify that it still
// can access `T`.
f(B<T> v, B<U> y) {}
f(x, y);
}
}
void main() {
new A<MyFisk>((MyFisk v) {});
new A<MyFisk>((MyFisk v) {}).foo<MyHest>((MyFisk v) {}, (MyHest v) {});
}
@@ -0,0 +1,32 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Verify that optimizing compiler does not perform an illegal code motion
// past CheckNull instruction.
import "package:expect/expect.dart";
class C {
final String padding = "";
final String field = "1"; // Note: need padding to hit an object header
// of the next object after [null] object when
// doing illegal null.field read. Need to hit
// object header to cause crash.
}
int foofoo(C? p) {
int sum = 0;
for (var i = 0; i < 10; i++) {
// Note: need redundant instructions in the loop to trigger Canonicalize
// after CSE. Canonicalize then would illegally remove the Redefinition.
sum += p!.field.length;
sum += p.field.length;
}
return sum;
}
void main() {
Expect.equals(20, foofoo(new C()));
Expect.throwsTypeError(() => foofoo(null));
}
@@ -0,0 +1,29 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Verify that VM does not omit type checks from closure prologues.
import "package:expect/expect.dart";
void invoke(dynamic f, dynamic arg) {
f(arg);
}
void main() {
dynamic x = 42;
foo(int v) {
x = v;
}
bar<T>() {
return (T v) {
x = v;
};
}
Expect.throwsTypeError(() => invoke(foo, "hello"));
Expect.throwsTypeError(() => invoke(bar<int>(), "hello"));
Expect.equals(42, x);
}
@@ -0,0 +1,38 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart=2.19
// Test verifying that default switch cast is cloned correctly by the
// mixin transformation.
import "package:expect/expect.dart";
void main() {
final o = new A();
Expect.isTrue(o.f());
Expect.isTrue(o.g());
}
class A extends B with M {}
class B {
bool f() {
switch (true) {
default:
return true;
}
return false;
}
}
class M {
bool g() {
switch (true) {
default:
return true;
}
return false;
}
}
@@ -0,0 +1,36 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Test verifying that default switch cast is cloned correctly by the
// mixin transformation.
import "package:expect/expect.dart";
void main() {
final o = new A();
Expect.isTrue(o.f());
Expect.isTrue(o.g());
}
class A extends B with M {}
class B {
bool f() {
switch (true) {
default:
return true;
}
return false;
}
}
mixin M {
bool g() {
switch (true) {
default:
return true;
}
return false;
}
}
@@ -0,0 +1,18 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Verify that VM correctly handles function type arguments across
// yield points.
import "package:expect/expect.dart";
void main() {
doStuff<String>();
}
doStuff<T>() async {
Expect.equals(String, T);
await null;
Expect.equals(String, T);
}
@@ -0,0 +1,38 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart=2.19
//
// Exact regression test for issue #33040.
import 'dart:async';
class Optional<T> {}
typedef T? ConvertFunction<T>();
T? blockingLatest<T>() {
return null;
}
abstract class ObservableModel<T> {}
abstract class AsyncValueMixin<T> {
Future<T>? get asyncValue {
ConvertFunction<T> f = blockingLatest;
if (f is! ConvertFunction<T>) throw "error";
return null;
}
}
abstract class OptionalSettableObservableModel<T>
extends ObservableModel<Optional<T>> with AsyncValueMixin<Optional<T>> {}
class FooObservableModel extends OptionalSettableObservableModel<int> {}
Future<void> main() async {
var model = new FooObservableModel();
await model.asyncValue;
}
@@ -0,0 +1,36 @@
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Exact regression test for issue #33040.
// @dart=2.19
import 'dart:async';
class Optional<T> {}
typedef T? ConvertFunction<T>();
T? blockingLatest<T>() {
return null;
}
abstract class ObservableModel<T> {}
abstract class AsyncValueMixin<T> {
Future<T>? get asyncValue {
ConvertFunction<T> f = blockingLatest;
if (f is! ConvertFunction<T>) throw "error";
return null;
}
}
abstract class OptionalSettableObservableModel<T>
extends ObservableModel<Optional<T>> with AsyncValueMixin<Optional<T>> {}
class FooObservableModel extends OptionalSettableObservableModel<int> {}
Future<void> main() async {
var model = new FooObservableModel();
await model.asyncValue;
}

Some files were not shown because too many files have changed in this diff Show More