Skip to content

Commit fc13f75

Browse files
committed
Consider substitution as constraints in evaluatePattern
Include substitution in known truth when simplifying
1 parent e8661b4 commit fc13f75

File tree

3 files changed

+24
-105
lines changed

3 files changed

+24
-105
lines changed

booster/library/Booster/Pattern/ApplyEquations.hs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,21 +455,42 @@ evaluatePattern ::
455455
Pattern ->
456456
io (Either EquationFailure Pattern, SimplifierCache)
457457
evaluatePattern def mLlvmLibrary smtSolver cache pat =
458-
runEquationT def mLlvmLibrary smtSolver cache pat.constraints . evaluatePattern' $ pat
458+
runEquationT
459+
def
460+
mLlvmLibrary
461+
smtSolver
462+
cache
463+
-- interpret substitution as additional known constraints
464+
(pat.constraints <> (Set.fromList . asEquations $ pat.substitution))
465+
. evaluatePattern'
466+
$ pat
459467

460468
-- version for internal nested evaluation
461469
evaluatePattern' ::
462470
LoggerMIO io =>
463471
Pattern ->
464472
EquationT io Pattern
465-
evaluatePattern' pat@Pattern{term, ceilConditions, substitution} = withPatternContext pat $ do
473+
evaluatePattern' pat@Pattern{term, ceilConditions} = withPatternContext pat $ do
466474
newTerm <- withTermContext term $ evaluateTerm' BottomUp term `catch_` keepTopLevelResults
467475
-- after evaluating the term, evaluate all (existing and
468476
-- newly-acquired) constraints, once
469477
traverse_ simplifyAssumedPredicate . predicates =<< getState
470478
-- this may yield additional new constraints, left unevaluated
471479
evaluatedConstraints <- predicates <$> getState
472-
pure Pattern{constraints = evaluatedConstraints, term = newTerm, ceilConditions, substitution}
480+
-- The interface-level evaluatePattern puts pat.substitution together with pat.constraints
481+
-- into the simplifier state as known truth. Here the substitution will bubble-up as part of
482+
-- evaluatedConstraints. To avoid duplicating constraints (i.e. having equivalent entities
483+
-- in pat.predicate and pat.substitution), we discard the old substitution here
484+
-- and extract a possible simplified one from evaluatedConstraints.
485+
let (simplifiedSubsitution, simplifiedConstraints) = partitionPredicates (Set.toList evaluatedConstraints)
486+
487+
pure
488+
Pattern
489+
{ constraints = Set.fromList simplifiedConstraints
490+
, term = newTerm
491+
, ceilConditions
492+
, substitution = simplifiedSubsitution
493+
}
473494
where
474495
-- when TooManyIterations exception occurred while evaluating the top-level term,
475496
-- i.e. not in a recursive evaluation of a side-condition,

booster/test/rpc-integration/test-use-path-condition-in-equations/response-test1.json

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -126,57 +126,6 @@
126126
"value": "42"
127127
}
128128
}
129-
},
130-
"predicate": {
131-
"format": "KORE",
132-
"version": 1,
133-
"term": {
134-
"tag": "Equals",
135-
"argSort": {
136-
"tag": "SortApp",
137-
"name": "SortBool",
138-
"args": []
139-
},
140-
"sort": {
141-
"tag": "SortApp",
142-
"name": "SortGeneratedTopCell",
143-
"args": []
144-
},
145-
"first": {
146-
"tag": "DV",
147-
"sort": {
148-
"tag": "SortApp",
149-
"name": "SortBool",
150-
"args": []
151-
},
152-
"value": "true"
153-
},
154-
"second": {
155-
"tag": "App",
156-
"name": "Lbl'UndsEqlsEqls'Int'Unds'",
157-
"sorts": [],
158-
"args": [
159-
{
160-
"tag": "EVar",
161-
"name": "Var'Ques'X",
162-
"sort": {
163-
"tag": "SortApp",
164-
"name": "SortInt",
165-
"args": []
166-
}
167-
},
168-
{
169-
"tag": "DV",
170-
"sort": {
171-
"tag": "SortApp",
172-
"name": "SortInt",
173-
"args": []
174-
},
175-
"value": "42"
176-
}
177-
]
178-
}
179-
}
180129
}
181130
}
182131
}

booster/test/rpc-integration/test-use-path-condition-in-equations/response-test2.json

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -126,57 +126,6 @@
126126
"value": "42"
127127
}
128128
}
129-
},
130-
"predicate": {
131-
"format": "KORE",
132-
"version": 1,
133-
"term": {
134-
"tag": "Equals",
135-
"argSort": {
136-
"tag": "SortApp",
137-
"name": "SortBool",
138-
"args": []
139-
},
140-
"sort": {
141-
"tag": "SortApp",
142-
"name": "SortGeneratedTopCell",
143-
"args": []
144-
},
145-
"first": {
146-
"tag": "DV",
147-
"sort": {
148-
"tag": "SortApp",
149-
"name": "SortBool",
150-
"args": []
151-
},
152-
"value": "true"
153-
},
154-
"second": {
155-
"tag": "App",
156-
"name": "Lbl'UndsEqlsEqls'Int'Unds'",
157-
"sorts": [],
158-
"args": [
159-
{
160-
"tag": "EVar",
161-
"name": "Var'Ques'X",
162-
"sort": {
163-
"tag": "SortApp",
164-
"name": "SortInt",
165-
"args": []
166-
}
167-
},
168-
{
169-
"tag": "DV",
170-
"sort": {
171-
"tag": "SortApp",
172-
"name": "SortInt",
173-
"args": []
174-
},
175-
"value": "42"
176-
}
177-
]
178-
}
179-
}
180129
}
181130
}
182131
}

0 commit comments

Comments
 (0)