Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(256)

Side by Side Diff: tests/compiler/dart2js/serialization_analysis_test.dart

Issue 1856713002: Test ResolutionImpact equivalence. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updated cf. comments Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 library dart2js.serialization_analysis_test; 5 library dart2js.serialization_analysis_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'package:async_helper/async_helper.dart'; 8 import 'package:async_helper/async_helper.dart';
9 import 'package:expect/expect.dart'; 9 import 'package:expect/expect.dart';
10 import 'package:compiler/src/commandline_options.dart'; 10 import 'package:compiler/src/commandline_options.dart';
11 import 'package:compiler/src/common/backend_api.dart'; 11 import 'package:compiler/src/common/backend_api.dart';
12 import 'package:compiler/src/common/names.dart'; 12 import 'package:compiler/src/common/names.dart';
13 import 'package:compiler/src/common/resolution.dart';
14 import 'package:compiler/src/compiler.dart'; 13 import 'package:compiler/src/compiler.dart';
15 import 'package:compiler/src/elements/elements.dart';
16 import 'package:compiler/src/filenames.dart'; 14 import 'package:compiler/src/filenames.dart';
17 import 'package:compiler/src/serialization/element_serialization.dart';
18 import 'package:compiler/src/serialization/impact_serialization.dart';
19 import 'package:compiler/src/serialization/json_serializer.dart';
20 import 'package:compiler/src/serialization/serialization.dart';
21 import 'package:compiler/src/serialization/task.dart';
22 import 'package:compiler/src/universe/world_impact.dart';
23 import 'memory_compiler.dart'; 15 import 'memory_compiler.dart';
16 import 'serialization_helper.dart';
24 17
25 const List<Test> TESTS = const <Test>[ 18 const List<Test> TESTS = const <Test>[
26 const Test(const { 19 const Test(const {
27 'main.dart': 'main() => print("Hello World");' 20 'main.dart': 'main() => print("Hello World");'
28 }), 21 }),
29 22
30 const Test(const { 23 const Test(const {
31 'main.dart': 'main() => print("Hello World", 0);' 24 'main.dart': 'main() => print("Hello World", 0);'
32 }, 25 },
33 expectedWarningCount: 1, 26 expectedWarningCount: 1,
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 } 228 }
236 229
237 Future analyze(String serializedData, Uri entryPoint, Test test) async { 230 Future analyze(String serializedData, Uri entryPoint, Test test) async {
238 DiagnosticCollector diagnosticCollector = new DiagnosticCollector(); 231 DiagnosticCollector diagnosticCollector = new DiagnosticCollector();
239 await runCompiler( 232 await runCompiler(
240 entryPoint: entryPoint, 233 entryPoint: entryPoint,
241 memorySourceFiles: test != null ? test.sourceFiles : const {}, 234 memorySourceFiles: test != null ? test.sourceFiles : const {},
242 options: [Flags.analyzeOnly], 235 options: [Flags.analyzeOnly],
243 diagnosticHandler: diagnosticCollector, 236 diagnosticHandler: diagnosticCollector,
244 beforeRun: (Compiler compiler) { 237 beforeRun: (Compiler compiler) {
245 Deserializer deserializer = new Deserializer.fromText( 238 deserialize(compiler, serializedData);
246 new DeserializationContext(),
247 serializedData,
248 const JsonSerializationDecoder());
249 deserializer.plugins.add(compiler.backend.serialization.deserializer);
250 compiler.serialization.deserializer =
251 new _DeserializerSystem(
252 deserializer,
253 compiler.backend.impactTransformer);
254 }); 239 });
255 if (test != null) { 240 if (test != null) {
256 Expect.equals(test.expectedErrorCount, diagnosticCollector.errors.length, 241 Expect.equals(test.expectedErrorCount, diagnosticCollector.errors.length,
257 "Unexpected error count."); 242 "Unexpected error count.");
258 Expect.equals( 243 Expect.equals(
259 test.expectedWarningCount, 244 test.expectedWarningCount,
260 diagnosticCollector.warnings.length, 245 diagnosticCollector.warnings.length,
261 "Unexpected warning count."); 246 "Unexpected warning count.");
262 Expect.equals(test.expectedHintCount, diagnosticCollector.hints.length, 247 Expect.equals(test.expectedHintCount, diagnosticCollector.hints.length,
263 "Unexpected hint count."); 248 "Unexpected hint count.");
264 Expect.equals(test.expectedInfoCount, diagnosticCollector.infos.length, 249 Expect.equals(test.expectedInfoCount, diagnosticCollector.infos.length,
265 "Unexpected info count."); 250 "Unexpected info count.");
266 } 251 }
267 } 252 }
268 253
269 Future<String> serializeDartCore() async {
270 Compiler compiler = compilerFor(
271 options: [Flags.analyzeAll]);
272 compiler.serialization.supportSerialization = true;
273 await compiler.run(Uris.dart_core);
274 return serialize(compiler);
275 }
276
277 String serialize(Compiler compiler) {
278 Serializer serializer = new Serializer();
279 serializer.plugins.add(compiler.backend.serialization.serializer);
280 serializer.plugins.add(new ResolutionImpactSerializer(compiler.resolution));
281
282 for (LibraryElement library in compiler.libraryLoader.libraries) {
283 serializer.serialize(library);
284 }
285 return serializer.toText(const JsonSerializationEncoder());
286 }
287
288 const String WORLD_IMPACT_TAG = 'worldImpact';
289
290 class ResolutionImpactSerializer extends SerializerPlugin {
291 final Resolution resolution;
292
293 ResolutionImpactSerializer(this.resolution);
294
295 @override
296 void onElement(Element element, ObjectEncoder createEncoder(String tag)) {
297 if (resolution.hasBeenResolved(element)) {
298 ResolutionImpact impact = resolution.getResolutionImpact(element);
299 ObjectEncoder encoder = createEncoder(WORLD_IMPACT_TAG);
300 new ImpactSerializer(encoder).serialize(impact);
301 }
302 }
303 }
304
305 class ResolutionImpactDeserializer extends DeserializerPlugin {
306 Map<Element, ResolutionImpact> impactMap = <Element, ResolutionImpact>{};
307
308 @override
309 void onElement(Element element, ObjectDecoder getDecoder(String tag)) {
310 ObjectDecoder decoder = getDecoder(WORLD_IMPACT_TAG);
311 if (decoder != null) {
312 impactMap[element] = ImpactDeserializer.deserializeImpact(decoder);
313 }
314 }
315 }
316
317 class _DeserializerSystem extends DeserializerSystem {
318 final Deserializer _deserializer;
319 final List<LibraryElement> deserializedLibraries = <LibraryElement>[];
320 final ResolutionImpactDeserializer _resolutionImpactDeserializer =
321 new ResolutionImpactDeserializer();
322 final ImpactTransformer _impactTransformer;
323
324 _DeserializerSystem(this._deserializer, this._impactTransformer) {
325 _deserializer.plugins.add(_resolutionImpactDeserializer);
326 }
327
328 LibraryElement readLibrary(Uri resolvedUri) {
329 LibraryElement library = _deserializer.lookupLibrary(resolvedUri);
330 if (library != null) {
331 deserializedLibraries.add(library);
332 }
333 return library;
334 }
335
336 @override
337 WorldImpact computeWorldImpact(Element element) {
338 ResolutionImpact resolutionImpact =
339 _resolutionImpactDeserializer.impactMap[element];
340 if (resolutionImpact == null) {
341 print('No impact found for $element (${element.library})');
342 return const WorldImpact();
343 } else {
344 return _impactTransformer.transformResolutionImpact(resolutionImpact);
345 }
346 }
347
348 @override
349 bool isDeserialized(Element element) {
350 return deserializedLibraries.contains(element.library);
351 }
352 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/mock_compiler.dart ('k') | tests/compiler/dart2js/serialization_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698