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

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: Rename constant_propagation.dart to type_propagation.dart. 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 areAssignable(a, b) => true;
411 getParameterType(_) => UNIT;
412 getReturnType(_) => UNIT;
413 join(a, b) => UNIT;
414 typeOf(_) => UNIT;
415 }
416
398 /// Parses the given input IR, runs an optimization pass over it, and compares 417 /// Parses the given input IR, runs an optimization pass over it, and compares
399 /// the stringification of the result against the expected output. 418 /// the stringification of the result against the expected output.
400 Future testConstantPropagator(String input, String expectedOutput) { 419 Future testConstantPropagator(String input, String expectedOutput) {
401 final compiler = new MockCompiler.internal( 420 final compiler = new MockCompiler.internal(
402 emitJavaScript: false, 421 emitJavaScript: false,
403 enableMinification: false); 422 enableMinification: false);
404 return compiler.init().then((_) { 423 return compiler.init().then((_) {
405 final unstringifier = new SExpressionUnstringifier(); 424 final unstringifier = new SExpressionUnstringifier();
406 final stringifier = new SExpressionStringifier(); 425 final stringifier = new SExpressionStringifier();
407 final optimizer = new ConstantPropagator( 426 final optimizer = new TypePropagator(
408 compiler, dart2js.DART_CONSTANT_SYSTEM); 427 compiler,
428 dart2js.DART_CONSTANT_SYSTEM,
429 new UnitTypeSystem(),
430 compiler.internalError);
409 431
410 final f = unstringifier.unstringify(input); 432 final f = unstringifier.unstringify(input);
411 optimizer.rewrite(f); 433 optimizer.rewrite(f);
412 434
413 String expected = normalizeSExpr(expectedOutput); 435 String expected = normalizeSExpr(expectedOutput);
414 String actual = normalizeSExpr(stringifier.visit(f)); 436 String actual = normalizeSExpr(stringifier.visit(f));
415 437
416 Expect.equals(expected, actual); 438 Expect.equals(expected, actual);
417 }); 439 });
418 } 440 }
419 441
420 void main() { 442 void main() {
421 asyncTest(() => testConstantPropagator(CP1_IN, CP1_OUT)); 443 asyncTest(() => testConstantPropagator(CP1_IN, CP1_OUT));
422 asyncTest(() => testConstantPropagator(CP2_IN, CP2_OUT)); 444 asyncTest(() => testConstantPropagator(CP2_IN, CP2_OUT));
423 asyncTest(() => testConstantPropagator(CP3_IN, CP3_OUT)); 445 asyncTest(() => testConstantPropagator(CP3_IN, CP3_OUT));
424 asyncTest(() => testConstantPropagator(CP4_IN, CP4_OUT)); 446 asyncTest(() => testConstantPropagator(CP4_IN, CP4_OUT));
425 asyncTest(() => testConstantPropagator(CP5_IN, CP5_OUT)); 447 asyncTest(() => testConstantPropagator(CP5_IN, CP5_OUT));
426 asyncTest(() => testConstantPropagator(CP6_IN, CP6_OUT)); 448 asyncTest(() => testConstantPropagator(CP6_IN, CP6_OUT));
427 asyncTest(() => testConstantPropagator(CP7_IN, CP7_OUT)); 449 asyncTest(() => testConstantPropagator(CP7_IN, CP7_OUT));
428 asyncTest(() => testConstantPropagator(CP8_IN, CP8_OUT)); 450 asyncTest(() => testConstantPropagator(CP8_IN, CP8_OUT));
429 asyncTest(() => testConstantPropagator(CP9_IN, CP9_OUT)); 451 asyncTest(() => testConstantPropagator(CP9_IN, CP9_OUT));
430 asyncTest(() => testConstantPropagator(CP10_IN, CP10_OUT)); 452 asyncTest(() => testConstantPropagator(CP10_IN, CP10_OUT));
431 } 453 }
OLDNEW
« no previous file with comments | « pkg/compiler/lib/src/js_backend/codegen/task.dart ('k') | tests/compiler/dart2js/js_backend_cps_ir_control_flow.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698