Skip to content

Commit c160ec5

Browse files
Add option to turn an arbitrary log entry into an error (#2298)
1 parent 3fd34f9 commit c160ec5

File tree

3 files changed

+99
-47
lines changed

3 files changed

+99
-47
lines changed

kore/src/Kore/Log.hs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,19 @@ koreLogTransformer
119119
-> LogAction m ActualEntry
120120
koreLogTransformer koreLogOptions baseLogger =
121121
Colog.cmap
122-
( warningsToErrors warningSwitch
123-
)
122+
( toErrors warningSwitch )
124123
baseLogger
125124
where
126-
KoreLogOptions { warningSwitch } = koreLogOptions
125+
KoreLogOptions { turnedIntoErrors, warningSwitch } = koreLogOptions
127126

128-
warningsToErrors :: WarningSwitch -> ActualEntry -> ActualEntry
129-
warningsToErrors AsError entry@ActualEntry { actualEntry }
127+
toErrors :: WarningSwitch -> ActualEntry -> ActualEntry
128+
toErrors AsError ActualEntry { actualEntry }
130129
| entrySeverity actualEntry == Warning =
131130
error . show . longDoc $ actualEntry
131+
toErrors _ entry@ActualEntry { actualEntry }
132+
| typeOfSomeEntry actualEntry `elem` turnedIntoErrors =
133+
error . show . longDoc $ actualEntry
132134
| otherwise = entry
133-
warningsToErrors AsWarning entry = entry
134135

135136
koreLogFilters
136137
:: Applicative m

kore/src/Kore/Log/KoreLogOptions.hs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import Kore.Log.DebugSolver
6868
)
6969
import Kore.Log.Registry
7070
( getEntryTypesAsText
71+
, getNoErrEntryTypesAsText
7172
, parseEntryType
7273
)
7374
import Kore.Log.SQLite
@@ -96,6 +97,7 @@ data KoreLogOptions = KoreLogOptions
9697
, startTime :: !TimeSpec
9798
, logSQLiteOptions :: !LogSQLiteOptions
9899
, warningSwitch :: !WarningSwitch
100+
, turnedIntoErrors :: !EntryTypes
99101
, debugApplyEquationOptions :: !DebugApplyEquationOptions
100102
, debugAttemptEquationOptions :: !DebugAttemptEquationOptions
101103
, debugEquationOptions :: !DebugEquationOptions
@@ -117,6 +119,7 @@ defaultKoreLogOptions exeName startTime =
117119
, startTime
118120
, logSQLiteOptions = def @LogSQLiteOptions
119121
, warningSwitch = def @WarningSwitch
122+
, turnedIntoErrors = mempty
120123
, debugApplyEquationOptions = def @DebugApplyEquationOptions
121124
, debugAttemptEquationOptions = def @DebugAttemptEquationOptions
122125
, debugEquationOptions = def @DebugEquationOptions
@@ -182,6 +185,7 @@ parseKoreLogOptions exeName startTime =
182185
<*> pure startTime
183186
<*> parseLogSQLiteOptions
184187
<*> parseWarningSwitch
188+
<*> (mconcat <$> many parseErrorEntries)
185189
<*> parseDebugApplyEquationOptions
186190
<*> parseDebugAttemptEquationOptions
187191
<*> parseDebugEquationOptions
@@ -201,12 +205,13 @@ parseEntryTypes =
201205
[ "Log entries: logs entries of supplied types"
202206
, "Available entry types:"
203207
, (OptPretty.indent 4 . OptPretty.vsep)
204-
(OptPretty.text <$> getEntryTypesAsText)
208+
( OptPretty.text <$> getEntryTypesAsText )
205209
]
206210

207-
parseCommaSeparatedEntries =
208-
Options.maybeReader $ Parser.parseMaybe parseEntryTypes'
209-
211+
parseCommaSeparatedEntries :: Options.ReadM EntryTypes
212+
parseCommaSeparatedEntries =
213+
Options.maybeReader $ Parser.parseMaybe parseEntryTypes'
214+
where
210215
parseEntryTypes' :: Parser.Parsec String String EntryTypes
211216
parseEntryTypes' = Set.fromList <$> Parser.sepEndBy parseSomeTypeRep comma
212217

@@ -244,6 +249,27 @@ parseWarningSwitch =
244249
<> Options.help "Turn warnings into errors"
245250
)
246251

252+
parseErrorEntries :: Parser EntryTypes
253+
parseErrorEntries =
254+
option parseCommaSeparatedEntries info
255+
where
256+
info =
257+
mempty
258+
<> Options.long "error-entries"
259+
<> Options.helpDoc ( Just nonErrorEntryTypes )
260+
261+
nonErrorEntryTypes :: OptPretty.Doc
262+
nonErrorEntryTypes =
263+
OptPretty.vsep
264+
[ "Turn arbitrary log entries into errors"
265+
, "Available entry types:"
266+
, (OptPretty.indent 4 . OptPretty.vsep)
267+
(OptPretty.text <$> getNoErrEntryTypesAsText)
268+
{- The user can still give error entries as arguments, but it's
269+
useless, so we don't list them here
270+
-}
271+
]
272+
247273
-- | Caller of the logging function
248274
newtype ExeName = ExeName { getExeName :: String }
249275
deriving (Eq, Show)
@@ -396,6 +422,7 @@ unparseKoreLogOptions
396422
_
397423
logSQLiteOptions
398424
warningSwitch
425+
toError
399426
debugApplyEquationOptions
400427
debugAttemptEquationOptions
401428
debugEquationOptions
@@ -409,6 +436,7 @@ unparseKoreLogOptions
409436
, debugSolverOptionsFlag debugSolverOptions
410437
, logSQLiteOptionsFlag logSQLiteOptions
411438
, ["--warnings-to-errors" | AsError <- [warningSwitch] ]
439+
, logEntriesFlag toError
412440
, debugApplyEquationOptionsFlag debugApplyEquationOptions
413441
, debugAttemptEquationOptionsFlag debugAttemptEquationOptions
414442
, debugEquationOptionsFlag debugEquationOptions

kore/src/Kore/Log/Registry.hs

Lines changed: 60 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@ module Kore.Log.Registry
1111
, typeToText
1212
, textToType
1313
, getEntryTypesAsText
14+
, getErrEntryTypesAsText
15+
, getNoErrEntryTypesAsText
1416
, typeOfSomeEntry
17+
, entryTypeRepsErr
18+
, entryTypeRepsNoErr
1519
, entryTypeReps
1620
) where
1721

1822
import Prelude.Kore
1923

24+
import Control.Lens
25+
( (%~)
26+
)
27+
import qualified Control.Lens as Lens
2028
import Data.Functor.Classes
2129
( eq2
2230
)
@@ -139,7 +147,8 @@ data Registry =
139147
-- When adding a new entry type you should register it here.
140148
registry :: Registry
141149
registry =
142-
let textToType = (Map.fromList . map register) entryTypeReps
150+
let textToType =
151+
(Map.fromList . map register) entryTypeReps
143152
typeToText = makeInverse textToType
144153
in if textToType `eq2` makeInverse typeToText
145154
then Registry { textToType, typeToText }
@@ -154,41 +163,49 @@ registry =
154163
(asText type', type')
155164

156165
entryTypeReps :: [SomeTypeRep]
157-
entryHelpDocs :: [Pretty.Doc ()]
158-
(entryTypeReps, entryHelpDocs) =
159-
unzip
160-
[ mk $ Proxy @DebugSolverSend
161-
, mk $ Proxy @DebugSolverRecv
162-
, mk $ Proxy @DebugClaimState
163-
, mk $ Proxy @DebugAppliedRewriteRules
164-
, mk $ Proxy @DebugSubstitutionSimplifier
165-
, mk $ Proxy @ErrorBottomTotalFunction
166-
, mk $ Proxy @ErrorDecidePredicateUnknown
167-
, mk $ Proxy @ErrorParse
168-
, mk $ Proxy @ErrorVerify
169-
, mk $ Proxy @ErrorRuleMergeDuplicateIds
170-
, mk $ Proxy @ErrorRuleMergeDuplicateLabels
171-
, mk $ Proxy @WarnFunctionWithoutEvaluators
172-
, mk $ Proxy @WarnSymbolSMTRepresentation
173-
, mk $ Proxy @WarnStuckClaimState
174-
, mk $ Proxy @WarnIfLowProductivity
175-
, mk $ Proxy @WarnTrivialClaim
176-
, mk $ Proxy @WarnRetrySolverQuery
177-
, mk $ Proxy @DebugEvaluateCondition
178-
, mk $ Proxy @ErrorException
179-
, mk $ Proxy @ErrorRewriteLoop
180-
, mk $ Proxy @LogMessage
181-
, mk $ Proxy @InfoAttemptUnification
182-
, mk $ Proxy @InfoReachability
183-
, mk $ Proxy @InfoExecBreadth
184-
, mk $ Proxy @ErrorRewritesInstantiation
185-
, mk $ Proxy @DebugAttemptEquation
186-
, mk $ Proxy @DebugApplyEquation
187-
, mk $ Proxy @DebugUnification
188-
, mk $ Proxy @InfoProofDepth
189-
, mk $ Proxy @InfoExecDepth
190-
, mk $ Proxy @DebugProven
191-
]
166+
entryTypeReps = entryTypeRepsErr <> entryTypeRepsNoErr
167+
168+
entryTypeRepsErr, entryTypeRepsNoErr :: [SomeTypeRep]
169+
entryHelpDocsErr, entryHelpDocsNoErr :: [Pretty.Doc ()]
170+
( (entryTypeRepsNoErr, entryHelpDocsNoErr)
171+
, (entryTypeRepsErr, entryHelpDocsErr) )
172+
=
173+
( [ mk $ Proxy @DebugSolverSend
174+
, mk $ Proxy @DebugSolverRecv
175+
, mk $ Proxy @DebugClaimState
176+
, mk $ Proxy @DebugAppliedRewriteRules
177+
, mk $ Proxy @DebugSubstitutionSimplifier
178+
, mk $ Proxy @WarnFunctionWithoutEvaluators
179+
, mk $ Proxy @WarnSymbolSMTRepresentation
180+
, mk $ Proxy @WarnStuckClaimState
181+
, mk $ Proxy @WarnIfLowProductivity
182+
, mk $ Proxy @WarnTrivialClaim
183+
, mk $ Proxy @WarnRetrySolverQuery
184+
, mk $ Proxy @DebugEvaluateCondition
185+
, mk $ Proxy @LogMessage
186+
, mk $ Proxy @InfoAttemptUnification
187+
, mk $ Proxy @InfoReachability
188+
, mk $ Proxy @InfoExecBreadth
189+
, mk $ Proxy @DebugAttemptEquation
190+
, mk $ Proxy @DebugApplyEquation
191+
, mk $ Proxy @DebugUnification
192+
, mk $ Proxy @InfoProofDepth
193+
, mk $ Proxy @InfoExecDepth
194+
, mk $ Proxy @DebugProven
195+
]
196+
197+
, [ mk $ Proxy @ErrorBottomTotalFunction
198+
, mk $ Proxy @ErrorDecidePredicateUnknown
199+
, mk $ Proxy @ErrorParse
200+
, mk $ Proxy @ErrorVerify
201+
, mk $ Proxy @ErrorRuleMergeDuplicateIds
202+
, mk $ Proxy @ErrorRuleMergeDuplicateLabels
203+
, mk $ Proxy @ErrorException
204+
, mk $ Proxy @ErrorRewriteLoop
205+
, mk $ Proxy @ErrorRewritesInstantiation
206+
]
207+
)
208+
& Lens.each %~ unzip
192209
where
193210
mk proxy =
194211
let tRep = someTypeRep proxy
@@ -233,4 +250,10 @@ typeOfSomeEntry :: SomeEntry -> SomeTypeRep
233250
typeOfSomeEntry (SomeEntry entry) = SomeTypeRep (typeOf entry)
234251

235252
getEntryTypesAsText :: [String]
236-
getEntryTypesAsText = show <$> entryHelpDocs
253+
getEntryTypesAsText = getNoErrEntryTypesAsText <> getErrEntryTypesAsText
254+
255+
getErrEntryTypesAsText :: [String]
256+
getErrEntryTypesAsText = show <$> entryHelpDocsErr
257+
258+
getNoErrEntryTypesAsText :: [String]
259+
getNoErrEntryTypesAsText = show <$> entryHelpDocsNoErr

0 commit comments

Comments
 (0)