| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 // Partial test that the closed world computed from [WorldImpact]s derived from | 5 // Partial test that the closed world computed from [WorldImpact]s derived from |
| 6 // kernel is equivalent to the original computed from resolution. | 6 // kernel is equivalent to the original computed from resolution. |
| 7 library dart2js.kernel.closed_world_from_dill_test; | 7 library dart2js.kernel.compile_from_dill_test; |
| 8 | 8 |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| 11 | 11 |
| 12 import 'package:async_helper/async_helper.dart'; | 12 import 'package:async_helper/async_helper.dart'; |
| 13 import 'package:compiler/compiler_new.dart'; |
| 13 import 'package:compiler/src/commandline_options.dart'; | 14 import 'package:compiler/src/commandline_options.dart'; |
| 14 import 'package:compiler/src/common.dart'; | 15 import 'package:compiler/src/common.dart'; |
| 15 import 'package:compiler/src/compiler.dart'; | 16 import 'package:compiler/src/compiler.dart'; |
| 16 import 'package:compiler/src/elements/resolution_types.dart'; | 17 import 'package:compiler/src/elements/resolution_types.dart'; |
| 17 import 'package:compiler/src/elements/types.dart'; | 18 import 'package:compiler/src/elements/types.dart'; |
| 18 import 'package:compiler/src/enqueue.dart'; | 19 import 'package:compiler/src/enqueue.dart'; |
| 19 import 'package:compiler/src/kernel/element_map.dart'; | 20 import 'package:compiler/src/kernel/element_map.dart'; |
| 20 import 'package:compiler/src/kernel/kernel_strategy.dart'; | 21 import 'package:compiler/src/kernel/kernel_strategy.dart'; |
| 22 import 'package:compiler/src/serialization/equivalence.dart'; |
| 21 import 'package:compiler/src/resolution/enum_creator.dart'; | 23 import 'package:compiler/src/resolution/enum_creator.dart'; |
| 22 import 'package:compiler/src/universe/world_builder.dart'; | 24 import 'package:compiler/src/universe/world_builder.dart'; |
| 23 import 'package:compiler/src/world.dart'; | 25 import 'package:compiler/src/world.dart'; |
| 24 import 'package:expect/expect.dart'; | 26 import 'package:expect/expect.dart'; |
| 25 import '../memory_compiler.dart'; | 27 import '../memory_compiler.dart'; |
| 26 import '../equivalence/check_functions.dart'; | 28 import '../equivalence/check_functions.dart'; |
| 29 import '../equivalence/check_helpers.dart'; |
| 27 import '../serialization/helper.dart'; | 30 import '../serialization/helper.dart'; |
| 28 import 'test_helpers.dart'; | 31 import 'test_helpers.dart'; |
| 29 | 32 |
| 30 import 'compiler_helper.dart'; | 33 import 'compiler_helper.dart'; |
| 31 | 34 |
| 32 const SOURCE = const { | 35 const SOURCE = const { |
| 33 'main.dart': ''' | 36 'main.dart': ''' |
| 34 | |
| 35 class ClassWithSetter { | |
| 36 void set setter(_) {} | |
| 37 } | |
| 38 | |
| 39 class Mixin { | |
| 40 method1() {} | |
| 41 method2() {} | |
| 42 method3() {} | |
| 43 method4() {} | |
| 44 var field; | |
| 45 get property => 0; | |
| 46 set property(_) {} | |
| 47 } | |
| 48 class Class1 = Object with Mixin; | |
| 49 class Class2 extends Object with Mixin { | |
| 50 method3() {} | |
| 51 method5() { | |
| 52 super.method4(); | |
| 53 super.property; | |
| 54 super.property = null; | |
| 55 super.field; | |
| 56 super.field = null; | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 main() { | 37 main() { |
| 61 print('Hello World'); | |
| 62 ''.contains; // Trigger member closurization. | |
| 63 new ClassWithSetter().setter = null; | |
| 64 new Class1().method1(); | |
| 65 new Class2().method2(); | |
| 66 new Class2().method3(); | |
| 67 new Class2().method5(); | |
| 68 } | 38 } |
| 69 ''' | 39 ''' |
| 70 }; | 40 }; |
| 71 | 41 |
| 72 main(List<String> args) { | 42 main(List<String> args) { |
| 73 asyncTest(() async { | 43 asyncTest(() async { |
| 74 await mainInternal(args); | 44 await mainInternal(args); |
| 75 }); | 45 }); |
| 76 } | 46 } |
| 77 | 47 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 93 enableDebugMode(); | 63 enableDebugMode(); |
| 94 EnumCreator.matchKernelRepresentationForTesting = true; | 64 EnumCreator.matchKernelRepresentationForTesting = true; |
| 95 | 65 |
| 96 Directory dir = await Directory.systemTemp.createTemp('dart2js-with-dill'); | 66 Directory dir = await Directory.systemTemp.createTemp('dart2js-with-dill'); |
| 97 print('--- create temp directory $dir -------------------------------'); | 67 print('--- create temp directory $dir -------------------------------'); |
| 98 memorySourceFiles.forEach((String name, String source) { | 68 memorySourceFiles.forEach((String name, String source) { |
| 99 new File.fromUri(dir.uri.resolve(name)).writeAsStringSync(source); | 69 new File.fromUri(dir.uri.resolve(name)).writeAsStringSync(source); |
| 100 }); | 70 }); |
| 101 entryPoint = dir.uri.resolve(entryPoint.path); | 71 entryPoint = dir.uri.resolve(entryPoint.path); |
| 102 | 72 |
| 103 print('---- analyze-only ------------------------------------------------'); | 73 print('---- compile from ast ----------------------------------------------'); |
| 104 DiagnosticCollector collector = new DiagnosticCollector(); | 74 DiagnosticCollector collector = new DiagnosticCollector(); |
| 75 OutputCollector collector1 = new OutputCollector(); |
| 105 Compiler compiler1 = compilerFor( | 76 Compiler compiler1 = compilerFor( |
| 106 entryPoint: entryPoint, | 77 entryPoint: entryPoint, |
| 107 diagnosticHandler: collector, | 78 diagnosticHandler: collector, |
| 108 options: [Flags.analyzeOnly, Flags.enableAssertMessage]); | 79 outputProvider: collector1, |
| 80 options: [Flags.disableTypeInference, Flags.enableAssertMessage]); |
| 109 ElementResolutionWorldBuilder.useInstantiationMap = true; | 81 ElementResolutionWorldBuilder.useInstantiationMap = true; |
| 110 compiler1.resolution.retainCachesForTesting = true; | 82 compiler1.resolution.retainCachesForTesting = true; |
| 111 await compiler1.run(entryPoint); | 83 await compiler1.run(entryPoint); |
| 112 if (collector.crashes.isNotEmpty) { | 84 if (collector.crashes.isNotEmpty) { |
| 113 print('Skipping due to crashes.'); | 85 print('Skipping due to crashes.'); |
| 114 return ResultKind.crashes; | 86 return ResultKind.crashes; |
| 115 } | 87 } |
| 116 if (collector.errors.isNotEmpty && skipErrors) { | 88 if (collector.errors.isNotEmpty && skipErrors) { |
| 117 print('Skipping due to errors.'); | 89 print('Skipping due to errors.'); |
| 118 return ResultKind.errors; | 90 return ResultKind.errors; |
| 119 } | 91 } |
| 120 if (collector.warnings.isNotEmpty && skipWarnings) { | 92 if (collector.warnings.isNotEmpty && skipWarnings) { |
| 121 print('Skipping due to warnings.'); | 93 print('Skipping due to warnings.'); |
| 122 return ResultKind.warnings; | 94 return ResultKind.warnings; |
| 123 } | 95 } |
| 124 Expect.isFalse(compiler1.compilationFailed); | 96 Expect.isFalse(compiler1.compilationFailed); |
| 125 ResolutionEnqueuer enqueuer1 = compiler1.enqueuer.resolution; | 97 ResolutionEnqueuer enqueuer1 = compiler1.enqueuer.resolution; |
| 126 ClosedWorld closedWorld1 = compiler1.resolutionWorldBuilder.closeWorld(); | 98 ClosedWorld closedWorld1 = |
| 99 compiler1.resolutionWorldBuilder.closedWorldForTesting; |
| 127 | 100 |
| 128 Compiler compiler2 = | 101 OutputCollector collector2 = new OutputCollector(); |
| 129 await compileWithDill(entryPoint, const {}, printSteps: true); | 102 Compiler compiler2 = await compileWithDill(entryPoint, const {}, |
| 103 [Flags.disableTypeInference, Flags.enableAssertMessage], |
| 104 printSteps: true, compilerOutput: collector2); |
| 130 | 105 |
| 131 KernelFrontEndStrategy frontEndStrategy = compiler2.frontEndStrategy; | 106 KernelFrontEndStrategy frontEndStrategy = compiler2.frontEndStrategy; |
| 132 KernelToElementMap elementMap = frontEndStrategy.elementMap; | 107 KernelToElementMap elementMap = frontEndStrategy.elementMap; |
| 133 | 108 |
| 134 Expect.isFalse(compiler2.compilationFailed); | 109 Expect.isFalse(compiler2.compilationFailed); |
| 135 | 110 |
| 136 KernelEquivalence equivalence = new KernelEquivalence(elementMap); | 111 KernelEquivalence equivalence = new KernelEquivalence(elementMap); |
| 137 | 112 |
| 138 ResolutionEnqueuer enqueuer2 = compiler2.enqueuer.resolution; | 113 ResolutionEnqueuer enqueuer2 = compiler2.enqueuer.resolution; |
| 139 ClosedWorld closedWorld2 = compiler2.resolutionWorldBuilder.closeWorld(); | 114 ClosedWorld closedWorld2 = |
| 115 compiler2.resolutionWorldBuilder.closedWorldForTesting; |
| 140 | 116 |
| 141 checkBackendUsage(closedWorld1.backendUsage, closedWorld2.backendUsage, | 117 checkBackendUsage(closedWorld1.backendUsage, closedWorld2.backendUsage, |
| 142 equivalence.defaultStrategy); | 118 equivalence.defaultStrategy); |
| 143 | 119 |
| 144 checkResolutionEnqueuers(closedWorld1.backendUsage, closedWorld2.backendUsage, | 120 checkResolutionEnqueuers(closedWorld1.backendUsage, closedWorld2.backendUsage, |
| 145 enqueuer1, enqueuer2, elementEquivalence: equivalence.entityEquivalence, | 121 enqueuer1, enqueuer2, elementEquivalence: equivalence.entityEquivalence, |
| 146 typeEquivalence: (ResolutionDartType a, DartType b) { | 122 typeEquivalence: (ResolutionDartType a, DartType b) { |
| 147 return equivalence.typeEquivalence(unalias(a), b); | 123 return equivalence.typeEquivalence(unalias(a), b); |
| 148 }, elementFilter: elementFilter, verbose: arguments.verbose); | 124 }, elementFilter: elementFilter, verbose: arguments.verbose); |
| 149 | 125 |
| 150 checkClosedWorlds(closedWorld1, closedWorld2, | 126 checkClosedWorlds(closedWorld1, closedWorld2, |
| 151 strategy: equivalence.defaultStrategy, verbose: arguments.verbose); | 127 strategy: equivalence.defaultStrategy, |
| 128 verbose: arguments.verbose, |
| 129 // TODO(johnniwinther,efortuna): Require closure class equivalence when |
| 130 // these are supported. |
| 131 allowMissingClosureClasses: true); |
| 152 | 132 |
| 133 // TODO(johnniwinther): Perform equivalence tests on the model: codegen world |
| 134 // impacts, codegen world builder, etc. |
| 135 |
| 136 collector1.outputMap |
| 137 .forEach((OutputType outputType, Map<String, BufferedOutputSink> map1) { |
| 138 if (outputType == OutputType.sourceMap) { |
| 139 // TODO(johnniwinther): Support source map from .dill. |
| 140 return; |
| 141 } |
| 142 Map<String, BufferedOutputSink> map2 = collector2.outputMap[outputType]; |
| 143 checkSets(map1.keys, map2.keys, 'output', equality); |
| 144 map1.forEach((String name, BufferedOutputSink output1) { |
| 145 BufferedOutputSink output2 = map2[name]; |
| 146 Expect.stringEquals(output1.text, output2.text); |
| 147 }); |
| 148 }); |
| 153 return ResultKind.success; | 149 return ResultKind.success; |
| 154 } | 150 } |
| OLD | NEW |