From 7a51df050d47df4023e59a6ecfaec780f1c8cf95 Mon Sep 17 00:00:00 2001 From: Siva Annamalai Date: Fri, 15 Dec 2017 09:47:28 -0800 Subject: [PATCH 1/6] Add a --strong option to the front end server so we can use strong mode with preview-dart-2. --- frontend_server/lib/server.dart | 5 ++- frontend_server/test/server_test.dart | 54 +++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/frontend_server/lib/server.dart b/frontend_server/lib/server.dart index 6e0fa6b74e861..0a4fb84f1b7c6 100644 --- a/frontend_server/lib/server.dart +++ b/frontend_server/lib/server.dart @@ -39,6 +39,9 @@ ArgParser _argParser = new ArgParser(allowTrailingOptions: true) ..addFlag('aot', help: 'Run compiler in AOT mode (enables whole-program transformations)', defaultsTo: false) + ..addFlag('strong', + help: 'Run compiler in strong mode (uses strong mode semantics)', + defaultsTo: false) ..addFlag('link-platform', help: 'When in batch mode, link platform kernel file into result kernel file.' @@ -148,7 +151,7 @@ class _FrontendCompiler implements CompilerInterface { ? new FileByteStore(byteStorePath) : new MemoryByteStore() ..sdkRoot = sdkRoot - ..strongMode = false + ..strongMode = options['strong'] ..target = new FlutterTarget(new TargetFlags()) ..reportMessages = true; diff --git a/frontend_server/test/server_test.dart b/frontend_server/test/server_test.dart index 5eb04e77cb24e..1d2d215905b44 100644 --- a/frontend_server/test/server_test.dart +++ b/frontend_server/test/server_test.dart @@ -51,6 +51,28 @@ Future main() async { ) ).captured; expect(capturedArgs.single['sdk-root'], equals('sdkroot')); + expect(capturedArgs.single['strong'], equals(false)); + }); + + test('compile from command line (strong mode)', () async { + final List args = [ + 'server.dart', + '--sdk-root', + 'sdkroot', + '--strong', + ]; + final int exitcode = await starter(args, compiler: compiler); + expect(exitcode, equals(0)); + final List capturedArgs = + verify( + compiler.compile( + argThat(equals('server.dart')), + captureAny, + generator: any, + ) + ).captured; + expect(capturedArgs.single['sdk-root'], equals('sdkroot')); + expect(capturedArgs.single['strong'], equals(true)); }); test('compile from command line with file byte store', () async { @@ -73,6 +95,7 @@ Future main() async { ).captured; expect(capturedArgs.single['sdk-root'], equals('sdkroot')); expect(capturedArgs.single['byte-store'], equals('path/to/bytestore')); + expect(capturedArgs.single['strong'], equals(false)); }); test('compile from command line with link platform', () async { @@ -94,6 +117,7 @@ Future main() async { ).captured; expect(capturedArgs.single['sdk-root'], equals('sdkroot')); expect(capturedArgs.single['link-platform'], equals(true)); + expect(capturedArgs.single['strong'], equals(false)); }); }); @@ -118,6 +142,7 @@ Future main() async { equals('sdkroot')); expect(invocation.positionalArguments[1]['byte-store'], equals('path/to/bytestore')); + expect(invocation.positionalArguments[1]['strong'], equals(false)); compileCalled.sendPort.send(true); } ); @@ -139,6 +164,11 @@ Future main() async { '--sdk-root', 'sdkroot', ]; + final List strongArgs = [ + '--sdk-root', + 'sdkroot', + '--strong', + ]; test('compile one file', () async { final StreamController> inputStreamController = @@ -148,6 +178,7 @@ Future main() async { (Invocation invocation) { expect(invocation.positionalArguments[0], equals('server.dart')); expect(invocation.positionalArguments[1]['sdk-root'], equals('sdkroot')); + expect(invocation.positionalArguments[1]['strong'], equals(false)); compileCalled.sendPort.send(true); } ); @@ -160,6 +191,28 @@ Future main() async { await compileCalled.first; inputStreamController.close(); }); + + test('compile one file (strong mode)', () async { + final StreamController> inputStreamController = + new StreamController>(); + final ReceivePort compileCalled = new ReceivePort(); + when(compiler.compile(any, any, generator: any)).thenAnswer( + (Invocation invocation) { + expect(invocation.positionalArguments[0], equals('server.dart')); + expect(invocation.positionalArguments[1]['sdk-root'], equals('sdkroot')); + expect(invocation.positionalArguments[1]['strong'], equals(true)); + compileCalled.sendPort.send(true); + } + ); + + final int exitcode = await starter(strongArgs, compiler: compiler, + input: inputStreamController.stream, + ); + expect(exitcode, equals(0)); + inputStreamController.add('compile server.dart\n'.codeUnits); + await compileCalled.first; + inputStreamController.close(); + }); test('compile few files', () async { final StreamController> streamController = @@ -170,6 +223,7 @@ Future main() async { (Invocation invocation) { expect(invocation.positionalArguments[0], equals('server${counter++}.dart')); expect(invocation.positionalArguments[1]['sdk-root'], equals('sdkroot')); + expect(invocation.positionalArguments[1]['strong'], equals(false)); compileCalled.sendPort.send(true); } ); From 537e1eaec3b2a0a28eb7a537e4fd9c55f0b0fb91 Mon Sep 17 00:00:00 2001 From: Siva Annamalai Date: Mon, 1 Jan 2018 19:34:01 -0800 Subject: [PATCH 2/6] Plumb the --strong option through the dart controller into the VM. --- common/settings.h | 1 + frontend_server/lib/server.dart | 2 +- runtime/dart_init.cc | 13 ++++++++++++- shell/common/shell.cc | 4 ++++ shell/common/switches.h | 3 +++ .../io/flutter/app/FlutterActivityDelegate.java | 3 +++ 6 files changed, 24 insertions(+), 2 deletions(-) diff --git a/common/settings.h b/common/settings.h index 5bb5c6cbbea42..cf1de7b87325d 100644 --- a/common/settings.h +++ b/common/settings.h @@ -24,6 +24,7 @@ struct Settings { bool enable_dart_profiling = false; bool use_test_fonts = false; bool dart_non_checked_mode = false; + bool dart_strong_mode = false; bool enable_software_rendering = false; bool using_blink = true; std::string aot_shared_library_path; diff --git a/frontend_server/lib/server.dart b/frontend_server/lib/server.dart index 0a4fb84f1b7c6..8cf82bbd88615 100644 --- a/frontend_server/lib/server.dart +++ b/frontend_server/lib/server.dart @@ -152,7 +152,7 @@ class _FrontendCompiler implements CompilerInterface { : new MemoryByteStore() ..sdkRoot = sdkRoot ..strongMode = options['strong'] - ..target = new FlutterTarget(new TargetFlags()) + ..target = new FlutterTarget(new TargetFlags(strongMode: options['strong'])) ..reportMessages = true; Program program; diff --git a/runtime/dart_init.cc b/runtime/dart_init.cc index e32249d2451bb..b070210827796 100644 --- a/runtime/dart_init.cc +++ b/runtime/dart_init.cc @@ -115,6 +115,14 @@ static const char* kDartCheckedModeArgs[] = { // clang-format on }; +static const char* kDartStrongModeArgs[] = { + // clang-format off + "--strong", + "--reify_generic_functions", + "--limit_ints_to_64_bits", + // clang-format on +}; + static const char* kDartStartPausedArgs[]{ "--pause_isolates_on_start", }; @@ -586,8 +594,11 @@ void InitDartVM(const uint8_t* vm_snapshot_data, arraysize(kDartWriteProtectCodeArgs)); #endif - if (use_checked_mode) + if (settings.dart_strong_mode) { + PushBackAll(&args, kDartStrongModeArgs, arraysize(kDartStrongModeArgs)); + } else if (use_checked_mode) { PushBackAll(&args, kDartCheckedModeArgs, arraysize(kDartCheckedModeArgs)); + } if (settings.start_paused) PushBackAll(&args, kDartStartPausedArgs, arraysize(kDartStartPausedArgs)); diff --git a/shell/common/shell.cc b/shell/common/shell.cc index d839820594df8..b2b70df5d5450 100644 --- a/shell/common/shell.cc +++ b/shell/common/shell.cc @@ -107,6 +107,10 @@ void Shell::InitStandalone(fxl::CommandLine command_line, settings.dart_non_checked_mode = command_line.HasOption(FlagForSwitch(Switch::DartNonCheckedMode)); + // strong mode setting. + settings.dart_strong_mode = + command_line.HasOption(FlagForSwitch(Switch::DartStrongMode)); + settings.ipv6 = command_line.HasOption(FlagForSwitch(Switch::IPv6)); settings.start_paused = diff --git a/shell/common/switches.h b/shell/common/switches.h index 6d5bd03a80a72..b29cba9599046 100644 --- a/shell/common/switches.h +++ b/shell/common/switches.h @@ -104,6 +104,9 @@ DEF_SWITCH(DartNonCheckedMode, "precompiled and checked mode is unsupported. However, this flag " "may be specified if the user wishes to run in the debug product " "mode (i.e. with JIT or DBC) with checked mode off.") +DEF_SWITCH(DartStrongMode, + "strong", + "Enable Dart 2.0 strong mode.") DEF_SWITCHES_END void PrintUsage(const std::string& executable_name); diff --git a/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java b/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java index 0ad8eb998eb1f..9402fb3d727cb 100644 --- a/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java +++ b/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java @@ -296,6 +296,9 @@ private static String[] getArgsFromIntent(Intent intent) { if (intent.getBooleanExtra("trace-skia", false)) { args.add("--trace-skia"); } + if (intent.getBooleanExtra("strong", false)) { + args.add("--strong"); + } if (!args.isEmpty()) { String[] argsArray = new String[args.size()]; return args.toArray(argsArray); From 143e794a807bf122db8d58bc5a82c0338419962c Mon Sep 17 00:00:00 2001 From: Siva Annamalai Date: Tue, 2 Jan 2018 15:52:12 -0800 Subject: [PATCH 3/6] - Build a strong version of platform.dill for use with the engine. - Fix a strong mode static error in the assert statement --- BUILD.gn | 2 +- lib/snapshot/BUILD.gn | 39 ++++++++++++++++++++++++++++++++++++++- lib/ui/natives.dart | 2 +- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 38ed755349741..9fb92a2befa55 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -6,7 +6,7 @@ group("flutter") { testonly = true public_deps = [ - "$flutter_root/lib/snapshot:compile_platform", + "$flutter_root/lib/snapshot:kernel_platform_files", "$flutter_root/lib/snapshot:generate_snapshot_bin", "$flutter_root/sky", "$flutter_root/third_party/txt", diff --git a/lib/snapshot/BUILD.gn b/lib/snapshot/BUILD.gn index 446da6e3b837d..786fdf8384d8f 100644 --- a/lib/snapshot/BUILD.gn +++ b/lib/snapshot/BUILD.gn @@ -396,9 +396,13 @@ generate_vm_patched_sdk("flutter_patched_sdk") { ] } -action("compile_platform") { +action("compile_non_strong_platform") { script = "//third_party/dart/tools/compile_platform.py" + visibility = [ + ":kernel_platform_files" + ] + sources = [ "$root_out_dir/flutter_patched_sdk/lib/libraries.json", ] @@ -423,8 +427,41 @@ action("compile_platform") { rebase_path(outputs, root_build_dir) } +action("compile_platform") { + script = "//third_party/dart/tools/compile_platform.py" + + visibility = [ + ":kernel_platform_files" + ] + + sources = [ + "$root_out_dir/flutter_patched_sdk/lib/libraries.json", + ] + + outputs = [ + "$root_out_dir/flutter_patched_sdk/platform_strong.dill", + "$root_out_dir/flutter_patched_sdk/vm_outline_strong.dill", + ] + + inputs = [] + + deps = [ + ":flutter_patched_sdk", + ] + + depfile = "$root_out_dir/flutter_patched_sdk/platform_strong.dill.d" + + args = [ + "--target=flutter", + "--strong", + "dart:core" + ] + rebase_path(sources, root_build_dir) + + rebase_path(outputs, root_build_dir) +} + group("kernel_platform_files") { public_deps = [ ":compile_platform", + ":compile_non_strong_platform", ] } diff --git a/lib/ui/natives.dart b/lib/ui/natives.dart index 99d1394005146..c2ab70a907496 100644 --- a/lib/ui/natives.dart +++ b/lib/ui/natives.dart @@ -32,7 +32,7 @@ void _setupHooks() { // In debug mode, register the schedule frame extension. developer.registerExtension('ext.ui.window.scheduleFrame', _scheduleFrame); return true; - }); + }()); } void _scheduleMicrotask(void callback()) native "ScheduleMicrotask"; From 7cece5760f0e24a966a4f492b4bc21129527a938 Mon Sep 17 00:00:00 2001 From: Siva Annamalai Date: Tue, 2 Jan 2018 16:13:15 -0800 Subject: [PATCH 4/6] Enable asserts when running debug version even in strong mode. --- runtime/dart_init.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/runtime/dart_init.cc b/runtime/dart_init.cc index 0e23d24be82d2..35d3c75dc7fb2 100644 --- a/runtime/dart_init.cc +++ b/runtime/dart_init.cc @@ -104,9 +104,14 @@ static const char* kDartWriteProtectCodeArgs[] FXL_ALLOW_UNUSED_TYPE = { "--no_write_protect_code", }; -static const char* kDartCheckedModeArgs[] = { +static const char* kDartAssertArgs[] = { // clang-format off "--enable_asserts", + // clang-format on +}; + +static const char* kDartCheckedModeArgs[] = { + // clang-format off "--enable_type_checks", "--error_on_bad_type", "--error_on_bad_override", @@ -593,8 +598,14 @@ void InitDartVM(const uint8_t* vm_snapshot_data, #endif if (settings.dart_strong_mode) { + // In strong mode we enable all the strong mode options and if running + // debug product mode we also enable asserts. PushBackAll(&args, kDartStrongModeArgs, arraysize(kDartStrongModeArgs)); + if (use_checked_mode) { + PushBackAll(&args, kDartAssertArgs, arraysize(kDartAssertArgs)); + } } else if (use_checked_mode) { + PushBackAll(&args, kDartAssertArgs, arraysize(kDartAssertArgs)); PushBackAll(&args, kDartCheckedModeArgs, arraysize(kDartCheckedModeArgs)); } From d9023b9a10811c6172858802d0b88fa1691b1aff Mon Sep 17 00:00:00 2001 From: Siva Annamalai Date: Tue, 2 Jan 2018 16:50:32 -0800 Subject: [PATCH 5/6] Use the correct platform dill file for linking when doing the aot builds. --- frontend_server/lib/server.dart | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend_server/lib/server.dart b/frontend_server/lib/server.dart index 8cf82bbd88615..6431cb24d4565 100644 --- a/frontend_server/lib/server.dart +++ b/frontend_server/lib/server.dart @@ -169,8 +169,10 @@ class _FrontendCompiler implements CompilerInterface { if (options['link-platform']) { // TODO(aam): Remove linkedDependencies once platform is directly embedded // into VM snapshot and http://dartbug.com/30111 is fixed. + final String platformKernelDill = + options['strong'] ? 'platform_strong.dill' : 'platform.dill'; compilerOptions.linkedDependencies = [ - sdkRoot.resolve('platform.dill') + sdkRoot.resolve(platformKernelDill) ]; } program = await _runWithPrintRedirection(() => compileToKernel( From b1736a13fd961d08b0f6a288757a69eece50e749 Mon Sep 17 00:00:00 2001 From: Siva Annamalai Date: Tue, 2 Jan 2018 17:21:04 -0800 Subject: [PATCH 6/6] Fix formatting issue. --- shell/common/switches.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/shell/common/switches.h b/shell/common/switches.h index b29cba9599046..4e41408569c25 100644 --- a/shell/common/switches.h +++ b/shell/common/switches.h @@ -104,9 +104,7 @@ DEF_SWITCH(DartNonCheckedMode, "precompiled and checked mode is unsupported. However, this flag " "may be specified if the user wishes to run in the debug product " "mode (i.e. with JIT or DBC) with checked mode off.") -DEF_SWITCH(DartStrongMode, - "strong", - "Enable Dart 2.0 strong mode.") +DEF_SWITCH(DartStrongMode, "strong", "Enable Dart 2.0 strong mode.") DEF_SWITCHES_END void PrintUsage(const std::string& executable_name);