فهرست منبع

only use explicit type for 'using' completion (faster)

Nicolas Cannasse 13 سال پیش
والد
کامیت
58b8fe76b7
3فایلهای تغییر یافته به همراه41 افزوده شده و 31 حذف شده
  1. 1 0
      main.ml
  2. 26 21
      typeload.ml
  3. 14 10
      typer.ml

+ 1 - 0
main.ml

@@ -530,6 +530,7 @@ and wait_loop boot_com host port =
 				Common.display_default := false;
 				Common.default_print := (fun str -> ssend sin ("\x01" ^ str));
 				Parser.resume_display := Ast.null_pos;
+				Typeload.return_partial_type := false;
 				measure_times := false;
 				close_times();
 				stats.s_files_parsed := 0;

+ 26 - 21
typeload.ml

@@ -34,6 +34,7 @@ let parse_file com file p =
 
 let parse_hook = ref parse_file
 let type_module_hook = ref (fun _ _ _ -> None)
+let return_partial_type = ref false
 
 let type_function_param ctx t e opt p =
 	match e with
@@ -891,11 +892,13 @@ let init_class ctx c p herits fields =
 					(fun() -> ())
 				| Some e ->
 					let r = exc_protect (fun r ->
-						r := (fun() -> t);
-						if ctx.com.verbose then Common.log ctx.com ("Typing " ^ s_type_path c.cl_path ^ "." ^ name);
-						mark_used cf;
-						cf.cf_expr <- Some (type_static_var ctx t e p);
-						cf.cf_type <- t;
+						if not !return_partial_type then begin
+							r := (fun() -> t);
+							if ctx.com.verbose then Common.log ctx.com ("Typing " ^ (if ctx.in_macro then "macro " else "") ^ s_type_path c.cl_path ^ "." ^ name);
+							mark_used cf;
+							cf.cf_expr <- Some (type_static_var ctx t e p);
+							cf.cf_type <- t;
+						end;
 						t
 					) in
 					bind_type cf r (snd e) false
@@ -975,22 +978,24 @@ let init_class ctx c p herits fields =
 				cf_params = params;
 			} in
 			let r = exc_protect (fun r ->
-				r := (fun() -> t);
-				incr stats.s_methods_typed;
-				if ctx.com.verbose then Common.log ctx.com ("Typing " ^ s_type_path c.cl_path ^ "." ^ name);
-				let e , fargs = type_function ctx args ret (if constr then FConstructor else if stat then FStatic else FMember) fd p in
-				let f = {
-					tf_args = fargs;
-					tf_type = ret;
-					tf_expr = e;
-				} in
-				if stat && name = "__init__" then
-					(match e.eexpr with
-					| TBlock [] | TBlock [{ eexpr = TConst _ }] | TConst _ | TObjectDecl [] -> ()
-					| _ -> c.cl_init <- Some e);
-				mark_used cf;
-				cf.cf_expr <- Some (mk (TFunction f) t p);
-				cf.cf_type <- t;
+				if not !return_partial_type then begin
+					r := (fun() -> t);
+					incr stats.s_methods_typed;
+					if ctx.com.verbose then Common.log ctx.com ("Typing " ^ (if ctx.in_macro then "macro " else "") ^ s_type_path c.cl_path ^ "." ^ name);
+					let e , fargs = type_function ctx args ret (if constr then FConstructor else if stat then FStatic else FMember) fd p in
+					let f = {
+						tf_args = fargs;
+						tf_type = ret;
+						tf_expr = e;
+					} in
+					if stat && name = "__init__" then
+						(match e.eexpr with
+						| TBlock [] | TBlock [{ eexpr = TConst _ }] | TConst _ | TObjectDecl [] -> ()
+						| _ -> c.cl_init <- Some e);
+					mark_used cf;
+					cf.cf_expr <- Some (mk (TFunction f) t p);
+					cf.cf_type <- t;
+				end;
 				t
 			) in
 			let delay = if ((c.cl_extern && not inline) || c.cl_interface) && cf.cf_name <> "__init__" then

+ 14 - 10
typer.ml

@@ -1698,18 +1698,21 @@ and type_expr ctx ?(need_val=true) (e,p) =
 		ctx.in_display <- true;
 		let e = (try type_expr ctx e with Error (Unknown_ident n,_) -> raise (Parser.TypePath ([n],None))) in
 		ctx.in_display <- old;
+		let opt_type t =
+			match t with
+			| TLazy f ->
+				Typeload.return_partial_type := true;
+				let t = (!f)() in
+				Typeload.return_partial_type := false;
+				t
+			| _ ->
+				t
+		in
 		let fields = (match follow e.etype with
 			| TInst (c,params) ->
 				let priv = is_parent c ctx.curclass in
-				let opt_field f =
-					match f.cf_type with
-					| TLazy _ ->
-						(* this is not yet typed, let's put a fake method : this will speedup results *)
-						{ f with cf_type = TFun ([],ctx.t.tvoid) }
-					| _ -> f
-				in
 				let merge ?(cond=(fun _ -> true)) a b =
-					PMap.foldi (fun k f m -> if cond f then PMap.add k (opt_field f) m else m) a b
+					PMap.foldi (fun k f m -> if cond f then PMap.add k f m else m) a b
 				in
 				let rec loop c params =
 					let m = List.fold_left (fun m (i,params) ->
@@ -1720,13 +1723,13 @@ and type_expr ctx ?(need_val=true) (e,p) =
 						| Some (csup,cparams) -> merge m (loop csup cparams)
 					) in
 					let m = merge ~cond:(fun f -> priv || f.cf_public) c.cl_fields m in
-					PMap.map (fun f -> { f with cf_type = apply_params c.cl_types params f.cf_type; cf_public = true; }) m
+					PMap.map (fun f -> { f with cf_type = apply_params c.cl_types params (opt_type f.cf_type); cf_public = true; }) m
 				in
 				loop c params
 			| TAnon a ->
 				(match !(a.a_status) with
 				| Statics c when is_parent c ctx.curclass ->
-					PMap.map (fun f -> { f with cf_public = true }) a.a_fields
+					PMap.map (fun f -> { f with cf_public = true; cf_type = opt_type f.cf_type }) a.a_fields
 				| _ ->
 					a.a_fields)
 			| _ ->
@@ -1743,6 +1746,7 @@ and type_expr ctx ?(need_val=true) (e,p) =
 				| TClassDecl c ->
 					let rec dup t = Type.map dup t in
 					List.iter (fun f ->
+						let f = { f with cf_type = opt_type f.cf_type } in
 						match follow (field_type f) with
 						| TFun ((_,_,t) :: args, ret) when (try unify_raise ctx (dup e.etype) t e.epos; true with _ -> false) ->
 							let f = { f with cf_type = TFun (args,ret); cf_params = [] } in