From 06d938046f72434f55bb10dd64f58bc9108c470d Mon Sep 17 00:00:00 2001 From: Johnni Winther Date: Wed, 19 Mar 2025 01:37:07 -0700 Subject: [PATCH] [kernel] Remove NonNullableByDefaultCompiledMode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit and TargetFlags.soundNullSafety TEST=existing Change-Id: I5e28d3d187b0f84fa23130c042fd3c55b89c687c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413460 Reviewed-by: Ömer Ağacan Reviewed-by: Jens Johansen Reviewed-by: Alexander Markov Commit-Queue: Johnni Winther Reviewed-by: Nate Biggs --- pkg/compiler/lib/src/compiler.dart | 3 +- pkg/compiler/lib/src/phase/load_kernel.dart | 2 +- pkg/dart2wasm/lib/dynamic_modules.dart | 3 +- pkg/dev_compiler/lib/src/command/command.dart | 9 +- .../kernel/expression_compiler_worker.dart | 6 +- .../lib/src/kernel/module_metadata.dart | 12 +- .../test/module_metadata_test.dart | 3 +- pkg/front_end/lib/src/api_unstable/ddc.dart | 2 +- .../lib/src/base/incremental_compiler.dart | 47 +----- .../lib/src/base/incremental_serializer.dart | 2 +- .../lib/src/base/processed_options.dart | 28 +--- .../lib/src/kernel/kernel_target.dart | 79 +--------- pkg/front_end/lib/src/kernel/utils.dart | 7 +- .../lib/src/kernel_generator_impl.dart | 8 +- .../src/source/source_compilation_unit.dart | 2 - .../lib/src/source/source_loader.dart | 37 ----- .../test/constant_evaluator_benchmark.dart | 19 +-- .../crashing_test_case_minimizer_impl.dart | 1 - pkg/front_end/test/incremental_suite.dart | 29 +--- pkg/front_end/test/split_dill_test.dart | 5 +- .../test/src/base/processed_options_test.dart | 10 +- pkg/front_end/test/testing/suite.dart | 17 -- pkg/front_end/test/utils/kernel_chain.dart | 5 +- pkg/front_end/tool/ast_model.dart | 1 - pkg/front_end/tool/entry_points.dart | 3 +- pkg/frontend_server/lib/compute_kernel.dart | 3 +- pkg/frontend_server/lib/frontend_server.dart | 4 +- .../lib/src/javascript_bundle.dart | 6 +- .../test/native_assets_test.dart | 2 - pkg/kernel/binary.md | 4 +- pkg/kernel/lib/binary/ast_from_binary.dart | 42 +---- pkg/kernel/lib/binary/ast_to_binary.dart | 14 +- pkg/kernel/lib/binary/tag.dart | 2 +- pkg/kernel/lib/src/ast/components.dart | 16 +- pkg/kernel/lib/src/ast/libraries.dart | 34 +--- pkg/kernel/lib/src/equivalence.dart | 8 - pkg/kernel/lib/target/targets.dart | 4 - pkg/kernel/lib/type_environment.dart | 16 -- .../test/binary/component_mode_test.dart | 147 ------------------ pkg/kernel/test/binary/lazy_reading_test.dart | 2 +- .../test/binary/library_flags_test.dart | 41 +---- pkg/kernel/test/binary/utils.dart | 3 +- .../convert_field_to_setter_getter_test.dart | 3 +- .../load_concat_dill_keeps_source_test.dart | 7 +- ...d_field_and_procedure_overwrites_test.dart | 3 +- pkg/kernel/test/relink_test.dart | 3 +- pkg/vm/bin/kernel_service.dart | 8 +- pkg/vm/bin/protobuf_aware_treeshaker.dart | 4 - pkg/vm/lib/incremental_compiler.dart | 11 +- pkg/vm/lib/kernel_front_end.dart | 15 +- .../test/native_assets/synthesizer_test.dart | 1 - .../frontend/kernel_translation_helper.h | 9 -- runtime/vm/kernel_binary.cc | 1 + runtime/vm/kernel_binary.h | 2 +- runtime/vm/kernel_loader.cc | 15 -- runtime/vm/object.h | 9 -- 56 files changed, 81 insertions(+), 698 deletions(-) delete mode 100644 pkg/kernel/test/binary/component_mode_test.dart diff --git a/pkg/compiler/lib/src/compiler.dart b/pkg/compiler/lib/src/compiler.dart index 0dea22aacd2..665d7051141 100644 --- a/pkg/compiler/lib/src/compiler.dart +++ b/pkg/compiler/lib/src/compiler.dart @@ -310,13 +310,12 @@ class Compiler { irLibraries.add(irLibraryMap[library]!); } var mainMethod = component.mainMethodName; - var componentMode = component.mode; final trimmedComponent = ir.Component( libraries: irLibraries, uriToSource: component.uriToSource, nameRoot: component.root, ); - trimmedComponent.setMainMethodAndMode(mainMethod, true, componentMode); + trimmedComponent.setMainMethodAndMode(mainMethod, true); return trimmedComponent; } diff --git a/pkg/compiler/lib/src/phase/load_kernel.dart b/pkg/compiler/lib/src/phase/load_kernel.dart index 8567336fd15..47d058f0db9 100644 --- a/pkg/compiler/lib/src/phase/load_kernel.dart +++ b/pkg/compiler/lib/src/phase/load_kernel.dart @@ -242,7 +242,7 @@ Future<_LoadFromKernelResult> _loadFromKernel( if (options.entryUri != null) { entryLibrary = _findEntryLibrary(component, options.entryUri!); var mainMethod = _findMainMethod(entryLibrary); - component.setMainMethodAndMode(mainMethod, true, component.mode); + component.setMainMethodAndMode(mainMethod, true); } _doTransformsOnKernelLoad(component, options, reporter); diff --git a/pkg/dart2wasm/lib/dynamic_modules.dart b/pkg/dart2wasm/lib/dynamic_modules.dart index 3758d9dea4e..7b497029299 100644 --- a/pkg/dart2wasm/lib/dynamic_modules.dart +++ b/pkg/dart2wasm/lib/dynamic_modules.dart @@ -250,8 +250,7 @@ class DynamicModuleStrategy extends DefaultModuleStrategy with KernelNodes { if (hasPragma(coreTypes, library, _mainLibPragma)) { final mainMethod = library.procedures .firstWhere((m) => hasPragma(coreTypes, m, _mainMethodPragma)); - component.setMainMethodAndMode( - mainMethod.reference, true, component.mode); + component.setMainMethodAndMode(mainMethod.reference, true); } } } diff --git a/pkg/dev_compiler/lib/src/command/command.dart b/pkg/dev_compiler/lib/src/command/command.dart index 4a6fef7a597..5e47117fd6a 100644 --- a/pkg/dev_compiler/lib/src/command/command.dart +++ b/pkg/dev_compiler/lib/src/command/command.dart @@ -839,13 +839,8 @@ ModuleSymbols _emitSymbols(Compiler compiler, String moduleName, ModuleMetadata _emitMetadata(js_ast.Program program, Component component, String sourceMapUri, String moduleUri, String? fullDillUri) { - var metadata = ModuleMetadata( - program.name!, - loadFunctionName(program.name!), - sourceMapUri, - moduleUri, - fullDillUri, - component.mode == NonNullableByDefaultCompiledMode.Strong); + var metadata = ModuleMetadata(program.name!, loadFunctionName(program.name!), + sourceMapUri, moduleUri, fullDillUri); for (var lib in component.libraries) { metadata.addLibrary(LibraryMetadata( 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 2c589e4c0fd..33dab218d08 100644 --- a/pkg/dev_compiler/lib/src/kernel/expression_compiler_worker.dart +++ b/pkg/dev_compiler/lib/src/kernel/expression_compiler_worker.dart @@ -429,8 +429,7 @@ class ExpressionCompilerWorker { libraries: libraries, nameRoot: originalComponent.root, uriToSource: originalComponent.uriToSource, - )..setMainMethodAndMode( - originalComponent.mainMethodName, true, originalComponent.mode); + )..setMainMethodAndMode(originalComponent.mainMethodName, true); _processedOptions.ticker.logMs('Collected libraries for $moduleName'); } @@ -491,8 +490,7 @@ class ExpressionCompilerWorker { libraries: librariesToEmit, nameRoot: finalComponent.root, uriToSource: finalComponent.uriToSource) - ..setMainMethodAndMode( - originalComponent.mainMethodName, true, originalComponent.mode); + ..setMainMethodAndMode(originalComponent.mainMethodName, true); kernel2jsCompiler.emitModule(componentToEmit); _processedOptions.ticker.logMs('Emitted module for expression'); diff --git a/pkg/dev_compiler/lib/src/kernel/module_metadata.dart b/pkg/dev_compiler/lib/src/kernel/module_metadata.dart index 0ed050af967..6b2d0e4ccaa 100644 --- a/pkg/dev_compiler/lib/src/kernel/module_metadata.dart +++ b/pkg/dev_compiler/lib/src/kernel/module_metadata.dart @@ -127,12 +127,8 @@ class ModuleMetadata { final Map libraries = {}; - /// True if the module corresponding to this metadata was compiled with sound - /// null safety enabled. - final bool soundNullSafety; - ModuleMetadata(this.name, this.closureName, this.sourceMapUri, this.moduleUri, - this.fullDillUri, this.soundNullSafety, + this.fullDillUri, {String? version}) : version = version ??= ModuleMetadataVersion.current.version; @@ -157,8 +153,7 @@ class ModuleMetadata { closureName = json['closureName'] as String, sourceMapUri = json['sourceMapUri'] as String, moduleUri = json['moduleUri'] as String, - fullDillUri = json['fullDillUri'] as String, - soundNullSafety = json['soundNullSafety'] as bool { + fullDillUri = json['fullDillUri'] as String { if (!ModuleMetadataVersion.current.isCompatibleWith(version)) { throw Exception('Unsupported metadata version $version'); } @@ -176,8 +171,7 @@ class ModuleMetadata { 'sourceMapUri': sourceMapUri, 'moduleUri': moduleUri, 'fullDillUri': fullDillUri, - 'libraries': [for (var lib in libraries.values) lib.toJson()], - 'soundNullSafety': soundNullSafety + 'libraries': [for (var lib in libraries.values) lib.toJson()] }; } } diff --git a/pkg/dev_compiler/test/module_metadata_test.dart b/pkg/dev_compiler/test/module_metadata_test.dart index e3a74e03e4a..da60be73f23 100644 --- a/pkg/dev_compiler/test/module_metadata_test.dart +++ b/pkg/dev_compiler/test/module_metadata_test.dart @@ -112,7 +112,7 @@ void main() { } ModuleMetadata createMetadata(String version) => ModuleMetadata( - 'module', 'closure', 'module.map', 'module.js', 'module.full.dill', true, + 'module', 'closure', 'module.map', 'module.js', 'module.full.dill', version: version) ..addLibrary(LibraryMetadata('library', 'package:library/test.dart', 'file:///source/library/lib/test.dart', ['src/test2.dart'])); @@ -125,7 +125,6 @@ void testMetadataFields(ModuleMetadata module, String version) { expect(module.sourceMapUri, 'module.map'); expect(module.moduleUri, 'module.js'); expect(module.fullDillUri, 'module.full.dill'); - expect(module.soundNullSafety, true); var libUri = module.libraries.keys.first; var lib = module.libraries[libUri]!; diff --git a/pkg/front_end/lib/src/api_unstable/ddc.dart b/pkg/front_end/lib/src/api_unstable/ddc.dart index ff315b4df36..0f8d48ba175 100644 --- a/pkg/front_end/lib/src/api_unstable/ddc.dart +++ b/pkg/front_end/lib/src/api_unstable/ddc.dart @@ -80,7 +80,7 @@ class DdcResult { Component _computeCompiledLibraries() { Component compiledLibraries = new Component( nameRoot: component.root, uriToSource: component.uriToSource) - ..setMainMethodAndMode(null, false, component.mode); + ..setMainMethodAndMode(null, false); for (Library lib in component.libraries) { if (!librariesFromDill.contains(lib)) { compiledLibraries.libraries.add(lib); diff --git a/pkg/front_end/lib/src/base/incremental_compiler.dart b/pkg/front_end/lib/src/base/incremental_compiler.dart index 3895b71f198..347ab2ab375 100644 --- a/pkg/front_end/lib/src/base/incremental_compiler.dart +++ b/pkg/front_end/lib/src/base/incremental_compiler.dart @@ -14,8 +14,7 @@ import 'package:kernel/binary/ast_from_binary.dart' CompilationModeError, InvalidKernelSdkVersionError, InvalidKernelVersionError, - SubComponentView, - mergeCompilationModeOrThrow; + SubComponentView; import 'package:kernel/canonical_name.dart' show CanonicalNameError, CanonicalNameSdkError; import 'package:kernel/class_hierarchy.dart' @@ -39,7 +38,6 @@ import 'package:kernel/kernel.dart' Name, NamedNode, Node, - NonNullableByDefaultCompiledMode, Procedure, ProcedureKind, Reference, @@ -492,14 +490,9 @@ class IncrementalCompiler implements IncrementalKernelGenerator { data.component?.mainMethod : componentWithDill.mainMethod; // ignore: unnecessary_null_comparison - NonNullableByDefaultCompiledMode? compiledMode = componentWithDill == null - ? - // Coverage-ignore(suite): Not run. - data.component?.mode - : componentWithDill.mode; Component result = context.options.target.configureComponent( new Component(libraries: outputLibraries, uriToSource: uriToSource)) - ..setMainMethodAndMode(mainMethod?.reference, true, compiledMode!) + ..setMainMethodAndMode(mainMethod?.reference, true) ..problemsAsJson = problemsAsJson; // Copy the metadata *just created*. This will likely not contain metadata @@ -944,28 +937,9 @@ class IncrementalCompiler implements IncrementalKernelGenerator { _dillLoadedData!.loader.currentSourceLoader = kernelTarget.loader; // Re-use the libraries we've deemed re-usable. - List seenModes = [false, false, false, false]; for (DillLibraryBuilder library in reusedLibraries) { - seenModes[library.library.nonNullableByDefaultCompiledMode.index] = true; kernelTarget.loader.registerLoadedDillLibraryBuilder(library); } - // Check compilation mode up against what we've seen here and set - // `hasInvalidNnbdModeLibrary` accordingly. - if (c.options.globalFeatures.nonNullable.isEnabled) { - // Don't expect weak or invalid. - if (seenModes[NonNullableByDefaultCompiledMode.Weak.index] || - seenModes[NonNullableByDefaultCompiledMode.Invalid.index]) { - // Coverage-ignore-block(suite): Not run. - kernelTarget.loader.hasInvalidNnbdModeLibrary = true; - } - } else { - // Coverage-ignore-block(suite): Not run. - // Don't expect strong or invalid. - if (seenModes[NonNullableByDefaultCompiledMode.Strong.index] || - seenModes[NonNullableByDefaultCompiledMode.Invalid.index]) { - kernelTarget.loader.hasInvalidNnbdModeLibrary = true; - } - } // The entry point(s) has to be set first for loader.firstUri to be setup // correctly. @@ -2491,8 +2465,7 @@ class _InitializationFromComponent extends _InitializationStrategy { .mainMethod // Coverage-ignore(suite): Not run. ?.reference, - true, - componentToInitializeFrom.mode); + true); componentProblems.saveComponentProblems(component); bool foundDartCore = false; @@ -2621,10 +2594,6 @@ class _InitializationFromUri extends _InitializationFromSdkSummary { .readComponent(data.component!, checkCanonicalNames: true, createView: true)!; - // Compute "output nnbd mode". - NonNullableByDefaultCompiledMode compiledMode = - NonNullableByDefaultCompiledMode.Strong; - // Check the any package-urls still point to the same file // (e.g. the package still exists and hasn't been updated). // Also verify NNBD settings. @@ -2638,16 +2607,6 @@ class _InitializationFromUri extends _InitializationFromSdkSummary { // For now just don't initialize from this dill. throw const PackageChangedError(); } - // Note: If a library has a NonNullableByDefaultCompiledMode.invalid - // we will throw and we won't initialize from it. - // That's wanted behavior. - if (compiledMode != - mergeCompilationModeOrThrow( - compiledMode, lib.nonNullableByDefaultCompiledMode)) { - throw new CompilationModeError( - "Can't compile to $compiledMode with library with mode " - "${lib.nonNullableByDefaultCompiledMode}."); - } } // Only initialize the incremental serializer when we know we'll diff --git a/pkg/front_end/lib/src/base/incremental_serializer.dart b/pkg/front_end/lib/src/base/incremental_serializer.dart index 3c102890b8f..fac3bef03c2 100644 --- a/pkg/front_end/lib/src/base/incremental_serializer.dart +++ b/pkg/front_end/lib/src/base/incremental_serializer.dart @@ -298,7 +298,7 @@ class IncrementalSerializer { libraries: libraries, uriToSource: component.uriToSource, nameRoot: component.root); - singlePackageLibraries.setMainMethodAndMode(null, false, component.mode); + singlePackageLibraries.setMainMethodAndMode(null, false); // Copy all metadata. This should be okay (e.g. not result in a leak) // because we serialize now and then (implicitly) throw this component away. diff --git a/pkg/front_end/lib/src/base/processed_options.dart b/pkg/front_end/lib/src/base/processed_options.dart index 0ad9353c229..c7155c55284 100644 --- a/pkg/front_end/lib/src/base/processed_options.dart +++ b/pkg/front_end/lib/src/base/processed_options.dart @@ -13,12 +13,7 @@ import 'package:_fe_analyzer_shared/src/util/libraries_specification.dart' TargetLibrariesSpecification; import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder; import 'package:kernel/kernel.dart' - show - CanonicalName, - Component, - Location, - NonNullableByDefaultCompiledMode, - Version; + show CanonicalName, Component, Location, Version; import 'package:kernel/target/targets.dart' show NoneTarget, Target, TargetFlags; import 'package:package_config/package_config.dart'; @@ -454,7 +449,7 @@ class ProcessedOptions { Target? _target; Target get target => _target ??= _raw.target ?? // Coverage-ignore(suite): Not run. - new NoneTarget(new TargetFlags(soundNullSafety: true)); + new NoneTarget(new TargetFlags()); /// Returns the global state of the experimental features. flags.GlobalFeatures get globalFeatures => _raw.globalFeatures; @@ -477,22 +472,6 @@ class ProcessedOptions { return _raw.isExperimentEnabledInLibraryByVersion(flag, importUri, version); } - Component _validateNullSafetyMode(Component component) { - if (component.mode == NonNullableByDefaultCompiledMode.Invalid) { - throw new FormatException( - 'Provided .dill file for the following libraries has an invalid null ' - 'safety mode and does not support null safety:\n' - '${component.libraries.join('\n')}'); - } - if (component.mode != NonNullableByDefaultCompiledMode.Strong) { - throw new FormatException( - 'Provided .dill file for the following libraries does not ' - 'support sound null safety:\n' - '${component.libraries.join('\n')}'); - } - return component; - } - /// Get an outline component that summarizes the SDK, if any. // TODO(sigmund): move, this doesn't feel like an "option". Future loadSdkSummary(CanonicalName? nameRoot) async { @@ -512,7 +491,6 @@ class ProcessedOptions { if (_sdkSummaryComponent != null) { throw new StateError("sdkSummary already loaded."); } - _validateNullSafetyMode(platform); _sdkSummaryComponent = platform; } @@ -550,7 +528,7 @@ class ProcessedOptions { disableLazyReading: false, alwaysCreateNewNamedNodes: alwaysCreateNewNamedNodes) .readComponent(component); - return _validateNullSafetyMode(component); + return component; } /// Get the [UriTranslator] which resolves "package:" and "dart:" URIs. diff --git a/pkg/front_end/lib/src/kernel/kernel_target.dart b/pkg/front_end/lib/src/kernel/kernel_target.dart index aef1aad36f6..70792fabbbc 100644 --- a/pkg/front_end/lib/src/kernel/kernel_target.dart +++ b/pkg/front_end/lib/src/kernel/kernel_target.dart @@ -760,12 +760,6 @@ class KernelTarget { Component component = backendTarget.configureComponent(new Component( nameRoot: nameRoot, libraries: libraries, uriToSource: uriToSource)); - NonNullableByDefaultCompiledMode? compiledMode = - NonNullableByDefaultCompiledMode.Strong; - if (loader.hasInvalidNnbdModeLibrary) { - compiledMode = NonNullableByDefaultCompiledMode.Invalid; - } - Reference? mainReference; LibraryBuilder? firstRoot = loader.rootLibrary; @@ -785,83 +779,12 @@ class KernelTarget { mainReference = declaration.invokeTarget.reference; } } - component.setMainMethodAndMode(mainReference, true, compiledMode); - - assert(_getLibraryNnbdModeError(component) == null, - "Got error: ${_getLibraryNnbdModeError(component)}"); + component.setMainMethodAndMode(mainReference, true); ticker.logMs("Linked component"); return component; } - String? _getLibraryNnbdModeError(Component component) { - if (loader.hasInvalidNnbdModeLibrary) { - // Coverage-ignore-block(suite): Not run. - // At least 1 library should be invalid or there should be a mix of strong - // and weak. For libraries we've just compiled it will be marked as - // invalid, but for libraries loaded from dill they have their original - // value (i.e. either strong or weak). - bool foundInvalid = false; - bool foundStrong = false; - bool foundWeak = false; - for (Library library in component.libraries) { - if (library.nonNullableByDefaultCompiledMode == - NonNullableByDefaultCompiledMode.Invalid) { - foundInvalid = true; - break; - } else if (!foundWeak && - library.nonNullableByDefaultCompiledMode == - NonNullableByDefaultCompiledMode.Weak) { - foundWeak = true; - if (foundStrong) break; - } else if (!foundStrong && - library.nonNullableByDefaultCompiledMode == - NonNullableByDefaultCompiledMode.Strong) { - foundStrong = true; - if (foundWeak) break; - } - } - if (!foundInvalid && !(foundStrong && foundWeak)) { - return "hasInvalidNnbdModeLibrary is true, but no library was invalid " - "and there was no weak/strong mix."; - } - if (component.mode != NonNullableByDefaultCompiledMode.Invalid) { - return "Component mode is not invalid as expected"; - } - } else { - // No libraries are allowed to be invalid, and should all be compatible - // with the component nnbd mode setting. - if (component.mode == NonNullableByDefaultCompiledMode.Invalid) { - return "Component mode is invalid which was not expected"; - } - if (component.modeRaw == null) { - return "Component mode not set at all"; - } - for (Library library in component.libraries) { - if (component.mode == NonNullableByDefaultCompiledMode.Strong) { - if (library.nonNullableByDefaultCompiledMode != - NonNullableByDefaultCompiledMode.Strong) { - // Coverage-ignore-block(suite): Not run. - return "Expected library ${library.importUri} to be strong, " - "but was ${library.nonNullableByDefaultCompiledMode}"; - } - } - // Coverage-ignore(suite): Not run. - else if (component.mode == NonNullableByDefaultCompiledMode.Weak) { - if (library.nonNullableByDefaultCompiledMode != - NonNullableByDefaultCompiledMode.Weak) { - return "Expected library ${library.importUri} to be weak, " - "but was ${library.nonNullableByDefaultCompiledMode}"; - } - } else { - return "Expected component mode to be either strong, " - "weak or agnostic but was ${component.mode}"; - } - } - } - return null; - } - void installDefaultSupertypes() { Class objectClass = this.objectClass; for (SourceLibraryBuilder library in loader.sourceLibraryBuilders) { diff --git a/pkg/front_end/lib/src/kernel/utils.dart b/pkg/front_end/lib/src/kernel/utils.dart index 1d98887460b..8c6b7fce0da 100644 --- a/pkg/front_end/lib/src/kernel/utils.dart +++ b/pkg/front_end/lib/src/kernel/utils.dart @@ -153,9 +153,7 @@ Component createExpressionEvaluationComponent(Procedure procedure) { Uri uri = new Uri(scheme: 'evaluate', path: 'source'); Library fakeLibrary = new Library(uri, fileUri: uri) - ..setLanguageVersion(realLibrary.languageVersion) - ..nonNullableByDefaultCompiledMode = - realLibrary.nonNullableByDefaultCompiledMode; + ..setLanguageVersion(realLibrary.languageVersion); // Add deferred library dependencies. They are needed for serializing // references to deferred libraries. We can just claim ownership of the ones @@ -209,8 +207,7 @@ Component createExpressionEvaluationComponent(Procedure procedure) { // TODO(vegorov) find a way to preserve metadata. Component component = new Component(libraries: [fakeLibrary]); - component.setMainMethodAndMode( - null, false, fakeLibrary.nonNullableByDefaultCompiledMode); + component.setMainMethodAndMode(null, false); return component; } diff --git a/pkg/front_end/lib/src/kernel_generator_impl.dart b/pkg/front_end/lib/src/kernel_generator_impl.dart index 52b7f3fba78..3bbd30789ee 100644 --- a/pkg/front_end/lib/src/kernel_generator_impl.dart +++ b/pkg/front_end/lib/src/kernel_generator_impl.dart @@ -186,14 +186,8 @@ Future _buildInternal(CompilerContext compilerContext, trimmedSummaryComponent.metadata.addAll(summaryComponent.metadata); trimmedSummaryComponent.uriToSource.addAll(summaryComponent.uriToSource); - NonNullableByDefaultCompiledMode compiledMode = - NonNullableByDefaultCompiledMode.Strong; - if (kernelTarget.loader.hasInvalidNnbdModeLibrary) { - compiledMode = NonNullableByDefaultCompiledMode.Invalid; - } - trimmedSummaryComponent.setMainMethodAndMode( - trimmedSummaryComponent.mainMethodName, false, compiledMode); + trimmedSummaryComponent.mainMethodName, false); // As documented, we only run outline transformations when we are building // summaries without building a full component (at this time, that's diff --git a/pkg/front_end/lib/src/source/source_compilation_unit.dart b/pkg/front_end/lib/src/source/source_compilation_unit.dart index 197b76c8d0b..e882d0c7e0f 100644 --- a/pkg/front_end/lib/src/source/source_compilation_unit.dart +++ b/pkg/front_end/lib/src/source/source_compilation_unit.dart @@ -984,8 +984,6 @@ class SourceCompilationUnitImpl implements SourceCompilationUnit { @override void buildOutlineNode(Library library) { - library.nonNullableByDefaultCompiledMode = - NonNullableByDefaultCompiledMode.Strong; for (LibraryPart libraryPart in _builderFactoryResult.libraryParts) { library.addPart(libraryPart); } diff --git a/pkg/front_end/lib/src/source/source_loader.dart b/pkg/front_end/lib/src/source/source_loader.dart index ad22718f14c..4ca2653ffc3 100644 --- a/pkg/front_end/lib/src/source/source_loader.dart +++ b/pkg/front_end/lib/src/source/source_loader.dart @@ -602,28 +602,11 @@ class SourceLoader extends Loader { DillLibraryBuilder? libraryBuilder = target.dillTarget.loader.lookupLibraryBuilder(uri); if (libraryBuilder != null) { - _checkDillLibraryBuilderNnbdMode(libraryBuilder); _checkForDartCore(uri, libraryBuilder.mainCompilationUnit); } return libraryBuilder; } - void _checkDillLibraryBuilderNnbdMode(DillLibraryBuilder libraryBuilder) { - NonNullableByDefaultCompiledMode libraryMode = - libraryBuilder.library.nonNullableByDefaultCompiledMode; - if (libraryMode == NonNullableByDefaultCompiledMode.Invalid) { - // Coverage-ignore-block(suite): Not run. - registerNnbdMismatchLibrary( - libraryBuilder, messageInvalidNnbdDillLibrary); - } else { - if (libraryMode != NonNullableByDefaultCompiledMode.Strong) { - // Coverage-ignore-block(suite): Not run. - registerNnbdMismatchLibrary( - libraryBuilder, messageStrongWithWeakDillLibrary); - } - } - } - void _markDartLibraries(Uri uri, CompilationUnit compilationUnit) { if (uri.isScheme("dart")) { if (uri.path == "core") { @@ -1094,18 +1077,6 @@ severity: $severity }); } - bool hasInvalidNnbdModeLibrary = false; - - Map? _nnbdMismatchLibraries; - - // Coverage-ignore(suite): Not run. - void registerNnbdMismatchLibrary( - LibraryBuilder libraryBuilder, Message message) { - _nnbdMismatchLibraries ??= {}; - _nnbdMismatchLibraries![libraryBuilder] = message; - hasInvalidNnbdModeLibrary = true; - } - void registerConstructorToBeInferred(InferableMember inferableMember) { _typeInferenceEngine!.toBeInferred[inferableMember.member] = inferableMember; @@ -1136,14 +1107,6 @@ severity: $severity } currentUriForCrashReporting = null; logSummary(outlineSummaryTemplate); - if (_nnbdMismatchLibraries != null) { - // Coverage-ignore-block(suite): Not run. - for (MapEntry entry - in _nnbdMismatchLibraries!.entries) { - addProblem(entry.value, -1, noLength, entry.key.fileUri); - } - _nnbdMismatchLibraries = null; - } if (_unavailableDartLibraries.isNotEmpty) { CompilationUnit? rootLibrary = rootCompilationUnit; LoadedLibraries? loadedLibraries; diff --git a/pkg/front_end/test/constant_evaluator_benchmark.dart b/pkg/front_end/test/constant_evaluator_benchmark.dart index 578cc98c781..b46dd0224d9 100644 --- a/pkg/front_end/test/constant_evaluator_benchmark.dart +++ b/pkg/front_end/test/constant_evaluator_benchmark.dart @@ -10,8 +10,6 @@ import 'package:compiler/src/kernel/dart2js_target.dart' show Dart2jsTarget; import 'package:dev_compiler/src/kernel/target.dart' show DevCompilerTarget; import 'package:front_end/src/api_prototype/compiler_options.dart' show CompilerOptions, DiagnosticMessage; -import 'package:front_end/src/api_prototype/experimental_flags.dart' - show ExperimentalFlag; import 'package:front_end/src/base/compiler_context.dart' show CompilerContext; import 'package:front_end/src/base/incremental_compiler.dart' show IncrementalCompiler; @@ -128,15 +126,12 @@ late IncrementalCompiler incrementalCompiler; Future main(List arguments) async { Uri? platformUri; Uri mainUri; - bool nnbd = false; String targetString = "VM"; String? filename; for (String arg in arguments) { if (arg.startsWith("--")) { - if (arg == "--nnbd") { - nnbd = true; - } else if (arg.startsWith("--platform=")) { + if (arg.startsWith("--platform=")) { String platform = arg.substring("--platform=".length); platformUri = Uri.base.resolve(platform); } else if (arg == "--target=VM") { @@ -178,20 +173,16 @@ Future main(List arguments) async { mainUri = file.absolute.uri; incrementalCompiler = new IncrementalCompiler( - setupCompilerContext(nnbd, targetString, false, platformUri, mainUri)); + setupCompilerContext(targetString, false, platformUri, mainUri)); await incrementalCompiler.computeDelta(); } -CompilerContext setupCompilerContext(bool nnbd, String targetString, +CompilerContext setupCompilerContext(String targetString, bool widgetTransformation, Uri platformUri, Uri mainUri) { CompilerOptions options = getOptions(); - if (nnbd) { - options.explicitExperimentalFlags = {ExperimentalFlag.nonNullable: true}; - } - - TargetFlags targetFlags = new TargetFlags( - soundNullSafety: nnbd, trackWidgetCreation: widgetTransformation); + TargetFlags targetFlags = + new TargetFlags(trackWidgetCreation: widgetTransformation); Target target; switch (targetString) { case "VM": diff --git a/pkg/front_end/test/crashing_test_case_minimizer_impl.dart b/pkg/front_end/test/crashing_test_case_minimizer_impl.dart index 7260229a487..9bff27cbe57 100644 --- a/pkg/front_end/test/crashing_test_case_minimizer_impl.dart +++ b/pkg/front_end/test/crashing_test_case_minimizer_impl.dart @@ -2075,7 +2075,6 @@ worlds: } TargetFlags targetFlags = new TargetFlags( - soundNullSafety: false, trackWidgetCreation: _settings.widgetTransformation); Target target; switch (_settings.targetString) { diff --git a/pkg/front_end/test/incremental_suite.dart b/pkg/front_end/test/incremental_suite.dart index 8aefea1335b..0ee33235a51 100644 --- a/pkg/front_end/test/incremental_suite.dart +++ b/pkg/front_end/test/incremental_suite.dart @@ -751,7 +751,7 @@ Future> createModules( throw "Module probably not setup right."; } Component result = new Component(libraries: wantedLibs) - ..setMainMethodAndMode(null, false, c.mode); + ..setMainMethodAndMode(null, false); Uint8List resultBytes = util.postProcess(result); moduleResult[moduleName] = resultBytes; } @@ -1387,9 +1387,6 @@ class NewWorldTest { world, data, compilerResult.neededDillLibraries, base); if (result != null) return result; - Result? nnbdCheck = checkNNBDSettings(component!); - if (nnbdCheck != null) return nnbdCheck.copyWithOutput(data); - if (!world.noFullComponent) { Set allLibraries = new Set(); for (Library lib in component!.libraries) { @@ -1885,26 +1882,6 @@ class Strategy extends EquivalenceStrategy { } } -Result? checkNNBDSettings(Component component) { - NonNullableByDefaultCompiledMode mode = component.mode; - if (mode == NonNullableByDefaultCompiledMode.Invalid) return null; - for (Library lib in component.libraries) { - if (mode == lib.nonNullableByDefaultCompiledMode) continue; - - if (mode == NonNullableByDefaultCompiledMode.Strong || - lib.nonNullableByDefaultCompiledMode == - NonNullableByDefaultCompiledMode.Strong) { - // Non agnostic and one (but not both) are strong => error. - return new Result( - null, - NNBDModeMismatch, - "Component mode was $mode but ${lib.importUri} had mode " - "${lib.nonNullableByDefaultCompiledMode}."); - } - } - return null; -} - Result? checkExpectFile(TestData data, int worldNum, String extraUriString, Context context, String actualSerialized) { Uri uri = data.loadedFrom.resolve(data.loadedFrom.pathSegments.last + @@ -2158,7 +2135,7 @@ Result checkIncrementalSerialization( World world) { if (incrementalSerialization == true) { Component c = new Component(nameRoot: component.root) - ..setMainMethodAndMode(null, false, component.mode); + ..setMainMethodAndMode(null, false); c.libraries.addAll(component.libraries); c.uriToSource.addAll(component.uriToSource); Map> originalContent = buildMapOfContent(c); @@ -2397,7 +2374,7 @@ String componentToStringSdkFiltered(Component component, c.libraries.add(lib); } } - c.setMainMethodAndMode(component.mainMethodName, true, component.mode); + c.setMainMethodAndMode(component.mainMethodName, true); c.problemsAsJson = component.problemsAsJson; StringBuffer s = new StringBuffer(); diff --git a/pkg/front_end/test/split_dill_test.dart b/pkg/front_end/test/split_dill_test.dart index 53311dfe490..b119103d4dd 100644 --- a/pkg/front_end/test/split_dill_test.dart +++ b/pkg/front_end/test/split_dill_test.dart @@ -19,7 +19,7 @@ Future main() async { Stopwatch stopwatch = new Stopwatch()..start(); Component component = await normalCompileToComponent(dart2jsUrl, options: getOptions() - ..target = new VmTarget(new TargetFlags(soundNullSafety: false)) + ..target = new VmTarget(new TargetFlags()) ..omitPlatform = false); print("Compiled dart2js in ${stopwatch.elapsedMilliseconds} ms"); @@ -31,8 +31,7 @@ Future main() async { Component libComponent = new Component(nameRoot: component.root); libComponent.libraries.add(lib); libComponent.uriToSource.addAll(component.uriToSource); - libComponent.setMainMethodAndMode( - component.mainMethodName, true, component.mode); + libComponent.setMainMethodAndMode(component.mainMethodName, true); libComponents.add(serializeComponent(libComponent)); } print("Serialized ${libComponents.length} separate library components " diff --git a/pkg/front_end/test/src/base/processed_options_test.dart b/pkg/front_end/test/src/base/processed_options_test.dart index 6847448e86d..bad0a0d85d3 100644 --- a/pkg/front_end/test/src/base/processed_options_test.dart +++ b/pkg/front_end/test/src/base/processed_options_test.dart @@ -12,12 +12,7 @@ import 'package:front_end/src/codes/cfe_codes.dart'; import 'package:front_end/src/util/bytes_sink.dart' show BytesSink; import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter; import 'package:kernel/kernel.dart' - show - CanonicalName, - Library, - Component, - loadComponentFromBytes, - NonNullableByDefaultCompiledMode; + show CanonicalName, Library, Component, loadComponentFromBytes; import 'package:package_config/package_config.dart'; import 'package:test/test.dart'; import 'package:test_reflective_loader/test_reflective_loader.dart'; @@ -75,8 +70,7 @@ class ProcessedOptionsTest { new Library(Uri.parse('org-dartlang-test:///a/b.dart'), fileUri: Uri.parse('org-dartlang-test:///a/b.dart')) ]) - ..setMainMethodAndMode( - null, false, NonNullableByDefaultCompiledMode.Strong); + ..setMainMethodAndMode(null, false); void test_compileSdk_false() { for (var value in [false, true]) { diff --git a/pkg/front_end/test/testing/suite.dart b/pkg/front_end/test/testing/suite.dart index 305517ad918..4544d996dea 100644 --- a/pkg/front_end/test/testing/suite.dart +++ b/pkg/front_end/test/testing/suite.dart @@ -68,7 +68,6 @@ import 'package:kernel/ast.dart' LibraryPart, Member, Node, - NonNullableByDefaultCompiledMode, RecursiveVisitor, Reference, TreeNode, @@ -501,22 +500,6 @@ class Run extends Step { await StdioProcess.run(context.vm.toFilePath(), args); print(process.output); Result runResult = process.toResult(); - if (result.component.mode == - NonNullableByDefaultCompiledMode.Invalid) { - // In this case we expect and want a runtime error. - if (runResult.outcome == - ExpectationSet.defaultExpectations["RuntimeError"]) { - // We convert this to pass because that's exactly what we'd - // expect. - return pass(result); - } else { - // Different outcome - that's a failure! - return new Result( - result, - ExpectationSet.defaultExpectations["MissingRuntimeError"], - runResult.error); - } - } return new Result( result, runResult.outcome, runResult.error); case "none": diff --git a/pkg/front_end/test/utils/kernel_chain.dart b/pkg/front_end/test/utils/kernel_chain.dart index fb8ddaaf4f1..b2c889765a1 100644 --- a/pkg/front_end/test/utils/kernel_chain.dart +++ b/pkg/front_end/test/utils/kernel_chain.dart @@ -475,7 +475,7 @@ class MatchExpectation ByteSink sink = new ByteSink(); Component writeMe = new Component( libraries: component.libraries.where(result.isUserLibrary).toList()) - ..setMainMethodAndMode(null, false, component.mode); + ..setMainMethodAndMode(null, false); writeMe.uriToSource.addAll(component.uriToSource); if (component.problemsAsJson != null) { writeMe.problemsAsJson = @@ -637,8 +637,7 @@ class WriteDill extends Step { Component userCode = new Component( nameRoot: component.root, uriToSource: new Map.from(component.uriToSource)); - userCode.setMainMethodAndMode( - component.mainMethodName, true, component.mode); + userCode.setMainMethodAndMode(component.mainMethodName, true); List auxiliaryLibraries = []; for (Library library in component.libraries) { bool includeLibrary; diff --git a/pkg/front_end/tool/ast_model.dart b/pkg/front_end/tool/ast_model.dart index 9d1748db437..067c397096f 100644 --- a/pkg/front_end/tool/ast_model.dart +++ b/pkg/front_end/tool/ast_model.dart @@ -87,7 +87,6 @@ const Map> _fieldRuleMap = { 'Component': { 'root': null, '_mainMethodName': FieldRule(name: 'mainMethodName'), - '_mode': FieldRule(name: 'mode'), }, 'Library': { '_languageVersion': FieldRule(name: 'languageVersion'), diff --git a/pkg/front_end/tool/entry_points.dart b/pkg/front_end/tool/entry_points.dart index ec777bab45b..f2f9a537173 100644 --- a/pkg/front_end/tool/entry_points.dart +++ b/pkg/front_end/tool/entry_points.dart @@ -394,8 +394,7 @@ Future _emitComponent(ProcessedOptions options, Component component, Component userCode = new Component( nameRoot: component.root, uriToSource: new Map.from(component.uriToSource)); - userCode.setMainMethodAndMode( - component.mainMethodName, true, component.mode); + userCode.setMainMethodAndMode(component.mainMethodName, true); for (Library library in component.libraries) { if (!library.importUri.isScheme("dart")) { userCode.libraries.add(library); diff --git a/pkg/frontend_server/lib/compute_kernel.dart b/pkg/frontend_server/lib/compute_kernel.dart index 1f550208b46..6801358e599 100644 --- a/pkg/frontend_server/lib/compute_kernel.dart +++ b/pkg/frontend_server/lib/compute_kernel.dart @@ -421,8 +421,7 @@ Future computeKernel(List args, if (summaryOnly) { incrementalComponent.uriToSource.clear(); incrementalComponent.problemsAsJson = null; - incrementalComponent.setMainMethodAndMode( - null, true, incrementalComponent.mode); + incrementalComponent.setMainMethodAndMode(null, true); target.performOutlineTransformations(incrementalComponent); makeStable(incrementalComponent); return new Future.value(fe.serializeComponent(incrementalComponent, diff --git a/pkg/frontend_server/lib/frontend_server.dart b/pkg/frontend_server/lib/frontend_server.dart index 69e22421f41..e9a84d023eb 100644 --- a/pkg/frontend_server/lib/frontend_server.dart +++ b/pkg/frontend_server/lib/frontend_server.dart @@ -928,7 +928,6 @@ class FrontendCompiler implements CompilerInterface { final BinaryPrinter printer = new BinaryPrinter(sink); printer.writeComponentFile(new Component( libraries: [nativeAssetsLibrary], - mode: nativeAssetsLibrary.nonNullableByDefaultCompiledMode, )); } await sink.close(); @@ -956,7 +955,6 @@ class FrontendCompiler implements CompilerInterface { final BinaryPrinter printer = new BinaryPrinter(sink); printer.writeComponentFile(new Component( libraries: [nativeAssetsLibrary], - mode: nativeAssetsLibrary.nonNullableByDefaultCompiledMode, )); await sink.close(); } @@ -1254,7 +1252,7 @@ class FrontendCompiler implements CompilerInterface { libraries: libraries, uriToSource: deltaProgram.uriToSource, nameRoot: deltaProgram.root); - singleLibrary.setMainMethodAndMode(null, false, deltaProgram.mode); + singleLibrary.setMainMethodAndMode(null, false); ByteSink byteSink = new ByteSink(); final BinaryPrinter printer = printerFactory.newBinaryPrinter(byteSink); printer.writeComponentFile(singleLibrary); diff --git a/pkg/frontend_server/lib/src/javascript_bundle.dart b/pkg/frontend_server/lib/src/javascript_bundle.dart index b7bb01316c7..d39a82f6bd7 100644 --- a/pkg/frontend_server/lib/src/javascript_bundle.dart +++ b/pkg/frontend_server/lib/src/javascript_bundle.dart @@ -137,8 +137,7 @@ class IncrementalJavaScriptBundler { _lastFullComponent = new Component( libraries: combined.values.toList(), uriToSource: uriToSource, - )..setMainMethodAndMode( - candidate.mainMethod?.reference, true, candidate.mode); + )..setMainMethodAndMode(candidate.mainMethod?.reference, true); for (final MetadataRepository repo in candidate.metadata.values) { _lastFullComponent.addMetadataRepository(repo); } @@ -155,8 +154,7 @@ class IncrementalJavaScriptBundler { nameRoot: _lastFullComponent.root, uriToSource: _lastFullComponent.uriToSource, ); - summaryComponent.setMainMethodAndMode( - null, false, _currentComponent.mode); + summaryComponent.setMainMethodAndMode(null, false); String baseName = urlForComponentUri(uri, packageConfig); _summaryToLibraryBundleJSPath[uri] = '$baseName.lib.js'; diff --git a/pkg/frontend_server/test/native_assets_test.dart b/pkg/frontend_server/test/native_assets_test.dart index b568f3b37a7..e3d9e48a387 100644 --- a/pkg/frontend_server/test/native_assets_test.dart +++ b/pkg/frontend_server/test/native_assets_test.dart @@ -101,8 +101,6 @@ void main() { final Library firstLib = component.libraries.first; expect(firstLib.importUri != _nativeAssetsLibraryUri, true); expect(nativeAssetsLibrary!.nonNullable, firstLib.nonNullable); - expect(nativeAssetsLibrary.nonNullableByDefaultCompiledMode, - firstLib.nonNullableByDefaultCompiledMode); await mainFile.writeAsString(''' void main() { diff --git a/pkg/kernel/binary.md b/pkg/kernel/binary.md index 3f36b5a23e5..f70fd667d6c 100644 --- a/pkg/kernel/binary.md +++ b/pkg/kernel/binary.md @@ -147,7 +147,7 @@ type CanonicalName { type ComponentFile { UInt32 magic = 0x90ABCDEF; - UInt32 formatVersion = 122; + UInt32 formatVersion = 123; Byte[10] shortSdkHash; List problemsAsJson; // Described in problems.md. Library[] libraries; @@ -188,7 +188,7 @@ type ComponentIndex { UInt32 binaryOffsetForStringTable; UInt32 binaryOffsetForStartOfComponentIndex; UInt32 mainMethodReference; // This is a ProcedureReference with a fixed-size integer. - UInt32 compilationMode; // enum NonNullableByDefaultCompiledMode { Disabled = 0, Weak = 1, Strong = 2, Agnostic = 3 } with a fixed-size integer. + UInt32 _dummy; // TODO(jensj): Previously the component mode. Remove this. UInt32[libraryCount + 1] libraryOffsets; UInt32 libraryCount; UInt32 componentFileSizeInBytes; diff --git a/pkg/kernel/lib/binary/ast_from_binary.dart b/pkg/kernel/lib/binary/ast_from_binary.dart index 4ef352d9b24..33d1ec6a3ce 100644 --- a/pkg/kernel/lib/binary/ast_from_binary.dart +++ b/pkg/kernel/lib/binary/ast_from_binary.dart @@ -78,7 +78,6 @@ class _ComponentIndex { final int binaryOffsetForConstantTableIndex; final int binaryOffsetForStartOfComponentIndex; final int mainMethodReference; - final NonNullableByDefaultCompiledMode compiledMode; final List libraryOffsets; final int libraryCount; final int componentFileSizeInBytes; @@ -93,7 +92,6 @@ class _ComponentIndex { required this.binaryOffsetForConstantTableIndex, required this.binaryOffsetForStartOfComponentIndex, required this.mainMethodReference, - required this.compiledMode, required this.libraryOffsets, required this.libraryCount, required this.componentFileSizeInBytes}); @@ -155,7 +153,6 @@ class BinaryBuilder { int _transformerFlags = 0; Library? _currentLibrary; int _componentStartOffset = 0; - NonNullableByDefaultCompiledMode? compilationMode; // If something goes wrong, this list should indicate what library, // class, and member was being built. @@ -808,8 +805,8 @@ class BinaryBuilder { int binaryOffsetForStartOfComponentIndex = _componentStartOffset + readUint32(); int mainMethodReference = readUint32(); - NonNullableByDefaultCompiledMode compiledMode = - NonNullableByDefaultCompiledMode.values[readUint32()]; + // TODO(jensj): Previously the component mode. Remove this. + readUint32(); for (int i = 0; i < libraryCount + 1; ++i) { libraryOffsets[i] = _componentStartOffset + readUint32(); } @@ -829,8 +826,7 @@ class BinaryBuilder { binaryOffsetForConstantTableIndex: binaryOffsetForConstantTableIndex, binaryOffsetForStartOfComponentIndex: binaryOffsetForStartOfComponentIndex, - mainMethodReference: mainMethodReference, - compiledMode: compiledMode); + mainMethodReference: mainMethodReference); } void _readOneComponentSource(Component component, int componentFileSize) { @@ -892,11 +888,6 @@ class BinaryBuilder { // Read component index from the end of this ComponentFiles serialized data. _ComponentIndex index = _readComponentIndex(componentFileSize); - if (compilationMode == null) { - compilationMode = component.modeRaw; - } - compilationMode = - mergeCompilationModeOrThrow(compilationMode, index.compiledMode); _byteOffset = index.binaryOffsetForStringTable; readStringTable(); @@ -938,7 +929,7 @@ class BinaryBuilder { Reference? mainMethod = getNullableMemberReferenceFromInt(index.mainMethodReference); - component.setMainMethodAndMode(mainMethod, false, compilationMode!); + component.setMainMethodAndMode(mainMethod, false); _byteOffset = _componentStartOffset + componentFileSize; @@ -1244,13 +1235,6 @@ class BinaryBuilder { library.fileUri = fileUri; library.problemsAsJson = problemsAsJson; - assert( - mergeCompilationModeOrThrow( - compilationMode, library.nonNullableByDefaultCompiledMode) == - compilationMode, - "Cannot load ${library.nonNullableByDefaultCompiledMode} " - "into component with mode $compilationMode"); - assert(() { debugPath.add(library!.name ?? library.importUri.toString()); return true; @@ -4482,21 +4466,3 @@ class _MetadataSubsection { _MetadataSubsection(this.repository, this.mapping); } - -/// Merges two compilation modes or throws if they are not compatible. -NonNullableByDefaultCompiledMode mergeCompilationModeOrThrow( - NonNullableByDefaultCompiledMode? a, NonNullableByDefaultCompiledMode b) { - if (a == null || a == b) { - return b; - } - - // If something is invalid, it should always merge as invalid. - if (a == NonNullableByDefaultCompiledMode.Invalid) { - return a; - } - if (b == NonNullableByDefaultCompiledMode.Invalid) { - return b; - } - - throw new CompilationModeError("Mixed compilation mode found: $a and $b"); -} diff --git a/pkg/kernel/lib/binary/ast_to_binary.dart b/pkg/kernel/lib/binary/ast_to_binary.dart index 0b4e4dc2322..84cdb5176b5 100644 --- a/pkg/kernel/lib/binary/ast_to_binary.dart +++ b/pkg/kernel/lib/binary/ast_to_binary.dart @@ -9,7 +9,6 @@ import 'dart:developer'; import 'dart:typed_data'; import '../ast.dart'; -import 'ast_from_binary.dart' show mergeCompilationModeOrThrow; import 'tag.dart'; /// Writes to a binary file. @@ -30,7 +29,6 @@ class BinaryPrinter implements Visitor, BinarySink { final List _sourcesUsedInLibrary = []; Map _libraryDependencyIndex = {}; - NonNullableByDefaultCompiledMode? compilationMode; List<_MetadataSubsection>? _metadataSubsections; @@ -586,7 +584,6 @@ class BinaryPrinter implements Visitor, BinarySink { void writeComponentFile(Component component) { Timeline.timeSync("BinaryPrinter.writeComponentFile", () { - compilationMode = component.mode; _computeCanonicalNames(component); final int componentOffset = getBufferOffset(); writeUInt32(Tag.ComponentFile); @@ -846,8 +843,8 @@ class BinaryPrinter implements Visitor, BinarySink { _ensureCanonicalName(getNonNullableMemberReferenceGetter(mainMethod)); writeUInt32(main.index + 1); } - assert(component.modeRaw != null, "Component mode not set."); - writeUInt32(component.mode.index); + // TODO(jensj): Previously the component mode. Remove this. + writeUInt32(0); assert(libraryOffsets.length == libraries.length); for (int offset in libraryOffsets) { @@ -1088,13 +1085,6 @@ class BinaryPrinter implements Visitor, BinarySink { libraryOffsets.add(getBufferOffset()); writeByte(node.flags); - assert( - mergeCompilationModeOrThrow( - compilationMode, node.nonNullableByDefaultCompiledMode) == - compilationMode, - "Cannot have ${node.nonNullableByDefaultCompiledMode} " - "in component with mode $compilationMode"); - writeUInt30(node.languageVersion.major); writeUInt30(node.languageVersion.minor); diff --git a/pkg/kernel/lib/binary/tag.dart b/pkg/kernel/lib/binary/tag.dart index a330cbc62f6..ca28f74889c 100644 --- a/pkg/kernel/lib/binary/tag.dart +++ b/pkg/kernel/lib/binary/tag.dart @@ -226,7 +226,7 @@ class Tag { /// Internal version of kernel binary format. /// Bump it when making incompatible changes in kernel binaries. /// Keep in sync with runtime/vm/kernel_binary.h, pkg/kernel/binary.md. - static const int BinaryFormatVersion = 122; + static const int BinaryFormatVersion = 123; } abstract class ConstantTag { diff --git a/pkg/kernel/lib/src/ast/components.dart b/pkg/kernel/lib/src/ast/components.dart index bc0932f64b3..17df623ab37 100644 --- a/pkg/kernel/lib/src/ast/components.dart +++ b/pkg/kernel/lib/src/ast/components.dart @@ -33,22 +33,14 @@ class Component extends TreeNode { /// Reference to the main method in one of the libraries. Reference? _mainMethodName; Reference? get mainMethodName => _mainMethodName; - NonNullableByDefaultCompiledMode? _mode; - NonNullableByDefaultCompiledMode get mode { - return _mode ?? NonNullableByDefaultCompiledMode.Strong; - } - - NonNullableByDefaultCompiledMode? get modeRaw => _mode; Component( {CanonicalName? nameRoot, List? libraries, - Map? uriToSource, - NonNullableByDefaultCompiledMode? mode}) + Map? uriToSource}) : root = nameRoot ?? new CanonicalName.root(), libraries = libraries ?? [], - uriToSource = uriToSource ?? {}, - _mode = mode { + uriToSource = uriToSource ?? {} { adoptChildren(); } @@ -121,12 +113,10 @@ class Component extends TreeNode { Procedure? get mainMethod => mainMethodName?.asProcedure; - void setMainMethodAndMode(Reference? main, bool overwriteMainIfSet, - NonNullableByDefaultCompiledMode mode) { + void setMainMethodAndMode(Reference? main, bool overwriteMainIfSet) { if (_mainMethodName == null || overwriteMainIfSet) { _mainMethodName = main; } - _mode = mode; } @override diff --git a/pkg/kernel/lib/src/ast/libraries.dart b/pkg/kernel/lib/src/ast/libraries.dart index 05e9d8e8924..6a19042069d 100644 --- a/pkg/kernel/lib/src/ast/libraries.dart +++ b/pkg/kernel/lib/src/ast/libraries.dart @@ -8,8 +8,6 @@ part of '../../ast.dart'; // LIBRARIES and CLASSES // ------------------------------------------------------------------------ -enum NonNullableByDefaultCompiledMode { Strong, Weak, Invalid } - class Library extends NamedNode implements Annotatable, Comparable, FileUriNode { /// An import path to this library. @@ -31,10 +29,7 @@ class Library extends NamedNode } static const int SyntheticFlag = 1 << 0; - - static const int NonNullableByDefaultModeBit1 = 1 << 1; - static const int NonNullableByDefaultModeBit2 = 1 << 2; - static const int IsUnsupportedFlag = 1 << 3; + static const int IsUnsupportedFlag = 1 << 1; int flags = 0; @@ -45,33 +40,6 @@ class Library extends NamedNode flags = value ? (flags | SyntheticFlag) : (flags & ~SyntheticFlag); } - NonNullableByDefaultCompiledMode get nonNullableByDefaultCompiledMode { - bool bit1 = (flags & NonNullableByDefaultModeBit1) != 0; - bool bit2 = (flags & NonNullableByDefaultModeBit2) != 0; - if (!bit1 && !bit2) return NonNullableByDefaultCompiledMode.Strong; - if (bit1 && !bit2) return NonNullableByDefaultCompiledMode.Weak; - if (!bit1 && bit2) return NonNullableByDefaultCompiledMode.Invalid; - throw new StateError("Unused bit-pattern for compilation mode"); - } - - void set nonNullableByDefaultCompiledMode( - NonNullableByDefaultCompiledMode mode) { - switch (mode) { - case NonNullableByDefaultCompiledMode.Strong: - flags = (flags & ~NonNullableByDefaultModeBit1) & - ~NonNullableByDefaultModeBit2; - break; - case NonNullableByDefaultCompiledMode.Weak: - flags = (flags | NonNullableByDefaultModeBit1) & - ~NonNullableByDefaultModeBit2; - break; - case NonNullableByDefaultCompiledMode.Invalid: - flags = (flags & ~NonNullableByDefaultModeBit1) | - NonNullableByDefaultModeBit2; - break; - } - } - /// If true, the library is not supported through the 'dart.library.*' value /// used in conditional imports and `bool.fromEnvironment` constants. bool get isUnsupported => flags & IsUnsupportedFlag != 0; diff --git a/pkg/kernel/lib/src/equivalence.dart b/pkg/kernel/lib/src/equivalence.dart index 0c3bb473b52..6dcc99a8ee7 100644 --- a/pkg/kernel/lib/src/equivalence.dart +++ b/pkg/kernel/lib/src/equivalence.dart @@ -1810,9 +1810,6 @@ class EquivalenceStrategy { if (!checkComponent_mainMethodName(visitor, node, other)) { result = visitor.resultOnInequivalence; } - if (!checkComponent_mode(visitor, node, other)) { - result = visitor.resultOnInequivalence; - } if (!checkComponent_fileOffset(visitor, node, other)) { result = visitor.resultOnInequivalence; } @@ -5920,11 +5917,6 @@ class EquivalenceStrategy { node.mainMethodName, other.mainMethodName, 'mainMethodName'); } - bool checkComponent_mode( - EquivalenceVisitor visitor, Component node, Component other) { - return visitor.checkValues(node.mode, other.mode, 'mode'); - } - bool checkTreeNode_fileOffset( EquivalenceVisitor visitor, TreeNode node, TreeNode other) { return visitor.checkValues(node.fileOffset, other.fileOffset, 'fileOffset'); diff --git a/pkg/kernel/lib/target/targets.dart b/pkg/kernel/lib/target/targets.dart index 6fbe6661b62..40502ce8cff 100644 --- a/pkg/kernel/lib/target/targets.dart +++ b/pkg/kernel/lib/target/targets.dart @@ -13,12 +13,10 @@ import 'changed_structure_notifier.dart'; class TargetFlags { final bool trackWidgetCreation; - final bool soundNullSafety; final bool supportMirrors; const TargetFlags( {this.trackWidgetCreation = false, - this.soundNullSafety = true, this.supportMirrors = true}); @override @@ -26,7 +24,6 @@ class TargetFlags { if (identical(this, other)) return true; return other is TargetFlags && trackWidgetCreation == other.trackWidgetCreation && - soundNullSafety == other.soundNullSafety && supportMirrors == other.supportMirrors; } @@ -34,7 +31,6 @@ class TargetFlags { int get hashCode { int hash = 485786; hash = 0x3fffffff & (hash * 31 + (hash ^ trackWidgetCreation.hashCode)); - hash = 0x3fffffff & (hash * 31 + (hash ^ soundNullSafety.hashCode)); hash = 0x3fffffff & (hash * 31 + (hash ^ supportMirrors.hashCode)); return hash; } diff --git a/pkg/kernel/lib/type_environment.dart b/pkg/kernel/lib/type_environment.dart index 15945ac5926..f80cac798ba 100644 --- a/pkg/kernel/lib/type_environment.dart +++ b/pkg/kernel/lib/type_environment.dart @@ -875,9 +875,6 @@ abstract class StaticTypeContext { /// For opt out libraries this is [Nullability.legacy]. Nullability get nullable; - /// Returns the mode under which the current library was compiled. - NonNullableByDefaultCompiledMode get nonNullableByDefaultCompiledMode; - /// Returns the static type of [node]. DartType getExpressionType(Expression node); @@ -941,11 +938,6 @@ class StaticTypeContextImpl implements StaticTypeContext { @override Nullability get nullable => _library.nullable; - /// Returns the mode under which the current library was compiled. - @override - NonNullableByDefaultCompiledMode get nonNullableByDefaultCompiledMode => - _library.nonNullableByDefaultCompiledMode; - @override DartType getExpressionType(Expression node) { if (_cache != null) { @@ -1053,10 +1045,6 @@ class _FlatStatefulStaticTypeContext extends StatefulStaticTypeContext { @override Nullability get nullable => _library.nullable; - @override - NonNullableByDefaultCompiledMode get nonNullableByDefaultCompiledMode => - _library.nonNullableByDefaultCompiledMode; - /// Updates the [nonNullable] and [thisType] to match static type context for /// the member [node]. /// @@ -1155,10 +1143,6 @@ class _StackedStatefulStaticTypeContext extends StatefulStaticTypeContext { @override Nullability get nullable => _library.nullable; - @override - NonNullableByDefaultCompiledMode get nonNullableByDefaultCompiledMode => - _library.nonNullableByDefaultCompiledMode; - /// Updates the [library] and [thisType] to match static type context for /// the member [node]. /// diff --git a/pkg/kernel/test/binary/component_mode_test.dart b/pkg/kernel/test/binary/component_mode_test.dart deleted file mode 100644 index 81b837e7667..00000000000 --- a/pkg/kernel/test/binary/component_mode_test.dart +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file -// for details. All rights reserved. Use of this source code is governed by a -// BSD-style license that can be found in the LICENSE file. - -import 'dart:typed_data'; - -import 'package:kernel/binary/ast_from_binary.dart'; - -import 'utils.dart'; - -void main() { - void setCompileMode(Component c, NonNullableByDefaultCompiledMode mode) { - c.setMainMethodAndMode(null, true, mode); - } - - void verifyMode(Component c, NonNullableByDefaultCompiledMode mode) { - if (c.mode != mode) { - throw "Serialized and re-read component had change in mode: " - "Expected $mode got ${c.mode}."; - } - } - - const List modes = const [ - NonNullableByDefaultCompiledMode.Weak, - NonNullableByDefaultCompiledMode.Strong, - ]; - - int combination = 0; - for (NonNullableByDefaultCompiledMode c1Mode in modes) { - for (NonNullableByDefaultCompiledMode c2Mode in modes) { - combination++; - print("Checking combination #$combination (" - "c1Mode: $c1Mode; " - "c2Mode: $c2Mode; " - ")"); - - // Try individually. - Uint8List c1Serialized; - { - Uri uri = Uri.parse("foo://bar.dart"); - Library lib1 = new Library(uri, fileUri: uri) - ..nonNullableByDefaultCompiledMode = c1Mode; - Component c1 = new Component(libraries: [lib1]); - setCompileMode(c1, c1Mode); - c1Serialized = serializeComponent(c1); - Component c1RoundTrip = loadComponentFromBytes(c1Serialized); - verifyMode(c1RoundTrip, c1Mode); - } - - Uint8List c2Serialized; - { - Uri uri = Uri.parse("foo://baz.dart"); - Library lib2 = new Library(uri, fileUri: uri) - ..nonNullableByDefaultCompiledMode = c2Mode; - Component c2 = new Component(libraries: [lib2]); - setCompileMode(c2, c2Mode); - c2Serialized = serializeComponent(c2); - Component c2RoundTrip = loadComponentFromBytes(c2Serialized); - verifyMode(c2RoundTrip, c2Mode); - } - - // Try with combined binary. - try { - Uint8List combined = - Uint8List.fromList([...c1Serialized, ...c2Serialized]); - Component combinedRoundTrip = loadComponentFromBytes(combined); - verifyMode(combinedRoundTrip, verifyOK(c1Mode, c2Mode)); - print(" -> OK with $c1Mode and $c2Mode"); - } on CompilationModeError catch (e) { - print(" -> Got $e with $c1Mode and $c2Mode"); - verifyError(c1Mode, c2Mode); - } - // Try other order. - try { - Uint8List combined = - Uint8List.fromList([...c2Serialized, ...c1Serialized]); - Component combinedRoundTrip = loadComponentFromBytes(combined); - verifyMode(combinedRoundTrip, verifyOK(c1Mode, c2Mode)); - print(" -> OK with $c1Mode and $c2Mode"); - } on CompilationModeError catch (e) { - print(" -> Got $e with $c1Mode and $c2Mode"); - verifyError(c1Mode, c2Mode); - } - - // Try with individual binary, but loaded into same component. - try { - Component combinedRoundTrip = loadComponentFromBytes(c1Serialized); - combinedRoundTrip = - loadComponentFromBytes(c2Serialized, combinedRoundTrip); - verifyMode(combinedRoundTrip, verifyOK(c1Mode, c2Mode)); - print(" -> OK with $c1Mode and $c2Mode"); - } on CompilationModeError catch (e) { - print(" -> Got $e with $c1Mode and $c2Mode"); - verifyError(c1Mode, c2Mode); - } - // Try other order. - try { - Component combinedRoundTrip = loadComponentFromBytes(c2Serialized); - combinedRoundTrip = - loadComponentFromBytes(c1Serialized, combinedRoundTrip); - verifyMode(combinedRoundTrip, verifyOK(c1Mode, c2Mode)); - print(" -> OK with $c1Mode and $c2Mode"); - } on CompilationModeError catch (e) { - print(" -> Got $e with $c1Mode and $c2Mode"); - verifyError(c1Mode, c2Mode); - } - - // Try with individual binary, but loaded into same component where - // component initially does not have a mode. - try { - Component combinedRoundTrip = new Component(); - combinedRoundTrip = - loadComponentFromBytes(c1Serialized, combinedRoundTrip); - combinedRoundTrip = - loadComponentFromBytes(c2Serialized, combinedRoundTrip); - verifyMode(combinedRoundTrip, verifyOK(c1Mode, c2Mode)); - print(" -> OK with $c1Mode and $c2Mode"); - } on CompilationModeError catch (e) { - print(" -> Got $e with $c1Mode and $c2Mode"); - verifyError(c1Mode, c2Mode); - } - } - } - - print("Done: Everything looks good."); -} - -bool isOK(NonNullableByDefaultCompiledMode c1Mode, - NonNullableByDefaultCompiledMode c2Mode) { - return c1Mode == c2Mode; -} - -NonNullableByDefaultCompiledMode verifyOK( - NonNullableByDefaultCompiledMode c1Mode, - NonNullableByDefaultCompiledMode c2Mode) { - if (isOK(c1Mode, c2Mode)) { - return c1Mode; - } - throw "Not OK combination: $c1Mode and $c2Mode"; -} - -void verifyError(NonNullableByDefaultCompiledMode c1Mode, - NonNullableByDefaultCompiledMode c2Mode) { - if (isOK(c1Mode, c2Mode)) { - throw "Unexpected error for $c1Mode and $c2Mode"; - } -} diff --git a/pkg/kernel/test/binary/lazy_reading_test.dart b/pkg/kernel/test/binary/lazy_reading_test.dart index 784630d25e5..7e0e751d9c0 100644 --- a/pkg/kernel/test/binary/lazy_reading_test.dart +++ b/pkg/kernel/test/binary/lazy_reading_test.dart @@ -34,7 +34,7 @@ void main() { classA.addConstructor(classAConstructor); } Component c = new Component(libraries: [lib]); - c.setMainMethodAndMode(null, false, NonNullableByDefaultCompiledMode.Strong); + c.setMainMethodAndMode(null, false); Uint8List loadMe = serializeComponent(c); // Load and make sure we can get at class B from class A (i.e. that it's diff --git a/pkg/kernel/test/binary/library_flags_test.dart b/pkg/kernel/test/binary/library_flags_test.dart index 69635238356..63ecb92ec80 100644 --- a/pkg/kernel/test/binary/library_flags_test.dart +++ b/pkg/kernel/test/binary/library_flags_test.dart @@ -16,41 +16,16 @@ void main() { } } - void setNonNullableByDefaultCompiledMode(Library lib, - NonNullableByDefaultCompiledMode nonNullableByDefaultCompiledMode) { - lib.nonNullableByDefaultCompiledMode = nonNullableByDefaultCompiledMode; - } - - void verifyNonNullableByDefaultCompiledMode(Library lib, - NonNullableByDefaultCompiledMode nonNullableByDefaultCompiledMode) { - if (lib.nonNullableByDefaultCompiledMode != - nonNullableByDefaultCompiledMode) { - throw "Serialized and re-read library had change in " - "nonNullableByDefaultCompiledMode flag."; - } - } - int combination = 0; for (bool isSynthetic in [true, false]) { - for (NonNullableByDefaultCompiledMode nonNullableByDefaultCompiledMode in [ - NonNullableByDefaultCompiledMode.Weak, - NonNullableByDefaultCompiledMode.Strong, - ]) { - combination++; - print("Checking combination #$combination (" - "isSynthetic: $isSynthetic; " - "nonNullableByDefaultCompiledMode:" - " $nonNullableByDefaultCompiledMode"); - Uri uri = Uri.parse("foo://bar.dart"); - Library lib = new Library(uri, fileUri: uri); - setSynthetic(lib, isSynthetic); - setNonNullableByDefaultCompiledMode( - lib, nonNullableByDefaultCompiledMode); - Library lib2 = libRoundTrip(lib); - verifySynthetic(lib2, isSynthetic); - verifyNonNullableByDefaultCompiledMode( - lib2, nonNullableByDefaultCompiledMode); - } + combination++; + print("Checking combination #$combination (" + "isSynthetic: $isSynthetic"); + Uri uri = Uri.parse("foo://bar.dart"); + Library lib = new Library(uri, fileUri: uri); + setSynthetic(lib, isSynthetic); + Library lib2 = libRoundTrip(lib); + verifySynthetic(lib2, isSynthetic); } print("Done: Everything looks good."); diff --git a/pkg/kernel/test/binary/utils.dart b/pkg/kernel/test/binary/utils.dart index acbad5cdfd1..7fc7c4c4e00 100644 --- a/pkg/kernel/test/binary/utils.dart +++ b/pkg/kernel/test/binary/utils.dart @@ -14,8 +14,7 @@ Library libRoundTrip(Library lib) { List serializationRoundTrip(List libraries) { Component c = new Component(libraries: libraries) - ..setMainMethodAndMode( - null, false, libraries.first.nonNullableByDefaultCompiledMode); + ..setMainMethodAndMode(null, false); Uint8List bytes = serializeComponent(c); Component c2 = loadComponentFromBytes(bytes); return c2.libraries; diff --git a/pkg/kernel/test/convert_field_to_setter_getter_test.dart b/pkg/kernel/test/convert_field_to_setter_getter_test.dart index 712d2d74beb..869de2966eb 100644 --- a/pkg/kernel/test/convert_field_to_setter_getter_test.dart +++ b/pkg/kernel/test/convert_field_to_setter_getter_test.dart @@ -188,8 +188,7 @@ void verifyTargets(Procedure libProcedure, Procedure lib2Procedure, Uint8List serialize(Library lib1, Library lib2) { Component component = new Component(libraries: [lib1, lib2]) - ..setMainMethodAndMode( - null, false, NonNullableByDefaultCompiledMode.Strong); + ..setMainMethodAndMode(null, false); ByteSink sink = new ByteSink(); new BinaryPrinter(sink).writeComponentFile(component); return sink.builder.takeBytes(); diff --git a/pkg/kernel/test/load_concat_dill_keeps_source_test.dart b/pkg/kernel/test/load_concat_dill_keeps_source_test.dart index efe935f86fa..883eefddf86 100644 --- a/pkg/kernel/test/load_concat_dill_keeps_source_test.dart +++ b/pkg/kernel/test/load_concat_dill_keeps_source_test.dart @@ -27,8 +27,7 @@ void main() { library2.addProcedure(p2); Component component = new Component(libraries: [library1, library2]) - ..setMainMethodAndMode( - null, false, NonNullableByDefaultCompiledMode.Strong); + ..setMainMethodAndMode(null, false); component.uriToSource[uri1] = new Source([42, 2 * 42], utf8.encode("source #1"), uri1, uri1); component.uriToSource[uri2] = @@ -36,7 +35,7 @@ void main() { expectSource(serialize(component), true, true); Component cPartial1 = new Component(nameRoot: component.root) - ..setMainMethodAndMode(null, false, NonNullableByDefaultCompiledMode.Strong) + ..setMainMethodAndMode(null, false) ..libraries.add(library1); cPartial1.uriToSource[uri1] = new Source([42, 2 * 42], utf8.encode("source #1"), uri1, uri1); @@ -46,7 +45,7 @@ void main() { expectSource(partial1Serialized, true, false); Component cPartial2 = new Component(nameRoot: component.root) - ..setMainMethodAndMode(null, false, NonNullableByDefaultCompiledMode.Strong) + ..setMainMethodAndMode(null, false) ..libraries.add(library2); cPartial2.uriToSource[uri1] = new Source.emptySource([42, 2 * 42], uri1, uri1); diff --git a/pkg/kernel/test/load_field_and_procedure_overwrites_test.dart b/pkg/kernel/test/load_field_and_procedure_overwrites_test.dart index 4973f32ad17..7d69c634b2f 100644 --- a/pkg/kernel/test/load_field_and_procedure_overwrites_test.dart +++ b/pkg/kernel/test/load_field_and_procedure_overwrites_test.dart @@ -61,8 +61,7 @@ void expect(dynamic actual, dynamic expected) { Uint8List serialize(Library lib1) { Component component = new Component(libraries: [lib1]) - ..setMainMethodAndMode( - null, false, NonNullableByDefaultCompiledMode.Strong); + ..setMainMethodAndMode(null, false); ByteSink sink = new ByteSink(); new BinaryPrinter(sink).writeComponentFile(component); return sink.builder.takeBytes(); diff --git a/pkg/kernel/test/relink_test.dart b/pkg/kernel/test/relink_test.dart index 80e1f9c8533..707212ed3dc 100644 --- a/pkg/kernel/test/relink_test.dart +++ b/pkg/kernel/test/relink_test.dart @@ -198,6 +198,5 @@ Component createComponent(int literal) { fileUri: mainUri); main.addProcedure(mainProcedure); return new Component(libraries: [main, lib]) - ..setMainMethodAndMode( - null, false, NonNullableByDefaultCompiledMode.Strong); + ..setMainMethodAndMode(null, false); } diff --git a/pkg/vm/bin/kernel_service.dart b/pkg/vm/bin/kernel_service.dart index f6dd88c7c7f..aab290ecaea 100644 --- a/pkg/vm/bin/kernel_service.dart +++ b/pkg/vm/bin/kernel_service.dart @@ -33,8 +33,7 @@ import 'package:front_end/src/api_prototype/front_end.dart' show CompilerResult; import 'package:front_end/src/api_prototype/memory_file_system.dart'; import 'package:front_end/src/api_unstable/vm.dart'; -import 'package:kernel/ast.dart' - show Component, Library, NonNullableByDefaultCompiledMode, Procedure; +import 'package:kernel/ast.dart' show Component, Library, Procedure; import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilderWithMetadata; import 'package:kernel/binary/ast_to_binary.dart'; @@ -1010,10 +1009,7 @@ Future _processLoadRequest(request) async { pragmaClass: compilerResult.coreTypes?.pragmaClass, ); if (nativeAssetsLibrary != null) { - nativeAssetsComponent = Component( - libraries: [nativeAssetsLibrary], - mode: NonNullableByDefaultCompiledMode.Strong, - ); + nativeAssetsComponent = Component(libraries: [nativeAssetsLibrary]); } } diff --git a/pkg/vm/bin/protobuf_aware_treeshaker.dart b/pkg/vm/bin/protobuf_aware_treeshaker.dart index c3069c1c507..3663d96acf4 100644 --- a/pkg/vm/bin/protobuf_aware_treeshaker.dart +++ b/pkg/vm/bin/protobuf_aware_treeshaker.dart @@ -128,10 +128,6 @@ Future main(List args) async { bytes = concatenate(File(platformFile).readAsBytesSync(), bytes); } final component = loadComponentFromBytes(bytes); - if (component.mode != NonNullableByDefaultCompiledMode.Strong) { - print('Input kernel file should be compiled with sound null safety.'); - exit(-1); - } installAdditionalTargets(); diff --git a/pkg/vm/lib/incremental_compiler.dart b/pkg/vm/lib/incremental_compiler.dart index 7b7f98f76bb..90625c224dd 100644 --- a/pkg/vm/lib/incremental_compiler.dart +++ b/pkg/vm/lib/incremental_compiler.dart @@ -99,8 +99,6 @@ class IncrementalCompiler { IncrementalCompilerResult _combinePendingDeltas(bool includePlatform) { assert(_pendingDeltas.isNotEmpty); Procedure? mainMethod; - NonNullableByDefaultCompiledMode compilationMode = - NonNullableByDefaultCompiledMode.Invalid; Map combined = {}; Map uriToSource = new Map(); ClassHierarchy classHierarchy = _pendingDeltas.last.classHierarchy; @@ -110,7 +108,6 @@ class IncrementalCompiler { if (delta.mainMethod != null) { mainMethod = delta.mainMethod; } - compilationMode = delta.mode; uriToSource.addAll(delta.uriToSource); for (Library library in delta.libraries) { bool isPlatform = @@ -125,7 +122,7 @@ class IncrementalCompiler { new Component( libraries: combined.values.toList(), uriToSource: uriToSource, - )..setMainMethodAndMode(mainMethod?.reference, true, compilationMode), + )..setMainMethodAndMode(mainMethod?.reference, true), classHierarchy: classHierarchy, coreTypes: coreTypes, ); @@ -174,11 +171,7 @@ class IncrementalCompiler { new Component( libraries: combined.values.toList(), uriToSource: uriToSource, - )..setMainMethodAndMode( - candidate.mainMethod?.reference, - true, - candidate.mode, - ), + )..setMainMethodAndMode(candidate.mainMethod?.reference, true), classHierarchy: result.classHierarchy, coreTypes: result.coreTypes, ); diff --git a/pkg/vm/lib/kernel_front_end.dart b/pkg/vm/lib/kernel_front_end.dart index c4d1b7333ef..aa85f1e40e7 100644 --- a/pkg/vm/lib/kernel_front_end.dart +++ b/pkg/vm/lib/kernel_front_end.dart @@ -34,8 +34,7 @@ import 'package:front_end/src/api_unstable/vm.dart' parseExperimentalFlags, printDiagnosticMessage, resolveInputUri; -import 'package:kernel/ast.dart' - show Component, Library, NonNullableByDefaultCompiledMode; +import 'package:kernel/ast.dart' show Component, Library; import 'package:kernel/binary/ast_to_binary.dart' show BinaryPrinter; import 'package:kernel/class_hierarchy.dart' show ClassHierarchy; import 'package:kernel/core_types.dart' show CoreTypes; @@ -482,12 +481,7 @@ Future runCompiler(ArgResults options, String usage) async { // If Dart component in JIT, write as concatenated dill, to not mess with // the incremental compiler. final BinaryPrinter printer = new BinaryPrinter(sink); - printer.writeComponentFile( - Component( - libraries: [nativeAssetsLibrary], - mode: NonNullableByDefaultCompiledMode.Strong, - ), - ); + printer.writeComponentFile(Component(libraries: [nativeAssetsLibrary])); } await sink.close(); @@ -1116,13 +1110,12 @@ Future forEachPackage( final mainMethod = component.mainMethod; final problemsAsJson = component.problemsAsJson; - final compilationMode = component.mode; - component.setMainMethodAndMode(null, true, compilationMode); + component.setMainMethodAndMode(null, true); component.problemsAsJson = null; for (String package in packages.keys) { await action(package, packages[package]!); } - component.setMainMethodAndMode(mainMethod?.reference, true, compilationMode); + component.setMainMethodAndMode(mainMethod?.reference, true); component.problemsAsJson = problemsAsJson; if (!mainFirst) { diff --git a/pkg/vm/test/native_assets/synthesizer_test.dart b/pkg/vm/test/native_assets/synthesizer_test.dart index d42e05e07f1..5569645a20e 100644 --- a/pkg/vm/test/native_assets/synthesizer_test.dart +++ b/pkg/vm/test/native_assets/synthesizer_test.dart @@ -26,7 +26,6 @@ native-assets: NativeAssetsValidator(errorDetector).parseAndValidate(yamlString)!; final component = Component( libraries: [NativeAssetsSynthesizer.synthesizeLibrary(validatedYaml)], - mode: NonNullableByDefaultCompiledMode.Strong, ); final libraryToString = kernelLibraryToString(component.libraries.single); final expectedKernel = '''@#C3 diff --git a/runtime/vm/compiler/frontend/kernel_translation_helper.h b/runtime/vm/compiler/frontend/kernel_translation_helper.h index 9a7b0a61f2f..f47719a13bf 100644 --- a/runtime/vm/compiler/frontend/kernel_translation_helper.h +++ b/runtime/vm/compiler/frontend/kernel_translation_helper.h @@ -874,15 +874,6 @@ class LibraryHelper { void SetJustRead(Field field) { next_read_ = field + 1; } bool IsSynthetic() const { return (flags_ & kSynthetic) != 0; } - NNBDCompiledMode GetNonNullableByDefaultCompiledMode() const { - bool bit1 = (flags_ & kNonNullableByDefaultCompiledModeBit1) != 0; - bool bit2 = (flags_ & kNonNullableByDefaultCompiledModeBit2) != 0; - if (!bit1 && !bit2) return NNBDCompiledMode::kStrong; - if (bit1 && !bit2) return NNBDCompiledMode::kWeak; - if (bit1 && bit2) return NNBDCompiledMode::kAgnostic; - if (!bit1 && bit2) return NNBDCompiledMode::kInvalid; - UNREACHABLE(); - } uint8_t flags_ = 0; NameIndex canonical_name_; diff --git a/runtime/vm/kernel_binary.cc b/runtime/vm/kernel_binary.cc index c3c43f760c5..d222d6110d9 100644 --- a/runtime/vm/kernel_binary.cc +++ b/runtime/vm/kernel_binary.cc @@ -174,6 +174,7 @@ std::unique_ptr Program::ReadFrom(Reader* reader, const char** error) { program->component_index_offset_ = reader->ReadUInt32(); program->main_method_reference_ = NameIndex(reader->ReadUInt32() - 1); + // TODO(jensj): Remove this. reader->ReadUInt32(); // Read and ignore NNBD compilation mode. return program; diff --git a/runtime/vm/kernel_binary.h b/runtime/vm/kernel_binary.h index 9748a759410..37b95173a10 100644 --- a/runtime/vm/kernel_binary.h +++ b/runtime/vm/kernel_binary.h @@ -18,7 +18,7 @@ namespace kernel { // package:kernel/binary.md. static const uint32_t kMagicProgramFile = 0x90ABCDEFu; -static const uint32_t kSupportedKernelFormatVersion = 122; +static const uint32_t kSupportedKernelFormatVersion = 123; // Keep in sync with package:kernel/lib/binary/tag.dart #define KERNEL_TAG_LIST(V) \ diff --git a/runtime/vm/kernel_loader.cc b/runtime/vm/kernel_loader.cc index 635dad7363a..dd4091a0f1c 100644 --- a/runtime/vm/kernel_loader.cc +++ b/runtime/vm/kernel_loader.cc @@ -828,21 +828,6 @@ LibraryPtr KernelLoader::LoadLibrary(intptr_t index) { if (library.Loaded()) return library.ptr(); - const NNBDCompiledMode mode = - library_helper.GetNonNullableByDefaultCompiledMode(); - if (mode == NNBDCompiledMode::kInvalid) { - H.ReportError( - "Library '%s' was compiled in an unsupported mixed mode between sound " - "null safety and not sound null safety.", - String::Handle(library.url()).ToCString()); - } - if (mode == NNBDCompiledMode::kWeak) { - H.ReportError( - "Library '%s' was compiled without sound null safety (in weak mode) " - "and it cannot be used at runtime", - String::Handle(library.url()).ToCString()); - } - library_kernel_data_ = helper_.reader_.ViewFromTo( library_kernel_offset_, library_kernel_offset_ + library_size); library.set_kernel_library_index(index); diff --git a/runtime/vm/object.h b/runtime/vm/object.h index ff698e84020..b570fdf5c95 100644 --- a/runtime/vm/object.h +++ b/runtime/vm/object.h @@ -1145,15 +1145,6 @@ enum class TypeEquality { kInSubtypeTest = 2, }; -// The NNBDCompiledMode reflects the mode in which constants of the library were -// compiled by CFE. -enum class NNBDCompiledMode { - kStrong = 0, - kWeak = 1, - kAgnostic = 2, - kInvalid = 3, -}; - class Class : public Object { public: enum InvocationDispatcherEntry {