Skip to content

Commit a6d8fe0

Browse files
CopilotSimn
andcommitted
Revert #12747 changes, keep only eval Domain changes, restore TestTimer test
Co-authored-by: Simn <634365+Simn@users.noreply.github.com>
1 parent c33223a commit a6d8fe0

File tree

16 files changed

+124
-154
lines changed

16 files changed

+124
-154
lines changed

src/codegen/dump.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ let dump_types com pretty =
127127
);
128128
close()
129129
in
130-
Parallel.run_with_pool com.sctx.pool (fun pool ->
130+
Parallel.run_in_new_pool com.timer_ctx (fun pool ->
131131
Parallel.ParallelArray.iter pool f (Array.of_list com.types)
132132
);
133133
restore()
@@ -144,7 +144,7 @@ let dump_record com =
144144
Buffer.add_string buf s;
145145
close()
146146
in
147-
Parallel.run_with_pool com.sctx.pool (fun pool ->
147+
Parallel.run_in_new_pool com.timer_ctx (fun pool ->
148148
Parallel.ParallelArray.iter pool f (Array.of_list com.types)
149149
)
150150

@@ -169,7 +169,7 @@ let dump_position com =
169169
| _ ->
170170
()
171171
in
172-
Parallel.run_with_pool com.sctx.pool (fun pool ->
172+
Parallel.run_in_new_pool com.timer_ctx (fun pool ->
173173
Parallel.ParallelArray.iter pool f (Array.of_list com.types)
174174
)
175175

src/compiler/generate.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ let check_hxb_output ctx config =
8383
None
8484
in
8585
let a_in = Array.of_list com.modules in
86-
let a_out = Parallel.run_with_pool com.sctx.pool (fun pool ->
86+
let a_out = Parallel.run_in_new_pool com.timer_ctx (fun pool ->
8787
Parallel.ParallelArray.map pool f a_in None
8888
) in
8989
Array.iter (function

src/compiler/haxe.ml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,9 @@ let start_semaphore = Semaphore.Binary.make false in
6363
let run_compiler () =
6464
Semaphore.Binary.acquire start_semaphore;
6565
let sctx = ServerCompilationContext.create false in
66-
Std.finally (fun () -> ServerCompilationContext.dispose sctx) (fun () ->
67-
let request_scope = Server.create_request_scope () in
68-
let parsed_args = Args.parse_args sctx args in
69-
Server.process sctx request_scope Compiler.HighLevel.entry (ServerCommunication.Communication.create_stdio ()) parsed_args;
70-
) ()
66+
let request_scope = Server.create_request_scope () in
67+
let parsed_args = Args.parse_args sctx args in
68+
Server.process sctx request_scope Compiler.HighLevel.entry (ServerCommunication.Communication.create_stdio ()) parsed_args
7169
in
7270

7371
let main_domain = Domain.spawn run_compiler in

src/compiler/server/server.ml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ let wait_loop entry verbose accept =
351351
EvalMain.main_domain_hack := worker.domain;
352352
(* Main loop: accept connections and enqueue requests for the worker.
353353
The loop exits if the accept function raises an exception (e.g. socket closed). *)
354-
begin try
354+
(try
355355
while true do
356356
let conn = accept() in
357357
begin try
@@ -373,13 +373,10 @@ let wait_loop entry verbose accept =
373373
conn.close()
374374
end;
375375
done
376-
with _ ->
377-
()
378-
end;
376+
with _ -> ());
379377
(* Signal the worker to shut down and wait for it to finish *)
380378
RequestQueue.shutdown rq;
381379
Domain.join worker.domain;
382-
ServerCompilationContext.dispose sctx;
383380
0
384381

385382
(* Connect to given host/port and return accept function for communication *)

src/compiler/server/serverCompilationContext.ml

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ type t = {
2222
mutable macro_context_setup : bool;
2323
(* Stdin content for the current display request *)
2424
mutable current_stdin : string option;
25-
(* The server's domain pool. *)
26-
pool : Domainslib.Task.pool Lazy.t;
2725
}
2826

2927
let create_version () =
@@ -36,25 +34,18 @@ let create_version () =
3634
extra = Version.version_extra;
3735
}
3836

39-
let create verbose =
40-
let pool = lazy (Domainslib.Task.setup_pool ~num_domains:(Domain.recommended_domain_count() - 1) ()) in
41-
{
42-
version = create_version ();
43-
verbose;
44-
cs = new CompilationCache.cache;
45-
class_paths = Hashtbl.create 0;
46-
changed_directories = Hashtbl.create 0;
47-
compilation_step = 0;
48-
delays = [];
49-
was_compilation = false;
50-
macro_context_setup = false;
51-
current_stdin = None;
52-
pool;
53-
}
54-
55-
let dispose sctx =
56-
if Lazy.is_val sctx.pool then
57-
Domainslib.Task.teardown_pool (Lazy.force sctx.pool)
37+
let create verbose = {
38+
version = create_version ();
39+
verbose;
40+
cs = new CompilationCache.cache;
41+
class_paths = Hashtbl.create 0;
42+
changed_directories = Hashtbl.create 0;
43+
compilation_step = 0;
44+
delays = [];
45+
was_compilation = false;
46+
macro_context_setup = false;
47+
current_stdin = None;
48+
}
5849

5950
let add_delay sctx f =
6051
sctx.delays <- f :: sctx.delays

src/context/common.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,6 @@ let to_gctx com = {
390390
include_files = com.include_files;
391391
std = com.std;
392392
timer_ctx = com.timer_ctx;
393-
pool = com.sctx.pool;
394393
}
395394
let enter_stage com stage =
396395
(* print_endline (Printf.sprintf "Entering stage %s" (s_compiler_stage stage)); *)

src/context/commonCache.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ let rec cache_context cs com =
109109
DynArray.add parallels (cc,m,f)
110110
in
111111
List.iter cache_module com.modules;
112-
let a = Parallel.run_with_pool com.sctx.pool (fun pool ->
112+
let a = Parallel.run_in_new_pool com.timer_ctx (fun pool ->
113113
Parallel.ParallelArray.map pool (fun (cc,m,f) ->
114114
let chunks = f() in
115115
(cc,m,chunks)

src/context/parallel.ml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,3 @@ let run_in_new_pool timer_ctx f =
4444
else
4545
let pool = Timer.time timer_ctx ["domainslib";"setup"] (Domainslib.Task.setup_pool ~num_domains:(Domain.recommended_domain_count() - 1)) () in
4646
Std.finally (fun () -> Timer.time timer_ctx ["domainslib";"teardown"] Domainslib.Task.teardown_pool pool) (Domainslib.Task.run pool) (fun () -> f (Some pool))
47-
48-
let run_with_pool pool f =
49-
if not !enable then
50-
f None
51-
else
52-
let pool = Lazy.force pool in
53-
Domainslib.Task.run pool (fun () -> f (Some pool))

src/core/tFunctions.ml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ let alloc_var =
9191
alloc_var
9292

9393
let alloc_mid =
94-
let mid = Atomic.make 0 in
95-
(fun() -> Atomic.incr mid; Atomic.get mid)
94+
let mid = ref 0 in
95+
(fun() -> incr mid; !mid)
9696

9797
let mk e t p = { eexpr = e; etype = t; epos = p }
9898

@@ -563,17 +563,19 @@ let apply_typedef td tl =
563563
let monomorphs eparams t =
564564
apply_params eparams (List.map (fun _ -> mk_mono()) eparams) t
565565

566-
let try_apply_params_rec stack cparams params t success =
567-
let old_stack = !stack in
566+
let apply_params_stack = ref []
567+
568+
let try_apply_params_rec cparams params t success =
569+
let old_stack = !apply_params_stack in
568570
try
569-
let result = success (apply_params ~stack:stack cparams params t) in
570-
stack := old_stack;
571+
let result = success (apply_params ~stack:apply_params_stack cparams params t) in
572+
apply_params_stack := old_stack;
571573
result
572574
with
573575
| ApplyParamsRecursion ->
574-
stack := old_stack;
576+
apply_params_stack := old_stack;
575577
| err ->
576-
stack := old_stack;
578+
apply_params_stack := old_stack;
577579
raise err
578580

579581
let rec follow t =

src/core/tUnification.ml

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ type unification_context = {
6060
variance_stack : (t * t) rec_stack;
6161
abstract_cast_stack : (t * t) rec_stack;
6262
unify_new_monos : t rec_stack;
63-
apply_params_stack : (t * t list) list ref;
6463
}
6564

6665
type unify_min_result =
@@ -95,7 +94,6 @@ let default_unification_context () = {
9594
variance_stack = new_rec_stack();
9695
abstract_cast_stack = new_rec_stack();
9796
unify_new_monos = new_rec_stack();
98-
apply_params_stack = ref [];
9997
}
10098

10199
(* Unify like targets (e.g. Java) probably would. *)
@@ -114,7 +112,6 @@ let native_unification_context = {
114112
variance_stack = new_rec_stack();
115113
abstract_cast_stack = new_rec_stack();
116114
unify_new_monos = new_rec_stack();
117-
apply_params_stack = ref [];
118115
}
119116

120117
module Monomorph = struct
@@ -627,11 +624,11 @@ let rec type_eq uctx a b =
627624
type_eq_params uctx a b tl1 tl2
628625
| TType (t,tl) , _ when can_follow a ->
629626
rec_stack uctx.eq_stack (a,b) (fast_eq_pair (a,b))
630-
(fun() -> try_apply_params_rec uctx.apply_params_stack t.t_params tl t.t_type (fun a -> type_eq uctx a b))
627+
(fun() -> try_apply_params_rec t.t_params tl t.t_type (fun a -> type_eq uctx a b))
631628
(fun l -> error (cannot_unify a b :: l))
632629
| _ , TType (t,tl) when can_follow b ->
633630
rec_stack uctx.eq_stack (a,b) (fast_eq_pair (a,b))
634-
(fun() -> try_apply_params_rec uctx.apply_params_stack t.t_params tl t.t_type (type_eq uctx a))
631+
(fun() -> try_apply_params_rec t.t_params tl t.t_type (type_eq uctx a))
635632
(fun l -> error (cannot_unify a b :: l))
636633
| TEnum (e1,tl1) , TEnum (e2,tl2) ->
637634
if e1 != e2 && not (param = EqCoreType && e1.e_path = e2.e_path) then error [cannot_unify a b];
@@ -767,12 +764,12 @@ let rec unify (uctx : unification_context) a b =
767764
| TType (t,tl) , _ ->
768765
rec_stack uctx.unify_stack (a,b)
769766
(fun(a2,b2) -> fast_eq_unbound_mono a a2 && fast_eq b b2)
770-
(fun() -> try_apply_params_rec uctx.apply_params_stack t.t_params tl t.t_type (fun a -> unify uctx a b))
767+
(fun() -> try_apply_params_rec t.t_params tl t.t_type (fun a -> unify uctx a b))
771768
(fun l -> error (cannot_unify a b :: l))
772769
| _ , TType (t,tl) ->
773770
rec_stack uctx.unify_stack (a,b)
774771
(fun(a2,b2) -> fast_eq a a2 && fast_eq_unbound_mono b b2)
775-
(fun() -> try_apply_params_rec uctx.apply_params_stack t.t_params tl t.t_type (unify uctx a))
772+
(fun() -> try_apply_params_rec t.t_params tl t.t_type (unify uctx a))
776773
(fun l -> error (cannot_unify a b :: l))
777774
| TEnum (ea,tl1) , TEnum (eb,tl2) ->
778775
if ea != eb then error [cannot_unify a b];

0 commit comments

Comments
 (0)