Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a60a14c

Browse files
authored
Support running sound null safe kernels from dart_runner (#49598)
Before starting an isolate, `dart[_test]_component_controller` detects sound null safety status for all given kernels and fails if they aren't the same, and uses the result to set `null_safety` in isolate flags. Also switch to `core` snapshots from `core-jit` snapshots, based on #30744, as it looks like `core-jit` snapshots are not null safety agnostic. See b/315776399 ## Pre-launch Checklist - [X] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [X] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [X] I read and followed the [Flutter Style Guide] and the [C++, Objective-C, Java style guides]. - [X] I listed at least one issue that this PR fixes in the description above. - [X] I added new tests to check the change I am making or feature I am adding, or the PR is [test-exempt]. See [testing the engine] for instructions on writing and running engine tests. - [X] I updated/added relevant documentation (doc comments with `///`). - [x] I signed the [CLA]. - [X] All existing and new tests are passing.
1 parent a4543da commit a60a14c

File tree

7 files changed

+88
-79
lines changed

7 files changed

+88
-79
lines changed

shell/platform/fuchsia/dart_runner/BUILD.gn

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -248,21 +248,11 @@ template("jit_runner_package") {
248248
rebase_path("$target_gen_dir/kernel/vm_data${product_suffix}.bin")
249249
dest = "vm_snapshot_data.bin"
250250
},
251-
{
252-
path = rebase_path(
253-
"$target_gen_dir/kernel/vm_instructions${product_suffix}.bin")
254-
dest = "vm_snapshot_instructions.bin"
255-
},
256251
{
257252
path = rebase_path(
258253
"$target_gen_dir/kernel/isolate_data${product_suffix}.bin")
259254
dest = "isolate_core_snapshot_data.bin"
260255
},
261-
{
262-
path = rebase_path(
263-
"$target_gen_dir/kernel/isolate_instructions${product_suffix}.bin")
264-
dest = "isolate_core_snapshot_instructions.bin"
265-
},
266256
]
267257

268258
if (!invoker.product) {

shell/platform/fuchsia/dart_runner/dart_component_controller.cc

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -304,22 +304,13 @@ bool DartComponentController::SetUpFromKernel() {
304304
isolate_snapshot_data_)) {
305305
return false;
306306
}
307-
if (!dart_utils::MappedResource::LoadFromNamespace(
308-
nullptr, "/pkg/data/isolate_core_snapshot_instructions.bin",
309-
isolate_snapshot_instructions_, true /* executable */)) {
310-
return false;
311-
}
312-
313-
if (!CreateIsolate(isolate_snapshot_data_.address(),
314-
isolate_snapshot_instructions_.address())) {
315-
return false;
316-
}
317-
318-
Dart_EnterScope();
319307

320308
std::string str(reinterpret_cast<const char*>(manifest.address()),
321309
manifest.size());
322310
Dart_Handle library = Dart_Null();
311+
312+
bool first_library = true;
313+
bool result_sound_null_safety = false;
323314
for (size_t start = 0; start < manifest.size();) {
324315
size_t end = str.find("\n", start);
325316
if (end == std::string::npos) {
@@ -339,16 +330,46 @@ bool DartComponentController::SetUpFromKernel() {
339330
Dart_ExitScope();
340331
return false;
341332
}
333+
bool sound_null_safety = Dart_DetectNullSafety(
334+
/*script_uri=*/nullptr, /*package_config=*/nullptr,
335+
/*original_working_directory=*/nullptr,
336+
isolate_snapshot_data_.address(),
337+
/*isolate_snapshot_instructions=*/nullptr, kernel.address(),
338+
kernel.size());
339+
340+
if (first_library) {
341+
result_sound_null_safety = sound_null_safety;
342+
first_library = false;
343+
} else if (sound_null_safety != result_sound_null_safety) {
344+
FX_LOG(ERROR, LOG_TAG, "Inconsistent sound null safety");
345+
return false;
346+
}
347+
348+
kernel_peices_.emplace_back(std::move(kernel));
349+
}
350+
351+
Dart_IsolateFlags isolate_flags;
352+
Dart_IsolateFlagsInitialize(&isolate_flags);
353+
isolate_flags.null_safety = result_sound_null_safety;
354+
355+
if (!CreateIsolate(isolate_snapshot_data_.address(),
356+
/*isolate_snapshot_instructions=*/nullptr,
357+
&isolate_flags)) {
358+
return false;
359+
}
360+
361+
Dart_EnterScope();
362+
363+
for (const auto& kernel : kernel_peices_) {
342364
library = Dart_LoadLibraryFromKernel(kernel.address(), kernel.size());
343365
if (Dart_IsError(library)) {
344366
FX_LOGF(ERROR, LOG_TAG, "Cannot load library from kernel: %s",
345367
Dart_GetError(library));
346368
Dart_ExitScope();
347369
return false;
348370
}
349-
350-
kernel_peices_.emplace_back(std::move(kernel));
351371
}
372+
352373
Dart_SetRootLibrary(library);
353374

354375
Dart_Handle result = Dart_FinalizeLoading(false);
@@ -381,19 +402,18 @@ bool DartComponentController::SetUpFromAppSnapshot() {
381402
isolate_snapshot_data_)) {
382403
return false;
383404
}
384-
if (!dart_utils::MappedResource::LoadFromNamespace(
385-
namespace_, data_path_ + "/isolate_snapshot_instructions.bin",
386-
isolate_snapshot_instructions_, true /* executable */)) {
387-
return false;
388-
}
405+
isolate_data = isolate_snapshot_data_.address();
406+
isolate_instructions = nullptr;
389407
}
390-
return CreateIsolate(isolate_data, isolate_instructions);
408+
return CreateIsolate(isolate_data, isolate_instructions,
409+
/*isolate_flags=*/nullptr);
391410
#endif // defined(AOT_RUNTIME)
392411
}
393412

394413
bool DartComponentController::CreateIsolate(
395414
const uint8_t* isolate_snapshot_data,
396-
const uint8_t* isolate_snapshot_instructions) {
415+
const uint8_t* isolate_snapshot_instructions,
416+
Dart_IsolateFlags* isolate_flags) {
397417
// Create the isolate from the snapshot.
398418
char* error = nullptr;
399419

@@ -406,7 +426,7 @@ bool DartComponentController::CreateIsolate(
406426

407427
isolate_ = Dart_CreateIsolateGroup(
408428
url_.c_str(), label_.c_str(), isolate_snapshot_data,
409-
isolate_snapshot_instructions, nullptr /* flags */, state, state, &error);
429+
isolate_snapshot_instructions, isolate_flags, state, state, &error);
410430
if (!isolate_) {
411431
FX_LOGF(ERROR, LOG_TAG, "Dart_CreateIsolateGroup failed: %s", error);
412432
return false;

shell/platform/fuchsia/dart_runner/dart_component_controller.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ class DartComponentController
6161
bool SetUpFromAppSnapshot();
6262

6363
bool CreateIsolate(const uint8_t* isolate_snapshot_data,
64-
const uint8_t* isolate_snapshot_instructions);
64+
const uint8_t* isolate_snapshot_instructions,
65+
Dart_IsolateFlags* isolate_flags);
6566

6667
// |Echo|
6768
void EchoString(fidl::StringPtr value, EchoStringCallback callback) override;

shell/platform/fuchsia/dart_runner/dart_runner.cc

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ const char* kDartVMArgs[] = {
5656
#if !defined(DART_PRODUCT) && (!defined(FLUTTER_PROFILE) || !defined(NDEBUG))
5757
"--enable_asserts",
5858
#endif
59-
// Run in unsound null safety mode as some packages used in Integration
60-
// testing have not been migrated yet.
61-
"--no-sound-null-safety",
62-
// clang-format on
6359
};
6460

6561
Dart_Isolate IsolateGroupCreateCallback(const char* uri,
@@ -226,13 +222,7 @@ DartRunner::DartRunner(sys::ComponentContext* context) : context_(context) {
226222
nullptr, "/pkg/data/vm_snapshot_data.bin", vm_snapshot_data_)) {
227223
FX_LOG(FATAL, LOG_TAG, "Failed to load vm snapshot data");
228224
}
229-
if (!dart_utils::MappedResource::LoadFromNamespace(
230-
nullptr, "/pkg/data/vm_snapshot_instructions.bin",
231-
vm_snapshot_instructions_, true /* executable */)) {
232-
FX_LOG(FATAL, LOG_TAG, "Failed to load vm snapshot instructions");
233-
}
234225
params.vm_snapshot_data = vm_snapshot_data_.address();
235-
params.vm_snapshot_instructions = vm_snapshot_instructions_.address();
236226
#endif
237227
params.create_group = IsolateGroupCreateCallback;
238228
params.shutdown_isolate = IsolateShutdownCallback;

shell/platform/fuchsia/dart_runner/dart_test_component_controller.cc

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -241,27 +241,17 @@ bool DartTestComponentController::SetUpFromKernel() {
241241
isolate_snapshot_data_)) {
242242
return false;
243243
}
244-
if (!dart_utils::MappedResource::LoadFromNamespace(
245-
nullptr, "/pkg/data/isolate_core_snapshot_instructions.bin",
246-
isolate_snapshot_instructions_, true /* executable */)) {
247-
return false;
248-
}
249-
250-
if (!CreateIsolate(isolate_snapshot_data_.address(),
251-
isolate_snapshot_instructions_.address())) {
252-
return false;
253-
}
254-
255-
Dart_EnterScope();
256244

257245
std::string str(reinterpret_cast<const char*>(manifest.address()),
258246
manifest.size());
259247
Dart_Handle library = Dart_Null();
248+
249+
bool first_library = true;
250+
bool result_sound_null_safety = false;
260251
for (size_t start = 0; start < manifest.size();) {
261252
size_t end = str.find("\n", start);
262253
if (end == std::string::npos) {
263254
FX_LOG(ERROR, LOG_TAG, "Malformed manifest");
264-
Dart_ExitScope();
265255
return false;
266256
}
267257

@@ -273,18 +263,46 @@ bool DartTestComponentController::SetUpFromKernel() {
273263
kernel)) {
274264
FX_LOGF(ERROR, LOG_TAG, "Cannot load kernel from namespace: %s",
275265
path.c_str());
276-
Dart_ExitScope();
277266
return false;
278267
}
268+
bool sound_null_safety = Dart_DetectNullSafety(
269+
/*script_uri=*/nullptr, /*package_config=*/nullptr,
270+
/*original_working_directory=*/nullptr,
271+
isolate_snapshot_data_.address(),
272+
/*isolate_snapshot_instructions=*/nullptr, kernel.address(),
273+
kernel.size());
274+
275+
if (first_library) {
276+
result_sound_null_safety = sound_null_safety;
277+
first_library = false;
278+
} else if (sound_null_safety != result_sound_null_safety) {
279+
FX_LOG(ERROR, LOG_TAG, "Inconsistent sound null safety");
280+
return false;
281+
}
282+
283+
kernel_peices_.emplace_back(std::move(kernel));
284+
}
285+
286+
Dart_IsolateFlags isolate_flags;
287+
Dart_IsolateFlagsInitialize(&isolate_flags);
288+
isolate_flags.null_safety = result_sound_null_safety;
289+
290+
if (!CreateIsolate(isolate_snapshot_data_.address(),
291+
/*isolate_snapshot_instructions=*/nullptr,
292+
&isolate_flags)) {
293+
return false;
294+
}
295+
296+
Dart_EnterScope();
297+
298+
for (const auto& kernel : kernel_peices_) {
279299
library = Dart_LoadLibraryFromKernel(kernel.address(), kernel.size());
280300
if (Dart_IsError(library)) {
281301
FX_LOGF(ERROR, LOG_TAG, "Cannot load library from kernel: %s",
282302
Dart_GetError(library));
283303
Dart_ExitScope();
284304
return false;
285305
}
286-
287-
kernel_peices_.emplace_back(std::move(kernel));
288306
}
289307
Dart_SetRootLibrary(library);
290308

@@ -318,19 +336,18 @@ bool DartTestComponentController::SetUpFromAppSnapshot() {
318336
isolate_snapshot_data_)) {
319337
return false;
320338
}
321-
if (!dart_utils::MappedResource::LoadFromNamespace(
322-
namespace_, data_path_ + "/isolate_snapshot_instructions.bin",
323-
isolate_snapshot_instructions_, true /* executable */)) {
324-
return false;
325-
}
339+
isolate_data = isolate_snapshot_data_.address();
340+
isolate_instructions = nullptr;
326341
}
327-
return CreateIsolate(isolate_data, isolate_instructions);
342+
return CreateIsolate(isolate_data, isolate_instructions,
343+
/*isolate_flags=*/nullptr);
328344
#endif // defined(AOT_RUNTIME)
329345
}
330346

331347
bool DartTestComponentController::CreateIsolate(
332348
const uint8_t* isolate_snapshot_data,
333-
const uint8_t* isolate_snapshot_instructions) {
349+
const uint8_t* isolate_snapshot_instructions,
350+
Dart_IsolateFlags* isolate_flags) {
334351
// Create the isolate from the snapshot.
335352
char* error = nullptr;
336353

@@ -343,7 +360,7 @@ bool DartTestComponentController::CreateIsolate(
343360

344361
isolate_ = Dart_CreateIsolateGroup(
345362
url_.c_str(), label_.c_str(), isolate_snapshot_data,
346-
isolate_snapshot_instructions, nullptr /* flags */, state, state, &error);
363+
isolate_snapshot_instructions, isolate_flags, state, state, &error);
347364
if (!isolate_) {
348365
FX_LOGF(ERROR, LOG_TAG, "Dart_CreateIsolateGroup failed: %s", error);
349366
return false;

shell/platform/fuchsia/dart_runner/dart_test_component_controller.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ class DartTestComponentController
7777
bool SetUpFromAppSnapshot();
7878

7979
bool CreateIsolate(const uint8_t* isolate_snapshot_data,
80-
const uint8_t* isolate_snapshot_instructions);
80+
const uint8_t* isolate_snapshot_instructions,
81+
Dart_IsolateFlags* isolate_flags);
8182

8283
// |ComponentController|
8384
void Kill() override;

shell/platform/fuchsia/dart_runner/kernel/BUILD.gn

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,11 @@ template("create_kernel_core_snapshot") {
4040
inputs = [ platform_dill ]
4141

4242
vm_snapshot_data = "$target_gen_dir/vm_data${product_suffix}.bin"
43-
vm_snapshot_instructions =
44-
"$target_gen_dir/vm_instructions${product_suffix}.bin"
4543
isolate_snapshot_data = "$target_gen_dir/isolate_data${product_suffix}.bin"
46-
isolate_snapshot_instructions =
47-
"$target_gen_dir/isolate_instructions${product_suffix}.bin"
4844
snapshot_profile = "$target_gen_dir/snapshot_profile${product_suffix}.json"
4945
outputs = [
5046
vm_snapshot_data,
51-
vm_snapshot_instructions,
5247
isolate_snapshot_data,
53-
isolate_snapshot_instructions,
5448
snapshot_profile,
5549
]
5650

@@ -64,14 +58,10 @@ template("create_kernel_core_snapshot") {
6458
args = [
6559
"--enable_mirrors=false",
6660
"--deterministic",
67-
"--snapshot_kind=core-jit",
61+
"--snapshot_kind=core",
6862
"--vm_snapshot_data=" + rebase_path(vm_snapshot_data, root_build_dir),
69-
"--vm_snapshot_instructions=" +
70-
rebase_path(vm_snapshot_instructions, root_build_dir),
7163
"--isolate_snapshot_data=" +
7264
rebase_path(isolate_snapshot_data, root_build_dir),
73-
"--isolate_snapshot_instructions=" +
74-
rebase_path(isolate_snapshot_instructions, root_build_dir),
7565
"--write_v8_snapshot_profile_to=" +
7666
rebase_path(snapshot_profile, root_build_dir),
7767
]

0 commit comments

Comments
 (0)