Skip to content

Commit 6f6b1f8

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[vm] Rename --null-safety option to --sound-null-safety
Deprecated option --null-safety still remains in order to allow graceful migration. Fixes #41853 Change-Id: Ie47b1bebc9dd6532658a60743ecb85dc7fdc108c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153660 Reviewed-by: Siva Annamalai <[email protected]> Reviewed-by: Régis Crelier <[email protected]> Commit-Queue: Alexander Markov <[email protected]>
1 parent 7a87766 commit 6f6b1f8

24 files changed

+97
-83
lines changed

pkg/front_end/test/fasta/testing/suite.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ class Run extends Step<ComponentResult, int, FastaContext> {
574574
if (experimentalFlags[ExperimentalFlag.nonNullable]) {
575575
args.add("--enable-experiment=non-nullable");
576576
if (!context.weak) {
577-
args.add("--null-safety");
577+
args.add("--sound-null-safety");
578578
}
579579
}
580580
args.add(generated.path);

pkg/frontend_server/lib/frontend_server.dart

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,9 +154,12 @@ ArgParser argParser = ArgParser(allowTrailingOptions: true)
154154
help: 'Include only bytecode into the output file', defaultsTo: true)
155155
..addFlag('enable-asserts',
156156
help: 'Whether asserts will be enabled.', defaultsTo: false)
157+
..addFlag('sound-null-safety',
158+
help: 'Respect the nullability of types at runtime.', defaultsTo: null)
159+
// TODO(alexmarkov) Remove obsolete --null-safety option.
157160
..addFlag('null-safety',
158-
help:
159-
'Respect the nullability of types at runtime in casts and instance checks.',
161+
help: 'Deprecated. Please use --sound-null-safety instead.',
162+
hide: true,
160163
defaultsTo: null)
161164
..addMultiOption('enable-experiment',
162165
help: 'Comma separated list of experimental features, eg set-literals.',
@@ -407,6 +410,8 @@ class FrontendCompiler implements CompilerInterface {
407410
final String platformKernelDill =
408411
options['platform'] ?? 'platform_strong.dill';
409412
final String packagesOption = _options['packages'];
413+
final bool nullSafety =
414+
_options['sound-null-safety'] ?? _options['null-safety'];
410415
final CompilerOptions compilerOptions = CompilerOptions()
411416
..sdkRoot = sdkRoot
412417
..fileSystem = _fileSystem
@@ -418,8 +423,7 @@ class FrontendCompiler implements CompilerInterface {
418423
..experimentalFlags = parseExperimentalFlags(
419424
parseExperimentalArguments(options['enable-experiment']),
420425
onError: (msg) => errors.add(msg))
421-
..nnbdMode =
422-
(options['null-safety'] == true) ? NnbdMode.Strong : NnbdMode.Weak
426+
..nnbdMode = (nullSafety == true) ? NnbdMode.Strong : NnbdMode.Weak
423427
..onDiagnostic = _onDiagnostic;
424428

425429
if (options.wasParsed('libraries-spec')) {
@@ -469,7 +473,7 @@ class FrontendCompiler implements CompilerInterface {
469473
}
470474
}
471475

472-
if (options['null-safety'] == null &&
476+
if (nullSafety == null &&
473477
compilerOptions.experimentalFlags[ExperimentalFlag.nonNullable]) {
474478
await autoDetectNullSafetyMode(_mainSource, compilerOptions);
475479
}

pkg/vm/bin/kernel_service.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ bool allowDartInternalImport = false;
8484
// Null Safety command line options
8585
//
8686
// Note: The values of these constants must match the
87-
// values of flag null_safety in ../../../../runtime/vm/flag_list.h.
88-
// 0 - No null_safety option specified on the command line.
89-
// 1 - '--no-null-safety' specified on the command line.
90-
// 2 - '--null-safety' option specified on the command line.
87+
// values of flag sound_null_safety in ../../../../runtime/vm/flag_list.h.
88+
// 0 - No --[no-]sound-null-safety option specified on the command line.
89+
// 1 - '--no-sound-null-safety' specified on the command line.
90+
// 2 - '--sound-null-safety' option specified on the command line.
9191
const int kNullSafetyOptionUnspecified = 0;
9292
const int kNullSafetyOptionWeak = 1;
9393
const int kNullSafetyOptionStrong = 2;

pkg/vm/lib/kernel_front_end.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,12 @@ void declareCompilerOptions(ArgParser args) {
118118
help: 'The values for the environment constants (e.g. -Dkey=value).');
119119
args.addFlag('enable-asserts',
120120
help: 'Whether asserts will be enabled.', defaultsTo: false);
121+
args.addFlag('sound-null-safety',
122+
help: 'Respect the nullability of types at runtime.', defaultsTo: null);
123+
// TODO(alexmarkov) Remove obsolete --null-safety option.
121124
args.addFlag('null-safety',
122-
help:
123-
'Respect the nullability of types at runtime in casts and instance checks.',
125+
help: 'Deprecated. Please use --sound-null-safety instead.',
126+
hide: true,
124127
defaultsTo: null);
125128
args.addFlag('split-output-by-packages',
126129
help:
@@ -189,7 +192,8 @@ Future<int> runCompiler(ArgResults options, String usage) async {
189192
final bool genBytecode = options['gen-bytecode'];
190193
final bool dropAST = options['drop-ast'];
191194
final bool enableAsserts = options['enable-asserts'];
192-
final bool nullSafety = options['null-safety'];
195+
final bool nullSafety =
196+
options['sound-null-safety'] ?? options['null-safety'];
193197
final bool useProtobufTreeShaker = options['protobuf-tree-shaker'];
194198
final bool useProtobufTreeShakerV2 = options['protobuf-tree-shaker-v2'];
195199
final bool splitOutputByPackages = options['split-output-by-packages'];

pkg/vm/tool/precompiler2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ for arg in "$@"; do
2626
PACKAGES="$arg"
2727
;;
2828
--enable-asserts | \
29-
--null-safety | \
30-
--no-null-safety | \
29+
--sound-null-safety | \
30+
--no-sound-null-safety | \
3131
--enable-experiment=*)
3232
GEN_KERNEL_OPTIONS+=("$arg")
3333
OPTIONS+=("$arg")

runtime/bin/BUILD.gn

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ gen_snapshot_action("generate_snapshot_bin") {
551551
]
552552
args = [
553553
"--enable-experiment=non-nullable",
554-
"--null-safety",
554+
"--sound-null-safety",
555555
"--deterministic",
556556
"--snapshot_kind=" + dart_core_snapshot_kind,
557557
"--vm_snapshot_data=" + rebase_path(vm_snapshot_data, root_build_dir),

runtime/tests/vm/dart/run_appended_aot_snapshot_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ Future<void> main(List<String> args) async {
2929
final extraGenKernelOptions = Platform.executableArguments
3030
.where((arg) =>
3131
arg.startsWith('--enable-experiment=') ||
32-
arg == '--null-safety' ||
33-
arg == '--no-null-safety')
32+
arg == '--sound-null-safety' ||
33+
arg == '--no-sound-null-safety')
3434
.toList();
3535

3636
{

runtime/tests/vm/dart/split_aot_kernel_generation_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Future<void> runSplitAOTKernelGenerationTest(Uri testScriptUri) async {
2020
final extraGenKernelOptions = Platform.executableArguments
2121
.where((arg) =>
2222
arg.startsWith('--enable-experiment=') ||
23-
arg == '--null-safety' ||
24-
arg == '--no-null-safety')
23+
arg == '--sound-null-safety' ||
24+
arg == '--no-sound-null-safety')
2525
.toList();
2626

2727
await runGenKernel('BUILD INTERMEDIATE DILL FILE', [

runtime/tests/vm/dart/type_casts_with_null_safety_autodetection_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ runTest(String script, String output, String temp) async {
2020
File.fromUri(Platform.script.resolve(script)).copySync(scriptInTemp);
2121

2222
// Do not add Platform.executableArguments into arguments to avoid passing
23-
// --null-safety / --no-null-safety arguments.
23+
// --sound-null-safety / --no-sound-null-safety arguments.
2424
final result = await runBinary("RUN $script", Platform.executable, [
2525
'--enable-experiment=non-nullable',
2626
'--deterministic',

runtime/tests/vm/dart/v8_snapshot_profile_writer_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,8 @@ main() async {
245245
platformDill,
246246
...Platform.executableArguments.where((arg) =>
247247
arg.startsWith('--enable-experiment=') ||
248-
arg == '--null-safety' ||
249-
arg == '--no-null-safety'),
248+
arg == '--sound-null-safety' ||
249+
arg == '--no-sound-null-safety'),
250250
'-o',
251251
dillPath,
252252
_thisTestPath

runtime/tests/vm/dart_2/split_aot_kernel_generation_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ Future<void> runSplitAOTKernelGenerationTest(Uri testScriptUri) async {
2020
final extraGenKernelOptions = Platform.executableArguments
2121
.where((arg) =>
2222
arg.startsWith('--enable-experiment=') ||
23-
arg == '--null-safety' ||
24-
arg == '--no-null-safety')
23+
arg == '--sound-null-safety' ||
24+
arg == '--no-sound-null-safety')
2525
.toList();
2626

2727
await runGenKernel('BUILD INTERMEDIATE DILL FILE', [

runtime/vm/benchmark_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ static Dart_NativeFunction NativeResolver(Dart_Handle name,
359359
// Measure compile of all kernel Service(CFE) functions.
360360
//
361361
BENCHMARK(KernelServiceCompileAll) {
362-
if (FLAG_null_safety == kNullSafetyOptionStrong) {
362+
if (FLAG_sound_null_safety == kNullSafetyOptionStrong) {
363363
// TODO(bkonyi): remove this check when we build the CFE in strong mode.
364364
return;
365365
}

runtime/vm/clustered_snapshot.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6785,14 +6785,14 @@ char* SnapshotHeaderReader::InitializeGlobalVMFlagsFromSnapshot(
67856785
#undef SET_FLAG
67866786

67876787
#if defined(DART_PRECOMPILED_RUNTIME)
6788-
if (FLAG_null_safety == kNullSafetyOptionUnspecified) {
6788+
if (FLAG_sound_null_safety == kNullSafetyOptionUnspecified) {
67896789
if (strncmp(cursor, "null-safety", end - cursor) == 0) {
6790-
FLAG_null_safety = kNullSafetyOptionStrong;
6790+
FLAG_sound_null_safety = kNullSafetyOptionStrong;
67916791
cursor = end;
67926792
continue;
67936793
}
67946794
if (strncmp(cursor, "no-null-safety", end - cursor) == 0) {
6795-
FLAG_null_safety = kNullSafetyOptionWeak;
6795+
FLAG_sound_null_safety = kNullSafetyOptionWeak;
67966796
cursor = end;
67976797
continue;
67986798
}

runtime/vm/dart.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ bool Dart::DetectNullSafety(const char* script_uri,
763763
// generating the kernel file
764764
// - if loading from an appJIT, based on the mode used
765765
// when generating the snapshot.
766-
ASSERT(FLAG_null_safety == kNullSafetyOptionUnspecified);
766+
ASSERT(FLAG_sound_null_safety == kNullSafetyOptionUnspecified);
767767

768768
// If snapshot is an appJIT/AOT snapshot we will figure out the mode by
769769
// sniffing the feature string in the snapshot.
@@ -1025,7 +1025,7 @@ const char* Dart::FeaturesString(Isolate* isolate,
10251025
buffer.AddString(" no-null-safety");
10261026
}
10271027
} else {
1028-
if (FLAG_null_safety == kNullSafetyOptionStrong) {
1028+
if (FLAG_sound_null_safety == kNullSafetyOptionStrong) {
10291029
buffer.AddString(" null-safety");
10301030
} else {
10311031
buffer.AddString(" no-null-safety");

runtime/vm/dart_api_impl.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3051,7 +3051,7 @@ DART_EXPORT Dart_Handle Dart_NewListOf(Dart_CoreType_Id element_type_id,
30513051
DARTSCOPE(Thread::Current());
30523052
if (T->isolate()->null_safety() && element_type_id != Dart_CoreType_Dynamic) {
30533053
return Api::NewError(
3054-
"Cannot use legacy types with --null-safety enabled. "
3054+
"Cannot use legacy types with --sound-null-safety enabled. "
30553055
"Use Dart_NewListOfType or Dart_NewListOfTypeFilled instead.");
30563056
}
30573057
CHECK_LENGTH(length, Array::kMaxElements);
@@ -5599,7 +5599,7 @@ DART_EXPORT Dart_Handle Dart_GetType(Dart_Handle library,
55995599
Dart_Handle* type_arguments) {
56005600
if (Thread::Current()->isolate()->null_safety()) {
56015601
return Api::NewError(
5602-
"Cannot use legacy types with --null-safety enabled. "
5602+
"Cannot use legacy types with --sound-null-safety enabled. "
56035603
"Use Dart_GetNullableType or Dart_GetNonNullableType instead.");
56045604
}
56055605
return GetTypeCommon(library, class_name, number_of_type_arguments,
@@ -6033,16 +6033,16 @@ DART_EXPORT bool Dart_DetectNullSafety(const char* script_uri,
60336033
const uint8_t* kernel_buffer,
60346034
intptr_t kernel_buffer_size) {
60356035
#if defined(DART_PRECOMPILED_RUNTIME)
6036-
ASSERT(FLAG_null_safety != kNullSafetyOptionUnspecified);
6037-
return (FLAG_null_safety == kNullSafetyOptionStrong);
6036+
ASSERT(FLAG_sound_null_safety != kNullSafetyOptionUnspecified);
6037+
return (FLAG_sound_null_safety == kNullSafetyOptionStrong);
60386038
#else
60396039
bool null_safety;
6040-
if (FLAG_null_safety == kNullSafetyOptionUnspecified) {
6040+
if (FLAG_sound_null_safety == kNullSafetyOptionUnspecified) {
60416041
null_safety = Dart::DetectNullSafety(
60426042
script_uri, snapshot_data, snapshot_instructions, kernel_buffer,
60436043
kernel_buffer_size, package_config, original_working_directory);
60446044
} else {
6045-
null_safety = (FLAG_null_safety == kNullSafetyOptionStrong);
6045+
null_safety = (FLAG_sound_null_safety == kNullSafetyOptionStrong);
60466046
}
60476047
return null_safety;
60486048
#endif // defined(DART_PRECOMPILED_RUNTIME)

runtime/vm/dart_api_impl_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5335,7 +5335,7 @@ TEST_CASE(DartAPI_NewListOf) {
53355335
EXPECT_STREQ("null", str);
53365336
} else {
53375337
EXPECT_ERROR(string_list,
5338-
"Cannot use legacy types with --null-safety enabled. "
5338+
"Cannot use legacy types with --sound-null-safety enabled. "
53395339
"Use Dart_NewListOfType or Dart_NewListOfTypeFilled instead.");
53405340
}
53415341

@@ -5356,7 +5356,7 @@ TEST_CASE(DartAPI_NewListOf) {
53565356
EXPECT_STREQ("null", str);
53575357
} else {
53585358
EXPECT_ERROR(int_list,
5359-
"Cannot use legacy types with --null-safety enabled. "
5359+
"Cannot use legacy types with --sound-null-safety enabled. "
53605360
"Use Dart_NewListOfType or Dart_NewListOfTypeFilled instead.");
53615361
}
53625362
}
@@ -6222,7 +6222,7 @@ TEST_CASE(DartAPI_TypeToNullability) {
62226222
if (Dart_IsError(type)) {
62236223
EXPECT_ERROR(
62246224
type,
6225-
"Cannot use legacy types with --null-safety enabled. "
6225+
"Cannot use legacy types with --sound-null-safety enabled. "
62266226
"Use Dart_GetNullableType or Dart_GetNonNullableType instead.");
62276227

62286228
nonNullableType = Dart_GetNonNullableType(lib, name, 0, nullptr);

runtime/vm/isolate.cc

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,15 +88,20 @@ DEFINE_FLAG_HANDLER(DeterministicModeHandler,
8888
deterministic,
8989
"Enable deterministic mode.");
9090

91-
int FLAG_null_safety = kNullSafetyOptionUnspecified;
92-
static void NullSafetyHandler(bool value) {
93-
FLAG_null_safety = value ? kNullSafetyOptionStrong : kNullSafetyOptionWeak;
91+
int FLAG_sound_null_safety = kNullSafetyOptionUnspecified;
92+
static void SoundNullSafetyHandler(bool value) {
93+
FLAG_sound_null_safety =
94+
value ? kNullSafetyOptionStrong : kNullSafetyOptionWeak;
9495
}
9596

96-
DEFINE_FLAG_HANDLER(
97-
NullSafetyHandler,
98-
null_safety,
99-
"Respect the nullability of types in casts and instance checks.");
97+
DEFINE_FLAG_HANDLER(SoundNullSafetyHandler,
98+
sound_null_safety,
99+
"Respect the nullability of types at runtime.");
100+
101+
// TODO(alexmarkov) Remove obsolete --null-safety option.
102+
DEFINE_FLAG_HANDLER(SoundNullSafetyHandler,
103+
null_safety,
104+
"Respect the nullability of types at runtime.");
100105

101106
DEFINE_FLAG(bool,
102107
disable_thread_pool_limit,

runtime/vm/isolate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class WeakTable;
9999
constexpr int kNullSafetyOptionUnspecified = 0;
100100
constexpr int kNullSafetyOptionWeak = 1;
101101
constexpr int kNullSafetyOptionStrong = 2;
102-
extern int FLAG_null_safety;
102+
extern int FLAG_sound_null_safety;
103103

104104
class PendingLazyDeopt {
105105
public:

runtime/vm/kernel_isolate.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ class KernelCompilationRequest : public ValueObject {
777777
null_safety.value.as_int32 =
778778
(isolate != NULL) ? (isolate->null_safety() ? kNullSafetyOptionStrong
779779
: kNullSafetyOptionWeak)
780-
: FLAG_null_safety;
780+
: FLAG_sound_null_safety;
781781

782782
intptr_t num_experimental_flags = experimental_flags->length();
783783
Dart_CObject** experimental_flags_array =

runtime/vm/kernel_loader.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,15 +1045,17 @@ LibraryPtr KernelLoader::LoadLibrary(intptr_t index) {
10451045
library_helper.GetNonNullableByDefaultCompiledMode();
10461046
if (!I->null_safety() && mode == NNBDCompiledMode::kStrong) {
10471047
H.ReportError(
1048-
"Library '%s' was compiled with null safety (in strong mode) and it "
1049-
"requires --null-safety option at runtime",
1048+
"Library '%s' was compiled with sound null safety (in strong mode) and "
1049+
"it "
1050+
"requires --sound-null-safety option at runtime",
10501051
String::Handle(library.url()).ToCString());
10511052
}
10521053
if (I->null_safety() && (mode == NNBDCompiledMode::kWeak ||
10531054
mode == NNBDCompiledMode::kDisabled)) {
10541055
H.ReportError(
1055-
"Library '%s' was compiled without null safety (in weak mode) and it "
1056-
"cannot be used with --null-safety at runtime",
1056+
"Library '%s' was compiled without sound null safety (in weak mode) "
1057+
"and it "
1058+
"cannot be used with --sound-null-safety at runtime",
10571059
String::Handle(library.url()).ToCString());
10581060
}
10591061
library.set_nnbd_compiled_mode(mode);

runtime/vm/object.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -908,8 +908,7 @@ enum class TypeEquality {
908908
};
909909

910910
// The NNBDMode reflects the opted-in status of libraries.
911-
// Note that the weak or strong testing mode is not reflected in NNBDMode, but
912-
// imposed globally by the value of --null-safety.
911+
// Note that the weak or strong checking mode is not reflected in NNBDMode.
913912
enum class NNBDMode {
914913
// Status of the library:
915914
kLegacyLib = 0, // Library is legacy.

tests/corelib/list_removeat_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ void testModifiableList(l1) {
2626
Expect.throwsRangeError(() => l1.removeAt(-1), "negative");
2727
Expect.throwsRangeError(() => l1.removeAt(5), "too large");
2828
Expect.throws(() => l1.removeAt(null),
29-
// With --null-safety a TypeError is thrown
30-
// With --no-null-safety an ArgumentError is thrown
29+
// With sound null safety a TypeError is thrown.
30+
// Without sound null safety an ArgumentError is thrown.
3131
(e) => e is TypeError || e is ArgumentError, "is null");
3232

3333
Expect.equals(2, l1.removeAt(2), "l1-remove2");

0 commit comments

Comments
 (0)