Browse Source

[inline] remove unused None return

Simon Krajewski 2 years ago
parent
commit
f703ba6bde

+ 4 - 6
src/optimization/inline.ml

@@ -656,7 +656,7 @@ let rec type_inline ctx cf f ethis params tret config p ?(self_calling_closure=f
 		) in
 		(match api_inline ctx cl cf.cf_name params p with
 		| None -> raise Exit
-		| Some e -> Some e)
+		| Some e -> e)
 	with Exit ->
 	let has_params,map_type = match config with Some config -> config | None -> inline_default_config cf ethis.etype in
 	let params = inline_rest_params ctx f params map_type p in
@@ -831,10 +831,8 @@ let rec type_inline ctx cf f ethis params tret config p ?(self_calling_closure=f
 			state#set_side_effect;
 			begin match follow t with
 			| TInst({ cl_constructor = Some ({cf_kind = Method MethInline; cf_expr = Some ({eexpr = TFunction tf})} as cf)} as c,_) ->
-				begin match type_inline_ctor ctx c cf tf ethis el po with
-				| Some e -> map term false e
-				| None -> raise_typing_error "Could not inline super constructor call" po
-				end
+				let e = type_inline_ctor ctx c cf tf ethis el po in
+				map term false e
 			| _ -> raise_typing_error "Cannot inline function containing super" po
 			end
 		| TCall(e1,el) ->
@@ -876,7 +874,7 @@ let rec type_inline ctx cf f ethis params tret config p ?(self_calling_closure=f
 			(se "\t" e)
 		);
 	end;
-	Some e
+	e
 
 (* Same as type_inline, but modifies the function body to add field inits *)
 and type_inline_ctor ctx c cf tf ethis el po =

+ 41 - 51
src/optimization/inlineConstructors.ml

@@ -374,34 +374,29 @@ let inline_constructors ctx original_e =
 					let argvs, pl = analyze_call_args pl in
 					let _, cname = c.cl_path in
 					let v = alloc_var VGenerated ("inl"^cname) e.etype e.epos in
-					match Inline.type_inline_ctor ctx c cf tf (mk (TLocal v) (TInst (c,tl)) e.epos) pl e.epos with
-					| Some inlined_expr ->
-						let inlined_expr = mark_ctors inlined_expr in
-						let has_untyped = (Meta.has Meta.HasUntyped cf.cf_meta) in
-						let forced = is_extern_ctor c cf || force_inline in
-						let io = mk_io (IOKCtor{ioc_class=c; ioc_tparams=tl; ioc_field=cf; ioc_forced=forced}) io_id inlined_expr ~has_untyped:has_untyped in
-						io.io_dependent_vars <- argvs;
-						let rec loop (c:tclass) (tl:t list) =
-							let apply = apply_params c.cl_params tl in
-							List.iter (fun cf ->
-								match cf.cf_kind,cf.cf_expr with
-								| Var _, _ ->
-									let fieldt = apply cf.cf_type in
-									ignore(alloc_io_field io cf.cf_name fieldt v.v_pos);
-								| _ -> ()
-							) c.cl_ordered_fields;
-							match c.cl_super with
-							| Some (c,tl) -> loop c (List.map apply tl)
-							| None -> ()
-						in loop c tl;
-						let iv = add v IVKLocal in
-						set_iv_alias iv io;
-						ignore(analyze_aliases_in_ctor cf true io.io_expr);
-						Some iv
-					| _ ->
-						List.iter (fun v -> cancel_v v v.v_pos) argvs;
-						if is_extern_ctor c cf then display_error ctx.com "Extern constructor could not be inlined" e.epos;
-						None
+					let inlined_expr = Inline.type_inline_ctor ctx c cf tf (mk (TLocal v) (TInst (c,tl)) e.epos) pl e.epos in
+					let inlined_expr = mark_ctors inlined_expr in
+					let has_untyped = (Meta.has Meta.HasUntyped cf.cf_meta) in
+					let forced = is_extern_ctor c cf || force_inline in
+					let io = mk_io (IOKCtor{ioc_class=c; ioc_tparams=tl; ioc_field=cf; ioc_forced=forced}) io_id inlined_expr ~has_untyped:has_untyped in
+					io.io_dependent_vars <- argvs;
+					let rec loop (c:tclass) (tl:t list) =
+						let apply = apply_params c.cl_params tl in
+						List.iter (fun cf ->
+							match cf.cf_kind,cf.cf_expr with
+							| Var _, _ ->
+								let fieldt = apply cf.cf_type in
+								ignore(alloc_io_field io cf.cf_name fieldt v.v_pos);
+							| _ -> ()
+						) c.cl_ordered_fields;
+						match c.cl_super with
+						| Some (c,tl) -> loop c (List.map apply tl)
+						| None -> ()
+					in loop c tl;
+					let iv = add v IVKLocal in
+					set_iv_alias iv io;
+					ignore(analyze_aliases_in_ctor cf true io.io_expr);
+					Some iv
 				end
 			| TNew({ cl_constructor = Some ({cf_kind = Method MethInline; cf_expr = Some _} as cf)} as c,_,pl),_ when is_extern_ctor c cf ->
 				raise_typing_error "Extern constructor could not be inlined" e.epos;
@@ -501,29 +496,24 @@ let inline_constructors ctx original_e =
 				let argvs, pl = analyze_call_args call_args in
 				io.io_dependent_vars <- io.io_dependent_vars @ argvs;
 				io.io_has_untyped <- io.io_has_untyped or (Meta.has Meta.HasUntyped cf.cf_meta);
-				begin match Inline.type_inline ctx cf tf (mk (TLocal io_var.iv_var) (TInst (c,tl)) e.epos) pl e.etype None e.epos true with
-				| Some e ->
-					let e = mark_ctors e in
-					io.io_inline_methods <- io.io_inline_methods @ [e];
-					begin match analyze_aliases captured e with
-						| Some(iv) ->
-							(*
-								The parent inline object might have been cancelled while analyzing the inlined method body
-								If the parent inline object is cancelled the inlining of this method will no longer happen,
-								so the return value must be cancelled.
-							*)
-							if io.io_cancelled then begin
-								cancel_iv iv e.epos;
-								None
-							end else begin
-								io.io_dependent_vars <- iv.iv_var :: io.io_dependent_vars;
-								Some(iv)
-							end
-						| None -> None
-					end
-				| None ->
-					cancel_io io e.epos;
-					None
+				let e = Inline.type_inline ctx cf tf (mk (TLocal io_var.iv_var) (TInst (c,tl)) e.epos) pl e.etype None e.epos true in
+				let e = mark_ctors e in
+				io.io_inline_methods <- io.io_inline_methods @ [e];
+				begin match analyze_aliases captured e with
+					| Some(iv) ->
+						(*
+							The parent inline object might have been cancelled while analyzing the inlined method body
+							If the parent inline object is cancelled the inlining of this method will no longer happen,
+							so the return value must be cancelled.
+						*)
+						if io.io_cancelled then begin
+							cancel_iv iv e.epos;
+							None
+						end else begin
+							io.io_dependent_vars <- iv.iv_var :: io.io_dependent_vars;
+							Some(iv)
+						end
+					| None -> None
 				end
 			| IOFInlineVar(iv) ->
 				cancel_iv iv e.epos;

+ 12 - 9
src/optimization/optimizer.ml

@@ -352,20 +352,23 @@ let rec reduce_loop ctx e =
 				let cf = mk_field "" ef.etype e.epos null_pos in
 				let ethis = mk (TConst TThis) t_dynamic e.epos in
 				let rt = (match follow ef.etype with TFun (_,rt) -> rt | _ -> die "" __LOC__) in
-				let inl = (try type_inline ctx cf func ethis el rt None e.epos ~self_calling_closure:true false with Error { err_message = Custom _ } -> None) in
-				(match inl with
-				| None -> reduce_expr ctx e
-				| Some e -> reduce_loop ctx e)
+				begin try
+					let e = type_inline ctx cf func ethis el rt None e.epos ~self_calling_closure:true false in
+					reduce_loop ctx e
+				with Error { err_message = Custom _ } ->
+					reduce_expr ctx e
+				end;
 			| {eexpr = TField(ef,(FStatic(cl,cf) | FInstance(cl,_,cf)))} when needs_inline ctx (Some cl) cf && 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 Abstract.follow_with_abstracts e1.etype with TFun (_,rt) -> rt | _ -> die "" __LOC__) in
-					let inl = (try type_inline ctx cf tf ef el rt config e.epos false with Error { err_message = Custom _ } -> None) in
-					(match inl with
-					| None -> reduce_expr ctx e
-					| Some e ->
-						rec_stack_default inline_stack cf (fun cf' -> cf' == cf) (fun () -> reduce_loop ctx e) e)
+					begin try
+						let e = type_inline ctx cf tf ef el rt config e.epos false in
+						rec_stack_default inline_stack cf (fun cf' -> cf' == cf) (fun () -> reduce_loop ctx e) e
+					with Error { err_message = Custom _ } ->
+						reduce_expr ctx e
+					end
 				| _ ->
 					reduce_expr ctx e
 				end

+ 1 - 5
src/typing/calls.ml

@@ -70,11 +70,7 @@ let make_call ctx e params t ?(force_inline=false) p =
 		(match f.cf_expr_unoptimized,f.cf_expr with
 		| Some {eexpr = TFunction fd},_
 		| None,Some { eexpr = TFunction fd } ->
-			(match Inline.type_inline ctx f fd ethis params t config p force_inline with
-			| None ->
-				if force_inline then raise_typing_error "Inline could not be done" p;
-				raise Exit;
-			| Some e -> e)
+			Inline.type_inline ctx f fd ethis params t config p force_inline
 		| _ ->
 			(*
 				we can't inline because there is most likely a loop in the typing.