5
5
module Main (main ) where
6
6
7
7
import Control.Concurrent.MVar
8
+ import Control.Monad.Catch (
9
+ SomeException ,
10
+ fromException ,
11
+ handle ,
12
+ throwM ,
13
+ )
8
14
import Data.Reflection
9
15
import GlobalMain
10
16
import Kore.BugReport
@@ -16,21 +22,30 @@ import qualified Kore.IndexedModule.MetadataToolsBuilder as MetadataTools (
16
22
)
17
23
import Kore.Log (
18
24
KoreLogOptions (.. ),
25
+ SomeEntry (.. ),
26
+ logEntry ,
19
27
runLoggerT ,
20
28
swappableLogger ,
21
29
withLogger ,
22
30
)
31
+ import Kore.Log.ErrorException (
32
+ errorException ,
33
+ )
23
34
import Kore.Log.KoreLogOptions (
24
35
parseKoreLogOptions ,
25
36
)
26
37
import Kore.Log.WarnIfLowProductivity (
27
38
warnIfLowProductivity ,
28
39
)
40
+ import qualified Kore.Reachability.Claim as Claim
29
41
import Kore.Repl.Data
30
42
import Kore.Step.SMT.Lemma
31
43
import Kore.Syntax.Module (
32
44
ModuleName (.. ),
33
45
)
46
+ import Kore.Unparser (
47
+ unparseToString ,
48
+ )
34
49
import Options.Applicative (
35
50
InfoMod ,
36
51
Parser ,
@@ -198,62 +213,89 @@ mainWithOptions
198
213
withLogger tempDirectory koreLogOptions $ \ actualLogAction -> do
199
214
mvarLogAction <- newMVar actualLogAction
200
215
let swapLogAction = swappableLogger mvarLogAction
201
- flip runLoggerT swapLogAction $ do
202
- definition <- loadDefinitions [definitionFileName, specFile]
203
- indexedModule <- loadModule mainModuleName definition
204
- specDefIndexedModule <- loadModule specModule definition
216
+ flip runLoggerT swapLogAction $
217
+ runExceptionHandlers $ do
218
+ definition <- loadDefinitions [definitionFileName, specFile]
219
+ indexedModule <- loadModule mainModuleName definition
220
+ specDefIndexedModule <- loadModule specModule definition
205
221
206
- let smtConfig =
207
- SMT. defaultConfig
208
- { SMT. timeOut = smtTimeOut
209
- , SMT. resetInterval = smtResetInterval
210
- , SMT. prelude = smtPrelude
211
- }
222
+ let smtConfig =
223
+ SMT. defaultConfig
224
+ { SMT. timeOut = smtTimeOut
225
+ , SMT. resetInterval = smtResetInterval
226
+ , SMT. prelude = smtPrelude
227
+ }
212
228
213
- when
214
- ( replMode == RunScript
215
- && isNothing (unReplScript replScript)
216
- )
217
- $ lift $ do
218
- hPutStrLn
219
- stderr
220
- " You must supply the path to the repl script\
221
- \ in order to run the repl in run-script mode."
222
- exitFailure
229
+ when
230
+ ( replMode == RunScript
231
+ && isNothing (unReplScript replScript)
232
+ )
233
+ $ lift $ do
234
+ hPutStrLn
235
+ stderr
236
+ " You must supply the path to the repl script\
237
+ \ in order to run the repl in run-script mode."
238
+ exitFailure
223
239
224
- when
225
- ( replMode == Interactive
226
- && scriptModeOutput == EnableOutput
227
- )
228
- $ lift $ do
229
- hPutStrLn
230
- stderr
231
- " The --save-run-output flag is only available\
232
- \ when running the repl in run-script mode."
233
- exitFailure
240
+ when
241
+ ( replMode == Interactive
242
+ && scriptModeOutput == EnableOutput
243
+ )
244
+ $ lift $ do
245
+ hPutStrLn
246
+ stderr
247
+ " The --save-run-output flag is only available\
248
+ \ when running the repl in run-script mode."
249
+ exitFailure
234
250
235
- SMT. runSMT
236
- smtConfig
237
- ( give
238
- (MetadataTools. build indexedModule)
239
- (declareSMTLemmas indexedModule)
240
- )
241
- $ proveWithRepl
242
- indexedModule
243
- specDefIndexedModule
244
- Nothing
245
- mvarLogAction
246
- replScript
247
- replMode
248
- scriptModeOutput
249
- outputFile
250
- mainModuleName
251
- koreLogOptions
251
+ SMT. runSMT
252
+ smtConfig
253
+ ( give
254
+ (MetadataTools. build indexedModule)
255
+ (declareSMTLemmas indexedModule)
256
+ )
257
+ $ proveWithRepl
258
+ indexedModule
259
+ specDefIndexedModule
260
+ Nothing
261
+ mvarLogAction
262
+ replScript
263
+ replMode
264
+ scriptModeOutput
265
+ outputFile
266
+ mainModuleName
267
+ koreLogOptions
252
268
253
- warnIfLowProductivity
254
- pure ExitSuccess
269
+ warnIfLowProductivity
270
+ pure ExitSuccess
255
271
exitWith exitCode
256
272
where
273
+ runExceptionHandlers action =
274
+ action
275
+ & handle exitReplHandler
276
+ & handle withConfigurationHandler
277
+ & handle someExceptionHandler
278
+
279
+ exitReplHandler :: ExitCode -> Main ExitCode
280
+ exitReplHandler = pure
281
+
282
+ withConfigurationHandler :: Claim. WithConfiguration -> Main ExitCode
283
+ withConfigurationHandler
284
+ (Claim. WithConfiguration lastConfiguration someException) =
285
+ do
286
+ liftIO $
287
+ hPutStrLn
288
+ stderr
289
+ (" // Last configuration:\n " <> unparseToString lastConfiguration)
290
+ throwM someException
291
+
292
+ someExceptionHandler :: SomeException -> Main ExitCode
293
+ someExceptionHandler someException = do
294
+ case fromException someException of
295
+ Just (SomeEntry entry) -> logEntry entry
296
+ Nothing -> errorException someException
297
+ throwM someException
298
+
257
299
mainModuleName :: ModuleName
258
300
mainModuleName = moduleName definitionModule
259
301
0 commit comments