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

A CEK Evaluator #223

Merged
merged 1 commit into from
Oct 31, 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
11 changes: 4 additions & 7 deletions repl/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
{-# LANGUAGE ViewPatterns #-}
module Main where

import Control.Exception
import Control.Exception hiding (evaluate)
import Control.Lens hiding (argument)
import Control.Monad
import Control.Monad.Trans.Reader
import Control.Monad.Trans.Except

import Data.Foldable (for_)
import Data.IORef
Expand Down Expand Up @@ -148,7 +146,6 @@ repl ctx startWorld = do
prettyPrint expr
putStrLn ""
currentWorld <- readIORef theWorld
runExceptT (runReaderT (runEval (eval expr)) (phaseEnv runtime currentWorld)) >>=
\case
Left evalErr -> print evalErr
Right val -> prettyPrintLn val
case evaluateIn (phaseEnv runtime currentWorld) expr of
Left evalErr -> print $ erroneousValue $ projectError evalErr
Right val -> prettyPrintLn val
Comment on lines +149 to +151
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider adding performance metrics logging.

Given the performance concerns, it would be helpful to add optional performance logging to track evaluation time and memory usage.

Add performance metrics with this diff:

                        currentWorld <- readIORef theWorld
+                       start <- getCurrentTime
                        case evaluateIn (phaseEnv runtime currentWorld) expr of
-                            Left evalErr -> print $ erroneousValue $ projectError evalErr
-                            Right val    -> prettyPrintLn val
+                            result -> do
+                                end <- getCurrentTime
+                                let duration = diffUTCTime end start
+                                when (duration > 0.1) $  -- Log slow evaluations
+                                    hPutStrLn stderr $ "Evaluation took: " ++ show duration
+                                case result of
+                                    Left evalErr -> print $ erroneousValue $ projectError evalErr
+                                    Right val    -> prettyPrintLn val

Committable suggestion was skipped due to low confidence.

Loading
Loading