From 45ae00676adcd36eda411dd6fcec550784128b9a Mon Sep 17 00:00:00 2001 From: Alexander Markov Date: Tue, 27 Jul 2021 17:52:18 +0000 Subject: [PATCH] Migrate pkg/vm to null safety, part 4 TEST=ci Issue: https://github.com/dart-lang/sdk/issues/46620 Change-Id: I74c45ed1525248447e769cc832366728e7a017fc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208020 Commit-Queue: Alexander Markov Reviewed-by: Johnni Winther Reviewed-by: Alexander Aprelev --- .../incremental_kernel_generator.dart | 6 +- .../lib/src/api_unstable/bazel_worker.dart | 4 +- pkg/vm/lib/incremental_compiler.dart | 43 +++-- pkg/vm/lib/kernel_front_end.dart | 156 +++++++++--------- pkg/vm/lib/target/dart_runner.dart | 2 - pkg/vm/lib/target/flutter.dart | 11 +- pkg/vm/lib/target/flutter_runner.dart | 2 - pkg/vm/lib/target/install.dart | 2 - pkg/vm/lib/target/vm.dart | 43 +++-- pkg/vm/test/common_test_utils.dart | 22 ++- 10 files changed, 141 insertions(+), 150 deletions(-) diff --git a/pkg/front_end/lib/src/api_prototype/incremental_kernel_generator.dart b/pkg/front_end/lib/src/api_prototype/incremental_kernel_generator.dart index 12614bbf741..a6d071f35cf 100644 --- a/pkg/front_end/lib/src/api_prototype/incremental_kernel_generator.dart +++ b/pkg/front_end/lib/src/api_prototype/incremental_kernel_generator.dart @@ -42,7 +42,7 @@ abstract class IncrementalKernelGenerator { /// Notice that the component has to include the platform, and that no other /// platform will be loaded. factory IncrementalKernelGenerator.fromComponent( - CompilerOptions options, Uri entryPoint, Component component, + CompilerOptions options, Uri entryPoint, Component? component, [bool? outlineOnly, IncrementalSerializer? incrementalSerializer]) { return new IncrementalCompiler.fromComponent( new CompilerContext( @@ -72,7 +72,7 @@ abstract class IncrementalKernelGenerator { /// Returns a component whose libraries are the recompiled libraries, /// or - in the case of [fullComponent] - a full Component. - Future computeDelta({List entryPoints, bool fullComponent}); + Future computeDelta({List? entryPoints, bool fullComponent}); /// Returns [CoreTypes] used during compilation. /// Valid after [computeDelta] is called. @@ -136,7 +136,7 @@ abstract class IncrementalKernelGenerator { List typeDefinitions, String syntheticProcedureName, Uri libraryUri, - [String className, + [String? className, bool isStatic = false]); /// Sets experimental features. diff --git a/pkg/front_end/lib/src/api_unstable/bazel_worker.dart b/pkg/front_end/lib/src/api_unstable/bazel_worker.dart index 46566f107bc..8cf810bd2e6 100644 --- a/pkg/front_end/lib/src/api_unstable/bazel_worker.dart +++ b/pkg/front_end/lib/src/api_unstable/bazel_worker.dart @@ -58,7 +58,7 @@ export 'compiler_state.dart' show InitializedCompilerState; /// Re-uses cached components from [oldState.workerInputCache], and reloads them /// as necessary based on [workerInputDigests]. Future initializeIncrementalCompiler( - InitializedCompilerState oldState, + InitializedCompilerState? oldState, Set tags, Uri sdkSummary, Uri packagesFile, @@ -99,7 +99,7 @@ Future initializeIncrementalCompiler( } Future initializeCompiler( - InitializedCompilerState oldState, + InitializedCompilerState? oldState, Uri sdkSummary, Uri librariesSpecificationUri, Uri packagesFile, diff --git a/pkg/vm/lib/incremental_compiler.dart b/pkg/vm/lib/incremental_compiler.dart index 5179a448e4f..a8d32713a9f 100644 --- a/pkg/vm/lib/incremental_compiler.dart +++ b/pkg/vm/lib/incremental_compiler.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - /// Defines wrapper class around incremental compiler to support /// the flow, where incremental deltas can be rejected by VM. import 'dart:async'; @@ -20,23 +18,23 @@ const String kDebugProcedureName = ":Eval"; /// deltas and combines them together into resultant program until it is /// accepted. class IncrementalCompiler { - IncrementalKernelGenerator _generator; - IncrementalSerializer incrementalSerializer; + late IncrementalKernelGenerator _generator; + IncrementalSerializer? incrementalSerializer; // Component that reflect the state that was most recently accepted by the // client. Is [null], if no compilation results were accepted by the client. - Component _lastKnownGood; - List _pendingDeltas; + Component? _lastKnownGood; + late List _pendingDeltas; CompilerOptions _compilerOptions; bool initialized = false; bool fullComponent = false; - Uri initializeFromDillUri; + Uri? initializeFromDillUri; Uri _entryPoint; final bool forExpressionCompilationOnly; Uri get entryPoint => _entryPoint; IncrementalKernelGenerator get generator => _generator; - Component get lastKnownGoodComponent => _lastKnownGood; + Component? get lastKnownGoodComponent => _lastKnownGood; IncrementalCompiler(this._compilerOptions, this._entryPoint, {this.initializeFromDillUri, bool incrementalSerialization: true}) @@ -61,12 +59,12 @@ class IncrementalCompiler { /// /// If [entryPoint] is specified, that points to new entry point for the /// compilation. Otherwise, previously set entryPoint is used. - Future compile({Uri entryPoint}) async { + Future compile({Uri? entryPoint}) async { final task = new TimelineTask(); try { task.start("IncrementalCompiler.compile"); _entryPoint = entryPoint ?? _entryPoint; - List entryPoints; + List? entryPoints; if (entryPoint != null) entryPoints = [entryPoint]; Component component = await _generator.computeDelta( entryPoints: entryPoints, fullComponent: fullComponent); @@ -80,8 +78,9 @@ class IncrementalCompiler { } _combinePendingDeltas(bool includePlatform) { - Procedure mainMethod; - NonNullableByDefaultCompiledMode compilationMode; + Procedure? mainMethod; + NonNullableByDefaultCompiledMode compilationMode = + NonNullableByDefaultCompiledMode.Invalid; Map combined = {}; Map uriToSource = new Map(); for (Component delta in _pendingDeltas) { @@ -104,8 +103,8 @@ class IncrementalCompiler { ..setMainMethodAndMode(mainMethod?.reference, true, compilationMode); } - CoreTypes getCoreTypes() => _generator.getCoreTypes(); - ClassHierarchy getClassHierarchy() => _generator.getClassHierarchy(); + CoreTypes? getCoreTypes() => _generator.getCoreTypes(); + ClassHierarchy? getClassHierarchy() => _generator.getClassHierarchy(); /// This lets incremental compiler know that results of last [compile] call /// were accepted, don't need to be included into subsequent [compile] calls @@ -118,13 +117,14 @@ class IncrementalCompiler { Map combined = {}; Map uriToSource = {}; - if (_lastKnownGood != null) { + Component? lastKnownGood = _lastKnownGood; + if (lastKnownGood != null) { // TODO(aam): Figure out how to skip no-longer-used libraries from // [_lastKnownGood] libraries. - for (Library library in _lastKnownGood.libraries) { + for (Library library in lastKnownGood.libraries) { combined[library.importUri] = library; } - uriToSource.addAll(_lastKnownGood.uriToSource); + uriToSource.addAll(lastKnownGood.uriToSource); } Component candidate = _combinePendingDeltas(true); @@ -133,13 +133,13 @@ class IncrementalCompiler { } uriToSource.addAll(candidate.uriToSource); - _lastKnownGood = new Component( + _lastKnownGood = lastKnownGood = new Component( libraries: combined.values.toList(), uriToSource: uriToSource, )..setMainMethodAndMode( candidate.mainMethod?.reference, true, candidate.mode); for (final repo in candidate.metadata.values) { - _lastKnownGood.addMetadataRepository(repo); + lastKnownGood.addMetadataRepository(repo); } _pendingDeltas.clear(); } @@ -182,12 +182,12 @@ class IncrementalCompiler { fullComponent = true; } - Future compileExpression( + Future compileExpression( String expression, List definitions, List typeDefinitions, String libraryUri, - String klass, + String? klass, bool isStatic) { Map completeDefinitions = {}; for (String name in definitions) { @@ -202,7 +202,6 @@ class IncrementalCompiler { } Uri library = Uri.parse(libraryUri); - if (library == null) return null; return _generator.compileExpression(expression, completeDefinitions, typeParameters, kDebugProcedureName, library, klass, isStatic); diff --git a/pkg/vm/lib/kernel_front_end.dart b/pkg/vm/lib/kernel_front_end.dart index 43d5a59bf8b..51ed004d883 100644 --- a/pkg/vm/lib/kernel_front_end.dart +++ b/pkg/vm/lib/kernel_front_end.dart @@ -2,10 +2,7 @@ // 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. -// @dart=2.9 - /// Defines the VM-specific translation of Dart source code to kernel binaries. -library vm.kernel_front_end; import 'dart:async'; import 'dart:io' show File, IOSink; @@ -162,7 +159,7 @@ const int compileTimeErrorExitCode = 254; /// Run kernel compiler tool with given [options] and [usage] /// and return exit code. Future runCompiler(ArgResults options, String usage) async { - final String platformKernel = options['platform']; + final String? platformKernel = options['platform']; if (options['help']) { print(usage); @@ -176,26 +173,26 @@ Future runCompiler(ArgResults options, String usage) async { final String input = options.rest.single; final String outputFileName = options['output'] ?? "$input.dill"; - final String packages = options['packages']; + final String? packages = options['packages']; final String targetName = options['target']; - final String fileSystemScheme = options['filesystem-scheme']; - final String depfile = options['depfile']; - final String fromDillFile = options['from-dill']; - final List fileSystemRoots = options['filesystem-root']; + final String? fileSystemScheme = options['filesystem-scheme']; + final String? depfile = options['depfile']; + final String? fromDillFile = options['from-dill']; + final List? fileSystemRoots = options['filesystem-root']; final bool aot = options['aot']; final bool tfa = options['tfa']; final bool linkPlatform = options['link-platform']; final bool embedSources = options['embed-sources']; final bool enableAsserts = options['enable-asserts']; - final bool nullSafety = options['sound-null-safety']; + final bool? nullSafety = options['sound-null-safety']; final bool useProtobufTreeShakerV2 = options['protobuf-tree-shaker-v2']; final bool splitOutputByPackages = options['split-output-by-packages']; - final String manifestFilename = options['manifest']; - final String dataDir = options['component-name'] ?? options['data-dir']; + final String? manifestFilename = options['manifest']; + final String? dataDir = options['component-name'] ?? options['data-dir']; final bool minimalKernel = options['minimal-kernel']; final bool treeShakeWriteOnlyFields = options['tree-shake-write-only-fields']; - final List experimentalFlags = options['enable-experiment']; + final List? experimentalFlags = options['enable-experiment']; final Map environmentDefines = {}; if (!parseCommandLineDefines(options['define'], environmentDefines, usage)) { @@ -217,7 +214,7 @@ Future runCompiler(ArgResults options, String usage) async { final fileSystem = createFrontEndFileSystem(fileSystemScheme, fileSystemRoots); - final Uri packagesUri = packages != null ? resolveInputUri(packages) : null; + final Uri? packagesUri = packages != null ? resolveInputUri(packages) : null; final platformKernelUri = Uri.base.resolveUri(new Uri.file(platformKernel)); final List additionalDills = []; @@ -232,7 +229,8 @@ Future runCompiler(ArgResults options, String usage) async { final verbosity = Verbosity.parseArgument(options['verbosity']); final errorPrinter = new ErrorPrinter(verbosity); - final errorDetector = new ErrorDetector(previousErrorHandler: errorPrinter); + final errorDetector = + new ErrorDetector(previousErrorHandler: errorPrinter.call); final CompilerOptions compilerOptions = new CompilerOptions() ..sdkSummary = platformKernelUri @@ -280,19 +278,20 @@ Future runCompiler(ArgResults options, String usage) async { errorPrinter.printCompilationMessages(); - if (errorDetector.hasCompilationErrors || (results.component == null)) { + final Component? component = results.component; + if (errorDetector.hasCompilationErrors || (component == null)) { return compileTimeErrorExitCode; } final IOSink sink = new File(outputFileName).openWrite(); final BinaryPrinter printer = new BinaryPrinter(sink, libraryFilter: (lib) => !results.loadedLibraries.contains(lib)); - printer.writeComponentFile(results.component); + printer.writeComponentFile(component); await sink.close(); if (depfile != null) { await writeDepfile( - fileSystem, results.compiledSources, outputFileName, depfile); + fileSystem, results.compiledSources!, outputFileName, depfile); } if (splitOutputByPackages) { @@ -314,14 +313,14 @@ Future runCompiler(ArgResults options, String usage) async { /// Results of [compileToKernel]: generated kernel [Component] and /// collection of compiled sources. class KernelCompilationResults { - final Component component; + final Component? component; /// Set of libraries loaded from .dill, with or without the SDK depending on /// the compilation settings. final Set loadedLibraries; - final ClassHierarchy classHierarchy; - final CoreTypes coreTypes; - final Iterable compiledSources; + final ClassHierarchy? classHierarchy; + final CoreTypes? coreTypes; + final Iterable? compiledSources; KernelCompilationResults(this.component, this.loadedLibraries, this.classHierarchy, this.coreTypes, this.compiledSources); @@ -338,29 +337,30 @@ Future compileToKernel( List deleteToStringPackageUris: const [], bool aot: false, bool useGlobalTypeFlowAnalysis: false, - Map environmentDefines, + required Map environmentDefines, bool enableAsserts: true, bool useProtobufTreeShakerV2: false, bool minimalKernel: false, bool treeShakeWriteOnlyFields: false, - String fromDillFile: null}) async { + String? fromDillFile: null}) async { // Replace error handler to detect if there are compilation errors. final errorDetector = new ErrorDetector(previousErrorHandler: options.onDiagnostic); - options.onDiagnostic = errorDetector; + options.onDiagnostic = errorDetector.call; + final target = options.target!; options.environmentDefines = - options.target.updateEnvironmentDefines(environmentDefines); + target.updateEnvironmentDefines(environmentDefines); - CompilerResult compilerResult; + CompilerResult? compilerResult; if (fromDillFile != null) { compilerResult = await loadKernel(options.fileSystem, resolveInputUri(fromDillFile)); } else { compilerResult = await kernelForProgram(source, options); } - Component component = compilerResult?.component; - Iterable compiledSources = component?.uriToSource?.keys; + final Component? component = compilerResult?.component; + Iterable? compiledSources = component?.uriToSource.keys; Set loadedLibraries = createLoadedLibrariesSet( compilerResult?.loadedComponents, compilerResult?.sdkComponent, @@ -373,13 +373,8 @@ Future compileToKernel( // Run global transformations only if component is correct. if ((aot || minimalKernel) && component != null) { - await runGlobalTransformations( - options.target, - component, - useGlobalTypeFlowAnalysis, - enableAsserts, - useProtobufTreeShakerV2, - errorDetector, + await runGlobalTransformations(target, component, useGlobalTypeFlowAnalysis, + enableAsserts, useProtobufTreeShakerV2, errorDetector, minimalKernel: minimalKernel, treeShakeWriteOnlyFields: treeShakeWriteOnlyFields); @@ -387,7 +382,7 @@ Future compileToKernel( // compiledSources is component.uriToSource.keys. // Make a copy of compiledSources to detach it from // component.uriToSource which is cleared below. - compiledSources = compiledSources.toList(); + compiledSources = compiledSources!.toList(); component.metadata.clear(); component.uriToSource.clear(); @@ -406,7 +401,7 @@ Future compileToKernel( } Set createLoadedLibrariesSet( - List loadedComponents, Component sdkComponent, + List? loadedComponents, Component? sdkComponent, {bool includePlatform: false}) { final Set loadedLibraries = {}; if (loadedComponents != null) { @@ -481,8 +476,11 @@ Future runGlobalTransformations( /// Runs given [action] with [CompilerContext]. This is needed to /// be able to report compile-time errors. -Future runWithFrontEndCompilerContext(Uri source, - CompilerOptions compilerOptions, Component component, T action()) async { +Future runWithFrontEndCompilerContext( + Uri source, + CompilerOptions compilerOptions, + Component component, + Future action()) async { final processedOptions = new ProcessedOptions(options: compilerOptions, inputs: [source]); @@ -498,7 +496,7 @@ Future runWithFrontEndCompilerContext(Uri source, } class ErrorDetector { - final DiagnosticMessageHandler previousErrorHandler; + final DiagnosticMessageHandler? previousErrorHandler; bool hasCompilationErrors = false; ErrorDetector({this.previousErrorHandler}); @@ -514,8 +512,9 @@ class ErrorDetector { class ErrorPrinter { final Verbosity verbosity; - final DiagnosticMessageHandler previousErrorHandler; - final compilationMessages = >{}; + final DiagnosticMessageHandler? previousErrorHandler; + final Map> compilationMessages = + >{}; ErrorPrinter(this.verbosity, {this.previousErrorHandler}); @@ -539,8 +538,8 @@ class ErrorPrinter { } return 0; }); - for (final Uri sourceUri in sortedUris) { - for (final DiagnosticMessage message in compilationMessages[sourceUri]) { + for (final Uri? sourceUri in sortedUris) { + for (final DiagnosticMessage message in compilationMessages[sourceUri]!) { if (Verbosity.shouldPrint(verbosity, message)) { printDiagnosticMessage(message, print); } @@ -576,7 +575,7 @@ Future autoDetectNullSafetyMode( } /// Create front-end target with given name. -Target createFrontEndTarget(String targetName, +Target? createFrontEndTarget(String targetName, {bool trackWidgetCreation = false, bool nullSafety = false}) { // Make sure VM-specific targets are available. installAdditionalTargets(); @@ -591,9 +590,8 @@ Target createFrontEndTarget(String targetName, /// If requested, create a virtual mutli-root file system and/or an http aware /// file system. FileSystem createFrontEndFileSystem( - String multiRootFileSystemScheme, List multiRootFileSystemRoots, - {bool allowHttp}) { - allowHttp ??= false; + String? multiRootFileSystemScheme, List? multiRootFileSystemRoots, + {bool allowHttp = false}) { FileSystem fileSystem = StandardFileSystem.instance; if (allowHttp) { fileSystem = HttpAwareFileSystem(fileSystem); @@ -615,7 +613,7 @@ FileSystem createFrontEndFileSystem( Future asFileUri(FileSystem fileSystem, Uri uri) async { FileSystemEntity fse = fileSystem.entityForUri(uri); if (fse is MultiRootFileSystemEntity) { - fse = await (fse as MultiRootFileSystemEntity).delegate; + fse = await fse.delegate; } return fse.uri; } @@ -645,8 +643,9 @@ Future convertToPackageUri( Future writeOutputSplitByPackages(Uri source, CompilerOptions compilerOptions, KernelCompilationResults compilationResults, String outputFileName) async { final packages = []; - await runWithFrontEndCompilerContext( - source, compilerOptions, compilationResults.component, () async { + final Component component = compilationResults.component!; + await runWithFrontEndCompilerContext(source, compilerOptions, component, + () async { // When loading a kernel file list, flutter_runner and dart_runner expect // 'main' to be last. await forEachPackage(compilationResults, @@ -655,12 +654,10 @@ Future writeOutputSplitByPackages(Uri source, CompilerOptions compilerOptions, final String filename = '$outputFileName-$package.dilp'; final IOSink sink = new File(filename).openWrite(); - Component partComponent = compilationResults.component; - final BinaryPrinter printer = new BinaryPrinter(sink, libraryFilter: (lib) => packageFor(lib, compilationResults.loadedLibraries) == package); - printer.writeComponentFile(partComponent); + printer.writeComponentFile(component); await sink.close(); }, mainFirst: false); @@ -673,7 +670,7 @@ Future writeOutputSplitByPackages(Uri source, CompilerOptions compilerOptions, await packagesList.close(); } -String packageFor(Library lib, Set loadedLibraries) { +String? packageFor(Library lib, Set loadedLibraries) { // Core libraries are not written into any package kernel binaries. if (loadedLibraries.contains(lib)) return null; @@ -701,23 +698,25 @@ void sortComponent(Component component) { } } -Future forEachPackage(KernelCompilationResults results, - T action(String package, List libraries), - {bool mainFirst}) async { - final Component component = results.component; +Future forEachPackage(KernelCompilationResults results, + Future action(String package, List libraries), + {required bool mainFirst}) async { + final Component component = results.component!; final Set loadedLibraries = results.loadedLibraries; sortComponent(component); - final packages = new Map>(); + final Map> packages = >{}; packages['main'] = []; // Always create 'main'. for (Library lib in component.libraries) { - packages - .putIfAbsent(packageFor(lib, loadedLibraries), () => []) - .add(lib); + final String? package = packageFor(lib, loadedLibraries); + // Ignore external libraries. + if (package == null) { + continue; + } + packages.putIfAbsent(package, () => []).add(lib); } - packages.remove(null); // Ignore external libraries. - final mainLibraries = packages.remove('main'); + final mainLibraries = packages.remove('main')!; if (mainFirst) { await action('main', mainLibraries); } @@ -728,7 +727,7 @@ Future forEachPackage(KernelCompilationResults results, component.setMainMethodAndMode(null, true, compilationMode); component.problemsAsJson = null; for (String package in packages.keys) { - await action(package, packages[package]); + await action(package, packages[package]!); } component.setMainMethodAndMode(mainMethod?.reference, true, compilationMode); component.problemsAsJson = problemsAsJson; @@ -750,8 +749,8 @@ Future writeDepfile(FileSystem fileSystem, Iterable compiledSources, file.write(_escapePath(output)); file.write(':'); for (Uri dep in compiledSources) { - // Skip empty or corelib dependencies. - if (dep == null || dep.scheme == 'org-dartlang-sdk') continue; + // Skip corelib dependencies. + if (dep.scheme == 'org-dartlang-sdk') continue; Uri uri = await asFileUri(fileSystem, dep); file.write(' '); file.write(_escapePath(uri.toFilePath())); @@ -761,7 +760,7 @@ Future writeDepfile(FileSystem fileSystem, Iterable compiledSources, } Future createFarManifest( - String output, String dataDir, String packageManifestFilename) async { + String output, String? dataDir, String packageManifestFilename) async { List packages = await File('$output-packages').readAsLines(); // Make sure the 'main' package is the last (convention with package loader). @@ -791,7 +790,7 @@ Future createFarManifest( 'typed_data', 'vector_math' ]) { - Digest digest; + Digest? digest; if (packages.contains(package)) { final filenameInBuild = '$output-$package.dilp'; final bytes = await File(filenameInBuild).readAsBytes(); @@ -813,11 +812,20 @@ class CompilerResultLoadedFromKernel implements CompilerResult { CompilerResultLoadedFromKernel(this.component); - List get summary => null; + @override + List? get summary => null; + + @override List get loadedComponents => const []; + + @override List get deps => const []; - CoreTypes get coreTypes => null; - ClassHierarchy get classHierarchy => null; + + @override + CoreTypes? get coreTypes => null; + + @override + ClassHierarchy? get classHierarchy => null; } Future loadKernel( diff --git a/pkg/vm/lib/target/dart_runner.dart b/pkg/vm/lib/target/dart_runner.dart index c1df052cedc..995d484422b 100644 --- a/pkg/vm/lib/target/dart_runner.dart +++ b/pkg/vm/lib/target/dart_runner.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - import 'package:kernel/target/targets.dart'; import 'package:vm/target/vm.dart' show VmTarget; diff --git a/pkg/vm/lib/target/flutter.dart b/pkg/vm/lib/target/flutter.dart index 3ffdc120778..1eadf20c3b2 100644 --- a/pkg/vm/lib/target/flutter.dart +++ b/pkg/vm/lib/target/flutter.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - import 'package:kernel/ast.dart' show Component, Library; import 'package:kernel/core_types.dart' show CoreTypes; import 'package:kernel/target/changed_structure_notifier.dart'; @@ -14,7 +12,7 @@ import 'package:vm/target/vm.dart' show VmTarget; class FlutterTarget extends VmTarget { FlutterTarget(TargetFlags flags) : super(flags); - WidgetCreatorTracker _widgetTracker; + late final WidgetCreatorTracker _widgetTracker = WidgetCreatorTracker(); @override String get name => 'flutter'; @@ -57,15 +55,12 @@ class FlutterTarget extends VmTarget { CoreTypes coreTypes, List libraries, DiagnosticReporter diagnosticReporter, - {void Function(String msg) logger, - ChangedStructureNotifier changedStructureNotifier}) { + {void Function(String msg)? logger, + ChangedStructureNotifier? changedStructureNotifier}) { super.performPreConstantEvaluationTransformations( component, coreTypes, libraries, diagnosticReporter, logger: logger, changedStructureNotifier: changedStructureNotifier); if (flags.trackWidgetCreation) { - if (_widgetTracker == null) { - _widgetTracker = WidgetCreatorTracker(); - } _widgetTracker.transform(component, libraries, changedStructureNotifier); } } diff --git a/pkg/vm/lib/target/flutter_runner.dart b/pkg/vm/lib/target/flutter_runner.dart index a9c41ac8f87..addd766fa53 100644 --- a/pkg/vm/lib/target/flutter_runner.dart +++ b/pkg/vm/lib/target/flutter_runner.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - import 'package:kernel/target/targets.dart'; import 'package:vm/target/vm.dart' show VmTarget; diff --git a/pkg/vm/lib/target/install.dart b/pkg/vm/lib/target/install.dart index d691d283e74..b22d46968cc 100644 --- a/pkg/vm/lib/target/install.dart +++ b/pkg/vm/lib/target/install.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - import 'package:kernel/target/targets.dart' show targets, TargetFlags; import 'package:vm/target/dart_runner.dart' show DartRunnerTarget; import 'package:vm/target/flutter.dart' show FlutterTarget; diff --git a/pkg/vm/lib/target/vm.dart b/pkg/vm/lib/target/vm.dart index 20cd1445c3a..ec6e1b107bf 100644 --- a/pkg/vm/lib/target/vm.dart +++ b/pkg/vm/lib/target/vm.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - import 'package:kernel/ast.dart'; import 'package:kernel/clone.dart'; import 'package:kernel/class_hierarchy.dart'; @@ -34,14 +32,14 @@ import '../transformations/ffi_use_sites.dart' as transformFfiUseSites class VmTarget extends Target { final TargetFlags flags; - Class _growableList; - Class _immutableList; - Class _internalLinkedHashMap; - Class _immutableMap; - Class _oneByteString; - Class _twoByteString; - Class _smi; - Class _double; // _Double, not double. + Class? _growableList; + Class? _immutableList; + Class? _internalLinkedHashMap; + Class? _immutableMap; + Class? _oneByteString; + Class? _twoByteString; + Class? _smi; + Class? _double; // _Double, not double. VmTarget(this.flags); @@ -116,7 +114,7 @@ class VmTarget extends Target { final Field little = coreTypes.index.getField('dart:typed_data', 'Endian', 'little'); host.isConst = true; - host.initializer = new CloneVisitorNotMembers().clone(little.initializer) + host.initializer = new CloneVisitorNotMembers().clone(little.initializer!) ..parent = host; } @@ -126,8 +124,8 @@ class VmTarget extends Target { CoreTypes coreTypes, List libraries, DiagnosticReporter diagnosticReporter, - {void Function(String msg) logger, - ChangedStructureNotifier changedStructureNotifier}) { + {void Function(String msg)? logger, + ChangedStructureNotifier? changedStructureNotifier}) { super.performPreConstantEvaluationTransformations( component, coreTypes, libraries, diagnosticReporter, logger: logger, changedStructureNotifier: changedStructureNotifier); @@ -152,11 +150,11 @@ class VmTarget extends Target { CoreTypes coreTypes, ClassHierarchy hierarchy, List libraries, - Map environmentDefines, + Map? environmentDefines, DiagnosticReporter diagnosticReporter, - ReferenceFromIndex referenceFromIndex, - {void Function(String msg) logger, - ChangedStructureNotifier changedStructureNotifier}) { + ReferenceFromIndex? referenceFromIndex, + {void Function(String msg)? logger, + ChangedStructureNotifier? changedStructureNotifier}) { transformMixins.transformLibraries( this, coreTypes, hierarchy, libraries, referenceFromIndex); logger?.call("Transformed mixin applications"); @@ -184,7 +182,7 @@ class VmTarget extends Target { } // TODO(kmillikin): Make this run on a per-method basis. - bool productMode = environmentDefines["dart.vm.product"] == "true"; + bool productMode = environmentDefines!["dart.vm.product"] == "true"; transformAsync.transformLibraries( new TypeEnvironment(coreTypes, hierarchy), libraries, productMode: productMode); @@ -204,9 +202,9 @@ class VmTarget extends Target { CoreTypes coreTypes, ClassHierarchy hierarchy, Procedure procedure, - Map environmentDefines, - {void Function(String msg) logger}) { - bool productMode = environmentDefines["dart.vm.product"] == "true"; + Map? environmentDefines, + {void Function(String msg)? logger}) { + bool productMode = environmentDefines!["dart.vm.product"] == "true"; transformAsync.transformProcedure( new TypeEnvironment(coreTypes, hierarchy), procedure, productMode: productMode); @@ -451,7 +449,7 @@ class VmTarget extends Target { } @override - Class concreteIntLiteralClass(CoreTypes coreTypes, int value) { + Class? concreteIntLiteralClass(CoreTypes coreTypes, int value) { const int bitsPerInt32 = 32; const int smiBits32 = bitsPerInt32 - 2; const int smiMin32 = -(1 << smiBits32); @@ -490,7 +488,6 @@ class VmTarget extends Target { Map updateEnvironmentDefines(Map map) { // TODO(alexmarkov): Call this from the front-end in order to have // the same defines when compiling platform. - assert(map != null); map['dart.isVM'] = 'true'; // TODO(dartbug.com/36460): Derive dart.library.* definitions from platform. for (String library in extraRequiredLibraries) { diff --git a/pkg/vm/test/common_test_utils.dart b/pkg/vm/test/common_test_utils.dart index 3f8bf9c3baa..1ff586aefc8 100644 --- a/pkg/vm/test/common_test_utils.dart +++ b/pkg/vm/test/common_test_utils.dart @@ -2,8 +2,6 @@ // 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. -// @dart=2.9 - import 'dart:async'; import 'dart:io'; @@ -37,11 +35,11 @@ class TestingVmTarget extends VmTarget { } Future compileTestCaseToKernelProgram(Uri sourceUri, - {Target target, + {Target? target, bool enableSuperMixins = false, - List experimentalFlags, - Map environmentDefines, - Uri packagesFileUri}) async { + List? experimentalFlags, + Map? environmentDefines, + Uri? packagesFileUri}) async { final platformKernel = computePlatformBinariesLocation().resolve('vm_platform_strong.dill'); target ??= new TestingVmTarget(new TargetFlags()) @@ -62,11 +60,11 @@ Future compileTestCaseToKernelProgram(Uri sourceUri, }; final Component component = - (await kernelForProgram(sourceUri, options)).component; + (await kernelForProgram(sourceUri, options))!.component!; // Make sure the library name is the same and does not depend on the order // of test cases. - component.mainMethod.enclosingLibrary.name = '#lib'; + component.mainMethod!.enclosingLibrary.name = '#lib'; return component; } @@ -75,19 +73,19 @@ String kernelLibraryToString(Library library) { final StringBuffer buffer = new StringBuffer(); final printer = new Printer(buffer, showMetadata: true); printer.writeLibraryFile(library); - printer.writeConstantTable(library.enclosingComponent); + printer.writeConstantTable(library.enclosingComponent!); return buffer .toString() - .replaceAll(library.importUri.toString(), library.name); + .replaceAll(library.importUri.toString(), library.name!); } String kernelComponentToString(Component component) { final StringBuffer buffer = new StringBuffer(); new Printer(buffer, showMetadata: true).writeComponentFile(component); - final mainLibrary = component.mainMethod.enclosingLibrary; + final mainLibrary = component.mainMethod!.enclosingLibrary; return buffer .toString() - .replaceAll(mainLibrary.importUri.toString(), mainLibrary.name); + .replaceAll(mainLibrary.importUri.toString(), mainLibrary.name!); } class DevNullSink extends Sink {