| Index: tests/compiler/dart2js/serialization_analysis_test.dart
|
| diff --git a/tests/compiler/dart2js/serialization_analysis_test.dart b/tests/compiler/dart2js/serialization_analysis_test.dart
|
| index 897b6a5b504a6aa481a450584d88e482dca08819..0c1923f12e6a3cdaf80c6bf5b274376f4969246b 100644
|
| --- a/tests/compiler/dart2js/serialization_analysis_test.dart
|
| +++ b/tests/compiler/dart2js/serialization_analysis_test.dart
|
| @@ -8,11 +8,14 @@ import 'dart:async';
|
| import 'package:async_helper/async_helper.dart';
|
| import 'package:expect/expect.dart';
|
| import 'package:compiler/src/commandline_options.dart';
|
| -import 'package:compiler/src/elements/elements.dart';
|
| +import 'package:compiler/src/common/resolution.dart';
|
| import 'package:compiler/src/compiler.dart';
|
| +import 'package:compiler/src/elements/elements.dart';
|
| import 'package:compiler/src/filenames.dart';
|
| -import 'package:compiler/src/serialization/serialization.dart';
|
| +import 'package:compiler/src/serialization/element_serialization.dart';
|
| +import 'package:compiler/src/serialization/impact_serialization.dart';
|
| import 'package:compiler/src/serialization/json_serializer.dart';
|
| +import 'package:compiler/src/serialization/serialization.dart';
|
| import 'package:compiler/src/serialization/task.dart';
|
| import 'package:compiler/src/universe/world_impact.dart';
|
| import 'memory_compiler.dart';
|
| @@ -142,6 +145,58 @@ main() {
|
| },
|
| expectedWarningCount: 1,
|
| expectedInfoCount: 1),
|
| +
|
| + const Test(const {
|
| + 'main.dart': r'''
|
| +import 'dart:math';
|
| +
|
| +class MyRandom implements Random {
|
| + int nextInt(int max) {
|
| + return max.length;
|
| + }
|
| + bool nextBool() => true;
|
| + double nextDouble() => 0.0;
|
| +}
|
| +main() {
|
| + new MyRandom().nextInt(0);
|
| +}'''
|
| + },
|
| + expectedWarningCount: 1,
|
| + expectedInfoCount: 0),
|
| +
|
| + const Test(const {
|
| + 'main.dart': r'''
|
| +import 'dart:math';
|
| +
|
| +class MyRandom implements Random {
|
| + int nextInt(int max) {
|
| + return max.length;
|
| + }
|
| + bool nextBool() => true;
|
| + double nextDouble() => 0.0;
|
| +}
|
| +main() {
|
| + new MyRandom();
|
| +}'''
|
| + }),
|
| +
|
| + const Test(const {
|
| + 'main.dart': r'''
|
| +import 'dart:math';
|
| +
|
| +class MyRandom implements Random {
|
| + int nextInt(int max) {
|
| + return max.length;
|
| + }
|
| + bool nextBool() => true;
|
| + double nextDouble() => 0.0;
|
| +}
|
| +main() {
|
| + [].shuffle(new MyRandom());
|
| +}'''
|
| + },
|
| + expectedWarningCount: 1,
|
| + expectedInfoCount: 0),
|
| ];
|
|
|
| main(List<String> arguments) {
|
| @@ -175,8 +230,6 @@ class Test {
|
| }
|
|
|
| Future analyze(String serializedData, Uri entryPoint, Test test) async {
|
| - Deserializer deserializer = new Deserializer.fromText(
|
| - serializedData, const JsonSerializationDecoder());
|
| DiagnosticCollector diagnosticCollector = new DiagnosticCollector();
|
| await runCompiler(
|
| entryPoint: entryPoint,
|
| @@ -184,6 +237,10 @@ Future analyze(String serializedData, Uri entryPoint, Test test) async {
|
| options: [Flags.analyzeOnly],
|
| diagnosticHandler: diagnosticCollector,
|
| beforeRun: (Compiler compiler) {
|
| + Deserializer deserializer = new Deserializer.fromText(
|
| + serializedData,
|
| + const JsonSerializationDecoder());
|
| + deserializer.plugins.add(compiler.backend.serialization.deserializer);
|
| compiler.serialization.deserializer =
|
| new _DeserializerSystem(deserializer);
|
| });
|
| @@ -205,22 +262,58 @@ Future<String> serializeDartCore() async {
|
| Compiler compiler = compilerFor(
|
| options: ['--analyze-all']);
|
| await compiler.run(Uri.parse('dart:core'));
|
| - return serialize(compiler.libraryLoader.libraries);
|
| + return serialize(compiler);
|
| }
|
|
|
| -String serialize(Iterable<LibraryElement> libraries) {
|
| +String serialize(Compiler compiler) {
|
| Serializer serializer = new Serializer(const JsonSerializationEncoder());
|
| - for (LibraryElement library in libraries) {
|
| + serializer.plugins.add(compiler.backend.serialization.serializer);
|
| + serializer.plugins.add(new WorldImpactSerializer(compiler.resolution));
|
| +
|
| + for (LibraryElement library in compiler.libraryLoader.libraries) {
|
| serializer.serialize(library);
|
| }
|
| return serializer.toText();
|
| }
|
|
|
| +const String WORLD_IMPACT_TAG = 'worldImpact';
|
| +
|
| +class WorldImpactSerializer extends SerializerPlugin {
|
| + final Resolution resolution;
|
| +
|
| + WorldImpactSerializer(this.resolution);
|
| +
|
| + @override
|
| + void onElement(Element element, ObjectEncoder createEncoder(String tag)) {
|
| + if (resolution.hasBeenResolved(element)) {
|
| + WorldImpact impact = resolution.getWorldImpact(element);
|
| + ObjectEncoder encoder = createEncoder(WORLD_IMPACT_TAG);
|
| + impact.apply(new ImpactSerializer(encoder));
|
| + }
|
| + }
|
| +}
|
| +
|
| +class WorldImpactDeserializer extends DeserializerPlugin {
|
| + Map<Element, WorldImpact> impactMap = <Element, WorldImpact>{};
|
| +
|
| + @override
|
| + void onElement(Element element, ObjectDecoder getDecoder(String tag)) {
|
| + ObjectDecoder decoder = getDecoder(WORLD_IMPACT_TAG);
|
| + if (decoder != null) {
|
| + impactMap[element] = ImpactDeserializer.deserializeImpact(decoder);
|
| + }
|
| + }
|
| +}
|
| +
|
| class _DeserializerSystem extends DeserializerSystem {
|
| final Deserializer _deserializer;
|
| final List<LibraryElement> deserializedLibraries = <LibraryElement>[];
|
| + final WorldImpactDeserializer _worldImpactDeserializer =
|
| + new WorldImpactDeserializer();
|
|
|
| - _DeserializerSystem(this._deserializer);
|
| + _DeserializerSystem(this._deserializer) {
|
| + _deserializer.plugins.add(_worldImpactDeserializer);
|
| + }
|
|
|
| LibraryElement readLibrary(Uri resolvedUri) {
|
| LibraryElement library = _deserializer.lookupLibrary(resolvedUri);
|
| @@ -232,11 +325,16 @@ class _DeserializerSystem extends DeserializerSystem {
|
|
|
| @override
|
| WorldImpact computeWorldImpact(Element element) {
|
| - return const WorldImpact();
|
| + WorldImpact impact = _worldImpactDeserializer.impactMap[element];
|
| + if (impact == null) {
|
| + print('No impact found for $element (${element.library})');
|
| + impact = const WorldImpact();
|
| + }
|
| + return impact;
|
| }
|
|
|
| @override
|
| bool isDeserialized(Element element) {
|
| return deserializedLibraries.contains(element.library);
|
| }
|
| -}
|
| +}
|
|
|