Skip to content

Commit 78659ee

Browse files
committed
Do not simplify substitution when normalising it
1 parent 58370f8 commit 78659ee

File tree

1 file changed

+5
-27
lines changed

1 file changed

+5
-27
lines changed

booster/library/Booster/Pattern/Rewrite.hs

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import Data.List (intersperse, partition)
3737
import Data.List.NonEmpty (NonEmpty (..), toList)
3838
import Data.List.NonEmpty qualified as NE
3939
import Data.Map qualified as Map
40-
import Data.Maybe (catMaybes, fromMaybe, mapMaybe)
40+
import Data.Maybe (catMaybes, fromMaybe)
4141
import Data.Sequence (Seq, (|>))
4242
import Data.Set qualified as Set
4343
import Data.Text as Text (Text, pack)
@@ -50,11 +50,9 @@ import Booster.LLVM as LLVM (API)
5050
import Booster.Log
5151
import Booster.Pattern.ApplyEquations (
5252
CacheTag (Equations),
53-
Direction (..),
5453
EquationFailure (..),
5554
SimplifierCache (..),
5655
evaluatePattern,
57-
evaluateTerm,
5856
simplifyConstraint,
5957
)
6058
import Booster.Pattern.Base
@@ -371,7 +369,6 @@ applyRule pat@Pattern{ceilConditions} rule =
371369
normalisedPatternSubst <-
372370
lift $
373371
normaliseSubstitution
374-
pat.constraints
375372
pat.substitution
376373
newSubsitution
377374
-- NOTE it is necessary to first apply the rule substitution and then the pattern/ensures substitution, but it is suboptimal to traverse the term twice.
@@ -395,31 +392,12 @@ applyRule pat@Pattern{ceilConditions} rule =
395392
where
396393
-- Given known predicates, a known substitution and a newly acquired substitution (from the ensures clause):
397394
-- - apply the new substitution to the old substitution
398-
-- - simplify the substituted old substitution, assuming known truth
399-
-- - TODO check for loops?
400-
-- - TODO filter out possible trivial items?
401-
-- - finally, merge with the new substitution items and return
395+
-- - merge with the new substitution items and return
402396
normaliseSubstitution ::
403-
Set.Set Predicate -> Substitution -> Substitution -> RewriteT io Substitution
404-
normaliseSubstitution knownTruth oldSubst newSubst = do
405-
RewriteConfig{definition, llvmApi, smtSolver} <- RewriteT ask
397+
Substitution -> Substitution -> RewriteT io Substitution
398+
normaliseSubstitution oldSubst newSubst = do
406399
let substitutedOldSubst = Map.map (substituteInTerm newSubst) oldSubst
407-
simplifiedSubstitution <-
408-
processResults
409-
<$> traverse
410-
(fmap fst . evaluateTerm BottomUp definition llvmApi smtSolver knownTruth)
411-
substitutedOldSubst
412-
pure (newSubst `Map.union` simplifiedSubstitution) -- new bindings take priority
413-
where
414-
processResults =
415-
Map.fromList
416-
. mapMaybe
417-
( \case
418-
(var, Left _err) -> (var,) <$> Map.lookup var oldSubst
419-
(var, Right simplified) -> Just (var, simplified)
420-
)
421-
. Map.assocs
422-
400+
pure (newSubst `Map.union` substitutedOldSubst) -- new bindings take priority
423401
filterOutKnownConstraints :: Set.Set Predicate -> [Predicate] -> RewriteT io [Predicate]
424402
filterOutKnownConstraints priorKnowledge constraitns = do
425403
let (knownTrue, toCheck) = partition (`Set.member` priorKnowledge) constraitns

0 commit comments

Comments
 (0)