Remove the fast reassemble / single widget reload feature (#132255)

Fixes https://github.com/flutter/flutter/issues/132157
This commit is contained in:
Ian Hickson
2023-08-10 14:48:06 -07:00
committed by GitHub
parent 6cf5dbe371
commit a2e2574941
25 changed files with 105 additions and 615 deletions

View File

@@ -118,14 +118,14 @@ void main() {
ProcessManager: () => FakeProcessManager.any(),
});
testWithoutContext('--flutter-widget-cache and --enable-experiment are removed from getDefaultCachedKernelPath hash', () {
testWithoutContext('--enable-experiment is removed from getDefaultCachedKernelPath hash', () {
final FileSystem fileSystem = MemoryFileSystem.test();
final Config config = Config.test();
expect(getDefaultCachedKernelPath(
trackWidgetCreation: true,
dartDefines: <String>[],
extraFrontEndOptions: <String>['--enable-experiment=foo', '--flutter-widget-cache'],
extraFrontEndOptions: <String>['--enable-experiment=foo'],
fileSystem: fileSystem,
config: config,
), 'build/cache.dill.track.dill');
@@ -133,7 +133,7 @@ void main() {
expect(getDefaultCachedKernelPath(
trackWidgetCreation: true,
dartDefines: <String>['foo=bar'],
extraFrontEndOptions: <String>['--enable-experiment=foo', '--flutter-widget-cache'],
extraFrontEndOptions: <String>['--enable-experiment=foo'],
fileSystem: fileSystem,
config: config,
), 'build/06ad47d8e64bd28de537b62ff85357c4.cache.dill.track.dill');
@@ -141,7 +141,7 @@ void main() {
expect(getDefaultCachedKernelPath(
trackWidgetCreation: false,
dartDefines: <String>[],
extraFrontEndOptions: <String>['--enable-experiment=foo', '--flutter-widget-cache'],
extraFrontEndOptions: <String>['--enable-experiment=foo'],
fileSystem: fileSystem,
config: config,
), 'build/cache.dill');
@@ -149,7 +149,7 @@ void main() {
expect(getDefaultCachedKernelPath(
trackWidgetCreation: true,
dartDefines: <String>[],
extraFrontEndOptions: <String>['--enable-experiment=foo', '--flutter-widget-cache', '--foo=bar'],
extraFrontEndOptions: <String>['--enable-experiment=foo', '--foo=bar'],
fileSystem: fileSystem,
config: config,
), 'build/95b595cca01caa5f0ca0a690339dd7f6.cache.dill.track.dill');

View File

@@ -178,7 +178,6 @@ void main() {
Map<FlutterDevice?, List<FlutterView>> viewCache,
void Function(String message)? onSlow,
String reloadMessage,
String? fastReassembleClassName,
) async => ReassembleResult(
<FlutterView?, FlutterVmService?>{null: null},
false,
@@ -296,7 +295,6 @@ void main() {
hotEventSdkName: 'Tester',
hotEventEmulator: false,
hotEventFullRestart: true,
fastReassemble: false,
hotEventOverallTimeInMs: 64000,
hotEventSyncedBytes: 4,
hotEventInvalidatedSourcesCount: 2,
@@ -379,7 +377,6 @@ void main() {
Map<FlutterDevice?, List<FlutterView>> viewCache,
void Function(String message)? onSlow,
String reloadMessage,
String? fastReassembleClassName,
) async => ReassembleResult(
<FlutterView?, FlutterVmService?>{null: null},
false,
@@ -402,7 +399,6 @@ void main() {
hotEventSdkName: 'Tester',
hotEventEmulator: false,
hotEventFullRestart: false,
fastReassemble: false,
hotEventCompileTimeInMs: 16000,
hotEventFindInvalidatedTimeInMs: 64000,
hotEventScannedSourcesCount: 16,

View File

@@ -25,7 +25,6 @@ import 'package:flutter_tools/src/convert.dart';
import 'package:flutter_tools/src/devfs.dart';
import 'package:flutter_tools/src/device.dart';
import 'package:flutter_tools/src/device_port_forwarder.dart';
import 'package:flutter_tools/src/features.dart';
import 'package:flutter_tools/src/globals.dart' as globals;
import 'package:flutter_tools/src/project.dart';
import 'package:flutter_tools/src/reporting/reporting.dart';
@@ -424,7 +423,6 @@ void main() {
hotEventSdkName: 'Android',
hotEventEmulator: false,
hotEventFullRestart: false,
fastReassemble: false,
)),
));
expect(fakeVmServiceHost?.hasRemainingExpectations, false);
@@ -480,7 +478,6 @@ void main() {
hotEventSdkName: 'Android',
hotEventEmulator: false,
hotEventFullRestart: false,
fastReassemble: false,
)),
));
expect(fakeVmServiceHost?.hasRemainingExpectations, false);
@@ -527,7 +524,6 @@ void main() {
hotEventSdkName: 'Android',
hotEventEmulator: false,
hotEventFullRestart: false,
fastReassemble: false,
)),
));
expect(fakeVmServiceHost?.hasRemainingExpectations, false);
@@ -766,96 +762,6 @@ void main() {
Usage: () => TestUsage(),
}));
testUsingContext('ResidentRunner can perform fast reassemble', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
listViews,
FakeVmServiceRequest(
method: 'getVM',
jsonResponse: fakeVM.toJson(),
),
listViews,
listViews,
FakeVmServiceRequest(
method: 'getVM',
jsonResponse: fakeVM.toJson(),
),
const FakeVmServiceRequest(
method: kReloadSourcesServiceName,
args: <String, Object>{
'isolateId': '1',
'pause': false,
'rootLibUri': 'main.dart.incremental.dill',
},
jsonResponse: <String, Object>{
'type': 'ReloadReport',
'success': true,
'details': <String, Object>{
'loadedLibraryCount': 1,
},
},
),
FakeVmServiceRequest(
method: 'getIsolatePauseEvent',
args: <String, Object>{
'isolateId': '1',
},
jsonResponse: fakeUnpausedEvent.toJson(),
),
FakeVmServiceRequest(
method: 'ext.flutter.fastReassemble',
args: <String, Object?>{
'isolateId': fakeUnpausedIsolate.id,
'className': 'FOO',
},
),
]);
final FakeDelegateFlutterDevice flutterDevice = FakeDelegateFlutterDevice(
device,
BuildInfo.debug,
FakeResidentCompiler(),
devFS,
)..vmService = fakeVmServiceHost!.vmService;
residentRunner = HotRunner(
<FlutterDevice>[
flutterDevice,
],
stayResident: false,
debuggingOptions: DebuggingOptions.enabled(BuildInfo.debug),
target: 'main.dart',
devtoolsHandler: createNoOpHandler,
);
devFS.nextUpdateReport = UpdateFSReport(
success: true,
fastReassembleClassName: 'FOO',
invalidatedSourcesCount: 1,
);
final Completer<DebugConnectionInfo> futureConnectionInfo = Completer<DebugConnectionInfo>.sync();
final Completer<void> futureAppStart = Completer<void>.sync();
unawaited(residentRunner.attach(
appStartedCompleter: futureAppStart,
connectionInfoCompleter: futureConnectionInfo,
enableDevTools: true,
));
await futureAppStart.future;
final OperationResult result = await residentRunner.restart();
expect(result.fatal, false);
expect(result.code, 0);
final TestUsageEvent event = (globals.flutterUsage as TestUsage).events.first;
expect(event.category, 'hot');
expect(event.parameter, 'reload');
expect(event.parameters?.fastReassemble, true);
}, overrides: <Type, Generator>{
FileSystem: () => MemoryFileSystem.test(),
Platform: () => FakePlatform(),
ProjectFileInvalidator: () => FakeProjectFileInvalidator(),
Usage: () => TestUsage(),
FeatureFlags: () => TestFeatureFlags(isSingleWidgetReloadEnabled: true),
}));
testUsingContext('ResidentRunner reports hot reload time details', () => testbed.run(() async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[
listViews,
@@ -893,10 +799,9 @@ void main() {
jsonResponse: fakeUnpausedEvent.toJson(),
),
FakeVmServiceRequest(
method: 'ext.flutter.fastReassemble',
method: 'ext.flutter.reassemble',
args: <String, Object?>{
'isolateId': fakeUnpausedIsolate.id,
'className': 'FOO',
},
),
]);
@@ -917,7 +822,6 @@ void main() {
);
devFS.nextUpdateReport = UpdateFSReport(
success: true,
fastReassembleClassName: 'FOO',
invalidatedSourcesCount: 1,
);
@@ -942,7 +846,6 @@ void main() {
Platform: () => FakePlatform(),
ProjectFileInvalidator: () => FakeProjectFileInvalidator(),
Usage: () => TestUsage(),
FeatureFlags: () => TestFeatureFlags(isSingleWidgetReloadEnabled: true),
}));
testUsingContext('ResidentRunner can send target platform to analytics from full restart', () => testbed.run(() async {
@@ -1225,7 +1128,6 @@ void main() {
hotEventSdkName: 'Android',
hotEventEmulator: false,
hotEventFullRestart: true,
fastReassemble: false,
)),
));
expect(fakeVmServiceHost?.hasRemainingExpectations, false);
@@ -1984,31 +1886,7 @@ flutter:
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('FlutterDevice passes flutter-widget-cache flag when feature is enabled', () async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
final FakeDevice device = FakeDevice();
final DefaultResidentCompiler? residentCompiler = (await FlutterDevice.create(
device,
buildInfo: const BuildInfo(
BuildMode.debug,
'',
treeShakeIcons: false,
extraFrontEndOptions: <String>[],
),
target: null, platform: FakePlatform(),
)).generator as DefaultResidentCompiler?;
expect(residentCompiler!.extraFrontEndOptions,
contains('--flutter-widget-cache'));
}, overrides: <Type, Generator>{
Artifacts: () => Artifacts.test(),
FileSystem: () => MemoryFileSystem.test(),
ProcessManager: () => FakeProcessManager.any(),
FeatureFlags: () => TestFeatureFlags(isSingleWidgetReloadEnabled: true),
});
testUsingContext('FlutterDevice passes alternative-invalidation-strategy flag', () async {
testUsingContext('FlutterDevice passes alternative-invalidation-strategy flag', () async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
final FakeDevice device = FakeDevice();
@@ -2032,7 +1910,7 @@ flutter:
ProcessManager: () => FakeProcessManager.any(),
});
testUsingContext('FlutterDevice passes initializeFromDill parameter if specified', () async {
testUsingContext('FlutterDevice passes initializeFromDill parameter if specified', () async {
fakeVmServiceHost = FakeVmServiceHost(requests: <VmServiceExpectation>[]);
final FakeDevice device = FakeDevice();

View File

@@ -1,63 +0,0 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'package:flutter_tools/src/base/file_system.dart';
import '../src/common.dart';
import 'test_data/single_widget_reload_project.dart';
import 'test_driver.dart';
import 'test_utils.dart';
void main() {
late Directory tempDir;
final SingleWidgetReloadProject project = SingleWidgetReloadProject();
late FlutterRunTestDriver flutter;
setUp(() async {
tempDir = createResolvedTempDirectorySync('hot_reload_test.');
await project.setUpIn(tempDir);
flutter = FlutterRunTestDriver(tempDir);
});
tearDown(() async {
await flutter.stop();
tryToDelete(tempDir);
});
testWithoutContext('newly added code executes during hot reload with single widget reloads, but only invalidated widget', () async {
final StringBuffer stdout = StringBuffer();
final StreamSubscription<String> subscription = flutter.stdout.listen(stdout.writeln);
await flutter.run(singleWidgetReloads: true);
project.uncommentHotReloadPrint();
try {
await flutter.hotReload();
expect(stdout.toString(), allOf(
contains('(((TICK 1)))'),
contains('(((((RELOAD WORKED)))))'),
// Does not invalidate parent widget, so second tick is not output.
isNot(contains('(((TICK 2)))'),
)));
} finally {
await subscription.cancel();
}
});
testWithoutContext('changes outside of the class body triggers a full reload', () async {
final StringBuffer stdout = StringBuffer();
final StreamSubscription<String> subscription = flutter.stdout.listen(stdout.writeln);
await flutter.run(singleWidgetReloads: true);
project.modifyFunction();
try {
await flutter.hotReload();
expect(stdout.toString(), allOf(
contains('(((TICK 1)))'),
contains('(((TICK 2)))'),
));
} finally {
await subscription.cancel();
}
});
}

View File

@@ -1,94 +0,0 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import '../test_utils.dart';
import 'project.dart';
class SingleWidgetReloadProject extends Project {
@override
final String pubspec = '''
name: test
environment:
sdk: '>=3.0.0-0 <4.0.0'
dependencies:
flutter:
sdk: flutter
''';
@override
final String main = r'''
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
final ByteData message = const StringCodec().encodeMessage('AppLifecycleState.resumed')!;
await ServicesBinding.instance!.defaultBinaryMessenger.handlePlatformMessage('flutter/lifecycle', message, (_) { });
runApp(MyApp());
}
int count = 1;
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
// PARENT WIDGET
print('((((TICK $count))))');
count += 1;
return MaterialApp(
title: 'Flutter Demo',
home: SecondWidget(),
);
}
}
class SecondWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
// Do not remove the next line, it's uncommented by a test to verify that
// hot reloading worked:
// printHotReloadWorked();
return Container();
}
}
void printHotReloadWorked() {
// The call to this function is uncommented by a test to verify that hot
// reloading worked.
print('(((((RELOAD WORKED)))))');
}
''';
Uri get parentWidgetUri => mainDart;
int get parentWidgetLine => lineContaining(main, '// PARENT WIDGET');
void uncommentHotReloadPrint() {
final String newMainContents = main.replaceAll(
'// printHotReloadWorked();',
'printHotReloadWorked();',
);
writeFile(
fileSystem.path.join(dir.path, 'lib', 'main.dart'),
newMainContents,
writeFutureModifiedDate: true,
);
}
void modifyFunction() {
final String newMainContents = main.replaceAll(
'(((((RELOAD WORKED)))))',
'(((((RELOAD WORKED 2)))))',
);
writeFile(
fileSystem.path.join(dir.path, 'lib', 'main.dart'),
newMainContents,
writeFutureModifiedDate: true,
);
}
}

View File

@@ -90,7 +90,6 @@ abstract class FlutterTestDriver {
List<String> arguments, {
String? script,
bool withDebugger = false,
bool singleWidgetReloads = false,
}) async {
final String flutterBin = fileSystem.path.join(getFlutterRoot(), 'bin', 'flutter');
if (withDebugger) {
@@ -114,8 +113,6 @@ abstract class FlutterTestDriver {
environment: <String, String>{
'FLUTTER_TEST': 'true',
'FLUTTER_WEB': 'true',
if (singleWidgetReloads)
'FLUTTER_SINGLE_WIDGET_RELOAD': 'true',
},
);
@@ -511,7 +508,6 @@ class FlutterRunTestDriver extends FlutterTestDriver {
bool chrome = false,
bool expressionEvaluation = true,
bool structuredErrors = false,
bool singleWidgetReloads = false,
bool serveObservatory = false,
String? script,
List<String>? additionalCommandArgs,
@@ -542,7 +538,6 @@ class FlutterRunTestDriver extends FlutterTestDriver {
startPaused: startPaused,
pauseOnExceptions: pauseOnExceptions,
script: script,
singleWidgetReloads: singleWidgetReloads,
);
}
@@ -551,7 +546,6 @@ class FlutterRunTestDriver extends FlutterTestDriver {
bool withDebugger = false,
bool startPaused = false,
bool pauseOnExceptions = false,
bool singleWidgetReloads = false,
bool serveObservatory = false,
List<String>? additionalCommandArgs,
}) async {
@@ -573,7 +567,6 @@ class FlutterRunTestDriver extends FlutterTestDriver {
withDebugger: withDebugger,
startPaused: startPaused,
pauseOnExceptions: pauseOnExceptions,
singleWidgetReloads: singleWidgetReloads,
attachPort: port,
);
}
@@ -585,7 +578,6 @@ class FlutterRunTestDriver extends FlutterTestDriver {
bool withDebugger = false,
bool startPaused = false,
bool pauseOnExceptions = false,
bool singleWidgetReloads = false,
int? attachPort,
}) async {
assert(!startPaused || withDebugger);
@@ -593,7 +585,6 @@ class FlutterRunTestDriver extends FlutterTestDriver {
args,
script: script,
withDebugger: withDebugger,
singleWidgetReloads: singleWidgetReloads,
);
final Completer<void> prematureExitGuard = Completer<void>();
@@ -806,13 +797,11 @@ class FlutterTestTestDriver extends FlutterTestDriver {
bool withDebugger = false,
bool pauseOnExceptions = false,
Future<void> Function()? beforeStart,
bool singleWidgetReloads = false,
}) async {
await super._setupProcess(
args,
script: script,
withDebugger: withDebugger,
singleWidgetReloads: singleWidgetReloads,
);
// Stash the PID so that we can terminate the VM more reliably than using

View File

@@ -443,7 +443,6 @@ class TestFeatureFlags implements FeatureFlags {
this.isMacOSEnabled = false,
this.isWebEnabled = false,
this.isWindowsEnabled = false,
this.isSingleWidgetReloadEnabled = false,
this.isAndroidEnabled = true,
this.isIOSEnabled = true,
this.isFuchsiaEnabled = false,
@@ -463,9 +462,6 @@ class TestFeatureFlags implements FeatureFlags {
@override
final bool isWindowsEnabled;
@override
final bool isSingleWidgetReloadEnabled;
@override
final bool isAndroidEnabled;
@@ -492,8 +488,6 @@ class TestFeatureFlags implements FeatureFlags {
return isMacOSEnabled;
case flutterWindowsDesktopFeature:
return isWindowsEnabled;
case singleWidgetReload:
return isSingleWidgetReloadEnabled;
case flutterAndroidFeature:
return isAndroidEnabled;
case flutterIOSFeature: