Browse Source

[inliner] stop at some point

closes #6992
Simon Krajewski 7 years ago
parent
commit
c2922df882

+ 13 - 0
src/core/type.ml

@@ -1704,6 +1704,19 @@ let rec_stack stack value fcheck frun ferror =
 				raise e
 				raise e
 	end
 	end
 
 
+let rec_stack_default stack value fcheck frun def =
+	if not (List.exists fcheck !stack) then begin
+		try
+			stack := value :: !stack;
+			let v = frun() in
+			stack := List.tl !stack;
+			v
+		with
+			| e ->
+				stack := List.tl !stack;
+				raise e
+	end	else def
+
 let rec_stack_bool stack value fcheck frun =
 let rec_stack_bool stack value fcheck frun =
 	if (List.exists fcheck !stack) then false else begin
 	if (List.exists fcheck !stack) then false else begin
 		try
 		try

+ 5 - 2
src/optimization/optimizer.ml

@@ -907,6 +907,8 @@ let reduce_control_flow ctx e = match e.eexpr with
 	| _ ->
 	| _ ->
 		e
 		e
 
 
+let inline_stack = ref []
+
 let rec reduce_loop ctx e =
 let rec reduce_loop ctx e =
 	let e = Type.map_expr (reduce_loop ctx) e in
 	let e = Type.map_expr (reduce_loop ctx) e in
 	sanitize_expr ctx.com (match e.eexpr with
 	sanitize_expr ctx.com (match e.eexpr with
@@ -924,10 +926,11 @@ let rec reduce_loop ctx e =
 				begin match cf.cf_expr with
 				begin match cf.cf_expr with
 				| Some {eexpr = TFunction tf} ->
 				| Some {eexpr = TFunction tf} ->
 					let rt = (match follow e1.etype with TFun (_,rt) -> rt | _ -> assert false) in
 					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
+					let inl = (try type_inline ctx cf tf ef el rt None e.epos false with Error (Custom _,_) -> None) in
 					(match inl with
 					(match inl with
 					| None -> reduce_expr ctx e
 					| None -> reduce_expr ctx e
-					| Some e -> reduce_loop ctx e)
+					| Some e ->
+						rec_stack_default inline_stack cf (fun cf' -> cf' == cf) (fun () -> reduce_loop ctx e) e)
 				| _ ->
 				| _ ->
 					reduce_expr ctx e
 					reduce_expr ctx e
 				end
 				end

+ 7 - 0
tests/misc/projects/Issue6992/Main.hx

@@ -0,0 +1,7 @@
+class Main {
+	static public function main() {
+		foo(12);
+	}
+
+	inline static function foo( b ) { foo(b); }
+}

+ 3 - 0
tests/misc/projects/Issue6992/compile.hxml

@@ -0,0 +1,3 @@
+-main Main
+-js whatever.js
+--no-output