diff --git a/pkg/vm/bin/kernel_service.dart b/pkg/vm/bin/kernel_service.dart index 76b385d6cee..d2bdbb81b7f 100644 --- a/pkg/vm/bin/kernel_service.dart +++ b/pkg/vm/bin/kernel_service.dart @@ -772,8 +772,7 @@ Future _processLoadRequest(request) async { } final SendPort port = request[1]; - final int isolateGroupId = request[7]; - + final int isolateGroupId = request[8]; if (tag == kListDependenciesTag) { await _processListDependenciesRequest(port, isolateGroupId); return; @@ -783,17 +782,18 @@ Future _processLoadRequest(request) async { final Uri? script = inputFileUri != null ? Uri.base.resolve(inputFileUri) : null; final bool incremental = request[4]; - final bool forAppJitSnapshot = request[5]; - final bool nullSafety = request[6]; - final List sourceFiles = request[8]; - final bool enableAsserts = request[9]; + final bool forSnapshot = request[5]; + final bool embedSources = request[6]; + final bool nullSafety = request[7]; + final List sourceFiles = request[9]; + final bool enableAsserts = request[10]; final List? experimentalFlags = - request[10] != null ? request[10].cast() : null; - final String? packageConfig = request[11]; - final String? multirootFilepaths = request[12]; - final String? multirootScheme = request[13]; - final String verbosityLevel = request[15]; - final bool enableMirrors = request[16]; + request[11] != null ? request[11].cast() : null; + final String? packageConfig = request[12]; + final String? multirootFilepaths = request[13]; + final String? multirootScheme = request[14]; + final String verbosityLevel = request[16]; + final bool enableMirrors = request[17]; Uri platformKernelPath; List? platformKernel = null; if (request[3] is String) { @@ -806,7 +806,7 @@ Future _processLoadRequest(request) async { computePlatformBinariesLocation().resolve('vm_platform_strong.dill'); } - final String invocationModes = forAppJitSnapshot ? 'compile' : ''; + final String invocationModes = forSnapshot ? 'compile' : ''; Compiler? compiler; @@ -873,7 +873,6 @@ Future _processLoadRequest(request) async { enableMirrors: enableMirrors); fileSystem = compiler.fileSystem; } else { - final embedSources = !forAppJitSnapshot; fileSystem = _buildFileSystem( sourceFiles, platformKernel, multirootFilepaths, multirootScheme); compiler = new SingleShotCompilerWrapper( @@ -1131,7 +1130,8 @@ Future trainInternal(String scriptUri, String? platformKernelPath) async { scriptUri, platformKernelPath, false /* incremental */, - false /* for_app_jit_snapshot */, + false /* for_snapshot */, + true /* embed_sources */, true /* null safety */, 1 /* isolateGroupId chosen randomly */, [] /* source files */, diff --git a/pkg/vm/test/kernel_service_test.dart b/pkg/vm/test/kernel_service_test.dart index 4adbb460f03..1d5198dd60c 100644 --- a/pkg/vm/test/kernel_service_test.dart +++ b/pkg/vm/test/kernel_service_test.dart @@ -116,18 +116,19 @@ Future singleShotCompile( /* [2] = String? = inputFileUri = */ entryFile, /* [3] = various = platformKernel = */ null, /* [4] = bool = incremental = */ false, - /* [5] = bool = snapshot = */ false, - /* [6] = bool = nullSafety = */ true, - /* [7] = int = isolateGroupId = */ 42, - /* [8] = List = sourceFiles = */ sourceFiles, - /* [9] = bool = enableAsserts = */ true, - /* [10] = List? = experimentalFlags = */ [], - /* [11] = String? = packageConfig = */ packageConfig, - /* [12] = String? = multirootFilepaths = */ null, - /* [13] = String? = multirootScheme = */ null, - /* [14] = String? = workingDirectory = */ null, - /* [15] = String = verbosityLevel = */ Verbosity.all.name, - /* [16] = bool = enableMirrors = */ false, + /* [5] = bool = for_snapshot = */ false, + /* [6] = bool = embed_sources = */ true, + /* [7] = bool = nullSafety = */ true, + /* [8] = int = isolateGroupId = */ 42, + /* [9] = List = sourceFiles = */ sourceFiles, + /* [10] = bool = enableAsserts = */ true, + /* [11] = List? = experimentalFlags = */ [], + /* [12] = String? = packageConfig = */ packageConfig, + /* [13] = String? = multirootFilepaths = */ null, + /* [14] = String? = multirootScheme = */ null, + /* [15] = String? = workingDirectory = */ null, + /* [16] = String = verbosityLevel = */ Verbosity.all.name, + /* [17] = bool = enableMirrors = */ false, ]); // Wait for kernel-service response. diff --git a/runtime/bin/dfe.cc b/runtime/bin/dfe.cc index ffadf0d5c7d..46fb6616146 100644 --- a/runtime/bin/dfe.cc +++ b/runtime/bin/dfe.cc @@ -188,7 +188,8 @@ const char* PathSanitizer::sanitized_uri() const { Dart_KernelCompilationResult DFE::CompileScript(const char* script_uri, bool incremental, const char* package_config, - bool for_app_jit_snapshot) { + bool for_snapshot, + bool embed_sources) { // TODO(aam): When Frontend is ready, VM should be passing vm_outline.dill // instead of vm_platform.dill to Frontend for compilation. PathSanitizer path_sanitizer(script_uri); @@ -196,7 +197,7 @@ Dart_KernelCompilationResult DFE::CompileScript(const char* script_uri, return Dart_CompileToKernel( sanitized_uri, platform_strong_dill, platform_strong_dill_size, - incremental, for_app_jit_snapshot, package_config, verbosity()); + incremental, for_snapshot, embed_sources, package_config, verbosity()); } void DFE::CompileAndReadScript(const char* script_uri, @@ -205,10 +206,11 @@ void DFE::CompileAndReadScript(const char* script_uri, char** error, int* exit_code, const char* package_config, - bool for_app_jit_snapshot) { + bool for_snapshot, + bool embed_sources) { Dart_KernelCompilationResult result = CompileScript(script_uri, use_incremental_compiler(), package_config, - for_app_jit_snapshot); + for_snapshot, embed_sources); switch (result.status) { case Dart_KernelCompilationStatus_Ok: *kernel_buffer = result.kernel; diff --git a/runtime/bin/dfe.h b/runtime/bin/dfe.h index 1ec3a12ca0a..cef87e3eb42 100644 --- a/runtime/bin/dfe.h +++ b/runtime/bin/dfe.h @@ -72,7 +72,8 @@ class DFE { Dart_KernelCompilationResult CompileScript(const char* script_uri, bool incremental, const char* package_config, - bool snapshot); + bool for_snapshot, + bool embedd_sources); // Compiles specified script and reads the resulting kernel file. // If the compilation is successful, returns a valid in memory kernel @@ -87,7 +88,8 @@ class DFE { char** error, int* exit_code, const char* package_config, - bool snapshot); + bool for_snapshot, + bool embed_sources); // Reads the script kernel file if specified 'script_uri' is a kernel file. // Returns an in memory kernel representation of the specified script is a diff --git a/runtime/bin/loader.cc b/runtime/bin/loader.cc index 11906e14847..44583ac2618 100644 --- a/runtime/bin/loader.cc +++ b/runtime/bin/loader.cc @@ -107,7 +107,8 @@ Dart_Handle Loader::LibraryTagHandler(Dart_LibraryTag tag, uint8_t* kernel_buffer = nullptr; intptr_t kernel_buffer_size = -1; dfe.CompileAndReadScript(url_string, &kernel_buffer, &kernel_buffer_size, - &error, &exit_code, nullptr, false); + &error, &exit_code, nullptr, + /*for_snapshot=*/false, /*embed_sources=*/true); if (exit_code == 0) { return Dart_LoadLibrary( WrapMallocedKernelBuffer(kernel_buffer, kernel_buffer_size)); diff --git a/runtime/bin/main_impl.cc b/runtime/bin/main_impl.cc index 3669d385611..9197663caa9 100644 --- a/runtime/bin/main_impl.cc +++ b/runtime/bin/main_impl.cc @@ -297,10 +297,14 @@ static Dart_Isolate IsolateSetupHelper(Dart_Isolate isolate, // duplicate null-safety info messages from the frontend when generating // a kernel snapshot (this flag is instead set in // Snapshot::GenerateKernel()). - const bool for_app_jit_snapshot = Options::gen_snapshot_kind() == kAppJIT; + const bool for_snapshot = Options::gen_snapshot_kind() == kAppJIT; + // If we compile for AppJIT the sources will not be included across app-jit + // snapshotting, so there's no reason CFE should embed them in the kernel. + const bool embed_sources = Options::gen_snapshot_kind() != kAppJIT; dfe.CompileAndReadScript(script_uri, &application_kernel_buffer, &application_kernel_buffer_size, error, exit_code, - resolved_packages_config, for_app_jit_snapshot); + resolved_packages_config, for_snapshot, + embed_sources); if (application_kernel_buffer == nullptr) { Dart_ExitScope(); Dart_ShutdownIsolate(); diff --git a/runtime/bin/snapshot_utils.cc b/runtime/bin/snapshot_utils.cc index 1268c91d95f..1b9ede8ddc3 100644 --- a/runtime/bin/snapshot_utils.cc +++ b/runtime/bin/snapshot_utils.cc @@ -729,8 +729,9 @@ void Snapshot::GenerateKernel(const char* snapshot_filename, WriteSnapshotFile(snapshot_filename, kernel_buffer, kernel_buffer_size); free(kernel_buffer); } else { - Dart_KernelCompilationResult result = dfe.CompileScript( - script_name, /*incremental*/ false, package_config, /*snapshot=*/true); + Dart_KernelCompilationResult result = + dfe.CompileScript(script_name, /*incremental*/ false, package_config, + /*snapshot=*/true, /*embedd_sources=*/true); if (result.status != Dart_KernelCompilationStatus_Ok) { Syslog::PrintErr("%s\n", result.error); Platform::Exit(kCompilationErrorExitCode); diff --git a/runtime/include/dart_api.h b/runtime/include/dart_api.h index 572cdf134f9..1b3962089e4 100644 --- a/runtime/include/dart_api.h +++ b/runtime/include/dart_api.h @@ -3788,6 +3788,9 @@ DART_EXPORT Dart_Port Dart_KernelPort(void); * This is used by the frontend to determine if compilation related information * should be printed to console (e.g., null safety mode). * + * \param embed_sources Set to `true` when sources should be embedded in the + * kernel file. + * * \param verbosity Specifies the logging behavior of the kernel compilation * service. * @@ -3809,6 +3812,7 @@ Dart_CompileToKernel(const char* script_uri, const intptr_t platform_kernel_size, bool incremental_compile, bool snapshot_compile, + bool embed_sources, const char* package_config, Dart_KernelCompilationVerbosityLevel verbosity); diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc index 33105f09d85..416cffadeaf 100644 --- a/runtime/vm/dart_api_impl.cc +++ b/runtime/vm/dart_api_impl.cc @@ -6137,7 +6137,8 @@ Dart_CompileToKernel(const char* script_uri, const uint8_t* platform_kernel, intptr_t platform_kernel_size, bool incremental_compile, - bool for_app_jit_snapshot, + bool for_snapshot, + bool embed_sources, const char* package_config, Dart_KernelCompilationVerbosityLevel verbosity) { API_TIMELINE_DURATION(Thread::Current()); @@ -6149,7 +6150,7 @@ Dart_CompileToKernel(const char* script_uri, #else result = KernelIsolate::CompileToKernel( script_uri, platform_kernel, platform_kernel_size, 0, nullptr, - incremental_compile, for_app_jit_snapshot, package_config, nullptr, + incremental_compile, for_snapshot, embed_sources, package_config, nullptr, nullptr, verbosity); if (incremental_compile) { Dart_KernelCompilationResult ack_result = diff --git a/runtime/vm/isolate_reload.cc b/runtime/vm/isolate_reload.cc index 535b70ad87e..4db95423f9a 100644 --- a/runtime/vm/isolate_reload.cc +++ b/runtime/vm/isolate_reload.cc @@ -1161,6 +1161,7 @@ char* IsolateGroupReloadContext::CompileToKernel(bool force_reload, root_lib_url, nullptr, 0, modified_scripts_count, modified_scripts, /*incremental_compile=*/true, /*snapshot_compile=*/false, + /*embed_sources=*/true, /*package_config=*/nullptr, /*multiroot_filepaths=*/nullptr, /*multiroot_scheme=*/nullptr); diff --git a/runtime/vm/kernel_isolate.cc b/runtime/vm/kernel_isolate.cc index aefa8da9768..809d4dbab90 100644 --- a/runtime/vm/kernel_isolate.cc +++ b/runtime/vm/kernel_isolate.cc @@ -768,7 +768,8 @@ class KernelCompilationRequest : public ValueObject { int source_files_count, Dart_SourceFile source_files[], bool incremental_compile, - bool for_app_jit_snapshot, + bool for_snapshot, + bool embed_sources, const char* package_config, const char* multiroot_filepaths, const char* multiroot_scheme, @@ -826,7 +827,11 @@ class KernelCompilationRequest : public ValueObject { Dart_CObject dart_snapshot; dart_snapshot.type = Dart_CObject_kBool; - dart_snapshot.value.as_bool = for_app_jit_snapshot; + dart_snapshot.value.as_bool = for_snapshot; + + Dart_CObject dart_embed_sources; + dart_embed_sources.type = Dart_CObject_kBool; + dart_embed_sources.value.as_bool = embed_sources; // TODO(aam): Assert that isolate exists once we move CompileAndReadScript // compilation logic out of CreateIsolateAndSetupHelper and into @@ -934,6 +939,7 @@ class KernelCompilationRequest : public ValueObject { &dart_platform_kernel, &dart_incremental, &dart_snapshot, + &dart_embed_sources, &null_safety, &isolate_id, &files, @@ -1103,7 +1109,8 @@ Dart_KernelCompilationResult KernelIsolate::CompileToKernel( int source_file_count, Dart_SourceFile source_files[], bool incremental_compile, - bool for_app_jit_snapshot, + bool for_snapshot, + bool embed_sources, const char* package_config, const char* multiroot_filepaths, const char* multiroot_scheme, @@ -1130,7 +1137,7 @@ Dart_KernelCompilationResult KernelIsolate::CompileToKernel( return request.SendAndWaitForResponse( kCompileTag, kernel_port, script_uri, platform_kernel, platform_kernel_size, source_file_count, source_files, - incremental_compile, for_app_jit_snapshot, package_config, + incremental_compile, for_snapshot, embed_sources, package_config, multiroot_filepaths, multiroot_scheme, experimental_flags_, nullptr, verbosity); } @@ -1147,7 +1154,7 @@ Dart_KernelCompilationResult KernelIsolate::ListDependencies() { KernelCompilationRequest request; return request.SendAndWaitForResponse( kListDependenciesTag, kernel_port, nullptr, nullptr, 0, 0, nullptr, false, - false, nullptr, nullptr, nullptr, experimental_flags_, nullptr, + false, false, nullptr, nullptr, nullptr, experimental_flags_, nullptr, Dart_KernelCompilationVerbosityLevel_Error); } @@ -1165,7 +1172,7 @@ Dart_KernelCompilationResult KernelIsolate::AcceptCompilation() { KernelCompilationRequest request; return request.SendAndWaitForResponse( kAcceptTag, kernel_port, nullptr, nullptr, 0, 0, nullptr, true, false, - nullptr, nullptr, nullptr, experimental_flags_, nullptr, + false, nullptr, nullptr, nullptr, experimental_flags_, nullptr, Dart_KernelCompilationVerbosityLevel_Error); } @@ -1183,7 +1190,7 @@ Dart_KernelCompilationResult KernelIsolate::RejectCompilation() { KernelCompilationRequest request; return request.SendAndWaitForResponse( kRejectTag, kernel_port, nullptr, nullptr, 0, 0, nullptr, true, false, - nullptr, nullptr, nullptr, experimental_flags_, nullptr, + false, nullptr, nullptr, nullptr, experimental_flags_, nullptr, Dart_KernelCompilationVerbosityLevel_Error); } @@ -1234,8 +1241,8 @@ Dart_KernelCompilationResult KernelIsolate::UpdateInMemorySources( KernelCompilationRequest request; return request.SendAndWaitForResponse( kUpdateSourcesTag, kernel_port, nullptr, nullptr, 0, source_files_count, - source_files, true, false, nullptr, nullptr, nullptr, experimental_flags_, - nullptr, Dart_KernelCompilationVerbosityLevel_Error); + source_files, true, false, false, nullptr, nullptr, nullptr, + experimental_flags_, nullptr, Dart_KernelCompilationVerbosityLevel_Error); } void KernelIsolate::NotifyAboutIsolateGroupShutdown( diff --git a/runtime/vm/kernel_isolate.h b/runtime/vm/kernel_isolate.h index 765ce6cd447..b1b8436d954 100644 --- a/runtime/vm/kernel_isolate.h +++ b/runtime/vm/kernel_isolate.h @@ -63,7 +63,8 @@ class KernelIsolate : public AllStatic { int source_files_count = 0, Dart_SourceFile source_files[] = nullptr, bool incremental_compile = true, - bool for_app_jit_snapshot = false, + bool for_snapshot = false, + bool embed_sources = true, const char* package_config = nullptr, const char* multiroot_filepaths = nullptr, const char* multiroot_scheme = nullptr, diff --git a/runtime/vm/unit_test.cc b/runtime/vm/unit_test.cc index 032153a7420..efc1847e5f5 100644 --- a/runtime/vm/unit_test.cc +++ b/runtime/vm/unit_test.cc @@ -332,8 +332,8 @@ char* TestCase::CompileTestScriptWithDFE(const char* url, Zone* zone = Thread::Current()->zone(); Dart_KernelCompilationResult result = KernelIsolate::CompileToKernel( url, platform_strong_dill, platform_strong_dill_size, sourcefiles_count, - sourcefiles, incrementally, false, nullptr, multiroot_filepaths, - multiroot_scheme); + sourcefiles, incrementally, /*for_snapshot=*/false, + /*embed_sources=*/true, nullptr, multiroot_filepaths, multiroot_scheme); if (result.status == Dart_KernelCompilationStatus_Ok) { if (KernelIsolate::AcceptCompilation().status != Dart_KernelCompilationStatus_Ok) {