@@ -155,33 +155,57 @@ respond stateVar request =
155
155
156
156
solver <- maybe (SMT. noSolver) (SMT. initSolver def) mSMTOptions
157
157
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
185
209
RpcTypes. AddModule RpcTypes. AddModuleRequest {_module, nameAsId = nameAsId'} -> Booster.Log. withContext CtxAddModule $ runExceptT $ do
186
210
-- block other request executions while modifying the server state
187
211
state <- liftIO $ takeMVar stateVar
0 commit comments