[ddc] Delete unsound null safety from the compiler
Change-Id: I7e8a8b954c706d421bce2e6671619123c6206122
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388746
Reviewed-by: Nate Biggs <natebiggs@google.com>
diff --git a/pkg/dev_compiler/lib/src/command/command.dart b/pkg/dev_compiler/lib/src/command/command.dart
index f592a4e..b9d1cb4 100644
--- a/pkg/dev_compiler/lib/src/command/command.dart
+++ b/pkg/dev_compiler/lib/src/command/command.dart
@@ -287,9 +287,8 @@
packageFile != null ? sourcePathToUri(packageFile) : null,
sourcePathToUri(librarySpecPath),
additionalDills,
- DevCompilerTarget(TargetFlags(
- trackWidgetCreation: trackWidgetCreation,
- soundNullSafety: options.soundNullSafety)),
+ DevCompilerTarget(
+ TargetFlags(trackWidgetCreation: trackWidgetCreation)),
fileSystem: fileSystem,
explicitExperimentalFlags: explicitExperimentalFlags,
environmentDefines: declaredVariables);
@@ -326,9 +325,8 @@
sourcePathToUri(librarySpecPath),
additionalDills,
inputDigests,
- DevCompilerTarget(TargetFlags(
- trackWidgetCreation: trackWidgetCreation,
- soundNullSafety: options.soundNullSafety)),
+ DevCompilerTarget(
+ TargetFlags(trackWidgetCreation: trackWidgetCreation)),
fileSystem: fileSystem,
explicitExperimentalFlags: explicitExperimentalFlags,
environmentDefines: declaredVariables,
diff --git a/pkg/dev_compiler/lib/src/command/options.dart b/pkg/dev_compiler/lib/src/command/options.dart
index 5cee12d..79070e8 100644
--- a/pkg/dev_compiler/lib/src/command/options.dart
+++ b/pkg/dev_compiler/lib/src/command/options.dart
@@ -83,8 +83,6 @@
/// for more details.
final Map<String, bool> experiments;
- final bool soundNullSafety;
-
/// Whether or not the `--canary` flag was specified during compilation.
final bool canaryFeatures;
@@ -98,10 +96,6 @@
/// Whether the compiler is generating a dynamic module.
final bool dynamicModule;
- /// When `true` stars "*" will appear to represent legacy types when printing
- /// runtime types in the compiled application.
- final bool printLegacyStars = false;
-
/// Raw precompiled macro options, each of the format
/// `<program-uri>;<macro-library-uri>`.
///
@@ -128,22 +122,13 @@
this.multiRootScheme = 'org-dartlang-app',
this.multiRootOutputPath,
this.experiments = const {},
- this.soundNullSafety = true,
this.canaryFeatures = false,
this.dynamicModule = false,
this.precompiledMacros = const [],
this.macroSerializationMode})
: emitLibraryBundle = canaryFeatures &&
moduleFormats.length == 1 &&
- moduleFormats.single == ModuleFormat.ddc {
- if (!soundNullSafety) {
- throw ArgumentError.value(
- soundNullSafety,
- 'soundNullSafety',
- 'Dart 3 only supports sound null safety, '
- 'see https://dart.dev/null-safety.\n');
- }
- }
+ moduleFormats.single == ModuleFormat.ddc;
Options.fromArguments(ArgResults args)
: this(
@@ -167,7 +152,6 @@
multiRootOutputPath: args['multi-root-output-path'] as String?,
experiments: parseExperimentalArguments(
args['enable-experiment'] as List<String>),
- soundNullSafety: args['sound-null-safety'] as bool,
canaryFeatures: args['canary'] as bool,
dynamicModule: args['dynamic-module'] as bool,
precompiledMacros: args['precompiled-macro'] as List<String>,
@@ -186,7 +170,6 @@
multiRootOutputPath: args['multi-root-output-path'] as String?,
experiments: parseExperimentalArguments(
args['enable-experiment'] as List<String>),
- soundNullSafety: args['sound-null-safety'] as bool,
canaryFeatures: args['canary'] as bool);
static void addArguments(ArgParser parser, {bool hide = true}) {
@@ -281,7 +264,8 @@
..addMultiOption('enable-experiment',
help: 'Enable/disable experimental language features.', hide: hide)
..addFlag('sound-null-safety',
- help: 'Compile for sound null safety at runtime.',
+ help: 'Ignored and will be removed in a future version. '
+ 'Sound null safety is always used.',
negatable: false,
defaultsTo: true)
..addFlag('canary',
diff --git a/pkg/dev_compiler/lib/src/kernel/compiler.dart b/pkg/dev_compiler/lib/src/kernel/compiler.dart
index 3f0f742..fd57163 100644
--- a/pkg/dev_compiler/lib/src/kernel/compiler.dart
+++ b/pkg/dev_compiler/lib/src/kernel/compiler.dart
@@ -783,28 +783,6 @@
libraries.any((l) => allowedNativeTest(l.importUri)));
_ticker?.logMs('Emitted imports and extension symbols');
- // Insert a check that runs when loading this module to verify that the null
- // safety mode it was compiled in matches the mode used when compiling the
- // dart sdk module.
- //
- // This serves as a sanity check at runtime that we don't have an
- // infrastructure issue that loaded js files compiled with different modes
- // into the same application.
- js_ast.LiteralBool soundNullSafety;
- switch (component.mode) {
- case NonNullableByDefaultCompiledMode.Strong:
- soundNullSafety = js_ast.LiteralBool(true);
- case NonNullableByDefaultCompiledMode.Weak:
- soundNullSafety = js_ast.LiteralBool(false);
- default:
- throw StateError('Unsupported Null Safety mode ${component.mode}, '
- 'in ${component.location?.file}.');
- }
- if (!_isBuildingSdk) {
- items.add(_runtimeStatement(
- '_checkModuleNullSafetyMode(#)', [soundNullSafety]));
- }
-
// Emit the hoisted type table cache variables
items.addAll(_typeTable.dischargeBoundTypes());
_ticker?.logMs('Emitted type table');
@@ -2517,12 +2495,6 @@
var body = <js_ast.Statement>[];
var value = _emitIdentifier('value');
- // Avoid adding a null checks on forwarding field setters.
- if (field.hasSetter &&
- _requiresExtraNullCheck(field.setterType, field.annotations)) {
- body.add(
- _nullSafetyParameterCheck(value, field.location, field.name.text));
- }
var args = field.isFinal
? [js_ast.Super(), name, value]
: [
@@ -2718,16 +2690,9 @@
member.fileOffset,
member.name.text.length));
if (!member.isFinal && !member.isConst) {
- var body = <js_ast.Statement>[];
- var value = _emitIdentifier('value');
- if (_requiresExtraNullCheck(member.setterType, member.annotations)) {
- body.add(_nullSafetyParameterCheck(
- value, member.location, member.name.text));
- }
- // Even when no null check is present a dummy setter is still required
- // to indicate writeable.
- accessors.add(js_ast.Method(
- access, js_ast.Fun([value], js_ast.Block(body)),
+ // A dummy setter is still required to indicate writeable.
+ accessors.add(js_ast.Method(access,
+ js_ast.Fun([_emitIdentifier('value')], js_ast.Block(const [])),
isSetter: true));
}
} else if (member is Procedure) {
@@ -3753,15 +3718,9 @@
FunctionNode fn, List<js_ast.Statement> Function() action) {
var savedFunction = _currentFunction;
_currentFunction = fn;
- if (_isDartLibrary(_currentLibrary!, '_rti') ||
- _isSdkInternalRuntime(_currentLibrary!)) {
- _nullableInference.treatDeclaredTypesAsSound = true;
- }
_nullableInference.enterFunction(fn);
var result = _withLetScope(action);
_nullableInference.exitFunction(fn);
- _nullableInference.treatDeclaredTypesAsSound = false;
-
_currentFunction = savedFunction;
return result;
}
@@ -3794,48 +3753,6 @@
bool _mustBeNonNullable(DartType type) =>
type.nullability == Nullability.nonNullable;
- /// Returns `true` when an additional null check is needed because of the
- /// null safety compile mode, the null safety migration status of the current
- /// library and the provided [type] with its [annotations].
- bool _requiresExtraNullCheck(DartType type, List<Expression> annotations) =>
- !_options.soundNullSafety &&
- // Libraries that haven't been migrated to null safety represent
- // non-nullable as legacy.
- _currentLibrary!.nonNullable == Nullability.nonNullable &&
- _mustBeNonNullable(type) &&
- !_annotatedNotNull(annotations) &&
- // Trust the nullability of types in the dart:_rti library.
- !_isDartLibrary(_currentLibrary!, '_rti');
-
- /// Returns a null check for [value] that if fails produces an error message
- /// containing the [location] and [name] of the original value being checked.
- ///
- /// This is used to generate checks for non-nullable parameters when running
- /// with weak null safety. The checks can be silent, warn, or throw, depending
- /// on the flags set in the SDK at runtime.
- js_ast.Statement _nullSafetyParameterCheck(
- js_ast.Identifier value, Location? location, String? name) {
- // TODO(nshahan): Remove when weak mode null safety assertions are no longer
- // supported.
- // The check on `field.setterType` is per:
- // https://github.com/dart-lang/language/blob/master/accepted/2.12/nnbd/feature-specification.md#automatic-debug-assertion-insertion
- var condition = js.call('# == null', [value]);
- // Offsets are not available for compiler-generated variables
- // Get the best available location even if the offset is missing.
- // https://github.com/dart-lang/sdk/issues/34942
- return js.statement(' if (#) #;', [
- condition,
- _runtimeCall('nullFailed(#, #, #, #)', [
- location != null
- ? _cacheUri(location.file.toString())
- : js_ast.LiteralNull(),
- js.number(location?.line ?? -1),
- js.number(location?.column ?? -1),
- js.escapedString('$name')
- ])
- ]);
- }
-
/// Emits argument initializers, which handles optional/named args, as well
/// as generic type checks needed due to our covariance.
List<js_ast.Statement> _emitArgumentInitializers(
@@ -3879,8 +3796,6 @@
if (_annotatedNullCheck(p.annotations)) {
body.add(_nullParameterCheck(jsParam));
- } else if (_requiresExtraNullCheck(p.type, p.annotations)) {
- body.add(_nullSafetyParameterCheck(jsParam, p.location, p.name));
}
}
@@ -3925,9 +3840,6 @@
bool _annotatedNullCheck(List<Expression> annotations) =>
annotations.any(_nullableInference.isNullCheckAnnotation);
- bool _annotatedNotNull(List<Expression> annotations) =>
- annotations.any(_nullableInference.isNotNullAnnotation);
-
bool _reifyGenericFunction(Member? m) =>
m == null ||
// JS interop members should not pass type arguments.
@@ -5202,8 +5114,7 @@
/// This is true for non-nullable native return types.
bool _isNullCheckableNative(Member member) {
var c = member.enclosingClass;
- return _options.soundNullSafety &&
- member.isExternal &&
+ return member.isExternal &&
c != null &&
_extensionTypes.isNativeClass(c) &&
member is Procedure &&
@@ -6143,6 +6054,8 @@
if (name == 'TYPE_REF') {
return _emitType(typeArgs.single);
}
+ // TODO(nshahan): Delete after uses are deleted from dart:_rti and the
+ // external signature is removed from dart:_foreign_helper.
if (name == 'LEGACY_TYPE_REF') {
return _emitType(
typeArgs.single.withDeclaredNullability(Nullability.legacy));
@@ -6184,22 +6097,11 @@
var value = flag.value;
return switch (value) {
'DEV_COMPILER' => js.boolean(true),
- 'PRINT_LEGACY_STARS' => js.boolean(_options.printLegacyStars),
- 'LEGACY' => _options.soundNullSafety
- ? js.boolean(false)
- // When running the new runtime type system with weak null
- // safety this flag gets toggled when performing `is` and `as`
- // checks. This allows DDC to produce optional warnings or
- // errors when tests pass but would fail in sound null safety.
- : _runtimeCall('legacyTypeChecks'),
- 'SOUND_NULL_SAFETY' => js.boolean(_options.soundNullSafety),
- 'EXTRA_NULL_SAFETY_CHECKS' => _options.soundNullSafety
- ? js.boolean(false)
- // When running the new runtime type system with weak null
- // safety this flag gets toggled when performing `is` and `as`
- // checks. This allows DDC to produce optional warnings or
- // errors when tests pass but would fail in sound null safety.
- : _runtimeCall('extraNullSafetyChecks'),
+ // TODO(nshahan): Delete 'PRINT_LEGACY_STARS', 'LEGACY', and
+ // 'EXTRA_NULL_SAFETY_CHECKS' after uses are deleted from dart:_rti.
+ 'PRINT_LEGACY_STARS' => js.boolean(false),
+ 'LEGACY' => js.boolean(false),
+ 'EXTRA_NULL_SAFETY_CHECKS' => js.boolean(false),
'MINIFIED' => js.boolean(false),
'VARIANCE' =>
// Variance is turned on by default, but only interfaces that have
@@ -6501,7 +6403,7 @@
// Add a check to make sure any JS() values from a native type are typed
// properly in sound null-safety.
- if (_isWebLibrary(_currentLibrary!.importUri) && _options.soundNullSafety) {
+ if (_isWebLibrary(_currentLibrary!.importUri)) {
var type = node.getStaticType(_staticTypeContext);
if (type.isPotentiallyNonNullable) {
result = _runtimeCall('checkNativeNonNull(#)', [result]);
@@ -6610,15 +6512,7 @@
}
/// Returns true if [expr] can be null.
- bool _isNullable(Expression expr) {
- if (_isDartLibrary(_currentLibrary!, '_rti') ||
- _isSdkInternalRuntime(_currentLibrary!)) {
- _nullableInference.treatDeclaredTypesAsSound = true;
- }
- final result = _nullableInference.isNullable(expr);
- _nullableInference.treatDeclaredTypesAsSound = false;
- return result;
- }
+ bool _isNullable(Expression expr) => _nullableInference.isNullable(expr);
js_ast.Expression _emitJSDoubleEq(List<js_ast.Expression> args,
{bool negated = false}) {
@@ -7657,7 +7551,6 @@
var headerOptions = [
if (_options.canaryFeatures) 'canary',
if (_options.emitLibraryBundle) 'emitLibraryBundle',
- 'soundNullSafety(${_options.soundNullSafety})',
'enableAsserts(${_options.enableAsserts})',
];
var enabledExperiments = <String>[];
diff --git a/pkg/dev_compiler/lib/src/kernel/compiler_new.dart b/pkg/dev_compiler/lib/src/kernel/compiler_new.dart
index 0ce6090..4973326 100644
--- a/pkg/dev_compiler/lib/src/kernel/compiler_new.dart
+++ b/pkg/dev_compiler/lib/src/kernel/compiler_new.dart
@@ -197,7 +197,6 @@
var headerOptions = [
if (_options.canaryFeatures) 'canary',
if (_options.emitLibraryBundle) 'emitLibraryBundle',
- 'soundNullSafety(${_options.soundNullSafety})',
'enableAsserts(${_options.enableAsserts})',
];
var enabledExperiments = <String>[];
@@ -951,28 +950,6 @@
});
}
- // Insert a check that runs when loading this module to verify that the null
- // safety mode it was compiled in matches the mode used when compiling the
- // dart sdk module.
- //
- // This serves as a sanity check at runtime that we don't have an
- // infrastructure issue that loaded js files compiled with different modes
- // into the same application.
- js_ast.LiteralBool soundNullSafety;
- switch (_component.mode) {
- case NonNullableByDefaultCompiledMode.Strong:
- soundNullSafety = js_ast.LiteralBool(true);
- case NonNullableByDefaultCompiledMode.Weak:
- soundNullSafety = js_ast.LiteralBool(false);
- default:
- throw StateError('Unsupported Null Safety mode ${_component.mode}, '
- 'in ${_component.location?.file}.');
- }
- if (!_isBuildingSdk) {
- items.add(_runtimeStatement(
- '_checkModuleNullSafetyMode(#)', [soundNullSafety]));
- }
-
// Additional method used by the module system to link class hierarchies.
_moduleItems.add(_emitLibraryLinkMethod(_currentLibrary!));
_ticker?.logMs('Emitted library link method');
@@ -2728,12 +2705,6 @@
var body = <js_ast.Statement>[];
var value = _emitIdentifier('value');
- // Avoid adding a null checks on forwarding field setters.
- if (field.hasSetter &&
- _requiresExtraNullCheck(field.setterType, field.annotations)) {
- body.add(
- _nullSafetyParameterCheck(value, field.location, field.name.text));
- }
var args = field.isFinal
? [js_ast.Super(), name, value]
: [
@@ -2867,14 +2838,8 @@
/// sentinel value if [field] is final to detect multiple initializations.
js_ast.Fun _emitLazyInitializingFunction(js_ast.Expression valueCache,
js_ast.Expression initializer, Field field) {
- // We avoid emitting casts for top level fields in the legacy SDK since
- // some are used for legacy type checks and must be initialized to avoid
- // infinite loops.
- var initialFieldValueExpression = !_compileForHotReload ||
- !_options.soundNullSafety && _isSdkInternalRuntime(_currentLibrary!)
- ? valueCache
- : _emitCast(valueCache, field.type);
-
+ var initialFieldValueExpression =
+ !_compileForHotReload ? valueCache : _emitCast(valueCache, field.type);
// Lazy static fields require an additional type check around their value
// cache if their type is updated after hot reload. To avoid a type check
// on every access, the generated getter overrides itself with a direct
@@ -3107,10 +3072,6 @@
if (!member.isFinal && !member.isConst) {
var body = <js_ast.Statement>[];
var param = _emitIdentifier('v');
- if (_requiresExtraNullCheck(member.setterType, member.annotations)) {
- body.add(_nullSafetyParameterCheck(
- param, member.location, member.name.text));
- }
body.add(js.statement('this.# = #;', [memberValueStore, param]));
// Even when no null check is present a dummy setter is still required
// to indicate writeable.
@@ -4179,15 +4140,9 @@
FunctionNode fn, List<js_ast.Statement> Function() action) {
var savedFunction = _currentFunction;
_currentFunction = fn;
- if (_isDartLibrary(_currentLibrary!, '_rti') ||
- _isSdkInternalRuntime(_currentLibrary!)) {
- _nullableInference.treatDeclaredTypesAsSound = true;
- }
_nullableInference.enterFunction(fn);
var result = _withLetScope(action);
_nullableInference.exitFunction(fn);
- _nullableInference.treatDeclaredTypesAsSound = false;
-
_currentFunction = savedFunction;
return result;
}
@@ -4220,48 +4175,6 @@
bool _mustBeNonNullable(DartType type) =>
type.nullability == Nullability.nonNullable;
- /// Returns `true` when an additional null check is needed because of the
- /// null safety compile mode, the null safety migration status of the current
- /// library and the provided [type] with its [annotations].
- bool _requiresExtraNullCheck(DartType type, List<Expression> annotations) =>
- !_options.soundNullSafety &&
- // Libraries that haven't been migrated to null safety represent
- // non-nullable as legacy.
- _currentLibrary!.nonNullable == Nullability.nonNullable &&
- _mustBeNonNullable(type) &&
- !_annotatedNotNull(annotations) &&
- // Trust the nullability of types in the dart:_rti library.
- !_isDartLibrary(_currentLibrary!, '_rti');
-
- /// Returns a null check for [value] that if fails produces an error message
- /// containing the [location] and [name] of the original value being checked.
- ///
- /// This is used to generate checks for non-nullable parameters when running
- /// with weak null safety. The checks can be silent, warn, or throw, depending
- /// on the flags set in the SDK at runtime.
- js_ast.Statement _nullSafetyParameterCheck(
- js_ast.Identifier value, Location? location, String? name) {
- // TODO(nshahan): Remove when weak mode null safety assertions are no longer
- // supported.
- // The check on `field.setterType` is per:
- // https://github.com/dart-lang/language/blob/master/accepted/2.12/nnbd/feature-specification.md#automatic-debug-assertion-insertion
- var condition = js.call('# == null', [value]);
- // Offsets are not available for compiler-generated variables
- // Get the best available location even if the offset is missing.
- // https://github.com/dart-lang/sdk/issues/34942
- return js.statement(' if (#) #;', [
- condition,
- _runtimeCall('nullFailed(#, #, #, #)', [
- location != null
- ? _cacheUri(location.file.toString())
- : js_ast.LiteralNull(),
- js.number(location?.line ?? -1),
- js.number(location?.column ?? -1),
- js.escapedString('$name')
- ])
- ]);
- }
-
/// Emits argument initializers, which handles optional/named args, as well
/// as generic type checks needed due to our covariance.
List<js_ast.Statement> _emitArgumentInitializers(
@@ -4305,8 +4218,6 @@
if (_annotatedNullCheck(p.annotations)) {
body.add(_nullParameterCheck(jsParam));
- } else if (_requiresExtraNullCheck(p.type, p.annotations)) {
- body.add(_nullSafetyParameterCheck(jsParam, p.location, p.name));
}
}
@@ -4351,9 +4262,6 @@
bool _annotatedNullCheck(List<Expression> annotations) =>
annotations.any(_nullableInference.isNullCheckAnnotation);
- bool _annotatedNotNull(List<Expression> annotations) =>
- annotations.any(_nullableInference.isNotNullAnnotation);
-
bool _reifyGenericFunction(Member? m) =>
m == null ||
// JS interop members should not pass type arguments.
@@ -5628,8 +5536,7 @@
/// This is true for non-nullable native return types.
bool _isNullCheckableNative(Member member) {
var c = member.enclosingClass;
- return _options.soundNullSafety &&
- member.isExternal &&
+ return member.isExternal &&
c != null &&
_extensionTypes.isNativeClass(c) &&
member is Procedure &&
@@ -6606,22 +6513,11 @@
var value = flag.value;
return switch (value) {
'DEV_COMPILER' => js.boolean(true),
- 'PRINT_LEGACY_STARS' => js.boolean(_options.printLegacyStars),
- 'LEGACY' => _options.soundNullSafety
- ? js.boolean(false)
- // When running the new runtime type system with weak null
- // safety this flag gets toggled when performing `is` and `as`
- // checks. This allows DDC to produce optional warnings or
- // errors when tests pass but would fail in sound null safety.
- : _runtimeCall('legacyTypeChecks'),
- 'SOUND_NULL_SAFETY' => js.boolean(_options.soundNullSafety),
- 'EXTRA_NULL_SAFETY_CHECKS' => _options.soundNullSafety
- ? js.boolean(false)
- // When running the new runtime type system with weak null
- // safety this flag gets toggled when performing `is` and `as`
- // checks. This allows DDC to produce optional warnings or
- // errors when tests pass but would fail in sound null safety.
- : _runtimeCall('extraNullSafetyChecks'),
+ // TODO(nshahan): Delete 'PRINT_LEGACY_STARS', 'LEGACY', and
+ // 'EXTRA_NULL_SAFETY_CHECKS' after uses are deleted from dart:_rti.
+ 'PRINT_LEGACY_STARS' => js.boolean(false),
+ 'LEGACY' => js.boolean(false),
+ 'EXTRA_NULL_SAFETY_CHECKS' => js.boolean(false),
'MINIFIED' => js.boolean(false),
'VARIANCE' =>
// Variance is turned on by default, but only interfaces that have
@@ -6926,7 +6822,7 @@
// Add a check to make sure any JS() values from a native type are typed
// properly in sound null-safety.
- if (_isWebLibrary(_currentLibrary!.importUri) && _options.soundNullSafety) {
+ if (_isWebLibrary(_currentLibrary!.importUri)) {
var type = node.getStaticType(_staticTypeContext);
if (type.isPotentiallyNonNullable) {
result = _runtimeCall('checkNativeNonNull(#)', [result]);
@@ -7035,15 +6931,7 @@
}
/// Returns true if [expr] can be null.
- bool _isNullable(Expression expr) {
- if (_isDartLibrary(_currentLibrary!, '_rti') ||
- _isSdkInternalRuntime(_currentLibrary!)) {
- _nullableInference.treatDeclaredTypesAsSound = true;
- }
- final result = _nullableInference.isNullable(expr);
- _nullableInference.treatDeclaredTypesAsSound = false;
- return result;
- }
+ bool _isNullable(Expression expr) => _nullableInference.isNullable(expr);
js_ast.Expression _emitJSDoubleEq(List<js_ast.Expression> args,
{bool negated = false}) {
diff --git a/pkg/dev_compiler/lib/src/kernel/expression_compiler_worker.dart b/pkg/dev_compiler/lib/src/kernel/expression_compiler_worker.dart
index 90a9a72..2c589e4 100644
--- a/pkg/dev_compiler/lib/src/kernel/expression_compiler_worker.dart
+++ b/pkg/dev_compiler/lib/src/kernel/expression_compiler_worker.dart
@@ -191,7 +191,6 @@
explicitExperimentalFlags: explicitExperimentalFlags,
sdkRoot: _argToUri(parsedArgs['sdk-root'] as String?),
trackWidgetCreation: parsedArgs['track-widget-creation'] as bool,
- soundNullSafety: parsedArgs['sound-null-safety'] as bool,
moduleFormat: moduleFormat,
canaryFeatures: parsedArgs['canary'] as bool,
enableAsserts: parsedArgs['enable-asserts'] as bool,
@@ -218,7 +217,6 @@
Map<ExperimentalFlag, bool> explicitExperimentalFlags = const {},
Uri? sdkRoot,
bool trackWidgetCreation = false,
- bool soundNullSafety = true,
ModuleFormat moduleFormat = ModuleFormat.amd,
bool canaryFeatures = false,
bool enableAsserts = true,
@@ -234,9 +232,8 @@
..sdkSummary = sdkSummary
..packagesFileUri = packagesFile
..librariesSpecificationUri = librariesSpecificationUri
- ..target = DevCompilerTarget(TargetFlags(
- trackWidgetCreation: trackWidgetCreation,
- soundNullSafety: soundNullSafety))
+ ..target = DevCompilerTarget(
+ TargetFlags(trackWidgetCreation: trackWidgetCreation))
..fileSystem = fileSystem
..omitPlatform = true
..environmentDefines = addGeneratedVariables({
@@ -469,7 +466,6 @@
sourceMap: true,
summarizeApi: false,
moduleName: moduleName,
- soundNullSafety: true,
canaryFeatures: _canaryFeatures,
enableAsserts: _enableAsserts,
),
diff --git a/pkg/dev_compiler/lib/src/kernel/nullable_inference.dart b/pkg/dev_compiler/lib/src/kernel/nullable_inference.dart
index 68fec810..a0e4408 100644
--- a/pkg/dev_compiler/lib/src/kernel/nullable_inference.dart
+++ b/pkg/dev_compiler/lib/src/kernel/nullable_inference.dart
@@ -40,22 +40,10 @@
/// [allowNotNullDeclarations].
bool allowPackageMetaAnnotations = false;
- /// Whether or not to treat type declarations as sound regardless of sound
- /// null safety mode.
- ///
- /// This is used to avoid emitting extraneous null checks in internal SDK
- /// libraries in legacy or mixed mode.
- ///
- /// Only used in dart:_runtime and dart:_rti.
- bool treatDeclaredTypesAsSound = false;
-
final _variableInference = _NullableVariableInference();
- final bool _soundNullSafety;
-
NullableInference(this.jsTypeRep, this._staticTypeContext, {Options? options})
- : coreTypes = jsTypeRep.coreTypes,
- _soundNullSafety = options?.soundNullSafety ?? true {
+ : coreTypes = jsTypeRep.coreTypes {
_variableInference._nullInference = this;
}
@@ -205,10 +193,8 @@
return _returnValueIsNullable(target);
}
- bool get soundNullSafety => _soundNullSafety || treatDeclaredTypesAsSound;
-
bool _staticallyNonNullable(DartType type) =>
- soundNullSafety && type.nullability == Nullability.nonNullable;
+ type.nullability == Nullability.nonNullable;
bool _returnValueIsNullable(Member target) {
var targetClass = target.enclosingClass;
@@ -412,11 +398,8 @@
@override
void visitFunctionNode(FunctionNode node) {
_functions.add(node);
- if (_nullInference.allowNotNullDeclarations ||
- _nullInference.soundNullSafety) {
- visitList(node.positionalParameters, this);
- visitList(node.namedParameters, this);
- }
+ visitList(node.positionalParameters, this);
+ visitList(node.namedParameters, this);
node.body?.accept(this);
}
@@ -439,8 +422,7 @@
}
}
var initializer = node.initializer;
- if (_nullInference.soundNullSafety &&
- node.type.nullability == Nullability.nonNullable) {
+ if (node.type.nullability == Nullability.nonNullable) {
// Avoid null checks for variables when the type system guarantees they
// can never be null.
_notNullLocals.add(node);
diff --git a/pkg/dev_compiler/test/memory_compiler.dart b/pkg/dev_compiler/test/memory_compiler.dart
index 2c88fda..c8cff25 100644
--- a/pkg/dev_compiler/test/memory_compiler.dart
+++ b/pkg/dev_compiler/test/memory_compiler.dart
@@ -68,8 +68,7 @@
null,
sourcePathToUri(defaultLibrarySpecPath),
[],
- DevCompilerTarget(
- TargetFlags(trackWidgetCreation: false, soundNullSafety: true)),
+ DevCompilerTarget(TargetFlags(trackWidgetCreation: false)),
fileSystem: fe.HybridFileSystem(memoryFileSystem),
environmentDefines: {},
explicitExperimentalFlags: explicitExperimentalFlags);