mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 00:39:49 +00:00
[ddc] Default native null asserts on in sound mode
This does not necessarily enable the native null assertions by default everywhere but it is a step on the path to get there. - The calls to the method that reads this value are only generated in sound null safety so even if this is true the checks don't happen in weak null safety. Added a warning when the option is enabled in weak null safety. - Many DDC integrations will set the flag manually during the bootstrap. That setting still overrides the default value being changed here. Change-Id: I4459fb8e8928424b461eb5519f3a7dc87c578172 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286606 Reviewed-by: Mark Zhou <markzipan@google.com> Commit-Queue: Nicholas Shahan <nshahan@google.com>
This commit is contained in:
parent
624fc6a9d6
commit
ecd37e5d83
|
@ -14,8 +14,7 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:args/args.dart' show ArgParser;
|
import 'package:args/args.dart' show ArgParser;
|
||||||
import 'package:dev_compiler/src/compiler/js_names.dart'
|
import 'package:dev_compiler/src/compiler/js_names.dart' as js_names;
|
||||||
as js_names;
|
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
enum NullSafety { strict, weak, disabled }
|
enum NullSafety { strict, weak, disabled }
|
||||||
|
@ -50,7 +49,8 @@ void main(List<String> args) async {
|
||||||
..addFlag('sound-null-safety',
|
..addFlag('sound-null-safety',
|
||||||
help: 'Compile for sound null safety at runtime. Passed through to the '
|
help: 'Compile for sound null safety at runtime. Passed through to the '
|
||||||
'DDC binary. Defaults to false.',
|
'DDC binary. Defaults to false.',
|
||||||
negatable: true, defaultsTo: true)
|
negatable: true,
|
||||||
|
defaultsTo: true)
|
||||||
..addFlag('emit-debug-symbols',
|
..addFlag('emit-debug-symbols',
|
||||||
help: 'Pass through flag for DDC, emits debug symbols file along with '
|
help: 'Pass through flag for DDC, emits debug symbols file along with '
|
||||||
'the compiled module.',
|
'the compiled module.',
|
||||||
|
@ -62,7 +62,6 @@ void main(List<String> args) async {
|
||||||
..addFlag('native-null-assertions',
|
..addFlag('native-null-assertions',
|
||||||
help: 'Run with assertions on non-nullable values returned from native '
|
help: 'Run with assertions on non-nullable values returned from native '
|
||||||
'APIs.',
|
'APIs.',
|
||||||
defaultsTo: true,
|
|
||||||
negatable: true)
|
negatable: true)
|
||||||
..addFlag('weak-null-safety-errors',
|
..addFlag('weak-null-safety-errors',
|
||||||
help: 'Treat weak null safety warnings as errors.', defaultsTo: false)
|
help: 'Treat weak null safety warnings as errors.', defaultsTo: false)
|
||||||
|
@ -126,7 +125,9 @@ void main(List<String> args) async {
|
||||||
var soundNullSafety = options['sound-null-safety'] as bool;
|
var soundNullSafety = options['sound-null-safety'] as bool;
|
||||||
var emitDebugSymbols = options['emit-debug-symbols'] as bool;
|
var emitDebugSymbols = options['emit-debug-symbols'] as bool;
|
||||||
var nonNullAsserts = options['null-assertions'] as bool;
|
var nonNullAsserts = options['null-assertions'] as bool;
|
||||||
var nativeNonNullAsserts = options['native-null-assertions'] as bool;
|
var nativeNonNullAsserts = options.wasParsed('native-null-assertions')
|
||||||
|
? options['native-null-assertions'] as bool
|
||||||
|
: soundNullSafety;
|
||||||
var weakNullSafetyErrors = options['weak-null-safety-errors'] as bool;
|
var weakNullSafetyErrors = options['weak-null-safety-errors'] as bool;
|
||||||
var canaryFeatures = options['canary'] as bool;
|
var canaryFeatures = options['canary'] as bool;
|
||||||
var entry = p.canonicalize(options.rest.first);
|
var entry = p.canonicalize(options.rest.first);
|
||||||
|
|
|
@ -78,14 +78,20 @@ void nonNullAsserts(bool enable) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@notNull
|
@notNull
|
||||||
bool _nativeNonNullAsserts = false;
|
bool _nativeNonNullAsserts = compileTimeFlag('soundNullSafety');
|
||||||
|
|
||||||
/// Enables null assertions on native APIs to make sure value returned from the
|
/// Enables null assertions on native APIs to make sure values returned from the
|
||||||
/// browser is sound.
|
/// browser are sound.
|
||||||
///
|
///
|
||||||
/// These apply to dart:html and similar web libraries. Note that these only are
|
/// These apply to dart:html and similar web libraries. Note that these only are
|
||||||
/// added in sound null-safety only.
|
/// added in sound null-safety only.
|
||||||
void nativeNonNullAsserts(bool enable) {
|
void nativeNonNullAsserts(bool enable) {
|
||||||
|
if (enable && !compileTimeFlag('soundNullSafety')) {
|
||||||
|
_warn('Enabling `native-null-assertions` is only supported when sound null '
|
||||||
|
'safety is enabled.');
|
||||||
|
}
|
||||||
|
// This value is only read from `checkNativeNonNull` and calls to that method
|
||||||
|
// are only generated in sound null safe code.
|
||||||
_nativeNonNullAsserts = enable;
|
_nativeNonNullAsserts = enable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue