Skip to content

Commit 1488993

Browse files
author
Vladimir Ciobanu
authored
Feature/repl step n (#501)
1 parent 7c8fbfb commit 1488993

39 files changed

+1107
-368
lines changed

include.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ KPROVE = $(K_DIST_BIN)/kprove
2121
KOMPILE_OPTS = --backend haskell
2222
KRUN_OPTS = --haskell-backend-command "$(KORE_EXEC) $(KORE_EXEC_OPTS)"
2323
KPROVE_OPTS = --haskell-backend-command "$(KORE_EXEC) $(KORE_EXEC_OPTS)"
24+
KPROVE_REPL_OPTS = --haskell-backend-command "$(KORE_REPL) $(KORE_EXEC_OPTS)"
2425

2526
HS_TOP = $(TOP)/kore
2627
HS_SOURCE_DIRS = $(HS_TOP)/src $(HS_TOP)/app $(HS_TOP)/test $(HS_TOP)/bench
@@ -42,5 +43,10 @@ STACK_LOCAL_HPC_ROOT ?= $(shell $(STACK_TEST) path --local-hpc-root)
4243
KORE_EXEC = $(STACK_LOCAL_INSTALL_ROOT)/bin/kore-exec
4344
KORE_EXEC_OPTS =
4445

46+
KORE_REPL = $(STACK_LOCAL_INSTALL_ROOT)/bin/kore-repl
47+
4548
$(KORE_EXEC):
4649
$(STACK_BUILD) $(STACK_NO_PROFILE) kore:exe:kore-exec
50+
51+
$(KORE_REPL):
52+
$(STACK_BUILD) $(STACK_NO_PROFILE) kore:exe:kore-repl

kore/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package = kore
22

3-
stack_yaml = STACK_YAML="../../../stack.yaml"
3+
stack_yaml = STACK_YAML="../stack.yaml"
44
stack = $(stack_yaml) stack
55
pattern = ""
66

@@ -34,6 +34,10 @@ pedantic:
3434
ghcid:
3535
$(stack) exec -- ghcid -c "stack ghci $(package) --test --ghci-options='-fobject-code -fno-warn-unused-do-bind' --main-is $(package):kore-exec"
3636

37+
ghcid-repl:
38+
$(stack) exec -- ghcid -c "stack ghci $(package) --test --ghci-options='-fobject-code -fno-warn-unused-do-bind' --main-is $(package):kore-repl"
39+
40+
3741
# TODO(Vladimir): remove 'hyperlink-source' when we upgrade from lts-12.10 (8.4.3)
3842
hoogle-gen:
3943
$(stack) haddock; $(stack) hoogle generate --rebuild --no-haddock-hyperlink-source -- --local

kore/app/exec/Main.hs

Lines changed: 20 additions & 184 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,22 @@
11
module Main (main) where
22

3-
import Control.Applicative
4-
( Alternative (..), optional, (<$) )
5-
import qualified Control.Lens as Lens
6-
import Data.Function
7-
( (&) )
8-
import Data.List
9-
( intercalate )
10-
import qualified Data.Map as Map
11-
import Data.Maybe
12-
( fromMaybe )
13-
import Data.Proxy
14-
( Proxy (..) )
15-
import Data.Semigroup
16-
( (<>) )
17-
import Data.Text
18-
( Text )
19-
import Data.Text.Prettyprint.Doc.Render.Text
20-
( hPutDoc, putDoc )
21-
import Options.Applicative
22-
( InfoMod, Parser, argument, auto, fullDesc, header, help,
23-
long, metavar, option, progDesc, readerError, str, strOption,
24-
switch, value )
25-
import System.Exit
26-
( ExitCode (..), exitWith )
27-
import System.IO
28-
( IOMode (WriteMode), withFile )
3+
import Control.Applicative
4+
( Alternative (..), optional, (<$) )
5+
import Data.List
6+
( intercalate )
7+
import Data.Maybe
8+
( fromMaybe )
9+
import Data.Semigroup
10+
( (<>) )
11+
import Data.Text.Prettyprint.Doc.Render.Text
12+
( hPutDoc, putDoc )
13+
import Options.Applicative
14+
( InfoMod, Parser, argument, auto, fullDesc, header, help, long,
15+
metavar, option, progDesc, readerError, str, strOption, value )
16+
import System.Exit
17+
( ExitCode (..), exitWith )
18+
import System.IO
19+
( IOMode (WriteMode), withFile )
2920

3021
import Data.Limit
3122
( Limit (..) )
@@ -35,24 +26,18 @@ import Kore.AST.Kore
3526
import Kore.AST.Pure
3627
import Kore.AST.Sentence
3728
import Kore.AST.Valid
38-
import Kore.ASTVerifier.DefinitionVerifier
39-
( AttributesVerification (DoNotVerifyAttributes),
40-
defaultAttributesVerification,
41-
verifyAndIndexDefinitionWithBase )
4229
import qualified Kore.Attribute.Axiom as Attribute
43-
import qualified Kore.Builtin as Builtin
4430
import Kore.Error
4531
( printError )
4632
import Kore.Exec
4733
import Kore.IndexedModule.IndexedModule
48-
( IndexedModule (..), VerifiedModule )
34+
( VerifiedModule )
4935
import Kore.Logger.Output
5036
( KoreLogOptions (..), parseKoreLogOptions, withLogger )
5137
import Kore.Parser.Parser
52-
( parseKoreDefinition, parseKorePattern )
38+
( parseKorePattern )
5339
import Kore.Predicate.Predicate
5440
( makePredicate )
55-
import qualified Kore.Repl as Repl
5641
import Kore.Step.Pattern
5742
import Kore.Step.Representation.ExpandedPattern
5843
( CommonExpandedPattern, Predicated (..) )
@@ -74,31 +59,6 @@ Main module to run kore-exec
7459
TODO: add command line argument tab-completion
7560
-}
7661

77-
data KoreProveOptions =
78-
KoreProveOptions
79-
{ specFileName :: !FilePath
80-
-- ^ Name of file containing the spec to be proven
81-
, specMainModule :: !ModuleName
82-
-- ^ The main module of the spec to be proven
83-
}
84-
85-
parseKoreProveOptions :: Parser KoreProveOptions
86-
parseKoreProveOptions =
87-
KoreProveOptions
88-
<$> strOption
89-
( metavar "SPEC_FILE"
90-
<> long "prove"
91-
<> help "Kore source file representing spec to be proven.\
92-
\Needs --spec-module."
93-
)
94-
<*> (ModuleName
95-
<$> strOption
96-
( metavar "SPEC_MODULE"
97-
<> long "spec-module"
98-
<> help "The name of the main module in the spec to be proven."
99-
)
100-
)
101-
10262

10363
data KoreSearchOptions =
10464
KoreSearchOptions
@@ -198,7 +158,6 @@ data KoreExecOptions = KoreExecOptions
198158
, koreLogOptions :: !KoreLogOptions
199159
, koreSearchOptions :: !(Maybe KoreSearchOptions)
200160
, koreProveOptions :: !(Maybe KoreProveOptions)
201-
, koreRepl :: !Bool
202161
}
203162

204163
-- | Command Line Argument Parser
@@ -247,10 +206,6 @@ parseKoreExecOptions =
247206
<*> parseKoreLogOptions
248207
<*> pure Nothing
249208
<*> optional parseKoreProveOptions
250-
<*> switch
251-
( long "repl"
252-
<> help "Enable REPL mode for prove"
253-
)
254209
SMT.Config { timeOut = defaultTimeOut } = SMT.defaultConfig
255210
readSMTTimeOut = do
256211
i <- auto
@@ -335,7 +290,6 @@ mainWithOptions
335290
, koreLogOptions
336291
, koreSearchOptions
337292
, koreProveOptions
338-
, koreRepl
339293
}
340294
= do
341295
let
@@ -345,10 +299,6 @@ mainWithOptions
345299
{ SMT.timeOut = smtTimeOut
346300
, SMT.preludeFile = smtPrelude
347301
}
348-
repl =
349-
if koreRepl
350-
then Repl.proveClaim
351-
else const . pure $ ()
352302
parsedDefinition <- parseDefinition definitionFileName
353303
indexedDefinition@(indexedModules, _) <-
354304
verifyDefinitionWithBase
@@ -391,7 +341,7 @@ mainWithOptions
391341
clockSomethingIO "Executing"
392342
$ withLogger koreLogOptions (\logger ->
393343
SMT.runSMT smtConfig
394-
$ evalSimplifier logger repl
344+
$ evalSimplifier logger
395345
$ case proveParameters of
396346
Nothing -> do
397347
let purePattern =
@@ -428,30 +378,6 @@ mainWithOptions
428378
withFile outputFile WriteMode (\h -> hPutDoc h unparsed)
429379
() <$ exitWith exitCode
430380

431-
mainModule
432-
:: ModuleName
433-
-> Map.Map
434-
ModuleName
435-
(VerifiedModule StepperAttributes Attribute.Axiom)
436-
-> IO (VerifiedModule StepperAttributes Attribute.Axiom)
437-
mainModule name modules =
438-
case Map.lookup name modules of
439-
Nothing ->
440-
error
441-
( "The main module, '"
442-
++ getModuleNameForError name
443-
++ "', was not found. Check the --module flag."
444-
)
445-
Just m -> return m
446-
447-
{- | Parse a Kore definition from a filename.
448-
449-
Also prints timing information; see 'mainParse'.
450-
451-
-}
452-
parseDefinition :: FilePath -> IO KoreDefinition
453-
parseDefinition = mainParse parseKoreDefinition
454-
455381
-- | IO action that parses a kore pattern from a filename and prints timing
456382
-- information.
457383
mainPatternParse :: String -> IO CommonKorePattern
@@ -484,100 +410,10 @@ mainParseSearchPattern indexedModule patternFileName = do
484410
}
485411
_ -> error "Unexpected non-conjunctive pattern"
486412

487-
-- | IO action that parses a kore AST entity from a filename and prints timing
488-
-- information.
489-
mainParse
490-
:: (FilePath -> String -> Either String a)
491-
-> String
492-
-> IO a
493-
mainParse parser fileName = do
494-
contents <-
495-
clockSomethingIO "Reading the input file" (readFile fileName)
496-
parseResult <-
497-
clockSomething "Parsing the file" (parser fileName contents)
498-
case parseResult of
499-
Left err -> error err
500-
Right definition -> return definition
501-
502-
{- | Verify the well-formedness of a Kore definition.
503-
504-
Also prints timing information; see 'mainParse'.
505-
506-
-}
507-
verifyDefinitionWithBase
508-
:: Maybe
509-
( Map.Map
510-
ModuleName
511-
(VerifiedModule StepperAttributes Attribute.Axiom)
512-
, Map.Map Text AstLocation
513-
)
514-
-- ^ base definition to use for verification
515-
-> Bool -- ^ whether to check (True) or ignore attributes during verification
516-
-> KoreDefinition -- ^ Parsed definition to check well-formedness
517-
-> IO
518-
( Map.Map
519-
ModuleName
520-
(VerifiedModule StepperAttributes Attribute.Axiom)
521-
, Map.Map Text AstLocation
522-
)
523-
verifyDefinitionWithBase maybeBaseModule willChkAttr definition =
524-
let attributesVerification =
525-
if willChkAttr
526-
then defaultAttributesVerification Proxy Proxy
527-
else DoNotVerifyAttributes
528-
in do
529-
verifyResult <-
530-
clockSomething "Verifying the definition"
531-
(verifyAndIndexDefinitionWithBase
532-
maybeBaseModule
533-
attributesVerification
534-
Builtin.koreVerifiers
535-
definition
536-
)
537-
case verifyResult of
538-
Left err1 -> error (printError err1)
539-
Right indexedDefinition -> return indexedDefinition
540-
541413
makePurePattern
542414
:: VerifiedKorePattern
543415
-> CommonStepPattern Object
544416
makePurePattern pat =
545417
case fromKorePattern Object pat of
546418
Left err -> error (printError err)
547419
Right objPat -> objPat
548-
549-
-- TODO (traiansf): Get rid of this.
550-
-- The function below works around several limitations of
551-
-- the current tool by tricking the tool into believing that
552-
-- functions are constructors (so that function patterns can match)
553-
-- and that @kseq@ and @dotk@ are both functional and constructor.
554-
constructorFunctions
555-
:: VerifiedModule StepperAttributes Attribute.Axiom
556-
-> VerifiedModule StepperAttributes Attribute.Axiom
557-
constructorFunctions ixm =
558-
ixm
559-
{ indexedModuleObjectSymbolSentences =
560-
Map.mapWithKey
561-
constructorFunctions1
562-
(indexedModuleObjectSymbolSentences ixm)
563-
, indexedModuleObjectAliasSentences =
564-
Map.mapWithKey
565-
constructorFunctions1
566-
(indexedModuleObjectAliasSentences ixm)
567-
, indexedModuleImports = recurseIntoImports <$> indexedModuleImports ixm
568-
}
569-
where
570-
constructorFunctions1 ident (atts, defn) =
571-
( atts
572-
& lensConstructor Lens.<>~ Constructor isCons
573-
& lensFunctional Lens.<>~ Functional (isCons || isInj)
574-
& lensInjective Lens.<>~ Injective (isCons || isInj)
575-
& lensSortInjection Lens.<>~ SortInjection isInj
576-
, defn
577-
)
578-
where
579-
isInj = getId ident == "inj"
580-
isCons = elem (getId ident) ["kseq", "dotk"]
581-
582-
recurseIntoImports (attrs, attributes, importedModule) =
583-
(attrs, attributes, constructorFunctions importedModule)

kore/app/parser/Main.hs

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -127,22 +127,6 @@ main = do
127127
when willPrintPattern $
128128
putStrLn (prettyPrintToString parsedPattern)
129129

130-
mainModule
131-
:: ModuleName
132-
-> Map.Map
133-
ModuleName
134-
(VerifiedModule StepperAttributes Attribute.Axiom)
135-
-> IO (VerifiedModule StepperAttributes Attribute.Axiom)
136-
mainModule name modules =
137-
case Map.lookup name modules of
138-
Nothing ->
139-
error
140-
( "The main module, '"
141-
++ getModuleNameForError name
142-
++ "', was not found. Check the --module flag."
143-
)
144-
Just m -> return m
145-
146130
-- | IO action that parses a kore definition from a filename and prints timing
147131
-- information.
148132
mainDefinitionParse :: String -> IO KoreDefinition
@@ -153,21 +137,6 @@ mainDefinitionParse = mainParse parseKoreDefinition
153137
mainPatternParse :: String -> IO CommonKorePattern
154138
mainPatternParse = mainParse parseKorePattern
155139

156-
-- | IO action that parses a kore AST entity from a filename and prints timing
157-
-- information.
158-
mainParse
159-
:: (FilePath -> String -> Either String a)
160-
-> String
161-
-> IO a
162-
mainParse parser fileName = do
163-
contents <-
164-
clockSomethingIO "Reading the input file" (readFile fileName)
165-
parseResult <-
166-
clockSomething "Parsing the file" (parser fileName contents)
167-
case parseResult of
168-
Left err -> error err
169-
Right definition -> return definition
170-
171140
-- | IO action verifies well-formedness of Kore definition and prints
172141
-- timing information.
173142
mainVerify

0 commit comments

Comments
 (0)