Skip to content

Commit bbc8aed

Browse files
a-sivacommit-bot@chromium.org
authored andcommitted
[VM/Runtime] - Fix for issue #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 #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]>
1 parent c909e16 commit bbc8aed

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

runtime/vm/clustered_snapshot.cc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6713,6 +6713,21 @@ char* SnapshotHeaderReader::InitializeGlobalVMFlagsFromSnapshot(
67136713
#undef CHECK_FLAG
67146714
#undef SET_FLAG
67156715

6716+
#if defined(DART_PRECOMPILED_RUNTIME)
6717+
if (FLAG_null_safety == kNullSafetyOptionUnspecified) {
6718+
if (strncmp(cursor, "null-safety", end - cursor) == 0) {
6719+
FLAG_null_safety = kNullSafetyOptionStrong;
6720+
cursor = end;
6721+
continue;
6722+
}
6723+
if (strncmp(cursor, "no-null-safety", end - cursor) == 0) {
6724+
FLAG_null_safety = kNullSafetyOptionWeak;
6725+
cursor = end;
6726+
continue;
6727+
}
6728+
}
6729+
#endif // defined(DART_PRECOMPILED_RUNTIME)
6730+
67166731
cursor = end;
67176732
}
67186733

runtime/vm/dart.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,12 +753,13 @@ bool Dart::DetectNullSafety(const char* script_uri,
753753
intptr_t kernel_buffer_size,
754754
const char* package_config,
755755
const char* original_working_directory) {
756+
#if !defined(DART_PRECOMPILED_RUNTIME)
756757
// Before creating the isolate we first determine the null safety mode
757758
// in which the isolate needs to run based on one of these factors :
758759
// - if loading from source, based on opt-in status of the source
759760
// - if loading from a kernel file, based on the mode used when
760761
// generating the kernel file
761-
// - if loading from an appJIT or AOT snapshot, based on the mode used
762+
// - if loading from an appJIT, based on the mode used
762763
// when generating the snapshot.
763764
ASSERT(FLAG_null_safety == kNullSafetyOptionUnspecified);
764765

@@ -772,7 +773,6 @@ bool Dart::DetectNullSafety(const char* script_uri,
772773
}
773774
}
774775

775-
#if !defined(DART_PRECOMPILED_RUNTIME)
776776
// If kernel_buffer is specified, it could be a self contained
777777
// kernel file or the kernel file of the application,
778778
// figure out the null safety mode by sniffing the kernel file.
@@ -791,8 +791,10 @@ bool Dart::DetectNullSafety(const char* script_uri,
791791
return KernelIsolate::DetectNullSafety(script_uri, package_config,
792792
original_working_directory);
793793
}
794-
#endif // !defined(DART_PRECOMPILED_RUNTIME)
795794
return false;
795+
#else
796+
UNREACHABLE();
797+
#endif // !defined(DART_PRECOMPILED_RUNTIME)
796798
}
797799

798800
#if defined(DART_PRECOMPILED_RUNTIME)

runtime/vm/dart_api_impl.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6032,6 +6032,10 @@ DART_EXPORT bool Dart_DetectNullSafety(const char* script_uri,
60326032
const uint8_t* snapshot_instructions,
60336033
const uint8_t* kernel_buffer,
60346034
intptr_t kernel_buffer_size) {
6035+
#if defined(DART_PRECOMPILED_RUNTIME)
6036+
ASSERT(FLAG_null_safety != kNullSafetyOptionUnspecified);
6037+
return (FLAG_null_safety == kNullSafetyOptionStrong);
6038+
#else
60356039
bool null_safety;
60366040
if (FLAG_null_safety == kNullSafetyOptionUnspecified) {
60376041
null_safety = Dart::DetectNullSafety(
@@ -6041,6 +6045,7 @@ DART_EXPORT bool Dart_DetectNullSafety(const char* script_uri,
60416045
null_safety = (FLAG_null_safety == kNullSafetyOptionStrong);
60426046
}
60436047
return null_safety;
6048+
#endif // defined(DART_PRECOMPILED_RUNTIME)
60446049
}
60456050

60466051
// --- Service support ---

0 commit comments

Comments
 (0)