OLD | NEW |
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/names.dart'; | 12 import 'package:compiler/src/common/names.dart'; |
12 import 'package:compiler/src/common/resolution.dart'; | 13 import 'package:compiler/src/common/resolution.dart'; |
13 import 'package:compiler/src/compiler.dart'; | 14 import 'package:compiler/src/compiler.dart'; |
14 import 'package:compiler/src/elements/elements.dart'; | 15 import 'package:compiler/src/elements/elements.dart'; |
15 import 'package:compiler/src/filenames.dart'; | 16 import 'package:compiler/src/filenames.dart'; |
16 import 'package:compiler/src/serialization/element_serialization.dart'; | 17 import 'package:compiler/src/serialization/element_serialization.dart'; |
17 import 'package:compiler/src/serialization/impact_serialization.dart'; | 18 import 'package:compiler/src/serialization/impact_serialization.dart'; |
18 import 'package:compiler/src/serialization/json_serializer.dart'; | 19 import 'package:compiler/src/serialization/json_serializer.dart'; |
19 import 'package:compiler/src/serialization/serialization.dart'; | 20 import 'package:compiler/src/serialization/serialization.dart'; |
20 import 'package:compiler/src/serialization/task.dart'; | 21 import 'package:compiler/src/serialization/task.dart'; |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 memorySourceFiles: test != null ? test.sourceFiles : const {}, | 241 memorySourceFiles: test != null ? test.sourceFiles : const {}, |
241 options: [Flags.analyzeOnly], | 242 options: [Flags.analyzeOnly], |
242 diagnosticHandler: diagnosticCollector, | 243 diagnosticHandler: diagnosticCollector, |
243 beforeRun: (Compiler compiler) { | 244 beforeRun: (Compiler compiler) { |
244 Deserializer deserializer = new Deserializer.fromText( | 245 Deserializer deserializer = new Deserializer.fromText( |
245 new DeserializationContext(), | 246 new DeserializationContext(), |
246 serializedData, | 247 serializedData, |
247 const JsonSerializationDecoder()); | 248 const JsonSerializationDecoder()); |
248 deserializer.plugins.add(compiler.backend.serialization.deserializer); | 249 deserializer.plugins.add(compiler.backend.serialization.deserializer); |
249 compiler.serialization.deserializer = | 250 compiler.serialization.deserializer = |
250 new _DeserializerSystem(deserializer); | 251 new _DeserializerSystem( |
| 252 deserializer, |
| 253 compiler.backend.impactTransformer); |
251 }); | 254 }); |
252 if (test != null) { | 255 if (test != null) { |
253 Expect.equals(test.expectedErrorCount, diagnosticCollector.errors.length, | 256 Expect.equals(test.expectedErrorCount, diagnosticCollector.errors.length, |
254 "Unexpected error count."); | 257 "Unexpected error count."); |
255 Expect.equals( | 258 Expect.equals( |
256 test.expectedWarningCount, | 259 test.expectedWarningCount, |
257 diagnosticCollector.warnings.length, | 260 diagnosticCollector.warnings.length, |
258 "Unexpected warning count."); | 261 "Unexpected warning count."); |
259 Expect.equals(test.expectedHintCount, diagnosticCollector.hints.length, | 262 Expect.equals(test.expectedHintCount, diagnosticCollector.hints.length, |
260 "Unexpected hint count."); | 263 "Unexpected hint count."); |
261 Expect.equals(test.expectedInfoCount, diagnosticCollector.infos.length, | 264 Expect.equals(test.expectedInfoCount, diagnosticCollector.infos.length, |
262 "Unexpected info count."); | 265 "Unexpected info count."); |
263 } | 266 } |
264 } | 267 } |
265 | 268 |
266 Future<String> serializeDartCore() async { | 269 Future<String> serializeDartCore() async { |
267 Compiler compiler = compilerFor( | 270 Compiler compiler = compilerFor( |
268 options: [Flags.analyzeAll]); | 271 options: [Flags.analyzeAll]); |
269 compiler.serialization.supportSerialization = true; | 272 compiler.serialization.supportSerialization = true; |
270 await compiler.run(Uris.dart_core); | 273 await compiler.run(Uris.dart_core); |
271 return serialize(compiler); | 274 return serialize(compiler); |
272 } | 275 } |
273 | 276 |
274 String serialize(Compiler compiler) { | 277 String serialize(Compiler compiler) { |
275 Serializer serializer = new Serializer(); | 278 Serializer serializer = new Serializer(); |
276 serializer.plugins.add(compiler.backend.serialization.serializer); | 279 serializer.plugins.add(compiler.backend.serialization.serializer); |
277 serializer.plugins.add(new WorldImpactSerializer(compiler.resolution)); | 280 serializer.plugins.add(new ResolutionImpactSerializer(compiler.resolution)); |
278 | 281 |
279 for (LibraryElement library in compiler.libraryLoader.libraries) { | 282 for (LibraryElement library in compiler.libraryLoader.libraries) { |
280 serializer.serialize(library); | 283 serializer.serialize(library); |
281 } | 284 } |
282 return serializer.toText(const JsonSerializationEncoder()); | 285 return serializer.toText(const JsonSerializationEncoder()); |
283 } | 286 } |
284 | 287 |
285 const String WORLD_IMPACT_TAG = 'worldImpact'; | 288 const String WORLD_IMPACT_TAG = 'worldImpact'; |
286 | 289 |
287 class WorldImpactSerializer extends SerializerPlugin { | 290 class ResolutionImpactSerializer extends SerializerPlugin { |
288 final Resolution resolution; | 291 final Resolution resolution; |
289 | 292 |
290 WorldImpactSerializer(this.resolution); | 293 ResolutionImpactSerializer(this.resolution); |
291 | 294 |
292 @override | 295 @override |
293 void onElement(Element element, ObjectEncoder createEncoder(String tag)) { | 296 void onElement(Element element, ObjectEncoder createEncoder(String tag)) { |
294 if (resolution.hasBeenResolved(element)) { | 297 if (resolution.hasBeenResolved(element)) { |
295 WorldImpact impact = resolution.getWorldImpact(element); | 298 ResolutionImpact impact = resolution.getResolutionImpact(element); |
296 ObjectEncoder encoder = createEncoder(WORLD_IMPACT_TAG); | 299 ObjectEncoder encoder = createEncoder(WORLD_IMPACT_TAG); |
297 impact.apply(new ImpactSerializer(encoder)); | 300 new ImpactSerializer(encoder).serialize(impact); |
298 } | 301 } |
299 } | 302 } |
300 } | 303 } |
301 | 304 |
302 class WorldImpactDeserializer extends DeserializerPlugin { | 305 class ResolutionImpactDeserializer extends DeserializerPlugin { |
303 Map<Element, WorldImpact> impactMap = <Element, WorldImpact>{}; | 306 Map<Element, ResolutionImpact> impactMap = <Element, ResolutionImpact>{}; |
304 | 307 |
305 @override | 308 @override |
306 void onElement(Element element, ObjectDecoder getDecoder(String tag)) { | 309 void onElement(Element element, ObjectDecoder getDecoder(String tag)) { |
307 ObjectDecoder decoder = getDecoder(WORLD_IMPACT_TAG); | 310 ObjectDecoder decoder = getDecoder(WORLD_IMPACT_TAG); |
308 if (decoder != null) { | 311 if (decoder != null) { |
309 impactMap[element] = ImpactDeserializer.deserializeImpact(decoder); | 312 impactMap[element] = ImpactDeserializer.deserializeImpact(decoder); |
310 } | 313 } |
311 } | 314 } |
312 } | 315 } |
313 | 316 |
314 class _DeserializerSystem extends DeserializerSystem { | 317 class _DeserializerSystem extends DeserializerSystem { |
315 final Deserializer _deserializer; | 318 final Deserializer _deserializer; |
316 final List<LibraryElement> deserializedLibraries = <LibraryElement>[]; | 319 final List<LibraryElement> deserializedLibraries = <LibraryElement>[]; |
317 final WorldImpactDeserializer _worldImpactDeserializer = | 320 final ResolutionImpactDeserializer _resolutionImpactDeserializer = |
318 new WorldImpactDeserializer(); | 321 new ResolutionImpactDeserializer(); |
| 322 final ImpactTransformer _impactTransformer; |
319 | 323 |
320 _DeserializerSystem(this._deserializer) { | 324 _DeserializerSystem(this._deserializer, this._impactTransformer) { |
321 _deserializer.plugins.add(_worldImpactDeserializer); | 325 _deserializer.plugins.add(_resolutionImpactDeserializer); |
322 } | 326 } |
323 | 327 |
324 LibraryElement readLibrary(Uri resolvedUri) { | 328 LibraryElement readLibrary(Uri resolvedUri) { |
325 LibraryElement library = _deserializer.lookupLibrary(resolvedUri); | 329 LibraryElement library = _deserializer.lookupLibrary(resolvedUri); |
326 if (library != null) { | 330 if (library != null) { |
327 deserializedLibraries.add(library); | 331 deserializedLibraries.add(library); |
328 } | 332 } |
329 return library; | 333 return library; |
330 } | 334 } |
331 | 335 |
332 @override | 336 @override |
333 WorldImpact computeWorldImpact(Element element) { | 337 WorldImpact computeWorldImpact(Element element) { |
334 WorldImpact impact = _worldImpactDeserializer.impactMap[element]; | 338 ResolutionImpact resolutionImpact = |
335 if (impact == null) { | 339 _resolutionImpactDeserializer.impactMap[element]; |
| 340 if (resolutionImpact == null) { |
336 print('No impact found for $element (${element.library})'); | 341 print('No impact found for $element (${element.library})'); |
337 impact = const WorldImpact(); | 342 return const WorldImpact(); |
| 343 } else { |
| 344 return _impactTransformer.transformResolutionImpact(resolutionImpact); |
338 } | 345 } |
339 return impact; | |
340 } | 346 } |
341 | 347 |
342 @override | 348 @override |
343 bool isDeserialized(Element element) { | 349 bool isDeserialized(Element element) { |
344 return deserializedLibraries.contains(element.library); | 350 return deserializedLibraries.contains(element.library); |
345 } | 351 } |
346 } | 352 } |
OLD | NEW |