Parcourir la source

better inlining of ctors and anons

Aleksandr Kuzmenko il y a 5 ans
Parent
commit
a8d036760e

+ 1 - 1
src/filters/filters.ml

@@ -848,8 +848,8 @@ let run com tctx main =
 		fix_return_dynamic_from_void_function tctx true;
 		check_local_vars_init;
 		check_abstract_as_value;
-		if Common.defined com Define.OldConstructorInline then Optimizer.inline_constructors tctx else InlineConstructors.inline_constructors tctx;
 		Optimizer.reduce_expression tctx;
+		if Common.defined com Define.OldConstructorInline then Optimizer.inline_constructors tctx else InlineConstructors.inline_constructors tctx;
 		CapturedVars.captured_vars com;
 	] in
 	let filters =

+ 24 - 3
tests/optimization/src/Test.hx

@@ -8,6 +8,16 @@ class InlineCtor {
 	}
 }
 
+class Set {
+	var amount:Int;
+	public inline function new(a:Int) amount = a;
+	public inline function count() return amount;
+}
+
+typedef Countable = {
+	function count():Int;
+}
+
 enum abstract MyEnum(String) to String {
 	var A = "a";
 }
@@ -85,6 +95,17 @@ class Test {
 		b.x = a;
 	}
 
+	@:js('
+		var v_amount = 10;
+		var a = 10;
+	')
+	static function testInlineCtor_passedToInlineMethodAsAnonConstraint() {
+		var a = count(new Set(10));
+	}
+	static inline function count<T:Countable>(v:T) {
+		return v.count();
+	}
+
 	@:js('
 		var x_foo = 1;
 		var x_bar = 2;
@@ -102,9 +123,9 @@ class Test {
 
 	@:js('var x = { "oh-my" : "god"};')
 	static function testStructureInlineInvalidField() {
-        var x = {
-            "oh-my": "god"
-        };
+		var x = {
+			"oh-my": "god"
+		};
 	}
 
 	@:js('

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

@@ -73,7 +73,7 @@ class TestJs {
 		return try a[i] catch (e:Dynamic) null;
 	}
 
-	@:js("var a_v_0_b = 1;a_v_0_b;")
+	@:js("var a_v_0_b = 1;")
 	@:analyzer(no_const_propagation, no_local_dce)
 	static function testDeepMatchingWithoutClosures() {
 		var a = {v: [{b: 1}]};

+ 13 - 7
tests/optimization/src/issues/Issue3524.hx

@@ -4,20 +4,26 @@ typedef List = { v : Int, next : List };
 
 class Issue3524 {
 	@:js('
-		var l1 = { v : 0, next : null};
-		var l2 = { v : 1, next : null};
-		l1.v - l2.v;
+		var l1_v;
+		var l1_next;
+		l1_v = 0;
+		l1_next = null;
+		var l2_v;
+		var l2_next;
+		l2_v = 1;
+		l2_next = null;
+		l1_v - l2_v;
 	')
 	@:analyzer(ignore)
-    static function main() {
+	static function main() {
 		var l1 = { v: 0, next: null };
 		var l2 = { v: 1, next: null };
 		apply(cmp, l1, l2);
-    }
+	}
 
 	static inline function cmp(a:List, b:List) {
-        return a.v - b.v;
-    }
+		return a.v - b.v;
+	}
 
 	static inline function apply(f:List -> List -> Int, l1:List, l2:List) {
 		f(l1, l2);

+ 6 - 1
tests/optimization/src/issues/Issue4690.hx

@@ -35,7 +35,12 @@ class Issue4690 {
 		TestJs.use("Child.new: Before super");
 		TestJs.use("Parent.new: Before assign");
 		c_x = 1;
-		c_y = "" + 2;
+		var c_y1 = false;
+		if(c_y1) {
+			c_y = "null";
+		} else {
+			c_y = "" + 2;
+		}
 		TestJs.use("Parent.new: After assign");
 		TestJs.use("Child.new: After super");
 		c_z = 3;