2
2
// for details. All rights reserved. Use of this source code is governed by a
3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
- // @dart = 2.10
6
-
7
5
import 'dart:async' ;
8
6
7
+ import 'package:collection/collection.dart' ;
9
8
import 'package:front_end/src/fasta/kernel/utils.dart' ;
10
9
import 'package:kernel/ast.dart' as ir;
11
10
import 'package:kernel/binary/ast_from_binary.dart' show BinaryBuilder;
@@ -49,7 +48,7 @@ class Output {
49
48
/// The [Uri] of the root library containing main.
50
49
/// Note: rootLibraryUri will be null for some modules, for example in the
51
50
/// case of dependent libraries processed modularly.
52
- final Uri rootLibraryUri;
51
+ final Uri ? rootLibraryUri;
53
52
54
53
/// Returns the [Uri] s of all libraries that have been loaded that are
55
54
/// reachable from the [rootLibraryUri] .
@@ -75,25 +74,25 @@ class Output {
75
74
}
76
75
77
76
Library _findEntryLibrary (Component component, Uri entryUri) {
78
- var entryLibrary = component.libraries
79
- . firstWhere ((l) => l.fileUri == entryUri, orElse : () => null );
77
+ final entryLibrary =
78
+ component.libraries. firstWhereOrNull ((l) => l.fileUri == entryUri);
80
79
if (entryLibrary == null ) {
81
80
throw ArgumentError ('Entry uri $entryUri not found in dill.' );
82
81
}
83
82
return entryLibrary;
84
83
}
85
84
86
85
ir.Reference _findMainMethod (Library entryLibrary) {
87
- var mainMethod = entryLibrary.procedures
88
- . firstWhere ((p) => p.name.text == 'main' , orElse : () => null );
86
+ var mainMethod =
87
+ entryLibrary.procedures. firstWhereOrNull ((p) => p.name.text == 'main' );
89
88
90
89
// In some cases, a main method is defined in another file, and then
91
90
// exported. In these cases, we search for the main method in
92
91
// [additionalExports].
93
- ir.Reference mainMethodReference;
92
+ ir.Reference ? mainMethodReference;
94
93
if (mainMethod == null ) {
95
94
mainMethodReference = entryLibrary.additionalExports
96
- .firstWhere ((p) => p.canonicalName.name == 'main' , orElse : () => null );
95
+ .firstWhereOrNull ((p) => p.canonicalName? .name == 'main' );
97
96
} else {
98
97
mainMethodReference = mainMethod.reference;
99
98
}
@@ -121,8 +120,8 @@ void _validateNullSafetyMode(CompilerOptions options) {
121
120
}
122
121
123
122
class _LoadFromKernelResult {
124
- final ir.Component component;
125
- final Library entryLibrary;
123
+ final ir.Component ? component;
124
+ final Library ? entryLibrary;
126
125
final List <Uri > moduleLibraries;
127
126
128
127
_LoadFromKernelResult (
@@ -135,8 +134,8 @@ void _doGlobalTransforms(Component component) {
135
134
136
135
Future <_LoadFromKernelResult > _loadFromKernel (CompilerOptions options,
137
136
api.CompilerInput compilerInput, String targetName) async {
138
- Library entryLibrary;
139
- var resolvedUri = options.compilationTarget;
137
+ Library ? entryLibrary;
138
+ var resolvedUri = options.compilationTarget! ;
140
139
ir.Component component = ir.Component ();
141
140
List <Uri > moduleLibraries = [];
142
141
@@ -171,24 +170,24 @@ Future<_LoadFromKernelResult> _loadFromKernel(CompilerOptions options,
171
170
options.modularMode || options.hasModularAnalysisInputs;
172
171
if (options.platformBinaries != null && ! platformBinariesIncluded) {
173
172
var platformUri = options.platformBinaries
174
- .resolve (_getPlatformFilename (options, targetName));
173
+ ? .resolve (_getPlatformFilename (options, targetName));
175
174
// Modular analysis can be run on the sdk by providing directly the
176
175
// path to the platform.dill file. In that case, we do not load the
177
176
// platform file implicitly.
178
177
// TODO(joshualitt): Change how we detect this case so it is less
179
178
// brittle.
180
- if (platformUri != resolvedUri) await read (platformUri);
179
+ if (platformUri != resolvedUri) await read (platformUri! );
181
180
}
182
181
183
182
// Concatenate dills.
184
183
if (options.dillDependencies != null ) {
185
- for (Uri dependency in options.dillDependencies) {
184
+ for (Uri dependency in options.dillDependencies! ) {
186
185
await read (dependency);
187
186
}
188
187
}
189
188
190
189
if (options.entryUri != null ) {
191
- entryLibrary = _findEntryLibrary (component, options.entryUri);
190
+ entryLibrary = _findEntryLibrary (component, options.entryUri! );
192
191
var mainMethod = _findMainMethod (entryLibrary);
193
192
component.setMainMethodAndMode (mainMethod, true , component.mode);
194
193
}
@@ -201,7 +200,7 @@ Future<_LoadFromKernelResult> _loadFromKernel(CompilerOptions options,
201
200
}
202
201
203
202
class _LoadFromSourceResult {
204
- final ir.Component component;
203
+ final ir.Component ? component;
205
204
final fe.InitializedCompilerState initializedCompilerState;
206
205
final List <Uri > moduleLibraries;
207
206
@@ -217,7 +216,7 @@ Future<_LoadFromSourceResult> _loadFromSource(
217
216
String targetName) async {
218
217
bool verbose = false ;
219
218
bool cfeConstants = options.features.cfeConstants.isEnabled;
220
- Map <String , String > environment = cfeConstants ? options.environment : null ;
219
+ Map <String , String >? environment = cfeConstants ? options.environment : null ;
221
220
Target target = Dart2jsTarget (targetName, TargetFlags (),
222
221
options: options,
223
222
canPerformGlobalTransforms: true ,
@@ -237,7 +236,7 @@ Future<_LoadFromSourceResult> _loadFromSource(
237
236
List <Uri > sources = [];
238
237
if (options.sources != null ) {
239
238
isModularCompile = true ;
240
- sources.addAll (options.sources);
239
+ sources.addAll (options.sources! );
241
240
} else {
242
241
fe.CompilerOptions feOptions = fe.CompilerOptions ()
243
242
..target = target
@@ -249,22 +248,22 @@ Future<_LoadFromSourceResult> _loadFromSource(
249
248
..fileSystem = fileSystem
250
249
..onDiagnostic = onDiagnostic
251
250
..verbosity = verbosity;
252
- Uri resolvedUri = options.compilationTarget;
251
+ Uri resolvedUri = options.compilationTarget! ;
253
252
bool isLegacy =
254
253
await fe.uriUsesLegacyLanguageVersion (resolvedUri, feOptions);
255
254
_inferNullSafetyMode (options, ! isLegacy);
256
- sources.add (options.compilationTarget);
255
+ sources.add (options.compilationTarget! );
257
256
}
258
257
259
258
// If we are performing a modular compile, we expect the platform binary to be
260
259
// supplied along with other dill dependencies.
261
260
List <Uri > dependencies = [];
262
261
if (options.platformBinaries != null && ! isModularCompile) {
263
- dependencies.add (options.platformBinaries
262
+ dependencies.add (options.platformBinaries!
264
263
.resolve (_getPlatformFilename (options, targetName)));
265
264
}
266
265
if (options.dillDependencies != null ) {
267
- dependencies.addAll (options.dillDependencies);
266
+ dependencies.addAll (options.dillDependencies! );
268
267
}
269
268
270
269
initializedCompilerState = fe.initializeCompiler (
@@ -279,14 +278,14 @@ Future<_LoadFromSourceResult> _loadFromSource(
279
278
options.useLegacySubtyping ? fe.NnbdMode .Weak : fe.NnbdMode .Strong ,
280
279
invocationModes: options.cfeInvocationModes,
281
280
verbosity: verbosity);
282
- ir.Component component = await fe.compile (initializedCompilerState, verbose,
281
+ ir.Component ? component = await fe.compile (initializedCompilerState, verbose,
283
282
fileSystem, onDiagnostic, sources, isModularCompile);
284
283
_validateNullSafetyMode (options);
285
284
286
285
// We have to compute canonical names on the component here to avoid missing
287
286
// canonical names downstream.
288
287
if (isModularCompile) {
289
- component.computeCanonicalNames ();
288
+ component? .computeCanonicalNames ();
290
289
}
291
290
return _LoadFromSourceResult (
292
291
component, initializedCompilerState, isModularCompile ? sources : []);
@@ -295,11 +294,11 @@ Future<_LoadFromSourceResult> _loadFromSource(
295
294
Output _createOutput (
296
295
CompilerOptions options,
297
296
DiagnosticReporter reporter,
298
- Library entryLibrary,
297
+ Library ? entryLibrary,
299
298
ir.Component component,
300
299
List <Uri > moduleLibraries,
301
300
fe.InitializedCompilerState initializedCompilerState) {
302
- Uri rootLibraryUri = null ;
301
+ Uri ? rootLibraryUri = null ;
303
302
Iterable <ir.Library > libraries = component.libraries;
304
303
if (! options.modularMode) {
305
304
// For non-modular builds we should always have a [mainMethod] at this
@@ -317,7 +316,7 @@ Output _createOutput(
317
316
// NOTE: Under some circumstances, the [entryLibrary] exports the
318
317
// [mainMethod] from another library, and thus the [enclosingLibrary] of
319
318
// the [mainMethod] may not be the same as the [entryLibrary].
320
- var root = entryLibrary ?? component.mainMethod.enclosingLibrary;
319
+ var root = entryLibrary ?? component.mainMethod! .enclosingLibrary;
321
320
rootLibraryUri = root.importUri;
322
321
323
322
// Filter unreachable libraries: [Component] was built by linking in the
@@ -360,15 +359,15 @@ Output _createOutput(
360
359
}
361
360
362
361
/// Loads an entire Kernel [Component] from a file on disk.
363
- Future <Output > run (Input input) async {
362
+ Future <Output ? > run (Input input) async {
364
363
CompilerOptions options = input.options;
365
364
api.CompilerInput compilerInput = input.compilerInput;
366
365
DiagnosticReporter reporter = input.reporter;
367
366
368
367
String targetName = options.compileForServer ? "dart2js_server" : "dart2js" ;
369
368
370
- Library entryLibrary;
371
- ir.Component component;
369
+ Library ? entryLibrary;
370
+ ir.Component ? component;
372
371
List <Uri > moduleLibraries = const [];
373
372
fe.InitializedCompilerState initializedCompilerState =
374
373
input.initializedCompilerState;
0 commit comments