| 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 // Helper to test compilation equivalence between source and .dill based | 5 // Helper to test compilation equivalence between source and .dill based |
| 6 // compilation. | 6 // compilation. |
| 7 library dart2js.kernel.compile_from_dill_test_helper; | 7 library dart2js.kernel.compile_from_dill_test_helper; |
| 8 | 8 |
| 9 import 'dart:async'; | 9 import 'dart:async'; |
| 10 | 10 |
| 11 import 'package:compiler/compiler_new.dart'; | 11 import 'package:compiler/compiler_new.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/compiler.dart'; | 14 import 'package:compiler/src/compiler.dart'; |
| 15 import 'package:compiler/src/elements/elements.dart'; | 15 import 'package:compiler/src/elements/elements.dart'; |
| 16 import 'package:compiler/src/elements/types.dart'; | 16 import 'package:compiler/src/elements/types.dart'; |
| 17 import 'package:compiler/src/kernel/element_map.dart'; | 17 import 'package:compiler/src/kernel/element_map.dart'; |
| 18 import 'package:compiler/src/kernel/kernel_backend_strategy.dart'; | 18 import 'package:compiler/src/kernel/kernel_backend_strategy.dart'; |
| 19 import 'package:compiler/src/kernel/kernel_strategy.dart'; | 19 import 'package:compiler/src/kernel/kernel_strategy.dart'; |
| 20 import 'package:compiler/src/serialization/equivalence.dart'; | 20 import 'package:compiler/src/serialization/equivalence.dart'; |
| 21 import 'package:compiler/src/resolution/class_hierarchy.dart'; |
| 21 import 'package:compiler/src/resolution/enum_creator.dart'; | 22 import 'package:compiler/src/resolution/enum_creator.dart'; |
| 22 import 'package:compiler/src/universe/world_builder.dart'; | 23 import 'package:compiler/src/universe/world_builder.dart'; |
| 23 import 'package:compiler/src/world.dart'; | 24 import 'package:compiler/src/world.dart'; |
| 24 import 'package:expect/expect.dart'; | 25 import 'package:expect/expect.dart'; |
| 25 import '../memory_compiler.dart'; | 26 import '../memory_compiler.dart'; |
| 26 import '../equivalence/check_functions.dart'; | 27 import '../equivalence/check_functions.dart'; |
| 27 import '../equivalence/check_helpers.dart'; | 28 import '../equivalence/check_helpers.dart'; |
| 28 import '../serialization/helper.dart'; | 29 import '../serialization/helper.dart'; |
| 29 import 'test_helpers.dart'; | 30 import 'test_helpers.dart'; |
| 30 | 31 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 } | 73 } |
| 73 | 74 |
| 74 class Generic<T> { | 75 class Generic<T> { |
| 75 method(o) => o is T; | 76 method(o) => o is T; |
| 76 } | 77 } |
| 77 | 78 |
| 78 var toplevel; | 79 var toplevel; |
| 79 | 80 |
| 80 typedef Typedef(); | 81 typedef Typedef(); |
| 81 | 82 |
| 83 class Mixin1 { |
| 84 var field1; |
| 85 } |
| 86 |
| 87 class Mixin2 { |
| 88 var field2; |
| 89 } |
| 90 |
| 91 class MixinSub1 extends Object with Mixin1 { |
| 92 } |
| 93 |
| 94 class MixinSub2 extends Object with Mixin1, Mixin2 { |
| 95 } |
| 96 |
| 82 main() { | 97 main() { |
| 83 foo(); | 98 foo(); |
| 84 bar(true); | 99 bar(true); |
| 85 []; | 100 []; |
| 86 <int>[]; | 101 <int>[]; |
| 87 {}; | 102 {}; |
| 88 new Object(); | 103 new Object(); |
| 89 new Class.named(''); | 104 new Class.named(''); |
| 90 new SubClass().method(); | 105 new SubClass().method(); |
| 91 Class.staticField; | 106 Class.staticField; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 x = new Generic<int>().method(x); | 149 x = new Generic<int>().method(x); |
| 135 x = testAsGeneric(x); | 150 x = testAsGeneric(x); |
| 136 x = testAsFunction(x); | 151 x = testAsFunction(x); |
| 137 print(x); | 152 print(x); |
| 138 var f = (x) { | 153 var f = (x) { |
| 139 return 400 + x; | 154 return 400 + x; |
| 140 }; | 155 }; |
| 141 x = f(x); | 156 x = f(x); |
| 142 x = Object; | 157 x = Object; |
| 143 x = Typedef; | 158 x = Typedef; |
| 159 new MixinSub2(); |
| 160 new MixinSub1(); |
| 144 return x; | 161 return x; |
| 145 } | 162 } |
| 146 typedef NoArg(); | 163 typedef NoArg(); |
| 147 @NoInline() | 164 @NoInline() |
| 148 testIs(o) => o is Generic<int> || o is NoArg; | 165 testIs(o) => o is Generic<int> || o is NoArg; |
| 149 @NoInline() | 166 @NoInline() |
| 150 testAsGeneric(o) => o as Generic<int>; | 167 testAsGeneric(o) => o as Generic<int>; |
| 151 @NoInline() | 168 @NoInline() |
| 152 testAsFunction(o) => o as NoArg; | 169 testAsFunction(o) => o as NoArg; |
| 153 ''' | 170 ''' |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 267 Uri entryPoint, Map<String, String> memorySourceFiles, | 284 Uri entryPoint, Map<String, String> memorySourceFiles, |
| 268 {bool skipWarnings: false, | 285 {bool skipWarnings: false, |
| 269 bool skipErrors: false, | 286 bool skipErrors: false, |
| 270 bool verbose: false, | 287 bool verbose: false, |
| 271 List<String> options: const <String>[], | 288 List<String> options: const <String>[], |
| 272 bool expectAstEquivalence: false, | 289 bool expectAstEquivalence: false, |
| 273 bool expectIdenticalOutput: true}) async { | 290 bool expectIdenticalOutput: true}) async { |
| 274 enableDebugMode(); | 291 enableDebugMode(); |
| 275 EnumCreator.matchKernelRepresentationForTesting = true; | 292 EnumCreator.matchKernelRepresentationForTesting = true; |
| 276 Elements.usePatchedDart2jsSdkSorting = true; | 293 Elements.usePatchedDart2jsSdkSorting = true; |
| 294 useOptimizedMixins = true; |
| 277 | 295 |
| 278 entryPoint = | 296 entryPoint = |
| 279 await createTemp(entryPoint, memorySourceFiles, printSteps: true); | 297 await createTemp(entryPoint, memorySourceFiles, printSteps: true); |
| 280 | 298 |
| 281 print('---- compile from ast ----------------------------------------------'); | 299 print('---- compile from ast ----------------------------------------------'); |
| 282 DiagnosticCollector collector = new DiagnosticCollector(); | 300 DiagnosticCollector collector = new DiagnosticCollector(); |
| 283 OutputCollector collector1 = new OutputCollector(); | 301 OutputCollector collector1 = new OutputCollector(); |
| 284 Compiler compiler1 = compilerFor( | 302 Compiler compiler1 = compilerFor( |
| 285 entryPoint: entryPoint, | 303 entryPoint: entryPoint, |
| 286 diagnosticHandler: collector, | 304 diagnosticHandler: collector, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 if (output1.text == output2.text) return; | 344 if (output1.text == output2.text) return; |
| 327 List<String> lines1 = output1.text.split('\n'); | 345 List<String> lines1 = output1.text.split('\n'); |
| 328 List<String> lines2 = output2.text.split('\n'); | 346 List<String> lines2 = output2.text.split('\n'); |
| 329 int prefix = 0; | 347 int prefix = 0; |
| 330 while (prefix < lines1.length && prefix < lines2.length) { | 348 while (prefix < lines1.length && prefix < lines2.length) { |
| 331 if (lines1[prefix] != lines2[prefix]) { | 349 if (lines1[prefix] != lines2[prefix]) { |
| 332 break; | 350 break; |
| 333 } | 351 } |
| 334 prefix++; | 352 prefix++; |
| 335 } | 353 } |
| 354 if (prefix > 0) prefix--; |
| 336 int suffix1 = lines1.length - 1; | 355 int suffix1 = lines1.length - 1; |
| 337 int suffix2 = lines2.length - 1; | 356 int suffix2 = lines2.length - 1; |
| 338 while (suffix1 >= 0 && suffix2 >= 0) { | 357 while (suffix1 >= 0 && suffix2 >= 0) { |
| 339 if (lines1[suffix1] != lines2[suffix2]) { | 358 if (lines1[suffix1] != lines2[suffix2]) { |
| 340 break; | 359 break; |
| 341 } | 360 } |
| 342 suffix1--; | 361 suffix1--; |
| 343 suffix2--; | 362 suffix2--; |
| 344 } | 363 } |
| 364 if (suffix1 + 1 < lines1.length) suffix1++; |
| 365 if (suffix2 + 1 < lines2.length) suffix2++; |
| 345 print('--- from source, lines [${prefix}-${suffix1}] ------------------'); | 366 print('--- from source, lines [${prefix}-${suffix1}] ------------------'); |
| 346 lines1.sublist(prefix, suffix1 + 1).forEach(print); | 367 lines1.sublist(prefix, suffix1 + 1).forEach(print); |
| 347 print('--- from dill, lines [${prefix}-${suffix2}] --------------------'); | 368 print('--- from dill, lines [${prefix}-${suffix2}] --------------------'); |
| 348 lines2.sublist(prefix, suffix2 + 1).forEach(print); | 369 lines2.sublist(prefix, suffix2 + 1).forEach(print); |
| 349 }); | 370 }); |
| 350 }); | 371 }); |
| 351 | 372 |
| 352 KernelFrontEndStrategy frontendStrategy = compiler2.frontendStrategy; | 373 KernelFrontEndStrategy frontendStrategy = compiler2.frontendStrategy; |
| 353 KernelToElementMap elementMap = frontendStrategy.elementMap; | 374 KernelToElementMap elementMap = frontendStrategy.elementMap; |
| 354 | 375 |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 422 Map<String, BufferedOutputSink> map2 = collector2.outputMap[outputType]; | 443 Map<String, BufferedOutputSink> map2 = collector2.outputMap[outputType]; |
| 423 checkSets(map1.keys, map2.keys, 'output', equality); | 444 checkSets(map1.keys, map2.keys, 'output', equality); |
| 424 map1.forEach((String name, BufferedOutputSink output1) { | 445 map1.forEach((String name, BufferedOutputSink output1) { |
| 425 BufferedOutputSink output2 = map2[name]; | 446 BufferedOutputSink output2 = map2[name]; |
| 426 Expect.stringEquals(output1.text, output2.text); | 447 Expect.stringEquals(output1.text, output2.text); |
| 427 }); | 448 }); |
| 428 }); | 449 }); |
| 429 } | 450 } |
| 430 return ResultKind.success; | 451 return ResultKind.success; |
| 431 } | 452 } |
| OLD | NEW |