Skip to content

Commit cc40009

Browse files
committed
Sketch promise-free
1 parent f5f9f6e commit cc40009

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

ArchSem/GenPromising.v

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Require Import ASCommon.Common.
5353
Require Import ASCommon.Exec.
5454
Require Import ASCommon.Effects.
5555
Require Import ASCommon.FMon.
56+
Require Import ASCommon.HVec.
5657
Require Import ASCommon.StateT.
5758

5859
Require Import Relations.
@@ -367,12 +368,31 @@ Module GenPromising (IWA : InterfaceWithArch) (TM : TermModelsT IWA).
367368
promise ← mchoosel (enum bool);
368369
if (promise : bool) then cpromise_tid fuel tid else run_tid isem prom tid.
369370

370-
Definition run_step_promise_first (fuel : nat) : Exec.t t string () :=
371+
(** Run only promise steps. If a thread has reached termination
372+
no progress is made in the thread (either instruction running or
373+
promises *)
374+
Fixpoint run_step_promise_first (fuel : nat) (terminated : fin n -> bool) : Exec.t t string () :=
371375
st ← mGet;
372-
tid ← mchoose n;
373-
if terminated_tid prom term st tid then mdiscard
376+
let all_terminated := ∀ tid ∈ (enum (fin n)), terminated tid in
377+
if decide all_terminated then
378+
mret ()
374379
else
375-
run_tid isem prom tid.
380+
if fuel is S fuel then
381+
tid ← mchoose n;
382+
if decide $ (terminated tid) then
383+
run_step_promise_first fuel terminated
384+
else
385+
let ev_res := promise_select_tid fuel st tid in
386+
if decide (Exec.has_error ev_res) then
387+
run_step_promise_first fuel (λ t, if decide (t = tid) then true else (terminated t))
388+
else
389+
let res_st :=
390+
ev ← ev_res;
391+
mret $ promise_tid prom st tid ev
392+
in
393+
mlift $ Exec.make ((.,()) <$> res_st.(Exec.results)) ((st,.) <$> res_st.(Exec.errors));;
394+
run_step_promise_first fuel terminated
395+
else mthrow "Could not finish promise-first within the size of the fuel".
376396

377397
(** The type of final promising state return by run *)
378398
Definition final := { x : t | terminated prom term x }.
@@ -407,6 +427,20 @@ Module GenPromising (IWA : InterfaceWithArch) (TM : TermModelsT IWA).
407427
if fuel is S fuel then
408428
run_step_promise_first (S fuel);;
409429
run_promise_first fuel
430+
431+
(** Computational evaluate all the possible allowed final states according
432+
to the promising model prom starting from st
433+
with promise-first optimization *)
434+
Definition run_promise_first (fuel : nat) : Exec.t t string final :=
435+
st ← mGet;
436+
(* Execute promise-first *)
437+
run_step_promise_first fuel;;
438+
439+
if decide $ terminated prom term st is left pt then mret (make_final st pt)
440+
else
441+
if fuel is S fuel then
442+
run_step (S fuel);;
443+
run fuel
410444
else mthrow "Could not finish running within the size of the fuel".
411445
End CPS.
412446
Arguments to_final_archState {_ _ _}.
@@ -421,7 +455,8 @@ Module GenPromising (IWA : InterfaceWithArch) (TM : TermModelsT IWA).
421455
$ CPState.to_final_archState
422456
<$> CPState.run isem prom term fuel.
423457

424-
(** Create a computational model from an ISA model and promising model *)
458+
(** Create a computational model from an ISA model and promising model
459+
with promise-free optimization *)
425460
Definition Promising_to_Modelc_promise_first (isem : iMon ()) (prom : BasicExecutablePM)
426461
(fuel : nat) : archModel.c ∅ :=
427462
fun n term (initMs : archState n) =>

0 commit comments

Comments
 (0)