Commit 85e4f052 authored by Alexander Aprelev's avatar Alexander Aprelev Committed by GitHub

Fix restart flow for preview-dart-2 mode. (#12496)

* Fix restart flow for preview-dart-2 mode.

Restart in preview-dart-2 needs to use kernel file and it has to be complete, rather than incremental kernel file.

* Add curly braces

* Do full compile on restart

* Roll engine to pick up changes to hot reload for preview-dart-2
parent a4b29d64
2a84f18c795d24ba95baed360fcb58b3dc66d661 248af2d5b6b5a4fd32c87bac68c624a62d8d9432
...@@ -174,4 +174,11 @@ class ResidentCompiler { ...@@ -174,4 +174,11 @@ class ResidentCompiler {
void reject() { void reject() {
_server.stdin.writeln('reject'); _server.stdin.writeln('reject');
} }
/// Should be invoked when frontend server compiler should forget what was
/// accepted previously so that next call to [recompile] produces complete
/// kernel file.
void reset() {
_server.stdin.writeln('reset');
}
} }
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert' show BASE64, UTF8; import 'dart:convert' show BASE64, UTF8;
import 'package:flutter_tools/src/artifacts.dart';
import 'package:json_rpc_2/json_rpc_2.dart' as rpc; import 'package:json_rpc_2/json_rpc_2.dart' as rpc;
import 'asset.dart'; import 'asset.dart';
...@@ -369,6 +370,7 @@ class DevFS { ...@@ -369,6 +370,7 @@ class DevFS {
bool bundleDirty: false, bool bundleDirty: false,
Set<String> fileFilter, Set<String> fileFilter,
ResidentCompiler generator, ResidentCompiler generator,
bool fullRestart: false,
}) async { }) async {
// Mark all entries as possibly deleted. // Mark all entries as possibly deleted.
for (DevFSContent content in _entries.values) { for (DevFSContent content in _entries.values) {
...@@ -441,7 +443,11 @@ class DevFS { ...@@ -441,7 +443,11 @@ class DevFS {
if (content is DevFSFileContent) if (content is DevFSFileContent)
invalidatedFiles.add(content.file.uri.toString()); invalidatedFiles.add(content.file.uri.toString());
printTrace('Compiling dart to kernel with ${invalidatedFiles.length} updated files'); printTrace('Compiling dart to kernel with ${invalidatedFiles.length} updated files');
final String compiledBinary = await generator.recompile(mainPath, invalidatedFiles); final String compiledBinary = fullRestart
? await compile(
sdkRoot: artifacts.getArtifactPath(Artifact.flutterPatchedSdkPath),
mainPath: mainPath)
: await generator.recompile(mainPath, invalidatedFiles);
if (compiledBinary != null && compiledBinary.isNotEmpty) if (compiledBinary != null && compiledBinary.isNotEmpty)
dirtyEntries.putIfAbsent( dirtyEntries.putIfAbsent(
Uri.parse(target + '.dill'), Uri.parse(target + '.dill'),
......
...@@ -331,7 +331,8 @@ class FlutterDevice { ...@@ -331,7 +331,8 @@ class FlutterDevice {
String target, String target,
AssetBundle bundle, AssetBundle bundle,
bool bundleDirty: false, bool bundleDirty: false,
Set<String> fileFilter Set<String> fileFilter,
bool fullRestart: false
}) async { }) async {
final Status devFSStatus = logger.startProgress( final Status devFSStatus = logger.startProgress(
'Syncing files to device ${device.name}...', 'Syncing files to device ${device.name}...',
...@@ -345,7 +346,8 @@ class FlutterDevice { ...@@ -345,7 +346,8 @@ class FlutterDevice {
bundle: bundle, bundle: bundle,
bundleDirty: bundleDirty, bundleDirty: bundleDirty,
fileFilter: fileFilter, fileFilter: fileFilter,
generator: generator generator: generator,
fullRestart: fullRestart
); );
} on DevFSException { } on DevFSException {
devFSStatus.cancel(); devFSStatus.cancel();
......
...@@ -241,7 +241,7 @@ class HotRunner extends ResidentRunner { ...@@ -241,7 +241,7 @@ class HotRunner extends ResidentRunner {
return devFSUris; return devFSUris;
} }
Future<bool> _updateDevFS() async { Future<bool> _updateDevFS({ bool fullRestart: false }) async {
if (!_refreshDartDependencies()) { if (!_refreshDartDependencies()) {
// Did not update DevFS because of a Dart source error. // Did not update DevFS because of a Dart source error.
return false; return false;
...@@ -261,6 +261,7 @@ class HotRunner extends ResidentRunner { ...@@ -261,6 +261,7 @@ class HotRunner extends ResidentRunner {
bundle: assetBundle, bundle: assetBundle,
bundleDirty: rebuildBundle, bundleDirty: rebuildBundle,
fileFilter: _dartDependencies, fileFilter: _dartDependencies,
fullRestart: fullRestart
); );
if (!result) if (!result)
return false; return false;
...@@ -334,15 +335,19 @@ class HotRunner extends ResidentRunner { ...@@ -334,15 +335,19 @@ class HotRunner extends ResidentRunner {
} }
final Stopwatch restartTimer = new Stopwatch()..start(); final Stopwatch restartTimer = new Stopwatch()..start();
final bool updatedDevFS = await _updateDevFS(); if (previewDart2) {
for (FlutterDevice device in flutterDevices) {
// Reset generator so that full kernel file is produced for VM to
// restart from.
if (device.generator != null)
device.generator.reset();
}
}
final bool updatedDevFS = await _updateDevFS(fullRestart: true);
if (!updatedDevFS) if (!updatedDevFS)
return new OperationResult(1, 'DevFS synchronization failed'); return new OperationResult(1, 'DevFS synchronization failed');
// Check if the isolate is paused and resume it. // Check if the isolate is paused and resume it.
for (FlutterDevice device in flutterDevices) { for (FlutterDevice device in flutterDevices) {
// VM must have accepted the kernel binary, there will be no reload
// report, so we let incremental compiler know that source code was accepted.
if (device.generator != null)
device.generator.accept();
for (FlutterView view in device.views) { for (FlutterView view in device.views) {
if (view.uiIsolate != null) { if (view.uiIsolate != null) {
// Reload the isolate. // Reload the isolate.
...@@ -357,7 +362,7 @@ class HotRunner extends ResidentRunner { ...@@ -357,7 +362,7 @@ class HotRunner extends ResidentRunner {
} }
// We are now running from source. // We are now running from source.
_runningFromSnapshot = false; _runningFromSnapshot = false;
await _launchFromDevFS(mainPath); await _launchFromDevFS(previewDart2 ? mainPath + '.dill' : mainPath);
restartTimer.stop(); restartTimer.stop();
printTrace('Restart performed in ' printTrace('Restart performed in '
'${getElapsedAsMilliseconds(restartTimer.elapsed)}.'); '${getElapsedAsMilliseconds(restartTimer.elapsed)}.');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment