-
Notifications
You must be signed in to change notification settings - Fork 56
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
Effectful Juvix tree evaluator #2623
Conversation
989a8a2
to
33e14c3
Compare
bcf822b
to
f52cebc
Compare
7b6a458
to
01db9c3
Compare
v <- eval' _nodeSaveArg | ||
withExtendedTemp v (eval' _nodeSaveBody) | ||
|
||
printValue :: InfoTable -> Value -> Text |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is code duplication here. Exactly the same function is available in Evaluator.hs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
ValString s -> s | ||
v -> ppPrint tab v | ||
|
||
valueToNode :: Value -> Node |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code duplication
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
return val | ||
|
||
-- | Catch EvalError and convert it to TreeError. | ||
catchEvalErrorIO :: IO a -> IO (Either TreeError a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed if errors are not Haskell exceptions. And code duplication.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
(\(ex :: EvalError) -> return (Left (toTreeError ex))) | ||
|
||
toTreeError :: EvalError -> TreeError | ||
toTreeError EvalError {..} = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code duplication
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
withExtendedTemp v (eval' _nodeSaveBody) | ||
|
||
printValue :: InfoTable -> Value -> Text | ||
printValue tab = \case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code duplication
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
v -> ppPrint tab v | ||
|
||
valueToNode :: Value -> Node | ||
valueToNode = \case |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code duplication
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
return val | ||
|
||
-- | Catch EvalError and convert it to TreeError. | ||
catchEvalErrorIO :: IO a -> IO (Either TreeError a) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicated and not needed for the effects-based version
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
(\(ex :: EvalError) -> return (Left (toTreeError ex))) | ||
|
||
toTreeError :: EvalError -> TreeError | ||
toTreeError EvalError {..} = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code duplication
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
eval :: (Output Value :> r, E.Error EvalError :> r) => InfoTable -> Node -> Eff r Value | ||
eval tab = E.runReader emptyEvalCtx . eval' | ||
where | ||
-- eval' :: forall r'. (Members '[Output Value, Reader EvalCtx, Error EvalError] r') => Node -> Sem r' Value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
mapM_ handle l | ||
pure a | ||
|
||
-- eval :: (Members '[Output Value, Error EvalError] r) => InfoTable -> Node -> Sem r Value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove unnecessary comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid code duplication
01db9c3
to
1993ad2
Compare
991c1ea
to
37869e6
Compare
This pr implements two additional versions of the Juvix Tree evaluator. Now we have
unsafePerformIO
for traces. It relies on bang patterns to force strictness and guarantee the expected order of execution (for traces). Avoiding effects allows for improved execution efficiency.polysemy
based implementation.effectful-core
based implementation.One can specify which evaluator to use thus:
where XXX is one of
raw
,polysemy
,effectful
.Preliminary benchmarks
More thorough benchmarks should be run, but here are some preliminary results:
Test032 (Fibonacci 20)
I've adapted test032 so that it main is a single call to fibonacci of 20.
Command:
Output:
Test034 (Higher-order function composition)
A modified version of test034 where main defined as
call[exp](3, 12)
Command:
Output:
Test036 (Streams without memoization)
A modified version of test036 where main defined as
call[nth](700, call[primes]())
Command:
Output: