mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 03:07:49 +00:00
[CFE] Don't mark procedures as async when not using await
This CL removes async markers where await wasn't used. In a few cases this also meant the ability to make the procedure not return a future at all. Also - at least on the VM with my benchmark run on my PC - returning new Future.value(whatever) in a non-async procedure is faster than returning whatever in an async procedure. TEST=CI and existing tests. Change-Id: I4ba888313c87de76bb0ca02c19eb1ab45f168a85 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213480 Commit-Queue: Jens Johansen <jensj@google.com> Reviewed-by: Johnni Winther <johnniwinther@google.com>
This commit is contained in:
parent
af18bfacc1
commit
211ad9acb1
|
@ -266,7 +266,7 @@ Future<CompilerResult> _compile(List<String> args,
|
|||
var additionalDills = summaryModules.keys.toList();
|
||||
|
||||
if (!useIncrementalCompiler) {
|
||||
compilerState = await fe.initializeCompiler(
|
||||
compilerState = fe.initializeCompiler(
|
||||
oldCompilerState,
|
||||
compileSdk,
|
||||
sourcePathToUri(getSdkPath()),
|
||||
|
|
|
@ -676,8 +676,8 @@ const nullCheck = const _NullCheck();
|
|||
var mainUri = Uri.file('/memory/test.dart');
|
||||
_fileSystem.entityForUri(mainUri).writeAsStringSync(code);
|
||||
var oldCompilerState = _compilerState;
|
||||
_compilerState = await fe.initializeCompiler(oldCompilerState, false, null,
|
||||
sdkUri, packagesUri, null, [], DevCompilerTarget(TargetFlags()),
|
||||
_compilerState = fe.initializeCompiler(oldCompilerState, false, null, sdkUri,
|
||||
packagesUri, null, [], DevCompilerTarget(TargetFlags()),
|
||||
fileSystem: _fileSystem,
|
||||
explicitExperimentalFlags: const {},
|
||||
environmentDefines: const {},
|
||||
|
|
|
@ -80,21 +80,23 @@ class MemoryFileSystemEntity implements FileSystemEntity {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<bool> exists() async {
|
||||
return _fileSystem._files[uri] != null ||
|
||||
_fileSystem._directories.contains(uri);
|
||||
Future<bool> exists() {
|
||||
return new Future.value(_fileSystem._files[uri] != null ||
|
||||
_fileSystem._directories.contains(uri));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> existsAsyncIfPossible() => exists();
|
||||
|
||||
@override
|
||||
Future<List<int>> readAsBytes() async {
|
||||
Future<List<int>> readAsBytes() {
|
||||
Uint8List? contents = _fileSystem._files[uri];
|
||||
if (contents == null) {
|
||||
throw new FileSystemException(uri, 'File $uri does not exist.');
|
||||
return new Future.error(
|
||||
new FileSystemException(uri, 'File $uri does not exist.'),
|
||||
StackTrace.current);
|
||||
}
|
||||
return contents;
|
||||
return new Future.value(contents);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -52,15 +52,15 @@ class _IoFileSystemEntity implements FileSystemEntity {
|
|||
other is _IoFileSystemEntity && other.uri == uri;
|
||||
|
||||
@override
|
||||
Future<bool> exists() async {
|
||||
Future<bool> exists() {
|
||||
if (new io.File.fromUri(uri).existsSync()) {
|
||||
return true;
|
||||
return new Future.value(true);
|
||||
}
|
||||
if (io.FileSystemEntity.isDirectorySync(uri.toFilePath())) {
|
||||
return true;
|
||||
return new Future.value(true);
|
||||
}
|
||||
// TODO(CFE-team): What about [Link]s?
|
||||
return false;
|
||||
return new Future.value(false);
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -76,12 +76,13 @@ class _IoFileSystemEntity implements FileSystemEntity {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<List<int>> readAsBytes() async {
|
||||
Future<List<int>> readAsBytes() {
|
||||
try {
|
||||
CompilerContext.recordDependency(uri);
|
||||
return new io.File.fromUri(uri).readAsBytesSync();
|
||||
return new Future.value(new io.File.fromUri(uri).readAsBytesSync());
|
||||
} on io.FileSystemException catch (exception) {
|
||||
throw _toFileSystemException(exception);
|
||||
return new Future.error(
|
||||
_toFileSystemException(exception), StackTrace.current);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,13 +136,13 @@ class DataFileSystemEntity implements FileSystemEntity {
|
|||
other is DataFileSystemEntity && other.uri == uri;
|
||||
|
||||
@override
|
||||
Future<bool> exists() async {
|
||||
return true;
|
||||
Future<bool> exists() {
|
||||
return new Future.value(true);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<int>> readAsBytes() async {
|
||||
return uri.data!.contentAsBytes();
|
||||
Future<List<int>> readAsBytes() {
|
||||
return new Future.value(uri.data!.contentAsBytes());
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -151,7 +152,7 @@ class DataFileSystemEntity implements FileSystemEntity {
|
|||
Future<List<int>> readAsBytesAsyncIfPossible() => readAsBytes();
|
||||
|
||||
@override
|
||||
Future<String> readAsString() async {
|
||||
return uri.data!.contentAsString();
|
||||
Future<String> readAsString() {
|
||||
return new Future.value(uri.data!.contentAsString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ Future<InitializedCompilerState> initializeIncrementalCompiler(
|
|||
Map<String, String> environmentDefines,
|
||||
{bool trackNeededDillLibraries: false,
|
||||
bool verbose: false,
|
||||
NnbdMode nnbdMode: NnbdMode.Weak}) async {
|
||||
NnbdMode nnbdMode: NnbdMode.Weak}) {
|
||||
List<Component> outputLoadedAdditionalDills =
|
||||
new List<Component>.filled(additionalDills.length, dummyComponent);
|
||||
Map<ExperimentalFlag, bool> experimentalFlags = parseExperimentalFlags(
|
||||
|
@ -98,7 +98,7 @@ Future<InitializedCompilerState> initializeIncrementalCompiler(
|
|||
nnbdMode: nnbdMode);
|
||||
}
|
||||
|
||||
Future<InitializedCompilerState> initializeCompiler(
|
||||
InitializedCompilerState initializeCompiler(
|
||||
InitializedCompilerState? oldState,
|
||||
Uri sdkSummary,
|
||||
Uri librariesSpecificationUri,
|
||||
|
@ -110,7 +110,7 @@ Future<InitializedCompilerState> initializeCompiler(
|
|||
Map<String, String> environmentDefines, {
|
||||
bool verbose: false,
|
||||
NnbdMode nnbdMode: NnbdMode.Weak,
|
||||
}) async {
|
||||
}) {
|
||||
// TODO(sigmund): use incremental compiler when it supports our use case.
|
||||
// Note: it is common for the summary worker to invoke the compiler with the
|
||||
// same input summary URIs, but with different contents, so we'd need to be
|
||||
|
|
|
@ -102,7 +102,7 @@ class DdcResult {
|
|||
}
|
||||
}
|
||||
|
||||
Future<InitializedCompilerState> initializeCompiler(
|
||||
InitializedCompilerState initializeCompiler(
|
||||
InitializedCompilerState? oldState,
|
||||
bool compileSdk,
|
||||
Uri sdkRoot,
|
||||
|
@ -114,7 +114,7 @@ Future<InitializedCompilerState> initializeCompiler(
|
|||
{FileSystem? fileSystem,
|
||||
Map<ExperimentalFlag, bool>? explicitExperimentalFlags,
|
||||
Map<String, String>? environmentDefines,
|
||||
required NnbdMode nnbdMode}) async {
|
||||
required NnbdMode nnbdMode}) {
|
||||
// ignore: unnecessary_null_comparison
|
||||
assert(nnbdMode != null, "No NnbdMode provided.");
|
||||
additionalDills.sort((a, b) => a.toString().compareTo(b.toString()));
|
||||
|
@ -173,7 +173,7 @@ Future<InitializedCompilerState> initializeIncrementalCompiler(
|
|||
required Map<ExperimentalFlag, bool> explicitExperimentalFlags,
|
||||
required Map<String, String> environmentDefines,
|
||||
bool trackNeededDillLibraries: false,
|
||||
required NnbdMode nnbdMode}) async {
|
||||
required NnbdMode nnbdMode}) {
|
||||
return modular.initializeIncrementalCompiler(
|
||||
oldState,
|
||||
tags,
|
||||
|
|
|
@ -85,12 +85,13 @@ class DillLoader extends Loader {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<Null> buildOutline(DillLibraryBuilder builder) async {
|
||||
Future<Null> buildOutline(DillLibraryBuilder builder) {
|
||||
// ignore: unnecessary_null_comparison
|
||||
if (builder.library == null) {
|
||||
unhandled("null", "builder.library", 0, builder.fileUri);
|
||||
}
|
||||
builder.markAsReadyToBuild();
|
||||
return new Future.value(null);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
|
@ -77,7 +77,9 @@ abstract class DataComputer<T> {
|
|||
void setup() {}
|
||||
|
||||
// Called to allow for (awaited) inspection of the compilation result.
|
||||
Future<void> inspectComponent(Component component) async {}
|
||||
Future<void> inspectComponent(Component component) {
|
||||
return new Future.value(null);
|
||||
}
|
||||
|
||||
/// Function that computes a data mapping for [member].
|
||||
///
|
||||
|
|
138
pkg/front_end/test/async_but_no_await_git_test.dart
Normal file
138
pkg/front_end/test/async_but_no_await_git_test.dart
Normal file
|
@ -0,0 +1,138 @@
|
|||
// Copyright (c) 2021, 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:io';
|
||||
|
||||
import 'package:_fe_analyzer_shared/src/messages/severity.dart';
|
||||
import 'package:front_end/src/api_prototype/compiler_options.dart' as api;
|
||||
import 'package:front_end/src/base/processed_options.dart';
|
||||
import 'package:front_end/src/compute_platform_binaries_location.dart'
|
||||
show computePlatformBinariesLocation;
|
||||
import 'package:front_end/src/fasta/compiler_context.dart';
|
||||
import 'package:front_end/src/fasta/incremental_compiler.dart';
|
||||
import 'package:kernel/class_hierarchy.dart';
|
||||
import 'package:kernel/core_types.dart';
|
||||
import 'package:kernel/kernel.dart';
|
||||
import 'package:kernel/reference_from_index.dart';
|
||||
import 'package:kernel/target/changed_structure_notifier.dart';
|
||||
import 'package:kernel/target/targets.dart';
|
||||
import "package:vm/target/vm.dart" show VmTarget;
|
||||
|
||||
import 'testing_utils.dart' show getGitFiles;
|
||||
import "utils/io_utils.dart";
|
||||
|
||||
final Uri repoDir = computeRepoDirUri();
|
||||
|
||||
Set<Uri> libUris = {};
|
||||
|
||||
Future<void> main(List<String> args) async {
|
||||
api.CompilerOptions compilerOptions = getOptions();
|
||||
|
||||
Uri dotPackagesUri = repoDir.resolve(".packages");
|
||||
if (!new File.fromUri(dotPackagesUri).existsSync()) {
|
||||
throw "Couldn't find .packages";
|
||||
}
|
||||
compilerOptions.packagesFileUri = dotPackagesUri;
|
||||
|
||||
ProcessedOptions options = new ProcessedOptions(options: compilerOptions);
|
||||
|
||||
libUris.add(repoDir.resolve("pkg/front_end/lib/"));
|
||||
libUris.add(repoDir.resolve("pkg/front_end/test/fasta/"));
|
||||
libUris.add(repoDir.resolve("pkg/front_end/tool/"));
|
||||
|
||||
for (Uri uri in libUris) {
|
||||
Set<Uri> gitFiles = await getGitFiles(uri);
|
||||
List<FileSystemEntity> entities =
|
||||
new Directory.fromUri(uri).listSync(recursive: true);
|
||||
for (FileSystemEntity entity in entities) {
|
||||
if (entity is File &&
|
||||
entity.path.endsWith(".dart") &&
|
||||
gitFiles.contains(entity.uri)) {
|
||||
options.inputs.add(entity.uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Stopwatch stopwatch = new Stopwatch()..start();
|
||||
|
||||
IncrementalCompiler compiler =
|
||||
new IncrementalCompiler(new CompilerContext(options));
|
||||
Component component = await compiler.computeDelta();
|
||||
|
||||
component.accept(new AsyncNoAwaitVisitor());
|
||||
|
||||
print("Done in ${stopwatch.elapsedMilliseconds} ms. "
|
||||
"Found $errorCount errors.");
|
||||
if (errorCount > 0) {
|
||||
throw "Found $errorCount errors.";
|
||||
}
|
||||
}
|
||||
|
||||
class AsyncNoAwaitVisitor extends RecursiveVisitor {
|
||||
bool sawAwait = false;
|
||||
|
||||
@override
|
||||
void visitProcedure(Procedure node) {
|
||||
if (node.function.asyncMarker != AsyncMarker.Async) return;
|
||||
sawAwait = false;
|
||||
defaultMember(node);
|
||||
if (!sawAwait) {
|
||||
Location? location = node.location;
|
||||
if (location?.file.path.contains("/pkg/front_end/") == true) {
|
||||
print("$node (${node.location}) is async "
|
||||
"but doesn't use 'await' anywhere.");
|
||||
errorCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void visitAwaitExpression(AwaitExpression node) {
|
||||
sawAwait = true;
|
||||
}
|
||||
}
|
||||
|
||||
int errorCount = 0;
|
||||
|
||||
api.CompilerOptions getOptions() {
|
||||
// Compile sdk because when this is run from a lint it uses the checked-in sdk
|
||||
// and we might not have a suitable compiled platform.dill file.
|
||||
Uri sdkRoot = computePlatformBinariesLocation(forceBuildDir: true);
|
||||
api.CompilerOptions options = new api.CompilerOptions()
|
||||
..sdkRoot = sdkRoot
|
||||
..compileSdk = true
|
||||
..target = new TestVmTarget(new TargetFlags())
|
||||
..librariesSpecificationUri = repoDir.resolve("sdk/lib/libraries.json")
|
||||
..omitPlatform = true
|
||||
..onDiagnostic = (api.DiagnosticMessage message) {
|
||||
if (message.severity == Severity.error) {
|
||||
print(message.plainTextFormatted.join('\n'));
|
||||
errorCount++;
|
||||
exitCode = 1;
|
||||
}
|
||||
}
|
||||
..environmentDefines = const {};
|
||||
return options;
|
||||
}
|
||||
|
||||
class TestVmTarget extends VmTarget with NoTransformationsMixin {
|
||||
TestVmTarget(TargetFlags flags) : super(flags);
|
||||
}
|
||||
|
||||
mixin NoTransformationsMixin on Target {
|
||||
@override
|
||||
void performModularTransformationsOnLibraries(
|
||||
Component component,
|
||||
CoreTypes coreTypes,
|
||||
ClassHierarchy hierarchy,
|
||||
List<Library> libraries,
|
||||
Map<String, String>? environmentDefines,
|
||||
DiagnosticReporter diagnosticReporter,
|
||||
ReferenceFromIndex? referenceFromIndex,
|
||||
{void Function(String msg)? logger,
|
||||
ChangedStructureNotifier? changedStructureNotifier}) {
|
||||
// We don't want to do the transformations because we need to await
|
||||
// statements.
|
||||
}
|
||||
}
|
|
@ -741,11 +741,11 @@ class Validate extends Step<MessageTestDescription, Example, MessageTestSuite> {
|
|||
|
||||
@override
|
||||
Future<Result<Example>> run(
|
||||
MessageTestDescription description, MessageTestSuite suite) async {
|
||||
MessageTestDescription description, MessageTestSuite suite) {
|
||||
if (description.problem != null) {
|
||||
return fail(null, description.problem);
|
||||
return new Future.value(fail(null, description.problem));
|
||||
} else {
|
||||
return pass(description.example);
|
||||
return new Future.value(pass(description.example));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -836,10 +836,10 @@ class Compile extends Step<Example, Null, MessageTestSuite> {
|
|||
}
|
||||
|
||||
Future<MessageTestSuite> createContext(
|
||||
Chain suite, Map<String, String> environment) async {
|
||||
Chain suite, Map<String, String> environment) {
|
||||
final bool fastOnly = environment["fastOnly"] == "true";
|
||||
final bool interactive = environment["interactive"] == "true";
|
||||
return new MessageTestSuite(fastOnly, interactive);
|
||||
return new Future.value(new MessageTestSuite(fastOnly, interactive));
|
||||
}
|
||||
|
||||
String relativize(Uri uri) {
|
||||
|
|
|
@ -12,8 +12,8 @@ import 'package:testing/testing.dart'
|
|||
import '../../utils/scanner_chain.dart' show Read, Scan, ScannedFile;
|
||||
|
||||
Future<ChainContext> createContext(
|
||||
Chain suite, Map<String, String> environment) async {
|
||||
return new ScannerContext();
|
||||
Chain suite, Map<String, String> environment) {
|
||||
return new Future.value(new ScannerContext());
|
||||
}
|
||||
|
||||
class ScannerContext extends ChainContext {
|
||||
|
@ -32,17 +32,17 @@ class Parse extends Step<ScannedFile, Null, ChainContext> {
|
|||
String get name => "parse";
|
||||
|
||||
@override
|
||||
Future<Result<Null>> run(ScannedFile file, ChainContext context) async {
|
||||
Future<Result<Null>> run(ScannedFile file, ChainContext context) {
|
||||
try {
|
||||
List<ParserError> errors = parse(file.result.tokens,
|
||||
useImplicitCreationExpression: useImplicitCreationExpressionInCfe);
|
||||
if (errors.isNotEmpty) {
|
||||
return fail(null, errors.join("\n"));
|
||||
return new Future.value(fail(null, errors.join("\n")));
|
||||
}
|
||||
} on ParserError catch (e, s) {
|
||||
return fail(null, e, s);
|
||||
return new Future.value(fail(null, e, s));
|
||||
}
|
||||
return pass(null);
|
||||
return new Future.value(pass(null));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,8 +9,8 @@ import 'package:testing/testing.dart' show Chain, ChainContext, Step, runMe;
|
|||
import '../../utils/scanner_chain.dart' show Read, Scan;
|
||||
|
||||
Future<ChainContext> createContext(
|
||||
Chain suite, Map<String, String> environment) async {
|
||||
return new ScannerContext();
|
||||
Chain suite, Map<String, String> environment) {
|
||||
return new Future.value(new ScannerContext());
|
||||
}
|
||||
|
||||
class ScannerContext extends ChainContext {
|
||||
|
|
|
@ -9,7 +9,7 @@ library fasta.test.sdk_test;
|
|||
import 'testing/suite.dart';
|
||||
|
||||
Future<FastaContext> createContext(
|
||||
Chain suite, Map<String, String> environment) async {
|
||||
Chain suite, Map<String, String> environment) {
|
||||
environment[ENABLE_FULL_COMPILE] = "";
|
||||
environment["skipVm"] ??= "true";
|
||||
environment["onlyCrashes"] ??= "true";
|
||||
|
|
|
@ -677,14 +677,14 @@ class FastaContext extends ChainContext with MatchContext {
|
|||
return platformBinaries.resolve(fileName);
|
||||
}
|
||||
|
||||
Future<Component> loadPlatform(Target target, NnbdMode nnbdMode) async {
|
||||
Component loadPlatform(Target target, NnbdMode nnbdMode) {
|
||||
Uri uri = _getPlatformUri(target, nnbdMode);
|
||||
return _platforms.putIfAbsent(uri, () {
|
||||
return loadComponentFromBytes(new File.fromUri(uri).readAsBytesSync());
|
||||
});
|
||||
}
|
||||
|
||||
void clearPlatformCache(Target target, NnbdMode nnbdMode) async {
|
||||
void clearPlatformCache(Target target, NnbdMode nnbdMode) {
|
||||
Uri uri = _getPlatformUri(target, nnbdMode);
|
||||
_platforms.remove(uri);
|
||||
}
|
||||
|
@ -737,7 +737,7 @@ class FastaContext extends ChainContext with MatchContext {
|
|||
}
|
||||
|
||||
static Future<FastaContext> create(
|
||||
Chain suite, Map<String, String> environment) async {
|
||||
Chain suite, Map<String, String> environment) {
|
||||
const Set<String> knownEnvironmentKeys = {
|
||||
"enableExtensionMethods",
|
||||
"enableNonNullable",
|
||||
|
@ -785,7 +785,7 @@ class FastaContext extends ChainContext with MatchContext {
|
|||
if (platformBinaries != null && !platformBinaries.endsWith('/')) {
|
||||
platformBinaries = '$platformBinaries/';
|
||||
}
|
||||
return new FastaContext(
|
||||
return new Future.value(new FastaContext(
|
||||
suite.uri,
|
||||
vm,
|
||||
platformBinaries == null
|
||||
|
@ -801,7 +801,7 @@ class FastaContext extends ChainContext with MatchContext {
|
|||
kernelTextSerialization,
|
||||
environment.containsKey(ENABLE_FULL_COMPILE),
|
||||
verify,
|
||||
soundNullSafety);
|
||||
soundNullSafety));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -877,7 +877,7 @@ class StressConstantEvaluatorStep
|
|||
|
||||
@override
|
||||
Future<Result<ComponentResult>> run(
|
||||
ComponentResult result, FastaContext context) async {
|
||||
ComponentResult result, FastaContext context) {
|
||||
KernelTarget target = result.sourceTarget;
|
||||
ConstantsBackend constantsBackend = target.backendTarget.constantsBackend;
|
||||
TypeEnvironment environment =
|
||||
|
@ -902,7 +902,7 @@ class StressConstantEvaluatorStep
|
|||
"evaluated: ${stressConstantEvaluatorVisitor.tries}, "
|
||||
"effectively constant: ${stressConstantEvaluatorVisitor.success}");
|
||||
}
|
||||
return pass(result);
|
||||
return new Future.value(pass(result));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1158,8 +1158,8 @@ class FuzzCompiles
|
|||
UriTranslator uriTranslator =
|
||||
await context.computeUriTranslator(result.description);
|
||||
|
||||
Component platform = await context.loadPlatform(
|
||||
backendTarget, compilationSetup.options.nnbdMode);
|
||||
Component platform =
|
||||
context.loadPlatform(backendTarget, compilationSetup.options.nnbdMode);
|
||||
Result<ComponentResult>? passResult = await performFileInvalidation(
|
||||
compilationSetup,
|
||||
platform,
|
||||
|
@ -1878,8 +1878,7 @@ class Outline extends Step<TestDescription, ComponentResult, FastaContext> {
|
|||
ProcessedOptions options,
|
||||
List<Uri> entryPoints,
|
||||
{Component? alsoAppend}) async {
|
||||
Component platform =
|
||||
await context.loadPlatform(options.target, options.nnbdMode);
|
||||
Component platform = context.loadPlatform(options.target, options.nnbdMode);
|
||||
Ticker ticker = new Ticker();
|
||||
UriTranslator uriTranslator =
|
||||
await context.computeUriTranslator(description);
|
||||
|
@ -2076,14 +2075,14 @@ class EnsureNoErrors
|
|||
|
||||
@override
|
||||
Future<Result<ComponentResult>> run(
|
||||
ComponentResult result, FastaContext context) async {
|
||||
ComponentResult result, FastaContext context) {
|
||||
List<Iterable<String>> errors = result.compilationSetup.errors;
|
||||
return errors.isEmpty
|
||||
return new Future.value(errors.isEmpty
|
||||
? pass(result)
|
||||
: fail(
|
||||
result,
|
||||
"Unexpected errors:\n"
|
||||
"${errors.map((error) => error.join('\n')).join('\n\n')}");
|
||||
"${errors.map((error) => error.join('\n')).join('\n\n')}"));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2096,7 +2095,7 @@ class MatchHierarchy
|
|||
|
||||
@override
|
||||
Future<Result<ComponentResult>> run(
|
||||
ComponentResult result, FastaContext context) async {
|
||||
ComponentResult result, FastaContext context) {
|
||||
Component component = result.component;
|
||||
Uri uri =
|
||||
component.uriToSource.keys.firstWhere((uri) => uri.scheme == "file");
|
||||
|
|
|
@ -47,9 +47,9 @@ const List<Map<String, String>> EXPECTATIONS = [
|
|||
},
|
||||
];
|
||||
|
||||
Future<Context> createContext(
|
||||
Chain suite, Map<String, String> environment) async {
|
||||
return new Context(environment["updateExpectations"] == "true");
|
||||
Future<Context> createContext(Chain suite, Map<String, String> environment) {
|
||||
return new Future.value(
|
||||
new Context(environment["updateExpectations"] == "true"));
|
||||
}
|
||||
|
||||
void main([List<String> arguments = const []]) =>
|
||||
|
|
|
@ -124,13 +124,13 @@ const Expectation InitializedFromDillMismatch =
|
|||
const Expectation.fail("InitializedFromDillMismatch");
|
||||
const Expectation NNBDModeMismatch = const Expectation.fail("NNBDModeMismatch");
|
||||
|
||||
Future<Context> createContext(
|
||||
Chain suite, Map<String, String> environment) async {
|
||||
Future<Context> createContext(Chain suite, Map<String, String> environment) {
|
||||
// Disable colors to ensure that expectation files are the same across
|
||||
// platforms and independent of stdin/stderr.
|
||||
colors.enableColors = false;
|
||||
return new Context(environment["updateExpectations"] == "true",
|
||||
environment["addDebugBreaks"] == "true");
|
||||
return new Future.value(new Context(
|
||||
environment["updateExpectations"] == "true",
|
||||
environment["addDebugBreaks"] == "true"));
|
||||
}
|
||||
|
||||
class Context extends ChainContext {
|
||||
|
|
|
@ -54,7 +54,7 @@ class FileTest extends _BaseTestNative {
|
|||
|
||||
void test_createDirectory_exists_asFile() async {
|
||||
file.writeAsStringSync('');
|
||||
expect(() => file.createDirectory(), _throwsFileSystemException);
|
||||
await expectLater(file.createDirectory, _throwsFileSystemException);
|
||||
}
|
||||
|
||||
void test_equals_differentPaths() {
|
||||
|
@ -94,8 +94,8 @@ class FileTest extends _BaseTestNative {
|
|||
expect(await file.readAsBytes(), bytes);
|
||||
}
|
||||
|
||||
void test_readAsBytes_doesNotExist() {
|
||||
expect(file.readAsBytes(), _throwsFileSystemException);
|
||||
void test_readAsBytes_doesNotExist() async {
|
||||
await expectLater(file.readAsBytes, _throwsFileSystemException);
|
||||
}
|
||||
|
||||
void test_readAsBytes_exists() async {
|
||||
|
@ -104,13 +104,13 @@ class FileTest extends _BaseTestNative {
|
|||
expect(await file.readAsBytes(), utf8.encode(s));
|
||||
}
|
||||
|
||||
void test_readAsString_badUtf8() {
|
||||
void test_readAsString_badUtf8() async {
|
||||
file.writeAsBytesSync([0xc0, 0x40]); // Invalid UTF-8
|
||||
expect(file.readAsString(), _throwsFileSystemException);
|
||||
await expectLater(file.readAsString, _throwsFileSystemException);
|
||||
}
|
||||
|
||||
void test_readAsString_doesNotExist() {
|
||||
expect(file.readAsString(), _throwsFileSystemException);
|
||||
void test_readAsString_doesNotExist() async {
|
||||
await expectLater(file.readAsString, _throwsFileSystemException);
|
||||
}
|
||||
|
||||
void test_readAsString_exists() async {
|
||||
|
@ -126,7 +126,8 @@ class FileTest extends _BaseTestNative {
|
|||
|
||||
void test_writeAsBytesSync_directory() async {
|
||||
file.createDirectory();
|
||||
expect(() => file.writeAsBytesSync([0]), _throwsFileSystemException);
|
||||
await expectLater(
|
||||
() => file.writeAsBytesSync([0]), _throwsFileSystemException);
|
||||
}
|
||||
|
||||
void test_writeAsBytesSync_modifyAfterRead() async {
|
||||
|
@ -162,7 +163,8 @@ class FileTest extends _BaseTestNative {
|
|||
|
||||
void test_writeAsStringSync_directory() async {
|
||||
file.createDirectory();
|
||||
expect(() => file.writeAsStringSync(''), _throwsFileSystemException);
|
||||
await expectLater(
|
||||
() => file.writeAsStringSync(''), _throwsFileSystemException);
|
||||
}
|
||||
|
||||
void test_writeAsStringSync_overwrite() async {
|
||||
|
@ -221,7 +223,7 @@ abstract class MemoryFileSystemTestMixin implements _BaseTest {
|
|||
Uri.parse('$tempUri/file.txt'));
|
||||
}
|
||||
|
||||
void test_entityForUri_fileUri_relative() {
|
||||
void test_entityForUri_fileUri_relative() async {
|
||||
// A weird quirk of the Uri class is that it doesn't seem possible to create
|
||||
// a `file:` uri with a relative path, no matter how many slashes you use or
|
||||
// if you populate the fields directly. But just to be certain, try to do
|
||||
|
@ -234,7 +236,7 @@ abstract class MemoryFileSystemTestMixin implements _BaseTest {
|
|||
Uri.parse('file:///file.txt')
|
||||
]) {
|
||||
if (!uri.path.startsWith('/')) {
|
||||
expect(() => fileSystem.entityForUri(uri),
|
||||
await expectLater(() => fileSystem.entityForUri(uri),
|
||||
throwsA(const TypeMatcher<Error>()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ class DirectoryTest extends _BaseTest {
|
|||
|
||||
void test_readAsBytes() async {
|
||||
await new io.Directory(path).create();
|
||||
expect(dir.readAsBytes(), _throwsFileSystemException);
|
||||
await expectLater(dir.readAsBytes, _throwsFileSystemException);
|
||||
}
|
||||
|
||||
void test_uri() {
|
||||
|
@ -108,8 +108,8 @@ class FileTest extends _BaseTest {
|
|||
expect(await file.readAsBytes(), bytes);
|
||||
}
|
||||
|
||||
void test_readAsBytes_doesNotExist() {
|
||||
expect(file.readAsBytes(), _throwsFileSystemException);
|
||||
void test_readAsBytes_doesNotExist() async {
|
||||
await expectLater(file.readAsBytes, _throwsFileSystemException);
|
||||
}
|
||||
|
||||
void test_readAsBytes_exists() async {
|
||||
|
@ -118,13 +118,13 @@ class FileTest extends _BaseTest {
|
|||
expect(await file.readAsBytes(), utf8.encode(s));
|
||||
}
|
||||
|
||||
void test_readAsString_badUtf8() {
|
||||
void test_readAsString_badUtf8() async {
|
||||
new io.File(path).writeAsBytesSync([0xc0, 0x40]); // Invalid UTF-8
|
||||
expect(file.readAsString(), _throwsFileSystemException);
|
||||
await expectLater(file.readAsString, _throwsFileSystemException);
|
||||
}
|
||||
|
||||
void test_readAsString_doesNotExist() {
|
||||
expect(file.readAsString(), _throwsFileSystemException);
|
||||
void test_readAsString_doesNotExist() async {
|
||||
await expectLater(file.readAsString, _throwsFileSystemException);
|
||||
}
|
||||
|
||||
void test_readAsString_exists() async {
|
||||
|
@ -206,8 +206,8 @@ class StandardFileSystemTest extends _BaseTest {
|
|||
}
|
||||
}
|
||||
|
||||
void test_entityForUri_nonFileUri() {
|
||||
expect(
|
||||
void test_entityForUri_nonFileUri() async {
|
||||
await expectLater(
|
||||
() => StandardFileSystem.instance
|
||||
.entityForUri(Uri.parse('package:foo/bar.dart')),
|
||||
_throwsFileSystemException);
|
||||
|
|
|
@ -176,21 +176,21 @@ class TypeCheck extends Step<ComponentResult, ComponentResult, ChainContext> {
|
|||
|
||||
@override
|
||||
Future<Result<ComponentResult>> run(
|
||||
ComponentResult result, ChainContext context) async {
|
||||
ComponentResult result, ChainContext context) {
|
||||
Component component = result.component;
|
||||
ErrorFormatter errorFormatter = new ErrorFormatter();
|
||||
NaiveTypeChecker checker =
|
||||
new NaiveTypeChecker(errorFormatter, component, ignoreSdk: true);
|
||||
checker.checkComponent(component);
|
||||
if (errorFormatter.numberOfFailures == 0) {
|
||||
return pass(result);
|
||||
return new Future.value(pass(result));
|
||||
} else {
|
||||
errorFormatter.failures.forEach(print);
|
||||
print('------- Found ${errorFormatter.numberOfFailures} errors -------');
|
||||
return new Result<ComponentResult>(
|
||||
return new Future.value(new Result<ComponentResult>(
|
||||
null,
|
||||
context.expectationSet["TypeCheckError"],
|
||||
'${errorFormatter.numberOfFailures} type errors');
|
||||
'${errorFormatter.numberOfFailures} type errors'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -460,13 +460,13 @@ class ReadDill extends Step<Uri, Uri, ChainContext> {
|
|||
String get name => "read .dill";
|
||||
|
||||
@override
|
||||
Future<Result<Uri>> run(Uri uri, _) async {
|
||||
Future<Result<Uri>> run(Uri uri, _) {
|
||||
try {
|
||||
loadComponentFromBinary(uri.toFilePath());
|
||||
} catch (e, s) {
|
||||
return fail(uri, e, s);
|
||||
return new Future.value(fail(uri, e, s));
|
||||
}
|
||||
return pass(uri);
|
||||
return new Future.value(pass(uri));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ class Scan extends Step<ReadFile, ScannedFile, ChainContext> {
|
|||
String get name => "scan";
|
||||
|
||||
@override
|
||||
Future<Result<ScannedFile>> run(ReadFile file, ChainContext context) async {
|
||||
return pass(new ScannedFile(file, scan(file.bytes)));
|
||||
Future<Result<ScannedFile>> run(ReadFile file, ChainContext context) {
|
||||
return new Future.value(pass(new ScannedFile(file, scan(file.bytes))));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -156,7 +156,7 @@ class BatchCompiler {
|
|||
}
|
||||
}
|
||||
|
||||
Future<bool> batchCompileArguments(List<String> arguments) async {
|
||||
Future<bool> batchCompileArguments(List<String> arguments) {
|
||||
return runProtectedFromAbort<bool>(
|
||||
() => withGlobalOptions<bool>("compile", arguments, true,
|
||||
(CompilerContext c, _) => batchCompileImpl(c)),
|
||||
|
@ -448,7 +448,7 @@ Future<void> compilePlatformInternal(CompilerContext c, Uri fullOutput,
|
|||
}
|
||||
}
|
||||
|
||||
Future<List<Uri>> computeHostDependencies(Uri hostPlatform) async {
|
||||
Future<List<Uri>> computeHostDependencies(Uri hostPlatform) {
|
||||
// Returns a list of source files that make up the Fasta compiler (the files
|
||||
// the Dart VM reads to run Fasta). Until Fasta is self-hosting (in strong
|
||||
// mode), this is only an approximation, albeit accurate. Once Fasta is
|
||||
|
|
|
@ -43,7 +43,7 @@ Future<void> main(List<String> args) async {
|
|||
|
||||
await setup(entryUri);
|
||||
|
||||
Map<Uri, List<int>> files = await scanReachableFiles(entryUri);
|
||||
Map<Uri, List<int>> files = scanReachableFiles(entryUri);
|
||||
var handlers = {
|
||||
'scan': () async => scanFiles(files),
|
||||
// TODO(sigmund): enable when we can run the ast-builder standalone.
|
||||
|
@ -113,7 +113,7 @@ void scanFiles(Map<Uri, List<int>> files) {
|
|||
|
||||
/// Load and scans all files we need to process: files reachable from the
|
||||
/// entrypoint and all core libraries automatically included by the VM.
|
||||
Future<Map<Uri, List<int>>> scanReachableFiles(Uri entryUri) async {
|
||||
Map<Uri, List<int>> scanReachableFiles(Uri entryUri) {
|
||||
var files = <Uri, List<int>>{};
|
||||
var loadTimer = new Stopwatch()..start();
|
||||
scanTimer = new Stopwatch();
|
||||
|
@ -134,7 +134,7 @@ Future<Map<Uri, List<int>>> scanReachableFiles(Uri entryUri) async {
|
|||
Uri.parse('dart:typed_data'),
|
||||
];
|
||||
for (var entry in entrypoints) {
|
||||
await collectSources(entry, files);
|
||||
collectSources(entry, files);
|
||||
}
|
||||
loadTimer.stop();
|
||||
|
||||
|
@ -151,7 +151,7 @@ Future<Map<Uri, List<int>>> scanReachableFiles(Uri entryUri) async {
|
|||
}
|
||||
|
||||
/// Add to [files] all sources reachable from [start].
|
||||
Future<Null> collectSources(Uri start, Map<Uri, List<int>> files) async {
|
||||
void collectSources(Uri start, Map<Uri, List<int>> files) {
|
||||
void helper(Uri uri) {
|
||||
uri = uriResolver.translate(uri) ?? uri;
|
||||
// ignore: unnecessary_null_comparison
|
||||
|
@ -221,7 +221,7 @@ Future<CompilerResult> generateKernel(Uri entryUri,
|
|||
{bool compileSdk: true}) async {
|
||||
// TODO(sigmund): this is here only to compute the input size,
|
||||
// we should extract the input size from the frontend instead.
|
||||
await scanReachableFiles(entryUri);
|
||||
scanReachableFiles(entryUri);
|
||||
|
||||
var timer = new Stopwatch()..start();
|
||||
var options = new CompilerOptions()
|
||||
|
|
|
@ -42,7 +42,7 @@ Future<void> main(List<String> args) async {
|
|||
var bench = args[0];
|
||||
var entryUri = Uri.base.resolve(args[1]);
|
||||
|
||||
await setup(path.fromUri(entryUri));
|
||||
setup(path.fromUri(entryUri));
|
||||
|
||||
Set<Source> files = scanReachableFiles(entryUri);
|
||||
var handlers = {
|
||||
|
@ -197,7 +197,7 @@ Set<Source> scanReachableFiles(Uri entryUri) {
|
|||
|
||||
/// Sets up analyzer to be able to load and resolve app, packages, and sdk
|
||||
/// sources.
|
||||
Future setup(String path) async {
|
||||
void setup(String path) {
|
||||
var provider = PhysicalResourceProvider.INSTANCE;
|
||||
|
||||
var packages = findPackagesFrom(
|
||||
|
|
|
@ -240,7 +240,7 @@ Future<ComputeKernelResult> computeKernel(List<String> args,
|
|||
verbose: verbose,
|
||||
nnbdMode: nnbdMode);
|
||||
} else {
|
||||
state = await fe.initializeCompiler(
|
||||
state = fe.initializeCompiler(
|
||||
// TODO(sigmund): pass an old state once we can make use of it.
|
||||
null,
|
||||
toUri(parsedArgs['dart-sdk-summary']),
|
||||
|
|
|
@ -83,7 +83,7 @@ Future compileToKernel(
|
|||
Uri outputFile,
|
||||
List<Uri> sources,
|
||||
List<Uri> additionalDills) async {
|
||||
final state = await fe.initializeCompiler(
|
||||
final state = fe.initializeCompiler(
|
||||
null,
|
||||
sdkSummary,
|
||||
librariesFile,
|
||||
|
|
Loading…
Reference in a new issue