Skip to content

Commit

Permalink
migrate package:frontend_server/compute_kernel.dart to null safety
Browse files Browse the repository at this point in the history
unblocks dart-lang/language#2274

Bug: #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>
  • Loading branch information
jakemac53 authored and Commit Bot committed Jun 9, 2022
1 parent 69f32d6 commit 4894ae4
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
38 changes: 19 additions & 19 deletions pkg/frontend_server/lib/compute_kernel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.8

/// A library to invoke the CFE to compute kernel summary files.
///
/// Used by `utils/bazel/kernel_worker.dart`.
Expand Down Expand Up @@ -119,7 +117,7 @@ final summaryArgsParser = new ArgParser()

class ComputeKernelResult {
final bool succeeded;
final fe.InitializedCompilerState previousState;
final fe.InitializedCompilerState? previousState;

ComputeKernelResult(this.succeeded, this.previousState);
}
Expand All @@ -134,9 +132,9 @@ class ComputeKernelResult {
/// 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;
Expand Down Expand Up @@ -172,7 +170,7 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
// 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);
Expand Down Expand Up @@ -225,6 +223,7 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
break;
default:
out.writeln('error: unsupported target: $targetName');
return ComputeKernelResult(false, previousState);
}

List<Uri> linkedInputs =
Expand Down Expand Up @@ -360,22 +359,22 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
}
}

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);
Component incrementalComponent = incrementalCompilerResult.component;

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.");
Expand All @@ -388,7 +387,7 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
wroteUsedDills = true;
}

kernel = await state.incrementalCompiler.context.runInContext((_) {
kernel = await state.incrementalCompiler!.context.runInContext((_) {
if (summaryOnly) {
incrementalComponent.uriToSource.clear();
incrementalComponent.problemsAsJson = null;
Expand All @@ -412,13 +411,15 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
kernel = await fe.compileSummary(state, sources, onDiagnostic,
includeOffsets: false);
} else {
Component component = await fe
Component? component = await fe
.compileComponent(state, sources, onDiagnostic, buildSummary: summary);
kernel = fe.serializeComponent(component,
filter: excludeNonSources
? (library) => sources.contains(library.importUri)
: null,
includeOffsets: true);
if (component != null) {
kernel = fe.serializeComponent(component,
filter: excludeNonSources
? (library) => sources.contains(library.importUri)
: null,
includeOffsets: true);
}
}
state.options.onDiagnostic = null; // See http://dartbug.com/36983.

Expand Down Expand Up @@ -468,7 +469,6 @@ class DevCompilerSummaryTarget extends DevCompilerTarget with SummaryMixin {
}

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("\\", "/"));
Expand Down
14 changes: 8 additions & 6 deletions pkg/frontend_server/lib/src/strong_components.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// 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';

Expand Down Expand Up @@ -45,7 +44,7 @@ class StrongComponents {
final Uri mainUri;

/// The filesystem instance for resolving files.
final FileSystem fileSystem;
final FileSystem? fileSystem;

/// The set of libraries for each module URI.
///
Expand All @@ -68,10 +67,13 @@ class StrongComponents {
}
// If we don't have a file uri, just use the first library in the
// component.
Library entrypoint = component.libraries.firstWhere(
(Library library) =>
library.fileUri == mainUri || library.importUri == mainUri,
orElse: () => null);
Library? entrypoint;
for (Library library in component.libraries) {
if (library.fileUri == mainUri || library.importUri == mainUri) {
entrypoint = library;
break;
}
}

if (entrypoint == null) {
throw Exception('Could not find entrypoint ${mainUri} in Component.');
Expand Down
1 change: 0 additions & 1 deletion pkg/frontend_server/test/src/strong_components_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// 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';
Expand Down

0 comments on commit 4894ae4

Please sign in to comment.