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

Side by Side Diff: tests/compiler/dart2js/serialization/model_test_helper.dart

Issue 2506393002: Enhance precision of recorded instantiation info in ResolutionWorldBuilder (Closed)
Patch Set: Updated cf. comments. Created 4 years, 1 month 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_model_test; 5 library dart2js.serialization_model_test;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:io'; 8 import 'dart:io';
9 import 'package:async_helper/async_helper.dart'; 9 import 'package:async_helper/async_helper.dart';
10 import 'package:expect/expect.dart'; 10 import 'package:expect/expect.dart';
11 import 'package:compiler/src/closure.dart'; 11 import 'package:compiler/src/closure.dart';
12 import 'package:compiler/src/commandline_options.dart'; 12 import 'package:compiler/src/commandline_options.dart';
13 import 'package:compiler/src/common.dart'; 13 import 'package:compiler/src/common.dart';
14 import 'package:compiler/src/constants/values.dart'; 14 import 'package:compiler/src/constants/values.dart';
15 import 'package:compiler/src/compiler.dart'; 15 import 'package:compiler/src/compiler.dart';
16 import 'package:compiler/src/dart_types.dart'; 16 import 'package:compiler/src/dart_types.dart';
17 import 'package:compiler/src/deferred_load.dart'; 17 import 'package:compiler/src/deferred_load.dart';
18 import 'package:compiler/src/elements/elements.dart'; 18 import 'package:compiler/src/elements/elements.dart';
19 import 'package:compiler/src/enqueue.dart'; 19 import 'package:compiler/src/enqueue.dart';
20 import 'package:compiler/src/filenames.dart'; 20 import 'package:compiler/src/filenames.dart';
21 import 'package:compiler/src/js_backend/js_backend.dart'; 21 import 'package:compiler/src/js_backend/js_backend.dart';
22 import 'package:compiler/src/serialization/equivalence.dart'; 22 import 'package:compiler/src/serialization/equivalence.dart';
23 import 'package:compiler/src/tree/nodes.dart'; 23 import 'package:compiler/src/tree/nodes.dart';
24 import 'package:compiler/src/universe/class_set.dart'; 24 import 'package:compiler/src/universe/class_set.dart';
25 import 'package:compiler/src/universe/world_builder.dart';
26 import 'package:compiler/src/util/enumset.dart';
25 import 'package:compiler/src/world.dart' show ClosedWorld; 27 import 'package:compiler/src/world.dart' show ClosedWorld;
26 import '../memory_compiler.dart'; 28 import '../memory_compiler.dart';
27 import 'helper.dart'; 29 import 'helper.dart';
28 import 'test_data.dart'; 30 import 'test_data.dart';
29 import 'test_helper.dart'; 31 import 'test_helper.dart';
30 32
31 /// Number of tests that are not part of the automatic test grouping. 33 /// Number of tests that are not part of the automatic test grouping.
32 int SKIP_COUNT = 2; 34 int SKIP_COUNT = 2;
33 35
34 /// Number of groups that the [TESTS] are split into. 36 /// Number of groups that the [TESTS] are split into.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 compilerNormal.closedWorld, compilerDeserialized.closedWorld, 102 compilerNormal.closedWorld, compilerDeserialized.closedWorld,
101 verbose: verbose); 103 verbose: verbose);
102 checkBackendInfo(compilerNormal, compilerDeserialized, verbose: verbose); 104 checkBackendInfo(compilerNormal, compilerDeserialized, verbose: verbose);
103 }); 105 });
104 } 106 }
105 107
106 void checkResolutionEnqueuers( 108 void checkResolutionEnqueuers(
107 ResolutionEnqueuer enqueuer1, ResolutionEnqueuer enqueuer2, 109 ResolutionEnqueuer enqueuer1, ResolutionEnqueuer enqueuer2,
108 {bool typeEquivalence(DartType a, DartType b): areTypesEquivalent, 110 {bool typeEquivalence(DartType a, DartType b): areTypesEquivalent,
109 bool elementFilter(Element element), 111 bool elementFilter(Element element),
112 bool checkInstantiatedTypesAndClasses: true,
110 bool verbose: false}) { 113 bool verbose: false}) {
111 Iterable<Element> processedElements1 = enqueuer1.processedElements; 114 Iterable<Element> processedElements1 = enqueuer1.processedElements;
112 Iterable<Element> processedElements2 = enqueuer2.processedElements; 115 Iterable<Element> processedElements2 = enqueuer2.processedElements;
113 if (elementFilter != null) { 116 if (elementFilter != null) {
114 processedElements1 = processedElements1.where(elementFilter); 117 processedElements1 = processedElements1.where(elementFilter);
115 processedElements2 = processedElements2.where(elementFilter); 118 processedElements2 = processedElements2.where(elementFilter);
116 } 119 }
117 120
118 checkSets(processedElements1, processedElements2, 121 checkSets(processedElements1, processedElements2,
119 "Processed element mismatch", areElementsEquivalent, 122 "Processed element mismatch", areElementsEquivalent,
120 verbose: verbose); 123 verbose: verbose);
121 124
122 checkSets( 125 /// Normalize the instantiation map by removing redirections and converting
123 enqueuer1.universe.directlyInstantiatedClasses, 126 /// redirecting factories to their effective target.
124 enqueuer2.universe.directlyInstantiatedClasses, 127 Map<ClassElement, InstantiationInfo> createInstantiationMap(
125 "Directly instantiated classes mismatch", 128 ResolutionWorldBuilder worldBuilder) {
129 Map<ClassElement, InstantiationInfo> instantiationMap =
130 <ClassElement, InstantiationInfo>{};
131
132 InstantiationInfo infoFor(ClassElement cls) {
133 return instantiationMap.putIfAbsent(cls, () => new InstantiationInfo());
134 }
135
136 worldBuilder.forEachInstantiatedClass((cls, info) {
137 if (info.instantiationMap != null) {
138 info.instantiationMap
139 .forEach((ConstructorElement constructor, Set<Instance> set) {
140 for (Instance instance in set) {
141 if (instance.isRedirection) {
142 continue;
143 }
144 if (constructor == null || !constructor.isRedirectingFactory) {
145 infoFor(cls)
146 .addInstantiation(constructor, instance.type, instance.kind);
147 } else {
148 ConstructorElement target = constructor.effectiveTarget;
149 InterfaceType targetType =
150 constructor.computeEffectiveTargetType(instance.type);
151 infoFor(targetType.element).addInstantiation(
152 target, targetType, Instantiation.DIRECTLY_INSTANTIATED);
153 }
154 }
155 });
156 }
157 });
158 return instantiationMap;
159 }
160
161 checkMaps(
162 createInstantiationMap(enqueuer1.universe),
163 createInstantiationMap(enqueuer2.universe),
164 "Instantiated classes mismatch",
126 areElementsEquivalent, 165 areElementsEquivalent,
166 (a, b) => areInstantiationInfosEquivalent(a, b, typeEquivalence),
127 verbose: verbose); 167 verbose: verbose);
168 if (checkInstantiatedTypesAndClasses) {
169 checkSets(
170 enqueuer1.universe.directlyInstantiatedClasses,
171 enqueuer2.universe.directlyInstantiatedClasses,
172 "Directly instantiated classes mismatch",
173 areElementsEquivalent,
174 verbose: verbose);
128 175
129 checkSets( 176 checkSets(
130 enqueuer1.universe.instantiatedTypes, 177 enqueuer1.universe.instantiatedTypes,
131 enqueuer2.universe.instantiatedTypes, 178 enqueuer2.universe.instantiatedTypes,
132 "Instantiated types mismatch", 179 "Instantiated types mismatch",
133 typeEquivalence, 180 typeEquivalence,
134 verbose: verbose); 181 verbose: verbose);
182 }
135 183
136 checkSets(enqueuer1.universe.isChecks, enqueuer2.universe.isChecks, 184 checkSets(enqueuer1.universe.isChecks, enqueuer2.universe.isChecks,
137 "Is-check mismatch", typeEquivalence, 185 "Is-check mismatch", typeEquivalence,
138 verbose: verbose); 186 verbose: verbose);
139 187
140 JavaScriptBackend backend1 = enqueuer1.backend; 188 JavaScriptBackend backend1 = enqueuer1.backend;
141 JavaScriptBackend backend2 = enqueuer2.backend; 189 JavaScriptBackend backend2 = enqueuer2.backend;
142 Expect.equals(backend1.hasInvokeOnSupport, backend2.hasInvokeOnSupport, 190 Expect.equals(backend1.hasInvokeOnSupport, backend2.hasInvokeOnSupport,
143 "Compiler.enabledInvokeOn mismatch"); 191 "Compiler.enabledInvokeOn mismatch");
144 Expect.equals( 192 Expect.equals(
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 check(outputUnit1, outputUnit2, 'OutputUnit.isMainOutput $message', 460 check(outputUnit1, outputUnit2, 'OutputUnit.isMainOutput $message',
413 outputUnit1.isMainOutput, outputUnit2.isMainOutput); 461 outputUnit1.isMainOutput, outputUnit2.isMainOutput);
414 checkSetEquivalence( 462 checkSetEquivalence(
415 outputUnit1, 463 outputUnit1,
416 outputUnit2, 464 outputUnit2,
417 'OutputUnit.imports $message', 465 'OutputUnit.imports $message',
418 outputUnit1.imports, 466 outputUnit1.imports,
419 outputUnit2.imports, 467 outputUnit2.imports,
420 (a, b) => areElementsEquivalent(a.declaration, b.declaration)); 468 (a, b) => areElementsEquivalent(a.declaration, b.declaration));
421 } 469 }
470
471 bool areInstantiationInfosEquivalent(InstantiationInfo info1,
472 InstantiationInfo info2, bool typeEquivalence(DartType a, DartType b)) {
473 checkMaps(
474 info1.instantiationMap,
475 info2.instantiationMap,
476 'instantiationMap of\n '
477 '${info1.instantiationMap}\nvs ${info2.instantiationMap}',
478 areElementsEquivalent,
479 (a, b) => areSetsEquivalent(
480 a, b, (a, b) => areInstancesEquivalent(a, b, typeEquivalence)));
481 return true;
482 }
483
484 bool areInstancesEquivalent(Instance instance1, Instance instance2,
485 bool typeEquivalence(DartType a, DartType b)) {
486 return typeEquivalence(instance1.type, instance2.type) &&
487 instance1.kind == instance2.kind &&
488 instance1.isRedirection == instance2.isRedirection;
489 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/kernel/closed_world_test.dart ('k') | tests/compiler/dart2js/serialization/test_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698