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

Side by Side Diff: tests/compiler/dart2js/backend_dart/opt_constprop_test.dart

Issue 800433003: First version of typr propagation in the new IR. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add type arguments, fix join and tests. Created 6 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 import 'dart:async'; 5 import 'dart:async';
6 import '../mock_compiler.dart'; 6 import '../mock_compiler.dart';
7 import 'sexpr_unstringifier.dart'; 7 import 'sexpr_unstringifier.dart';
8 import 'package:async_helper/async_helper.dart'; 8 import 'package:async_helper/async_helper.dart';
9 import "package:expect/expect.dart"; 9 import "package:expect/expect.dart";
10 import 'package:compiler/src/cps_ir/cps_ir_nodes_sexpr.dart'; 10 import 'package:compiler/src/cps_ir/cps_ir_nodes_sexpr.dart';
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after
388 (InvokeContinuation k0 v0)) 388 (InvokeContinuation k0 v0))
389 """; 389 """;
390 String CP10_OUT = CP10_IN; 390 String CP10_OUT = CP10_IN;
391 391
392 /// Normalizes whitespace by replacing all whitespace sequences by a single 392 /// Normalizes whitespace by replacing all whitespace sequences by a single
393 /// space and trimming leading and trailing whitespace. 393 /// space and trimming leading and trailing whitespace.
394 String normalizeSExpr(String input) { 394 String normalizeSExpr(String input) {
395 return input.replaceAll(new RegExp(r'[ \n\t]+'), ' ').trim(); 395 return input.replaceAll(new RegExp(r'[ \n\t]+'), ' ').trim();
396 } 396 }
397 397
398 class UnitTypeSystem implements TypeSystem<String> {
399 static const String UNIT = 'unit';
400
401 get boolType => UNIT;
402 get dynamicType => UNIT;
403 get functionType => UNIT;
404 get intType => UNIT;
405 get listType => UNIT;
406 get mapType => UNIT;
407 get stringType => UNIT;
408 get typeType => UNIT;
409
410 bool areEqual(a, b) => true;
411 bool areAssignable(a, b) => true;
412 getParameterType(_) => UNIT;
413 getReturnType(_) => UNIT;
414 join(a, b) => UNIT;
415 typeOf(_) => UNIT;
416 }
417
398 /// Parses the given input IR, runs an optimization pass over it, and compares 418 /// Parses the given input IR, runs an optimization pass over it, and compares
399 /// the stringification of the result against the expected output. 419 /// the stringification of the result against the expected output.
400 Future testConstantPropagator(String input, String expectedOutput) { 420 Future testConstantPropagator(String input, String expectedOutput) {
401 final compiler = new MockCompiler.internal( 421 final compiler = new MockCompiler.internal(
402 emitJavaScript: false, 422 emitJavaScript: false,
403 enableMinification: false); 423 enableMinification: false);
404 return compiler.init().then((_) { 424 return compiler.init().then((_) {
405 final unstringifier = new SExpressionUnstringifier(); 425 final unstringifier = new SExpressionUnstringifier();
406 final stringifier = new SExpressionStringifier(); 426 final stringifier = new SExpressionStringifier();
407 final optimizer = new ConstantPropagator( 427 final optimizer = new TypePropagator(
408 compiler, dart2js.DART_CONSTANT_SYSTEM); 428 compiler,
429 dart2js.DART_CONSTANT_SYSTEM,
430 new UnitTypeSystem(),
431 compiler.internalError);
409 432
410 final f = unstringifier.unstringify(input); 433 final f = unstringifier.unstringify(input);
411 optimizer.rewrite(f); 434 optimizer.rewrite(f);
412 435
413 String expected = normalizeSExpr(expectedOutput); 436 String expected = normalizeSExpr(expectedOutput);
414 String actual = normalizeSExpr(stringifier.visit(f)); 437 String actual = normalizeSExpr(stringifier.visit(f));
415 438
416 Expect.equals(expected, actual); 439 Expect.equals(expected, actual);
417 }); 440 });
418 } 441 }
419 442
420 void main() { 443 void main() {
421 asyncTest(() => testConstantPropagator(CP1_IN, CP1_OUT)); 444 asyncTest(() => testConstantPropagator(CP1_IN, CP1_OUT));
422 asyncTest(() => testConstantPropagator(CP2_IN, CP2_OUT)); 445 asyncTest(() => testConstantPropagator(CP2_IN, CP2_OUT));
423 asyncTest(() => testConstantPropagator(CP3_IN, CP3_OUT)); 446 asyncTest(() => testConstantPropagator(CP3_IN, CP3_OUT));
424 asyncTest(() => testConstantPropagator(CP4_IN, CP4_OUT)); 447 asyncTest(() => testConstantPropagator(CP4_IN, CP4_OUT));
425 asyncTest(() => testConstantPropagator(CP5_IN, CP5_OUT)); 448 asyncTest(() => testConstantPropagator(CP5_IN, CP5_OUT));
426 asyncTest(() => testConstantPropagator(CP6_IN, CP6_OUT)); 449 asyncTest(() => testConstantPropagator(CP6_IN, CP6_OUT));
427 asyncTest(() => testConstantPropagator(CP7_IN, CP7_OUT)); 450 asyncTest(() => testConstantPropagator(CP7_IN, CP7_OUT));
428 asyncTest(() => testConstantPropagator(CP8_IN, CP8_OUT)); 451 asyncTest(() => testConstantPropagator(CP8_IN, CP8_OUT));
429 asyncTest(() => testConstantPropagator(CP9_IN, CP9_OUT)); 452 asyncTest(() => testConstantPropagator(CP9_IN, CP9_OUT));
430 asyncTest(() => testConstantPropagator(CP10_IN, CP10_OUT)); 453 asyncTest(() => testConstantPropagator(CP10_IN, CP10_OUT));
431 } 454 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698