From 1ddf553eb6205f5459fe4d69b37eb17e4186cdff Mon Sep 17 00:00:00 2001 From: Florian Loitsch Date: Mon, 4 Jun 2018 18:05:20 +0000 Subject: [PATCH] Make --sync-async the default for the VM. Change-Id: Ic6d7bbc27835ea7b197cccf05724adb99e95dd51 Reviewed-on: https://dart-review.googlesource.com/57580 Commit-Queue: Vyacheslav Egorov Reviewed-by: Martin Kustermann --- CHANGELOG.md | 3 ++ .../dart/completion_contributor_util.dart | 12 +++--- .../lib/src/dart/analysis/driver.dart | 2 + pkg/front_end/tool/_fasta/command_line.dart | 2 +- pkg/vm/bin/gen_kernel.dart | 3 +- pkg/vm/lib/frontend_server.dart | 2 +- pkg/vm/test/frontend_server_test.dart | 8 ++-- .../service/async_single_step_out_test.dart | 2 +- .../observatory/tests/service/service.status | 4 ++ runtime/vm/dart_api_impl_test.cc | 37 ------------------- runtime/vm/flag_list.h | 2 +- runtime/vm/kernel_isolate.cc | 2 +- tests/co19/co19-runtime.status | 1 + tests/language/language.status | 4 ++ tests/lib/lib.status | 1 + .../isolate/native_wrapper_message_test.dart | 34 +++++++++++++++++ tests/lib_2/lib_2_vm.status | 3 ++ 17 files changed, 70 insertions(+), 52 deletions(-) create mode 100644 tests/lib_2/isolate/native_wrapper_message_test.dart diff --git a/CHANGELOG.md b/CHANGELOG.md index a353d326264..1ff283eb530 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,9 @@ ### Dart VM +* The VM now uses `--sync-async` by default. Users can still opt out by + providing the `--no-sync-async` flag. + ### Tool Changes #### Analyzer diff --git a/pkg/analysis_server/test/services/completion/dart/completion_contributor_util.dart b/pkg/analysis_server/test/services/completion/dart/completion_contributor_util.dart index 024e565ebfb..f47d69df466 100644 --- a/pkg/analysis_server/test/services/completion/dart/completion_contributor_util.dart +++ b/pkg/analysis_server/test/services/completion/dart/completion_contributor_util.dart @@ -533,15 +533,17 @@ abstract class DartCompletionContributorTest extends AbstractContextTest { } Future performAnalysis(int times, Completer completer) async { + // Await a microtask. Otherwise the futures are chained and would + // resolve linearly using up the stack. + await null; if (completer.isCompleted) { return completer.future; } // We use a delayed future to allow microtask events to finish. The - // Future.value or Future() constructors use scheduleMicrotask themselves and - // would therefore not wait for microtask callbacks that are scheduled after - // invoking this method. - return new Future.delayed( - Duration.zero, () => performAnalysis(times - 1, completer)); + // Future.value or Future.microtask() constructors use scheduleMicrotask + // themselves and would therefore not wait for microtask callbacks that + // are scheduled after invoking this method. + return new Future(() => performAnalysis(times - 1, completer)); } void resolveSource(String path, String content) { diff --git a/pkg/analyzer/lib/src/dart/analysis/driver.dart b/pkg/analyzer/lib/src/dart/analysis/driver.dart index 763bedafb19..5cfa1e7ef26 100644 --- a/pkg/analyzer/lib/src/dart/analysis/driver.dart +++ b/pkg/analyzer/lib/src/dart/analysis/driver.dart @@ -1939,6 +1939,8 @@ class AnalysisDriverScheduler { * priority first. */ Future _run() async { + // Give other microtasks the time to run before doing the analysis cycle. + await null; Stopwatch timer = new Stopwatch()..start(); PerformanceLogSection analysisSection; while (true) { diff --git a/pkg/front_end/tool/_fasta/command_line.dart b/pkg/front_end/tool/_fasta/command_line.dart index c804b1e1ba8..b34bcdf8159 100644 --- a/pkg/front_end/tool/_fasta/command_line.dart +++ b/pkg/front_end/tool/_fasta/command_line.dart @@ -212,7 +212,7 @@ const Map optionSpecification = const { "--sdk": Uri, "--strong": "--strong-mode", "--strong-mode": false, - "--sync-async": false, + "--sync-async": true, "--target": String, "--verbose": false, "--verify": false, diff --git a/pkg/vm/bin/gen_kernel.dart b/pkg/vm/bin/gen_kernel.dart index 16212bf43c0..151be0eb6d3 100644 --- a/pkg/vm/bin/gen_kernel.dart +++ b/pkg/vm/bin/gen_kernel.dart @@ -28,7 +28,8 @@ final ArgParser _argParser = new ArgParser(allowTrailingOptions: true) 'Produce kernel file for AOT compilation (enables global transformations).', defaultsTo: false) ..addFlag('strong-mode', help: 'Enable strong mode', defaultsTo: true) - ..addFlag('sync-async', help: 'Start `async` functions synchronously') + ..addFlag('sync-async', + help: 'Start `async` functions synchronously', defaultsTo: true) ..addFlag('embed-sources', help: 'Embed source files in the generated kernel component', defaultsTo: true) diff --git a/pkg/vm/lib/frontend_server.dart b/pkg/vm/lib/frontend_server.dart index 0bf5ffb1def..38b2e107299 100644 --- a/pkg/vm/lib/frontend_server.dart +++ b/pkg/vm/lib/frontend_server.dart @@ -48,7 +48,7 @@ ArgParser argParser = new ArgParser(allowTrailingOptions: true) help: 'Run compiler in strong mode (uses strong mode semantics)', defaultsTo: false) ..addFlag('sync-async', - help: 'Start `async` functions synchronously.', defaultsTo: false) + help: 'Start `async` functions synchronously.', defaultsTo: true) ..addFlag('tfa', help: 'Enable global type flow analysis and related transformations in AOT mode.', diff --git a/pkg/vm/test/frontend_server_test.dart b/pkg/vm/test/frontend_server_test.dart index bfd1219c7aa..997bdf96971 100644 --- a/pkg/vm/test/frontend_server_test.dart +++ b/pkg/vm/test/frontend_server_test.dart @@ -69,16 +69,16 @@ Future main() async { )).captured; expect(capturedArgs.single['sdk-root'], equals('sdkroot')); expect(capturedArgs.single['strong'], equals(true)); - expect(capturedArgs.single['sync-async'], equals(false)); + expect(capturedArgs.single['sync-async'], equals(true)); }); - test('compile from command line (sync-async)', () async { + test('compile from command line (no-sync-async)', () async { final List args = [ 'server.dart', '--sdk-root', 'sdkroot', '--strong', - '--sync-async', + '--no-sync-async', ]; final int exitcode = await starter(args, compiler: compiler); expect(exitcode, equals(0)); @@ -89,7 +89,7 @@ Future main() async { )).captured; expect(capturedArgs.single['sdk-root'], equals('sdkroot')); expect(capturedArgs.single['strong'], equals(true)); - expect(capturedArgs.single['sync-async'], equals(true)); + expect(capturedArgs.single['sync-async'], equals(false)); }); test('compile from command line with link platform', () async { diff --git a/runtime/observatory/tests/service/async_single_step_out_test.dart b/runtime/observatory/tests/service/async_single_step_out_test.dart index 5f0777fc3e3..7da09fb8f39 100644 --- a/runtime/observatory/tests/service/async_single_step_out_test.dart +++ b/runtime/observatory/tests/service/async_single_step_out_test.dart @@ -1,7 +1,7 @@ // 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=--error_on_bad_type --error_on_bad_override --verbose_debug --async_debugger +// VMOptions=--error_on_bad_type --error_on_bad_override --verbose_debug --async_debugger --no-sync-async import 'dart:developer'; import 'service_test_common.dart'; diff --git a/runtime/observatory/tests/service/service.status b/runtime/observatory/tests/service/service.status index 8a40809b047..b4a7666321e 100644 --- a/runtime/observatory/tests/service/service.status +++ b/runtime/observatory/tests/service/service.status @@ -78,8 +78,12 @@ async_scope_test: Pass, Slow *: Skip [ ($compiler == none || $compiler == precompiler) && ($runtime == dart_precompiled || $runtime == vm) ] +async_step_out_test: RuntimeError # Issue 29158, Async debugging +awaiter_async_stack_contents_test: RuntimeError # Issue 29158, Async debugging evaluate_activation_test/instance: RuntimeError # http://dartbug.com/20047 evaluate_activation_test/scope: RuntimeError # http://dartbug.com/20047 +regress_28980_test: RuntimeError # Issue 29158, Async debugging +set_library_debuggable_test: RuntimeError # Issue 29158, Async debugging [ $arch != ia32 || $arch != x64 || $system != linux ] get_native_allocation_samples_test: Skip # Unsupported. diff --git a/runtime/vm/dart_api_impl_test.cc b/runtime/vm/dart_api_impl_test.cc index 5867cf59de8..2e6c340ab4b 100644 --- a/runtime/vm/dart_api_impl_test.cc +++ b/runtime/vm/dart_api_impl_test.cc @@ -4408,43 +4408,6 @@ TEST_CASE(DartAPI_NegativeNativeFieldAccess) { EXPECT(Dart_IsError(result)); } -TEST_CASE(DartAPI_NegativeNativeFieldInIsolateMessage) { - const char* kScriptChars = - "import 'dart:isolate';\n" - "import 'dart:nativewrappers';\n" - "echo(msg) {\n" - " var data = msg[0];\n" - " var reply = msg[1];\n" - " reply.send('echoing ${data(1)}}');\n" - "}\n" - "class Test extends NativeFieldWrapperClass2 {\n" - " Test(this.i, this.j);\n" - " int i, j;\n" - "}\n" - "main() {\n" - " var port = new RawReceivePort();\n" - " var obj = new Test(1,2);\n" - " var msg = [obj, port.sendPort];\n" - " var snd = Isolate.spawn(echo, msg);\n" - " port.handler = (msg) {\n" - " port.close();\n" - " print('from worker ${msg}');\n" - " };\n" - "}\n"; - - CHECK_API_SCOPE(thread); - HANDLESCOPE(thread); - - // Create a test library and Load up a test script in it. - Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); - - // Invoke 'main' which should spawn an isolate and try to send an - // object with native fields over to the spawned isolate. This - // should result in an unhandled exception which is checked. - Dart_Handle retobj = Dart_Invoke(lib, NewString("main"), 0, NULL); - EXPECT(Dart_IsError(retobj)); -} - TEST_CASE(DartAPI_GetStaticField_RunsInitializer) { const char* kScriptChars = "class TestClass {\n" diff --git a/runtime/vm/flag_list.h b/runtime/vm/flag_list.h index 2d5540a47e3..f50108945d0 100644 --- a/runtime/vm/flag_list.h +++ b/runtime/vm/flag_list.h @@ -152,7 +152,7 @@ C(stress_async_stacks, false, false, bool, false, \ "Stress test async stack traces") \ P(strong, bool, false, "Enable strong mode.") \ - P(sync_async, bool, false, "Start `async` functions synchronously.") \ + P(sync_async, bool, true, "Start `async` functions synchronously.") \ R(support_ast_printer, false, bool, true, "Support the AST printer.") \ R(support_compiler_stats, false, bool, true, "Support compiler stats.") \ R(support_disassembler, false, bool, true, "Support the disassembler.") \ diff --git a/runtime/vm/kernel_isolate.cc b/runtime/vm/kernel_isolate.cc index bdba93143ca..f0b47d51b57 100644 --- a/runtime/vm/kernel_isolate.cc +++ b/runtime/vm/kernel_isolate.cc @@ -88,7 +88,7 @@ class RunKernelTask : public ThreadPool::Task { api_flags.enable_error_on_bad_override = false; api_flags.reify_generic_functions = false; api_flags.strong = false; - api_flags.sync_async = false; + api_flags.sync_async = true; #if !defined(DART_PRECOMPILER) && !defined(TARGET_ARCH_DBC) api_flags.use_field_guards = true; #endif diff --git a/tests/co19/co19-runtime.status b/tests/co19/co19-runtime.status index 2dd32600d0a..ff9af544e3a 100644 --- a/tests/co19/co19-runtime.status +++ b/tests/co19/co19-runtime.status @@ -168,6 +168,7 @@ LibTest/typed_data/Int32List/buffer_A01_t02: Pass, Timeout # Flutter Issue 9109 [ $runtime == vm ] Language/Classes/Constructors/Generative_Constructors/execution_of_an_initializer_t02: MissingCompileTimeError # Issue 114 +Language/Expressions/Function_Invocation/async_invokation_t02: RuntimeError # sync-async is on by default. LibTest/isolate/Isolate/spawnUri_A01_t06: Pass, Fail # Issue 28269, These tests are timing dependent and should be non-flaky once the fix for https://github.com/dart-lang/co19/issues/86 is merged into master. (They are skipped on $runtime == pre_compiled below.) LibTest/isolate/Isolate/spawnUri_A01_t07: Pass, Fail # Issue 28269, These tests are timing dependent and should be non-flaky once the fix for https://github.com/dart-lang/co19/issues/86 is merged into master. (They are skipped on $runtime == pre_compiled below.) LibTest/isolate/Isolate/spawn_A04_t01: Pass, Fail # Issue 28269, These tests are timing dependent and should be non-flaky once the fix for https://github.com/dart-lang/co19/issues/86 is merged into master. (They are skipped on $runtime == pre_compiled below.) diff --git a/tests/language/language.status b/tests/language/language.status index a228688bfa0..eae8a6529a0 100644 --- a/tests/language/language.status +++ b/tests/language/language.status @@ -474,6 +474,10 @@ vm/causal_async_exception_stack_test: SkipByDesign # Causal async stacks are not [ $runtime == dart_precompiled || $runtime == vm ] arithmetic_test: CompileTimeError # Large integer literal +async_await_test: RuntimeError # sync-async is on by default +asyncstar_throw_in_catch_test: RuntimeError # sync-async is on by default +await_nonfuture_test: RuntimeError # sync-async is on by default +await_not_started_immediately_test: RuntimeError # sync-async is on by default bit_operations_test: CompileTimeError # Large integer literal deopt_inlined_function_lazy_test: CompileTimeError # Large integer literal guess_cid_test: CompileTimeError # Large integer literal diff --git a/tests/lib/lib.status b/tests/lib/lib.status index 116c44e761e..1bfcfb9bb58 100644 --- a/tests/lib/lib.status +++ b/tests/lib/lib.status @@ -153,6 +153,7 @@ typed_data/float32x4_test: Fail, Pass # Safari has an optimization bug (nightlie typed_data/int32x4_test: Fail, Pass # Safari has an optimization bug (nightlies are already fine). [ $runtime == vm ] +async/async_await_sync_completer_test: RuntimeError # sync-async is on by default. convert/streamed_conversion_json_utf8_decode_test: Pass, Slow # Infrequent timeouts. [ !$checked ] diff --git a/tests/lib_2/isolate/native_wrapper_message_test.dart b/tests/lib_2/isolate/native_wrapper_message_test.dart new file mode 100644 index 00000000000..09dcb408da1 --- /dev/null +++ b/tests/lib_2/isolate/native_wrapper_message_test.dart @@ -0,0 +1,34 @@ +// 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 'dart:isolate'; +import 'dart:nativewrappers'; +import 'package:expect/expect.dart'; +import 'package:async_helper/async_helper.dart'; + +echo(msg) { + var data = msg[0]; + var reply = msg[1]; + reply.send('echoing ${data(1)}}'); +} + +class Test extends NativeFieldWrapperClass2 { + Test(this.i, this.j); + int i, j; +} + +main() { + var port = new RawReceivePort(); + var obj = new Test(1, 2); + var msg = [obj, port.sendPort]; + var snd = Isolate.spawn(echo, msg); + + asyncStart(); + snd.catchError((e) { + Expect.isTrue(e is ArgumentError); + Expect.isTrue("$e".contains("NativeWrapper")); + port.close(); + asyncEnd(); + }); +} diff --git a/tests/lib_2/lib_2_vm.status b/tests/lib_2/lib_2_vm.status index 16463be043e..6b5454d7bc4 100644 --- a/tests/lib_2/lib_2_vm.status +++ b/tests/lib_2/lib_2_vm.status @@ -2,6 +2,9 @@ # 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. +[ $runtime != vm ] +isolate/native_wrapper_message_test: Skip # A VM specific test. + [ $arch == arm64 && $runtime == vm ] mirrors/immutable_collections_test: Pass, Slow # http://dartbug.com/33057