diff --git a/CHANGELOG.md b/CHANGELOG.md index fa402782d4a..6ee88f9f1c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## 3.5.0 +### Dart Runtime +- The Dart VM only executes sound null safe code, running of unsound null + safe code using the option `--no-sound-null-safety` has been removed. + ## 3.4.0 ### Language diff --git a/runtime/bin/BUILD.gn b/runtime/bin/BUILD.gn index 52b9bdba29e..92c06d5dc47 100644 --- a/runtime/bin/BUILD.gn +++ b/runtime/bin/BUILD.gn @@ -514,7 +514,6 @@ gen_snapshot_action("generate_snapshot_bin") { isolate_snapshot_instructions, ] args = [ - "--sound-null-safety", "--deterministic", "--snapshot_kind=core", "--vm_snapshot_data=" + rebase_path(vm_snapshot_data, root_build_dir), diff --git a/runtime/bin/analyze_snapshot.cc b/runtime/bin/analyze_snapshot.cc index 6c38f9e589a..320a7cab4d6 100644 --- a/runtime/bin/analyze_snapshot.cc +++ b/runtime/bin/analyze_snapshot.cc @@ -216,10 +216,6 @@ int RunAnalyzer(int argc, char** argv) { Dart_IsolateFlags isolate_flags; Dart_IsolateFlagsInitialize(&isolate_flags); - // Null safety can be determined from the snapshot itself - isolate_flags.null_safety = - Dart_DetectNullSafety(nullptr, nullptr, nullptr, vm_snapshot_data, - vm_snapshot_instructions, nullptr, -1); Dart_CreateIsolateGroup(nullptr, nullptr, vm_isolate_data, vm_isolate_instructions, &isolate_flags, diff --git a/runtime/bin/dartdev_isolate.cc b/runtime/bin/dartdev_isolate.cc index 297192e4dec..2fae7b07fc5 100644 --- a/runtime/bin/dartdev_isolate.cc +++ b/runtime/bin/dartdev_isolate.cc @@ -42,7 +42,6 @@ DartDevIsolate::DartDev_Result DartDevIsolate::DartDevRunner::result_ = DartDevIsolate::DartDev_Result_Unknown; char** DartDevIsolate::DartDevRunner::script_ = nullptr; char** DartDevIsolate::DartDevRunner::package_config_override_ = nullptr; -bool* DartDevIsolate::DartDevRunner::force_no_sound_null_safety_ = nullptr; std::unique_ptr DartDevIsolate::DartDevRunner::argv_ = std::unique_ptr(nullptr, [](char**) {}); @@ -109,13 +108,11 @@ void DartDevIsolate::DartDevRunner::Run( Dart_IsolateGroupCreateCallback create_isolate, char** packages_file, char** script, - bool* force_no_sound_null_safety, CommandLineOptions* dart_options) { create_isolate_ = create_isolate; dart_options_ = dart_options; package_config_override_ = packages_file; script_ = script; - force_no_sound_null_safety_ = force_no_sound_null_safety; // We've encountered an error during preliminary argument parsing so we'll // output the standard help message and exit with an error code. @@ -176,8 +173,6 @@ void DartDevIsolate::DartDevRunner::DartDevResultCallback( *package_config_override_ = Utils::StrDup(item2->value.as_string); } - *force_no_sound_null_safety_ = item3->value.as_bool; - ASSERT(GetArrayItem(message, 4)->type == Dart_CObject_kArray); Dart_CObject* args = GetArrayItem(message, 4); argc_ = args->value.as_array.length; @@ -230,7 +225,6 @@ void DartDevIsolate::DartDevRunner::RunCallback(uword args) { Dart_IsolateFlags flags; Dart_IsolateFlagsInitialize(&flags); flags.enable_asserts = false; - flags.null_safety = true; flags.use_field_guards = true; flags.use_osr = true; flags.is_system_isolate = true; @@ -306,10 +300,8 @@ DartDevIsolate::DartDev_Result DartDevIsolate::RunDartDev( Dart_IsolateGroupCreateCallback create_isolate, char** packages_file, char** script, - bool* force_no_sound_null_safety, CommandLineOptions* dart_options) { - runner_.Run(create_isolate, packages_file, script, force_no_sound_null_safety, - dart_options); + runner_.Run(create_isolate, packages_file, script, dart_options); return runner_.result(); } diff --git a/runtime/bin/dartdev_isolate.h b/runtime/bin/dartdev_isolate.h index cac3cc4138b..a5158f78285 100644 --- a/runtime/bin/dartdev_isolate.h +++ b/runtime/bin/dartdev_isolate.h @@ -58,7 +58,6 @@ class DartDevIsolate { Dart_IsolateGroupCreateCallback create_isolate, char** packages_file, char** script, - bool* sound_null_safety, CommandLineOptions* dart_options); protected: @@ -69,7 +68,6 @@ class DartDevIsolate { void Run(Dart_IsolateGroupCreateCallback create_isolate, char** package_config_override_, char** script, - bool* force_no_sound_null_safety, CommandLineOptions* dart_options); DartDev_Result result() const { return result_; } @@ -83,7 +81,6 @@ class DartDevIsolate { static DartDev_Result result_; static char** script_; static char** package_config_override_; - static bool* force_no_sound_null_safety_; static std::unique_ptr argv_; static intptr_t argc_; diff --git a/runtime/bin/gen_snapshot.cc b/runtime/bin/gen_snapshot.cc index 75cea1e262d..ad7ea2eac52 100644 --- a/runtime/bin/gen_snapshot.cc +++ b/runtime/bin/gen_snapshot.cc @@ -112,13 +112,16 @@ static const char* const kSnapshotKindNames[] = { V(save_debugging_info, debugging_info_filename) \ V(save_obfuscation_map, obfuscation_map_filename) +// We define sound_null_safety as an unused option here just to make sure +// scripts that were passing in this option do not break. #define BOOL_OPTIONS_LIST(V) \ V(compile_all, compile_all) \ V(help, help) \ V(obfuscate, obfuscate) \ V(strip, strip) \ V(verbose, verbose) \ - V(version, version) + V(version, version) \ + V(sound_null_safety, sound_null_safety) #define STRING_OPTION_DEFINITION(flag, variable) \ static const char* variable = nullptr; \ @@ -680,9 +683,6 @@ static int CreateIsolateAndSnapshot(const CommandLineOptions& inputs) { Dart_IsolateFlags isolate_flags; Dart_IsolateFlagsInitialize(&isolate_flags); - isolate_flags.null_safety = - Dart_DetectNullSafety(nullptr, nullptr, nullptr, nullptr, nullptr, - kernel_buffer, kernel_buffer_size); if (IsSnapshottingForPrecompilation()) { isolate_flags.obfuscate = obfuscate; } diff --git a/runtime/bin/main_impl.cc b/runtime/bin/main_impl.cc index 2826f4834c9..0e9331b4e0e 100644 --- a/runtime/bin/main_impl.cc +++ b/runtime/bin/main_impl.cc @@ -511,9 +511,6 @@ static Dart_Isolate CreateAndSetupServiceIsolate(const char* script_uri, const uint8_t* isolate_snapshot_data = app_isolate_snapshot_data; const uint8_t* isolate_snapshot_instructions = app_isolate_snapshot_instructions; - flags->null_safety = - Dart_DetectNullSafety(nullptr, nullptr, nullptr, isolate_snapshot_data, - isolate_snapshot_instructions, nullptr, -1); isolate = Dart_CreateIsolateGroup( script_uri, DART_VM_SERVICE_ISOLATE_NAME, isolate_snapshot_data, isolate_snapshot_instructions, flags, isolate_group_data, @@ -678,8 +675,7 @@ static Dart_Isolate CreateIsolateGroupAndSetupHelper( Dart_IsolateFlags* flags, void* callback_data, char** error, - int* exit_code, - bool force_no_sound_null_safety = false) { + int* exit_code) { int64_t start = Dart_TimelineGetMicros(); ASSERT(script_uri != nullptr); uint8_t* kernel_buffer = nullptr; @@ -714,9 +710,6 @@ static Dart_Isolate CreateIsolateGroupAndSetupHelper( } bool isolate_run_app_snapshot = true; - flags->null_safety = - Dart_DetectNullSafety(nullptr, nullptr, nullptr, isolate_snapshot_data, - isolate_snapshot_instructions, nullptr, -1); #else // JIT: Main isolate starts from the app snapshot, if any. Other isolates // use the core libraries snapshot. @@ -757,15 +750,6 @@ static Dart_Isolate CreateIsolateGroupAndSetupHelper( } PathSanitizer script_uri_sanitizer(script_uri); PathSanitizer packages_config_sanitizer(packages_config); - if (force_no_sound_null_safety) { - flags->null_safety = false; - } else { - flags->null_safety = Dart_DetectNullSafety( - script_uri_sanitizer.sanitized_uri(), - packages_config_sanitizer.sanitized_uri(), - DartUtils::original_working_directory, isolate_snapshot_data, - isolate_snapshot_instructions, kernel_buffer, kernel_buffer_size); - } #endif // !defined(DART_PRECOMPILED_RUNTIME) auto isolate_group_data = new IsolateGroupData( @@ -991,7 +975,6 @@ static void CompileAndSaveKernel(const char* script_name, void RunMainIsolate(const char* script_name, const char* package_config_override, - bool force_no_sound_null_safety, CommandLineOptions* dart_options) { if (script_name != nullptr) { const char* base_name = strrchr(script_name, '/'); @@ -1030,8 +1013,7 @@ void RunMainIsolate(const char* script_name, /* is_main_isolate */ true, script_name, "main", Options::packages_file() == nullptr ? package_config_override : Options::packages_file(), - &flags, nullptr /* callback_data */, &error, &exit_code, - force_no_sound_null_safety); + &flags, nullptr /* callback_data */, &error, &exit_code); if (isolate == nullptr) { Syslog::PrintErr("%s\n", error); @@ -1411,13 +1393,12 @@ void main(int argc, char** argv) { Dart_SetEmbedderInformationCallback(&EmbedderInformationCallback); bool ran_dart_dev = false; bool should_run_user_program = true; - bool force_no_sound_null_safety = false; #if !defined(DART_PRECOMPILED_RUNTIME) if (DartDevIsolate::should_run_dart_dev() && !Options::disable_dart_dev() && Options::gen_snapshot_kind() == SnapshotKind::kNone) { DartDevIsolate::DartDev_Result dartdev_result = DartDevIsolate::RunDartDev( CreateIsolateGroupAndSetup, &package_config_override, &script_name, - &force_no_sound_null_safety, &dart_options); + &dart_options); ASSERT(dartdev_result != DartDevIsolate::DartDev_Result_Unknown); ran_dart_dev = true; should_run_user_program = @@ -1439,8 +1420,7 @@ void main(int argc, char** argv) { CompileAndSaveKernel(script_name, package_config_override, &dart_options); } else { // Run the main isolate until we aren't told to restart. - RunMainIsolate(script_name, package_config_override, - force_no_sound_null_safety, &dart_options); + RunMainIsolate(script_name, package_config_override, &dart_options); } } diff --git a/runtime/bin/main_options.h b/runtime/bin/main_options.h index b46685c3b13..a80314e6246 100644 --- a/runtime/bin/main_options.h +++ b/runtime/bin/main_options.h @@ -30,6 +30,8 @@ namespace bin { // As STRING_OPTIONS_LIST but for boolean valued options. The default value is // always false, and the presence of the flag switches the value to true. +// we define sound_null_safety as an unused option here just to make sure +// scripts that were passing in this option do not break. #define BOOL_OPTIONS_LIST(V) \ V(version, version_option) \ V(compile_all, compile_all) \ @@ -53,7 +55,8 @@ namespace bin { V(serve_devtools, enable_devtools) \ V(no_serve_observatory, disable_observatory) \ V(serve_observatory, enable_observatory) \ - V(print_dtd, print_dtd) + V(print_dtd, print_dtd) \ + V(sound_null_safety, sound_null_safety) // Boolean flags that have a short form. #define SHORT_BOOL_OPTIONS_LIST(V) \ diff --git a/runtime/include/dart_api.h b/runtime/include/dart_api.h index 12ff2b32f93..b3dccd78c67 100644 --- a/runtime/include/dart_api.h +++ b/runtime/include/dart_api.h @@ -3812,41 +3812,7 @@ DART_EXPORT void Dart_SetDartLibrarySourcesKernel( const intptr_t platform_kernel_size); /** - * Detect the null safety opt-in status. - * - * When running from source, it is based on the opt-in status of `script_uri`. - * When running from a kernel buffer, it is based on the mode used when - * generating `kernel_buffer`. - * When running from an appJIT or AOT snapshot, it is based on the mode used - * when generating `snapshot_data`. - * - * \param script_uri Uri of the script that contains the source code - * - * \param package_config Uri of the package configuration file (either in format - * of .packages or .dart_tool/package_config.json) for the null safety - * detection to resolve package imports against. If this parameter is not - * passed the package resolution of the parent isolate should be used. - * - * \param original_working_directory current working directory when the VM - * process was launched, this is used to correctly resolve the path specified - * for package_config. - * - * \param snapshot_data Buffer containing the snapshot data of the - * isolate or NULL if no snapshot is provided. If provided, the buffers must - * remain valid until the isolate shuts down. - * - * \param snapshot_instructions Buffer containing the snapshot instructions of - * the isolate or NULL if no snapshot is provided. If provided, the buffers - * must remain valid until the isolate shuts down. - * - * \param kernel_buffer A buffer which contains a kernel/DIL program. Must - * remain valid until isolate shutdown. - * - * \param kernel_buffer_size The size of `kernel_buffer`. - * - * \return Returns true if the null safety is opted in by the input being - * run `script_uri`, `snapshot_data` or `kernel_buffer`. - * + * Always return true as the VM only supports strong null safety. */ DART_EXPORT bool Dart_DetectNullSafety(const char* script_uri, const char* package_config, diff --git a/runtime/vm/app_snapshot.cc b/runtime/vm/app_snapshot.cc index 27a087d7198..8e9b42599c0 100644 --- a/runtime/vm/app_snapshot.cc +++ b/runtime/vm/app_snapshot.cc @@ -9854,65 +9854,12 @@ char* SnapshotHeaderReader::InitializeGlobalVMFlagsFromSnapshot( #undef CHECK_FLAG #undef SET_FLAG -#if defined(DART_PRECOMPILED_RUNTIME) - if (strncmp(cursor, "null-safety", end - cursor) == 0) { - FLAG_sound_null_safety = true; - cursor = end; - continue; - } - if (strncmp(cursor, "no-null-safety", end - cursor) == 0) { - FLAG_sound_null_safety = false; - cursor = end; - continue; - } -#endif // defined(DART_PRECOMPILED_RUNTIME) - cursor = end; } return nullptr; } -bool SnapshotHeaderReader::NullSafetyFromSnapshot(const Snapshot* snapshot) { - bool null_safety = false; - SnapshotHeaderReader header_reader(snapshot); - const char* features = nullptr; - intptr_t features_length = 0; - - char* error = header_reader.ReadFeatures(&features, &features_length); - if (error != nullptr) { - return false; - } - - ASSERT(features[features_length] == '\0'); - const char* cursor = features; - while (*cursor != '\0') { - while (*cursor == ' ') { - cursor++; - } - - const char* end = strstr(cursor, " "); - if (end == nullptr) { - end = features + features_length; - } - - if (strncmp(cursor, "null-safety", end - cursor) == 0) { - cursor = end; - null_safety = true; - continue; - } - if (strncmp(cursor, "no-null-safety", end - cursor) == 0) { - cursor = end; - null_safety = false; - continue; - } - - cursor = end; - } - - return null_safety; -} - ApiErrorPtr FullSnapshotReader::ReadVMSnapshot() { SnapshotHeaderReader header_reader(kind_, buffer_, size_); diff --git a/runtime/vm/app_snapshot.h b/runtime/vm/app_snapshot.h index 598b2e26011..0cc99733846 100644 --- a/runtime/vm/app_snapshot.h +++ b/runtime/vm/app_snapshot.h @@ -72,7 +72,6 @@ class LoadingUnitSerializationData : public ZoneAllocated { class SnapshotHeaderReader { public: static char* InitializeGlobalVMFlagsFromSnapshot(const Snapshot* snapshot); - static bool NullSafetyFromSnapshot(const Snapshot* snapshot); explicit SnapshotHeaderReader(const Snapshot* snapshot) : SnapshotHeaderReader(snapshot->kind(), diff --git a/runtime/vm/benchmark_test.cc b/runtime/vm/benchmark_test.cc index 9af4e6af844..381d70ac2cd 100644 --- a/runtime/vm/benchmark_test.cc +++ b/runtime/vm/benchmark_test.cc @@ -220,9 +220,6 @@ static Dart_NativeFunction NativeResolver(Dart_Handle name, // BENCHMARK(KernelServiceCompileAll) { // kernel_service.dill is built with sound null safety. - if (!FLAG_sound_null_safety) { - return; - } bin::Builtin::SetNativeResolver(bin::Builtin::kBuiltinLibrary); bin::Builtin::SetNativeResolver(bin::Builtin::kIOLibrary); bin::Builtin::SetNativeResolver(bin::Builtin::kCLILibrary); diff --git a/runtime/vm/compiler/backend/flow_graph_test.cc b/runtime/vm/compiler/backend/flow_graph_test.cc index 7cb14db0bb4..e5c00bfcae7 100644 --- a/runtime/vm/compiler/backend/flow_graph_test.cc +++ b/runtime/vm/compiler/backend/flow_graph_test.cc @@ -328,12 +328,6 @@ ISOLATE_UNIT_TEST_CASE(FlowGraph_PhiUnboxingHeuristic_Double) { RELEASE_ASSERT(cursor.TryMatch({ kMatchAndMoveFunctionEntry, })); - if (!FLAG_sound_null_safety) { - RELEASE_ASSERT(cursor.TryMatch({ - kMatchAndMoveBranchFalse, - kMatchAndMoveTargetEntry, - })); - } RELEASE_ASSERT(cursor.TryMatch({ kMatchAndMoveUnbox, // outside of loop kMatchAndMoveCheckSmi, @@ -382,12 +376,6 @@ static void TestPhiUnboxingHeuristicSimd(const char* script) { RELEASE_ASSERT(cursor.TryMatch({ kMatchAndMoveFunctionEntry, })); - if (!FLAG_sound_null_safety) { - RELEASE_ASSERT(cursor.TryMatch({ - kMatchAndMoveBranchFalse, - kMatchAndMoveTargetEntry, - })); - } RELEASE_ASSERT(cursor.TryMatch({ kMatchAndMoveUnbox, // outside of loop kMatchAndMoveCheckSmi, diff --git a/runtime/vm/compiler/backend/il_printer.cc b/runtime/vm/compiler/backend/il_printer.cc index 2ba1c727e72..00b1676b4a5 100644 --- a/runtime/vm/compiler/backend/il_printer.cc +++ b/runtime/vm/compiler/backend/il_printer.cc @@ -71,7 +71,7 @@ class IlTestPrinter : public AllStatic { AttributesSerializer(&writer).WriteDescriptors(); writer.CloseObject(); writer.OpenObject("flags"); - writer.PrintPropertyBool("nnbd", IsolateGroup::Current()->null_safety()); + writer.PrintPropertyBool("nnbd", true); writer.CloseObject(); writer.CloseObject(); THR_Print("%s\n", writer.ToCString()); diff --git a/runtime/vm/compiler/backend/il_test.cc b/runtime/vm/compiler/backend/il_test.cc index 742782f50b4..8a89577f5eb 100644 --- a/runtime/vm/compiler/backend/il_test.cc +++ b/runtime/vm/compiler/backend/il_test.cc @@ -934,8 +934,6 @@ FlowGraph* SetupFfiFlowgraph(TestPipeline* pipeline, // Additionally test that register allocation is done correctly by clobbering // all volatile registers in the native function being called. ISOLATE_UNIT_TEST_CASE(IRTest_FfiCallInstrLeafDoesntSpill) { - SetFlagScope sfs(&FLAG_sound_null_safety, true); - const char* kScript = R"( import 'dart:ffi'; diff --git a/runtime/vm/compiler/backend/inliner.cc b/runtime/vm/compiler/backend/inliner.cc index 91bbe08acf8..eedae3e9f17 100644 --- a/runtime/vm/compiler/backend/inliner.cc +++ b/runtime/vm/compiler/backend/inliner.cc @@ -111,7 +111,7 @@ static bool IsSmiValue(Value* val, intptr_t* int_val) { } static bool IsCompilingForSoundNullSafety() { - return dart::Thread::Current()->isolate_group()->null_safety(); + return true; } // Test if a call is recursive by looking in the deoptimization environment. diff --git a/runtime/vm/compiler/backend/redundancy_elimination_test.cc b/runtime/vm/compiler/backend/redundancy_elimination_test.cc index d92bfce3a2f..cf3fcf7c28b 100644 --- a/runtime/vm/compiler/backend/redundancy_elimination_test.cc +++ b/runtime/vm/compiler/backend/redundancy_elimination_test.cc @@ -1337,11 +1337,6 @@ main() { kMatchAndMoveFunctionEntry, kMatchAndMoveCheckStackOverflow, })); - if (!FLAG_sound_null_safety) { - RELEASE_ASSERT(cursor.TryMatch({ - kMatchAndMoveCheckClass, - })); - } RELEASE_ASSERT(cursor.TryMatch({ kMatchAndMoveUnbox, kMatchAndMoveBinaryDoubleOp, @@ -1986,10 +1981,6 @@ ISOLATE_UNIT_TEST_CASE(LICM_Deopt_Regress51220) { // Verifies that deoptimization at the hoisted GuardFieldClass // doesn't result in the infinite re-optimization loop. ISOLATE_UNIT_TEST_CASE(LICM_Deopt_Regress50245) { - if (!FLAG_sound_null_safety) { - return; - } - const char* kScript = R"( class A { List foo; diff --git a/runtime/vm/compiler/backend/type_propagator_test.cc b/runtime/vm/compiler/backend/type_propagator_test.cc index 4a51b780dd9..42b3de66535 100644 --- a/runtime/vm/compiler/backend/type_propagator_test.cc +++ b/runtime/vm/compiler/backend/type_propagator_test.cc @@ -534,11 +534,6 @@ ISOLATE_UNIT_TEST_CASE(TypePropagator_RegressFlutter76919) { // is non-nullable with sound null safety. // Regression test for https://github.com/dart-lang/sdk/issues/47119. ISOLATE_UNIT_TEST_CASE(TypePropagator_NonNullableLoadStaticField) { - if (!IsolateGroup::Current()->null_safety()) { - // This test requires sound null safety. - return; - } - const char* kScript = R"( const y = 0xDEADBEEF; final int x = int.parse('0xFEEDFEED'); diff --git a/runtime/vm/compiler/backend/typed_data_aot_test.cc b/runtime/vm/compiler/backend/typed_data_aot_test.cc index 7508041850f..bb575d5c283 100644 --- a/runtime/vm/compiler/backend/typed_data_aot_test.cc +++ b/runtime/vm/compiler/backend/typed_data_aot_test.cc @@ -39,43 +39,25 @@ ISOLATE_UNIT_TEST_CASE(IRTest_TypedDataAOT_Inlining) { auto entry = flow_graph->graph_entry()->normal_entry(); EXPECT(entry != nullptr); - CheckNullInstr* check_null = nullptr; LoadFieldInstr* load_field = nullptr; GenericCheckBoundInstr* bounds_check = nullptr; LoadFieldInstr* load_untagged = nullptr; LoadIndexedInstr* load_indexed = nullptr; ILMatcher cursor(flow_graph, entry); - if (IsolateGroup::Current()->null_safety()) { - RELEASE_ASSERT(cursor.TryMatch({ - kMoveGlob, - {kMatchAndMoveLoadField, &load_field}, - kMoveGlob, - kMatchAndMoveBranchTrue, - kMoveGlob, - {kMatchAndMoveGenericCheckBound, &bounds_check}, - {kMatchAndMoveLoadField, &load_untagged}, - kMoveParallelMoves, - {kMatchAndMoveLoadIndexed, &load_indexed}, - kMoveGlob, - kMatchDartReturn, - })); - } else { - RELEASE_ASSERT(cursor.TryMatch({ - kMoveGlob, - {kMatchAndMoveCheckNull, &check_null}, - {kMatchAndMoveLoadField, &load_field}, - kMoveGlob, - kMatchAndMoveBranchTrue, - kMoveGlob, - {kMatchAndMoveGenericCheckBound, &bounds_check}, - {kMatchAndMoveLoadField, &load_untagged}, - kMoveParallelMoves, - {kMatchAndMoveLoadIndexed, &load_indexed}, - kMoveGlob, - kMatchDartReturn, - })); - } + RELEASE_ASSERT(cursor.TryMatch({ + kMoveGlob, + {kMatchAndMoveLoadField, &load_field}, + kMoveGlob, + kMatchAndMoveBranchTrue, + kMoveGlob, + {kMatchAndMoveGenericCheckBound, &bounds_check}, + {kMatchAndMoveLoadField, &load_untagged}, + kMoveParallelMoves, + {kMatchAndMoveLoadIndexed, &load_indexed}, + kMoveGlob, + kMatchDartReturn, + })); EXPECT(load_field->InputAt(0)->definition()->IsParameter()); EXPECT(bounds_check->length() @@ -127,94 +109,48 @@ ISOLATE_UNIT_TEST_CASE(IRTest_TypedDataAOT_FunctionalGetSet) { // Ensure the IL matches what we expect. ILMatcher cursor(flow_graph, entry); - if (IsolateGroup::Current()->null_safety()) { - EXPECT(cursor.TryMatch({ - // Before loop - kMoveGlob, - kMatchAndMoveLoadField, - kMoveGlob, - kMatchAndMoveBranchTrue, + EXPECT(cursor.TryMatch({ + // Before loop + kMoveGlob, + kMatchAndMoveLoadField, + kMoveGlob, + kMatchAndMoveBranchTrue, - // Loop - kMoveGlob, - // Load 1 - kMatchAndMoveGenericCheckBound, - kMoveGlob, - kMatchAndMoveLoadField, - kMoveParallelMoves, - kMatchAndMoveLoadIndexed, - kMoveGlob, - // Load 2 - kMatchAndMoveGenericCheckBound, - kMoveGlob, - kMatchAndMoveLoadField, - kMoveParallelMoves, - kMatchAndMoveLoadIndexed, - kMoveGlob, - // Store 1 - kMatchAndMoveCheckWritable, - kMoveParallelMoves, - kMatchAndMoveLoadField, - kMoveParallelMoves, - kMatchAndMoveStoreIndexed, - kMoveGlob, - // Store 2 - kMoveParallelMoves, - kMatchAndMoveLoadField, - kMoveParallelMoves, - kMatchAndMoveStoreIndexed, - kMoveGlob, + // Loop + kMoveGlob, + // Load 1 + kMatchAndMoveGenericCheckBound, + kMoveGlob, + kMatchAndMoveLoadField, + kMoveParallelMoves, + kMatchAndMoveLoadIndexed, + kMoveGlob, + // Load 2 + kMatchAndMoveGenericCheckBound, + kMoveGlob, + kMatchAndMoveLoadField, + kMoveParallelMoves, + kMatchAndMoveLoadIndexed, + kMoveGlob, + // Store 1 + kMatchAndMoveCheckWritable, + kMoveParallelMoves, + kMatchAndMoveLoadField, + kMoveParallelMoves, + kMatchAndMoveStoreIndexed, + kMoveGlob, + // Store 2 + kMoveParallelMoves, + kMatchAndMoveLoadField, + kMoveParallelMoves, + kMatchAndMoveStoreIndexed, + kMoveGlob, - // Exit the loop. - kMatchAndMoveBranchFalse, - kMoveGlob, - kMatchDartReturn, - })); - } else { - EXPECT(cursor.TryMatch({ - // Before loop - kMoveGlob, - kMatchAndMoveCheckNull, - kMatchAndMoveLoadField, - kMoveGlob, - kMatchAndMoveBranchTrue, - - // Loop - kMoveGlob, - // Load 1 - kMatchAndMoveGenericCheckBound, - kMoveGlob, - kMatchAndMoveLoadField, - kMoveParallelMoves, - kMatchAndMoveLoadIndexed, - kMoveGlob, - // Load 2 - kMatchAndMoveGenericCheckBound, - kMoveGlob, - kMatchAndMoveLoadField, - kMoveParallelMoves, - kMatchAndMoveLoadIndexed, - kMoveGlob, - // Store 1 - kMatchAndMoveCheckWritable, - kMoveParallelMoves, - kMatchAndMoveLoadField, - kMoveParallelMoves, - kMatchAndMoveStoreIndexed, - kMoveGlob, - // Store 2 - kMoveParallelMoves, - kMatchAndMoveLoadField, - kMoveParallelMoves, - kMatchAndMoveStoreIndexed, - kMoveGlob, - - // Exit the loop. - kMatchAndMoveBranchFalse, - kMoveGlob, - kMatchDartReturn, - })); - } + // Exit the loop. + kMatchAndMoveBranchFalse, + kMoveGlob, + kMatchDartReturn, + })); }; check_il("Uint8List"); @@ -270,63 +206,27 @@ ISOLATE_UNIT_TEST_CASE(IRTest_TypedDataAOT_FunctionalIndexError) { // Ensure the IL matches what we expect. ILMatcher cursor(flow_graph, entry, /*trace=*/true); - if (IsolateGroup::Current()->null_safety()) { - EXPECT(cursor.TryMatch({ - // LoadField length - kMoveGlob, - kMatchAndMoveLoadField, + EXPECT(cursor.TryMatch({ + // LoadField length + kMoveGlob, + kMatchAndMoveLoadField, - // Bounds check - kMoveGlob, - kMatchAndMoveGenericCheckBound, + // Bounds check + kMoveGlob, + kMatchAndMoveGenericCheckBound, - // Store value. - kMoveGlob, - kMatchAndMoveLoadField, - kMoveParallelMoves, - kMatchAndMoveOptionalUnbox, - kMoveParallelMoves, - kMatchAndMoveStoreIndexed, + // Store value. + kMoveGlob, + kMatchAndMoveLoadField, + kMoveParallelMoves, + kMatchAndMoveOptionalUnbox, + kMoveParallelMoves, + kMatchAndMoveStoreIndexed, - // Return - kMoveGlob, - kMatchDartReturn, - })); - } else { - EXPECT(cursor.TryMatch({ - // Receiver null check - kMoveGlob, - kMatchAndMoveCheckNull, - - // Index null check - kMoveGlob, - kMatchAndMoveCheckNull, - - // Value null check - kMoveGlob, - kMatchAndMoveCheckNull, - - // LoadField length - kMoveGlob, - kMatchAndMoveLoadField, - - // Bounds check - kMoveGlob, - kMatchAndMoveGenericCheckBound, - - // Store value. - kMoveGlob, - kMatchAndMoveLoadField, - kMoveParallelMoves, - kMatchAndMoveOptionalUnbox, - kMoveParallelMoves, - kMatchAndMoveStoreIndexed, - - // Return - kMoveGlob, - kMatchDartReturn, - })); - } + // Return + kMoveGlob, + kMatchDartReturn, + })); // Compile the graph and attach the code. pipeline.CompileGraphAndAttachFunction(); @@ -377,8 +277,7 @@ ISOLATE_UNIT_TEST_CASE(IRTest_TypedDataAOT_FunctionalIndexError) { const auto& float_value = Double::Handle(Double::New(4.2)); // With null safety nulls cannot be passed as non-nullable arguments, so // skip all error stages and only run the last stage. - const intptr_t first_stage = - IsolateGroup::Current()->null_safety() ? kLastStage : 0; + const intptr_t first_stage = kLastStage; for (intptr_t stage = first_stage; stage <= kLastStage; ++stage) { run_test("Uint8List", "int", int8_list, int_value, stage); run_test("Int8List", "int", uint8_list, int_value, stage); diff --git a/runtime/vm/dart.cc b/runtime/vm/dart.cc index 7fc13a1de68..2e2efe7c75e 100644 --- a/runtime/vm/dart.cc +++ b/runtime/vm/dart.cc @@ -1084,22 +1084,6 @@ char* Dart::FeaturesString(IsolateGroup* isolate_group, #endif } - if (!Snapshot::IsAgnosticToNullSafety(kind)) { - if (isolate_group != nullptr) { - if (isolate_group->null_safety()) { - buffer.AddString(" null-safety"); - } else { - buffer.AddString(" no-null-safety"); - } - } else { - if (FLAG_sound_null_safety) { - buffer.AddString(" null-safety"); - } else { - buffer.AddString(" no-null-safety"); - } - } - } - #undef ADD_ISOLATE_FLAG #undef ADD_D #undef ADD_C diff --git a/runtime/vm/dart_api_impl.cc b/runtime/vm/dart_api_impl.cc index af4452fc340..82cece8f263 100644 --- a/runtime/vm/dart_api_impl.cc +++ b/runtime/vm/dart_api_impl.cc @@ -3069,8 +3069,7 @@ static TypeArgumentsPtr TypeArgumentsForElementType( DART_EXPORT Dart_Handle Dart_NewListOf(Dart_CoreType_Id element_type_id, intptr_t length) { DARTSCOPE(Thread::Current()); - if (T->isolate_group()->null_safety() && - element_type_id != Dart_CoreType_Dynamic) { + if (element_type_id != Dart_CoreType_Dynamic) { return Api::NewError( "Cannot use legacy types with --sound-null-safety enabled. " "Use Dart_NewListOfType or Dart_NewListOfTypeFilled instead."); @@ -5602,13 +5601,9 @@ DART_EXPORT Dart_Handle Dart_GetType(Dart_Handle library, Dart_Handle class_name, intptr_t number_of_type_arguments, Dart_Handle* type_arguments) { - if (IsolateGroup::Current()->null_safety()) { - return Api::NewError( - "Cannot use legacy types with --sound-null-safety enabled. " - "Use Dart_GetNullableType or Dart_GetNonNullableType instead."); - } - return GetTypeCommon(library, class_name, number_of_type_arguments, - type_arguments, Nullability::kLegacy); + return Api::NewError( + "Cannot use legacy types with --sound-null-safety enabled. " + "Use Dart_GetNullableType or Dart_GetNonNullableType instead."); } DART_EXPORT Dart_Handle Dart_GetNullableType(Dart_Handle library, @@ -6113,30 +6108,7 @@ 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 we have a snapshot then try to figure out the mode by - // sniffing the feature string in the snapshot. - if (snapshot_data != nullptr) { - // Read the snapshot and check for null safety option. - const Snapshot* snapshot = Snapshot::SetupFromBuffer(snapshot_data); - if (!Snapshot::IsAgnosticToNullSafety(snapshot->kind())) { - return SnapshotHeaderReader::NullSafetyFromSnapshot(snapshot); - } - } - -#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. - if (kernel_buffer != nullptr) { - const auto null_safety = - kernel::Program::DetectNullSafety(kernel_buffer, kernel_buffer_size); - if (null_safety != NNBDCompiledMode::kInvalid) { - return null_safety == NNBDCompiledMode::kStrong; - } - } -#endif - - return FLAG_sound_null_safety; + return true; } // --- Service support --- diff --git a/runtime/vm/flag_list.h b/runtime/vm/flag_list.h index 92264e535b1..9a95ce7f31d 100644 --- a/runtime/vm/flag_list.h +++ b/runtime/vm/flag_list.h @@ -250,8 +250,6 @@ constexpr bool FLAG_support_il_printer = false; P(verify_entry_points, bool, false, \ "Throw API error on invalid member access through native API. See " \ "entry_point_pragma.md") \ - P(sound_null_safety, bool, true, \ - "Respect the nullability of types at runtime.") \ C(branch_coverage, false, false, bool, false, "Enable branch coverage") #endif // RUNTIME_VM_FLAG_LIST_H_ diff --git a/runtime/vm/isolate.cc b/runtime/vm/isolate.cc index 71863b7fc55..cb20722b7fe 100644 --- a/runtime/vm/isolate.cc +++ b/runtime/vm/isolate.cc @@ -1544,6 +1544,7 @@ void IsolateGroup::FlagsInitialize(Dart_IsolateFlags* api_flags) { #undef INIT_FROM_FLAG api_flags->is_service_isolate = false; api_flags->is_kernel_isolate = false; + api_flags->null_safety = true; } void IsolateGroup::FlagsCopyTo(Dart_IsolateFlags* api_flags) { @@ -1554,6 +1555,7 @@ void IsolateGroup::FlagsCopyTo(Dart_IsolateFlags* api_flags) { #undef INIT_FROM_FIELD api_flags->is_service_isolate = false; api_flags->is_kernel_isolate = false; + api_flags->null_safety = true; } void IsolateGroup::FlagsCopyFrom(const Dart_IsolateFlags& api_flags) { @@ -1578,7 +1580,7 @@ void IsolateGroup::FlagsCopyFrom(const Dart_IsolateFlags& api_flags) { BOOL_ISOLATE_GROUP_FLAG_LIST(SET_FROM_FLAG) // Needs to be called manually, otherwise we don't set the null_safety_set // bit. - set_null_safety(api_flags.null_safety); + set_null_safety(true); #undef FLAG_FOR_NONPRODUCT #undef FLAG_FOR_PRECOMPILER #undef FLAG_FOR_PRODUCT @@ -1595,6 +1597,7 @@ void Isolate::FlagsInitialize(Dart_IsolateFlags* api_flags) { #undef INIT_FROM_FLAG api_flags->is_service_isolate = false; api_flags->is_kernel_isolate = false; + api_flags->null_safety = true; } void Isolate::FlagsCopyTo(Dart_IsolateFlags* api_flags) const { @@ -1607,6 +1610,7 @@ void Isolate::FlagsCopyTo(Dart_IsolateFlags* api_flags) const { #undef INIT_FROM_FIELD api_flags->is_service_isolate = false; api_flags->is_kernel_isolate = false; + api_flags->null_safety = true; } void Isolate::FlagsCopyFrom(const Dart_IsolateFlags& api_flags) { diff --git a/runtime/vm/kernel.h b/runtime/vm/kernel.h index e0b7468d13a..4dd65c6b79c 100644 --- a/runtime/vm/kernel.h +++ b/runtime/vm/kernel.h @@ -61,9 +61,6 @@ enum LogicalOperator { kAnd, kOr }; class Program { public: - static NNBDCompiledMode DetectNullSafety(const uint8_t* buffer, - intptr_t buffer_length); - // Read a kernel Program from the given Reader. Note the returned Program // can potentially contain several "sub programs", though the library count // etc will reference the last "sub program" only. diff --git a/runtime/vm/kernel_binary.cc b/runtime/vm/kernel_binary.cc index 78729b2a917..6dff65c4b62 100644 --- a/runtime/vm/kernel_binary.cc +++ b/runtime/vm/kernel_binary.cc @@ -85,14 +85,6 @@ bool IsValidSdkHash(const uint8_t* sdk_hash) { return true; } -NNBDCompiledMode Program::DetectNullSafety(const uint8_t* buffer, - intptr_t buffer_length) { - Reader reader(buffer, buffer_length); - std::unique_ptr program = Program::ReadFrom(&reader, nullptr); - if (program == nullptr) return NNBDCompiledMode::kInvalid; - return program->compilation_mode_; -} - std::unique_ptr Program::ReadFrom(Reader* reader, const char** error) { if (reader->size() < 70) { // A kernel file (v43) currently contains at least the following: diff --git a/runtime/vm/kernel_isolate.cc b/runtime/vm/kernel_isolate.cc index f1fcb1fced9..99ca1c5d9cb 100644 --- a/runtime/vm/kernel_isolate.cc +++ b/runtime/vm/kernel_isolate.cc @@ -866,9 +866,7 @@ class KernelCompilationRequest : public ValueObject { Dart_CObject sound_null_safety; sound_null_safety.type = Dart_CObject_kBool; - sound_null_safety.value.as_bool = (isolate_group != nullptr) - ? isolate_group->null_safety() - : FLAG_sound_null_safety; + sound_null_safety.value.as_bool = true; intptr_t num_experimental_flags = experimental_flags->length(); Dart_CObject** experimental_flags_array = diff --git a/runtime/vm/kernel_isolate.h b/runtime/vm/kernel_isolate.h index 2490a1e49df..18e77453053 100644 --- a/runtime/vm/kernel_isolate.h +++ b/runtime/vm/kernel_isolate.h @@ -69,10 +69,6 @@ class KernelIsolate : public AllStatic { Dart_KernelCompilationVerbosityLevel verbosity = Dart_KernelCompilationVerbosityLevel_All); - static bool DetectNullSafety(const char* script_uri, - const char* package_config, - const char* original_working_directory); - static Dart_KernelCompilationResult AcceptCompilation(); static Dart_KernelCompilationResult RejectCompilation(); static Dart_KernelCompilationResult UpdateInMemorySources( diff --git a/runtime/vm/kernel_loader.cc b/runtime/vm/kernel_loader.cc index 6327fdb374c..3a848529a8c 100644 --- a/runtime/vm/kernel_loader.cc +++ b/runtime/vm/kernel_loader.cc @@ -819,14 +819,7 @@ LibraryPtr KernelLoader::LoadLibrary(intptr_t index) { "null safety and not sound null safety.", String::Handle(library.url()).ToCString()); } - if (!IG->null_safety() && mode == NNBDCompiledMode::kStrong) { - H.ReportError( - "Library '%s' was compiled with sound null safety (in strong mode) and " - "it " - "requires --sound-null-safety option at runtime", - String::Handle(library.url()).ToCString()); - } - if (IG->null_safety() && (mode == NNBDCompiledMode::kWeak)) { + if (mode == NNBDCompiledMode::kWeak) { H.ReportError( "Library '%s' was compiled without sound null safety (in weak mode) " "and it " diff --git a/runtime/vm/unit_test.cc b/runtime/vm/unit_test.cc index 6d8f4cdfd74..2328f91ea3b 100644 --- a/runtime/vm/unit_test.cc +++ b/runtime/vm/unit_test.cc @@ -115,7 +115,7 @@ Dart_Isolate TestCase::CreateIsolate(const uint8_t* data_buffer, char* err; Dart_IsolateFlags api_flags; Isolate::FlagsInitialize(&api_flags); - api_flags.null_safety = FLAG_sound_null_safety; + api_flags.null_safety = true; Dart_Isolate isolate = nullptr; if (len == 0) { isolate = Dart_CreateIsolateGroup( diff --git a/utils/dartdev/BUILD.gn b/utils/dartdev/BUILD.gn index 9bc0edfc592..5cd9e5e38ef 100644 --- a/utils/dartdev/BUILD.gn +++ b/utils/dartdev/BUILD.gn @@ -28,7 +28,7 @@ application_snapshot("generate_dartdev_snapshot") { "../dtd:dtd", ] - vm_args = [ "--sound-null-safety" ] + vm_args = [] output = "$root_gen_dir/dartdev.dart.snapshot" } diff --git a/utils/dtd/BUILD.gn b/utils/dtd/BUILD.gn index 695184ba692..876a7c292d6 100644 --- a/utils/dtd/BUILD.gn +++ b/utils/dtd/BUILD.gn @@ -20,6 +20,6 @@ application_snapshot("generate_dtd_snapshot") { main_dart = "../../pkg/dtd_impl/bin/dtd.dart" training_args = [ "--train" ] - vm_args = [ "--sound-null-safety" ] + vm_args = [] output = "$root_gen_dir/dart_tooling_daemon.dart.snapshot" }