Skip to content

Commit 55cc495

Browse files
alexmarkovcommit-bot@chromium.org
authored andcommitted
[vm/nnbd] Rename --strong-non-nullable-type-checks to --null-safety and pass it to CFE
Issue: #38845 Change-Id: I9baeb4a384a6b2de79df9f97e82c127ae4f611c0 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/137120 Commit-Queue: Alexander Markov <[email protected]> Reviewed-by: Régis Crelier <[email protected]> Reviewed-by: Liam Appelbe <[email protected]>
1 parent aa2c1a4 commit 55cc495

File tree

10 files changed

+39
-30
lines changed

10 files changed

+39
-30
lines changed

pkg/vm/bin/kernel_service.dart

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ abstract class Compiler {
8080
final Uri platformKernelPath;
8181
final bool suppressWarnings;
8282
final bool enableAsserts;
83+
final bool nullSafety;
8384
final List<String> experimentalFlags;
8485
final bool bytecode;
8586
final String packageConfig;
@@ -96,6 +97,7 @@ abstract class Compiler {
9697
Compiler(this.isolateId, this.fileSystem, this.platformKernelPath,
9798
{this.suppressWarnings: false,
9899
this.enableAsserts: false,
100+
this.nullSafety: false,
99101
this.experimentalFlags: null,
100102
this.bytecode: false,
101103
this.supportCodeCoverage: false,
@@ -135,6 +137,7 @@ abstract class Compiler {
135137
onError: (msg) => errors.add(msg))
136138
..environmentDefines = new EnvironmentMap()
137139
..enableAsserts = enableAsserts
140+
..nnbdMode = nullSafety ? NnbdMode.Strong : NnbdMode.Weak
138141
..onDiagnostic = (DiagnosticMessage message) {
139142
bool printMessage;
140143
switch (message.severity) {
@@ -281,12 +284,14 @@ class IncrementalCompilerWrapper extends Compiler {
281284
int isolateId, FileSystem fileSystem, Uri platformKernelPath,
282285
{bool suppressWarnings: false,
283286
bool enableAsserts: false,
287+
bool nullSafety: false,
284288
List<String> experimentalFlags: null,
285289
bool bytecode: false,
286290
String packageConfig: null})
287291
: super(isolateId, fileSystem, platformKernelPath,
288292
suppressWarnings: suppressWarnings,
289293
enableAsserts: enableAsserts,
294+
nullSafety: nullSafety,
290295
experimentalFlags: experimentalFlags,
291296
bytecode: bytecode,
292297
supportHotReload: true,
@@ -312,6 +317,7 @@ class IncrementalCompilerWrapper extends Compiler {
312317
isolateId, fileSystem, platformKernelPath,
313318
suppressWarnings: suppressWarnings,
314319
enableAsserts: enableAsserts,
320+
nullSafety: nullSafety,
315321
experimentalFlags: experimentalFlags,
316322
bytecode: bytecode,
317323
packageConfig: packageConfig);
@@ -342,12 +348,14 @@ class SingleShotCompilerWrapper extends Compiler {
342348
{this.requireMain: false,
343349
bool suppressWarnings: false,
344350
bool enableAsserts: false,
351+
bool nullSafety: false,
345352
List<String> experimentalFlags: null,
346353
bool bytecode: false,
347354
String packageConfig: null})
348355
: super(isolateId, fileSystem, platformKernelPath,
349356
suppressWarnings: suppressWarnings,
350357
enableAsserts: enableAsserts,
358+
nullSafety: nullSafety,
351359
experimentalFlags: experimentalFlags,
352360
bytecode: bytecode,
353361
packageConfig: packageConfig);
@@ -380,6 +388,7 @@ Future<Compiler> lookupOrBuildNewIncrementalCompiler(int isolateId,
380388
List sourceFiles, Uri platformKernelPath, List<int> platformKernel,
381389
{bool suppressWarnings: false,
382390
bool enableAsserts: false,
391+
bool nullSafety: false,
383392
List<String> experimentalFlags: null,
384393
bool bytecode: false,
385394
String packageConfig: null,
@@ -411,6 +420,7 @@ Future<Compiler> lookupOrBuildNewIncrementalCompiler(int isolateId,
411420
isolateId, fileSystem, platformKernelPath,
412421
suppressWarnings: suppressWarnings,
413422
enableAsserts: enableAsserts,
423+
nullSafety: nullSafety,
414424
experimentalFlags: experimentalFlags,
415425
bytecode: bytecode,
416426
packageConfig: packageConfig);
@@ -613,7 +623,8 @@ Future _processLoadRequest(request) async {
613623
final String inputFileUri = request[2];
614624
final Uri script =
615625
inputFileUri != null ? Uri.base.resolve(inputFileUri) : null;
616-
bool incremental = request[4];
626+
final bool incremental = request[4];
627+
final bool nullSafety = request[5];
617628
final int isolateId = request[6];
618629
final List sourceFiles = request[7];
619630
final bool suppressWarnings = request[8];
@@ -680,6 +691,7 @@ Future _processLoadRequest(request) async {
680691
isolateId, sourceFiles, platformKernelPath, platformKernel,
681692
suppressWarnings: suppressWarnings,
682693
enableAsserts: enableAsserts,
694+
nullSafety: nullSafety,
683695
experimentalFlags: experimentalFlags,
684696
bytecode: bytecode,
685697
packageConfig: packageConfig,
@@ -693,6 +705,7 @@ Future _processLoadRequest(request) async {
693705
requireMain: false,
694706
suppressWarnings: suppressWarnings,
695707
enableAsserts: enableAsserts,
708+
nullSafety: nullSafety,
696709
experimentalFlags: experimentalFlags,
697710
bytecode: bytecode,
698711
packageConfig: packageConfig);
@@ -841,7 +854,7 @@ Future trainInternal(
841854
scriptUri,
842855
platformKernelPath,
843856
false /* incremental */,
844-
true /* strong */,
857+
false /* null safety */,
845858
1 /* isolateId chosen randomly */,
846859
[] /* source files */,
847860
false /* suppress warnings */,

runtime/vm/compiler/backend/type_propagator.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ bool CompileType::IsAssignableTo(NNBDMode mode, const AbstractType& other) {
826826
const AbstractType& compile_type = *ToAbstractType();
827827

828828
if (compile_type.IsNullType()) {
829-
if (!FLAG_strong_non_nullable_type_checks) {
829+
if (!FLAG_null_safety) {
830830
// In weak mode, 'null' is assignable to any type.
831831
return true;
832832
}

runtime/vm/flag_list.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,8 @@ constexpr bool kDartUseBackgroundCompilation = true;
189189
P(reorder_basic_blocks, bool, true, "Reorder basic blocks") \
190190
C(stress_async_stacks, false, false, bool, false, \
191191
"Stress test async stack traces") \
192-
P(strong_non_nullable_type_checks, bool, false, \
193-
"Enable strong non-nullable type checking mode.") \
192+
P(null_safety, bool, false, \
193+
"Respect the nullability of types in casts and instance checks.") \
194194
P(use_table_dispatch, bool, true, "Enable dispatch table based calls.") \
195195
P(enable_isolate_groups, bool, false, "Enable isolate group support.") \
196196
P(show_invisible_frames, bool, false, \

runtime/vm/isolate_reload.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2074,7 +2074,7 @@ class FieldInvalidator {
20742074

20752075
DART_FORCE_INLINE
20762076
void CheckValueType(const Instance& value, const Field& field) {
2077-
if (!FLAG_strong_non_nullable_type_checks && value.IsNull()) {
2077+
if (!FLAG_null_safety && value.IsNull()) {
20782078
return;
20792079
}
20802080
type_ = field.type();

runtime/vm/kernel_isolate.cc

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -613,10 +613,6 @@ class KernelCompilationRequest : public ValueObject {
613613
dart_incremental.type = Dart_CObject_kBool;
614614
dart_incremental.value.as_bool = incremental_compile;
615615

616-
Dart_CObject dart_strong;
617-
dart_strong.type = Dart_CObject_kBool;
618-
dart_strong.value.as_bool = true;
619-
620616
// TODO(aam): Assert that isolate exists once we move CompileAndReadScript
621617
// compilation logic out of CreateIsolateAndSetupHelper and into
622618
// IsolateSetupHelper in main.cc.
@@ -644,6 +640,10 @@ class KernelCompilationRequest : public ValueObject {
644640
enable_asserts.value.as_bool =
645641
isolate != NULL ? isolate->asserts() : FLAG_enable_asserts;
646642

643+
Dart_CObject null_safety;
644+
null_safety.type = Dart_CObject_kBool;
645+
null_safety.value.as_bool = FLAG_null_safety;
646+
647647
intptr_t num_experimental_flags = experimental_flags->length();
648648
Dart_CObject** experimental_flags_array =
649649
new Dart_CObject*[num_experimental_flags];
@@ -702,7 +702,7 @@ class KernelCompilationRequest : public ValueObject {
702702
&uri,
703703
&dart_platform_kernel,
704704
&dart_incremental,
705-
&dart_strong,
705+
&null_safety,
706706
&isolate_id,
707707
&files,
708708
&suppress_warnings,

runtime/vm/object.cc

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17484,7 +17484,7 @@ bool Instance::IsAssignableTo(
1748417484
// In weak mode type casts, whether in legacy or opted-in libraries, the null
1748517485
// instance is detected and handled in inlined code and therefore cannot be
1748617486
// encountered here as a Dart null receiver.
17487-
ASSERT(FLAG_strong_non_nullable_type_checks || !IsNull());
17487+
ASSERT(FLAG_null_safety || !IsNull());
1748817488
// In strong mode, compute NNBD_SUBTYPE(runtimeType, other).
1748917489
// In weak mode, compute LEGACY_SUBTYPE(runtimeType, other).
1749017490
return RuntimeTypeIsSubtypeOf(mode, other, other_instantiator_type_arguments,
@@ -17543,7 +17543,7 @@ bool Instance::RuntimeTypeIsSubtypeOf(
1754317543
return true;
1754417544
}
1754517545
// In weak testing mode, Null type is a subtype of any type.
17546-
if (IsNull() && !FLAG_strong_non_nullable_type_checks) {
17546+
if (IsNull() && !FLAG_null_safety) {
1754717547
return true;
1754817548
}
1754917549
Thread* thread = Thread::Current();
@@ -17609,7 +17609,7 @@ bool Instance::RuntimeTypeIsSubtypeOf(
1760917609
return false;
1761017610
}
1761117611
if (IsNull()) {
17612-
ASSERT(FLAG_strong_non_nullable_type_checks);
17612+
ASSERT(FLAG_null_safety);
1761317613
if (instantiated_other.IsNullType()) {
1761417614
return true;
1761517615
}
@@ -18340,7 +18340,7 @@ bool AbstractType::IsSubtypeOf(NNBDMode mode,
1834018340
// Only Never? remains, which maps to Null regardless of weak/strong mode.
1834118341
if (IsNullType() || IsNeverType()) {
1834218342
// In weak mode, Null is a bottom type.
18343-
if (!FLAG_strong_non_nullable_type_checks) {
18343+
if (!FLAG_null_safety) {
1834418344
return true;
1834518345
}
1834618346
const AbstractType& unwrapped_other =
@@ -18420,8 +18420,7 @@ bool AbstractType::IsSubtypeOf(NNBDMode mode,
1842018420
}
1842118421
return false;
1842218422
}
18423-
if (FLAG_strong_non_nullable_type_checks && IsNullable() &&
18424-
other.IsNonNullable()) {
18423+
if (FLAG_null_safety && IsNullable() && other.IsNonNullable()) {
1842518424
return false;
1842618425
}
1842718426
return Class::IsSubtypeOf(
@@ -18789,8 +18788,7 @@ bool Type::IsEquivalent(const Instance& other,
1878918788
Nullability this_type_nullability = nullability();
1879018789
Nullability other_type_nullability = other_type.nullability();
1879118790
if (kind == TypeEquality::kInSubtypeTest) {
18792-
if (FLAG_strong_non_nullable_type_checks &&
18793-
this_type_nullability == Nullability::kNullable &&
18791+
if (FLAG_null_safety && this_type_nullability == Nullability::kNullable &&
1879418792
other_type_nullability == Nullability::kNonNullable) {
1879518793
return false;
1879618794
}
@@ -19509,7 +19507,7 @@ bool TypeParameter::IsEquivalent(const Instance& other,
1950919507
Nullability this_type_param_nullability = nullability();
1951019508
Nullability other_type_param_nullability = other_type_param.nullability();
1951119509
if (kind == TypeEquality::kInSubtypeTest) {
19512-
if (FLAG_strong_non_nullable_type_checks &&
19510+
if (FLAG_null_safety &&
1951319511
this_type_param_nullability == Nullability::kNullable &&
1951419512
(other_type_param_nullability == Nullability::kNonNullable ||
1951519513
other_type_param_nullability == Nullability::kUndetermined)) {

runtime/vm/object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,7 @@ enum class TypeEquality {
892892
// tests. The mode reflects the opted-in status of the library performing type
893893
// reification and/or subtype tests.
894894
// Note that the weak or strong testing mode is not reflected in NNBDMode, but
895-
// imposed globally by the value of FLAG_strong_non_nullable_type_checks.
895+
// imposed globally by the value of FLAG_null_safety.
896896
enum class NNBDMode {
897897
// Status of the library:
898898
kLegacyLib = 0, // Library is legacy.

runtime/vm/runtime_entry.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ DEFINE_RUNTIME_ENTRY(TypeCheck, 8) {
821821
ASSERT(!dst_type.IsDynamicType()); // No need to check assignment.
822822
// A null instance is already detected and allowed in inlined code, unless
823823
// strong checking is enabled.
824-
ASSERT(!src_instance.IsNull() || FLAG_strong_non_nullable_type_checks);
824+
ASSERT(!src_instance.IsNull() || FLAG_null_safety);
825825
const bool is_instance_of = src_instance.IsAssignableTo(
826826
nnbd_mode, dst_type, instantiator_type_arguments,
827827
function_type_arguments);

runtime/vm/type_testing_stubs.cc

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,15 @@ RawCode* TypeTestingStubGenerator::DefaultCodeForType(
105105
}
106106

107107
if (cid == kDynamicCid || cid == kVoidCid ||
108-
(cid == kInstanceCid &&
109-
(!FLAG_strong_non_nullable_type_checks || !type.IsNonNullable()))) {
108+
(cid == kInstanceCid && (!FLAG_null_safety || !type.IsNonNullable()))) {
110109
return StubCode::TopTypeTypeTest().raw();
111110
}
112111

113112
if (type.IsType() || type.IsTypeParameter()) {
114113
// TODO(dartbug.com/38845): Add support for specialized TTS for
115114
// nullable and non-nullable types in NNBD strong mode.
116-
const bool should_specialize =
117-
!FLAG_precompiled_mode && lazy_specialize &&
118-
(type.IsLegacy() || !FLAG_strong_non_nullable_type_checks);
115+
const bool should_specialize = !FLAG_precompiled_mode && lazy_specialize &&
116+
(type.IsLegacy() || !FLAG_null_safety);
119117
return should_specialize ? StubCode::LazySpecializeTypeTest().raw()
120118
: StubCode::DefaultTypeTest().raw();
121119
}

tools/bots/test_matrix.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@
717717
"--null-safety"
718718
],
719719
"vm-options": [
720-
"--strong-non-nullable-type-checks"
720+
"--null-safety"
721721
]
722722
}
723723
},
@@ -730,7 +730,7 @@
730730
"--null-safety"
731731
],
732732
"vm-options": [
733-
"--strong-non-nullable-type-checks"
733+
"--null-safety"
734734
]
735735
}
736736
},
@@ -744,7 +744,7 @@
744744
"--null-safety"
745745
],
746746
"vm-options": [
747-
"--strong-non-nullable-type-checks"
747+
"--null-safety"
748748
]
749749
}
750750
},

0 commit comments

Comments
 (0)