Skip to content

Commit 237742f

Browse files
natebiggsCommit Queue
authored andcommitted
[dart2js] Remove '--no-sound-null-safety' flag and make '--sound-null-safety' flag a no-op with warning.
Change-Id: I0225f9306aa2a84494f3fc17c9f7191214404249 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/406081 Reviewed-by: Ivan Inozemtsev <[email protected]> Commit-Queue: Nate Biggs <[email protected]> Reviewed-by: Bob Nystrom <[email protected]> Reviewed-by: Mayank Patke <[email protected]>
1 parent bb53879 commit 237742f

File tree

13 files changed

+34
-148
lines changed

13 files changed

+34
-148
lines changed

pkg/compiler/lib/src/commandline_options.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class Flags {
134134
static const String serverMode = '--server-mode';
135135

136136
static const String soundNullSafety = '--sound-null-safety';
137-
static const String noSoundNullSafety = '--no-sound-null-safety';
137+
138138
static const String mergeFragmentsThreshold = '--merge-fragments-threshold';
139139

140140
static const String writeResources = '--write-resources';

pkg/compiler/lib/src/dart2js.dart

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -359,15 +359,6 @@ Future<api.CompilationResult> compile(
359359
);
360360
}
361361

362-
String? nullSafetyMode;
363-
void setNullSafetyMode(String argument) {
364-
if (nullSafetyMode != null && nullSafetyMode != argument) {
365-
_helpAndFail("Cannot specify both $nullSafetyMode and $argument.");
366-
}
367-
nullSafetyMode = argument;
368-
passThrough(argument);
369-
}
370-
371362
void setInvoker(String argument) {
372363
invoker = extractParameter(argument);
373364
}
@@ -525,8 +516,7 @@ Future<api.CompilationResult> compile(
525516
_OneOption(Flags.enableProtoShaking, passThrough),
526517
_OneOption(Flags.benchmarkingProduction, passThrough),
527518
_OneOption(Flags.benchmarkingExperiment, passThrough),
528-
_OneOption(Flags.soundNullSafety, setNullSafetyMode),
529-
_OneOption(Flags.noSoundNullSafety, setNullSafetyMode),
519+
_OneOption(Flags.soundNullSafety, passThrough),
530520
_OneOption(Flags.dumpUnusedLibraries, passThrough),
531521
_OneOption(Flags.writeResources, passThrough),
532522

@@ -597,18 +587,6 @@ Future<api.CompilationResult> compile(
597587

598588
parseCommandLine(handlers, argv);
599589

600-
if (nullSafetyMode == Flags.noSoundNullSafety && platformBinaries == null) {
601-
// Compiling without sound null safety is no longer allowed except in the
602-
// cases where an unsound platform .dill file is manually provided.
603-
// The unsound .dills are no longer packaged in the SDK release so any
604-
// compile initiated through `dart compile js --no-sound-null-safety`
605-
// will not find a .dill in the default location and should be prevented
606-
// from executing.
607-
_fail(
608-
'the flag --no-sound-null-safety is not supported in Dart 3.\n'
609-
'See: https://dart.dev/null-safety.',
610-
);
611-
}
612590
final diagnostic = diagnosticHandler = FormattingDiagnosticHandler();
613591
if (verbose != null) {
614592
diagnostic.verbose = verbose!;
@@ -644,6 +622,14 @@ Future<api.CompilationResult> compile(
644622
);
645623
}
646624

625+
if (options.contains(Flags.soundNullSafety)) {
626+
warning(
627+
"Option '${Flags.soundNullSafety}' is deprecated. As of Dart 3, Dart "
628+
"only supports sound null safety. This flag will be removed in a future "
629+
"version of Dart.",
630+
);
631+
}
632+
647633
for (String hint in hints) {
648634
diagnostic.info(hint, api.Diagnostic.hint);
649635
}

pkg/compiler/lib/src/js_emitter/startup_emitter/model_emitter.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,6 @@ class ModelEmitter {
401401
/// Generates a simple header that provides the compiler's build id.
402402
js.Comment buildGeneratedBy() {
403403
final flavor = StringBuffer();
404-
flavor.write(_options.nullSafetyMode);
405404
if (_options.trustPrimitives) flavor.write(', trust primitives');
406405
if (_options.omitImplicitChecks) flavor.write(', omit checks');
407406
if (_options.laxRuntimeTypeToString) {

pkg/compiler/lib/src/options.dart

Lines changed: 3 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ import 'package:front_end/src/api_unstable/dart2js.dart' as fe;
1111
import 'commandline_options.dart' show Flags;
1212
import 'util/util.dart';
1313

14-
enum NullSafetyMode { unsound, sound }
15-
1614
enum FeatureStatus { shipped, shipping, canary }
1715

1816
enum CompilerPhase {
@@ -534,13 +532,6 @@ class CompilerOptions implements DiagnosticOptions {
534532
/// Whether to generate code containing user's `assert` statements.
535533
bool enableUserAssertions = false;
536534

537-
/// Whether to generate code asserting that non-nullable parameters in opt-in
538-
/// code are not null. In mixed mode code (some opting into non-nullable, some
539-
/// not), null-safety is unsound, allowing `null` values to be assigned to
540-
/// variables with non-nullable types. This assertion lets the opt-in code
541-
/// operate with a stronger guarantee.
542-
bool enableNullAssertions = false;
543-
544535
/// Whether to generate code asserting that non-nullable return values of
545536
/// `@Native` methods or `JS()` invocations are checked for being non-null.
546537
/// Emits checks only in sound null-safety.
@@ -678,22 +669,10 @@ class CompilerOptions implements DiagnosticOptions {
678669
/// migrated to null safety (but before sound null safety is enabled).
679670
bool experimentNullSafetyChecks = false;
680671

681-
/// Whether the compiler should emit code with unsound or sound semantics.
682-
/// Since Dart 3.0 this is no longer inferred from sources, but defaults to
683-
/// sound semantics.
684-
///
685-
/// This option should rarely need to be accessed directly. Consider using
686-
/// [useLegacySubtyping] instead.
687-
NullSafetyMode nullSafetyMode = NullSafetyMode.sound;
688-
bool _soundNullSafety = false;
689-
bool _noSoundNullSafety = false;
690-
691672
/// Whether to use legacy subtype semantics rather than null-safe semantics.
692673
/// This is `true` if unsound null-safety semantics are being used, since
693674
/// dart2js does not emit warnings for unsound null-safety.
694-
bool get useLegacySubtyping {
695-
return nullSafetyMode == NullSafetyMode.unsound;
696-
}
675+
bool get useLegacySubtyping => false;
697676

698677
/// If specified, a bundle of optimizations to enable (or disable).
699678
int? optimizationLevel;
@@ -937,9 +916,6 @@ class CompilerOptions implements DiagnosticOptions {
937916
..enableUserAssertions =
938917
_hasOption(options, Flags.enableCheckedMode) ||
939918
_hasOption(options, Flags.enableAsserts)
940-
..enableNullAssertions =
941-
_hasOption(options, Flags.enableCheckedMode) ||
942-
_hasOption(options, Flags.enableNullAssertions)
943919
..nativeNullAssertions = _hasOption(options, Flags.nativeNullAssertions)
944920
.._noNativeNullAssertions = _hasOption(
945921
options,
@@ -1014,8 +990,6 @@ class CompilerOptions implements DiagnosticOptions {
1014990
.._cfeOnly = _hasOption(options, Flags.cfeOnly)
1015991
.._stageFlag = _extractStringOption(options, '${Flags.stage}=', null)
1016992
..debugGlobalInference = _hasOption(options, Flags.debugGlobalInference)
1017-
.._soundNullSafety = _hasOption(options, Flags.soundNullSafety)
1018-
.._noSoundNullSafety = _hasOption(options, Flags.noSoundNullSafety)
1019993
.._mergeFragmentsThreshold = _extractIntOption(
1020994
options,
1021995
'${Flags.mergeFragmentsThreshold}=',
@@ -1094,12 +1068,6 @@ class CompilerOptions implements DiagnosticOptions {
10941068
equalMaps(experimentalFlags, fe.defaultExperimentalFlags)) {
10951069
throw ArgumentError("Missing required ${Flags.platformBinaries}");
10961070
}
1097-
if (_soundNullSafety && _noSoundNullSafety) {
1098-
throw ArgumentError(
1099-
"'${Flags.soundNullSafety}' is incompatible with "
1100-
"'${Flags.noSoundNullSafety}'",
1101-
);
1102-
}
11031071
if (nativeNullAssertions && _noNativeNullAssertions) {
11041072
throw ArgumentError(
11051073
"'${Flags.nativeNullAssertions}' is incompatible with "
@@ -1112,7 +1080,7 @@ class CompilerOptions implements DiagnosticOptions {
11121080
"'${Flags.noInteropNullAssertions}'",
11131081
);
11141082
}
1115-
if (nullSafetyMode == NullSafetyMode.sound && experimentNullSafetyChecks) {
1083+
if (experimentNullSafetyChecks) {
11161084
throw ArgumentError(
11171085
'${Flags.experimentNullSafetyChecks} is incompatible '
11181086
'with sound null safety.',
@@ -1135,9 +1103,6 @@ class CompilerOptions implements DiagnosticOptions {
11351103
features.forceCanary();
11361104
}
11371105

1138-
if (_soundNullSafety) nullSafetyMode = NullSafetyMode.sound;
1139-
if (_noSoundNullSafety) nullSafetyMode = NullSafetyMode.unsound;
1140-
11411106
if (optimizationLevel != null) {
11421107
if (optimizationLevel == 0) {
11431108
disableInlining = true;
@@ -1187,12 +1152,7 @@ class CompilerOptions implements DiagnosticOptions {
11871152
omitLateNames = false;
11881153
}
11891154

1190-
if (nullSafetyMode != NullSafetyMode.sound) {
1191-
// Technically, we should still assert if the user passed in a flag to
1192-
// assert, but this was not the behavior before, so to avoid a breaking
1193-
// change, we don't assert in unsound mode.
1194-
nativeNullAssertions = false;
1195-
} else if (_noNativeNullAssertions) {
1155+
if (_noNativeNullAssertions) {
11961156
// Never assert if the user tells us not to.
11971157
nativeNullAssertions = false;
11981158
} else if (!nativeNullAssertions &&

pkg/compiler/lib/src/phase/load_kernel.dart

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -234,19 +234,6 @@ Future<_LoadFromKernelResult> _loadFromKernel(
234234

235235
await read(resolvedUri);
236236

237-
var isStrongDill =
238-
component.mode == ir.NonNullableByDefaultCompiledMode.Strong;
239-
var incompatibleNullSafetyMode =
240-
isStrongDill ? NullSafetyMode.unsound : NullSafetyMode.sound;
241-
if (options.nullSafetyMode == incompatibleNullSafetyMode) {
242-
var dillMode = isStrongDill ? 'sound' : 'unsound';
243-
var option = isStrongDill ? Flags.noSoundNullSafety : Flags.soundNullSafety;
244-
throw ArgumentError(
245-
"$resolvedUri was compiled with $dillMode null "
246-
"safety and is incompatible with the '$option' option",
247-
);
248-
}
249-
250237
if (options.platformBinaries != null &&
251238
options.stage.shouldReadPlatformBinaries) {
252239
var platformUri = options.platformBinaries?.resolve(
@@ -294,9 +281,7 @@ Future<_LoadFromSourceResult> _loadFromSource(
294281
Map<String, String>? environment = cfeConstants ? options.environment : null;
295282
Target target = Dart2jsTarget(
296283
targetName,
297-
TargetFlags(
298-
soundNullSafety: options.nullSafetyMode == NullSafetyMode.sound,
299-
),
284+
TargetFlags(),
300285
options: options,
301286
supportsUnevaluatedConstants: !cfeConstants,
302287
);
@@ -333,14 +318,12 @@ Future<_LoadFromSourceResult> _loadFromSource(
333318
'${Flags.experimentNullSafetyChecks}.',
334319
});
335320
}
336-
if (isLegacy && options.nullSafetyMode == NullSafetyMode.sound) {
321+
if (isLegacy) {
337322
reporter.reportErrorMessage(noLocationSpannable, MessageKind.generic, {
338323
'text':
339324
"Starting with Dart 3.0, `dart compile js` expects programs to "
340325
"be null-safe by default. Some libraries reached from $resolvedUri "
341-
"are opted out of null safety. You can temporarily compile this "
342-
"application using the deprecated '${Flags.noSoundNullSafety}' "
343-
"option.",
326+
"are opted out of null safety.",
344327
});
345328
}
346329

pkg/compiler/lib/src/serialization/task.dart

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import 'package:kernel/binary/ast_from_binary.dart' as ir;
1010
import 'package:kernel/binary/ast_to_binary.dart' as ir;
1111

1212
import '../../compiler_api.dart' as api;
13-
import '../commandline_options.dart' show Flags;
1413
import '../common/codegen.dart';
1514
import '../common/tasks.dart';
1615
import '../deferred_load/output_unit.dart';
@@ -97,31 +96,8 @@ class SerializationTask extends CompilerTask {
9796
});
9897
}
9998

100-
void updateOptionsFromComponent(ir.Component component) {
101-
var isStrongDill =
102-
component.mode == ir.NonNullableByDefaultCompiledMode.Strong;
103-
var incompatibleNullSafetyMode =
104-
isStrongDill ? NullSafetyMode.unsound : NullSafetyMode.sound;
105-
if (_options.nullSafetyMode == incompatibleNullSafetyMode) {
106-
var dillMode = isStrongDill ? 'sound' : 'unsound';
107-
var option =
108-
isStrongDill ? Flags.noSoundNullSafety : Flags.soundNullSafety;
109-
throw ArgumentError(
110-
"${_options.inputDillUri} was compiled with "
111-
"$dillMode null safety and is incompatible with the '$option' "
112-
"option",
113-
);
114-
}
115-
116-
_options.nullSafetyMode =
117-
component.mode == ir.NonNullableByDefaultCompiledMode.Strong
118-
? NullSafetyMode.sound
119-
: NullSafetyMode.unsound;
120-
}
121-
12299
Future<ir.Component> deserializeComponentAndUpdateOptions() async {
123100
ir.Component component = await deserializeComponent();
124-
updateOptionsFromComponent(component);
125101
return component;
126102
}
127103

pkg/compiler/lib/src/ssa/builder.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,6 @@ class KernelSsaGraphBuilder extends ir.VisitorDefault<void>
20652065
HInstruction value,
20662066
DartType type,
20672067
) {
2068-
if (!options.enableNullAssertions) return value;
20692068
if (!dartTypes.isNonNullableIfSound(type)) return value;
20702069

20712070
// `operator==` is usually augmented to handle a `null`-argument before this

pkg/compiler/test/dump_info/data/deferred/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
"id": "outputUnit/1",
106106
"kind": "outputUnit",
107107
"name": "1",
108-
"size": 1204,
108+
"size": 1184,
109109
"filename": "out_1.part.js",
110110
"imports": [
111111
"lib"
@@ -223,7 +223,7 @@
223223
"id": "outputUnit/1",
224224
"kind": "outputUnit",
225225
"name": "1",
226-
"size": 1204,
226+
"size": 1184,
227227
"filename": "out_1.part.js",
228228
"imports": [
229229
"lib"

pkg/compiler/test/dump_info/data/deferred_future/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
"id": "outputUnit/1",
114114
"kind": "outputUnit",
115115
"name": "1",
116-
"size": 928,
116+
"size": 908,
117117
"filename": "out_1.part.js",
118118
"imports": [
119119
"lib1"

pkg/compiler/test/end_to_end/modular_loader_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ main() {
4848
options: [
4949
'--input-dill=memory:c.dill',
5050
'--dill-dependencies=memory:a.dill,memory:b.dill,memory:unused.dill',
51-
'--sound-null-safety',
5251
],
5352
memorySourceFiles: {
5453
'a.dill': aDill,

0 commit comments

Comments
 (0)