Skip to content

Commit dae7d2a

Browse files
Code documentation
- Add description for `BranchStmA` - Reword description about not handling the catch handler argument
1 parent 780e11a commit dae7d2a

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

io-sim/src/Control/Monad/IOSim/Types.hs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -895,10 +895,22 @@ data StmTxResult s a =
895895
| StmTxAborted [SomeTVar s] SomeException
896896

897897

898-
-- | A branch is an alternative of a `OrElse` or a `CatchStm` statement
899-
data BranchStmA s a = OrElseStmA (StmA s a)
900-
| CatchStmA (SomeException -> StmA s a)
901-
| NoOpStmA
898+
-- | A branch indicates an alternative statment available in the current context.
899+
-- For example, `OrElse` has two alternative statements, say "left" and "right".
900+
-- While executing the left statement, `OrElseStmA` branch indicates that the
901+
-- right branch is still available, in case, left statement fails.
902+
data BranchStmA s a =
903+
-- | `OrElse` statement with its 'right' alternative.
904+
OrElseStmA (StmA s a)
905+
-- | `CatchStm` statment with 'catch' handler.
906+
| CatchStmA (SomeException -> StmA s a)
907+
-- | No op statment is not a part of the STM semantics. It simply
908+
-- indicates that there are no alternative statements left to be executed.
909+
-- For example, when running right alternative of the `OrElse` statement
910+
-- or when running the catch handler of a `CatchStm` statement, there are
911+
-- alternative statements available. This case is represented by no-op
912+
-- branch.
913+
| NoOpStmA
902914

903915
data StmStack s b a where
904916
-- | Executing in the context of a top level 'atomically'.

io-sim/test/Test/STM.hs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ evalTerm !env !heap !allocs term = case term of
319319
-- Rule XSTM1
320320
-- M; heap, {} => return P; heap', allocs'
321321
-- --------------------------------------------------------
322-
-- S[catch M N]; heap, allocs => S[return P]; heap', allocs'
322+
-- S[catch M N]; heap, allocs => S[return P]; heap', allocs U allocs'
323323
NfReturn v -> (NfReturn v, heap', allocs <> allocs')
324324

325325
-- Rule XSTM2
@@ -771,10 +771,8 @@ shrinkExpr (ExprName (Name _ (TyRepVar _))) = []
771771
freeNamesTerm :: Term t -> Set NameId
772772
freeNamesTerm (Return e) = freeNamesExpr e
773773
freeNamesTerm (Throw e) = freeNamesExpr e
774-
-- A catch handler should actually have an argument, and then the implementation
775-
-- should handle it. But since current implementation of catch never binds the
776-
-- variable, the following implementation is correct as of now. It needs to be
777-
-- tackled once nested exceptions are handled.
774+
-- The current generator of catch term ignores the argument passed to the
775+
-- handler.
778776
-- TODO: Correctly handle free names when the handler also binds a variable.
779777
freeNamesTerm (Catch t1 t2) = freeNamesTerm t1 <> freeNamesTerm t2
780778
freeNamesTerm Retry = Set.empty

0 commit comments

Comments
 (0)