@@ -41,6 +41,9 @@ import qualified Data.Foldable as Foldable
4141import Data.List.NonEmpty
4242 ( NonEmpty (.. )
4343 )
44+ import Data.Map.Strict
45+ ( Map
46+ )
4447import qualified Data.Map.Strict as Map
4548import Data.Set
4649 ( Set
@@ -154,7 +157,7 @@ attemptEquation
154157 . HasCallStack
155158 => MonadSimplify simplifier
156159 => InternalVariable variable
157- => SideCondition ( Target variable )
160+ => SideCondition variable
158161 -> TermLike (Target variable )
159162 -> Equation variable
160163 -> simplifier (AttemptEquationResult variable )
@@ -168,11 +171,25 @@ attemptEquation sideCondition termLike equation =
168171 applyMatchResult equationRenamed matchResult
169172 & whileApplyMatchResult
170173 Just argument' -> do
174+ (matchPredicate, matchSubstitution) <-
175+ match left termLike
176+ & whileMatch
171177 matchResults <-
172- whileMatch
173- $ match left termLike
174- >>= simplifyArgumentWithResult argument' antiLeft
175- applyAndSelectMatchResult matchResults
178+ applySubstitutionAndSimplify
179+ argument'
180+ antiLeft
181+ matchSubstitution
182+ & whileMatch
183+ (equation', predicate) <-
184+ applyAndSelectMatchResult matchResults
185+ let matchPredicate' =
186+ Predicate. mapVariables
187+ (pure Target. unTarget)
188+ matchPredicate
189+ return
190+ ( equation'
191+ , makeAndPredicate predicate matchPredicate'
192+ )
176193 let Equation { requires } = equation'
177194 checkRequires sideCondition predicate requires & whileCheckRequires
178195 let Equation { right, ensures } = equation'
@@ -210,26 +227,26 @@ attemptEquation sideCondition termLike equation =
210227 debugAttemptEquationResult equation result
211228 return result
212229
213- simplifyArgumentWithResult
230+ applySubstitutionAndSimplify
214231 :: HasCallStack
215232 => Predicate (Target variable )
216233 -> Maybe (Predicate (Target variable ))
217- -> MatchResult ( Target variable )
234+ -> Map ( SomeVariableName ( Target variable )) ( TermLike ( Target variable ) )
218235 -> ExceptT
219236 (MatchError (Target variable ))
220237 simplifier
221238 [MatchResult (Target variable )]
222- simplifyArgumentWithResult
239+ applySubstitutionAndSimplify
223240 argument
224241 antiLeft
225- (matchPredicate, matchSubstitution)
242+ matchSubstitution
226243 =
227244 lift $ do
228245 let toMatchResult Conditional { predicate, substitution } =
229246 (predicate, Substitution. toMap substitution)
230247 Substitution. mergePredicatesAndSubstitutions
231- sideCondition
232- ([ argument, matchPredicate] <> maybeToList antiLeft)
248+ SideCondition. top
249+ (argument : maybeToList antiLeft)
233250 [from @ _ @ (Substitution _ ) matchSubstitution]
234251 & Logic. observeAllT
235252 & (fmap . fmap ) toMatchResult
@@ -333,7 +350,7 @@ checkRequires
333350 :: forall simplifier variable
334351 . MonadSimplify simplifier
335352 => InternalVariable variable
336- => SideCondition ( Target variable )
353+ => SideCondition variable
337354 -> Predicate variable -- ^ requires from matching
338355 -> Predicate variable -- ^ requires from 'Equation'
339356 -> ExceptT (CheckRequiresError variable ) simplifier ()
@@ -357,13 +374,7 @@ checkRequires sideCondition predicate requires =
357374 -- and the rule will not be applied.
358375 & (OrCondition. observeAllT >=> assertBottom)
359376 where
360- simplifyCondition = Simplifier. simplifyCondition sideCondition'
361-
362- -- TODO (thomas.tuegel): Do not unwrap sideCondition.
363- sideCondition' =
364- SideCondition. mapVariables
365- (pure Target. unTarget)
366- sideCondition
377+ simplifyCondition = Simplifier. simplifyCondition sideCondition
367378
368379 assertBottom orCondition
369380 | isBottom orCondition = done
@@ -376,7 +387,7 @@ checkRequires sideCondition predicate requires =
376387 }
377388
378389 -- Pair a configuration with sideCondition for evaluation by the solver.
379- withSideCondition = (,) sideCondition'
390+ withSideCondition = (,) sideCondition
380391
381392 withoutAxioms =
382393 fmap Condition. forgetSimplified
@@ -392,7 +403,7 @@ The variables are marked 'Target' and renamed to avoid any variables in the
392403targetEquationVariables
393404 :: forall variable
394405 . InternalVariable variable
395- => SideCondition ( Target variable )
406+ => SideCondition variable
396407 -> TermLike (Target variable )
397408 -> Equation variable
398409 -> Equation (Target variable )
@@ -401,7 +412,11 @@ targetEquationVariables sideCondition initial =
401412 . Equation. refreshVariables avoiding
402413 . Equation. mapVariables Target. mkUnifiedTarget
403414 where
404- avoiding = freeVariables sideCondition <> freeVariables initial
415+ avoiding = sideConditionVariables <> freeVariables initial
416+ sideConditionVariables =
417+ FreeVariables. mapFreeVariables
418+ Target. mkUnifiedNonTarget
419+ $ freeVariables sideCondition
405420
406421-- * Errors
407422
0 commit comments