forked from agda/agda
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NonLinMatch.hs
539 lines (481 loc) · 20.8 KB
/
NonLinMatch.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
{-# LANGUAGE CPP #-}
{-# LANGUAGE NondecreasingIndentation #-}
{-# LANGUAGE UndecidableInstances #-}
{- | Non-linear matching of the lhs of a rewrite rule against a
neutral term.
Given a lhs
Δ ⊢ lhs : B
and a candidate term
Γ ⊢ t : A
we seek a substitution Γ ⊢ σ : Δ such that
Γ ⊢ B[σ] = A and
Γ ⊢ lhs[σ] = t : A
-}
module Agda.TypeChecking.Rewriting.NonLinMatch where
import Prelude hiding (null, sequence)
import Control.Arrow (first, second)
import Control.Monad.State
import Debug.Trace
import System.IO.Unsafe
import Data.Maybe
import Data.Monoid
import Data.Traversable (Traversable,traverse)
import Data.IntMap (IntMap)
import qualified Data.IntMap as IntMap
import Data.IntSet (IntSet)
import qualified Data.IntSet as IntSet
import Data.Monoid
import qualified Data.Set as Set
import Data.Set (Set)
import Agda.Syntax.Common
import qualified Agda.Syntax.Common as C
import Agda.Syntax.Internal
import Agda.TypeChecking.Conversion.Pure
import Agda.TypeChecking.Datatypes
import Agda.TypeChecking.EtaContract
import Agda.TypeChecking.Free
import Agda.TypeChecking.Free.Reduce
import Agda.TypeChecking.Level
import Agda.TypeChecking.Monad
import Agda.TypeChecking.Monad.Builtin (HasBuiltins(..), getBuiltin', builtinLevel, primLevelSuc, primLevelMax)
import Agda.TypeChecking.Pretty
import Agda.TypeChecking.Records
import Agda.TypeChecking.Reduce
import Agda.TypeChecking.Reduce.Monad
import Agda.TypeChecking.Substitute
import Agda.TypeChecking.Telescope
import Agda.Utils.Either
import Agda.Utils.Except
import Agda.Utils.Functor
import Agda.Utils.Lens
import Agda.Utils.List
import Agda.Utils.Maybe
import Agda.Utils.Monad
import Agda.Utils.Null
import Agda.Utils.Permutation
import Agda.Utils.Singleton
import Agda.Utils.Size
#include "undefined.h"
import Agda.Utils.Impossible
-- | Turn a term into a non-linear pattern, treating the
-- free variables as pattern variables.
-- The first argument indicates the relevance we are working under: if this
-- is Irrelevant, then we construct a pattern that never fails to match.
-- The second argument is the number of bound variables (from pattern lambdas).
-- The third argument is the type of the term.
class PatternFrom t a b where
patternFrom :: Relevance -> Int -> t -> a -> TCM b
instance (PatternFrom t a b) => PatternFrom (Dom t) (Arg a) (Arg b) where
patternFrom r k t u = let r' = r `composeRelevance` getRelevance u
in traverse (patternFrom r' k $ unDom t) u
instance PatternFrom (Type, Term) Elims [Elim' NLPat] where
patternFrom r k (t,hd) = \case
[] -> return []
(Apply u : es) -> do
~(Pi a b) <- reduce $ unEl t
p <- patternFrom r k a u
t' <- t `piApplyM` u
let hd' = hd `apply` [ u ]
ps <- patternFrom r k (t',hd') es
return $ Apply p : ps
(IApply x y u : es) -> __IMPOSSIBLE__ -- TODO
(Proj o f : es) -> do
~(Just (El _ (Pi a b))) <- getDefType f =<< reduce t
let t' = b `absApp` hd
hd' <- applyDef o f (argFromDom a $> hd)
ps <- patternFrom r k (t',hd') es
return $ Proj o f : ps
instance (PatternFrom t a b) => PatternFrom t (Dom a) (Dom b) where
patternFrom r k t = traverse $ patternFrom r k t
instance PatternFrom () Type NLPType where
patternFrom r k _ a = NLPType <$> patternFrom r k () (getSort a)
<*> patternFrom r k (sort $ getSort a) (unEl a)
instance PatternFrom () Sort NLPat where
patternFrom r k _ s = do
s <- reduce s
let done = return PWild
case s of
Type l -> do
t <- levelType
patternFrom Irrelevant k t (Level l)
Prop l -> done --TODO
Inf -> done
SizeUniv -> done
PiSort _ _ -> __IMPOSSIBLE__
UnivSort _ -> __IMPOSSIBLE__
MetaS{} -> __IMPOSSIBLE__
DefS{} -> done
DummyS s -> do
reportSLn "impossible" 10 $ unlines
[ "patternFrom: hit dummy sort with content:"
, s
]
__IMPOSSIBLE__
instance PatternFrom Type Term NLPat where
patternFrom r k t v = do
t <- reduce t
etaRecord <- isEtaRecordType t
v <- unLevel =<< reduce v
reportSDoc "rewriting.build" 60 $ sep
[ "building a pattern from term v = " <+> prettyTCM v
, " of type " <+> prettyTCM t
]
let done = if isIrrelevant r then
return PWild
else
return $ PTerm v
case (unEl t , v) of
(Pi a b , _) -> do
let body = raise 1 v `apply` [ Arg (domInfo a) $ var 0 ]
p <- addContext a (patternFrom r (k+1) (absBody b) body)
return $ PLam (domInfo a) $ Abs (absName b) p
(_ , Var i es)
| i < k -> do
t <- typeOfBV i
PBoundVar i <$> patternFrom r k (t , var i) es
-- The arguments of `var i` should be distinct bound variables
-- in order to build a Miller pattern
| Just vs <- allApplyElims es -> do
TelV tel _ <- telView =<< typeOfBV i
unless (size tel >= size vs) __IMPOSSIBLE__
let ts = applySubst (parallelS $ reverse $ map unArg vs) $ map unDom $ flattenTel tel
mbvs <- forM (zip ts vs) $ \(t , v) -> do
isEtaVar (unArg v) t >>= \case
Just j | j < k -> return $ Just $ v $> j
_ -> return Nothing
case sequence mbvs of
Just bvs | fastDistinct bvs -> do
let allBoundVars = IntSet.fromList (downFrom k)
ok = not (isIrrelevant r) ||
IntSet.fromList (map unArg bvs) == allBoundVars
if ok then return (PVar i bvs) else done
_ -> done
| otherwise -> done
(_ , _ ) | Just (d, pars) <- etaRecord -> do
def <- theDef <$> getConstInfo d
(tel, c, ci, vs) <- etaExpandRecord_ d pars def v
caseMaybeM (getFullyAppliedConType c t) __IMPOSSIBLE__ $ \ (_ , ct) -> do
PDef (conName c) <$> patternFrom r k (ct , Con c ci []) (map Apply vs)
(_ , Lam i t) -> __IMPOSSIBLE__
(_ , Lit{}) -> done
(_ , Def f es) | isIrrelevant r -> done
(_ , Def f es) -> do
Def lsuc [] <- primLevelSuc
Def lmax [] <- primLevelMax
case es of
[x] | f == lsuc -> done
[x , y] | f == lmax -> done
_ -> do
ft <- defType <$> getConstInfo f
PDef f <$> patternFrom r k (ft , Def f []) es
(_ , Con c ci vs) | isIrrelevant r -> done
(_ , Con c ci vs) ->
caseMaybeM (getFullyAppliedConType c t) __IMPOSSIBLE__ $ \ (_ , ct) -> do
PDef (conName c) <$> patternFrom r k (ct , Con c ci []) vs
(_ , Pi a b) | isIrrelevant r -> done
(_ , Pi a b) -> do
pa <- patternFrom r k () a
pb <- addContext a (patternFrom r (k+1) () $ absBody b)
return $ PPi pa (Abs (absName b) pb)
(_ , Sort s) -> done
(_ , Level l) -> __IMPOSSIBLE__
(_ , DontCare{}) -> return PWild
(_ , MetaV{}) -> __IMPOSSIBLE__
(_ , Dummy s) -> __IMPOSSIBLE_VERBOSE__ s
-- | Monad for non-linear matching.
type NLM = ExceptT Blocked_ (StateT NLMState ReduceM)
data NLMState = NLMState
{ _nlmSub :: Sub
, _nlmEqs :: PostponedEquations
}
instance Null NLMState where
empty = NLMState { _nlmSub = empty , _nlmEqs = empty }
null s = null (s^.nlmSub) && null (s^.nlmEqs)
nlmSub :: Lens' Sub NLMState
nlmSub f s = f (_nlmSub s) <&> \x -> s {_nlmSub = x}
nlmEqs :: Lens' PostponedEquations NLMState
nlmEqs f s = f (_nlmEqs s) <&> \x -> s {_nlmEqs = x}
runNLM :: (MonadReduce m) => NLM () -> m (Either Blocked_ NLMState)
runNLM nlm = do
(ok,out) <- liftReduce $ runStateT (runExceptT nlm) empty
case ok of
Left block -> return $ Left block
Right _ -> return $ Right out
matchingBlocked :: Blocked_ -> NLM ()
matchingBlocked = throwError
-- | Add substitution @i |-> v : a@ to result of matching.
tellSub :: Relevance -> Int -> Type -> Term -> NLM ()
tellSub r i a v = do
old <- IntMap.lookup i <$> use nlmSub
case old of
Nothing -> nlmSub %= IntMap.insert i (r,v)
Just (r',v')
| isIrrelevant r -> return ()
| isIrrelevant r' -> nlmSub %= IntMap.insert i (r,v)
| otherwise -> whenJustM (equal a v v') matchingBlocked
tellEq :: Telescope -> Telescope -> Type -> Term -> Term -> NLM ()
tellEq gamma k a u v = do
traceSDoc "rewriting.match" 30 (sep
[ "adding equality between" <+> addContext (gamma `abstract` k) (prettyTCM u)
, " and " <+> addContext k (prettyTCM v) ]) $ do
nlmEqs %= (PostponedEquation k a u v:)
type Sub = IntMap (Relevance, Term)
-- | Matching against a term produces a constraint
-- which we have to verify after applying
-- the substitution computed by matching.
data PostponedEquation = PostponedEquation
{ eqFreeVars :: Telescope -- ^ Telescope of free variables in the equation
, eqType :: Type -- ^ Type of the equation, living in same context as the rhs.
, eqLhs :: Term -- ^ Term from pattern, living in pattern context.
, eqRhs :: Term -- ^ Term from scrutinee, living in context where matching was invoked.
}
type PostponedEquations = [PostponedEquation]
-- | Match a non-linear pattern against a neutral term,
-- returning a substitution.
class Match t a b where
match :: Relevance -- ^ Are we currently matching in an irrelevant context?
-> Telescope -- ^ The telescope of pattern variables
-> Telescope -- ^ The telescope of lambda-bound variables
-> t -- ^ The type of the pattern
-> a -- ^ The pattern to match
-> b -- ^ The term to be matched against the pattern
-> NLM ()
instance Match t a b => Match (Dom t) (Arg a) (Arg b) where
match r gamma k t p v = let r' = r `composeRelevance` getRelevance p
in match r' gamma k (unDom t) (unArg p) (unArg v)
instance Match (Type, Term) [Elim' NLPat] Elims where
match r gamma k (t, hd) [] [] = return ()
match r gamma k (t, hd) [] _ = matchingBlocked $ NotBlocked ReallyNotBlocked ()
match r gamma k (t, hd) _ [] = matchingBlocked $ NotBlocked ReallyNotBlocked ()
match r gamma k (t, hd) (p:ps) (v:vs) = case (p,v) of
(Apply p, Apply v) -> do
~(Pi a b) <- reduce $ unEl t
match r gamma k a p v
t' <- addContext k $ t `piApplyM` v
let hd' = hd `apply` [ v ]
match r gamma k (t',hd') ps vs
(Proj o f, Proj o' f') | f == f' -> do
~(Just (El _ (Pi a b))) <- getDefType f =<< reduce t
let t' = b `absApp` hd
hd' <- addContext k $ applyDef o f (argFromDom a $> hd)
match r gamma k (t',hd') ps vs
(Proj _ f, Proj _ f') | otherwise -> do
traceSDoc "rewriting.match" 20 (sep
[ "mismatch between projections " <+> prettyTCM f
, " and " <+> prettyTCM f' ]) mzero
(Apply{}, Proj{} ) -> __IMPOSSIBLE__
(Proj{} , Apply{}) -> __IMPOSSIBLE__
(IApply{} , _ ) -> __IMPOSSIBLE__ -- TODO
(_ , IApply{} ) -> __IMPOSSIBLE__ -- TODO
instance Match t a b => Match t (Dom a) (Dom b) where
match r gamma k t p v = match r gamma k t (C.unDom p) (C.unDom v)
instance Match () NLPType Type where
match r gamma k _ (NLPType lp p) (El s a) = do
match r gamma k () lp s
match r gamma k (sort s) p a
instance Match () NLPat Sort where
match r gamma k _ p s = case (p , s) of
(PWild , _ ) -> return ()
(p , Type l) -> match Irrelevant gamma k () p l
_ -> matchingBlocked $ NotBlocked ReallyNotBlocked ()
instance Match () NLPat Level where
match r gamma k _ p l = do
t <- El (mkType 0) . fromMaybe __IMPOSSIBLE__ <$> getBuiltin' builtinLevel
v <- reallyUnLevelView l
match r gamma k t p v
instance Match Type NLPat Term where
match r gamma k t p v = do
vbt <- addContext k $ reduceB (v,t)
etaRecord <- addContext k $ isEtaRecordType t
let n = size k
b = void vbt
(v,t) = ignoreBlocking vbt
prettyPat = withShowAllArguments $ addContext (gamma `abstract` k) (prettyTCM p)
prettyTerm = withShowAllArguments $ addContext k $ prettyTCM v
prettyType = withShowAllArguments $ addContext k $ prettyTCM t
traceSDoc "rewriting.match" 30 (sep
[ "matching pattern " <+> prettyPat
, " with term " <+> prettyTerm
, " of type " <+> prettyType ]) $ do
traceSDoc "rewriting.match" 80 (vcat
[ " raw pattern: " <+> text (show p)
, " raw term: " <+> text (show v)
, " raw type: " <+> text (show t) ]) $ do
traceSDoc "rewriting.match" 70 (vcat
[ "pattern vars: " <+> prettyTCM gamma
, "bound vars: " <+> prettyTCM k ]) $ do
let yes = return ()
no msg = do
traceSDoc "rewriting.match" 10 (sep
[ "mismatch between" <+> prettyPat
, " and " <+> prettyTerm
, " of type " <+> prettyType
, msg ]) $ do
traceSDoc "rewriting.match" 30 (sep
[ "blocking tag from reduction: " <+> text (show b) ]) $ do
matchingBlocked b
block b' = do
traceSDoc "rewriting.match" 10 (sep
[ "matching blocked on meta"
, text (show b') ]) $ do
traceSDoc "rewriting.match" 30 (sep
[ "blocking tag from reduction: " <+> text (show b') ]) $ do
matchingBlocked (b `mappend` b')
case p of
PWild -> yes
PVar i bvs -> traceSDoc "rewriting.match" 60 ("matching a PVar: " <+> text (show i)) $ do
let allowedVars :: IntSet
allowedVars = IntSet.fromList (map unArg bvs)
badVars :: IntSet
badVars = IntSet.difference (IntSet.fromList (downFrom n)) allowedVars
perm :: Permutation
perm = Perm n $ reverse $ map unArg $ bvs
tel :: Telescope
tel = permuteTel perm k
ok <- addContext k $ reallyFree badVars v
case ok of
Left b -> block b
Right Nothing -> no ""
Right (Just v) -> tellSub r (i-n) t $ teleLam tel $ renameP __IMPOSSIBLE__ perm v
_ | MetaV m es <- v -> matchingBlocked $ Blocked m ()
PDef f ps -> traceSDoc "rewriting.match" 60 ("matching a PDef: " <+> prettyTCM f) $ do
v <- addContext k $ constructorForm =<< unLevel v
case v of
Def f' es
| f == f' -> do
ft <- addContext k $ defType <$> getConstInfo f
match r gamma k (ft , Def f []) ps es
Con c ci vs
| f == conName c -> do
~(Just (_ , ct)) <- addContext k $ getFullyAppliedConType c t
match r gamma k (ct , Con c ci []) ps vs
_ | Pi a b <- unEl t -> do
let ai = domInfo a
pbody = PDef f $ raise 1 ps ++ [ Apply $ Arg ai $ PTerm $ var 0 ]
body = raise 1 v `apply` [ Arg (domInfo a) $ var 0 ]
k' = ExtendTel a (Abs (absName b) k)
match r gamma k' (absBody b) pbody body
_ | Just (d, pars) <- etaRecord -> do
-- If v is not of record constructor form but we are matching at record
-- type, e.g., we eta-expand both v to (c vs) and
-- the pattern (p = PDef f ps) to @c (p .f1) ... (p .fn)@.
def <- addContext k $ theDef <$> getConstInfo d
(tel, c, ci, vs) <- addContext k $ etaExpandRecord_ d pars def v
~(Just (_ , ct)) <- addContext k $ getFullyAppliedConType c t
let flds = recFields def
mkField fld = PDef f (ps ++ [Proj ProjSystem fld])
-- Issue #3335: when matching against the record constructor,
-- don't add projections but take record field directly.
ps'
| conName c == f = ps
| otherwise = map (Apply . fmap mkField) flds
match r gamma k (ct, Con c ci []) ps' (map Apply vs)
MetaV m es -> do
matchingBlocked $ Blocked m ()
_ -> no ""
PLam i p' -> case unEl t of
Pi a b -> do
let body = raise 1 v `apply` [Arg i (var 0)]
k' = ExtendTel a (Abs (absName b) k)
match r gamma k' (absBody b) (absBody p') body
_ -> no ""
PPi pa pb -> case v of
Pi a b -> do
match r gamma k () pa a
let k' = ExtendTel a (Abs (absName b) k)
match r gamma k' () (absBody pb) (absBody b)
_ -> no ""
PBoundVar i ps -> case v of
Var i' es | i == i' -> do
let ti = unDom $ indexWithDefault __IMPOSSIBLE__ (flattenTel k) i
match r gamma k (ti , var i) ps es
_ | Pi a b <- unEl t -> do
let ai = domInfo a
pbody = PBoundVar i $ raise 1 ps ++ [ Apply $ Arg ai $ PTerm $ var 0 ]
body = raise 1 v `apply` [ Arg ai $ var 0 ]
k' = ExtendTel a (Abs (absName b) k)
match r gamma k' (absBody b) pbody body
_ | Just (d, pars) <- etaRecord -> do
def <- addContext k $ theDef <$> getConstInfo d
(tel, c, ci, vs) <- addContext k $ etaExpandRecord_ d pars def v
~(Just (_ , ct)) <- addContext k $ getFullyAppliedConType c t
let flds = recFields def
ps' = map (fmap $ \fld -> PBoundVar i (ps ++ [Proj ProjSystem fld])) flds
match r gamma k (ct, Con c ci []) (map Apply ps') (map Apply vs)
_ -> no ""
PTerm u -> traceSDoc "rewriting.match" 60 ("matching a PTerm" <+> addContext (gamma `abstract` k) (prettyTCM u)) $
tellEq gamma k t u v
-- Checks if the given term contains any free variables that satisfy the
-- given condition on their DBI, possibly reducing the term in the process.
-- Returns `Right Nothing` if there are such variables, `Right (Just v')`
-- if there are none (where v' is the possibly reduced version of the given
-- term) or `Left b` if the problem is blocked on a meta.
reallyFree :: (MonadReduce m, Reduce a, ForceNotFree a)
=> IntSet -> a -> m (Either Blocked_ (Maybe a))
reallyFree xs v = do
(mxs , v') <- forceNotFree xs v
case IntMap.foldr pickFree NotFree mxs of
MaybeFree ms
| null ms -> return $ Right Nothing
| otherwise -> return $ Left $
Set.foldr (\m -> mappend $ Blocked m ()) (notBlocked ()) ms
NotFree -> return $ Right (Just v')
where
-- Check if any of the variables occur freely.
-- Prefer occurrences that do not depend on any metas.
pickFree :: IsFree -> IsFree -> IsFree
pickFree f1@(MaybeFree ms1) f2
| null ms1 = f1
pickFree f1@(MaybeFree ms1) f2@(MaybeFree ms2)
| null ms2 = f2
| otherwise = f1
pickFree f1@(MaybeFree ms1) NotFree = f1
pickFree NotFree f2 = f2
makeSubstitution :: Telescope -> Sub -> Substitution
makeSubstitution gamma sub =
prependS __IMPOSSIBLE__ (map val [0 .. size gamma-1]) IdS
where
val i = case IntMap.lookup i sub of
Just (Irrelevant, v) -> Just $ dontCare v
Just (_ , v) -> Just v
Nothing -> Nothing
checkPostponedEquations :: (MonadReduce m, MonadAddContext m, HasConstInfo m, HasBuiltins m, MonadDebug m)
=> Substitution -> PostponedEquations -> m (Maybe Blocked_)
checkPostponedEquations sub eqs = forM' eqs $
\ (PostponedEquation k a lhs rhs) -> do
let lhs' = applySubst (liftS (size k) sub) lhs
traceSDoc "rewriting.match" 30 (sep
[ "checking postponed equality between" , addContext k (prettyTCM lhs')
, " and " , addContext k (prettyTCM rhs) ]) $ do
addContext k $ equal a lhs' rhs
-- main function
nonLinMatch :: (MonadReduce m, MonadAddContext m, HasConstInfo m, HasBuiltins m, MonadDebug m, Match t a b)
=> Telescope -> t -> a -> b -> m (Either Blocked_ Substitution)
nonLinMatch gamma t p v = do
let no msg b = traceSDoc "rewriting.match" 10 (sep
[ "matching failed during" <+> text msg
, "blocking: " <+> text (show b) ]) $ return (Left b)
caseEitherM (runNLM $ match Relevant gamma EmptyTel t p v) (no "matching") $ \ s -> do
let sub = makeSubstitution gamma $ s^.nlmSub
eqs = s^.nlmEqs
traceSDoc "rewriting.match" 90 (text $ "sub = " ++ show sub) $ do
ok <- checkPostponedEquations sub eqs
case ok of
Nothing -> return $ Right sub
Just b -> no "checking of postponed equations" b
-- | Typed βη-equality, also handles empty record types.
-- Returns `Nothing` if the terms are equal, or `Just b` if the terms are not
-- (where b contains information about possible metas blocking the comparison)
equal :: (MonadReduce m, MonadAddContext m, HasConstInfo m, HasBuiltins m)
=> Type -> Term -> Term -> m (Maybe Blocked_)
equal a u v = pureEqualTerm a u v >>= \case
True -> return Nothing
False -> traceSDoc "rewriting.match" 10 (sep
[ "mismatch between " <+> prettyTCM u
, " and " <+> prettyTCM v
]) $ do
return $ Just block
where
block = caseMaybe (firstMeta (u, v))
(NotBlocked ReallyNotBlocked ())
(\m -> Blocked m ())