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