Migrated test block 165 to Dart 2.0.

Minor changes to a couple of tests to make them strong-mode clean.

Bug:
Change-Id: Id0cac7a120dbdf940d101c3e5de8c206a0ad6342
Reviewed-on: https://dart-review.googlesource.com/4613
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
This commit is contained in:
Ben Konyi 2017-09-21 19:00:36 +00:00 committed by commit-bot@chromium.org
parent edee53f93d
commit a87493f8ca
52 changed files with 2037 additions and 8 deletions

View file

@ -40,6 +40,8 @@ deferred_mixin_test: Crash # Requires deferred libraries
issue21159_test: Pass, Crash # Issue 29094
issue_22780_test/01: Pass, Crash # Issue 29094
issue_1751477_test: Crash # Requires deferred libraries
vm/regress_27201_test: Pass, Crash # Requires deferred libraries
vm/optimized_stacktrace_test: Pass, Slow
[ ! $checked && ! $strong ]
closure_type_test: RuntimeError
@ -68,6 +70,26 @@ is_not_class2_test/01: MissingCompileTimeError # Requires strong mode
isnot_malformed_type_test/01: MissingCompileTimeError
issue11724_test/01: MissingCompileTimeError
void_block_return_test/00: MissingCompileTimeError # Requires strong mode
vm/type_vm_test/01: MissingCompileTimeError
vm/type_vm_test/02: MissingCompileTimeError
vm/type_vm_test/03: MissingCompileTimeError
vm/type_vm_test/04: MissingCompileTimeError
vm/type_vm_test/05: MissingCompileTimeError
vm/type_vm_test/06: MissingCompileTimeError
vm/type_vm_test/08: MissingCompileTimeError
vm/type_vm_test/09: MissingCompileTimeError
vm/type_vm_test/10: MissingCompileTimeError
vm/type_vm_test/11: MissingCompileTimeError
vm/type_vm_test/12: MissingCompileTimeError
vm/type_vm_test/13: MissingCompileTimeError
vm/type_vm_test/14: MissingCompileTimeError
vm/type_vm_test/15: MissingCompileTimeError
vm/type_vm_test/16: MissingCompileTimeError
vm/type_vm_test/22: MissingCompileTimeError
vm/type_vm_test/24: MissingCompileTimeError
vm/type_vm_test/25: MissingCompileTimeError
vm/type_vm_test/26: MissingCompileTimeError
vm/type_vm_test/27: MissingCompileTimeError
void_type_callbacks_test: Skip # Requires strong mode
void_type_function_types_test: Skip # Requires strong mode
void_type_override_test: Skip # Requires strong mode

View file

@ -402,6 +402,8 @@ vm/debug_break_enabled_vm_test: Skip
vm/debug_break_vm_test/*: Skip
is_not_class1_negative_test: CompileTimeError
is_not_class4_negative_test: CompileTimeError
inst_field_initializer1_negative_test: CompileTimeError
vm/reflect_core_vm_test: CompileTimeError
[ $strong && $compiler == dart2analyzer ]
accessor_conflict_export2_test: CompileTimeError # Issue 25626
@ -627,6 +629,7 @@ unresolved_default_constructor_test/01: MissingCompileTimeError
unresolved_in_factory_test: MissingCompileTimeError
unresolved_top_level_method_test: MissingCompileTimeError
unresolved_top_level_var_test: MissingCompileTimeError
vm/type_vm_test: StaticWarning
[ $compiler == dart2analyzer && $runtime == none ]
assertion_initializer_const_error2_test/none: CompileTimeError
@ -644,3 +647,6 @@ generic_methods_type_expression_test: CompileTimeError # Incorrectly disallows t
constant_type_literal_test/01: MissingCompileTimeError # Issue 28823
instantiate_type_variable_test/01: CompileTimeError
string_interpolate_test: CompileTimeError
[$compiler == dart2analyzer]
vm/regress_27201_test: SkipByDesign # Loads bad library, so will always crash.

View file

@ -318,6 +318,7 @@ instanceof4_test/01: RuntimeError
instanceof4_test/none: RuntimeError
invocation_mirror_test: RuntimeError
many_generic_instanceof_test: RuntimeError
vm/*: SkipByDesign # Tests for the VM.
[ $compiler == dart2js && $runtime != none && !$checked && !$dart2js_with_kernel ]
covariant_subtyping_tearoff1_test: RuntimeError
@ -1007,6 +1008,7 @@ deferred_constraints_constants_test: Pass # mirrors not supported, passes for th
invocation_mirror2_test: Fail # mirrors not supported
invocation_mirror_invoke_on2_test: Fail # mirrors not supported
invocation_mirror_invoke_on_test: Fail # mirrors not supported
vm/reflect_core_vm_test: Fail # mirrors not supported
[ $compiler == dart2js && $runtime == chrome && $system == macos ]
await_future_test: Pass, Timeout # Issue 26735

View file

@ -177,4 +177,5 @@ label_test: RuntimeError # Issue 30675
modulo_test: RuntimeError # Issue 29920
named_parameter_clash_test: RuntimeError # Issue 29920
named_parameters_default_eq_test/none: RuntimeError
vm/*: SkipByDesign # Tests for the VM.
yieldstar_pause_test: Skip # Times out

View file

@ -86,6 +86,10 @@ is_malformed_type_test/97: CompileTimeError
is_malformed_type_test/98: CompileTimeError
is_malformed_type_test/99: CompileTimeError
is_not_class2_test: RuntimeError
instance_creation_in_function_annotation_test: CompileTimeError
vm/reflect_core_vm_test: CompileTimeError
vm/no_such_method_error_message_callable_vm_test: RuntimeError # Flutter Issue 9110
vm/regress_27201_test: Fail # Flutter Issue 9110
# The VM doesn't enforce that potentially const expressions are actually
# const expressions when the constructor is called with `const`.

View file

@ -350,6 +350,8 @@ vm/debug_break_enabled_vm_test/01: CompileTimeError # KernelVM bug: Bad test usi
vm/debug_break_enabled_vm_test/none: CompileTimeError # KernelVM bug: Bad test using extended break syntax.
vm/closure_memory_retention_test: Skip # KernelVM bug: Hits OOM
named_constructor_test/01: MissingRuntimeError # Fasta bug: Bad compilation of constructor reference.
vm/regress_27201_test: CompileTimeError # Fasta/KernelVM bug: Deferred loading kernel issue 28335.
vm/type_vm_test: RuntimeError # Fasta bug: Bad position information in stack trace.
[ $checked && ($compiler == dartk || $compiler == dartkp) ]
assign_static_type_test/02: MissingCompileTimeError
@ -381,6 +383,10 @@ named_parameters_type_test/01: Crash
named_parameters_type_test/02: Crash
named_parameters_type_test/03: Crash
vm/integer_type_propagation_test: Crash
vm/optimized_stacktrace_test: Crash
vm/regress_27671_test: Crash
vm/type_vm_test: Crash
[ ($compiler == dartkp) && !$checked ]
generic_field_mixin6_test/none: RuntimeError
@ -404,3 +410,4 @@ cyclic_type_variable_test/none: Crash
[ $compiler == none || $compiler == app_jit || $compiler == dartk || $runtime == dart_precompiled ]
constructor3_test: Fail, OK, Pass
vm/regress_29145_test: Skip # Issue 29145

View file

@ -114,6 +114,7 @@ cyclic_type_variable_test/04: MissingCompileTimeError
cyclic_typedef_test/13: MissingCompileTimeError
default_factory2_test/01: MissingCompileTimeError
default_factory_test/01: MissingCompileTimeError
deferred_constraints_constants_test: SkipByDesign
deferred_constraints_type_annotation_test/as_operation: MissingCompileTimeError
deferred_constraints_type_annotation_test/catch_check: MissingCompileTimeError
deferred_constraints_type_annotation_test/is_check: MissingCompileTimeError
@ -210,6 +211,10 @@ instanceof2_test: RuntimeError
instanceof4_test/01: RuntimeError
instanceof4_test/none: RuntimeError
interface_test/00: MissingCompileTimeError
invocation_mirror2_test: SkipByDesign
invocation_mirror_invoke_on2_test: SkipByDesign
invocation_mirror_invoke_on_test: SkipByDesign
issue21079_test: SkipByDesign
many_generic_instanceof_test: RuntimeError
mixin_with_two_implicit_constructors_test: MissingCompileTimeError
mixin_type_parameters_super_test: RuntimeError
@ -284,13 +289,10 @@ unresolved_in_factory_test: MissingCompileTimeError
unresolved_top_level_method_test: MissingCompileTimeError
unresolved_top_level_var_test: MissingCompileTimeError
instance_creation_in_function_annotation_test: SkipByDesign
wrong_number_type_arguments_test/*: MissingCompileTimeError
void_block_return_test/00: MissingCompileTimeError
deferred_constraints_constants_test: SkipByDesign
issue21079_test: SkipByDesign
invocation_mirror2_test: SkipByDesign
invocation_mirror_invoke_on2_test: SkipByDesign
invocation_mirror_invoke_on_test: SkipByDesign
vm/type_vm_test: RuntimeError # Expects line and column numbers
vm/reflect_core_vm_test: SkipByDesign
wrong_number_type_arguments_test/*: MissingCompileTimeError
[ $compiler == precompiler && $runtime == dart_precompiled ]
assertion_initializer_const_error2_test/cc01: Crash, MissingCompileTimeError
@ -326,6 +328,8 @@ generic_constructor_mixin2_test/01: MissingCompileTimeError
generic_constructor_mixin3_test/01: MissingCompileTimeError
generic_methods_recursive_bound_test/02: MissingCompileTimeError
typevariable_substitution2_test/02: RuntimeError
vm/regress_27671_test: Skip # Unsupported
vm/optimized_stacktrace_test: Skip # Issue 30198
[ $compiler == precompiler && $runtime == dart_precompiled && $checked ]
assertion_initializer_const_error2_test/cc01: Pass
@ -383,8 +387,9 @@ generic_local_functions_test: Pass # Issue 25869
generic_methods_generic_function_parameter_test: Pass # Issue 25869
[ $runtime == dart_precompiled || $compiler == app_jit ]
hello_dart_test: Skip # Incompatible flag: --compile_all
ct_const2_test: Skip # Incompatible flag: --compile_all
hello_dart_test: Skip # Incompatible flag: --compile_all
vm/type_cast_vm_test: RuntimeError # Expects line and column numbers
[ ($runtime == vm || $runtime == flutter || $runtime == dart_precompiled) && ($compiler == none || $compiler == app_jit || $compiler == precompiler) ]
generalized_void_syntax_test: CompileTimeError # Issue #30176
@ -392,6 +397,7 @@ generalized_void_syntax_test: CompileTimeError # Issue #30176
[ $compiler == precompiler ]
deferred_global_test: Fail
implicit_closure_test: Skip # Incompatible flag: --use_slow_path
vm/regress_27201_test: Fail
[ $mode == product || $compiler == app_jit || $compiler == precompiler ]
deferred_load_constants_test/02: Fail
@ -410,3 +416,15 @@ cyclic_type_test/*: Skip
[ $runtime == dart_precompiled || $mode == product ]
vm/causal_async_exception_stack_test: SkipByDesign
vm/causal_async_exception_stack2_test: SkipByDesign
[ ($compiler == none || $compiler == precompiler || $compiler == app_jit) && (($runtime == vm || $runtime == dart_precompiled)) && $arch == ia32 ]
vm/regress_24517_test: Pass, Fail # Issue 24517.
[ $mode == product || $compiler == app_jit || $compiler == precompiler ]
vm/regress_27201_test: Fail
[ $runtime == dart_precompiled && $minified ]
vm/no_such_args_error_message_vm_test: Skip
vm/no_such_method_error_message_callable_vm_test: Skip
vm/no_such_method_error_message_vm_test: Skip
vm/regress_28325_test:Skip

View file

@ -295,6 +295,9 @@ generic_methods_dynamic_test/04: MissingRuntimeError
generic_methods_reuse_type_variables_test: RuntimeError
generic_methods_simple_as_expression_test/02: MissingRuntimeError
[ ($compiler == none || $compiler == app_jit) && $runtime == vm && $mode != product ]
vm/type_vm_test: RuntimeError
[ $runtime == vm && $checked ]
constructor_call_as_function_test/01: MissingCompileTimeError
covariant_subtyping_test: RuntimeError
@ -486,7 +489,7 @@ generic_methods_dynamic_test/02: MissingRuntimeError
generic_methods_dynamic_test/04: MissingRuntimeError
generic_methods_simple_as_expression_test/02: MissingRuntimeError
[$runtime == vm && $compiler == none && $system == fuchsia]
[ $runtime == vm && $compiler == none && $system == fuchsia ]
closure_cycles_test: Pass, Crash
vm/causal_async_exception_stack_test: RuntimeError
vm/causal_async_exception_stack2_test: RuntimeError
@ -501,3 +504,6 @@ constructor_call_as_function_test/01: MissingCompileTimeError
[ ($runtime == vm || $runtime == flutter || $runtime == dart_precompiled) && $arch == arm64 ]
closure_cycles_test: Pass, Slow
large_class_declaration_test: SkipSlow # Uses too much memory.
[ $runtime == vm && $compiler == none && $system == windows && $arch == ia32 ]
vm/optimized_stacktrace_test: Pass, Crash # Issue 28276

View file

@ -0,0 +1,35 @@
// 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 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) {
Expect.isTrue(e.toString().contains(
"Tried calling: testClosureMessage.<anonymous closure>(\"bar\")"));
}
}
noargs() {}
testFunctionMessage() {
try {
call_with_bar(noargs);
} catch (e) {
Expect.isTrue(e.toString().contains("Tried calling: noargs(\"bar\")"));
}
}
main() {
for (var i = 0; i < 20; i++) testClosureMessage();
for (var i = 0; i < 20; i++) testFunctionMessage();
}

View file

@ -0,0 +1,39 @@
// 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: non-existent 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) {
final noMatchingArgs =
"has no instance method 'call' with matching arguments";
Expect.isTrue(e.toString().contains(noMatchingArgs));
}
}
main() {
for (var i = 0; i < 20; i++) testMessageProp();
for (var i = 0; i < 20; i++) testMessageCall();
}

View file

@ -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: non-existent 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();
}

View file

@ -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;

View file

@ -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(10);
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]);
}

View file

@ -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));
}
}

View file

@ -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()));
}

View file

@ -0,0 +1,79 @@
// 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/expect.dart";
import 'package:async_helper/async_helper.dart';
class A {
A(this.a);
var a;
}
class B extends A {
B(a, this.b) : super(a) {}
var b;
}
f1(SendPort send_port) {
send_port.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<B> item = receive_port.first;
item.then((B value) {
Expect.equals("foobar", test_b(value));
receive_port.close();
asyncEnd();
});
}
class C {
C(this.list);
final List list;
}
f2(SendPort send_port) {
send_port.send(new C(new List(1)));
}
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(10000));
for (var i = 0; i < 200; i++) {
test_c(c);
}
Expect.equals(null, test_c(c));
Future<C> item = receive_port.first;
item.then((C value) {
Expect.throws(() => test_c(value), (e) => e is RangeError);
receive_port.close();
asyncEnd();
});
}
main() {
test_field_type();
test_list_length();
}

View file

@ -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(5), new Uint8List(5));
var b = new D.named(new List(5), 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();
}

View file

@ -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));
}

View file

@ -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>(-1);
Expect.isTrue(false); // Unreachable.
} on RangeError {
return true;
}
Expect.isTrue(false); // Unreachable.
}
main() {
for (var i = 0; i < 20; i++) {
Expect.isTrue(test());
}
}

View file

@ -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];
}
return r;
}
main() {
var a = new List<int>(1);
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));
}

View file

@ -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));
}

View file

@ -0,0 +1,42 @@
// 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 --enable-inlining-annotations --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) {
if (value < i) {
throw "";
}
o = o.next;
}
return value;
}
const NeverInline = 'NeverInline';
@NeverInline
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));
}

View file

@ -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);
}

View file

@ -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);
}

View file

@ -0,0 +1,43 @@
// 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();
res += obj.uniqueField; // This load must not be hoisted out of the loop.
}
return res;
}
test2(obj) {
final objAlias = obj;
closure() => objAlias;
var res = 0;
for (var i = 0; i < 2; i++) {
obj._uniqueSelector();
res +=
objAlias.uniqueField; // This load must not be hoisted out of the loop.
}
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));
}

View file

@ -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;
}
Expect.equals(10 * 123, s);
}

View file

@ -0,0 +1,15 @@
// 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 reflection of private functions in core classes.
import "package:expect/expect.dart";
import "dart:mirrors";
main() {
var s = "string";
var im = reflect(s);
Expect.throws(() => im.invoke(const Symbol("_setAt"), [0, 65]),
(e) => e is NoSuchMethodError);
}

View file

@ -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 big = 100000000000000000000000000000000000;
var before = cmp(big, big, 0);
Expect.equals(16, before);
for (var i = 0; i < 20; i++) cmp(big, big + 1, 0);
Expect.equals(before, cmp(big, big, 0));
}

View file

@ -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(var 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);
}

View file

@ -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);
}
}

View file

@ -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));
}

View file

@ -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));
}
}

View file

@ -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=--gc_at_instance_allocation=_Mint --inline_alloc=false
main() {
var re = new RegExp(r"IsolateStubs (.*)");
return re.firstMatch("oooo");
}

View file

@ -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);
}

View file

@ -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=5 --no-background-compilation
import 'package:expect/expect.dart';
mintLeftShift(x, y) => x << y;
mintRightShift(x, y) => x >> y;
main() {
for (var i = 0; i < 20; 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(x, mintRightShift(mintLeftShift(x, i), i));
}
}

View file

@ -0,0 +1,15 @@
// 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;
}
}

View file

@ -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));
}

View file

@ -0,0 +1,19 @@
// 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.
library import_lib;
final foo = 1;
var someVar = 3;
var _privateVar;
int get someGetter => 2;
void set someSetter(int val) {}
int someFunc() => 0;
class SomeClass {}
typedef int Func(Object a);

View file

@ -0,0 +1,52 @@
/*
* 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 "dart:async";
import "package:expect/expect.dart";
import "regress_27201_lib.dart" deferred as p;
import "regress_27201_bad_lib_path.dart" deferred as q;
test_loaded() {
try {
p.someFunc();
} catch (e) {
Expect.fail("Should not be here");
}
try {
p.someGetter;
} catch (e) {
Expect.fail("Should not be here");
}
try {
p.someSetter = 1;
} catch (e) {
Expect.fail("Should not be here");
}
try {
p.Func;
} catch (e) {
Expect.fail("Should not be here");
}
try {
Expect.isTrue(p.loadLibrary() is Future);
} catch (e) {
Expect.fail("Should not be here");
}
}
main() {
p.loadLibrary().then((v) {
test_loaded();
}, onError: (e) {
Expect.fail("Should have loaded library!");
});
// Ensure bad library import is handled correctly.
q.loadLibrary().then((v) {
Expect.fail("Should have failed");
}, onError: (e) {
Expect.throws(() => q.x);
});
}

View file

@ -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';
@AlwaysInline
void check(f, x) {
assert(f(x) && true);
}

View file

@ -0,0 +1,32 @@
// 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 --enable-inlining-annotations --optimization-counter-threshold=10 --no-background-compilation
import 'package:expect/expect.dart';
import 'regress_27671_other.dart';
const AlwaysInline = "AlwaysInline";
const NeverInline = "NeverInline";
@AlwaysInline
bounce(x) {
for (int i = 0; i < 10; i++) {
check(f, x);
}
}
@AlwaysInline
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'));
}
}

View file

@ -0,0 +1,20 @@
// 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 source positions in async errors.
import "package:expect/expect.dart";
import "dart:io";
main() async {
try {
await Socket.connect("localhost", 0);
Expect.isTrue(false); // Unreachable.
} catch (e, s) {
Expect.isTrue(e is SocketException);
Expect.isTrue(s.toString().contains("regress_28325_test.dart"));
print(s);
Expect.isTrue(s.toString().contains(":12")); // Line number of "await".
}
}

View file

@ -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=5 --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 < 10; i++) {
Expect.equals(rotated, rot8(value));
}
}

View file

@ -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);
}

View file

@ -0,0 +1,78 @@
// 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=--enable-inlining-annotations --optimization-counter-threshold=1000 --no-background-compilation
// Regression test for correct LICM and type propagation.
const AlwaysInline = "AlwaysInline";
const NeverInline = "NeverInline";
class Attribute {
final id = 123;
}
abstract class Name {
Name(this.name);
final String name;
get attr;
@AlwaysInline
int compareTo(other) {
int nameCompare = name.compareTo(other.name);
if (nameCompare != 0) return nameCompare;
if (attr == null) return 0;
return attr.id - other.attr.id;
}
}
class AName extends Name {
AName() : super("abc");
final attr = new Attribute();
}
class BName extends Name {
BName(name) : super(name);
get attr => null;
}
class Member {
Member(this.name);
var name;
}
Member find(List<Member> members, Name name) {
int low = 0, high = members.length - 1;
while (low <= high) {
int mid = low + ((high - low) >> 1);
Member pivot = members[mid];
int comparison = name.compareTo(pivot.name);
if (comparison < 0) {
high = mid - 1;
} else if (comparison > 0) {
low = mid + 1;
} else {
return pivot;
}
}
return null;
}
main() {
var list = [
new Member(new AName()),
new Member(new BName("a")),
new Member(new BName("b")),
new Member(new BName("c")),
new Member(new BName("d"))
];
find(list, new AName());
find(list, new BName("e"));
find(list, new BName("b"));
for (var i = 0; i < 1000; ++i) {
find(list, new BName("b"));
find(list, new BName("e"));
}
}

View file

@ -0,0 +1,89 @@
// 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 reusable boxes.
// VMOptions=--optimization_counter_threshold=100 --no-background_compilation
library reusable_boxes_test;
import 'dart:typed_data';
import 'package:expect/expect.dart';
class D {
var a = 0.0;
var b = 1.0;
var c = 2.0;
test() {
a = 0.0;
b = 1.0;
c = a + b;
return c;
}
testParam(x, y) {
x = x * x;
y = y * y;
c = x + y;
}
}
testD() {
var f = new D();
var r = 0.0;
for (var i = 0; i < 20; i++) {
r += f.test();
}
Expect.equals(20.0, r);
// Trigger a deopt of test.
f.testParam(new Float32x4(1.0, 2.0, 3.0, 4.0), new Float32x4.zero());
r = 0.0;
for (var i = 0; i < 20; i++) {
r += f.test();
}
Expect.equals(20.0, r);
}
class F {
var a = new Float32x4.zero();
var b = new Float32x4(1.0, 2.0, 3.0, 4.0);
var c = new Float32x4.zero();
test() {
a = new Float32x4.zero();
b = new Float32x4(1.0, 2.0, 3.0, 4.0);
c = a + b;
return c;
}
testParam(x, y) {
x = x * x;
y = y * y;
c = x + y;
}
}
testF() {
var f = new F();
var r = new Float32x4.zero();
for (var i = 0; i < 20; i++) {
r += f.test();
}
Expect.equals(20.0, r.x);
Expect.equals(40.0, r.y);
Expect.equals(60.0, r.z);
Expect.equals(80.0, r.w);
// Trigger a deopt of test.
f.testParam(1.0, 2.0);
r = new Float32x4.zero();
for (var i = 0; i < 20; i++) {
r += f.test();
}
Expect.equals(20.0, r.x);
Expect.equals(40.0, r.y);
Expect.equals(60.0, r.z);
Expect.equals(80.0, r.w);
}
main() {
testD();
testF();
}

View file

@ -0,0 +1,123 @@
// 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";
class C {
var x;
var y;
final z = 123;
}
class D {
var x = 0.0;
}
var array = [0, 0];
s1(a) {
a.x = 42;
a.x = 43;
return a.x;
}
void foo(a) {
Expect.equals(42, a.x);
}
s1a(a) {
a.x = 42;
foo(a);
a.x = 43;
return a.x;
}
s2() {
var t = new C();
return t;
}
s3(a, b) {
a.x = b + 1;
if (b % 2 == 0) {
a.x = 0;
} else {
a.x = 0;
}
return a.x;
}
s4(a, b) {
a.x = b + 1.0;
if (b % 2 == 0) {
a.x = b + 2.0;
}
a.x = b + 1.0;
return a.x;
}
test_with_context() {
f(a) {
var b = a + 1;
return (() => b + 1)();
}
for (var i = 0; i < 100000; i++) f(42);
Expect.equals(44, f(42));
}
test_with_instance() {
for (var i = 0; i < 20; i++) Expect.equals(43, s1(new C()));
for (var i = 0; i < 20; i++) Expect.equals(43, s1a(new C()));
for (var i = 0; i < 20; i++) Expect.equals(123, s2().z);
for (var i = 0; i < 20; i++) Expect.equals(0, s3(new C(), i));
for (var i = 0; i < 20; i++) Expect.equals(i + 1.0, s4(new D(), i));
}
arr1(a) {
a[0] = 42;
a[0] = 43;
Expect.equals(a[0], 43);
return a[0];
}
arr2(a, b) {
a[0] = 42;
a[b % 2] = 43;
Expect.equals(a[b % 2], 43);
return a[0];
}
test_with_array() {
for (var i = 0; i < 20; i++) Expect.equals(43, arr1(array));
for (var i = 0; i < 20; i++) {
Expect.equals(i % 2 == 0 ? 43 : 42, arr2(array, i));
}
}
var st = 0;
static1(b) {
st = 42;
if (b % 2 == 0) {
st = 2;
}
st = b + 1;
Expect.equals(st, b + 1);
return st;
}
test_with_static() {
for (var i = 0; i < 20; i++) Expect.equals(i + 1, static1(i));
}
main() {
test_with_instance();
test_with_array();
test_with_context();
test_with_static();
}

View file

@ -0,0 +1,33 @@
// 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=100 --no-background_compilation
library store_to_load_forwarding_phis_vm_test;
import 'dart:async';
class A {
var _foo;
get foo {
if (_foo == null) {
_foo = new A();
}
return _foo;
}
}
foo(obj) {
var a = obj.foo;
return new Future.value().then((val) {});
}
main() {
final obj = new A();
for (var i = 0; i < 200; i++) {
foo(obj);
}
}

View file

@ -0,0 +1,32 @@
// 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';
test1(String a, String b) {
return a == b;
}
var LEN = 500;
var ITER = 100000 / LEN;
measure(fn, a, b) {
for (var i = 0; i < ITER; i++) {
Expect.equals(true, fn(a, b));
}
}
main() {
var n = LEN;
StringBuffer s = new StringBuffer();
for (var i = 0; i < n; ++i) s.write("A");
String t = s.toString();
String u = s.toString();
String v = s.toString() + "\u1234";
String w = s.toString() + "\u1234";
for (var i = 0; i < 10; i++) measure(test1, t, u);
for (var i = 0; i < 10; i++) measure(test1, v, w);
}

View file

@ -0,0 +1,139 @@
// 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.
// VMOptions=--no_show_internal_names
// Dart test program testing type casts.
import "package:expect/expect.dart";
checkSecondFunction(String expected, StackTrace stacktrace) {
var topLine = stacktrace.toString().split("\n")[1];
int startPos = topLine.lastIndexOf("/");
int endPos = topLine.lastIndexOf(")");
String subs = topLine.substring(startPos + 1, endPos);
Expect.equals(expected, subs);
}
// Test that the initializer expression gets properly skipped.
bool b = "foo" as bool;
class TypeTest {
static test() {
int result = 0;
try {
var i = "hello" as int; // Throws a CastError
} catch (error) {
result = 1;
Expect.isTrue(error is CastError);
var msg = error.toString();
Expect.isTrue(msg.contains("int")); // dstType
Expect.isTrue(msg.contains("String")); // srcType
checkSecondFunction("type_cast_vm_test.dart:23:23", error.stackTrace);
}
return result;
}
static testSideEffect() {
int result = 0;
int index() {
result++;
return 0;
}
try {
var a = new List<int>(1) as List<int>;
a[0] = 0;
a[index()]++; // Type check succeeds, but does not create side effects.
Expect.equals(1, a[0]);
} catch (error) {
result = 100;
}
return result;
}
static testArgument() {
int result = 0;
int f(int i) {
return i;
}
try {
int i = f("hello" as int); // Throws a CastError
} catch (error) {
result = 1;
Expect.isTrue(error is CastError);
var msg = error.toString();
Expect.isTrue(msg.contains("int")); // dstType
Expect.isTrue(msg.contains("String")); // srcType
checkSecondFunction("type_cast_vm_test.dart:60:25", error.stackTrace);
}
return result;
}
static testReturn() {
int result = 0;
int f(String s) {
return s as int; // Throws a CastError
}
try {
int i = f("hello");
} catch (error) {
result = 1;
Expect.isTrue(error is CastError);
var msg = error.toString();
Expect.isTrue(msg.contains("int")); // dstType
Expect.isTrue(msg.contains("String")); // srcType
checkSecondFunction("type_cast_vm_test.dart:75:16", error.stackTrace);
}
return result;
}
static var field = "hello";
static testField() {
int result = 0;
Expect.equals(5, (field as String).length);
try {
field as int; // Throws a CastError
} catch (error) {
result = 1;
var msg = error.toString();
Expect.isTrue(msg.contains("int")); // dstType
Expect.isTrue(msg.contains("String")); // srcType
checkSecondFunction("type_cast_vm_test.dart:97:13", error.stackTrace);
}
return result;
}
static testAnyFunction() {
int result = 0;
Function anyFunction;
f() {}
;
anyFunction = f as Function; // No error.
anyFunction = null as Function; // No error.
try {
var i = f as int; // Throws a TypeError if type checks are enabled.
} catch (error) {
result = 1;
var msg = error.toString();
Expect.isTrue(msg.contains("int")); // dstType
Expect.isTrue(msg.contains("() => dynamic")); // srcType
checkSecondFunction("type_cast_vm_test.dart:116:17", error.stackTrace);
}
return result;
}
static testMain() {
Expect.equals(1, test());
Expect.equals(1, testSideEffect());
Expect.equals(1, testArgument());
Expect.equals(1, testReturn());
Expect.equals(1, testField());
Expect.equals(1, testAnyFunction());
}
}
main() {
TypeTest.testMain();
}

View file

@ -0,0 +1,57 @@
// 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=1000 --max-polymorphic-checks=1 --no-background-compilation
// Test correct loop invariant code motion and type propagation from is-checks
// and null-comparisons.
class B {
var b;
B(this.b);
}
class C {
final f0 = null;
final a;
C() : a = new B(0);
}
foo(x) {
for (var i = 0; i < 10; i++) {
i + i;
i + i;
if (x is C) {
x.a.b < 0;
}
}
}
class Y {
var f = null;
}
bar(y) {
var x = y.f;
for (var i = 0; i < 10; i++) {
if (x != null) {
x.a.b < 0;
}
}
}
main() {
var o = new Y();
o.f = new C();
bar(o);
o.f = null;
bar(o);
for (var i = 0; i < 1000; i++) bar(o);
foo(new C());
foo(0);
for (var i = 0; i < 1000; i++) foo(0);
}

View file

@ -0,0 +1,187 @@
// 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.
// VMOptions=--enable_type_checks --enable_asserts --no_show_internal_names
// Dart test program testing type checks.
import "package:expect/expect.dart";
class C {
factory C() {
return 1; //# 01: compile-time error
}
}
class TypeTest {
static test() {
int i = "hello"; //# 02: compile-time error
return 1;
}
static testSideEffect() {
int result = 0;
int index() {
result++;
return 0;
}
try {
List<int> a = new List<int>(1);
a[0] = 0;
a[index()]++; // Type check succeeds, but does not create side effects.
Expect.equals(1, a[0]);
} on TypeError catch (error) {
result = 100;
}
return result;
}
static testArgument() {
int f(int i) {
return i;
}
int i = f("hello"); //# 03: compile-time error
return 1;
}
static testReturn() {
int f(String s) { //# 04: continued
return s; //# 04: compile-time error
} //# 04: continued
int i = f("hello"); //# 04: continued
return 1;
}
static int field;
static testField() {
field = "hello"; //# 05: compile-time error
return 1;
}
static testAnyFunction() {
Function anyFunction;
f() {}
anyFunction = f; // No error.
int i = f; //# 06: compile-time error
return 1;
}
static testVoidFunction() {
Function anyFunction;
void acceptVoidFunObj(void voidFunObj(Object obj)) {}
void acceptObjFunObj(Object objFunObj(Object obj)) {}
void voidFunObj(Object obj) {}
Object objFunObj(Object obj) {
return obj;
}
;
anyFunction = voidFunObj; // No error.
anyFunction = objFunObj; // No error.
acceptVoidFunObj(voidFunObj);
acceptVoidFunObj(objFunObj);
acceptObjFunObj(objFunObj);
acceptObjFunObj(voidFunObj);
return 1;
}
static testFunctionNum() {
Function anyFunction;
void acceptFunNum(void funNum(num n)) {}
void funObj(Object obj) {}
void funNum(num n) {}
void funInt(int i) {}
void funString(String s) {}
anyFunction = funObj; // No error.
anyFunction = funNum; // No error.
anyFunction = funInt; // No error.
anyFunction = funString; // No error.
acceptFunNum(funObj); // No error.
acceptFunNum(funNum); // No error.
acceptFunNum(funInt); //# 27: compile-time error
acceptFunNum(funString); //# 08: compile-time error
return 1;
}
static testBoolCheck() {
bool i = !"hello"; //# 09: compile-time error
while ("hello") {} //# 10: compile-time error
do {} while ("hello"); //# 11: compile-time error
for (; "hello";) {} //# 12: compile-time error
int i = "hello" ? 1 : 0; //# 13: compile-time error
if ("hello") {} //# 14: compile-time error
if ("hello" || false) {} //# 15: compile-time error
if (false || "hello") {} //# 16: compile-time error
if (null) {}
return 9;
}
static int testFactory() {
var x = new C(); //# 01: continued
return 1;
}
static int testListAssigment() {
int result = 0;
{
var a = new List(5);
List a0 = a;
List<Object> ao = a;
List<int> ai = a;
List<num> an = a;
List<String> as = a;
}
{
var a = new List<Object>(5);
List a0 = a;
List<Object> ao = a;
List<int> ai = a;
List<num> an = a;
List<String> as = a;
}
{
var a = new List<int>(5);
List a0 = a;
List<Object> ao = a;
List<int> ai = a;
List<num> an = a;
List<String> as = a; //# 22: compile-time error
}
{
var a = new List<num>(5);
List a0 = a;
List<Object> ao = a;
List<int> ai = a;
List<num> an = a;
List<String> as = a; //# 24: compile-time error
}
{
var a = new List<String>(5);
List a0 = a;
List<Object> ao = a;
List<int> ai = a; //# 25: compile-time error
List<num> an = a; //# 26: compile-time error
List<String> as = a;
}
return 8;
}
static testMain() {
Expect.equals(1, test());
Expect.equals(1, testSideEffect());
Expect.equals(1, testArgument());
Expect.equals(1, testReturn());
Expect.equals(1, testField());
Expect.equals(1, testAnyFunction());
Expect.equals(1, testVoidFunction());
Expect.equals(1, testFunctionNum());
Expect.equals(9, testBoolCheck());
Expect.equals(1, testFactory());
Expect.equals(8, testListAssigment());
}
}
main() {
TypeTest.testMain();
}