Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unnecessary awaits #1982

Merged
merged 13 commits into from
Feb 23, 2023
Merged
1 change: 1 addition & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Display records as a container of fields.
- Remove test-only code from `sdk_configuration.dart`.
- Move shared test-only code to a new `test_common` package.
- Convert unnecessary async code to sync.

**Breaking changes**
- Require `sdkConfigurationProvider` in `ExpressionCompilerService`
Expand Down
1 change: 0 additions & 1 deletion dwds/debug_extension/tool/update_dev_files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// for details. 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 'dart:io';

void main() async {
Expand Down
1 change: 0 additions & 1 deletion dwds/debug_extension_mv3/tool/build_extension.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
// - For prod: dart run tool/build_extension.dart prod
// - For MV3: dart run tool/build_extension.dart --mv3

import 'dart:async';
import 'dart:convert';
import 'dart:io';

Expand Down
1 change: 0 additions & 1 deletion dwds/debug_extension_mv3/tool/update_dev_files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// for details. 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';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why the analyzer does not catch those...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, it should

https://dart.dev/tools/diagnostic-messages#unnecessary_import

@srawlins - do you know why these aren't flagged?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not offhand. I've seen unnecessary_import call out other dart:async imports.

import 'dart:io';

void main() async {
Expand Down
2 changes: 0 additions & 2 deletions dwds/debug_extension_mv3/web/background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
@JS()
library background;

import 'dart:async';

import 'package:dwds/data/debug_info.dart';
import 'package:js/js.dart';

Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/shared/batched_stream.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class BatchedStreamController<T> {
Stream<List<T>> get stream => _outputController.stream;

/// Close the controller.
Future<dynamic> close() async {
Future<dynamic> close() {
safeUnawaited(_inputController.close());
return _completer.future.then((value) => _outputController.close());
}
Expand Down
6 changes: 3 additions & 3 deletions dwds/lib/src/debugging/classes.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. 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';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like accidental change propagated by copy and paste in places:)

// BSD-style license that can be found in the LICENSE file.

import 'package:dwds/src/debugging/metadata/class.dart';
import 'package:dwds/src/loaders/strategy.dart';
Expand Down Expand Up @@ -191,7 +191,7 @@ class ClassHelper extends Domain {
});
final fieldRefs = <FieldRef>[];
final fieldDescriptors = classDescriptor['fields'] as Map<String, dynamic>;
fieldDescriptors.forEach((name, descriptor) async {
fieldDescriptors.forEach((name, descriptor) {
final classMetaData = ClassMetaData(
jsName: descriptor['classRefName'],
libraryId: descriptor['classRefLibraryId'],
Expand All @@ -214,7 +214,7 @@ class ClassHelper extends Domain {

final staticFieldDescriptors =
classDescriptor['staticFields'] as Map<String, dynamic>;
staticFieldDescriptors.forEach((name, descriptor) async {
staticFieldDescriptors.forEach((name, descriptor) {
fieldRefs.add(
FieldRef(
name: name,
Expand Down
4 changes: 2 additions & 2 deletions dwds/lib/src/debugging/debugger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ class Debugger extends Domain {
// TODO(alanknight): Can these be moved to dart_scope.dart?
final properties = await visibleProperties(debugger: this, frame: frame);
final boundVariables = await Future.wait(
properties.map((property) async => await _boundVariable(property)),
properties.map(_boundVariable),
);

// Filter out variables that do not come from dart code, such as native
Expand Down Expand Up @@ -659,7 +659,7 @@ class Debugger extends Domain {
// TODO(grouma) - In the future we should send all previously computed
// skipLists.
await _remoteDebugger.stepInto(params: {
'skipList': await _skipLists.compute(
'skipList': _skipLists.compute(
scriptId,
await _locations.locationsForUrl(url),
)
Expand Down
7 changes: 3 additions & 4 deletions dwds/lib/src/debugging/inspector.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. 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';
// BSD-style license that can be found in the LICENSE file.

import 'package:async/async.dart';
import 'package:collection/collection.dart';
Expand Down Expand Up @@ -114,9 +114,8 @@ class AppInspector implements AppInspectorInterface {
final scripts = await scriptRefs;

await DartUri.initialize();
await DartUri.recordAbsoluteUris(
libraries.map((lib) => lib.uri).whereNotNull());
await DartUri.recordAbsoluteUris(
DartUri.recordAbsoluteUris(libraries.map((lib) => lib.uri).whereNotNull());
DartUri.recordAbsoluteUris(
scripts.map((script) => script.uri).whereNotNull());

isolate.extensionRPCs?.addAll(await _getExtensionRpcs());
Expand Down
6 changes: 3 additions & 3 deletions dwds/lib/src/debugging/instance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class InstanceHelper extends Domain {
..offset = (truncated ? offset : null);
}

Future<Instance?> _closureInstanceFor(RemoteObject remoteObject) async {
Instance? _closureInstanceFor(RemoteObject remoteObject) {
final objectId = remoteObject.objectId;
if (objectId == null) return null;
final result = Instance(
Expand Down Expand Up @@ -354,8 +354,8 @@ class InstanceHelper extends Domain {
count: count, elementCount: elements.length, length: length);
final range = elements.sublist(0, rangeCount);

return Future.wait(range
.map((element) async => await _instanceRefForRemote(element.value)));
return Future.wait(
range.map((element) => _instanceRefForRemote(element.value)));
}

/// Return elements of the list from [properties].
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/debugging/libraries.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. 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';
// BSD-style license that can be found in the LICENSE file.

import 'package:collection/collection.dart';
import 'package:dwds/src/debugging/metadata/class.dart';
Expand Down
4 changes: 2 additions & 2 deletions dwds/lib/src/debugging/location.dart
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,10 @@ class Locations {
/// [module] refers to the JS path of a DDC module without the extension.
///
/// This will populate the [_sourceToLocation] and [_moduleToLocations] maps.
Future<Set<Location>> _locationsForModule(String module) async {
Future<Set<Location>> _locationsForModule(String module) {
final memoizer = _locationMemoizer.putIfAbsent(module, AsyncMemoizer.new);

return await memoizer.runOnce(() async {
return memoizer.runOnce(() async {
if (_moduleToLocations.containsKey(module)) {
return _moduleToLocations[module]!;
}
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/debugging/metadata/class.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. 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';
// BSD-style license that can be found in the LICENSE file.

import 'package:dwds/src/debugging/remote_debugger.dart';
import 'package:dwds/src/loaders/strategy.dart';
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/debugging/metadata/function.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. 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';
// BSD-style license that can be found in the LICENSE file.

import 'package:dwds/src/debugging/remote_debugger.dart';
import 'package:dwds/src/loaders/strategy.dart';
Expand Down
3 changes: 1 addition & 2 deletions dwds/lib/src/debugging/metadata/provider.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. 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';
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:convert';

import 'package:async/async.dart';
Expand Down
4 changes: 2 additions & 2 deletions dwds/lib/src/debugging/skip_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ class SkipLists {
/// https://chromedevtools.github.io/devtools-protocol/tot/Debugger/#method-stepInto
///
/// Can return a cached value.
Future<List<Map<String, dynamic>>> compute(
List<Map<String, dynamic>> compute(
String scriptId,
Set<Location> locations,
) async {
) {
if (_idToList.containsKey(scriptId)) return _idToList[scriptId]!;

final sortedLocations = locations.toList()
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/dwds_vm_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ class DwdsVmClient {
}

Future<Map<String, dynamic>> hotRestart(
ChromeProxyService chromeProxyService, VmService client) async {
ChromeProxyService chromeProxyService, VmService client) {
return _hotRestartQueue.run(() => _hotRestart(chromeProxyService, client));
}
}
Expand Down
19 changes: 9 additions & 10 deletions dwds/lib/src/handlers/dev_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,8 @@ class DevHandler {
for (var handler in _sseHandlers.values) {
handler.shutdown();
}
await Future.wait(_servicesByAppId.values.map((service) async {
await service.close();
}));
await Future.wait(
_servicesByAppId.values.map((service) => service.close()));
_servicesByAppId.clear();
}();

Expand Down Expand Up @@ -269,19 +268,19 @@ class DevHandler {
if (message is DevToolsRequest) {
await _handleDebugRequest(connection, injectedConnection);
} else if (message is IsolateExit) {
await _handleIsolateExit(connection);
_handleIsolateExit(connection);
} else if (message is IsolateStart) {
await _handleIsolateStart(connection, injectedConnection);
} else if (message is BatchedDebugEvents) {
await _servicesByAppId[connection.request.appId]
_servicesByAppId[connection.request.appId]
?.chromeProxyService
.parseBatchedDebugEvents(message);
} else if (message is DebugEvent) {
await _servicesByAppId[connection.request.appId]
_servicesByAppId[connection.request.appId]
?.chromeProxyService
.parseDebugEvent(message);
} else if (message is RegisterEvent) {
await _servicesByAppId[connection.request.appId]
_servicesByAppId[connection.request.appId]
?.chromeProxyService
.parseRegisterEvent(message);
}
Expand All @@ -302,7 +301,7 @@ class DevHandler {
}
});

safeUnawaited(injectedConnection.sink.done.then((_) async {
safeUnawaited(injectedConnection.sink.done.then((_) {
_injectedConnections.remove(injectedConnection);
final connection = appConnection;
if (connection != null) {
Expand Down Expand Up @@ -419,7 +418,7 @@ class DevHandler {
return connection;
}

Future<void> _handleIsolateExit(AppConnection appConnection) async {
void _handleIsolateExit(AppConnection appConnection) {
_servicesByAppId[appConnection.request.appId]
?.chromeProxyService
.destroyIsolate();
Expand All @@ -432,7 +431,7 @@ class DevHandler {
.createIsolate(appConnection);
}

Future<void> _listen() async {
void _listen() {
_subs.add(_injected.devHandlerPaths.listen((devHandlerPath) async {
final uri = Uri.parse(devHandlerPath);
if (!_sseHandlers.containsKey(uri.path)) {
Expand Down
8 changes: 3 additions & 5 deletions dwds/lib/src/loaders/legacy.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,21 +100,19 @@ class LegacyStrategy extends LoadStrategy {
'window.\$dartLoader.forceLoadModule("$clientScript");\n';

@override
Future<String?> moduleForServerPath(
String entrypoint, String serverPath) async =>
Future<String?> moduleForServerPath(String entrypoint, String serverPath) =>
_moduleForServerPath(metadataProviderFor(entrypoint), serverPath);

@override
Future<Map<String, ModuleInfo>> moduleInfoForEntrypoint(String entrypoint) =>
_moduleInfoForProvider(metadataProviderFor(entrypoint));

@override
Future<String?> serverPathForModule(String entrypoint, String module) async =>
Future<String?> serverPathForModule(String entrypoint, String module) =>
_serverPathForModule(metadataProviderFor(entrypoint), module);

@override
Future<String?> sourceMapPathForModule(
String entrypoint, String module) async =>
Future<String?> sourceMapPathForModule(String entrypoint, String module) =>
_sourceMapPathForModule(metadataProviderFor(entrypoint), module);

@override
Expand Down
14 changes: 7 additions & 7 deletions dwds/lib/src/readers/frontend_server_asset_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,22 @@ class FrontendServerAssetReader implements AssetReader {
/// Updates the internal caches by reading the Frontend Server output files.
///
/// Will only read the incremental files on additional calls.
Future<void> updateCaches() async {
void updateCaches() {
if (!_haveReadOriginals) {
await _updateCaches(_mapOriginal, _jsonOriginal);
_updateCaches(_mapOriginal, _jsonOriginal);
_haveReadOriginals = true;
} else {
await _updateCaches(_mapIncremental, _jsonIncremental);
_updateCaches(_mapIncremental, _jsonIncremental);
}
}

Future<void> _updateCaches(File map, File json) async {
if (!(await map.exists() && await json.exists())) {
void _updateCaches(File map, File json) {
if (!(map.existsSync() && json.existsSync())) {
throw StateError('$map and $json do not exist.');
}
final sourceContents = await map.readAsBytes();
final sourceContents = map.readAsBytesSync();
final sourceInfo =
jsonDecode(await json.readAsString()) as Map<String, dynamic>;
jsonDecode(json.readAsStringSync()) as Map<String, dynamic>;
for (var key in sourceInfo.keys) {
final info = sourceInfo[key];
_mapContents[key] = utf8.decode(sourceContents
Expand Down
1 change: 0 additions & 1 deletion dwds/lib/src/readers/proxy_server_asset_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// for details. 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 'dart:convert';
import 'dart:io';

Expand Down
1 change: 0 additions & 1 deletion dwds/lib/src/servers/extension_backend.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// for details. 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 'dart:io';

import 'package:async/async.dart';
Expand Down
2 changes: 0 additions & 2 deletions dwds/lib/src/services/app_debug_services.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// for details. 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:dwds/src/dwds_vm_client.dart';
import 'package:dwds/src/events.dart';
import 'package:dwds/src/services/chrome_proxy_service.dart'
Expand Down
2 changes: 1 addition & 1 deletion dwds/lib/src/services/batched_expression_evaluator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class BatchedExpressionEvaluator extends ExpressionEvaluator {
return request.completer.future;
}

Future<void> _processRequest(List<EvaluateRequest> requests) async {
void _processRequest(List<EvaluateRequest> requests) {
String? libraryUri;
String? isolateId;
Map<String, String>? scope;
Expand Down
Loading