From 499761f0da7e8f5c19da95490507faf6bd14d425 Mon Sep 17 00:00:00 2001 From: asiva Date: Sat, 18 Aug 2018 22:50:09 +0000 Subject: [PATCH] [VM/SDK] Switch kernel isolate to run in Dart 2 mode - Switch the kernel isolate to run in Dart2 mode - Refactor build rules so bootstrapping of the front end happens with a prebuilt dart sdk - Refactor application snapshot build rules so the kernel application snapshot rule does not get into a cyclic dependency during the bootstrap stage Change-Id: I067c5f1165fb93811dcc8e390a8bf381db721e5b Reviewed-on: https://dart-review.googlesource.com/70461 Reviewed-by: Siva Annamalai Commit-Queue: Siva Annamalai --- BUILD.gn | 4 - pkg/vm/bin/kernel_service.dart | 4 +- runtime/bin/BUILD.gn | 2 + runtime/bin/main.cc | 40 +++--- runtime/bin/run_vm_tests.cc | 93 ++++++------ runtime/bin/snapshot_utils.cc | 17 ++- runtime/runtime_args.gni | 11 ++ runtime/vm/isolate.cc | 12 +- runtime/vm/isolate_reload.cc | 6 + runtime/vm/kernel_isolate.cc | 17 ++- sdk/BUILD.gn | 25 ++-- .../testing/dart/compiler_configuration.dart | 8 +- utils/analysis_server/BUILD.gn | 1 - utils/application_snapshot.gni | 132 ++++++++++++++---- utils/bazel/BUILD.gn | 1 - utils/compiler/BUILD.gn | 4 +- utils/dartanalyzer/BUILD.gn | 1 - utils/dartdevc/BUILD.gn | 6 +- utils/dartdoc/BUILD.gn | 1 - utils/dartfmt/BUILD.gn | 1 - utils/kernel-service/BUILD.gn | 38 +++-- utils/pub/BUILD.gn | 1 - 22 files changed, 265 insertions(+), 160 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index 5dbba45bff0..6f97c3c8787 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -51,12 +51,8 @@ group("runtime") { "runtime/bin:sample_extension", "runtime/bin:test_extension", "runtime/vm:kernel_platform_files($host_toolchain)", - - # TODO(rmacnak): Link this into 'dart'. - "utils/kernel-service:copy_kernel_service_snapshot", "utils/kernel-service:kernel-service", ] - if (target_supports_aot) { deps += [ "runtime/bin:precompiler_entry_points_json" ] } diff --git a/pkg/vm/bin/kernel_service.dart b/pkg/vm/bin/kernel_service.dart index 6814e1c2b61..5002f3b4a53 100644 --- a/pkg/vm/bin/kernel_service.dart +++ b/pkg/vm/bin/kernel_service.dart @@ -260,8 +260,8 @@ Future _processExpressionCompilationRequest(request) async { final SendPort port = request[1]; final int isolateId = request[2]; final String expression = request[3]; - final List definitions = request[4]; - final List typeDefinitions = request[5]; + final List definitions = request[4].cast(); + final List typeDefinitions = request[5].cast(); final String libraryUri = request[6]; final String klass = request[7]; // might be null final bool isStatic = request[8]; diff --git a/runtime/bin/BUILD.gn b/runtime/bin/BUILD.gn index a4c50fb6f49..3583691273c 100644 --- a/runtime/bin/BUILD.gn +++ b/runtime/bin/BUILD.gn @@ -1237,6 +1237,8 @@ executable("run_vm_tests") { sources = [ "builtin_nolib.cc", + "dfe.cc", + "dfe.h", "error_exit.cc", "error_exit.h", "run_vm_tests.cc", diff --git a/runtime/bin/main.cc b/runtime/bin/main.cc index c33cb6cb153..e0f1f0482f5 100644 --- a/runtime/bin/main.cc +++ b/runtime/bin/main.cc @@ -459,10 +459,7 @@ static Dart_Isolate CreateAndSetupKernelIsolate(const char* script_uri, Dart_IsolateFlags* flags, char** error, int* exit_code) { - const char* kernel_snapshot_uri = NULL; - if (Options::gen_snapshot_kind() != kAppJIT) { - kernel_snapshot_uri = dfe.frontend_filename(); - } + const char* kernel_snapshot_uri = dfe.frontend_filename(); const char* uri = kernel_snapshot_uri != NULL ? kernel_snapshot_uri : script_uri; @@ -473,20 +470,19 @@ static Dart_Isolate CreateAndSetupKernelIsolate(const char* script_uri, Dart_Isolate isolate; IsolateData* isolate_data = NULL; bool isolate_run_app_snapshot = false; - if (kernel_snapshot_uri != NULL) { - // Kernel isolate uses an app snapshot or the core libraries snapshot. - const uint8_t* isolate_snapshot_data = core_isolate_snapshot_data; - const uint8_t* isolate_snapshot_instructions = - core_isolate_snapshot_instructions; - AppSnapshot* app_snapshot = Snapshot::TryReadAppSnapshot(uri); - if (app_snapshot != NULL) { - isolate_run_app_snapshot = true; - const uint8_t* ignore_vm_snapshot_data; - const uint8_t* ignore_vm_snapshot_instructions; - app_snapshot->SetBuffers( - &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, - &isolate_snapshot_data, &isolate_snapshot_instructions); - } + AppSnapshot* app_snapshot = NULL; + // Kernel isolate uses an app snapshot or uses the dill file. + if ((kernel_snapshot_uri != NULL) && + (app_snapshot = Snapshot::TryReadAppSnapshot(kernel_snapshot_uri)) != + NULL) { + const uint8_t* isolate_snapshot_data = NULL; + const uint8_t* isolate_snapshot_instructions = NULL; + const uint8_t* ignore_vm_snapshot_data; + const uint8_t* ignore_vm_snapshot_instructions; + isolate_run_app_snapshot = true; + app_snapshot->SetBuffers( + &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, + &isolate_snapshot_data, &isolate_snapshot_instructions); IsolateData* isolate_data = new IsolateData(uri, package_root, packages_config, app_snapshot); isolate = Dart_CreateIsolate( @@ -1258,7 +1254,13 @@ void main(int argc, char** argv) { application_kernel_buffer_size); // Since we saw a dill file, it means we have to turn on all the // preview_dart_2 options. - Options::SetDart2Options(&vm_options); + if (Options::no_preview_dart_2()) { + Log::PrintErr( + "A kernel file is specified as the input, " + "--no-preview-dart-2 option is incompatible with it\n"); + Platform::Exit(kErrorExitCode); + } + Options::dfe()->set_use_dfe(); } #endif diff --git a/runtime/bin/run_vm_tests.cc b/runtime/bin/run_vm_tests.cc index e2f792d4162..ebd050ec686 100644 --- a/runtime/bin/run_vm_tests.cc +++ b/runtime/bin/run_vm_tests.cc @@ -125,43 +125,45 @@ static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, strdup("Spawning of only Kernel isolate is supported in run_vm_tests."); return NULL; } - if (kernel_snapshot == NULL) { - *error = - strdup("Kernel snapshot location has to be specified via --dfe option"); - return NULL; - } - script_uri = kernel_snapshot; + Dart_Isolate isolate = NULL; + bin::IsolateData* isolate_data = NULL; + const uint8_t* kernel_service_buffer = NULL; + intptr_t kernel_service_buffer_size = 0; - // Kernel isolate uses an app snapshot or the core libraries snapshot. - bool isolate_run_script_snapshot = false; - const uint8_t* isolate_snapshot_data = bin::core_isolate_snapshot_data; - const uint8_t* isolate_snapshot_instructions = - bin::core_isolate_snapshot_instructions; - bin::AppSnapshot* app_snapshot = NULL; - switch (bin::DartUtils::SniffForMagicNumber(script_uri)) { - case bin::DartUtils::kAppJITMagicNumber: { - app_snapshot = bin::Snapshot::TryReadAppSnapshot(script_uri); - ASSERT(app_snapshot != NULL); - - const uint8_t* ignore_vm_snapshot_data; - const uint8_t* ignore_vm_snapshot_instructions; - app_snapshot->SetBuffers( - &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, - &isolate_snapshot_data, &isolate_snapshot_instructions); - break; - } - case bin::DartUtils::kSnapshotMagicNumber: { - isolate_run_script_snapshot = true; - break; - } - default: - return NULL; + // Kernel isolate uses an app snapshot or the kernel service dill file. + if (kernel_snapshot != NULL && + (bin::DartUtils::SniffForMagicNumber(kernel_snapshot) == + bin::DartUtils::kAppJITMagicNumber)) { + script_uri = kernel_snapshot; + bin::AppSnapshot* app_snapshot = + bin::Snapshot::TryReadAppSnapshot(script_uri); + ASSERT(app_snapshot != NULL); + const uint8_t* ignore_vm_snapshot_data; + const uint8_t* ignore_vm_snapshot_instructions; + const uint8_t* isolate_snapshot_data; + const uint8_t* isolate_snapshot_instructions; + app_snapshot->SetBuffers( + &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, + &isolate_snapshot_data, &isolate_snapshot_instructions); + isolate_data = new bin::IsolateData(script_uri, package_root, + packages_config, app_snapshot); + isolate = Dart_CreateIsolate( + DART_KERNEL_ISOLATE_NAME, main, isolate_snapshot_data, + isolate_snapshot_instructions, NULL, NULL, flags, isolate_data, error); + } else { + bin::dfe.Init(); + bin::dfe.LoadKernelService(&kernel_service_buffer, + &kernel_service_buffer_size); + ASSERT(kernel_service_buffer != NULL); + isolate_data = + new bin::IsolateData(script_uri, package_root, packages_config, NULL); + isolate_data->set_kernel_buffer(const_cast(kernel_service_buffer), + kernel_service_buffer_size, + false /* take_ownership */); + isolate = Dart_CreateIsolateFromKernel( + script_uri, main, kernel_service_buffer, kernel_service_buffer_size, + flags, isolate_data, error); } - bin::IsolateData* isolate_data = new bin::IsolateData( - script_uri, package_root, packages_config, app_snapshot); - Dart_Isolate isolate = Dart_CreateIsolate( - DART_KERNEL_ISOLATE_NAME, main, isolate_snapshot_data, - isolate_snapshot_instructions, NULL, NULL, flags, isolate_data, error); if (isolate == NULL) { delete isolate_data; return NULL; @@ -169,22 +171,18 @@ static Dart_Isolate CreateIsolateAndSetup(const char* script_uri, Dart_EnterScope(); - if (isolate_run_script_snapshot) { - uint8_t* payload; - intptr_t payload_length; - void* file = bin::DartUtils::OpenFile(script_uri, false); - bin::DartUtils::ReadFile(&payload, &payload_length, file); - bin::DartUtils::CloseFile(file); - - Dart_Handle result = Dart_LoadScriptFromSnapshot(payload, payload_length); - CHECK_RESULT(result); - } - bin::DartUtils::SetOriginalWorkingDirectory(); Dart_Handle result = bin::DartUtils::PrepareForScriptLoading( false /* is_service_isolate */, false /* trace_loading */); CHECK_RESULT(result); + // Setup kernel service as the main script for this isolate. + if (kernel_service_buffer) { + result = Dart_LoadScriptFromKernel(kernel_service_buffer, + kernel_service_buffer_size); + CHECK_RESULT(result); + } + Dart_ExitScope(); Dart_ExitIsolate(); *error = Dart_IsolateMakeRunnable(isolate); @@ -217,6 +215,9 @@ static int Main(int argc, const char** argv) { // Save the console state so we can restore it later. dart::bin::Console::SaveConfig(); + // Store the executable name. + dart::bin::Platform::SetExecutableName(argv[0]); + if (argc < 2) { // Bad parameter count. PrintUsage(); diff --git a/runtime/bin/snapshot_utils.cc b/runtime/bin/snapshot_utils.cc index c5db6b94683..7f11ffa85c8 100644 --- a/runtime/bin/snapshot_utils.cc +++ b/runtime/bin/snapshot_utils.cc @@ -337,12 +337,19 @@ void Snapshot::GenerateKernel(const char* snapshot_filename, bool strong, const char* package_config) { #if !defined(EXCLUDE_CFE_AND_KERNEL_PLATFORM) && !defined(TESTING) - Dart_KernelCompilationResult result = - dfe.CompileScript(script_name, strong, false, package_config); - if (result.status != Dart_KernelCompilationStatus_Ok) { - ErrorExit(kErrorExitCode, "%s\n", result.error); + uint8_t* kernel_buffer = NULL; + intptr_t kernel_buffer_size = 0; + dfe.ReadScript(script_name, &kernel_buffer, &kernel_buffer_size); + if (kernel_buffer != NULL) { + WriteSnapshotFile(snapshot_filename, kernel_buffer, kernel_buffer_size); + } else { + Dart_KernelCompilationResult result = + dfe.CompileScript(script_name, strong, false, package_config); + if (result.status != Dart_KernelCompilationStatus_Ok) { + ErrorExit(kErrorExitCode, "%s\n", result.error); + } + WriteSnapshotFile(snapshot_filename, result.kernel, result.kernel_size); } - WriteSnapshotFile(snapshot_filename, result.kernel, result.kernel_size); #else UNREACHABLE(); #endif // !defined(EXCLUDE_CFE_AND_KERNEL_PLATFORM) && !defined(TESTING) diff --git a/runtime/runtime_args.gni b/runtime/runtime_args.gni index cfff1aff4f8..91cb9cdee52 100644 --- a/runtime/runtime_args.gni +++ b/runtime/runtime_args.gni @@ -86,3 +86,14 @@ declare_args() { # product). exclude_kernel_service = false } + +declare_args() { + # We create a kernel service app-jit snapshot only for when the target + # architecture is x64 for other cases we will use the '.dill' file + # which is already linked in the VM. + if (dart_target_arch == "x64") { + create_kernel_service_snapshot = true + } else { + create_kernel_service_snapshot = false + } +} diff --git a/runtime/vm/isolate.cc b/runtime/vm/isolate.cc index a4226969115..0a8e3f853fe 100644 --- a/runtime/vm/isolate.cc +++ b/runtime/vm/isolate.cc @@ -643,7 +643,7 @@ MessageHandler::MessageStatus IsolateMessageHandler::HandleMessage( #ifndef PRODUCT void IsolateMessageHandler::NotifyPauseOnStart() { - if (!FLAG_support_service) { + if (!FLAG_support_service || Isolate::IsVMInternalIsolate(I)) { return; } if (Service::debug_stream.enabled() || FLAG_warn_on_pause_with_no_debugger) { @@ -659,7 +659,7 @@ void IsolateMessageHandler::NotifyPauseOnStart() { } void IsolateMessageHandler::NotifyPauseOnExit() { - if (!FLAG_support_service) { + if (!FLAG_support_service || Isolate::IsVMInternalIsolate(I)) { return; } if (Service::debug_stream.enabled() || FLAG_warn_on_pause_with_no_debugger) { @@ -1310,7 +1310,8 @@ const char* Isolate::MakeRunnable() { event->Complete(); } } - if (FLAG_support_service && Service::isolate_stream.enabled()) { + if (FLAG_support_service && !Isolate::IsVMInternalIsolate(this) && + Service::isolate_stream.enabled()) { ServiceEvent runnableEvent(this, ServiceEvent::kIsolateRunnable); Service::HandleEvent(&runnableEvent); } @@ -2438,10 +2439,7 @@ void Isolate::AppendServiceExtensionCall(const Instance& closure, // done atomically. void Isolate::RegisterServiceExtensionHandler(const String& name, const Instance& closure) { - if (!FLAG_support_service) { - return; - } - if (Isolate::IsVMInternalIsolate(this)) { + if (!FLAG_support_service || Isolate::IsVMInternalIsolate(this)) { return; } GrowableObjectArray& handlers = diff --git a/runtime/vm/isolate_reload.cc b/runtime/vm/isolate_reload.cc index 22469549039..d138b12b7d4 100644 --- a/runtime/vm/isolate_reload.cc +++ b/runtime/vm/isolate_reload.cc @@ -469,6 +469,9 @@ IsolateReloadContext::~IsolateReloadContext() { } void IsolateReloadContext::ReportError(const Error& error) { + if (!FLAG_support_service || Isolate::IsVMInternalIsolate(I)) { + return; + } if (FLAG_trace_reload) { THR_Print("ISO-RELOAD: Error: %s\n", error.ToErrorCString()); } @@ -478,6 +481,9 @@ void IsolateReloadContext::ReportError(const Error& error) { } void IsolateReloadContext::ReportSuccess() { + if (!FLAG_support_service || Isolate::IsVMInternalIsolate(I)) { + return; + } ServiceEvent service_event(I, ServiceEvent::kIsolateReload); Service::HandleEvent(&service_event); } diff --git a/runtime/vm/kernel_isolate.cc b/runtime/vm/kernel_isolate.cc index c11ad21ac37..ea23d2cd9d1 100644 --- a/runtime/vm/kernel_isolate.cc +++ b/runtime/vm/kernel_isolate.cc @@ -92,9 +92,10 @@ class RunKernelTask : public ThreadPool::Task { api_flags.enable_asserts = false; api_flags.enable_error_on_bad_type = false; 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.use_dart_frontend = true; + api_flags.reify_generic_functions = true; + api_flags.strong = true; + api_flags.sync_async = true; #if !defined(DART_PRECOMPILER) && !defined(TARGET_ARCH_DBC) && \ !defined(DART_USE_INTERPRETER) api_flags.use_field_guards = true; @@ -233,12 +234,10 @@ void KernelIsolate::Run() { } void KernelIsolate::Shutdown() { - Isolate::KillIfExists(isolate_, Isolate::kInternalKillMsg); - { - MonitorLocker ml(monitor_); - while (isolate_ != NULL) { - ml.Wait(); - } + MonitorLocker ml(monitor_); + while (isolate_ != NULL) { + Isolate::KillIfExists(isolate_, Isolate::kInternalKillMsg); + ml.Wait(); } } diff --git a/sdk/BUILD.gn b/sdk/BUILD.gn index 2a8e9b56b67..b657a32b6b6 100644 --- a/sdk/BUILD.gn +++ b/sdk/BUILD.gn @@ -14,6 +14,7 @@ # fail. import("../build/dart/copy_tree.gni") +import("../runtime/runtime_args.gni") declare_args() { # Build a SDK with less stuff. It excludes dart2js, ddc, and web libraries. @@ -129,15 +130,19 @@ _platform_sdk_snapshots = [ "dartfmt", "../utils/dartfmt", ], - [ - "kernel-service", - "../utils/kernel-service", - ], [ "pub", "../utils/pub", ], ] +if (create_kernel_service_snapshot) { + _platform_sdk_snapshots += [ + [ + "kernel-service", + "../utils/kernel-service:kernel-service_snapshot", + ], + ] +} _full_sdk_snapshots = [ [ @@ -172,15 +177,19 @@ _full_sdk_snapshots = [ "kernel_worker", "../utils/bazel:kernel_worker", ], - [ - "kernel-service", - "../utils/kernel-service", - ], [ "pub", "../utils/pub", ], ] +if (create_kernel_service_snapshot) { + _full_sdk_snapshots += [ + [ + "kernel-service", + "../utils/kernel-service:kernel-service_snapshot", + ], + ] +} # Libraries that go under lib/ _full_sdk_libraries = [ diff --git a/tools/testing/dart/compiler_configuration.dart b/tools/testing/dart/compiler_configuration.dart index 7d4225682ed..f1762e6110d 100644 --- a/tools/testing/dart/compiler_configuration.dart +++ b/tools/testing/dart/compiler_configuration.dart @@ -833,14 +833,8 @@ class AppJitCompilerConfiguration extends CompilerConfiguration { int get timeoutMultiplier { var multiplier = 1; - if (_isDebug) multiplier *= 4; + if (_isDebug) multiplier *= 2; if (_isChecked) multiplier *= 2; - - // The CL in 396c92e disabled running the kernel-isolate from app-jit - // snapshots if the VM is run with --snapshot-kind=app-jit. This made our - // app-jit tests run slower. - if (previewDart2) multiplier *= 2; - return multiplier; } diff --git a/utils/analysis_server/BUILD.gn b/utils/analysis_server/BUILD.gn index 7cc939a152a..00ff1968415 100644 --- a/utils/analysis_server/BUILD.gn +++ b/utils/analysis_server/BUILD.gn @@ -5,7 +5,6 @@ import("../application_snapshot.gni") application_snapshot("analysis_server") { - dart_version = 2 main_dart = "../../pkg/analysis_server/bin/server.dart" training_args = [ "--train-using=" + rebase_path("../../pkg/analyzer_cli"), diff --git a/utils/application_snapshot.gni b/utils/application_snapshot.gni index 5ed85b2d384..e8e6d35f3e4 100644 --- a/utils/application_snapshot.gni +++ b/utils/application_snapshot.gni @@ -3,15 +3,17 @@ # BSD-style license that can be found in the LICENSE file. import("../build/dart/dart_action.gni") +import("../runtime/runtime_args.gni") _dart_root = get_path_info("..", "abspath") declare_args() { # Default to building app-jit snapshots. The simulator and cross builds # override this to script snapshots to cut down on build time. - dart_snapshot_kind = "app-jit" if (target_cpu != host_cpu) { dart_snapshot_kind = "script" + } else { + dart_snapshot_kind = "app-jit" } } @@ -24,12 +26,8 @@ declare_args() { # training_args (required): # Arguments to pass to the Dart application for the training run. # -# dart_version (optional): -# Must be 1 or 2. Defaults to 1. -# # vm_args (optional): -# Additional arguments to the Dart VM. Do not put --preview-dart-2 here. -# Instead set dart_version = 2. +# Additional arguments to the Dart VM. # # name (optional): # The name of the snapshot if different from the target name. The output @@ -46,7 +44,7 @@ declare_args() { # # output (optional): # Overrides the full output path. -template("application_snapshot") { +template("_application_snapshot") { assert(defined(invoker.main_dart), "Must specify 'main_dart'") assert(defined(invoker.training_args), "Must specify 'training_args'") snapshot_vm_args = [] @@ -76,27 +74,8 @@ template("application_snapshot") { if (defined(invoker.output)) { output = invoker.output } - # TODO(asiva), flip default once the VM is dart2 by default. - dart_version = 1 - if (defined(invoker.dart_version)) { - dart_version = invoker.dart_version - } - assert(dart_version == 1 || dart_version == 2, - "For $target_name, dart_version must be 1 or 2") dart_action(target_name) { deps = extra_deps - - if (dart_version == 1) { - snapshot_vm_args += [ "--no-preview-dart-2" ] - } else { - # HACK: When creating app-jit snapshots for Dart 2 apps, the standalone - # Dart VM binary requires the app-jit snapshot for the kernel service to - # be adjacent to it. This deps ensures that it is there, but a different - # approach will be needed when the kernel service itself switches to - # Dart 2 to avoid creating a circular dependence. - deps += [ "$_dart_root/utils/kernel-service:copy_kernel_service_snapshot"] - } - depfile = "$output.d" script = main_dart @@ -132,6 +111,107 @@ template("application_snapshot") { } } +# Creates an app-jit snapshot for a Dart2 program based on a training run. +# +# Parameters: +# main_dart (required): +# The entrypoint to the Dart application. +# +# training_args (required): +# Arguments to pass to the Dart application for the training run. +# +# vm_args (optional): +# Additional arguments to the Dart VM. Do not put --no-preview-dart-2 here. +# Instead use the template application_snapshot_dart1. +# +# name (optional): +# The name of the snapshot if different from the target name. The output +# will be in $root_gen_dir/$name.dart.snapshot. +# +# deps (optional): +# Any build dependencies. +# +# dot_packages (optional): +# The .packages file for the app. Defaults to the $_dart_root/.packages. +# +# output (optional): +# Overrides the full output path. +template("application_snapshot") { + _application_snapshot(target_name) { + forward_variables_from(invoker, "*") + if (!defined(invoker.deps)) { + deps = [] + } + deps += [ + "$_dart_root/utils/kernel-service:kernel-service_snapshot" + ] + } +} + +# Creates an app-jit snapshot for a Dart1 program based on a training run. +# +# Parameters: +# main_dart (required): +# The entrypoint to the Dart application. +# +# training_args (required): +# Arguments to pass to the Dart application for the training run. +# +# vm_args (optional): +# Additional arguments to the Dart VM. Do not put --no-preview-dart-2 here. +# +# name (optional): +# The name of the snapshot if different from the target name. The output +# will be in $root_gen_dir/$name.dart.snapshot. +# +# deps (optional): +# Any build dependencies. +# +# dot_packages (optional): +# The .packages file for the app. Defaults to the $_dart_root/.packages. +# +# output (optional): +# Overrides the full output path. +template("application_snapshot_dart1") { + _application_snapshot(target_name) { + forward_variables_from(invoker, "*") + if (!defined(invoker.vm_args)) { + vm_args = [] + } + vm_args += [ "--no-preview-dart-2" ] + } +} + +# Creates an app-jit snapshot for the common FE based on a training run. +# +# Parameters: +# main_dart (required): +# The entrypoint to the Dart application. +# +# training_args (required): +# Arguments to pass to the Dart application for the training run. +# +# vm_args (optional): +# Additional arguments to the Dart VM. Do not put --no-preview-dart-2 here. +# +# name (optional): +# The name of the snapshot if different from the target name. The output +# will be in $root_gen_dir/$name.dart.snapshot. +# +# deps (optional): +# Any build dependencies. +# +# dot_packages (optional): +# The .packages file for the app. Defaults to the $_dart_root/.packages. +# +# output (optional): +# Overrides the full output path. +template("kernel_application_snapshot") { + _application_snapshot(target_name) { + forward_variables_from(invoker, "*") + } +} + template("aot_assembly") { assert(defined(invoker.main_dart), "Must specify 'main_dart'") aot_vm_args = [] diff --git a/utils/bazel/BUILD.gn b/utils/bazel/BUILD.gn index eb754ab9968..6f6d3dad6b0 100644 --- a/utils/bazel/BUILD.gn +++ b/utils/bazel/BUILD.gn @@ -7,5 +7,4 @@ import("../application_snapshot.gni") application_snapshot("kernel_worker") { main_dart = "kernel_worker.dart" training_args = [ "--help" ] - dart_version = 2 } diff --git a/utils/compiler/BUILD.gn b/utils/compiler/BUILD.gn index d9f1cd04707..f6024c4430b 100644 --- a/utils/compiler/BUILD.gn +++ b/utils/compiler/BUILD.gn @@ -32,7 +32,7 @@ dart_action("dart2js_create_snapshot_entry") { # dart_action() needs kernel service snapshot to run in Dart 2 mode. # This can't be added as a dependency to dart_action() itself as it will # create a circular dependency. - deps += [ "../../utils/kernel-service:copy_kernel_service_snapshot" ] + deps += [ "../../utils/kernel-service:kernel-service" ] output_dir = rebase_path(target_gen_dir) @@ -58,8 +58,6 @@ dart_action("dart2js_create_snapshot_entry") { } application_snapshot("dart2js") { - dart_version = 2 - deps = [ ":compile_dart2js_platform", ":compile_dart2js_platform_strong", diff --git a/utils/dartanalyzer/BUILD.gn b/utils/dartanalyzer/BUILD.gn index ff06c7bdaa8..e41c7f62d96 100644 --- a/utils/dartanalyzer/BUILD.gn +++ b/utils/dartanalyzer/BUILD.gn @@ -21,7 +21,6 @@ analyzer_files = exec_script("../../tools/list_dart_files.py", "list lines") application_snapshot("generate_dartanalyzer_snapshot") { - dart_version = 2 main_dart = "../../pkg/analyzer_cli/bin/analyzer.dart" training_args = [ "--dart-sdk=" + rebase_path("../../sdk"), diff --git a/utils/dartdevc/BUILD.gn b/utils/dartdevc/BUILD.gn index cd84c197c66..6fecc509af6 100644 --- a/utils/dartdevc/BUILD.gn +++ b/utils/dartdevc/BUILD.gn @@ -11,8 +11,6 @@ sdk_summary = "$target_gen_dir/ddc_sdk.sum" sdk_dill = "$target_gen_dir/kernel/ddc_sdk.dill" application_snapshot("dartdevc") { - dart_version = 2 - main_dart = "../../pkg/dev_compiler/bin/dartdevc.dart" training_args = [ @@ -35,8 +33,6 @@ application_snapshot("dartdevc") { } application_snapshot("dartdevk") { - dart_version = 2 - main_dart = "../../pkg/dev_compiler/bin/dartdevk.dart" training_args = [ @@ -93,7 +89,7 @@ template("dart2js_compile") { # dart_action() needs kernel service snapshot to run in Dart 2 mode. # This can't be added as a dependency to dart_action() itself as it will # create a circular dependency. - deps += [ "../../utils/kernel-service:copy_kernel_service_snapshot" ] + deps += [ "../../utils/kernel-service:kernel-service" ] inputs = sdk_lib_files + compiler_files + dev_compiler_files + [ "$root_out_dir/dart2js_platform.dill", diff --git a/utils/dartdoc/BUILD.gn b/utils/dartdoc/BUILD.gn index 688a76ba93a..0ba4fe2b644 100644 --- a/utils/dartdoc/BUILD.gn +++ b/utils/dartdoc/BUILD.gn @@ -5,7 +5,6 @@ import("../application_snapshot.gni") application_snapshot("dartdoc") { - dart_version = 2 main_dart = "../../third_party/pkg/dartdoc/bin/dartdoc.dart" training_args = [ "--help" ] } diff --git a/utils/dartfmt/BUILD.gn b/utils/dartfmt/BUILD.gn index 99ae1edfc05..466a1b8d771 100644 --- a/utils/dartfmt/BUILD.gn +++ b/utils/dartfmt/BUILD.gn @@ -5,7 +5,6 @@ import("../application_snapshot.gni") application_snapshot("dartfmt") { - dart_version = 2 main_dart = "../../third_party/pkg_tested/dart_style/bin/format.dart" # Train it on formatting its own source. diff --git a/utils/kernel-service/BUILD.gn b/utils/kernel-service/BUILD.gn index df39bb9ef0f..489e38dcd63 100644 --- a/utils/kernel-service/BUILD.gn +++ b/utils/kernel-service/BUILD.gn @@ -4,24 +4,39 @@ import("../../build/dart/dart_action.gni") import("../../build/dart/dart_host_sdk_toolchain.gni") +import("../../runtime/runtime_args.gni") import("../application_snapshot.gni") +group("kernel-service") { + if (create_kernel_service_snapshot) { + deps = [ + # TODO(rmacnak): Link this into 'dart'. + ":copy_kernel-service_snapshot", + ] + } else { + deps = [ + ":kernel_service_dill", + ] + } +} + # TODO: Switch this to use kernel based app-jit snapshot # when we are ready to switch to the kernel based core snapshots. -application_snapshot("kernel-service") { - main_dart = "../../pkg/vm/bin/kernel_service.dart" +kernel_application_snapshot("kernel-service_snapshot") { + main_dart = "$root_gen_dir/kernel_service.dill" deps = [ - "../../runtime/vm:kernel_platform_files($dart_host_toolchain)", + ":kernel_service_dill", ] training_args = [ "--train", "file://" + rebase_path("../../pkg/compiler/lib/src/dart2js.dart"), ] + output = "$root_gen_dir/kernel-service.dart.snapshot" } -copy("copy_kernel_service_snapshot") { +copy("copy_kernel-service_snapshot") { deps = [ - ":kernel-service", + ":kernel-service_snapshot", ] sources = [ "$root_gen_dir/kernel-service.dart.snapshot", @@ -40,14 +55,15 @@ application_snapshot("frontend_server") { training_args = [ "--train", "--sdk-root=$sdk_root/", - "--platform=$sdk_root/vm_platform.dill", + "--platform=$sdk_root/vm_platform_strong.dill", ] output = "$root_out_dir/frontend_server.dart.snapshot" } prebuilt_dart_action("kernel_service_dill") { deps = [ - "../../runtime/vm:vm_legacy_platform", + "../../runtime/vm:vm_platform", + "../../runtime/vm:kernel_platform_files($dart_host_toolchain)", ] kernel_service_script = "../../pkg/vm/bin/kernel_service.dart" gen_kernel_script = "../../pkg/vm/bin/gen_kernel.dart" @@ -55,7 +71,7 @@ prebuilt_dart_action("kernel_service_dill") { inputs = [ gen_kernel_script, kernel_service_script, - "$root_out_dir/vm_platform.dill", + "$root_out_dir/vm_platform_strong.dill", ] output = "$root_gen_dir/kernel_service.dill" outputs = [ @@ -74,14 +90,10 @@ prebuilt_dart_action("kernel_service_dill") { script = gen_kernel_script - # TODO: Switch over to vm_platform_strong.dill and remove the - # flags --no-strong-mode once https://github.com/dart-lang/sdk/issues/31623 - # is fixed. args = [ "--packages=" + rebase_path("../../.packages"), - "--platform=" + rebase_path("$root_out_dir/vm_platform.dill"), + "--platform=" + rebase_path("$root_out_dir/vm_platform_strong.dill"), "--no-aot", - "--no-strong-mode", "--no-embed-sources", "--output=" + rebase_path("$root_gen_dir/kernel_service.dill"), rebase_path(kernel_service_script), diff --git a/utils/pub/BUILD.gn b/utils/pub/BUILD.gn index a87616b7d12..b2f724c1a74 100644 --- a/utils/pub/BUILD.gn +++ b/utils/pub/BUILD.gn @@ -5,7 +5,6 @@ import("../application_snapshot.gni") application_snapshot("pub") { - dart_version = 2 main_dart = "../../third_party/pkg/pub/bin/pub.dart" training_args = [ "--help" ] }