Skip to content

Commit

Permalink
Extract typer_pass to avoid extra dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
kLabz committed Jan 20, 2025
1 parent 3b3f073 commit c96ffdf
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/compiler/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ let get_hxb_module com cc path =
class hxb_reader_api_server
(com : Common.context)
(cc : context_cache)
(delay : Typecore.typer_pass -> (unit -> unit) -> unit)
(delay : TyperPass.typer_pass -> (unit -> unit) -> unit)
= object(self)

method make_module (path : path) (file : string) =
Expand Down
2 changes: 1 addition & 1 deletion src/context/display/syntaxExplorer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ let explore_uncached_modules tctx cs symbols =
begin try
let m = tctx.g.do_load_module tctx (cfile.c_package,module_name) null_pos in
(* We have to flush immediately so we catch exceptions from weird modules *)
Typecore.flush_pass tctx.g Typecore.PFinal ("final",cfile.c_package @ [module_name]);
Typecore.flush_pass tctx.g PFinal ("final",cfile.c_package @ [module_name]);
m :: acc
with _ ->
acc
Expand Down
18 changes: 2 additions & 16 deletions src/context/typecore.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ open Globals
open Ast
open Common
open Type
open TyperPass
open Error
open Resolution
open FieldCallCandidate
Expand Down Expand Up @@ -50,21 +51,6 @@ type access_mode =
| MSet of Ast.expr option (* rhs, if exists *)
| MCall of Ast.expr list (* call arguments *)

type typer_pass =
| PBuildModule (* build the module structure and setup module type parameters *)
| PBuildClass (* build the class structure *)
| PConnectField (* handle associated fields, which may affect each other. E.g. a property and its getter *)
| PTypeField (* type the class field, allow access to types structures *)
| PCheckConstraint (* perform late constraint checks with inferred types *)
| PForce (* usually ensure that lazy have been evaluated *)
| PFinal (* not used, only mark for finalize *)

let all_typer_passes = [
PBuildModule;PBuildClass;PConnectField;PTypeField;PCheckConstraint;PForce;PFinal
]

let all_typer_passes_length = List.length all_typer_passes

type typer_module = {
curmod : module_def;
import_resolution : resolution_list;
Expand Down Expand Up @@ -478,7 +464,7 @@ let delay_if_mono g p t f = match follow t with
| _ ->
f()

let rec flush_pass g p where =
let rec flush_pass g (p : typer_pass) where =
let rec loop i =
if i > (Obj.magic p) then
()
Expand Down
14 changes: 14 additions & 0 deletions src/context/typerPass.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
type typer_pass =
| PBuildModule (* build the module structure and setup module type parameters *)
| PBuildClass (* build the class structure *)
| PConnectField (* handle associated fields, which may affect each other. E.g. a property and its getter *)
| PTypeField (* type the class field, allow access to types structures *)
| PCheckConstraint (* perform late constraint checks with inferred types *)
| PForce (* usually ensure that lazy have been evaluated *)
| PFinal (* not used, only mark for finalize *)

let all_typer_passes = [
PBuildModule;PBuildClass;PConnectField;PTypeField;PCheckConstraint;PForce;PFinal
]

let all_typer_passes_length = List.length all_typer_passes
3 changes: 2 additions & 1 deletion src/typing/typeloadCacheHook.ml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
open Globals
open TType
open TyperPass
open Common
open TFunctions

Expand All @@ -9,7 +10,7 @@ type find_module_result =
| BinaryModule of HxbData.module_cache
| NoModule

let type_module_hook : (Common.context -> (Typecore.typer_pass -> (unit -> unit) -> unit) -> path -> pos -> find_module_result) ref = ref (fun _ _ _ _ -> NoModule)
let type_module_hook : (Common.context -> (typer_pass -> (unit -> unit) -> unit) -> path -> pos -> find_module_result) ref = ref (fun _ _ _ _ -> NoModule)

let fake_modules = Hashtbl.create 0

Expand Down
2 changes: 1 addition & 1 deletion src/typing/typerEntry.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ let create com macros =
core_api = None;
macros = macros;
module_check_policies = [];
delayed = Array.init all_typer_passes_length (fun _ -> { tasks = []});
delayed = Array.init TyperPass.all_typer_passes_length (fun _ -> { tasks = []});
delayed_min_index = 0;
debug_delayed = [];
doinline = com.display.dms_inline && not (Common.defined com Define.NoInline);
Expand Down

0 comments on commit c96ffdf

Please sign in to comment.