Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 // Partial test that the closed world computed from [WorldImpact]s derived from | 5 // Partial test that the closed world computed from [WorldImpact]s derived from |
| 6 // kernel is equivalent to the original computed from resolution. | 6 // kernel is equivalent to the original computed from resolution. |
| 7 library dart2js.kernel.compiler_helper; | 7 library dart2js.kernel.compiler_helper; |
| 8 | 8 |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| 11 | 11 |
| 12 import 'package:compiler/compiler_new.dart'; | 12 import 'package:compiler/compiler_new.dart'; |
| 13 import 'package:compiler/src/commandline_options.dart'; | 13 import 'package:compiler/src/commandline_options.dart'; |
| 14 import 'package:compiler/src/common.dart'; | 14 import 'package:compiler/src/common.dart'; |
| 15 import 'package:compiler/src/common/names.dart'; | |
| 16 import 'package:compiler/src/common/tasks.dart'; | 15 import 'package:compiler/src/common/tasks.dart'; |
| 17 import 'package:compiler/src/compiler.dart'; | 16 import 'package:compiler/src/compiler.dart'; |
| 18 import 'package:compiler/src/elements/elements.dart'; | |
| 19 import 'package:compiler/src/filenames.dart'; | 17 import 'package:compiler/src/filenames.dart'; |
| 20 import 'package:compiler/src/kernel/element_map.dart'; | 18 import 'package:compiler/src/kernel/element_map.dart'; |
| 21 import 'package:compiler/src/kernel/kernel_strategy.dart'; | 19 import 'package:compiler/src/kernel/kernel_strategy.dart'; |
| 22 import 'package:compiler/src/library_loader.dart'; | 20 import 'package:compiler/src/library_loader.dart'; |
| 23 import 'package:compiler/src/universe/world_builder.dart'; | 21 import 'package:compiler/src/universe/world_builder.dart'; |
| 24 import 'package:compiler/src/util/util.dart'; | 22 import 'package:compiler/src/util/util.dart'; |
| 25 import 'package:expect/expect.dart'; | |
| 26 import 'package:kernel/ast.dart' as ir; | 23 import 'package:kernel/ast.dart' as ir; |
| 27 import '../memory_compiler.dart'; | 24 import '../memory_compiler.dart'; |
| 28 import '../../../../pkg/compiler/tool/generate_kernel.dart' as generate; | 25 import '../../../../pkg/compiler/tool/generate_kernel.dart' as generate; |
| 29 | 26 |
| 30 typedef Future<Compiler> CompileFunction(); | 27 typedef Future<Compiler> CompileFunction(); |
| 31 | 28 |
| 32 /// Create multiple compilations for a list of [sources]. | 29 /// Create multiple compilations for a list of [sources]. |
| 33 /// | 30 /// |
| 34 /// This methods speeds up testing kernel based compilation by creating the IR | 31 /// This methods speeds up testing kernel based compilation by creating the IR |
| 35 /// nodes for all [sources] at the same time. The returned list of | 32 /// nodes for all [sources] at the same time. The returned list of |
| 36 /// [CompileFunction]s compiles one of the [source] at a time using the kernel | 33 /// [CompileFunction]s compiles one of the [source] at a time using the kernel |
| 37 /// based compiler. | 34 /// based compiler. |
| 38 /// | 35 /// |
| 39 /// Currently, the returned compile function only runs with '--analyze-only' | 36 /// Currently, the returned compile function only runs with '--analyze-only' |
| 40 /// flag. | 37 /// flag. |
| 41 Future<List<CompileFunction>> compileMultiple(List<String> sources) async { | 38 Future<List<CompileFunction>> compileMultiple(List<String> sources) async { |
| 42 List<Uri> uris = <Uri>[]; | |
| 43 Uri entryPoint = Uri.parse('memory:main.dart'); | 39 Uri entryPoint = Uri.parse('memory:main.dart'); |
| 44 Map<String, String> memorySourceFiles = <String, String>{ | |
| 45 'main.dart': 'main() {}' | |
| 46 }; | |
| 47 for (String source in sources) { | |
| 48 String name = 'input${memorySourceFiles.length}.dart'; | |
| 49 Uri uri = Uri.parse('memory:$name'); | |
| 50 memorySourceFiles[name] = source; | |
| 51 uris.add(uri); | |
| 52 } | |
| 53 Compiler compiler = compilerFor( | |
| 54 entryPoint: entryPoint, | |
| 55 memorySourceFiles: memorySourceFiles, | |
| 56 options: [ | |
| 57 Flags.analyzeAll, | |
| 58 Flags.useKernelInSsa, | |
| 59 Flags.enableAssertMessage | |
| 60 ]); | |
| 61 compiler.librariesToAnalyzeWhenRun = uris; | |
| 62 await compiler.run(entryPoint); | |
| 63 | 40 |
| 64 List<CompileFunction> compilers = <CompileFunction>[]; | 41 List<CompileFunction> compilers = <CompileFunction>[]; |
| 65 for (Uri uri in uris) { | 42 for (String source in sources) { |
| 66 compilers.add(() async { | 43 compilers.add(() async { |
| 67 Compiler compiler2 = compilerFor( | 44 Compiler compiler2 = compilerFor( |
|
Siggi Cherem (dart-lang)
2017/08/25 00:27:39
nit: rename compiler2 to compiler? (since there is
Johnni Winther
2017/08/30 09:02:51
Done.
| |
| 68 entryPoint: uri, | 45 entryPoint: entryPoint, |
| 69 memorySourceFiles: memorySourceFiles, | 46 memorySourceFiles: { |
| 47 'main.dart': source | |
| 48 }, | |
| 70 options: [ | 49 options: [ |
| 71 Flags.analyzeOnly, | 50 Flags.analyzeOnly, |
| 72 Flags.enableAssertMessage, | 51 Flags.enableAssertMessage, |
| 73 Flags.useKernel | 52 Flags.useKernel |
| 74 ]); | 53 ]); |
| 75 ElementResolutionWorldBuilder.useInstantiationMap = true; | 54 ElementResolutionWorldBuilder.useInstantiationMap = true; |
| 76 compiler2.resolution.retainCachesForTesting = true; | 55 compiler2.resolution.retainCachesForTesting = true; |
| 77 KernelFrontEndStrategy frontendStrategy = compiler2.frontendStrategy; | 56 await compiler2.run(entryPoint); |
| 78 KernelToElementMapForImpact elementMap = frontendStrategy.elementMap; | |
| 79 ir.Program program = new ir.Program( | |
| 80 libraries: | |
| 81 compiler.backend.kernelTask.kernel.libraryDependencies(uri)); | |
| 82 LibraryElement library = compiler.libraryLoader.lookupLibrary(uri); | |
| 83 Expect.isNotNull(library, 'No library found for $uri'); | |
| 84 program.mainMethod = compiler.backend.kernelTask.kernel | |
| 85 .functionToIr(library.findExported(Identifiers.main)); | |
| 86 compiler2.libraryLoader = new MemoryKernelLibraryLoaderTask( | |
| 87 elementMap, compiler2.reporter, compiler2.measurer, program); | |
| 88 await compiler2.run(uri); | |
| 89 return compiler2; | 57 return compiler2; |
| 90 }); | 58 }); |
| 91 } | 59 } |
| 92 return compilers; | 60 return compilers; |
| 93 } | 61 } |
| 94 | 62 |
| 95 /// Analyze [memorySourceFiles] with [entryPoint] as entry-point using the | 63 /// Analyze [memorySourceFiles] with [entryPoint] as entry-point using the |
| 96 /// kernel based element model. The returned [Pair] contains the compiler used | 64 /// kernel based element model. The returned [Pair] contains the compiler used |
| 97 /// to create the IR and the kernel based compiler. | 65 /// to create the IR and the kernel based compiler. |
| 98 Future<Pair<Compiler, Compiler>> analyzeOnly( | 66 Future<Pair<Compiler, Compiler>> analyzeOnly( |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 198 diagnosticHandler: diagnosticHandler, | 166 diagnosticHandler: diagnosticHandler, |
| 199 outputProvider: compilerOutput); | 167 outputProvider: compilerOutput); |
| 200 ElementResolutionWorldBuilder.useInstantiationMap = true; | 168 ElementResolutionWorldBuilder.useInstantiationMap = true; |
| 201 compiler.resolution.retainCachesForTesting = true; | 169 compiler.resolution.retainCachesForTesting = true; |
| 202 if (beforeRun != null) { | 170 if (beforeRun != null) { |
| 203 beforeRun(compiler); | 171 beforeRun(compiler); |
| 204 } | 172 } |
| 205 await compiler.run(entryPoint); | 173 await compiler.run(entryPoint); |
| 206 return compiler; | 174 return compiler; |
| 207 } | 175 } |
| OLD | NEW |