Skip to content

Commit

Permalink
Simplify things a bit.
Browse files Browse the repository at this point in the history
For the moment we separate loading files and just parsing to check
for changes.
  • Loading branch information
yav authored and glguy committed Nov 1, 2024
1 parent e300802 commit 445df7d
Show file tree
Hide file tree
Showing 6 changed files with 257 additions and 240 deletions.
2 changes: 1 addition & 1 deletion cryptol.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ library
ghc-prim,
GraphSCC >= 1.0.4,
heredoc >= 0.2,
HsYAML,
language-c99,
language-c99-simple,
libBF >= 0.6 && < 0.7,
Expand All @@ -82,6 +81,7 @@ library
strict,
text >= 1.1,
tf-random >= 0.5,
toml-parser >= 2.0 && <2.1,
transformers-base >= 0.4,
vector,
mtl >= 2.2.1,
Expand Down
11 changes: 6 additions & 5 deletions src/Cryptol/ModuleSystem/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,11 @@ parseModule path = do
, "Label: " ++ show p
, "Exception: " ++ show exn ]

let fp = fingerprint bytes
txt <- case decodeUtf8' bytes of
Right txt -> return $! (T.replace "\r\n" "\n" txt)
Left e -> badUtf8 path e
Right txt -> return txt
Left e -> badUtf8 path fp e


let cfg = P.defaultConfig
{ P.cfgSource = case path of
Expand All @@ -194,8 +196,7 @@ parseModule path = do

case P.parseModule cfg txt of
Right pms ->
do let fp = fingerprint bytes
(pm1,deps) <-
do (pm1,deps) <-
case path of
InFile p ->
do r <- getByteReader
Expand All @@ -222,7 +223,7 @@ parseModule path = do
--}
fp `seq` return (fp, deps, pm1)

Left err -> moduleParseError path err
Left err -> moduleParseError path fp err


-- Top Level Modules and Signatures --------------------------------------------
Expand Down
25 changes: 13 additions & 12 deletions src/Cryptol/ModuleSystem/Monad.hs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Cryptol.ModuleSystem.Interface
import Cryptol.ModuleSystem.Name (FreshM(..),Supply)
import Cryptol.ModuleSystem.Renamer (RenamerError(),RenamerWarning())
import Cryptol.ModuleSystem.NamingEnv(NamingEnv)
import Cryptol.ModuleSystem.Fingerprint(Fingerprint)
import qualified Cryptol.Parser as Parser
import qualified Cryptol.Parser.AST as P
import Cryptol.Utils.Panic (panic)
Expand Down Expand Up @@ -94,11 +95,11 @@ data ModuleError
-- ^ Unable to find the module given, tried looking in these paths
| CantFindFile FilePath
-- ^ Unable to open a file
| BadUtf8 ModulePath UnicodeException
| BadUtf8 ModulePath Fingerprint UnicodeException
-- ^ Bad UTF-8 encoding in while decoding this file
| OtherIOError FilePath IOException
-- ^ Some other IO error occurred while reading this file
| ModuleParseError ModulePath Parser.ParseError
| ModuleParseError ModulePath Fingerprint Parser.ParseError
-- ^ Generated this parse error when parsing the file for module m
| RecursiveModules [ImportSource]
-- ^ Recursive module group discovered
Expand All @@ -124,17 +125,17 @@ data ModuleError
| ErrorInFile ModulePath ModuleError
-- ^ This is just a tag on the error, indicating the file containing it.
-- It is convenient when we had to look for the module, and we'd like
-- to communicate the location of pthe problematic module to the handler.
-- to communicate the location of the problematic module to the handler.

deriving (Show)

instance NFData ModuleError where
rnf e = case e of
ModuleNotFound src path -> src `deepseq` path `deepseq` ()
CantFindFile path -> path `deepseq` ()
BadUtf8 path ue -> rnf (path, ue)
BadUtf8 path fp ue -> rnf (path, fp, ue)
OtherIOError path exn -> path `deepseq` exn `seq` ()
ModuleParseError source err -> source `deepseq` err `deepseq` ()
ModuleParseError source fp err -> rnf (source, fp, err)
RecursiveModules mods -> mods `deepseq` ()
RenamerErrors src errs -> src `deepseq` errs `deepseq` ()
NoPatErrors src errs -> src `deepseq` errs `deepseq` ()
Expand Down Expand Up @@ -165,7 +166,7 @@ instance PP ModuleError where
text "[error]" <+>
text "can't find file:" <+> text path

BadUtf8 path _ue ->
BadUtf8 path _fp _ue ->
text "[error]" <+>
text "bad utf-8 encoding:" <+> pp path

Expand All @@ -174,7 +175,7 @@ instance PP ModuleError where
text "IO error while loading file:" <+> text path <.> colon)
4 (text (show exn))

ModuleParseError _source err -> Parser.ppError err
ModuleParseError _source _fp err -> Parser.ppError err

RecursiveModules mods ->
hang (text "[error] module imports form a cycle:")
Expand Down Expand Up @@ -217,15 +218,15 @@ moduleNotFound name paths = ModuleT (raise (ModuleNotFound name paths))
cantFindFile :: FilePath -> ModuleM a
cantFindFile path = ModuleT (raise (CantFindFile path))

badUtf8 :: ModulePath -> UnicodeException -> ModuleM a
badUtf8 path ue = ModuleT (raise (BadUtf8 path ue))
badUtf8 :: ModulePath -> Fingerprint -> UnicodeException -> ModuleM a
badUtf8 path fp ue = ModuleT (raise (BadUtf8 path fp ue))

otherIOError :: FilePath -> IOException -> ModuleM a
otherIOError path exn = ModuleT (raise (OtherIOError path exn))

moduleParseError :: ModulePath -> Parser.ParseError -> ModuleM a
moduleParseError path err =
ModuleT (raise (ModuleParseError path err))
moduleParseError :: ModulePath -> Fingerprint -> Parser.ParseError -> ModuleM a
moduleParseError path fp err =
ModuleT (raise (ModuleParseError path fp err))

recursiveModules :: [ImportSource] -> ModuleM a
recursiveModules loaded = ModuleT (raise (RecursiveModules loaded))
Expand Down
Loading

0 comments on commit 445df7d

Please sign in to comment.