Skip to content

Commit

Permalink
[typer] move t_dynamic_def to typer globals
Browse files Browse the repository at this point in the history
I have no idea why I didn't do that in the first place and instead wrote that essay...
  • Loading branch information
Simn committed Jan 11, 2024
1 parent 07918a0 commit 5f3acad
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 15 deletions.
14 changes: 7 additions & 7 deletions src/context/display/displayEmitter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)) ->
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/context/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 0 additions & 6 deletions src/core/tFunctions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/typing/typerDisplay.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/typing/typerEntry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5f3acad

Please sign in to comment.