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'; | 15 import 'package:compiler/src/common/names.dart'; |
16 import 'package:compiler/src/common/tasks.dart'; | 16 import 'package:compiler/src/common/tasks.dart'; |
17 import 'package:compiler/src/compiler.dart'; | 17 import 'package:compiler/src/compiler.dart'; |
18 import 'package:compiler/src/elements/elements.dart'; | 18 import 'package:compiler/src/elements/elements.dart'; |
19 import 'package:compiler/src/kernel/element_map_impl.dart'; | 19 import 'package:compiler/src/kernel/element_map.dart'; |
20 import 'package:compiler/src/kernel/kernel_strategy.dart'; | 20 import 'package:compiler/src/kernel/kernel_strategy.dart'; |
21 import 'package:compiler/src/library_loader.dart'; | 21 import 'package:compiler/src/library_loader.dart'; |
22 import 'package:compiler/src/universe/world_builder.dart'; | 22 import 'package:compiler/src/universe/world_builder.dart'; |
23 import 'package:compiler/src/util/util.dart'; | 23 import 'package:compiler/src/util/util.dart'; |
24 import 'package:expect/expect.dart'; | 24 import 'package:expect/expect.dart'; |
25 import 'package:kernel/ast.dart' as ir; | 25 import 'package:kernel/ast.dart' as ir; |
26 import '../memory_compiler.dart'; | 26 import '../memory_compiler.dart'; |
27 import '../../../../pkg/compiler/tool/generate_kernel.dart' as generate; | 27 import '../../../../pkg/compiler/tool/generate_kernel.dart' as generate; |
28 | 28 |
29 typedef Future<Compiler> CompileFunction(); | 29 typedef Future<Compiler> CompileFunction(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 entryPoint: uri, | 63 entryPoint: uri, |
64 memorySourceFiles: memorySourceFiles, | 64 memorySourceFiles: memorySourceFiles, |
65 options: [ | 65 options: [ |
66 Flags.analyzeOnly, | 66 Flags.analyzeOnly, |
67 Flags.enableAssertMessage, | 67 Flags.enableAssertMessage, |
68 Flags.loadFromDill | 68 Flags.loadFromDill |
69 ]); | 69 ]); |
70 ElementResolutionWorldBuilder.useInstantiationMap = true; | 70 ElementResolutionWorldBuilder.useInstantiationMap = true; |
71 compiler2.resolution.retainCachesForTesting = true; | 71 compiler2.resolution.retainCachesForTesting = true; |
72 KernelFrontEndStrategy frontendStrategy = compiler2.frontendStrategy; | 72 KernelFrontEndStrategy frontendStrategy = compiler2.frontendStrategy; |
73 KernelToElementMapImpl elementMap = frontendStrategy.elementMap; | 73 KernelToElementMapForImpact elementMap = frontendStrategy.elementMap; |
74 ir.Program program = new ir.Program( | 74 ir.Program program = new ir.Program( |
75 libraries: | 75 libraries: |
76 compiler.backend.kernelTask.kernel.libraryDependencies(uri)); | 76 compiler.backend.kernelTask.kernel.libraryDependencies(uri)); |
77 LibraryElement library = compiler.libraryLoader.lookupLibrary(uri); | 77 LibraryElement library = compiler.libraryLoader.lookupLibrary(uri); |
78 Expect.isNotNull(library, 'No library found for $uri'); | 78 Expect.isNotNull(library, 'No library found for $uri'); |
79 program.mainMethod = compiler.backend.kernelTask.kernel | 79 program.mainMethod = compiler.backend.kernelTask.kernel |
80 .functionToIr(library.findExported(Identifiers.main)); | 80 .functionToIr(library.findExported(Identifiers.main)); |
81 compiler2.libraryLoader = new MemoryDillLibraryLoaderTask( | 81 compiler2.libraryLoader = new MemoryDillLibraryLoaderTask( |
82 elementMap, compiler2.reporter, compiler2.measurer, program); | 82 elementMap, compiler2.reporter, compiler2.measurer, program); |
83 await compiler2.run(uri); | 83 await compiler2.run(uri); |
(...skipping 25 matching lines...) Expand all Loading... |
109 entryPoint: entryPoint, | 109 entryPoint: entryPoint, |
110 memorySourceFiles: memorySourceFiles, | 110 memorySourceFiles: memorySourceFiles, |
111 options: [ | 111 options: [ |
112 Flags.analyzeOnly, | 112 Flags.analyzeOnly, |
113 Flags.enableAssertMessage, | 113 Flags.enableAssertMessage, |
114 Flags.loadFromDill | 114 Flags.loadFromDill |
115 ]); | 115 ]); |
116 ElementResolutionWorldBuilder.useInstantiationMap = true; | 116 ElementResolutionWorldBuilder.useInstantiationMap = true; |
117 compiler2.resolution.retainCachesForTesting = true; | 117 compiler2.resolution.retainCachesForTesting = true; |
118 KernelFrontEndStrategy frontendStrategy = compiler2.frontendStrategy; | 118 KernelFrontEndStrategy frontendStrategy = compiler2.frontendStrategy; |
119 KernelToElementMapImpl elementMap = frontendStrategy.elementMap; | 119 KernelToElementMapForImpact elementMap = frontendStrategy.elementMap; |
120 compiler2.libraryLoader = new MemoryDillLibraryLoaderTask( | 120 compiler2.libraryLoader = new MemoryDillLibraryLoaderTask( |
121 elementMap, | 121 elementMap, |
122 compiler2.reporter, | 122 compiler2.reporter, |
123 compiler2.measurer, | 123 compiler2.measurer, |
124 compiler.backend.kernelTask.program); | 124 compiler.backend.kernelTask.program); |
125 await compiler2.run(entryPoint); | 125 await compiler2.run(entryPoint); |
126 return new Pair<Compiler, Compiler>(compiler, compiler2); | 126 return new Pair<Compiler, Compiler>(compiler, compiler2); |
127 } | 127 } |
128 | 128 |
129 class MemoryDillLibraryLoaderTask extends DillLibraryLoaderTask { | 129 class MemoryDillLibraryLoaderTask extends DillLibraryLoaderTask { |
130 final ir.Program program; | 130 final ir.Program program; |
131 | 131 |
132 MemoryDillLibraryLoaderTask(KernelToElementMapImpl elementMap, | 132 MemoryDillLibraryLoaderTask(KernelToElementMapForImpact elementMap, |
133 DiagnosticReporter reporter, Measurer measurer, this.program) | 133 DiagnosticReporter reporter, Measurer measurer, this.program) |
134 : super(elementMap, null, null, reporter, measurer); | 134 : super(elementMap, null, null, reporter, measurer); |
135 | 135 |
136 Future<LoadedLibraries> loadLibrary(Uri resolvedUri, | 136 Future<LoadedLibraries> loadLibrary(Uri resolvedUri, |
137 {bool skipFileWithPartOfTag: false}) async { | 137 {bool skipFileWithPartOfTag: false}) async { |
138 return createLoadedLibraries(program); | 138 return createLoadedLibraries(program); |
139 } | 139 } |
140 } | 140 } |
141 | 141 |
142 Future createTemp(Uri entryPoint, Map<String, String> memorySourceFiles, | 142 Future createTemp(Uri entryPoint, Map<String, String> memorySourceFiles, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 options: [Flags.loadFromDill]..addAll(options), | 182 options: [Flags.loadFromDill]..addAll(options), |
183 outputProvider: compilerOutput); | 183 outputProvider: compilerOutput); |
184 ElementResolutionWorldBuilder.useInstantiationMap = true; | 184 ElementResolutionWorldBuilder.useInstantiationMap = true; |
185 compiler.resolution.retainCachesForTesting = true; | 185 compiler.resolution.retainCachesForTesting = true; |
186 if (beforeRun != null) { | 186 if (beforeRun != null) { |
187 beforeRun(compiler); | 187 beforeRun(compiler); |
188 } | 188 } |
189 await compiler.run(dillFile); | 189 await compiler.run(dillFile); |
190 return compiler; | 190 return compiler; |
191 } | 191 } |
OLD | NEW |