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

Unified Diff: tests/compiler/dart2js/serialization/test_helper.dart

Issue 2668623003: Check equivalence on impact computed with KernelWorldBuilder. (Closed)
Patch Set: Created 3 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/compiler/dart2js/kernel/impact_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js/serialization/test_helper.dart
diff --git a/tests/compiler/dart2js/serialization/test_helper.dart b/tests/compiler/dart2js/serialization/test_helper.dart
index 813700da1b6e95cf6060de008773113271b10947..7d32dd7aa0969cffd450fa346dd9ba3f59203456 100644
--- a/tests/compiler/dart2js/serialization/test_helper.dart
+++ b/tests/compiler/dart2js/serialization/test_helper.dart
@@ -8,13 +8,14 @@ import 'dart:collection';
import 'package:compiler/src/common/resolution.dart';
import 'package:compiler/src/constants/expressions.dart';
import 'package:compiler/src/constants/values.dart';
+import 'package:compiler/src/compiler.dart';
+import 'package:compiler/src/elements/elements.dart';
import 'package:compiler/src/elements/entities.dart';
import 'package:compiler/src/elements/resolution_types.dart';
import 'package:compiler/src/elements/types.dart';
-import 'package:compiler/src/compiler.dart';
-import 'package:compiler/src/elements/elements.dart';
+import 'package:compiler/src/kernel/elements.dart';
+import 'package:compiler/src/kernel/world_builder.dart';
import 'package:compiler/src/serialization/equivalence.dart';
-import 'package:compiler/src/tree/nodes.dart';
import 'package:expect/expect.dart';
import 'test_data.dart';
@@ -434,7 +435,8 @@ void checkImpacts(
throw 'Missing impact for $member2. $member1 has $impact1';
}
- testResolutionImpactEquivalence(impact1, impact2, const CheckStrategy());
+ testResolutionImpactEquivalence(impact1, impact2,
+ strategy: const CheckStrategy());
}
void checkSets(
@@ -630,3 +632,158 @@ List<String> testSegment(int index, int count, int skip) {
return [segmentNumber(index - 1), segmentNumber(index)];
}
}
+
+class KernelEquivalence {
+ final WorldDeconstructionForTesting testing;
+
+ KernelEquivalence(KernelWorldBuilder builder)
+ : testing = new WorldDeconstructionForTesting(builder);
+
+ TestStrategy get defaultStrategy => new TestStrategy(
+ elementEquivalence: entityEquivalence, typeEquivalence: typeEquivalence);
+
+ bool entityEquivalence(Element a, Entity b, {TestStrategy strategy}) {
+ if (identical(a, b)) return true;
+ if (a == null || b == null) return false;
+ strategy ??= defaultStrategy;
+ switch (a.kind) {
+ case ElementKind.GENERATIVE_CONSTRUCTOR:
+ if (b is KGenerativeConstructor) {
+ return strategy.test(a, b, 'name', a.name, b.name) &&
+ strategy.testElements(
+ a, b, 'enclosingClass', a.enclosingClass, b.enclosingClass);
+ }
+ return false;
+ case ElementKind.FACTORY_CONSTRUCTOR:
+ if (b is KFactoryConstructor) {
+ return strategy.test(a, b, 'name', a.name, b.name) &&
+ strategy.testElements(
+ a, b, 'enclosingClass', a.enclosingClass, b.enclosingClass);
+ }
+ return false;
+ case ElementKind.CLASS:
+ if (b is KClass) {
+ return strategy.test(a, b, 'name', a.name, b.name) &&
+ strategy.testElements(
+ a, b, 'library', a.library, testing.getLibraryForClass(b));
+ }
+ return false;
+ case ElementKind.LIBRARY:
+ if (b is KLibrary) {
+ LibraryElement libraryA = a;
+ return libraryA.canonicalUri == testing.getLibraryUri(b);
+ }
+ return false;
+ case ElementKind.FUNCTION:
+ if (b is KMethod) {
+ if (!strategy.test(a, b, 'name', a.name, b.name)) return false;
+ if (b.enclosingClass != null) {
+ return strategy.testElements(
+ a, b, 'enclosingClass', a.enclosingClass, b.enclosingClass);
+ } else {
+ return strategy.testElements(
+ a, b, 'library', a.library, testing.getLibraryForFunction(b));
+ }
+ } else if (b is KLocalFunction) {
+ LocalFunctionElement aLocalFunction = a;
+ return strategy.test(a, b, 'name', a.name, b.name ?? '') &&
+ strategy.testElements(a, b, 'executableContext',
+ aLocalFunction.executableContext, b.executableContext) &&
+ strategy.testElements(a, b, 'memberContext',
+ aLocalFunction.memberContext, b.memberContext);
+ }
+ return false;
+ case ElementKind.GETTER:
+ if (b is KGetter) {
+ if (!strategy.test(a, b, 'name', a.name, b.name)) return false;
+ if (b.enclosingClass != null) {
+ return strategy.testElements(
+ a, b, 'enclosingClass', a.enclosingClass, b.enclosingClass);
+ } else {
+ return strategy.testElements(
+ a, b, 'library', a.library, testing.getLibraryForFunction(b));
+ }
+ }
+ return false;
+ case ElementKind.SETTER:
+ if (b is KSetter) {
+ if (!strategy.test(a, b, 'name', a.name, b.name)) return false;
+ if (b.enclosingClass != null) {
+ return strategy.testElements(
+ a, b, 'enclosingClass', a.enclosingClass, b.enclosingClass);
+ } else {
+ return strategy.testElements(
+ a, b, 'library', a.library, testing.getLibraryForFunction(b));
+ }
+ }
+ return false;
+ case ElementKind.FIELD:
+ if (b is KField) {
+ if (!strategy.test(a, b, 'name', a.name, b.name)) return false;
+ if (b.enclosingClass != null) {
+ return strategy.testElements(
+ a, b, 'enclosingClass', a.enclosingClass, b.enclosingClass);
+ } else {
+ return strategy.testElements(
+ a, b, 'library', a.library, testing.getLibraryForField(b));
+ }
+ }
+ return false;
+ case ElementKind.TYPE_VARIABLE:
+ if (b is KTypeVariable) {
+ TypeVariableElement aElement = a;
+ return strategy.test(a, b, 'index', aElement.index, b.index) &&
+ strategy.testElements(a, b, 'typeDeclaration',
+ aElement.typeDeclaration, b.typeDeclaration);
+ }
+ return false;
+ default:
+ throw new UnsupportedError('Unsupported equivalence: '
+ '$a (${a.runtimeType}) vs $b (${b.runtimeType})');
+ }
+ }
+
+ bool typeEquivalence(ResolutionDartType a, DartType b,
+ {TestStrategy strategy}) {
+ if (identical(a, b)) return true;
+ if (a == null || b == null) return false;
+ strategy ??= defaultStrategy;
+ switch (a.kind) {
+ case ResolutionTypeKind.DYNAMIC:
+ return b is DynamicType;
+ case ResolutionTypeKind.VOID:
+ return b is VoidType;
+ case ResolutionTypeKind.INTERFACE:
+ if (b is InterfaceType) {
+ ResolutionInterfaceType aType = a;
+ return strategy.testElements(a, b, 'element', a.element, b.element) &&
+ strategy.testTypeLists(
+ a, b, 'typeArguments', aType.typeArguments, b.typeArguments);
+ }
+ return false;
+ case ResolutionTypeKind.TYPE_VARIABLE:
+ if (b is TypeVariableType) {
+ return strategy.testElements(a, b, 'element', a.element, b.element);
+ }
+ return false;
+ case ResolutionTypeKind.FUNCTION:
+ if (b is FunctionType) {
+ ResolutionFunctionType aType = a;
+ return strategy.testTypes(
+ a, b, 'returnType', aType.returnType, b.returnType) &&
+ strategy.testTypeLists(a, b, 'parameterTypes',
+ aType.parameterTypes, b.parameterTypes) &&
+ strategy.testTypeLists(a, b, 'optionalParameterTypes',
+ aType.optionalParameterTypes, b.optionalParameterTypes) &&
+ strategy.testLists(a, b, 'namedParameters', aType.namedParameters,
+ b.namedParameters) &&
+ strategy.testTypeLists(a, b, 'namedParameterTypes',
+ aType.namedParameterTypes, b.namedParameterTypes);
+ }
+ return false;
+ default:
+ throw new UnsupportedError('Unsupported equivalence: '
+ '$a (${a.runtimeType}) vs $b (${b.runtimeType})');
+ }
+ }
+}
« no previous file with comments | « tests/compiler/dart2js/kernel/impact_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698