Switch to accept/reject-friendly incremental compiler (#4601)

* Switch to accept/reject-friendly incremental compiler

* Merge
This commit is contained in:
Alexander Aprelev 2018-02-13 06:58:04 -08:00 committed by GitHub
parent 981ebb5e97
commit 5529f893e2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 45 deletions

View File

@ -12,7 +12,6 @@ import 'package:args/args.dart';
// ignore_for_file: implementation_imports
import 'package:front_end/src/api_prototype/compiler_options.dart';
import 'package:front_end/src/api_prototype/file_system.dart' show FileSystemEntity;
import 'package:front_end/src/api_prototype/incremental_kernel_generator.dart';
import 'package:kernel/ast.dart';
import 'package:kernel/binary/ast_to_binary.dart';
import 'package:kernel/binary/limited_ast_to_binary.dart';
@ -20,6 +19,7 @@ import 'package:kernel/kernel.dart' show Program, loadProgramFromBytes;
import 'package:kernel/target/flutter.dart';
import 'package:kernel/target/targets.dart';
import 'package:usage/uuid/uuid.dart';
import 'package:vm/incremental_compiler.dart' show IncrementalCompiler;
import 'package:vm/kernel_front_end.dart' show compileToKernel;
ArgParser _argParser = new ArgParser(allowTrailingOptions: true)
@ -64,7 +64,6 @@ Instructions:
...
<boundary-key>
- accept
- reject
- quit
Output:
@ -87,7 +86,7 @@ abstract class CompilerInterface {
Future<Null> compile(
String filename,
ArgResults options, {
IncrementalKernelGenerator generator,
IncrementalCompiler generator,
});
/// Assuming some Dart program was previously compiled, recompile it again
@ -98,10 +97,6 @@ abstract class CompilerInterface {
/// won't recompile sources that were previously reported as changed.
void acceptLastDelta();
/// Reject results of previous compilation. Next recompilation cycle will
/// recompile sources indicated as changed.
void rejectLastDelta();
/// This let's compiler know that source file identifed by `uri` was changed.
void invalidate(Uri uri);
@ -131,7 +126,7 @@ class _FrontendCompiler implements CompilerInterface {
CompilerOptions _compilerOptions;
Uri _entryPoint;
IncrementalKernelGenerator _generator;
IncrementalCompiler _generator;
String _kernelBinaryFilename;
String _kernelBinaryFilenameIncremental;
String _kernelBinaryFilenameFull;
@ -140,7 +135,7 @@ class _FrontendCompiler implements CompilerInterface {
Future<Null> compile(
String filename,
ArgResults options, {
IncrementalKernelGenerator generator,
IncrementalCompiler generator,
}) async {
final Uri filenameUri = Uri.base.resolveUri(new Uri.file(filename));
_kernelBinaryFilenameFull = '$filename.dill';
@ -162,7 +157,7 @@ class _FrontendCompiler implements CompilerInterface {
_compilerOptions = compilerOptions;
_generator = generator ?? _createGenerator(new Uri.file(_kernelBinaryFilenameFull));
await invalidateIfBootstrapping();
program = await _runWithPrintRedirection(() => _generator.computeDelta());
program = await _runWithPrintRedirection(() => _generator.compile());
} else {
if (options['link-platform']) {
// TODO(aam): Remove linkedDependencies once platform is directly embedded
@ -233,7 +228,7 @@ class _FrontendCompiler implements CompilerInterface {
final String boundaryKey = new Uuid().generateV4();
_outputStream.writeln('result $boundaryKey');
await invalidateIfBootstrapping();
final Program deltaProgram = await _generator.computeDelta();
final Program deltaProgram = await _generator.compile();
final IOSink sink = new File(_kernelBinaryFilename).openWrite();
final BinaryPrinter printer = printerFactory.newBinaryPrinter(sink);
printer.writeProgramFile(deltaProgram);
@ -245,12 +240,7 @@ class _FrontendCompiler implements CompilerInterface {
@override
void acceptLastDelta() {
// TODO(aam): implement this considering new incremental compiler API.
}
@override
void rejectLastDelta() {
// TODO(aam): implement this considering new incremental compiler API.
_generator.accept();
}
@override
@ -264,8 +254,9 @@ class _FrontendCompiler implements CompilerInterface {
_kernelBinaryFilename = _kernelBinaryFilenameFull;
}
IncrementalKernelGenerator _createGenerator(Uri bootstrapDill) {
return new IncrementalKernelGenerator(_compilerOptions, _entryPoint, bootstrapDill);
IncrementalCompiler _createGenerator(Uri bootstrapDill) {
return new IncrementalCompiler(_compilerOptions, _entryPoint,
bootstrapDill: bootstrapDill);
}
Uri _ensureFolderPath(String path) {
@ -295,7 +286,7 @@ Future<int> starter(
CompilerInterface compiler,
Stream<List<int>> input,
StringSink output,
IncrementalKernelGenerator generator,
IncrementalCompiler generator,
BinaryPrinterFactory binaryPrinterFactory,
}) async {
ArgResults options;
@ -358,9 +349,6 @@ Future<int> starter(
state = _State.RECOMPILE_LIST;
} else if (string == 'accept') {
compiler.acceptLastDelta();
} else if (string == 'reject') {
// TODO(aam) implement reject so it won't reset compiler.
compiler.resetIncrementalCompiler();
} else if (string == 'reset') {
compiler.resetIncrementalCompiler();
} else if (string == 'quit') {

View File

@ -10,16 +10,16 @@ import 'package:frontend_server/server.dart';
// that would replace api used below. This api was made private in
// an effort to discourage further use.
// ignore_for_file: implementation_imports
import 'package:front_end/src/api_prototype/incremental_kernel_generator.dart';
import 'package:kernel/binary/ast_to_binary.dart';
import 'package:kernel/ast.dart' show Program;
import 'package:mockito/mockito.dart';
import 'package:test/test.dart';
import 'package:vm/incremental_compiler.dart';
class _MockedCompiler extends Mock implements CompilerInterface {}
class _MockedIncrementalKernelGenerator extends Mock
implements IncrementalKernelGenerator {}
class _MockedIncrementalCompiler extends Mock
implements IncrementalCompiler {}
class _MockedBinaryPrinterFactory extends Mock implements BinaryPrinterFactory {}
@ -265,22 +265,6 @@ Future<int> main() async {
inputStreamController.close();
});
test('reject', () async {
final StreamController<List<int>> inputStreamController =
new StreamController<List<int>>();
final ReceivePort resetCalled = new ReceivePort();
when(compiler.resetIncrementalCompiler()).thenAnswer((Invocation invocation) {
resetCalled.sendPort.send(true);
});
final int exitcode = await starter(args, compiler: compiler,
input: inputStreamController.stream,
);
expect(exitcode, equals(0));
inputStreamController.add('reject\n'.codeUnits);
await resetCalled.first;
inputStreamController.close();
});
test('reset', () async {
final StreamController<List<int>> inputStreamController =
new StreamController<List<int>>();
@ -358,9 +342,9 @@ Future<int> main() async {
}
});
final _MockedIncrementalKernelGenerator generator =
new _MockedIncrementalKernelGenerator();
when(generator.computeDelta())
final _MockedIncrementalCompiler generator =
new _MockedIncrementalCompiler();
when(generator.compile())
.thenAnswer((_) => new Future<Program>.value(new Program()));
final _MockedBinaryPrinterFactory printerFactory =
new _MockedBinaryPrinterFactory();