Skip to content

Commit

Permalink
[VM/Runtime] - Fix for issue #42421
Browse files Browse the repository at this point in the history
Set global null safety flag based on the snapshot instead of trying to
detect it per isolate (was causing issues with the vm isolate loading).
Should fix #42421

Bug:42421
Change-Id: I9143560b76fedcb991e96522cbf5d820fde99f7f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151866
Reviewed-by: Alexander Markov <[email protected]>
Commit-Queue: Siva Annamalai <[email protected]>
  • Loading branch information
a-siva authored and [email protected] committed Jun 20, 2020
1 parent c909e16 commit bbc8aed
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
15 changes: 15 additions & 0 deletions runtime/vm/clustered_snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6713,6 +6713,21 @@ char* SnapshotHeaderReader::InitializeGlobalVMFlagsFromSnapshot(
#undef CHECK_FLAG
#undef SET_FLAG

#if defined(DART_PRECOMPILED_RUNTIME)
if (FLAG_null_safety == kNullSafetyOptionUnspecified) {
if (strncmp(cursor, "null-safety", end - cursor) == 0) {
FLAG_null_safety = kNullSafetyOptionStrong;
cursor = end;
continue;
}
if (strncmp(cursor, "no-null-safety", end - cursor) == 0) {
FLAG_null_safety = kNullSafetyOptionWeak;
cursor = end;
continue;
}
}
#endif // defined(DART_PRECOMPILED_RUNTIME)

cursor = end;
}

Expand Down
8 changes: 5 additions & 3 deletions runtime/vm/dart.cc
Original file line number Diff line number Diff line change
Expand Up @@ -753,12 +753,13 @@ bool Dart::DetectNullSafety(const char* script_uri,
intptr_t kernel_buffer_size,
const char* package_config,
const char* original_working_directory) {
#if !defined(DART_PRECOMPILED_RUNTIME)
// Before creating the isolate we first determine the null safety mode
// in which the isolate needs to run based on one of these factors :
// - if loading from source, based on opt-in status of the source
// - if loading from a kernel file, based on the mode used when
// generating the kernel file
// - if loading from an appJIT or AOT snapshot, based on the mode used
// - if loading from an appJIT, based on the mode used
// when generating the snapshot.
ASSERT(FLAG_null_safety == kNullSafetyOptionUnspecified);

Expand All @@ -772,7 +773,6 @@ bool Dart::DetectNullSafety(const char* script_uri,
}
}

#if !defined(DART_PRECOMPILED_RUNTIME)
// If kernel_buffer is specified, it could be a self contained
// kernel file or the kernel file of the application,
// figure out the null safety mode by sniffing the kernel file.
Expand All @@ -791,8 +791,10 @@ bool Dart::DetectNullSafety(const char* script_uri,
return KernelIsolate::DetectNullSafety(script_uri, package_config,
original_working_directory);
}
#endif // !defined(DART_PRECOMPILED_RUNTIME)
return false;
#else
UNREACHABLE();
#endif // !defined(DART_PRECOMPILED_RUNTIME)
}

#if defined(DART_PRECOMPILED_RUNTIME)
Expand Down
5 changes: 5 additions & 0 deletions runtime/vm/dart_api_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6032,6 +6032,10 @@ DART_EXPORT bool Dart_DetectNullSafety(const char* script_uri,
const uint8_t* snapshot_instructions,
const uint8_t* kernel_buffer,
intptr_t kernel_buffer_size) {
#if defined(DART_PRECOMPILED_RUNTIME)
ASSERT(FLAG_null_safety != kNullSafetyOptionUnspecified);
return (FLAG_null_safety == kNullSafetyOptionStrong);
#else
bool null_safety;
if (FLAG_null_safety == kNullSafetyOptionUnspecified) {
null_safety = Dart::DetectNullSafety(
Expand All @@ -6041,6 +6045,7 @@ DART_EXPORT bool Dart_DetectNullSafety(const char* script_uri,
null_safety = (FLAG_null_safety == kNullSafetyOptionStrong);
}
return null_safety;
#endif // defined(DART_PRECOMPILED_RUNTIME)
}

// --- Service support ---
Expand Down

0 comments on commit bbc8aed

Please sign in to comment.