فهرست منبع

[analyzer] allow inlining unsafe casts

Simon Krajewski 10 سال پیش
والد
کامیت
f386f74b3b
1فایلهای تغییر یافته به همراه4 افزوده شده و 1 حذف شده
  1. 4 1
      analyzer.ml

+ 4 - 1
analyzer.ml

@@ -1041,7 +1041,7 @@ module ConstPropagation = struct
 		with Not_found ->
 			-1
 
-	let can_be_inlined com v0 e = type_iseq v0.v_type e.etype && match e.eexpr with
+	let rec can_be_inlined com v0 e = type_iseq v0.v_type e.etype && match e.eexpr with
 		| TConst ct ->
 			begin match ct with
 				| TThis | TSuper -> false
@@ -1065,6 +1065,9 @@ module ConstPropagation = struct
 			Ssa.get_var_usage_count v0 <= 1
 		| TField(_,FEnum _) ->
 			Ssa.get_var_usage_count v0 <= 1
+		| TCast(e1,None) ->
+			(* We can inline an unsafe cast if the variable is only used once. *)
+			can_be_inlined com v0 {e1 with etype = e.etype} && Ssa.get_var_usage_count v0 <= 1
 		| _ ->
 			false