Revert "migrate package:frontend_server/compute_kernel.dart to null safety" This reverts commit 4894ae493f5d5262222ecb6122eba6c8b95cb51c. Reason for revert: Breaks google3 Original change's description: > migrate package:frontend_server/compute_kernel.dart to null safety > > unblocks https://github.com/dart-lang/language/issues/2274 > > Bug: https://github.com/dart-lang/sdk/issues/49212 > Change-Id: I8d6b055dbc00dadce5efee57692ee1f21e8fde77 > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/247601 > Commit-Queue: Jake Macdonald <jakemac@google.com> > Auto-Submit: Jake Macdonald <jakemac@google.com> > Reviewed-by: Johnni Winther <johnniwinther@google.com> TBR=johnniwinther@google.com,jakemac@google.com Change-Id: I824374df31721fe60a08195b90f545e28460a982 No-Presubmit: true No-Tree-Checks: true No-Try: true Bug: https://github.com/dart-lang/sdk/issues/49212 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/247760 Auto-Submit: Jake Macdonald <jakemac@google.com> Reviewed-by: Jake Macdonald <jakemac@google.com> Reviewed-by: Bob Nystrom <rnystrom@google.com> Commit-Queue: Bob Nystrom <rnystrom@google.com>
diff --git a/pkg/frontend_server/lib/compute_kernel.dart b/pkg/frontend_server/lib/compute_kernel.dart index 2341ca6..2c70e9d 100644 --- a/pkg/frontend_server/lib/compute_kernel.dart +++ b/pkg/frontend_server/lib/compute_kernel.dart
@@ -2,6 +2,8 @@ // 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.8 + /// A library to invoke the CFE to compute kernel summary files. /// /// Used by `utils/bazel/kernel_worker.dart`. @@ -117,7 +119,7 @@ class ComputeKernelResult { final bool succeeded; - final fe.InitializedCompilerState? previousState; + final fe.InitializedCompilerState previousState; ComputeKernelResult(this.succeeded, this.previousState); } @@ -132,9 +134,9 @@ /// Returns whether or not the summary was successfully output. Future<ComputeKernelResult> computeKernel(List<String> args, {bool isWorker: false, - StringBuffer? outputBuffer, - Map<Uri, List<int>>? inputDigests, - fe.InitializedCompilerState? previousState}) async { + StringBuffer outputBuffer, + Map<Uri, List<int>> inputDigests, + fe.InitializedCompilerState previousState}) async { inputDigests ??= <Uri, List<int>>{}; dynamic out = outputBuffer ?? stderr; bool succeeded = true; @@ -170,7 +172,7 @@ // TODO(sigmund,jakemac): make target mandatory. We allow null to be backwards // compatible while we migrate existing clients of this tool. var targetName = - (parsedArgs['target'] as String?) ?? (summaryOnly ? 'ddc' : 'vm'); + (parsedArgs['target'] as String) ?? (summaryOnly ? 'ddc' : 'vm'); var targetFlags = new TargetFlags( trackWidgetCreation: trackWidgetCreation, enableNullSafety: nnbdMode == fe.NnbdMode.Strong); @@ -223,7 +225,6 @@ break; default: out.writeln('error: unsupported target: $targetName'); - return ComputeKernelResult(false, previousState); } List<Uri> linkedInputs = @@ -359,12 +360,12 @@ } } - List<int>? kernel; + List<int> kernel; bool wroteUsedDills = false; if (usingIncrementalCompiler) { state.options.onDiagnostic = onDiagnostic; IncrementalCompilerResult incrementalCompilerResult = - await state.incrementalCompiler!.computeDelta( + await state.incrementalCompiler.computeDelta( entryPoints: sources, fullComponent: true, trackNeededDillLibraries: recordUsedInputs); @@ -372,9 +373,9 @@ if (recordUsedInputs) { Set<Uri> usedOutlines = {}; - for (Library lib in incrementalCompilerResult.neededDillLibraries!) { + for (Library lib in incrementalCompilerResult.neededDillLibraries) { if (lib.importUri.isScheme("dart")) continue; - Uri? uri = state.libraryToInputDill![lib.importUri]; + Uri uri = state.libraryToInputDill[lib.importUri]; if (uri == null) { throw new StateError("Library ${lib.importUri} was recorded as used, " "but was not in the list of known libraries."); @@ -387,7 +388,7 @@ wroteUsedDills = true; } - kernel = await state.incrementalCompiler!.context.runInContext((_) { + kernel = await state.incrementalCompiler.context.runInContext((_) { if (summaryOnly) { incrementalComponent.uriToSource.clear(); incrementalComponent.problemsAsJson = null; @@ -411,15 +412,13 @@ kernel = await fe.compileSummary(state, sources, onDiagnostic, includeOffsets: false); } else { - Component? component = await fe + Component component = await fe .compileComponent(state, sources, onDiagnostic, buildSummary: summary); - if (component != null) { - kernel = fe.serializeComponent(component, - filter: excludeNonSources - ? (library) => sources.contains(library.importUri) - : null, - includeOffsets: true); - } + kernel = fe.serializeComponent(component, + filter: excludeNonSources + ? (library) => sources.contains(library.importUri) + : null, + includeOffsets: true); } state.options.onDiagnostic = null; // See http://dartbug.com/36983. @@ -469,6 +468,7 @@ } Uri toUri(String uriString) { + if (uriString == null) return null; // Windows-style paths use '\', so convert them to '/' in case they've been // concatenated with Unix-style paths. return Uri.base.resolve(uriString.replaceAll("\\", "/"));
diff --git a/pkg/frontend_server/lib/src/strong_components.dart b/pkg/frontend_server/lib/src/strong_components.dart index a436b7c..0711f2d 100644 --- a/pkg/frontend_server/lib/src/strong_components.dart +++ b/pkg/frontend_server/lib/src/strong_components.dart
@@ -2,6 +2,7 @@ // 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/util/graph.dart'; @@ -44,7 +45,7 @@ final Uri mainUri; /// The filesystem instance for resolving files. - final FileSystem? fileSystem; + final FileSystem fileSystem; /// The set of libraries for each module URI. /// @@ -67,13 +68,10 @@ } // If we don't have a file uri, just use the first library in the // component. - Library? entrypoint; - for (Library library in component.libraries) { - if (library.fileUri == mainUri || library.importUri == mainUri) { - entrypoint = library; - break; - } - } + Library entrypoint = component.libraries.firstWhere( + (Library library) => + library.fileUri == mainUri || library.importUri == mainUri, + orElse: () => null); if (entrypoint == null) { throw Exception('Could not find entrypoint ${mainUri} in Component.');
diff --git a/pkg/frontend_server/test/src/strong_components_test.dart b/pkg/frontend_server/test/src/strong_components_test.dart index 9bb6596..2281e82 100644 --- a/pkg/frontend_server/test/src/strong_components_test.dart +++ b/pkg/frontend_server/test/src/strong_components_test.dart
@@ -2,6 +2,7 @@ // 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:frontend_server/src/strong_components.dart'; import 'package:kernel/ast.dart'; import 'package:test/test.dart';