|
| 1 | +// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +// @dart = 2.9 |
| 6 | + |
| 7 | +import 'dart:io'; |
| 8 | + |
| 9 | +import 'package:front_end/src/api_unstable/vm.dart'; |
| 10 | +import 'package:front_end/src/fasta/incremental_compiler.dart'; |
| 11 | +import 'package:kernel/ast.dart'; |
| 12 | + |
| 13 | +import 'incremental_load_from_dill_suite.dart' show getOptions; |
| 14 | + |
| 15 | +main() async { |
| 16 | + Uri compileTarget = Platform.script.resolve("binary_md_dill_reader.dart"); |
| 17 | + if (!(new File.fromUri(compileTarget)).existsSync()) { |
| 18 | + throw "$compileTarget doesn't exist"; |
| 19 | + } |
| 20 | + |
| 21 | + List<Future> futures = []; |
| 22 | + List<int> compilesLeft = new List<int>.filled(5, 8); |
| 23 | + for (int i = 0; i < compilesLeft.length; i++) { |
| 24 | + Future<Component> compileAgain() async { |
| 25 | + print("$i has ${compilesLeft[i]} left."); |
| 26 | + if (compilesLeft[i] > 0) { |
| 27 | + compilesLeft[i]--; |
| 28 | + return compile(i, compileTarget).then((value) => compileAgain()); |
| 29 | + } |
| 30 | + return null; |
| 31 | + } |
| 32 | + |
| 33 | + print("Starting first compile for $i"); |
| 34 | + futures.add(compile(i, compileTarget).then((value) => compileAgain())); |
| 35 | + } |
| 36 | + await Future.wait(futures); |
| 37 | + |
| 38 | + print("Checkpoint #1: Can compiles several at once " |
| 39 | + "(with different compilers!)"); |
| 40 | + |
| 41 | + for (int i = 0; i < 5; i++) { |
| 42 | + futures.clear(); |
| 43 | + for (int j = 0; j < 10; j++) { |
| 44 | + futures.add(compile(0, compileTarget)); |
| 45 | + } |
| 46 | + await Future.wait(futures); |
| 47 | + } |
| 48 | + |
| 49 | + print("Checkpoint #2: Can compiles several at once " |
| 50 | + "(with the same compiler) (without crashing)"); |
| 51 | +} |
| 52 | + |
| 53 | +List<IncrementalCompiler> compilers = []; |
| 54 | + |
| 55 | +Future<Component> compile(int compilerNum, Uri uri) async { |
| 56 | + if (compilers.length <= compilerNum) { |
| 57 | + compilers.length = compilerNum + 1; |
| 58 | + } |
| 59 | + IncrementalCompiler compiler = compilers[compilerNum]; |
| 60 | + if (compiler == null) { |
| 61 | + var options = getOptions(); |
| 62 | + compiler = new IncrementalCompiler(new CompilerContext( |
| 63 | + new ProcessedOptions(options: options, inputs: [uri]))); |
| 64 | + compilers[compilerNum] = compiler; |
| 65 | + } else { |
| 66 | + compiler.invalidateAllSources(); |
| 67 | + } |
| 68 | + Component result = await compiler.computeDelta(); |
| 69 | + print("Now compile is done!"); |
| 70 | + return result; |
| 71 | +} |
0 commit comments