소스 검색

[typer] move t_dynamic_def to typer globals

I have no idea why I didn't do that in the first place and instead wrote that essay...
Simon Krajewski 1 년 전
부모
커밋
5f3acadf3a
5개의 변경된 파일11개의 추가작업 그리고 15개의 파일을 삭제
  1. 7 7
      src/context/display/displayEmitter.ml
  2. 1 0
      src/context/typecore.ml
  3. 0 6
      src/core/tFunctions.ml
  4. 1 1
      src/typing/typerDisplay.ml
  5. 2 1
      src/typing/typerEntry.ml

+ 7 - 7
src/context/display/displayEmitter.ml

@@ -54,9 +54,9 @@ let rec display_type ctx t p =
 	try
 		display_module_type ctx (module_type_of_type t) p
 	with Exit ->
-		match follow t,follow !t_dynamic_def with
+		match follow t,follow ctx.g.t_dynamic_def with
 		| _,TDynamic _ -> () (* sanity check in case it's still t_dynamic *)
-		| TDynamic _,_ -> display_type ctx !t_dynamic_def p
+		| TDynamic _,_ -> display_type ctx ctx.g.t_dynamic_def p
 		| _ ->
 			match dm.dms_kind with
 			| DMHover ->
@@ -77,14 +77,14 @@ let check_display_type ctx t ptp =
 	add_type_hint();
 	maybe_display_type()
 
-let raise_position_of_type t =
+let raise_position_of_type ctx t =
 	let mt =
 		let rec follow_null t =
 			match t with
 				| TMono r -> (match r.tm_type with None -> raise_positions [null_pos] | Some t -> follow_null t)
 				| TLazy f -> follow_null (lazy_type f)
 				| TAbstract({a_path = [],"Null"},[t]) -> follow_null t
-				| TDynamic _ -> !t_dynamic_def
+				| TDynamic _ -> ctx.g.t_dynamic_def
 				| _ -> t
 		in
 		try
@@ -96,7 +96,7 @@ let raise_position_of_type t =
 
 let display_variable ctx v p = match ctx.com.display.dms_kind with
 	| DMDefinition -> raise_positions [v.v_pos]
-	| DMTypeDefinition -> raise_position_of_type v.v_type
+	| DMTypeDefinition -> raise_position_of_type ctx v.v_type
 	| DMUsage _ -> ReferencePosition.set (v.v_name,v.v_pos,SKVariable v)
 	| DMHover ->
 		let ct = CompletionType.from_type (get_import_status ctx) ~values:(get_value_meta v.v_meta) v.v_type in
@@ -105,7 +105,7 @@ let display_variable ctx v p = match ctx.com.display.dms_kind with
 
 let display_field ctx origin scope cf p = match ctx.com.display.dms_kind with
 	| DMDefinition -> raise_positions [cf.cf_name_pos]
-	| DMTypeDefinition -> raise_position_of_type cf.cf_type
+	| DMTypeDefinition -> raise_position_of_type ctx cf.cf_type
 	| DMUsage _ | DMImplementation ->
 		let name,kind = match cf.cf_name,origin with
 			| "new",(Self (TClassDecl c) | Parent(TClassDecl c)) ->
@@ -136,7 +136,7 @@ let maybe_display_field ctx origin scope cf p =
 
 let display_enum_field ctx en ef p = match ctx.com.display.dms_kind with
 	| DMDefinition -> raise_positions [ef.ef_name_pos]
-	| DMTypeDefinition -> raise_position_of_type ef.ef_type
+	| DMTypeDefinition -> raise_position_of_type ctx ef.ef_type
 	| DMUsage _ -> ReferencePosition.set (ef.ef_name,ef.ef_name_pos,SKEnumField ef)
 	| DMHover ->
 		let ct = CompletionType.from_type (get_import_status ctx) ef.ef_type in

+ 1 - 0
src/context/typecore.ml

@@ -117,6 +117,7 @@ type typer_globals = {
 	functional_interface_lut : (path,tclass_field) lookup;
 	mutable return_partial_type : bool;
 	mutable build_count : int;
+	mutable t_dynamic_def : Type.t;
 	(* api *)
 	do_macro : typer -> macro_mode -> path -> string -> expr list -> pos -> macro_result;
 	do_load_macro : typer -> bool -> path -> string -> pos -> ((string * bool * t) list * t * tclass * Type.tclass_field);

+ 0 - 6
src/core/tFunctions.ml

@@ -97,12 +97,6 @@ let mk_anon ?fields status =
 	let fields = match fields with Some fields -> fields | None -> PMap.empty in
 	TAnon { a_fields = fields; a_status = status; }
 
-(* We use this for display purposes because otherwise we never see the Dynamic type that
-   is defined in StdTypes.hx. This is set each time a typer is created, but this is fine
-   because Dynamic is the same in all contexts. If this ever changes we'll have to review
-   how we handle this. *)
-let t_dynamic_def = ref t_dynamic
-
 let tfun pl r = TFun (List.map (fun t -> "",false,t) pl,r)
 
 let fun_args l = List.map (fun (a,c,t) -> a, c <> None, t) l

+ 1 - 1
src/typing/typerDisplay.ml

@@ -490,7 +490,7 @@ and display_expr ctx e_ast e dk mode with_type p =
 		let pl = loop e in
 		raise_positions pl
 	| DMTypeDefinition ->
-		raise_position_of_type e.etype
+		raise_position_of_type ctx e.etype
 	| DMDefault when not (!Parser.had_resume)->
 		let display_fields e_ast e1 so =
 			let l = match so with None -> 0 | Some s -> String.length s in

+ 2 - 1
src/typing/typerEntry.ml

@@ -27,6 +27,7 @@ let create com macros =
 			load_only_cached_modules = false;
 			return_partial_type = false;
 			build_count = 0;
+			t_dynamic_def = t_dynamic;
 			functional_interface_lut = new Lookup.pmap_lookup;
 			do_macro = MacroContext.type_macro;
 			do_load_macro = MacroContext.load_macro';
@@ -110,7 +111,7 @@ let create com macros =
 				Type.unify t ctx.t.tbool;
 				ctx.t.tbool <- t
 			| "Dynamic" ->
-				t_dynamic_def := TAbstract(a,extract_param_types a.a_params);
+				ctx.g.t_dynamic_def <- TAbstract(a,extract_param_types a.a_params);
 			| "Null" ->
 				let mk_null t =
 					try