Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EM: do not exec the same task twice #1050

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions language-server/dm/documentManager.ml
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ let interpret_to st id check_mode =
let pv_event = mk_proof_view_event id in
st, [event] @ [pv_event]
| Settings.Mode.Continuous ->
match ExecutionManager.is_executed st.execution_state id with
match ExecutionManager.is_locally_executed st.execution_state id with
| true -> st, [mk_proof_view_event id]
| false -> st, []

Expand Down Expand Up @@ -915,7 +915,7 @@ module Internal = struct
let code_lines_by_id = Document.code_lines_sorted_by_loc st.document in
let code_lines_by_end = Document.code_lines_by_end_sorted_by_loc st.document in
let string_of_state id =
if ExecutionManager.is_executed st.execution_state id then "(executed)"
if ExecutionManager.is_locally_executed st.execution_state id then "(executed)"
else if ExecutionManager.is_remotely_executed st.execution_state id then "(executed in worker)"
else "(not executed)"
in
Expand Down
48 changes: 33 additions & 15 deletions language-server/dm/executionManager.ml
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,29 @@ let find_fulfilled_opt x m =
| Delegated _ -> None
with Not_found -> None


let exec_error_of_execution_status id v = match v with
| Success _ -> None
| Error ((loc, _), _, _) -> Some (id, loc)

let get_vs_and_exec_error st id =
match fst @@ SM.find id st.of_sentence with
| Done (Success (Some vs) as es) -> vs, exec_error_of_execution_status id es
| Done (Error (_,_,Some vs) as es) -> vs, exec_error_of_execution_status id es
| _ -> CErrors.anomaly Pp.(str "get_vs_and_exec_error call should be protected with is_locally_executed")
| exception Not_found -> assert false

let is_locally_executed st id =
match find_fulfilled_opt id st.of_sentence with
| Some (Success (Some _) | Error (_,_,Some _)) -> true
| _ -> false

let is_remotely_executed st id =
match find_fulfilled_opt id st.of_sentence with
| Some (Success None | Error (_,_,None)) -> true
| _ -> false


let jobs : (DelegationManager.job_handle * Sel.Event.cancellation_handle * ProofJob.t) Queue.t = Queue.create ()

(* TODO: kill all Delegated... *)
Expand Down Expand Up @@ -608,12 +631,17 @@ let execute_task st (vs, events, interrupted) task =
(st, vs, events, false, None)
| PExec { id; ast; synterp; error_recovery } ->
let vs = { vs with Vernacstate.synterp } in
let vs, v, ev = interp_ast ~doc_id:st.doc_id ~state_id:id ~st:vs ~error_recovery ast in
let exec_error = match v with
| Success _ -> None
| Error ((loc, _), _, _) -> Some (id, loc)
let vs, st, ev, exec_error =
if is_locally_executed st id then
let vs, exec_error = get_vs_and_exec_error st id in
log (fun () -> Format.asprintf "skipping execution of already executed %s" (Stateid.to_string id));
vs, st, [], exec_error
else
let vs, v, ev = interp_ast ~doc_id:st.doc_id ~state_id:id ~st:vs ~error_recovery ast in
let st = update st id v in
let exec_error = exec_error_of_execution_status id v in
vs, st, ev, exec_error
in
let st = update st id v in
(st, vs, events @ ev, false, exec_error)
| PQuery { id; ast; synterp; error_recovery } ->
let vs = { vs with Vernacstate.synterp } in
Expand Down Expand Up @@ -799,16 +827,6 @@ let executed_ids st =
| Done _ -> id :: acc
| _ -> acc) st.of_sentence []

let is_executed st id =
match find_fulfilled_opt id st.of_sentence with
| Some (Success (Some _) | Error (_,_,Some _)) -> true
| _ -> false

let is_remotely_executed st id =
match find_fulfilled_opt id st.of_sentence with
| Some (Success None | Error (_,_,None)) -> true
| _ -> false

let invalidate1 of_sentence id =
try
let p,_ = SM.find id of_sentence in
Expand Down
6 changes: 5 additions & 1 deletion language-server/dm/executionManager.mli
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ val reset_overview : state -> Document.document -> state
val shift_overview : state -> before:RawDocument.t -> after:RawDocument.t -> start:int -> offset:int -> state
val shift_diagnostics_locs : state -> start:int -> offset:int -> state
val executed_ids : state -> sentence_id list
val is_executed : state -> sentence_id -> bool

(** we know if it worked and we have the state in this process *)
val is_locally_executed : state -> sentence_id -> bool

(** we know if it worked but we do not have the state in this process *)
val is_remotely_executed : state -> sentence_id -> bool

val get_context : state -> sentence_id -> (Evd.evar_map * Environ.env) option
Expand Down
4 changes: 2 additions & 2 deletions language-server/tests/dm_tests.ml
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ let%test_unit "edit.edit_non_root_observe_id_top" =
let todo = Sel.Todo.(add init_events events) in
let st = handle_dm_events todo st in
let st = edit_text st ~start:0 ~stop:18 ~text:"Definition x := 3." in
[%test_eq: bool] (ExecutionManager.is_executed (DocumentManager.Internal.execution_state st) s2.id) false;
[%test_eq: bool] (ExecutionManager.is_locally_executed (DocumentManager.Internal.execution_state st) s2.id) false;
[%test_eq: int option] (Option.map ~f:Stateid.to_int (DocumentManager.Internal.observe_id st)) None

let%test_unit "edit.edit_non_root_observe_id" =
Expand All @@ -321,6 +321,6 @@ let%test_unit "edit.edit_non_root_observe_id" =
let todo = Sel.Todo.(add init_events events) in
let st = handle_dm_events todo st in
let st = edit_text st ~start:19 ~stop:37 ~text:"Definition y := 4." in
[%test_eq: bool] (ExecutionManager.is_executed (DocumentManager.Internal.execution_state st) s3.id) false;
[%test_eq: bool] (ExecutionManager.is_locally_executed (DocumentManager.Internal.execution_state st) s3.id) false;
[%test_eq: int option] (Option.map ~f:Stateid.to_int (DocumentManager.Internal.observe_id st))
(Some (Stateid.to_int s1.id))
Loading