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

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

Issue 1811173003: Support per-library serialization. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 9 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_test; 5 library dart2js.serialization_test;
6 6
7 import 'dart:io'; 7 import 'dart:io';
8 import 'memory_compiler.dart'; 8 import 'memory_compiler.dart';
9 import 'package:async_helper/async_helper.dart'; 9 import 'package:async_helper/async_helper.dart';
10 import 'package:compiler/src/commandline_options.dart';
10 import 'package:compiler/src/constants/constructors.dart'; 11 import 'package:compiler/src/constants/constructors.dart';
11 import 'package:compiler/src/constants/expressions.dart'; 12 import 'package:compiler/src/constants/expressions.dart';
12 import 'package:compiler/src/dart_types.dart'; 13 import 'package:compiler/src/dart_types.dart';
13 import 'package:compiler/src/compiler.dart'; 14 import 'package:compiler/src/compiler.dart';
14 import 'package:compiler/src/diagnostics/invariant.dart'; 15 import 'package:compiler/src/diagnostics/invariant.dart';
15 import 'package:compiler/src/elements/elements.dart'; 16 import 'package:compiler/src/elements/elements.dart';
16 import 'package:compiler/src/elements/visitor.dart'; 17 import 'package:compiler/src/elements/visitor.dart';
17 import 'package:compiler/src/ordered_typeset.dart'; 18 import 'package:compiler/src/ordered_typeset.dart';
18 import 'package:compiler/src/serialization/element_serialization.dart'; 19 import 'package:compiler/src/serialization/element_serialization.dart';
19 import 'package:compiler/src/serialization/json_serializer.dart'; 20 import 'package:compiler/src/serialization/json_serializer.dart';
(...skipping 20 matching lines...) Expand all
40 print("Multiple entrypoints is not supported."); 41 print("Multiple entrypoints is not supported.");
41 } 42 }
42 entryPoint = Uri.parse(arg); 43 entryPoint = Uri.parse(arg);
43 } 44 }
44 } 45 }
45 if (entryPoint == null) { 46 if (entryPoint == null) {
46 entryPoint = Uri.parse('dart:core'); 47 entryPoint = Uri.parse('dart:core');
47 } 48 }
48 asyncTest(() async { 49 asyncTest(() async {
49 CompilationResult result = await runCompiler( 50 CompilationResult result = await runCompiler(
50 entryPoint: entryPoint, options: ['--analyze-all']); 51 entryPoint: entryPoint, options: [Flags.analyzeAll]);
51 Compiler compiler = result.compiler; 52 Compiler compiler = result.compiler;
52 testSerialization(compiler.libraryLoader.libraries, 53 testSerialization(compiler.libraryLoader.libraries,
53 outPath: outPath, 54 outPath: outPath,
54 prettyPrint: prettyPrint); 55 prettyPrint: prettyPrint);
55 }); 56 });
56 } 57 }
57 58
58 void testSerialization(Iterable<LibraryElement> libraries1, 59 void testSerialization(Iterable<LibraryElement> libraries1,
59 {String outPath, 60 {String outPath,
60 bool prettyPrint}) { 61 bool prettyPrint}) {
61 Serializer serializer = new Serializer(const JsonSerializationEncoder()); 62 Serializer serializer = new Serializer();
62 for (LibraryElement library1 in libraries1) { 63 for (LibraryElement library1 in libraries1) {
63 serializer.serialize(library1); 64 serializer.serialize(library1);
64 } 65 }
65 String text = serializer.toText(); 66 String text = serializer.toText(const JsonSerializationEncoder());
66 String outText = text; 67 String outText = text;
67 if (prettyPrint) { 68 if (prettyPrint) {
68 outText = serializer.prettyPrint(); 69 outText = serializer.prettyPrint();
69 } 70 }
70 if (outPath != null) { 71 if (outPath != null) {
71 new File(outPath).writeAsStringSync(outText); 72 new File(outPath).writeAsStringSync(outText);
72 } else if (prettyPrint) { 73 } else if (prettyPrint) {
73 print(outText); 74 print(outText);
74 } 75 }
75 76
76 Deserializer deserializer = new Deserializer.fromText( 77 Deserializer deserializer = new Deserializer.fromText(
78 new DeserializationContext(),
77 text, const JsonSerializationDecoder()); 79 text, const JsonSerializationDecoder());
78 List<LibraryElement> libraries2 = <LibraryElement>[]; 80 List<LibraryElement> libraries2 = <LibraryElement>[];
79 for (LibraryElement library1 in libraries1) { 81 for (LibraryElement library1 in libraries1) {
80 LibraryElement library2 = 82 LibraryElement library2 =
81 deserializer.lookupLibrary(library1.canonicalUri); 83 deserializer.lookupLibrary(library1.canonicalUri);
82 if (library2 == null) { 84 if (library2 == null) {
83 throw new ArgumentError('No library ${library1.canonicalUri} found.'); 85 throw new ArgumentError('No library ${library1.canonicalUri} found.');
84 } 86 }
85 checkLibraryContent('library1', 'library2', 'library', library1, library2); 87 checkLibraryContent('library1', 'library2', 'library', library1, library2);
86 libraries2.add(library2); 88 libraries2.add(library2);
87 } 89 }
88 90
89 Serializer serializer2 = new Serializer(const JsonSerializationEncoder()); 91 Serializer serializer2 = new Serializer();
90 for (LibraryElement library2 in libraries2) { 92 for (LibraryElement library2 in libraries2) {
91 serializer2.serialize(library2); 93 serializer2.serialize(library2);
92 } 94 }
93 String text2 = serializer2.toText(); 95 String text2 = serializer2.toText(const JsonSerializationEncoder());
94 96
95 Deserializer deserializer3 = new Deserializer.fromText( 97 Deserializer deserializer3 = new Deserializer.fromText(
98 new DeserializationContext(),
96 text2, const JsonSerializationDecoder()); 99 text2, const JsonSerializationDecoder());
97 for (LibraryElement library1 in libraries1) { 100 for (LibraryElement library1 in libraries1) {
98 LibraryElement library2 = 101 LibraryElement library2 =
99 deserializer.lookupLibrary(library1.canonicalUri); 102 deserializer.lookupLibrary(library1.canonicalUri);
100 if (library2 == null) { 103 if (library2 == null) {
101 throw new ArgumentError('No library ${library1.canonicalUri} found.'); 104 throw new ArgumentError('No library ${library1.canonicalUri} found.');
102 } 105 }
103 LibraryElement library3 = 106 LibraryElement library3 =
104 deserializer3.lookupLibrary(library1.canonicalUri); 107 deserializer3.lookupLibrary(library1.canonicalUri);
105 if (library3 == null) { 108 if (library3 == null) {
(...skipping 20 matching lines...) Expand all
126 Object object1, object2, String property, 129 Object object1, object2, String property,
127 Element element1, Element element2) { 130 Element element1, Element element2) {
128 const ElementPropertyEquivalence().visit(element1, element2); 131 const ElementPropertyEquivalence().visit(element1, element2);
129 } 132 }
130 133
131 /// Check the equivalence of the two lists of elements, [list1] and [list2]. 134 /// Check the equivalence of the two lists of elements, [list1] and [list2].
132 /// 135 ///
133 /// Uses [object1], [object2] and [property] to provide context for failures. 136 /// Uses [object1], [object2] and [property] to provide context for failures.
134 checkElementLists(Object object1, Object object2, String property, 137 checkElementLists(Object object1, Object object2, String property,
135 Iterable<Element> list1, Iterable<Element> list2) { 138 Iterable<Element> list1, Iterable<Element> list2) {
139 //print('checking\n> $list1\n> $list2');
136 checkListEquivalence(object1, object2, property, 140 checkListEquivalence(object1, object2, property,
137 list1, list2, checkElementProperties); 141 list1, list2, checkElementProperties);
138 } 142 }
139 143
140 /// Check equivalence of the two lists, [list1] and [list2], using 144 /// Check equivalence of the two lists, [list1] and [list2], using
141 /// [checkEquivalence] to check the pair-wise equivalence. 145 /// [checkEquivalence] to check the pair-wise equivalence.
142 /// 146 ///
143 /// Uses [object1], [object2] and [property] to provide context for failures. 147 /// Uses [object1], [object2] and [property] to provide context for failures.
144 void checkListEquivalence( 148 void checkListEquivalence(
145 Object object1, Object object2, String property, 149 Object object1, Object object2, String property,
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 void visitElement(Element e, Element arg) { 474 void visitElement(Element e, Element arg) {
471 throw new UnsupportedError("Unsupported element $e"); 475 throw new UnsupportedError("Unsupported element $e");
472 } 476 }
473 477
474 @override 478 @override
475 void visitLibraryElement(LibraryElement element1, LibraryElement element2) { 479 void visitLibraryElement(LibraryElement element1, LibraryElement element2) {
476 checkElementIdentities(null, null, null, element1, element2); 480 checkElementIdentities(null, null, null, element1, element2);
477 check(element1, element2, 'name', element1.name, element2.name); 481 check(element1, element2, 'name', element1.name, element2.name);
478 check(element1, element2, 'libraryName', 482 check(element1, element2, 'libraryName',
479 element1.libraryName, element2.libraryName); 483 element1.libraryName, element2.libraryName);
484 //print('checkingMembers of library ${element1.name}');
480 visitMembers(element1, element2); 485 visitMembers(element1, element2);
481 visit(element1.entryCompilationUnit, element2.entryCompilationUnit); 486 visit(element1.entryCompilationUnit, element2.entryCompilationUnit);
482 487
483 checkElementLists( 488 checkElementLists(
484 element1, element2, 'compilationUnits', 489 element1, element2, 'compilationUnits',
485 LibrarySerializer.getCompilationUnits(element1), 490 LibrarySerializer.getCompilationUnits(element1),
486 LibrarySerializer.getCompilationUnits(element2)); 491 LibrarySerializer.getCompilationUnits(element2));
487 492
488 checkElementListIdentities( 493 checkElementListIdentities(
489 element1, element2, 'imports', 494 element1, element2, 'imports',
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 643
639 List<ConstructorElement> getConstructors(ClassElement cls) { 644 List<ConstructorElement> getConstructors(ClassElement cls) {
640 return cls.implementation.constructors.map((c) => c.declaration).toList(); 645 return cls.implementation.constructors.map((c) => c.declaration).toList();
641 } 646 }
642 647
643 checkElementLists( 648 checkElementLists(
644 element1, element2, 'constructors', 649 element1, element2, 'constructors',
645 getConstructors(element1), 650 getConstructors(element1),
646 getConstructors(element2)); 651 getConstructors(element2));
647 652
653 //print('Checking class members of ${element1} vs ${element2} (${element2.ru ntimeType})');
Siggi Cherem (dart-lang) 2016/03/18 20:00:20 delete this and other commented lines above?
Johnni Winther 2016/03/29 09:05:54 Done.
648 visitMembers(element1, element2); 654 visitMembers(element1, element2);
649 } 655 }
650 656
651 @override 657 @override
652 void visitFieldElement(FieldElement element1, FieldElement element2) { 658 void visitFieldElement(FieldElement element1, FieldElement element2) {
653 checkElementIdentities(null, null, null, element1, element2); 659 checkElementIdentities(null, null, null, element1, element2);
654 check(element1, element2, 'name', 660 check(element1, element2, 'name',
655 element1.name, element2.name); 661 element1.name, element2.name);
656 check(element1, element2, 'sourcePosition', 662 check(element1, element2, 'sourcePosition',
657 element1.sourcePosition, element2.sourcePosition); 663 element1.sourcePosition, element2.sourcePosition);
(...skipping 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 exp1, exp2, 'expression', 1130 exp1, exp2, 'expression',
1125 exp1.expression, exp2.expression); 1131 exp1.expression, exp2.expression);
1126 } 1132 }
1127 1133
1128 @override 1134 @override
1129 visitDeferred(DeferredConstantExpression exp1, 1135 visitDeferred(DeferredConstantExpression exp1,
1130 DeferredConstantExpression exp2) { 1136 DeferredConstantExpression exp2) {
1131 // TODO: implement visitDeferred 1137 // TODO: implement visitDeferred
1132 } 1138 }
1133 } 1139 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698