From a9e1e7e4fdac300ebc87ae9f8904bc3d89ab8d33 Mon Sep 17 00:00:00 2001 From: jonahwilliams Date: Fri, 11 Oct 2019 19:47:40 +0000 Subject: [PATCH] Remove 'new' from frontend_server Change-Id: I23afa1ab5d9e722f355eabaaa0491b3f08f261eb Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121404 Reviewed-by: Alexander Aprelev Commit-Queue: Jonah Williams --- pkg/frontend_server/lib/frontend_server.dart | 95 ++++++++++---------- 1 file changed, 47 insertions(+), 48 deletions(-) diff --git a/pkg/frontend_server/lib/frontend_server.dart b/pkg/frontend_server/lib/frontend_server.dart index acc8df5fdd7..c409d5fea56 100644 --- a/pkg/frontend_server/lib/frontend_server.dart +++ b/pkg/frontend_server/lib/frontend_server.dart @@ -55,7 +55,7 @@ import 'package:vm/target/flutter.dart' show FlutterTarget; import 'package:vm/target/flutter_runner.dart' show FlutterRunnerTarget; import 'package:vm/target/vm.dart' show VmTarget; -ArgParser argParser = new ArgParser(allowTrailingOptions: true) +ArgParser argParser = ArgParser(allowTrailingOptions: true) ..addFlag('train', help: 'Run through sample command line to produce snapshot', negatable: false) @@ -261,7 +261,7 @@ abstract class ProgramTransformer { class BinaryPrinterFactory { /// Creates new [BinaryPrinter] to write to [targetSink]. BinaryPrinter newBinaryPrinter(Sink> targetSink) { - return new LimitedBinaryPrinter(targetSink, (_) => true /* predicate */, + return LimitedBinaryPrinter(targetSink, (_) => true /* predicate */, false /* excludeUriToSource */); } } @@ -273,7 +273,7 @@ class FrontendCompiler implements CompilerInterface { this.unsafePackageSerialization, this.incrementalSerialization: true}) { _outputStream ??= stdout; - printerFactory ??= new BinaryPrinterFactory(); + printerFactory ??= BinaryPrinterFactory(); // Initialize supported kernel targets. targets['dart_runner'] = (TargetFlags flags) => DartRunnerTarget(flags); targets['flutter'] = (TargetFlags flags) => FlutterTarget(flags); @@ -304,7 +304,7 @@ class FrontendCompiler implements CompilerInterface { final ProgramTransformer transformer; - final List errors = new List(); + final List errors = List(); @override Future compile( @@ -324,12 +324,12 @@ class FrontendCompiler implements CompilerInterface { _kernelBinaryFilename = _kernelBinaryFilenameFull; _initializeFromDill = _options['initialize-from-dill'] ?? _kernelBinaryFilenameFull; - final String boundaryKey = new Uuid().generateV4(); + final String boundaryKey = Uuid().generateV4(); _outputStream.writeln('result $boundaryKey'); final Uri sdkRoot = _ensureFolderPath(options['sdk-root']); final String platformKernelDill = options['platform'] ?? 'platform_strong.dill'; - final CompilerOptions compilerOptions = new CompilerOptions() + final CompilerOptions compilerOptions = CompilerOptions() ..sdkRoot = sdkRoot ..fileSystem = _fileSystem ..packagesFileUri = _getFileOrUri(_options['packages']) @@ -375,7 +375,7 @@ class FrontendCompiler implements CompilerInterface { } compilerOptions.bytecode = options['gen-bytecode']; - final BytecodeOptions bytecodeOptions = new BytecodeOptions( + final BytecodeOptions bytecodeOptions = BytecodeOptions( enableAsserts: options['enable-asserts'], emitSourceFiles: options['embed-source-text'], environmentDefines: environmentDefines) @@ -393,7 +393,7 @@ class FrontendCompiler implements CompilerInterface { final String importDill = options['import-dill']; if (importDill != null) { compilerOptions.inputSummaries = [ - Uri.base.resolveUri(new Uri.file(importDill)) + Uri.base.resolveUri(Uri.file(importDill)) ]; } @@ -415,12 +415,11 @@ class FrontendCompiler implements CompilerInterface { setVMEnvironmentDefines(environmentDefines, _compilerOptions); _compilerOptions.omitPlatform = false; - _generator = - generator ?? _createGenerator(new Uri.file(_initializeFromDill)); + _generator = generator ?? _createGenerator(Uri.file(_initializeFromDill)); await invalidateIfInitializingFromDill(); Component component = await _runWithPrintRedirection(() => _generator.compile()); - results = new KernelCompilationResults( + results = KernelCompilationResults( component, _generator.getClassHierarchy(), _generator.getCoreTypes(), @@ -485,7 +484,7 @@ class FrontendCompiler implements CompilerInterface { } void _outputDependenciesDelta(Iterable compiledSources) async { - Set uris = new Set(); + Set uris = Set(); for (Uri uri in compiledSources) { // Skip empty or corelib dependencies. if (uri == null || uri.scheme == 'org-dartlang-sdk') continue; @@ -525,7 +524,7 @@ class FrontendCompiler implements CompilerInterface { if (_compilerOptions.bytecode) { { // Generate bytecode as the output proper. - final IOSink sink = new File(filename).openWrite(); + final IOSink sink = File(filename).openWrite(); await runWithFrontEndCompilerContext( _mainSource, _compilerOptions, component, () async { if (_options['incremental']) { @@ -545,7 +544,7 @@ class FrontendCompiler implements CompilerInterface { // of [filename] so that a later invocation of frontend_server will the // same arguments will use this to initialize its incremental kernel // compiler. - final repository = new BinaryCacheMetadataRepository(); + final repository = BinaryCacheMetadataRepository(); component.addMetadataRepository(repository); for (var lib in component.libraries) { var bytes = BinaryCacheMetadataRepository.lookup(lib); @@ -554,9 +553,9 @@ class FrontendCompiler implements CompilerInterface { } } - final IOSink sink = new File(_initializeFromDill).openWrite(); + final IOSink sink = File(_initializeFromDill).openWrite(); final BinaryPrinter printer = filterExternal - ? new LimitedBinaryPrinter( + ? LimitedBinaryPrinter( sink, (lib) => !lib.isExternal, true /* excludeUriToSource */) : printerFactory.newBinaryPrinter(sink); @@ -567,9 +566,9 @@ class FrontendCompiler implements CompilerInterface { } } else { // Generate AST as the output proper. - final IOSink sink = new File(filename).openWrite(); + final IOSink sink = File(filename).openWrite(); final BinaryPrinter printer = filterExternal - ? new LimitedBinaryPrinter( + ? LimitedBinaryPrinter( sink, (lib) => !lib.isExternal, true /* excludeUriToSource */) : printerFactory.newBinaryPrinter(sink); @@ -594,7 +593,7 @@ class FrontendCompiler implements CompilerInterface { // be invalidated by the normal approach anyway. if (_generator.initialized) return null; - final File f = new File(_initializeFromDill); + final File f = File(_initializeFromDill); if (!f.existsSync()) return null; Component component; @@ -672,8 +671,8 @@ class FrontendCompiler implements CompilerInterface { } } - final byteSink = new ByteSink(); - final BinaryPrinter printer = new LimitedBinaryPrinter(byteSink, + final byteSink = ByteSink(); + final BinaryPrinter printer = LimitedBinaryPrinter(byteSink, (lib) => packageFor(lib) == package, false /* excludeUriToSource */); printer.writeComponentFile(partComponent); @@ -686,7 +685,7 @@ class FrontendCompiler implements CompilerInterface { @override Future recompileDelta({String entryPoint}) async { - final String boundaryKey = new Uuid().generateV4(); + final String boundaryKey = Uuid().generateV4(); _outputStream.writeln('result $boundaryKey'); await invalidateIfInitializingFromDill(); if (entryPoint != null) { @@ -699,7 +698,7 @@ class FrontendCompiler implements CompilerInterface { transformer.transform(deltaProgram); } - KernelCompilationResults results = new KernelCompilationResults( + KernelCompilationResults results = KernelCompilationResults( deltaProgram, _generator.getClassHierarchy(), _generator.getCoreTypes(), @@ -723,14 +722,14 @@ class FrontendCompiler implements CompilerInterface { String libraryUri, String klass, bool isStatic) async { - final String boundaryKey = new Uuid().generateV4(); + final String boundaryKey = Uuid().generateV4(); _outputStream.writeln('result $boundaryKey'); Procedure procedure = await _generator.compileExpression( expression, definitions, typeDefinitions, libraryUri, klass, isStatic); if (procedure != null) { Component component = createExpressionEvaluationComponent(procedure); component = await _generateBytecodeIfNeeded(component); - final IOSink sink = new File(_kernelBinaryFilename).openWrite(); + final IOSink sink = File(_kernelBinaryFilename).openWrite(); sink.add(serializeComponent(component)); await sink.close(); _outputStream @@ -743,7 +742,7 @@ class FrontendCompiler implements CompilerInterface { @override void reportError(String msg) { - final String boundaryKey = new Uuid().generateV4(); + final String boundaryKey = Uuid().generateV4(); _outputStream.writeln('result $boundaryKey'); _outputStream.writeln(msg); _outputStream.writeln(boundaryKey); @@ -752,7 +751,7 @@ class FrontendCompiler implements CompilerInterface { /// Map of already serialized dill data. All uris in a serialized component /// maps to the same blob of data. Used by /// [writePackagesToSinkAndTrimComponent]. - Map> cachedPackageLibraries = new Map>(); + Map> cachedPackageLibraries = Map>(); /// Map of dependencies for already serialized dill data. /// E.g. if blob1 dependents on blob2, but only using a single file from blob1 @@ -760,14 +759,14 @@ class FrontendCompiler implements CompilerInterface { /// dill file in a weird state that could cause the VM to crash if asked to /// forcefully compile everything. Used by /// [writePackagesToSinkAndTrimComponent]. - Map> cachedPackageDependencies = new Map>(); + Map> cachedPackageDependencies = Map>(); writePackagesToSinkAndTrimComponent( Component deltaProgram, Sink> ioSink) { if (deltaProgram == null) return; - List packageLibraries = new List(); - List libraries = new List(); + List packageLibraries = List(); + List libraries = List(); deltaProgram.computeCanonicalNames(); for (var lib in deltaProgram.libraries) { @@ -782,8 +781,8 @@ class FrontendCompiler implements CompilerInterface { ..clear() ..addAll(libraries); - Map> newPackages = new Map>(); - Set> alreadyAdded = new Set>(); + Map> newPackages = Map>(); + Set> alreadyAdded = Set>(); addDataAndDependentData(List data, Uri uri) { if (alreadyAdded.add(data)) { @@ -808,20 +807,20 @@ class FrontendCompiler implements CompilerInterface { for (String package in newPackages.keys) { List libraries = newPackages[package]; - Component singleLibrary = new Component( + Component singleLibrary = Component( libraries: libraries, uriToSource: deltaProgram.uriToSource, nameRoot: deltaProgram.root); - ByteSink byteSink = new ByteSink(); + ByteSink byteSink = ByteSink(); final BinaryPrinter printer = printerFactory.newBinaryPrinter(byteSink); printer.writeComponentFile(singleLibrary); // Record things this package blob dependent on. - Set libraryUris = new Set(); + Set libraryUris = Set(); for (Library lib in libraries) { libraryUris.add(lib.fileUri); } - Set deps = new Set(); + Set deps = Set(); for (Library lib in libraries) { for (LibraryDependency dep in lib.dependencies) { Library dependencyLibrary = dep.importedLibraryReference.asLibrary; @@ -836,7 +835,7 @@ class FrontendCompiler implements CompilerInterface { List data = byteSink.builder.takeBytes(); for (Library lib in libraries) { cachedPackageLibraries[lib.fileUri] = data; - cachedPackageDependencies[lib.fileUri] = new List.from(deps); + cachedPackageDependencies[lib.fileUri] = List.from(deps); } ioSink.add(data); } @@ -850,7 +849,7 @@ class FrontendCompiler implements CompilerInterface { @override Future rejectLastDelta() async { await _generator.reject(); - final String boundaryKey = new Uuid().generateV4(); + final String boundaryKey = Uuid().generateV4(); _outputStream.writeln('result $boundaryKey'); _outputStream.writeln(boundaryKey); } @@ -870,13 +869,13 @@ class FrontendCompiler implements CompilerInterface { convertFileOrUriArgumentToUri(_fileSystem, fileOrUri); IncrementalCompiler _createGenerator(Uri initializeFromDillUri) { - return new IncrementalCompiler(_compilerOptions, _mainSource, + return IncrementalCompiler(_compilerOptions, _mainSource, initializeFromDillUri: initializeFromDillUri, incrementalSerialization: incrementalSerialization); } Uri _ensureFolderPath(String path) { - String uriPath = new Uri.file(path).toString(); + String uriPath = Uri.file(path).toString(); if (!uriPath.endsWith('/')) { uriPath = '$uriPath/'; } @@ -886,8 +885,8 @@ class FrontendCompiler implements CompilerInterface { /// Runs the given function [f] in a Zone that redirects all prints into /// [_outputStream]. Future _runWithPrintRedirection(Future f()) { - return runZoned(() => new Future(f), - zoneSpecification: new ZoneSpecification( + return runZoned(() => Future(f), + zoneSpecification: ZoneSpecification( print: (Zone self, ZoneDelegate parent, Zone zone, String line) => _outputStream.writeln(line))); } @@ -895,7 +894,7 @@ class FrontendCompiler implements CompilerInterface { /// A [Sink] that directly writes data into a byte builder. class ByteSink implements Sink> { - final BytesBuilder builder = new BytesBuilder(); + final BytesBuilder builder = BytesBuilder(); void add(List data) { builder.add(data); @@ -963,7 +962,7 @@ void listenAndCompile(CompilerInterface compiler, Stream> input, // // // - compileExpressionRequest = new _CompileExpressionRequest(); + compileExpressionRequest = _CompileExpressionRequest(); boundaryKey = string.substring(COMPILE_EXPRESSION_INSTRUCTION_SPACE.length); state = _State.COMPILE_EXPRESSION_EXPRESSION; @@ -1069,11 +1068,11 @@ Future starter( '--output-dill=$outputTrainingDill', ]; if (platform != null) { - args.add('--platform=${new Uri.file(platform)}'); + args.add('--platform=${Uri.file(platform)}'); } options = argParser.parse(args); compiler ??= - new FrontendCompiler(output, printerFactory: binaryPrinterFactory); + FrontendCompiler(output, printerFactory: binaryPrinterFactory); await compiler.compile(input, options, generator: generator); compiler.acceptLastDelta(); @@ -1090,7 +1089,7 @@ Future starter( } } - compiler ??= new FrontendCompiler(output, + compiler ??= FrontendCompiler(output, printerFactory: binaryPrinterFactory, unsafePackageSerialization: options["unsafe-package-serialization"], incrementalSerialization: options["incremental-serialization"]); @@ -1102,7 +1101,7 @@ Future starter( : 254; } - Completer completer = new Completer(); + Completer completer = Completer(); listenAndCompile(compiler, input ?? stdin, options, completer, generator: generator); return completer.future;