Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
af0b7e5
WIP: kore-match-disjunction tool
ana-pantilie Jun 23, 2021
4d93128
General structure of new tool
ana-pantilie Jun 24, 2021
b645dda
Format with fourmolu
invalid-email-address Jun 24, 2021
5b5a44e
Implement kore-match-disjunction
ana-pantilie Jun 29, 2021
43ea665
Materialize Nix expressions
invalid-email-address Jun 29, 2021
ad4b9c8
Clean-up kore-exec main
ana-pantilie Jun 29, 2021
0d5551d
Merge branch 'match-disjunction-tool' of github.com:kframework/kore i…
ana-pantilie Jun 29, 2021
f7d0aca
Fix building and HLS processing
andreiburdusa Jul 26, 2021
5dac97a
Materialize Nix expressions
invalid-email-address Jul 26, 2021
6a8ea25
Merge remote-tracking branch 'origin/master' into match-disjunction-tool
andreiburdusa Jul 26, 2021
e0559ff
Allow "make ghcid-match"
andreiburdusa Jul 26, 2021
c79b499
Merge branch 'match-disjunction-tool' of github.com:kframework/kore i…
andreiburdusa Jul 26, 2021
9815891
Apply pedantic
andreiburdusa Jul 26, 2021
32ca719
Add two trivial unit tests
andreiburdusa Jul 26, 2021
8c56ab7
Add unit tests inspired by "search" integration test
andreiburdusa Aug 3, 2021
771d384
Remove comments
andreiburdusa Aug 4, 2021
4f49cd8
Merge branch 'master' into match-disjunction-tool
ana-pantilie Aug 4, 2021
72d3346
Address or remove TODOs
andreiburdusa Aug 5, 2021
5045cfc
Merge branch 'match-disjunction-tool' of github.com:kframework/kore i…
andreiburdusa Aug 5, 2021
374ea46
Merge branch 'master' into match-disjunction-tool
ana-pantilie Aug 6, 2021
184086b
Merge branch 'master' into match-disjunction-tool
ana-pantilie Aug 6, 2021
b0a4386
Merge branch 'master' into match-disjunction-tool
ana-pantilie Aug 9, 2021
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
1 change: 1 addition & 0 deletions hie-cabal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ cradle:
- { path: "./kore/app/parser", component: "kore:kore-parser" }
- { path: "./kore/app/prof", component: "kore:kore-prof" }
- { path: "./kore/app/repl", component: "kore:kore-repl" }
- { path: "./kore/app/match-disjunction", component: "kore:kore-match-disjunction" }
1 change: 1 addition & 0 deletions hie-stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ cradle:
- { path: "./kore/app/parser", component: "kore:kore-parser" }
- { path: "./kore/app/prof", component: "kore:kore-prof" }
- { path: "./kore/app/repl", component: "kore:kore-repl" }
- { path: "./kore/app/match-disjunction", component: "kore:kore-match-disjunction" }
2 changes: 2 additions & 0 deletions kore/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ ghcid:
ghcid-repl:
$(stack) exec -- ghcid -c "stack ghci $(package) --test --ghci-options='-fobject-code -fno-warn-unused-do-bind' --main-is $(package):kore-repl --work-dir .stack-work-ghci"

ghcid-match:
$(stack) exec -- ghcid -c "stack ghci $(package) --test --ghci-options='-fobject-code -fno-warn-unused-do-bind' --main-is $(package):kore-match-disjunction --work-dir .stack-work-ghci"

# TODO(Vladimir): remove 'hyperlink-source' when we upgrade from lts-12.10 (8.4.3)
hoogle-gen:
Expand Down
49 changes: 0 additions & 49 deletions kore/app/exec/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,11 @@ import Kore.Internal.MultiAnd (
)
import qualified Kore.Internal.MultiAnd as MultiAnd
import qualified Kore.Internal.OrPattern as OrPattern
import Kore.Internal.Pattern (
Conditional (..),
Pattern,
)
import Kore.Internal.Predicate (
makePredicate,
)
import Kore.Internal.TermLike (
TermLike,
VariableName,
mkSortVariable,
mkTop,
pattern And_,
)
import Kore.Log (
KoreLogOptions (..),
Expand All @@ -91,10 +83,6 @@ import Kore.Log.WarnIfLowProductivity (
import qualified Kore.ModelChecker.Bounded as Bounded (
CheckResult (..),
)
import Kore.Parser (
ParsedPattern,
parseKorePattern,
)
import Kore.Parser.ParserUtils (
readPositiveIntegral,
)
Expand Down Expand Up @@ -161,7 +149,6 @@ import Options.SMT (
import Prelude.Kore
import Pretty (
Doc,
Pretty (..),
hPutDoc,
putDoc,
vsep,
Expand Down Expand Up @@ -919,48 +906,12 @@ loadPattern mainModule (Just fileName) =
mainPatternParseAndVerify mainModule fileName
loadPattern _ Nothing = error "Missing: --pattern PATTERN_FILE"

{- | IO action that parses a kore pattern from a filename and prints timing
information.
-}
mainPatternParse :: String -> Main ParsedPattern
mainPatternParse = mainParse parseKorePattern

renderResult :: KoreExecOptions -> Doc ann -> IO ()
renderResult KoreExecOptions{outputFileName} doc =
case outputFileName of
Nothing -> putDoc doc
Just outputFile -> withFile outputFile WriteMode (`hPutDoc` doc)

{- | IO action that parses a kore pattern from a filename, verifies it,
converts it to a pure pattern, and prints timing information.
-}
mainPatternParseAndVerify ::
VerifiedModule StepperAttributes ->
String ->
Main (TermLike VariableName)
mainPatternParseAndVerify indexedModule patternFileName =
mainPatternParse patternFileName >>= mainPatternVerify indexedModule

mainParseSearchPattern ::
VerifiedModule StepperAttributes ->
String ->
Main (Pattern VariableName)
mainParseSearchPattern indexedModule patternFileName = do
purePattern <- mainPatternParseAndVerify indexedModule patternFileName
case purePattern of
And_ _ term predicateTerm ->
return
Conditional
{ term
, predicate =
either
(error . show . pretty)
id
(makePredicate predicateTerm)
, substitution = mempty
}
_ -> error "Unexpected non-conjunctive pattern"

savedProofsModuleName :: ModuleName
savedProofsModuleName =
ModuleName
Expand Down
192 changes: 192 additions & 0 deletions kore/app/match-disjunction/Main.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
module Main (main) where

import GlobalMain
import Kore.Attribute.Symbol (
StepperAttributes,
)
import Kore.BugReport
import Kore.Exec (matchDisjunction)
import Kore.IndexedModule.IndexedModule (
VerifiedModule,
)
import Kore.Internal.Pattern (Pattern)
import qualified Kore.Internal.Pattern as Pattern
import Kore.Internal.TermLike (
pattern Or_,
)
import Kore.Log (
KoreLogOptions,
parseKoreLogOptions,
runKoreLog,
)
import Kore.Rewrite.RewritingVariable (
RewritingVariableName,
mkRewritingPattern,
)
import Kore.Syntax.Module (
ModuleName (..),
)
import Kore.Unparser (
unparse,
)
import Options.Applicative (
InfoMod,
Parser,
argument,
fullDesc,
header,
help,
long,
metavar,
progDesc,
str,
strOption,
)
import Prelude.Kore
import Pretty
import System.Clock (
Clock (..),
TimeSpec,
getTime,
)
import System.Exit (
exitWith,
)
import System.IO (
IOMode (WriteMode),
withFile,
)

exeName :: ExeName
exeName = ExeName "kore-match-disjunction"

envName :: String
envName = "KORE_MATCH_DISJUNCTION_OPTS"

data KoreMatchDisjunctionOptions = KoreMatchDisjunctionOptions
{ -- | Name of file containing a definition to verify and use for execution
definitionFileName :: !FilePath
, -- | Name of file containing a disjunction to verify and use for matching
disjunctionFileName :: !FilePath
, -- | Name of file used to match with disjunction
matchFileName :: !FilePath
, -- | Name for file to contain the output pattern
outputFileName :: !(Maybe FilePath)
, -- | The name of the main module in the definition
mainModuleName :: !ModuleName
, bugReportOption :: !BugReportOption
, koreLogOptions :: !KoreLogOptions
}

parseKoreMatchDisjunctionOptions :: TimeSpec -> Parser KoreMatchDisjunctionOptions
parseKoreMatchDisjunctionOptions startTime =
KoreMatchDisjunctionOptions
<$> argument
str
( metavar "DEFINITION_FILE"
<> help "Kore definition file to verify and use for execution."
)
<*> strOption
( metavar "DISJUNCTION_FILE"
<> long "disjunction"
<> help "File containing a disjunction of concrete terms."
)
<*> strOption
( metavar "MATCH_FILE"
<> long "match"
<> help "Kore source file representing pattern to search for."
)
<*> optional
( strOption
( metavar "PATTERN_OUTPUT_FILE"
<> long "output"
<> help "Output file to contain final Kore pattern."
)
)
<*> parseMainModuleName
<*> parseBugReportOption
<*> parseKoreLogOptions exeName startTime
where
parseMainModuleName =
GlobalMain.parseModuleName
"MODULE"
"module"
"The name of the main module in the Kore definition."

parserInfoModifiers :: InfoMod options
parserInfoModifiers =
fullDesc
<> progDesc "Matches Kore pattern in MATCH_FILE with Kore pattern in DISJUNCTION_FILE"
<> header "kore-match-disjunction - a tool for applying search patterns to disjunctions of configurations"

main :: IO ()
main = do
startTime <- getTime Monotonic
options <-
mainGlobal
exeName
(Just envName)
(parseKoreMatchDisjunctionOptions startTime)
parserInfoModifiers
for_ (localOptions options) mainWithOptions

mainWithOptions :: KoreMatchDisjunctionOptions -> IO ()
mainWithOptions options = do
exitCode <-
withBugReport exeName bugReportOption $ \tmpDir ->
koreMatchDisjunction options
& runKoreLog tmpDir koreLogOptions
exitWith exitCode
where
KoreMatchDisjunctionOptions{bugReportOption} = options
KoreMatchDisjunctionOptions{koreLogOptions} = options

koreMatchDisjunction :: KoreMatchDisjunctionOptions -> Main ExitCode
koreMatchDisjunction options = do
definition <- loadDefinitions [definitionFileName]
mainModule <- loadModule mainModuleName definition
matchPattern <- mainParseMatchPattern mainModule matchFileName
disjunctionPattern <-
mainParseDisjunctionPattern mainModule disjunctionFileName
final <-
clockSomethingIO "Executing" $
matchDisjunction mainModule matchPattern disjunctionPattern
lift $
renderResult
options
(unparse final)
return ExitSuccess
where
mainParseMatchPattern mainModule fileName =
mainParseSearchPattern mainModule fileName
<&> mkRewritingPattern
KoreMatchDisjunctionOptions
{ definitionFileName
, disjunctionFileName
, matchFileName
, mainModuleName
} = options

mainParseDisjunctionPattern ::
VerifiedModule StepperAttributes ->
String ->
Main [Pattern RewritingVariableName]
mainParseDisjunctionPattern indexedModule patternFileName = do
purePattern <- mainPatternParseAndVerify indexedModule patternFileName
return $ parseDisjunction purePattern
where
parseDisjunction (Or_ _ term1 term2) =
parseDisjunction term1 <> parseDisjunction term2
parseDisjunction term =
let patt =
mkRewritingPattern
. Pattern.fromTermLike
$ term
in [patt]

renderResult :: KoreMatchDisjunctionOptions -> Doc ann -> IO ()
renderResult KoreMatchDisjunctionOptions{outputFileName} doc =
case outputFileName of
Nothing -> putDoc doc
Just outputFile ->
withFile outputFile WriteMode (`hPutDoc` doc)
49 changes: 48 additions & 1 deletion kore/app/share/GlobalMain.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ module GlobalMain (
LoadedModule,
loadDefinitions,
loadModule,
mainParseSearchPattern,
mainPatternParseAndVerify,
) where

import Control.Exception (
Expand Down Expand Up @@ -58,13 +60,20 @@ import Kore.Attribute.Definition (
import Kore.Attribute.SourceLocation (
notDefault,
)
import Kore.Attribute.Symbol (
StepperAttributes,
)
import qualified Kore.Attribute.Symbol as Attribute (
Symbol,
)
import qualified Kore.Builtin as Builtin
import Kore.IndexedModule.IndexedModule (
VerifiedModule,
)
import Kore.Internal.Conditional (Conditional (..))
import Kore.Internal.Pattern (Pattern)
import Kore.Internal.Predicate (makePredicate)
import Kore.Internal.TermLike (TermLike, pattern And_)
import Kore.Log as Log
import Kore.Log.ErrorParse (
errorParse,
Expand All @@ -75,6 +84,7 @@ import Kore.Log.ErrorVerify (
import Kore.Parser (
ParsedPattern,
parseKoreDefinition,
parseKorePattern,
)
import qualified Kore.Parser.Lexer as Lexer
import Kore.Parser.ParserUtils (
Expand All @@ -83,7 +93,7 @@ import Kore.Parser.ParserUtils (
import Kore.Rewrite.Strategy (
GraphSearchOrder (..),
)
import Kore.Syntax
import Kore.Syntax hiding (Pattern)
import Kore.Syntax.Definition (
ModuleName (..),
ParsedDefinition,
Expand Down Expand Up @@ -130,6 +140,7 @@ import qualified Paths_kore as MetaData (
version,
)
import Prelude.Kore
import qualified Pretty as KorePretty
import System.Clock (
Clock (Monotonic),
diffTimeSpec,
Expand Down Expand Up @@ -513,3 +524,39 @@ loadDefinitions filePaths =

loadModule :: ModuleName -> LoadedDefinition -> Main LoadedModule
loadModule moduleName = lookupMainModule moduleName . indexedModules

mainParseSearchPattern ::
VerifiedModule StepperAttributes ->
String ->
Main (Pattern VariableName)
mainParseSearchPattern indexedModule patternFileName = do
purePattern <- mainPatternParseAndVerify indexedModule patternFileName
case purePattern of
And_ _ term predicateTerm ->
return
Conditional
{ term
, predicate =
either
(error . show . KorePretty.pretty)
id
(makePredicate predicateTerm)
, substitution = mempty
}
_ -> error "Unexpected non-conjunctive pattern"

{- | IO action that parses a kore pattern from a filename, verifies it,
converts it to a pure pattern, and prints timing information.
-}
mainPatternParseAndVerify ::
VerifiedModule StepperAttributes ->
String ->
Main (TermLike VariableName)
mainPatternParseAndVerify indexedModule patternFileName =
mainPatternParse patternFileName >>= mainPatternVerify indexedModule

{- | IO action that parses a kore pattern from a filename and prints timing
information.
-}
mainPatternParse :: String -> Main ParsedPattern
mainPatternParse = mainParse parseKorePattern
Loading