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

Gracefully skip docstrings on top-level functors #1730

Merged
merged 1 commit into from
Aug 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
47 changes: 26 additions & 21 deletions cryptol-remote-api/src/CryptolServer/CheckDocstrings.hs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import CryptolServer.Exceptions (noModule, moduleNotLoaded)
import qualified Cryptol.REPL.Monad as REPL
import Cryptol.Utils.Logger (quietLogger)
import Cryptol.Parser.AST (ImpName(..))
import qualified Cryptol.TypeCheck.AST as T
import qualified System.Random.TF as TF
import qualified Cryptol.Symbolic.SBV as SBV
import Cryptol.REPL.Monad (mkUserEnv, userOptions)
Expand All @@ -45,27 +46,31 @@ checkDocstrings CheckDocstringsParams = do
m <- case M.lookupModule ln env of
Nothing -> raise (moduleNotLoaded ln)
Just m -> pure m
solver <- getTCSolver
cfg <- getTCSolverConfig
liftIO $
do rng <- TF.newTFGen
rwRef <- newIORef REPL.RW
{ REPL.eLoadedMod = Nothing
, REPL.eEditFile = Nothing
, REPL.eContinue = True
, REPL.eIsBatch = False
, REPL.eModuleEnv = env
, REPL.eUserEnv = mkUserEnv userOptions
, REPL.eLogger = quietLogger
, REPL.eCallStacks = False
, REPL.eUpdateTitle = return ()
, REPL.eProverConfig = Left SBV.defaultProver
, REPL.eTCConfig = cfg
, REPL.eTCSolver = Just solver
, REPL.eTCSolverRestarts = 0
, REPL.eRandomGen = rng
}
REPL.unREPL (CheckDocstringsResult <$> checkDocStrings m) rwRef

if T.isParametrizedModule (M.lmdModule (M.lmData m)) then
pure (CheckDocstringsResult [])
else do
solver <- getTCSolver
cfg <- getTCSolverConfig
liftIO $
do rng <- TF.newTFGen
rwRef <- newIORef REPL.RW
{ REPL.eLoadedMod = Nothing
, REPL.eEditFile = Nothing
, REPL.eContinue = True
, REPL.eIsBatch = False
, REPL.eModuleEnv = env
, REPL.eUserEnv = mkUserEnv userOptions
, REPL.eLogger = quietLogger
, REPL.eCallStacks = False
, REPL.eUpdateTitle = return ()
, REPL.eProverConfig = Left SBV.defaultProver
, REPL.eTCConfig = cfg
, REPL.eTCSolver = Just solver
, REPL.eTCSolverRestarts = 0
, REPL.eRandomGen = rng
}
REPL.unREPL (CheckDocstringsResult <$> checkDocStrings m) rwRef

newtype CheckDocstringsResult = CheckDocstringsResult [DocstringResult]

Expand Down
41 changes: 23 additions & 18 deletions src/Cryptol/REPL/Command.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2199,21 +2199,26 @@ checkDocStringsCmd input
rPutStrLn ("Module " ++ show input ++ " is not loaded")
pure emptyCommandResult { crSuccess = False }

Just fe -> do
results <- checkDocStrings fe
let (successes, nofences, failures) = countOutcomes [concat (drFences r) | r <- results]

forM_ results $ \dr ->
unless (null (drFences dr)) $
do rPutStrLn ""
rPutStrLn ("\nChecking " ++ show (pp (drName dr)))
forM_ (drFences dr) $ \fence ->
forM_ fence $ \line -> do
rPutStrLn ""
rPutStrLn (T.unpack (srInput line))
rPutStr (srLog line)

rPutStrLn ""
rPutStrLn ("Successes: " ++ show successes ++ ", No fences: " ++ show nofences ++ ", Failures: " ++ show failures)

pure emptyCommandResult { crSuccess = failures == 0 }
Just fe
| T.isParametrizedModule (M.lmdModule (M.lmData fe)) -> do
rPutStrLn "Skipping docstrings on parameterized module"
pure emptyCommandResult

| otherwise -> do
results <- checkDocStrings fe
let (successes, nofences, failures) = countOutcomes [concat (drFences r) | r <- results]

forM_ results $ \dr ->
unless (null (drFences dr)) $
do rPutStrLn ""
rPutStrLn ("\nChecking " ++ show (pp (drName dr)))
forM_ (drFences dr) $ \fence ->
forM_ fence $ \line -> do
rPutStrLn ""
rPutStrLn (T.unpack (srInput line))
rPutStr (srLog line)

rPutStrLn ""
rPutStrLn ("Successes: " ++ show successes ++ ", No fences: " ++ show nofences ++ ", Failures: " ++ show failures)

pure emptyCommandResult { crSuccess = failures == 0 }
4 changes: 4 additions & 0 deletions tests/docstrings/T09.cry
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module T09 where

parameter
type n : #
2 changes: 2 additions & 0 deletions tests/docstrings/T09.icry
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:m T09
:check-docstrings
5 changes: 5 additions & 0 deletions tests/docstrings/T09.icry.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Loading module Cryptol
Loading module Cryptol
Loading interface module `parameter` interface of T09
Loading module T09
Skipping docstrings on parameterized module
Loading