Skip to content

Commit cf8aa7c

Browse files
committed
Check consistency of the pattern before rewriting
1 parent 4b1f940 commit cf8aa7c

File tree

1 file changed

+51
-27
lines changed

1 file changed

+51
-27
lines changed

booster/library/Booster/JsonRpc.hs

+51-27
Original file line numberDiff line numberDiff line change
@@ -155,33 +155,57 @@ respond stateVar request =
155155

156156
solver <- maybe (SMT.noSolver) (SMT.initSolver def) mSMTOptions
157157

158-
logger <- getLogger
159-
prettyModifiers <- getPrettyModifiers
160-
let rewriteConfig =
161-
RewriteConfig
162-
{ definition = def
163-
, llvmApi = mLlvmLibrary
164-
, smtSolver = solver
165-
, varsToAvoid = substVars
166-
, doTracing
167-
, logger
168-
, prettyModifiers
169-
, mbMaxDepth = mbDepth
170-
, mbSimplify = rewriteOpts.interimSimplification
171-
, cutLabels = cutPoints
172-
, terminalLabels = terminals
173-
}
174-
result <-
175-
performRewrite rewriteConfig substPat
176-
SMT.finaliseSolver solver
177-
stop <- liftIO $ getTime Monotonic
178-
let duration =
179-
if fromMaybe False req.logTiming
180-
then
181-
Just $
182-
fromIntegral (toNanoSecs (diffTimeSpec stop start)) / 1e9
183-
else Nothing
184-
pure $ execResponse duration req result substitution unsupported
158+
-- check input pattern's consistency before starting rewriting
159+
evaluatedInitialPattern <-
160+
ApplyEquations.evaluatePattern
161+
def
162+
mLlvmLibrary
163+
solver
164+
mempty
165+
substPat
166+
167+
case evaluatedInitialPattern of
168+
(Left ApplyEquations.SideConditionFalse{}, _) -> do
169+
stop <- liftIO $ getTime Monotonic
170+
let duration =
171+
if fromMaybe False req.logTiming
172+
then
173+
Just $
174+
fromIntegral (toNanoSecs (diffTimeSpec stop start)) / 1e9
175+
else Nothing
176+
pure $ execResponse duration req (0, mempty, RewriteTrivial substPat) substitution unsupported
177+
(Left other, _) ->
178+
pure . Left . RpcError.backendError $ RpcError.Aborted (Text.pack . constructorName $ other)
179+
(Right newPattern, _simplifierCache) -> do
180+
-- FIXME do not throw away @simplifierCache@, pass it to performRewrite somehow
181+
logger <- getLogger
182+
prettyModifiers <- getPrettyModifiers
183+
let rewriteConfig =
184+
RewriteConfig
185+
{ definition = def
186+
, llvmApi = mLlvmLibrary
187+
, smtSolver = solver
188+
, varsToAvoid = substVars
189+
, doTracing
190+
, logger
191+
, prettyModifiers
192+
, mbMaxDepth = mbDepth
193+
, mbSimplify = rewriteOpts.interimSimplification
194+
, cutLabels = cutPoints
195+
, terminalLabels = terminals
196+
}
197+
198+
result <-
199+
performRewrite rewriteConfig newPattern
200+
SMT.finaliseSolver solver
201+
stop <- liftIO $ getTime Monotonic
202+
let duration =
203+
if fromMaybe False req.logTiming
204+
then
205+
Just $
206+
fromIntegral (toNanoSecs (diffTimeSpec stop start)) / 1e9
207+
else Nothing
208+
pure $ execResponse duration req result substitution unsupported
185209
RpcTypes.AddModule RpcTypes.AddModuleRequest{_module, nameAsId = nameAsId'} -> Booster.Log.withContext CtxAddModule $ runExceptT $ do
186210
-- block other request executions while modifying the server state
187211
state <- liftIO $ takeMVar stateVar

0 commit comments

Comments
 (0)