소스 검색

[optimization] inline calls to inlined fields

closes #3524
Simon Krajewski 7 년 전
부모
커밋
b0d2d56234
3개의 변경된 파일36개의 추가작업 그리고 1개의 파일을 삭제
  1. 11 0
      src/optimization/optimizer.ml
  2. 25 0
      tests/optimization/src/issues/Issue3524.hx
  3. 0 1
      tests/optimization/src/issues/Issue6283.hx

+ 11 - 0
src/optimization/optimizer.ml

@@ -1131,6 +1131,17 @@ let rec reduce_loop ctx e =
 				(match inl with
 				| None -> reduce_expr ctx e
 				| Some e -> reduce_loop ctx e)
+			| {eexpr = TField(ef,(FStatic(_,cf) | FInstance(_,_,cf)))} when cf.cf_kind = Method MethInline ->
+				begin match cf.cf_expr with
+				| Some {eexpr = TFunction tf} ->
+					let rt = (match follow e1.etype with TFun (_,rt) -> rt | _ -> assert false) in
+					let inl = (try type_inline ctx cf tf ef el rt None e.epos ~self_calling_closure:true false with Error (Custom _,_) -> None) in
+					(match inl with
+					| None -> reduce_expr ctx e
+					| Some e -> reduce_loop ctx e)
+				| _ ->
+					reduce_expr ctx e
+				end
 			| { eexpr = TField ({ eexpr = TTypeExpr (TClassDecl c) },field) } ->
 				(match api_inline ctx c (field_name field) el e.epos with
 				| None -> reduce_expr ctx e

+ 25 - 0
tests/optimization/src/issues/Issue3524.hx

@@ -0,0 +1,25 @@
+package issues;
+
+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;
+	')
+	@:analyzer(ignore)
+    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;
+    }
+
+	static inline function apply(f:List -> List -> Int, l1:List, l2:List) {
+		f(l1, l2);
+	}
+}

+ 0 - 1
tests/optimization/src/issues/Issue6283.hx

@@ -6,7 +6,6 @@ import TestJs.use;
 
 @:callable
 abstract From<T>(T) from T to T {
-	inline function new (t:T) return new From(t);
 	@:from macro public static function fromExpr (e:haxe.macro.Expr) {
 		return macro function (a, b) return a+b;
 	}