22// for details. All rights reserved. Use of this source code is governed by a
33// BSD-style license that can be found in the LICENSE file.
44
5- // @dart=2.9
6-
75/// Defines wrapper class around incremental compiler to support
86/// the flow, where incremental deltas can be rejected by VM.
97import 'dart:async' ;
@@ -20,23 +18,23 @@ const String kDebugProcedureName = ":Eval";
2018/// deltas and combines them together into resultant program until it is
2119/// accepted.
2220class IncrementalCompiler {
23- IncrementalKernelGenerator _generator;
24- IncrementalSerializer incrementalSerializer;
21+ late IncrementalKernelGenerator _generator;
22+ IncrementalSerializer ? incrementalSerializer;
2523
2624 // Component that reflect the state that was most recently accepted by the
2725 // client. Is [null], if no compilation results were accepted by the client.
28- Component _lastKnownGood;
29- List <Component > _pendingDeltas;
26+ Component ? _lastKnownGood;
27+ late List <Component > _pendingDeltas;
3028 CompilerOptions _compilerOptions;
3129 bool initialized = false ;
3230 bool fullComponent = false ;
33- Uri initializeFromDillUri;
31+ Uri ? initializeFromDillUri;
3432 Uri _entryPoint;
3533 final bool forExpressionCompilationOnly;
3634
3735 Uri get entryPoint => _entryPoint;
3836 IncrementalKernelGenerator get generator => _generator;
39- Component get lastKnownGoodComponent => _lastKnownGood;
37+ Component ? get lastKnownGoodComponent => _lastKnownGood;
4038
4139 IncrementalCompiler (this ._compilerOptions, this ._entryPoint,
4240 {this .initializeFromDillUri, bool incrementalSerialization: true })
@@ -61,12 +59,12 @@ class IncrementalCompiler {
6159 ///
6260 /// If [entryPoint] is specified, that points to new entry point for the
6361 /// compilation. Otherwise, previously set entryPoint is used.
64- Future <Component > compile ({Uri entryPoint}) async {
62+ Future <Component > compile ({Uri ? entryPoint}) async {
6563 final task = new TimelineTask ();
6664 try {
6765 task.start ("IncrementalCompiler.compile" );
6866 _entryPoint = entryPoint ?? _entryPoint;
69- List <Uri > entryPoints;
67+ List <Uri >? entryPoints;
7068 if (entryPoint != null ) entryPoints = [entryPoint];
7169 Component component = await _generator.computeDelta (
7270 entryPoints: entryPoints, fullComponent: fullComponent);
@@ -80,8 +78,9 @@ class IncrementalCompiler {
8078 }
8179
8280 _combinePendingDeltas (bool includePlatform) {
83- Procedure mainMethod;
84- NonNullableByDefaultCompiledMode compilationMode;
81+ Procedure ? mainMethod;
82+ NonNullableByDefaultCompiledMode compilationMode =
83+ NonNullableByDefaultCompiledMode .Invalid ;
8584 Map <Uri , Library > combined = < Uri , Library > {};
8685 Map <Uri , Source > uriToSource = new Map <Uri , Source >();
8786 for (Component delta in _pendingDeltas) {
@@ -104,8 +103,8 @@ class IncrementalCompiler {
104103 ..setMainMethodAndMode (mainMethod? .reference, true , compilationMode);
105104 }
106105
107- CoreTypes getCoreTypes () => _generator.getCoreTypes ();
108- ClassHierarchy getClassHierarchy () => _generator.getClassHierarchy ();
106+ CoreTypes ? getCoreTypes () => _generator.getCoreTypes ();
107+ ClassHierarchy ? getClassHierarchy () => _generator.getClassHierarchy ();
109108
110109 /// This lets incremental compiler know that results of last [compile] call
111110 /// were accepted, don't need to be included into subsequent [compile] calls
@@ -118,13 +117,14 @@ class IncrementalCompiler {
118117 Map <Uri , Library > combined = < Uri , Library > {};
119118 Map <Uri , Source > uriToSource = < Uri , Source > {};
120119
121- if (_lastKnownGood != null ) {
120+ Component ? lastKnownGood = _lastKnownGood;
121+ if (lastKnownGood != null ) {
122122 // TODO(aam): Figure out how to skip no-longer-used libraries from
123123 // [_lastKnownGood] libraries.
124- for (Library library in _lastKnownGood .libraries) {
124+ for (Library library in lastKnownGood .libraries) {
125125 combined[library.importUri] = library;
126126 }
127- uriToSource.addAll (_lastKnownGood .uriToSource);
127+ uriToSource.addAll (lastKnownGood .uriToSource);
128128 }
129129
130130 Component candidate = _combinePendingDeltas (true );
@@ -133,13 +133,13 @@ class IncrementalCompiler {
133133 }
134134 uriToSource.addAll (candidate.uriToSource);
135135
136- _lastKnownGood = new Component (
136+ _lastKnownGood = lastKnownGood = new Component (
137137 libraries: combined.values.toList (),
138138 uriToSource: uriToSource,
139139 )..setMainMethodAndMode (
140140 candidate.mainMethod? .reference, true , candidate.mode);
141141 for (final repo in candidate.metadata.values) {
142- _lastKnownGood .addMetadataRepository (repo);
142+ lastKnownGood .addMetadataRepository (repo);
143143 }
144144 _pendingDeltas.clear ();
145145 }
@@ -182,12 +182,12 @@ class IncrementalCompiler {
182182 fullComponent = true ;
183183 }
184184
185- Future <Procedure > compileExpression (
185+ Future <Procedure ? > compileExpression (
186186 String expression,
187187 List <String > definitions,
188188 List <String > typeDefinitions,
189189 String libraryUri,
190- String klass,
190+ String ? klass,
191191 bool isStatic) {
192192 Map <String , DartType > completeDefinitions = {};
193193 for (String name in definitions) {
@@ -202,7 +202,6 @@ class IncrementalCompiler {
202202 }
203203
204204 Uri library = Uri .parse (libraryUri);
205- if (library == null ) return null ;
206205
207206 return _generator.compileExpression (expression, completeDefinitions,
208207 typeParameters, kDebugProcedureName, library, klass, isStatic);
0 commit comments