Browse Source

use the same inline config for typer-time and optimizer-time inlining (fixes #9058)

Aleksandr Kuzmenko 5 years ago
parent
commit
33ceaf4c0a
4 changed files with 28 additions and 24 deletions
  1. 2 1
      extra/CHANGES.txt
  2. 22 0
      src/optimization/inline.ml
  3. 3 2
      src/optimization/optimizer.ml
  4. 1 21
      src/typing/calls.ml

+ 2 - 1
extra/CHANGES.txt

@@ -4,7 +4,8 @@
 
 	all : emit an error on an attempt to modify abstract `this` through a chain of inlined calls in a non-inlined method (#9067)
 	all : fixed completion of target specific hx files without the common hx file (e.g. `Example.js.hx` with non-existent `Example.hx`) (#6435)
-	js : fix startup exception in IE8 related to `Object.defineProperty` (#6918)
+	all : fixed inlining regression (#9058)
+	js : fixed startup exception in IE8 related to `Object.defineProperty` (#6918)
 
 
 2019-12-17: 4.0.5

+ 22 - 0
src/optimization/inline.ml

@@ -239,6 +239,28 @@ let inline_default_config cf t =
 	let tparams = fst tparams @ cf.cf_params in
 	tparams <> [], apply_params tparams tmonos
 
+let inline_config cls_opt cf call_args return_type =
+	match cls_opt with
+	| Some ({cl_kind = KAbstractImpl _}) when Meta.has Meta.Impl cf.cf_meta ->
+		let t = if cf.cf_name = "_new" then
+			return_type
+		else if call_args = [] then
+			error "Invalid abstract implementation function" cf.cf_pos
+		else
+			follow (List.hd call_args).etype
+		in
+		begin match t with
+			| TAbstract(a,pl) ->
+				let has_params = a.a_params <> [] || cf.cf_params <> [] in
+				let monos = List.map (fun _ -> mk_mono()) cf.cf_params in
+				let map_type = fun t -> apply_params a.a_params pl (apply_params cf.cf_params monos t) in
+				Some (has_params,map_type)
+			| _ ->
+				None
+		end
+	| _ ->
+		None
+
 let inline_metadata e meta =
 	let inline_meta e meta = match meta with
 		| (Meta.Deprecated | Meta.Pure),_,_ -> mk (TMeta(meta,e)) e.etype e.epos

+ 3 - 2
src/optimization/optimizer.ml

@@ -282,11 +282,12 @@ 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 && not (rec_stack_memq cf inline_stack) ->
+			| {eexpr = TField(ef,(FStatic(cl,cf) | FInstance(cl,_,cf)))} when cf.cf_kind = Method MethInline && not (rec_stack_memq cf inline_stack) ->
 				begin match cf.cf_expr with
 				| Some {eexpr = TFunction tf} ->
+					let config = inline_config (Some cl) cf el e.etype 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 false with Error (Custom _,_) -> None) in
+					let inl = (try type_inline ctx cf tf ef el rt config e.epos false with Error (Custom _,_) -> None) in
 					(match inl with
 					| None -> reduce_expr ctx e
 					| Some e ->

+ 1 - 21
src/typing/calls.ml

@@ -44,27 +44,7 @@ let make_call ctx e params t ?(force_inline=false) p =
 					if List.exists has_override c.cl_descendants then error (Printf.sprintf "Cannot force inline-call to %s because it is overridden" f.cf_name) p
 				)
 		end;
-		let config = match cl with
-			| Some ({cl_kind = KAbstractImpl _}) when Meta.has Meta.Impl f.cf_meta ->
-				let t = if f.cf_name = "_new" then
-					t
-				else if params = [] then
-					error "Invalid abstract implementation function" f.cf_pos
-				else
-					follow (List.hd params).etype
-				in
-				begin match t with
-					| TAbstract(a,pl) ->
-						let has_params = a.a_params <> [] || f.cf_params <> [] in
-						let monos = List.map (fun _ -> mk_mono()) f.cf_params in
-						let map_type = fun t -> apply_params a.a_params pl (apply_params f.cf_params monos t) in
-						Some (has_params,map_type)
-					| _ ->
-						None
-				end
-			| _ ->
-				None
-		in
+		let config = Inline.inline_config cl f params t in
 		ignore(follow f.cf_type); (* force evaluation *)
 		(match cl, ctx.curclass.cl_kind, params with
 			| Some c, KAbstractImpl _, { eexpr = TLocal { v_meta = v_meta } } :: _ when c == ctx.curclass ->