| 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'; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 }; | 46 }; |
| 47 for (String source in sources) { | 47 for (String source in sources) { |
| 48 String name = 'input${memorySourceFiles.length}.dart'; | 48 String name = 'input${memorySourceFiles.length}.dart'; |
| 49 Uri uri = Uri.parse('memory:$name'); | 49 Uri uri = Uri.parse('memory:$name'); |
| 50 memorySourceFiles[name] = source; | 50 memorySourceFiles[name] = source; |
| 51 uris.add(uri); | 51 uris.add(uri); |
| 52 } | 52 } |
| 53 Compiler compiler = compilerFor( | 53 Compiler compiler = compilerFor( |
| 54 entryPoint: entryPoint, | 54 entryPoint: entryPoint, |
| 55 memorySourceFiles: memorySourceFiles, | 55 memorySourceFiles: memorySourceFiles, |
| 56 options: [Flags.analyzeAll, Flags.useKernel, Flags.enableAssertMessage]); | 56 options: [ |
| 57 Flags.analyzeAll, |
| 58 Flags.useKernelInSsa, |
| 59 Flags.enableAssertMessage |
| 60 ]); |
| 57 compiler.librariesToAnalyzeWhenRun = uris; | 61 compiler.librariesToAnalyzeWhenRun = uris; |
| 58 await compiler.run(entryPoint); | 62 await compiler.run(entryPoint); |
| 59 | 63 |
| 60 List<CompileFunction> compilers = <CompileFunction>[]; | 64 List<CompileFunction> compilers = <CompileFunction>[]; |
| 61 for (Uri uri in uris) { | 65 for (Uri uri in uris) { |
| 62 compilers.add(() async { | 66 compilers.add(() async { |
| 63 Compiler compiler2 = compilerFor( | 67 Compiler compiler2 = compilerFor( |
| 64 entryPoint: uri, | 68 entryPoint: uri, |
| 65 memorySourceFiles: memorySourceFiles, | 69 memorySourceFiles: memorySourceFiles, |
| 66 options: [ | 70 options: [ |
| 67 Flags.analyzeOnly, | 71 Flags.analyzeOnly, |
| 68 Flags.enableAssertMessage, | 72 Flags.enableAssertMessage, |
| 69 Flags.loadFromDill | 73 Flags.useKernel |
| 70 ]); | 74 ]); |
| 71 ElementResolutionWorldBuilder.useInstantiationMap = true; | 75 ElementResolutionWorldBuilder.useInstantiationMap = true; |
| 72 compiler2.resolution.retainCachesForTesting = true; | 76 compiler2.resolution.retainCachesForTesting = true; |
| 73 KernelFrontEndStrategy frontendStrategy = compiler2.frontendStrategy; | 77 KernelFrontEndStrategy frontendStrategy = compiler2.frontendStrategy; |
| 74 KernelToElementMapForImpact elementMap = frontendStrategy.elementMap; | 78 KernelToElementMapForImpact elementMap = frontendStrategy.elementMap; |
| 75 ir.Program program = new ir.Program( | 79 ir.Program program = new ir.Program( |
| 76 libraries: | 80 libraries: |
| 77 compiler.backend.kernelTask.kernel.libraryDependencies(uri)); | 81 compiler.backend.kernelTask.kernel.libraryDependencies(uri)); |
| 78 LibraryElement library = compiler.libraryLoader.lookupLibrary(uri); | 82 LibraryElement library = compiler.libraryLoader.lookupLibrary(uri); |
| 79 Expect.isNotNull(library, 'No library found for $uri'); | 83 Expect.isNotNull(library, 'No library found for $uri'); |
| 80 program.mainMethod = compiler.backend.kernelTask.kernel | 84 program.mainMethod = compiler.backend.kernelTask.kernel |
| 81 .functionToIr(library.findExported(Identifiers.main)); | 85 .functionToIr(library.findExported(Identifiers.main)); |
| 82 compiler2.libraryLoader = new MemoryDillLibraryLoaderTask( | 86 compiler2.libraryLoader = new MemoryKernelLibraryLoaderTask( |
| 83 elementMap, compiler2.reporter, compiler2.measurer, program); | 87 elementMap, compiler2.reporter, compiler2.measurer, program); |
| 84 await compiler2.run(uri); | 88 await compiler2.run(uri); |
| 85 return compiler2; | 89 return compiler2; |
| 86 }); | 90 }); |
| 87 } | 91 } |
| 88 return compilers; | 92 return compilers; |
| 89 } | 93 } |
| 90 | 94 |
| 91 /// Analyze [memorySourceFiles] with [entryPoint] as entry-point using the | 95 /// Analyze [memorySourceFiles] with [entryPoint] as entry-point using the |
| 92 /// kernel based element model. The returned [Pair] contains the compiler used | 96 /// kernel based element model. The returned [Pair] contains the compiler used |
| 93 /// to create the IR and the kernel based compiler. | 97 /// to create the IR and the kernel based compiler. |
| 94 Future<Pair<Compiler, Compiler>> analyzeOnly( | 98 Future<Pair<Compiler, Compiler>> analyzeOnly( |
| 95 Uri entryPoint, Map<String, String> memorySourceFiles, | 99 Uri entryPoint, Map<String, String> memorySourceFiles, |
| 96 {bool printSteps: false}) async { | 100 {bool printSteps: false}) async { |
| 97 if (printSteps) { | 101 if (printSteps) { |
| 98 print('---- analyze-all -------------------------------------------------'); | 102 print('---- analyze-all -------------------------------------------------'); |
| 99 } | 103 } |
| 100 Compiler compiler = compilerFor( | 104 Compiler compiler = compilerFor( |
| 101 entryPoint: entryPoint, | 105 entryPoint: entryPoint, |
| 102 memorySourceFiles: memorySourceFiles, | 106 memorySourceFiles: memorySourceFiles, |
| 103 options: [Flags.analyzeAll, Flags.useKernel, Flags.enableAssertMessage]); | 107 options: [ |
| 108 Flags.analyzeAll, |
| 109 Flags.useKernelInSsa, |
| 110 Flags.enableAssertMessage |
| 111 ]); |
| 104 await compiler.run(entryPoint); | 112 await compiler.run(entryPoint); |
| 105 | 113 |
| 106 if (printSteps) { | 114 if (printSteps) { |
| 107 print('---- closed world from kernel ------------------------------------'); | 115 print('---- closed world from kernel ------------------------------------'); |
| 108 } | 116 } |
| 109 Compiler compiler2 = compilerFor( | 117 Compiler compiler2 = compilerFor( |
| 110 entryPoint: entryPoint, | 118 entryPoint: entryPoint, |
| 111 memorySourceFiles: memorySourceFiles, | 119 memorySourceFiles: memorySourceFiles, |
| 112 options: [ | 120 options: [Flags.analyzeOnly, Flags.enableAssertMessage, Flags.useKernel]); |
| 113 Flags.analyzeOnly, | |
| 114 Flags.enableAssertMessage, | |
| 115 Flags.loadFromDill | |
| 116 ]); | |
| 117 ElementResolutionWorldBuilder.useInstantiationMap = true; | 121 ElementResolutionWorldBuilder.useInstantiationMap = true; |
| 118 compiler2.resolution.retainCachesForTesting = true; | 122 compiler2.resolution.retainCachesForTesting = true; |
| 119 KernelFrontEndStrategy frontendStrategy = compiler2.frontendStrategy; | 123 KernelFrontEndStrategy frontendStrategy = compiler2.frontendStrategy; |
| 120 KernelToElementMapForImpact elementMap = frontendStrategy.elementMap; | 124 KernelToElementMapForImpact elementMap = frontendStrategy.elementMap; |
| 121 compiler2.libraryLoader = new MemoryDillLibraryLoaderTask( | 125 compiler2.libraryLoader = new MemoryKernelLibraryLoaderTask( |
| 122 elementMap, | 126 elementMap, |
| 123 compiler2.reporter, | 127 compiler2.reporter, |
| 124 compiler2.measurer, | 128 compiler2.measurer, |
| 125 compiler.backend.kernelTask.program); | 129 compiler.backend.kernelTask.program); |
| 126 await compiler2.run(entryPoint); | 130 await compiler2.run(entryPoint); |
| 127 return new Pair<Compiler, Compiler>(compiler, compiler2); | 131 return new Pair<Compiler, Compiler>(compiler, compiler2); |
| 128 } | 132 } |
| 129 | 133 |
| 130 class MemoryDillLibraryLoaderTask extends DillLibraryLoaderTask { | 134 class MemoryKernelLibraryLoaderTask extends KernelLibraryLoaderTask { |
| 131 final ir.Program program; | 135 final ir.Program program; |
| 132 | 136 |
| 133 MemoryDillLibraryLoaderTask(KernelToElementMapForImpact elementMap, | 137 MemoryKernelLibraryLoaderTask(KernelToElementMapForImpact elementMap, |
| 134 DiagnosticReporter reporter, Measurer measurer, this.program) | 138 DiagnosticReporter reporter, Measurer measurer, this.program) |
| 135 : super(elementMap, null, null, reporter, measurer); | 139 : super(elementMap, null, reporter, measurer); |
| 136 | 140 |
| 137 Future<LoadedLibraries> loadLibrary(Uri resolvedUri, | 141 Future<LoadedLibraries> loadLibrary(Uri resolvedUri, |
| 138 {bool skipFileWithPartOfTag: false}) async { | 142 {bool skipFileWithPartOfTag: false}) async { |
| 139 return createLoadedLibraries(program); | 143 return createLoadedLibraries(program); |
| 140 } | 144 } |
| 141 } | 145 } |
| 142 | 146 |
| 143 Future createTemp(Uri entryPoint, Map<String, String> memorySourceFiles, | 147 Future createTemp(Uri entryPoint, Map<String, String> memorySourceFiles, |
| 144 {bool printSteps: false}) async { | 148 {bool printSteps: false}) async { |
| 145 if (memorySourceFiles.isNotEmpty) { | 149 if (memorySourceFiles.isNotEmpty) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 CompilerOutput compilerOutput, | 185 CompilerOutput compilerOutput, |
| 182 void beforeRun(Compiler compiler)}) async { | 186 void beforeRun(Compiler compiler)}) async { |
| 183 Uri dillFile = | 187 Uri dillFile = |
| 184 await generateDill(entryPoint, memorySourceFiles, printSteps: printSteps); | 188 await generateDill(entryPoint, memorySourceFiles, printSteps: printSteps); |
| 185 | 189 |
| 186 if (printSteps) { | 190 if (printSteps) { |
| 187 print('---- compile from dill $dillFile ---------------------------------'); | 191 print('---- compile from dill $dillFile ---------------------------------'); |
| 188 } | 192 } |
| 189 Compiler compiler = compilerFor( | 193 Compiler compiler = compilerFor( |
| 190 entryPoint: dillFile, | 194 entryPoint: dillFile, |
| 191 options: [Flags.loadFromDill]..addAll(options), | 195 options: [Flags.useKernel]..addAll(options), |
| 192 outputProvider: compilerOutput); | 196 outputProvider: compilerOutput); |
| 193 ElementResolutionWorldBuilder.useInstantiationMap = true; | 197 ElementResolutionWorldBuilder.useInstantiationMap = true; |
| 194 compiler.resolution.retainCachesForTesting = true; | 198 compiler.resolution.retainCachesForTesting = true; |
| 195 if (beforeRun != null) { | 199 if (beforeRun != null) { |
| 196 beforeRun(compiler); | 200 beforeRun(compiler); |
| 197 } | 201 } |
| 198 await compiler.run(dillFile); | 202 await compiler.run(dillFile); |
| 199 return compiler; | 203 return compiler; |
| 200 } | 204 } |
| OLD | NEW |