Skip to content

Commit 341e6d3

Browse files
authored
Removed unsound null safety options from classes ModuleMetadata and MetadataProvider (#2510)
* Remove unsound null safety options from classes ModuleMetadata and MetadataProvider * updated changelog * Removed unsound null safety options from classes ModuleMetadata, MetadataProvider & Metadata_test. * deprecated metadataProvider's soundNullSafety and associated tests * Deprecated CompilerOptions' soundNullSafety and related usage * deprecated sdk_configuration_test's soundNullSafety * deprecated test_sdk_layout's soundNullSafety * removed remaining use of sound/weak null safety * deprecated sound/weak sdkSummaryPath but kept variables in constructor to avoid breaking changes * deprecated sound/weak sdkSummaryPath for SdkLayout class but kept variables in constructor to avoid breaking changes * formatted code * formatted code * Deprecated public getters soundSdkSummaryUri & weakSdkSummaryUri
1 parent d4b7b83 commit 341e6d3

20 files changed

+167
-401
lines changed

dwds/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Replace deprecated JS code `this.__proto__` with `Object.getPrototypeOf(this)`. - [#2500](https://github.com/dart-lang/webdev/pull/2500)
44
- Migrate injected client code to `package:web`. - [#2491](https://github.com/dart-lang/webdev/pull/2491)
5+
- Deprecated MetadataProvider's, CompilerOptions', SdkConfiguration's & SdkLayout's soundNullSafety. - [#2427](https://github.com/dart-lang/webdev/issues/2427)
56

67
## 24.1.0
78

dwds/lib/src/debugging/metadata/module_metadata.dart

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,13 @@ class ModuleMetadata {
114114
/// Module uri
115115
final String moduleUri;
116116

117-
/// True if the module corresponding to this metadata was compiled with sound
118-
/// null safety enabled.
119-
final bool soundNullSafety;
120-
121117
final Map<String, LibraryMetadata> libraries = {};
122118

123119
ModuleMetadata(
124120
this.name,
125121
this.closureName,
126122
this.sourceMapUri,
127-
this.moduleUri,
128-
this.soundNullSafety, {
123+
this.moduleUri, {
129124
String? ver,
130125
}) {
131126
version = ver ?? ModuleMetadataVersion.current.version;
@@ -151,8 +146,7 @@ class ModuleMetadata {
151146
name = _readRequiredField(json, 'name'),
152147
closureName = _readRequiredField(json, 'closureName'),
153148
sourceMapUri = _readRequiredField(json, 'sourceMapUri'),
154-
moduleUri = _readRequiredField(json, 'moduleUri'),
155-
soundNullSafety = _readOptionalField(json, 'soundNullSafety') ?? false {
149+
moduleUri = _readRequiredField(json, 'moduleUri') {
156150
if (!ModuleMetadataVersion.current.isCompatibleWith(version) &&
157151
!ModuleMetadataVersion.previous.isCompatibleWith(version)) {
158152
throw Exception('Unsupported metadata version $version. '
@@ -174,7 +168,6 @@ class ModuleMetadata {
174168
'sourceMapUri': sourceMapUri,
175169
'moduleUri': moduleUri,
176170
'libraries': [for (final lib in libraries.values) lib.toJson()],
177-
'soundNullSafety': soundNullSafety,
178171
};
179172
}
180173
}

dwds/lib/src/debugging/metadata/provider.dart

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class MetadataProvider {
1515
final AssetReader _assetReader;
1616
final _logger = Logger('MetadataProvider');
1717
final String entrypoint;
18-
bool _soundNullSafety;
1918
final List<String> _libraries = [];
2019
final Map<String, String> _scriptToModule = {};
2120
final Map<String, String> _moduleToSourceMap = {};
@@ -65,15 +64,15 @@ class MetadataProvider {
6564
'dart:ui',
6665
];
6766

68-
MetadataProvider(this.entrypoint, this._assetReader)
69-
: _soundNullSafety = false;
67+
MetadataProvider(this.entrypoint, this._assetReader);
7068

7169
/// A sound null safety mode for the whole app.
7270
///
7371
/// All libraries have to agree on null safety mode.
72+
@Deprecated('Only sound null safety is supported as of Dart 3.0')
7473
Future<bool> get soundNullSafety async {
7574
await _initialize();
76-
return _soundNullSafety;
75+
return true;
7776
}
7877

7978
/// A list of all libraries in the Dart application.
@@ -178,8 +177,6 @@ class MetadataProvider {
178177

179178
Future<void> _initialize() async {
180179
await _metadataMemoizer.runOnce(() async {
181-
var hasSoundNullSafety = true;
182-
var hasUnsoundNullSafety = true;
183180
// The merged metadata resides next to the entrypoint.
184181
// Assume that <name>.bootstrap.js has <name>.ddc_merged_metadata
185182
if (entrypoint.endsWith('.bootstrap.js')) {
@@ -199,22 +196,14 @@ class MetadataProvider {
199196
final metadata =
200197
ModuleMetadata.fromJson(moduleJson as Map<String, dynamic>);
201198
_addMetadata(metadata);
202-
hasUnsoundNullSafety &= !metadata.soundNullSafety;
203-
hasSoundNullSafety &= metadata.soundNullSafety;
204199
_logger
205200
.fine('Loaded debug metadata for module: ${metadata.name}');
206201
} catch (e) {
207202
_logger.warning('Failed to read metadata: $e');
208203
rethrow;
209204
}
210205
}
211-
if (!hasSoundNullSafety && !hasUnsoundNullSafety) {
212-
throw Exception('Metadata contains modules with mixed null safety');
213-
}
214-
_soundNullSafety = hasSoundNullSafety;
215206
}
216-
_logger.info('Loaded debug metadata '
217-
'(${_soundNullSafety ? "sound" : "weak"} null safety)');
218207
}
219208
});
220209
}

dwds/lib/src/services/chrome_proxy_service.dart

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,10 @@ class ChromeProxyService implements VmServiceInterface {
205205
final canaryFeatures = loadStrategy.buildSettings.canaryFeatures;
206206
final experiments = loadStrategy.buildSettings.experiments;
207207

208-
// TODO(annagrin): Read null safety setting from the build settings.
209-
final metadataProvider = loadStrategy.metadataProviderFor(entrypoint);
210-
final soundNullSafety = await metadataProvider.soundNullSafety;
211-
212-
_logger.info('Initializing expression compiler for $entrypoint '
213-
'with sound null safety: $soundNullSafety');
208+
_logger.info('Initializing expression compiler for $entrypoint');
214209

215210
final compilerOptions = CompilerOptions(
216211
moduleFormat: ModuleFormat.values.byName(moduleFormat),
217-
soundNullSafety: soundNullSafety,
218212
canaryFeatures: canaryFeatures,
219213
experiments: experiments,
220214
);

dwds/lib/src/services/expression_compiler.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@
55
/// Options passed to DDC and the expression compiler.
66
class CompilerOptions {
77
final ModuleFormat moduleFormat;
8+
9+
@Deprecated('Only sound null safety is supported as of Dart 3.0')
810
final bool soundNullSafety;
11+
912
final bool canaryFeatures;
1013
final List<String> experiments;
1114

1215
CompilerOptions({
1316
required this.moduleFormat,
14-
required this.soundNullSafety,
17+
this.soundNullSafety = true,
1518
required this.canaryFeatures,
1619
required this.experiments,
1720
});

dwds/lib/src/services/expression_compiler_service.dart

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ class _Compiler {
5353
/// expression compilation (summaries, libraries spec, compiler worker
5454
/// snapshot).
5555
///
56-
/// [soundNullSafety] indicates if the compiler should support sound
57-
/// null safety.
58-
///
5956
/// Performs handshake with the isolate running expression compiler
6057
/// worker to establish communication via send/receive ports, returns
6158
/// the service after the communication is established.
@@ -69,16 +66,10 @@ class _Compiler {
6966
bool verbose,
7067
) async {
7168
sdkConfiguration.validateSdkDir();
72-
if (compilerOptions.soundNullSafety) {
73-
sdkConfiguration.validateSoundSummaries();
74-
} else {
75-
sdkConfiguration.validateWeakSummaries();
76-
}
69+
sdkConfiguration.validateSummaries();
7770

7871
final workerUri = sdkConfiguration.compilerWorkerUri!;
79-
final sdkSummaryUri = compilerOptions.soundNullSafety
80-
? sdkConfiguration.soundSdkSummaryUri!
81-
: sdkConfiguration.weakSdkSummaryUri!;
72+
final sdkSummaryUri = sdkConfiguration.sdkSummaryUri!;
8273

8374
final args = [
8475
'--experimental-expression-compiler',
@@ -91,9 +82,7 @@ class _Compiler {
9182
'--module-format',
9283
compilerOptions.moduleFormat.name,
9384
if (verbose) '--verbose',
94-
compilerOptions.soundNullSafety
95-
? '--sound-null-safety'
96-
: '--no-sound-null-safety',
85+
'--sound-null-safety',
9786
for (final experiment in compilerOptions.experiments)
9887
'--enable-experiment=$experiment',
9988
if (compilerOptions.canaryFeatures) '--canary',

dwds/lib/src/utilities/sdk_configuration.dart

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,24 @@ class SdkLayout {
4242
SdkLayout.createDefault(defaultSdkDirectory);
4343

4444
final String sdkDirectory;
45+
final String summaryPath;
46+
final String dartdevcSnapshotPath;
47+
48+
@Deprecated('Only sound null safety is supported as of Dart 3.0')
4549
final String soundSummaryPath;
50+
51+
@Deprecated('Only sound null safety is supported as of Dart 3.0')
4652
final String weakSummaryPath;
47-
final String dartdevcSnapshotPath;
4853

4954
SdkLayout.createDefault(String sdkDirectory)
5055
: this(
5156
sdkDirectory: sdkDirectory,
52-
soundSummaryPath: p.join(
57+
summaryPath: p.join(
5358
sdkDirectory,
5459
'lib',
5560
'_internal',
5661
'ddc_outline.dill',
5762
),
58-
weakSummaryPath: p.join(
59-
sdkDirectory,
60-
'lib',
61-
'_internal',
62-
'ddc_outline_unsound.dill',
63-
),
6463
dartdevcSnapshotPath: p.join(
6564
sdkDirectory,
6665
'bin',
@@ -71,8 +70,9 @@ class SdkLayout {
7170

7271
const SdkLayout({
7372
required this.sdkDirectory,
74-
required this.soundSummaryPath,
75-
required this.weakSummaryPath,
73+
required this.summaryPath,
74+
this.soundSummaryPath = '',
75+
this.weakSummaryPath = '',
7676
required this.dartdevcSnapshotPath,
7777
});
7878
}
@@ -87,12 +87,18 @@ class SdkConfiguration {
8787
SdkConfiguration.fromSdkLayout(SdkLayout.defaultSdkLayout);
8888

8989
final String? sdkDirectory;
90+
final String? sdkSummaryPath;
91+
final String? compilerWorkerPath;
92+
93+
@Deprecated('Only sound null safety is supported as of Dart 3.0')
9094
final String? weakSdkSummaryPath;
95+
96+
@Deprecated('Only sound null safety is supported as of Dart 3.0')
9197
final String? soundSdkSummaryPath;
92-
final String? compilerWorkerPath;
9398

9499
const SdkConfiguration({
95100
this.sdkDirectory,
101+
this.sdkSummaryPath,
96102
this.weakSdkSummaryPath,
97103
this.soundSdkSummaryPath,
98104
this.compilerWorkerPath,
@@ -103,8 +109,7 @@ class SdkConfiguration {
103109
SdkConfiguration.fromSdkLayout(SdkLayout sdkLayout)
104110
: this(
105111
sdkDirectory: sdkLayout.sdkDirectory,
106-
weakSdkSummaryPath: sdkLayout.weakSummaryPath,
107-
soundSdkSummaryPath: sdkLayout.soundSummaryPath,
112+
sdkSummaryPath: sdkLayout.summaryPath,
108113
compilerWorkerPath: sdkLayout.dartdevcSnapshotPath,
109114
);
110115

@@ -113,7 +118,12 @@ class SdkConfiguration {
113118
path == null ? null : p.toUri(p.absolute(path));
114119

115120
Uri? get sdkDirectoryUri => _toUri(sdkDirectory);
121+
Uri? get sdkSummaryUri => _toUri(sdkSummaryPath);
122+
123+
@Deprecated('Only sound null safety is supported as of Dart 3.0')
116124
Uri? get soundSdkSummaryUri => _toUri(soundSdkSummaryPath);
125+
126+
@Deprecated('Only sound null safety is supported as of Dart 3.0')
117127
Uri? get weakSdkSummaryUri => _toUri(weakSdkSummaryPath);
118128

119129
/// Note: has to be ///file: Uri to run in an isolate.
@@ -139,28 +149,10 @@ class SdkConfiguration {
139149
}
140150

141151
void validateSummaries({FileSystem fileSystem = const LocalFileSystem()}) {
142-
validateSoundSummaries(fileSystem: fileSystem);
143-
validateWeakSummaries(fileSystem: fileSystem);
144-
}
145-
146-
void validateWeakSummaries({
147-
FileSystem fileSystem = const LocalFileSystem(),
148-
}) {
149-
if (weakSdkSummaryPath == null ||
150-
!fileSystem.file(weakSdkSummaryPath).existsSync()) {
151-
throw InvalidSdkConfigurationException(
152-
'Sdk summary $weakSdkSummaryPath does not exist',
153-
);
154-
}
155-
}
156-
157-
void validateSoundSummaries({
158-
FileSystem fileSystem = const LocalFileSystem(),
159-
}) {
160-
if (soundSdkSummaryPath == null ||
161-
!fileSystem.file(soundSdkSummaryPath).existsSync()) {
152+
if (sdkSummaryPath == null ||
153+
!fileSystem.file(sdkSummaryPath).existsSync()) {
162154
throw InvalidSdkConfigurationException(
163-
'Sdk summary $soundSdkSummaryPath does not exist',
155+
'Sdk summary $sdkSummaryPath does not exist',
164156
);
165157
}
166158
}

dwds/test/expression_compiler_service_ddc_and_canary_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ void main() async {
1616
testAll(
1717
compilerOptions: CompilerOptions(
1818
moduleFormat: ModuleFormat.ddc,
19-
soundNullSafety: true,
2019
canaryFeatures: true,
2120
experiments: const <String>[],
2221
),

dwds/test/expression_compiler_service_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ void main() async {
1616
testAll(
1717
compilerOptions: CompilerOptions(
1818
moduleFormat: ModuleFormat.amd,
19-
soundNullSafety: true,
2019
canaryFeatures: false,
2120
experiments: const <String>[],
2221
),

dwds/test/fixtures/utilities.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,5 +300,5 @@ class TestCompilerOptions extends CompilerOptions {
300300
required super.canaryFeatures,
301301
super.experiments = const [],
302302
super.moduleFormat = ModuleFormat.amd,
303-
}) : super(soundNullSafety: true);
303+
});
304304
}

0 commit comments

Comments
 (0)