@@ -207,7 +207,7 @@ rewriteStep cutLabels terminalLabels pat = do
207
207
RewriteStuck {} -> pure $ RewriteTrivial pat
208
208
other -> pure other
209
209
-- all branches but one were either not applied or trivial
210
- [(r, x )]
210
+ [(r, (x, _remainder, _subst) )]
211
211
| labelOf r `elem` cutLabels ->
212
212
pure $ RewriteCutPoint (labelOf r) (uniqueId r) pat x
213
213
| labelOf r `elem` terminalLabels ->
@@ -220,7 +220,7 @@ rewriteStep cutLabels terminalLabels pat = do
220
220
pure $
221
221
RewriteBranch pat $
222
222
NE. fromList $
223
- map (\ (r, p ) -> (ruleLabelOrLocT r, uniqueId r, p)) rxs
223
+ map (\ (r, (p, _remainder, _subst) ) -> (ruleLabelOrLocT r, uniqueId r, p)) rxs
224
224
225
225
-- | Rewrite rule application transformer: may throw exceptions on non-applicable or trivial rule applications
226
226
type RewriteRuleAppT m a = ExceptT RewriteRuleAppException m a
@@ -260,7 +260,7 @@ applyRule ::
260
260
LoggerMIO io =>
261
261
Pattern ->
262
262
RewriteRule " Rewrite" ->
263
- RewriteT io (RewriteRuleAppResult Pattern )
263
+ RewriteT io (RewriteRuleAppResult ( Pattern , Predicate , Substitution ) )
264
264
applyRule pat@ Pattern {ceilConditions} rule =
265
265
withRuleContext rule $
266
266
runRewriteRuleAppT $
@@ -326,12 +326,6 @@ applyRule pat@Pattern{ceilConditions} rule =
326
326
-- check required constraints from lhs: Stop if any is false,
327
327
-- add as remainders if indeterminate.
328
328
unclearRequiresAfterSmt <- checkRequires subst
329
- -- when unclearRequiresAfterSmt is non-empty, we need to add it as a rule remainder.
330
- -- To maintain the old behaviour, we fail hard here
331
- unless (null unclearRequiresAfterSmt) $
332
- failRewrite $
333
- RuleConditionUnclear rule . coerce . foldl1 AndTerm $
334
- map coerce unclearRequiresAfterSmt
335
329
336
330
-- check ensures constraints (new) from rhs: stop and return `Trivial` if
337
331
-- any are false, remove all that are trivially true, return the rest
@@ -366,9 +360,21 @@ applyRule pat@Pattern{ceilConditions} rule =
366
360
<> (Set. fromList $ map (coerce . substituteInTerm existentialSubst . coerce) newConstraints)
367
361
)
368
362
ceilConditions
369
- withContext CtxSuccess $
370
- withPatternContext rewritten $
371
- return rewritten
363
+ withContext CtxSuccess $ do
364
+ case unclearRequiresAfterSmt of
365
+ [] -> withPatternContext rewritten $ pure (rewritten, Predicate FalseBool , subst)
366
+ _ -> do
367
+ failRewrite $
368
+ RuleConditionUnclear rule . coerce . foldl1 AndTerm $
369
+ map coerce unclearRequiresAfterSmt
370
+ -- TODO the following code is intentionally dead and should be enabled to get rewrite rule remainders
371
+ -- when unclearRequiresAfterSmt is non-empty, we need to add it as a rule remainder predicate, which means:
372
+ -- - the resulting patten will have it conjoined to its constraints TODO is this right?
373
+ -- - its negation, i.e. the remainder predicate, will be returned as the second component of the result
374
+ let rewritten' = rewritten{constraints = rewritten. constraints <> Set. fromList unclearRequiresAfterSmt}
375
+ in withPatternContext rewritten' $
376
+ pure
377
+ (rewritten', Predicate $ NotBool $ coerce $ collapseAndBools unclearRequiresAfterSmt, subst)
372
378
where
373
379
filterOutKnownConstraints :: Set. Set Predicate -> [Predicate ] -> RewriteT io [Predicate ]
374
380
filterOutKnownConstraints priorKnowledge constraitns = do
0 commit comments