Skip to content

keep cache and constraint store after recursion, revert state on exceptions #3929

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

Merged
merged 7 commits into from
Jun 13, 2024
Merged
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
13 changes: 11 additions & 2 deletions booster/library/Booster/Pattern/ApplyEquations.hs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,15 @@ throw = EquationT . lift . throwE
catch_ ::
Copy link
Contributor

@geo2a geo2a Jun 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function now deserves a comment explaining what it does. How about we write something like: "Recover from an EquationFailure, taking into account the accumulated EquationState while executing the exception handler"?

Monad io => EquationT io a -> (EquationFailure -> EquationT io a) -> EquationT io a
catch_ (EquationT op) hdlr = EquationT $ do
prior <- lift . lift $ get
cfg <- ask
lift (runReaderT op cfg `catchE` (\e -> let EquationT fallBack = hdlr e in runReaderT fallBack cfg))
lift
( runReaderT op cfg
`catchE` ( \e -> do
let EquationT fallBack = hdlr e
runReaderT (lift (lift (put prior)) >> fallBack) cfg
)
)

data EquationFailure
= IndexIsNone Term
Expand Down Expand Up @@ -965,5 +972,7 @@ simplifyConstraint' recurseIntoEvalBool = \case
prior <- getState -- save prior state so we can revert
eqState $ put prior{termStack = mempty, changed = False}
result <- iterateEquations BottomUp PreferFunctions t
eqState $ put prior
-- reset change flag and term stack to prior values
-- (keep the updated cache and added predicates, if any)
eqState $ modify $ \s -> s{changed = prior.changed, termStack = prior.termStack}
pure result
Loading
Loading