From 41c97b10163f5779810a048b18af582d41bf57ae Mon Sep 17 00:00:00 2001 From: Jessy Yameogo Date: Mon, 7 Oct 2024 15:51:17 -0400 Subject: [PATCH 1/3] Remove unsound null safety options from classes ModuleMetadata and MetadataProvider --- .../src/debugging/metadata/module_metadata.dart | 13 +++++++------ dwds/lib/src/debugging/metadata/provider.dart | 16 +++------------- dwds/test/metadata_test.dart | 4 ++-- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/dwds/lib/src/debugging/metadata/module_metadata.dart b/dwds/lib/src/debugging/metadata/module_metadata.dart index ce186df28..06c4bdf5a 100644 --- a/dwds/lib/src/debugging/metadata/module_metadata.dart +++ b/dwds/lib/src/debugging/metadata/module_metadata.dart @@ -114,8 +114,8 @@ class ModuleMetadata { /// Module uri final String moduleUri; - /// True if the module corresponding to this metadata was compiled with sound - /// null safety enabled. + // Keep the soundNullSafety flag for backward compatibility + @Deprecated('This field is deprecated as sound null safety is enforced.') final bool soundNullSafety; final Map libraries = {}; @@ -124,8 +124,8 @@ class ModuleMetadata { this.name, this.closureName, this.sourceMapUri, - this.moduleUri, - this.soundNullSafety, { + this.moduleUri, { + this.soundNullSafety = true, // Default to true String? ver, }) { version = ver ?? ModuleMetadataVersion.current.version; @@ -152,7 +152,9 @@ class ModuleMetadata { closureName = _readRequiredField(json, 'closureName'), sourceMapUri = _readRequiredField(json, 'sourceMapUri'), moduleUri = _readRequiredField(json, 'moduleUri'), - soundNullSafety = _readOptionalField(json, 'soundNullSafety') ?? false { + // Deprecated field still present for backward compatibility + // Defaults to true if missing + soundNullSafety = _readOptionalField(json, 'soundNullSafety') ?? true { if (!ModuleMetadataVersion.current.isCompatibleWith(version) && !ModuleMetadataVersion.previous.isCompatibleWith(version)) { throw Exception('Unsupported metadata version $version. ' @@ -174,7 +176,6 @@ class ModuleMetadata { 'sourceMapUri': sourceMapUri, 'moduleUri': moduleUri, 'libraries': [for (final lib in libraries.values) lib.toJson()], - 'soundNullSafety': soundNullSafety, }; } } diff --git a/dwds/lib/src/debugging/metadata/provider.dart b/dwds/lib/src/debugging/metadata/provider.dart index 41541659f..dfe46ec0f 100644 --- a/dwds/lib/src/debugging/metadata/provider.dart +++ b/dwds/lib/src/debugging/metadata/provider.dart @@ -15,7 +15,8 @@ class MetadataProvider { final AssetReader _assetReader; final _logger = Logger('MetadataProvider'); final String entrypoint; - bool _soundNullSafety; + @Deprecated('This field is deprecated as sound null safety is enforced.') + final bool _soundNullSafety = true; final List _libraries = []; final Map _scriptToModule = {}; final Map _moduleToSourceMap = {}; @@ -65,8 +66,7 @@ class MetadataProvider { 'dart:ui', ]; - MetadataProvider(this.entrypoint, this._assetReader) - : _soundNullSafety = false; + MetadataProvider(this.entrypoint, this._assetReader); /// A sound null safety mode for the whole app. /// @@ -178,8 +178,6 @@ class MetadataProvider { Future _initialize() async { await _metadataMemoizer.runOnce(() async { - var hasSoundNullSafety = true; - var hasUnsoundNullSafety = true; // The merged metadata resides next to the entrypoint. // Assume that .bootstrap.js has .ddc_merged_metadata if (entrypoint.endsWith('.bootstrap.js')) { @@ -199,8 +197,6 @@ class MetadataProvider { final metadata = ModuleMetadata.fromJson(moduleJson as Map); _addMetadata(metadata); - hasUnsoundNullSafety &= !metadata.soundNullSafety; - hasSoundNullSafety &= metadata.soundNullSafety; _logger .fine('Loaded debug metadata for module: ${metadata.name}'); } catch (e) { @@ -208,13 +204,7 @@ class MetadataProvider { rethrow; } } - if (!hasSoundNullSafety && !hasUnsoundNullSafety) { - throw Exception('Metadata contains modules with mixed null safety'); - } - _soundNullSafety = hasSoundNullSafety; } - _logger.info('Loaded debug metadata ' - '(${_soundNullSafety ? "sound" : "weak"} null safety)'); } }); } diff --git a/dwds/test/metadata_test.dart b/dwds/test/metadata_test.dart index 046e635e7..fc8ae177e 100644 --- a/dwds/test/metadata_test.dart +++ b/dwds/test/metadata_test.dart @@ -69,7 +69,7 @@ void main() { await provider.libraries, contains('org-dartlang-app:///web/main.dart'), ); - expect(await provider.soundNullSafety, false); + expect(await provider.soundNullSafety, true); }); test('throws on metadata with absolute import uris', () async { @@ -114,6 +114,6 @@ void main() { expect(parts.length, 1); expect(parts[0], 'org-dartlang-app:///web/main.dart'); } - expect(metadata.soundNullSafety, false); + expect(metadata.soundNullSafety, true); }); } From 23ff7d10f068c717376b2c902420fa1a3f59f56d Mon Sep 17 00:00:00 2001 From: Jessy Yameogo Date: Mon, 7 Oct 2024 15:56:19 -0400 Subject: [PATCH 2/3] updated changelog --- dwds/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index 95cd526b0..597627616 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -1,5 +1,6 @@ ## 24.2.0-wip - Replace deprecated JS code `this.__proto__` with `Object.getPrototypeOf(this)` - [#2500](https://github.com/dart-lang/webdev/pull/2500) +- Removed unsound null safety options from classes ModuleMetadata and MetadataProvider - [#2427](https://github.com/dart-lang/webdev/issues/2427) ## 24.1.0 From ee10f9b9f612547a56dcb39644ee7d2455155d7d Mon Sep 17 00:00:00 2001 From: Jessy Yameogo Date: Tue, 8 Oct 2024 10:50:51 -0400 Subject: [PATCH 3/3] Removed unsound null safety options from classes ModuleMetadata, MetadataProvider & Metadata_test. --- dwds/CHANGELOG.md | 2 +- dwds/lib/src/debugging/metadata/module_metadata.dart | 10 +--------- dwds/lib/src/debugging/metadata/provider.dart | 4 +--- dwds/test/metadata_test.dart | 1 - 4 files changed, 3 insertions(+), 14 deletions(-) diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index 009f1f162..07f7c7543 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -2,7 +2,7 @@ - Replace deprecated JS code `this.__proto__` with `Object.getPrototypeOf(this)`. - [#2500](https://github.com/dart-lang/webdev/pull/2500) - Migrate injected client code to `package:web`. - [#2491](https://github.com/dart-lang/webdev/pull/2491) -- Removed unsound null safety options from classes ModuleMetadata and MetadataProvider - [#2427](https://github.com/dart-lang/webdev/issues/2427) +- Removed unsound null safety options from classes ModuleMetadata, MetadataProvider & Metadata_test. - [#2427](https://github.com/dart-lang/webdev/issues/2427) ## 24.1.0 diff --git a/dwds/lib/src/debugging/metadata/module_metadata.dart b/dwds/lib/src/debugging/metadata/module_metadata.dart index 06c4bdf5a..2a83d1a27 100644 --- a/dwds/lib/src/debugging/metadata/module_metadata.dart +++ b/dwds/lib/src/debugging/metadata/module_metadata.dart @@ -114,10 +114,6 @@ class ModuleMetadata { /// Module uri final String moduleUri; - // Keep the soundNullSafety flag for backward compatibility - @Deprecated('This field is deprecated as sound null safety is enforced.') - final bool soundNullSafety; - final Map libraries = {}; ModuleMetadata( @@ -125,7 +121,6 @@ class ModuleMetadata { this.closureName, this.sourceMapUri, this.moduleUri, { - this.soundNullSafety = true, // Default to true String? ver, }) { version = ver ?? ModuleMetadataVersion.current.version; @@ -151,10 +146,7 @@ class ModuleMetadata { name = _readRequiredField(json, 'name'), closureName = _readRequiredField(json, 'closureName'), sourceMapUri = _readRequiredField(json, 'sourceMapUri'), - moduleUri = _readRequiredField(json, 'moduleUri'), - // Deprecated field still present for backward compatibility - // Defaults to true if missing - soundNullSafety = _readOptionalField(json, 'soundNullSafety') ?? true { + moduleUri = _readRequiredField(json, 'moduleUri') { if (!ModuleMetadataVersion.current.isCompatibleWith(version) && !ModuleMetadataVersion.previous.isCompatibleWith(version)) { throw Exception('Unsupported metadata version $version. ' diff --git a/dwds/lib/src/debugging/metadata/provider.dart b/dwds/lib/src/debugging/metadata/provider.dart index dfe46ec0f..570defb9e 100644 --- a/dwds/lib/src/debugging/metadata/provider.dart +++ b/dwds/lib/src/debugging/metadata/provider.dart @@ -15,8 +15,6 @@ class MetadataProvider { final AssetReader _assetReader; final _logger = Logger('MetadataProvider'); final String entrypoint; - @Deprecated('This field is deprecated as sound null safety is enforced.') - final bool _soundNullSafety = true; final List _libraries = []; final Map _scriptToModule = {}; final Map _moduleToSourceMap = {}; @@ -73,7 +71,7 @@ class MetadataProvider { /// All libraries have to agree on null safety mode. Future get soundNullSafety async { await _initialize(); - return _soundNullSafety; + return true; } /// A list of all libraries in the Dart application. diff --git a/dwds/test/metadata_test.dart b/dwds/test/metadata_test.dart index fc8ae177e..aa320d116 100644 --- a/dwds/test/metadata_test.dart +++ b/dwds/test/metadata_test.dart @@ -114,6 +114,5 @@ void main() { expect(parts.length, 1); expect(parts[0], 'org-dartlang-app:///web/main.dart'); } - expect(metadata.soundNullSafety, true); }); }