From bbc8aedada6f9670c21fd142cf7771f55d6c5409 Mon Sep 17 00:00:00 2001 From: asiva Date: Sat, 20 Jun 2020 04:18:59 +0000 Subject: [PATCH] [VM/Runtime] - Fix for issue https://github.com/dart-lang/sdk/issues/42421 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 https://github.com/dart-lang/sdk/issues/42421 Bug:42421 Change-Id: I9143560b76fedcb991e96522cbf5d820fde99f7f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151866 Reviewed-by: Alexander Markov Commit-Queue: Siva Annamalai --- runtime/vm/clustered_snapshot.cc | 15 +++++++++++++++ runtime/vm/dart.cc | 8 +++++--- runtime/vm/dart_api_impl.cc | 5 +++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/runtime/vm/clustered_snapshot.cc b/runtime/vm/clustered_snapshot.cc index f3ca74d5071..4bd04c85ce3 100644 --- a/runtime/vm/clustered_snapshot.cc +++ b/runtime/vm/clustered_snapshot.cc @@ -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; } diff --git a/runtime/vm/dart.cc b/runtime/vm/dart.cc index 3ec567d8947..31f297378ad 100644 --- a/runtime/vm/dart.cc +++ b/runtime/vm/dart.cc @@ -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); @@ -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. @@ -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) diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc index b3800b5b45d..78930305403 100644 --- a/runtime/vm/dart_api_impl.cc +++ b/runtime/vm/dart_api_impl.cc @@ -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( @@ -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 ---