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/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 6e0fa6b74e861..6431cb24d4565 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,8 +151,8 @@ class _FrontendCompiler implements CompilerInterface { ? new FileByteStore(byteStorePath) : new MemoryByteStore() ..sdkRoot = sdkRoot - ..strongMode = false - ..target = new FlutterTarget(new TargetFlags()) + ..strongMode = options['strong'] + ..target = new FlutterTarget(new TargetFlags(strongMode: options['strong'])) ..reportMessages = true; Program program; @@ -166,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( 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); } ); 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"; diff --git a/runtime/dart_init.cc b/runtime/dart_init.cc index 4049fbb7fe7e3..35d3c75dc7fb2 100644 --- a/runtime/dart_init.cc +++ b/runtime/dart_init.cc @@ -104,15 +104,28 @@ 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", // 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", }; @@ -584,8 +597,17 @@ void InitDartVM(const uint8_t* vm_snapshot_data, arraysize(kDartWriteProtectCodeArgs)); #endif - if (use_checked_mode) + 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)); + } 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..4e41408569c25 100644 --- a/shell/common/switches.h +++ b/shell/common/switches.h @@ -104,6 +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_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 4472b8b194ef6..47af58e96d737 100644 --- a/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java +++ b/shell/platform/android/io/flutter/app/FlutterActivityDelegate.java @@ -301,6 +301,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);