1+ {-# OPTIONS_GHC -Wall #-}
2+
13module Certifier (
24 runCertifier
35 , mkCertifier
@@ -6,14 +8,13 @@ module Certifier (
68 , CertifierError (.. )
79 ) where
810
9- import Control.Monad ((>=>) )
1011import Control.Monad.Except (ExceptT (.. ), runExceptT , throwError )
1112import Control.Monad.IO.Class (liftIO )
1213import Data.Char (toUpper )
1314import Data.List (find )
1415import Data.List.NonEmpty (NonEmpty (.. ))
1516import Data.List.NonEmpty qualified as NE
16- import Data.Maybe (fromJust )
17+ import Data.Maybe (fromMaybe )
1718import Data.Time.Clock.System (getSystemTime , systemNanoseconds )
1819import System.Directory (createDirectory )
1920import System.FilePath ((</>) )
@@ -35,9 +36,7 @@ data CertifierError
3536 | InvalidCompilerOutput
3637 | ValidationError CertName
3738
38- newtype CertifierSuccess = CertifierSuccess
39- { certDir :: CertDir
40- }
39+ newtype CertifierSuccess = CertifierSuccess CertDir
4140
4241prettyCertifierError :: CertifierError -> String
4342prettyCertifierError (InvalidCertificate certDir) =
@@ -140,10 +139,10 @@ mkCertificate certName rawTrace =
140139 -> [(SimplifierStage , (UTerm , UTerm ))]
141140 -> [(SimplifierStage , (TermWithId , TermWithId ))]
142141 go _ [] = []
143- go id ((stage, (before, after)) : rest) =
144- let beforeWithId = TermWithId id before
145- afterWithId = TermWithId (id + 1 ) after
146- in (stage, (beforeWithId, afterWithId)) : go (id + 2 ) rest
142+ go id' ((stage, (before, after)) : rest) =
143+ let beforeWithId = TermWithId id' before
144+ afterWithId = TermWithId (id' + 1 ) after
145+ in (stage, (beforeWithId, afterWithId)) : go (id' + 2 ) rest
147146
148147 extractTermWithIds
149148 :: [(SimplifierStage , (TermWithId , TermWithId ))]
@@ -163,17 +162,24 @@ mkCertificate certName rawTrace =
163162 getRepresentatives :: [NonEmpty Ast ] -> [Ast ]
164163 getRepresentatives = fmap NE. head
165164
166- mkAsts :: [TermWithId ] -> [Ast ]
167- mkAsts = findEquivClasses >=> NE. toList
165+ errorMessage :: String
166+ errorMessage =
167+ " Internal error: could not find AST.\
168+ \ This is an issue in the certifier, please open a bug report at\
169+ \ https://github.com/IntersectMBO/plutus/issues"
168170
169171 mkAstTrace
170172 :: [Ast ]
171173 -> [(SimplifierStage , (TermWithId , TermWithId ))]
172174 -> [(SimplifierStage , (Ast , Ast ))]
173175 mkAstTrace _ [] = []
174176 mkAstTrace allAsts ((stage, (rawBefore, rawAfter)) : rest) =
175- let Just processedBefore = find (\ ast -> getTermId ast == termId rawBefore) allAsts
176- Just processedAfter = find (\ ast -> getTermId ast == termId rawAfter) allAsts
177+ let processedBefore =
178+ fromMaybe (error errorMessage)
179+ $ find (\ ast -> getTermId ast == termId rawBefore) allAsts
180+ processedAfter =
181+ fromMaybe (error errorMessage)
182+ $ find (\ ast -> getTermId ast == termId rawAfter) allAsts
177183 in (stage, (processedBefore, processedAfter)) : mkAstTrace allAsts rest
178184
179185mkAstModuleName :: Ast -> String
@@ -306,8 +312,6 @@ writeCertificateProject
306312 = liftIO $ do
307313 let (mainModulePath, mainModuleContents) = mainModule
308314 (agdalibPath, agdalibContents) = agdalib
309- astModulePaths = fmap fst astModules
310- astModuleContents = fmap snd astModules
311315 time <- systemNanoseconds <$> getSystemTime
312316 let actualProjectDir = projectDir <> " -" <> show time
313317 createDirectory actualProjectDir
0 commit comments