Browse Source

adjust optimization tests

Simon Krajewski 10 years ago
parent
commit
aecc641f02
2 changed files with 28 additions and 18 deletions
  1. 3 1
      tests/optimization/src/TestJs.hx
  2. 25 17
      tests/optimization/src/TestLocalDce.hx

+ 3 - 1
tests/optimization/src/TestJs.hx

@@ -13,7 +13,7 @@ class TestJs {
 	//Std.string(x);
 	//}
 
-	@:js("var a = new List();var _g_head = a.h;var _g_val = null;while(_g_head != null) {var tmp;_g_val = _g_head[0];_g_head = _g_head[1];tmp = _g_val;tmp;}")
+	@:js("var a = new List();var _g_head = a.h;var _g_val = null;while(_g_head != null) {var tmp;_g_val = _g_head[0];_g_head = _g_head[1];tmp = _g_val;}")
 	static function testListIteratorInline() {
 		var a = new List();
 		for (v in a) { }
@@ -22,6 +22,7 @@ class TestJs {
 	@:js("var a = 1;var tmp;var v2 = a;tmp = a + v2;if(tmp > 0) {}")
 	@:analyzer(no_const_propagation)
 	@:analyzer(no_check_has_effect)
+	@:analyzer(no_local_dce)
 	static function testInlineWithArgumentUsedMoreThanOnce() {
 		var a = 1;
 		if (_inlineWithArgumentUsedMoreThanOnce(a) > 0) { }
@@ -34,6 +35,7 @@ class TestJs {
 
 	@:js("var a = [];var tmp;try {tmp = a[0];} catch( e ) {tmp = null;}if(tmp) {}")
 	@:analyzer(no_check_has_effect)
+	@:analyzer(no_local_dce)
 	static function testInlineWithComplexExpr() {
 		var a = [];
 		if (_inlineWithComplexExpr(a, 0)) {}

+ 25 - 17
tests/optimization/src/TestLocalDce.hx

@@ -15,24 +15,25 @@ private abstract MyEnum(String) to String {
 
 @:analyzer(no_check_has_effect)
 class TestLocalDce {
-	@:js('3;')
+	@:js('console.log(3);')
 	static function testNoOpRemoval() {
 		1;
 		2;
 		{}
-		3;
+		trace(3);
 	}
 
 	@:js('
-		27;
+		console.log(27);
 	')
 	static function testConstMath() {
 		var a = 1 + 2;
 		var b = 9 * 3;
+		trace(b);
 	}
 
 	@:js('
-		"foo";
+		console.log("foo");
 	')
 	static function testInlineCtor1() {
 		var c = new InlineCtor(12, "foo");
@@ -40,10 +41,11 @@ class TestLocalDce {
 		c.x = 13;
 		x = c.x;
 		var y = c.y;
+		trace(y);
 	}
 
 	@:js('
-		12;
+		console.log(12);
 	')
 	static function testInlineCtor2() {
 		var a = 0;
@@ -52,11 +54,11 @@ class TestLocalDce {
 			a = 2;
 			new InlineCtor(12, "foo");
 		}
-		a = c.x;
+		trace(a = c.x);
 	}
 
 	@:js('
-		1;
+		console.log(1);
 	')
 	static function testInlineCtor3() {
 		var a = 0;
@@ -65,11 +67,11 @@ class TestLocalDce {
 			a = 1;
 			new InlineCtor(2, "b");
 		}
-		b.x = a;
+		trace(b.x = a);
 	}
 
 	@:js('
-		2;
+		console.log(2);
 	')
 	static function testStructureInline1() {
 		var x = {
@@ -78,47 +80,53 @@ class TestLocalDce {
 		}
 		var y = x.foo;
 		var z = x.bar;
+		trace(z);
 	}
 
 	@:js('
-		"god";
+		TestLocalDce.keep("god");
 	')
 	static function testStructureInlineInvalidField() {
         var x = {
-            "oh-my": "god"
+            "oh-my": keep("god")
         };
 	}
 
 	@:js('
-		2;
+		console.log(2);
 	')
 	static function testArrayInline() {
 		var a = [1, 2];
 		var b = a.length;
+		trace(b);
 	}
 
 	@:js('
 		var a = [1,2];
-		a[-1];
+		console.log(a[-1]);
 	')
 	static function testArrayInlineCancelNegative() {
 		var a = [1, 2];
-		a[-1];
+		trace(a[-1]);
 	}
 
 	@:js('
 		var a = [1,2];
-		a[2];
+		console.log(a[2]);
 	')
 	static function testArrayInlineCancelExceeds() {
 		var a = [1, 2];
-		a[2];
+		trace(a[2]);
 	}
 
 	@:js('
-		"" + "a";
+		var s = "" + "a";
+		console.log(s);
 	')
 	static function testAbstractOverStringBinop() {
 		var s = "" + A;
+		trace(s);
 	}
+
+	static function keep(v) { return v; }
 }