2
0
Эх сурвалжийг харах

store original expression in `cf_expr_unoptimized` and use it for inlining

closes #5320
Simon Krajewski 9 жил өмнө
parent
commit
0136ac356b

+ 1 - 0
src/generators/gencommon.ml

@@ -1157,6 +1157,7 @@ let mk_class_field name t public pos kind params =
 		cf_kind = kind;
 		cf_params = params;
 		cf_expr = None;
+		cf_expr_unoptimized = None;
 		cf_overloads = [];
 	}
 

+ 1 - 1
src/generators/gencpp.ml

@@ -7074,7 +7074,7 @@ let generate_source ctx =
    (match common_ctx.main with
    | None -> generate_dummy_main common_ctx
    | Some e ->
-      let main_field = { cf_name = "__main__"; cf_type = t_dynamic; cf_expr = Some e; cf_pos = e.epos; cf_name_pos = null_pos; cf_public = true; cf_meta = []; cf_overloads = []; cf_doc = None; cf_kind = Var { v_read = AccNormal; v_write = AccNormal; }; cf_params = [] } in
+      let main_field = { cf_name = "__main__"; cf_type = t_dynamic; cf_expr = Some e; cf_expr_unoptimized = None; cf_pos = e.epos; cf_name_pos = null_pos; cf_public = true; cf_meta = []; cf_overloads = []; cf_doc = None; cf_kind = Var { v_read = AccNormal; v_write = AccNormal; }; cf_params = [] } in
       let class_def = { null_class with cl_path = ([],"@Main"); cl_ordered_statics = [main_field] } in
       main_deps := find_referenced_types ctx (TClassDecl class_def) super_deps constructor_deps false true false;
       generate_main ctx super_deps class_def

+ 1 - 0
src/generators/genswf9.ml

@@ -2120,6 +2120,7 @@ let generate_class ctx c =
 				cf_type = TFun ([],t_dynamic);
 				cf_params = [];
 				cf_expr = None;
+				cf_expr_unoptimized = None;
 				cf_kind = Method MethNormal;
 				cf_overloads = [];
 			} false;

+ 1 - 0
src/macro/interp.ml

@@ -4916,6 +4916,7 @@ let decode_cfield v =
 		cf_kind = decode_field_kind (field v "kind");
 		cf_params = decode_type_params (field v "params");
 		cf_expr = None;
+		cf_expr_unoptimized = None;
 		cf_overloads = decode_ref (field v "overloads");
 	}
 

+ 1 - 0
src/optimization/analyzer.ml

@@ -1197,6 +1197,7 @@ module Run = struct
 	let run_on_field ctx config c cf = match cf.cf_expr with
 		| Some e when not (is_ignored cf.cf_meta) && not (Typecore.is_removable_field ctx cf) ->
 			let config = update_config_from_meta ctx.Typecore.com config cf.cf_meta in
+			(match e.eexpr with TFunction tf -> cf.cf_expr_unoptimized <- Some tf | _ -> ());
 			let actx = create_analyzer_context ctx.Typecore.com config e in
 			let debug() =
 				prerr_endline (Printf.sprintf "While analyzing %s.%s" (s_type_path c.cl_path) cf.cf_name);

+ 2 - 0
src/typing/type.ml

@@ -155,6 +155,7 @@ and tclass_field = {
 	mutable cf_kind : field_kind;
 	mutable cf_params : type_params;
 	mutable cf_expr : texpr option;
+	mutable cf_expr_unoptimized : tfunc option;
 	mutable cf_overloads : tclass_field list;
 }
 
@@ -416,6 +417,7 @@ let mk_field name t p name_pos = {
 	cf_public = true;
 	cf_kind = Var { v_read = AccNormal; v_write = AccNormal };
 	cf_expr = None;
+	cf_expr_unoptimized = None;
 	cf_params = [];
 	cf_overloads = [];
 }

+ 6 - 0
src/typing/typeload.ml

@@ -652,6 +652,7 @@ and load_complex_type ctx allow_display p (t,pn) =
 				cf_kind = access;
 				cf_params = !params;
 				cf_expr = None;
+				cf_expr_unoptimized = None;
 				cf_doc = f.cff_doc;
 				cf_meta = f.cff_meta;
 				cf_overloads = [];
@@ -2286,6 +2287,7 @@ module ClassInitializer = struct
 			cf_name_pos = pos f.cff_name;
 			cf_kind = Var (if fctx.is_inline then { v_read = AccInline ; v_write = AccNever } else { v_read = AccNormal; v_write = AccNormal });
 			cf_expr = None;
+			cf_expr_unoptimized = None;
 			cf_public = is_public (ctx,cctx) f.cff_access None;
 			cf_params = [];
 			cf_overloads = [];
@@ -2510,6 +2512,7 @@ module ClassInitializer = struct
 			cf_name_pos = pos f.cff_name;
 			cf_kind = Method (if fctx.is_macro then MethMacro else if fctx.is_inline then MethInline else if dynamic then MethDynamic else MethNormal);
 			cf_expr = None;
+			cf_expr_unoptimized = None;
 			cf_public = is_public (ctx,cctx) f.cff_access parent;
 			cf_params = params;
 			cf_overloads = [];
@@ -2684,6 +2687,7 @@ module ClassInitializer = struct
 			cf_name_pos = pos f.cff_name;
 			cf_kind = Var { v_read = get; v_write = set };
 			cf_expr = None;
+			cf_expr_unoptimized = None;
 			cf_type = ret;
 			cf_public = is_public (ctx,cctx) f.cff_access None;
 			cf_params = [];
@@ -3240,6 +3244,7 @@ let init_module_type ctx context_init do_init (decl,p) =
 				cf_doc = f.ef_doc;
 				cf_meta = no_meta;
 				cf_expr = None;
+				cf_expr_unoptimized = None;
 				cf_params = f.ef_params;
 				cf_overloads = [];
 			} in
@@ -4044,6 +4049,7 @@ let extend_xml_proxy ctx c t file p =
 						cf_kind = Var { v_read = AccResolve; v_write = AccNo };
 						cf_params = [];
 						cf_expr = None;
+						cf_expr_unoptimized = None;
 						cf_overloads = [];
 					} in
 					c.cl_fields <- PMap.add id f c.cl_fields;

+ 5 - 2
src/typing/typer.ml

@@ -864,8 +864,9 @@ let make_call ctx e params t p =
 		ignore(follow f.cf_type); (* force evaluation *)
 		let params = List.map (ctx.g.do_optimize ctx) params in
 		let force_inline = is_forced_inline cl f in
-		(match f.cf_expr with
-		| Some { eexpr = TFunction fd } ->
+		(match f.cf_expr_unoptimized,f.cf_expr with
+		| Some fd,_
+		| None,Some { eexpr = TFunction fd } ->
 			(match Optimizer.type_inline ctx f fd ethis params t config p force_inline with
 			| None ->
 				if force_inline then error "Inline could not be done" p;
@@ -1502,6 +1503,7 @@ and type_field ?(resume=false) ctx e i p mode =
 					cf_name_pos = null_pos;
 					cf_kind = Var { v_read = AccNormal; v_write = (match mode with MSet -> AccNormal | MGet | MCall -> AccNo) };
 					cf_expr = None;
+					cf_expr_unoptimized = None;
 					cf_params = [];
 					cf_overloads = [];
 				} in
@@ -1519,6 +1521,7 @@ and type_field ?(resume=false) ctx e i p mode =
 			cf_name_pos = null_pos;
 			cf_kind = Var { v_read = AccNormal; v_write = (match mode with MSet -> AccNormal | MGet | MCall -> AccNo) };
 			cf_expr = None;
+			cf_expr_unoptimized = None;
 			cf_params = [];
 			cf_overloads = [];
 		} in