Repository navigation
Description
{-# OPTIONS -v tc.meta:45 #-}
open import Common.Prelude
open import Common.Product
open import Common.Equality
postulate
f : Bool → Bool
test : let
X : Bool → Bool → Bool
X = ?
Y : Bool
Y = ?
in ∀ b → Y ≡ f (X b (f (if true then true else b))) ×
(∀ a → X a (f b) ≡ f b)
test b = refl , λ a → reflCannot instantiate the metavariable _22 to solution f b since it
contains the variable b which is not in scope of the metavariable
or irrelevant in the metavariable but relevant in the solution
when checking that the expression refl has type (_22 ≡ f b)
Here, Agda complains although there is a solution
X a b = b
Y = f (f true)
Looking at the first constraint
Y = f (X b (f (if true then true else b)))
agda prunes both arguments of X since they have rigid occurrences of b.
However, the second occurrences goes away by normalization:
Y = f (X b (f true))
For efficiency reasons, see issue #415, Agda first does not normalize during
occurs check. Thus, the free variable check for the arg (if true then true
else b) returns b as rigid, which means we have a neutral term (f (...b...))
with a rigid occurrence of bad variable b, and we prune this argument of meta
X. This is unsound, since the free variable check only returns a superset of
the actual (semantic) variable dependencies.
The following code in Occurs.hs is faulty:
-- This could be optimized, by not computing the whole variable set
-- at once, but allow early failure
rigidVarsNotContainedIn :: Free a => a -> [Nat] -> Bool
rigidVarsNotContainedIn v xs =
not $ rigidVars (freeVars v) `VarSet.isSubsetOf` VarSet.fromList xsWhich makes its application wrong:
-- | @hasBadRigid xs v = Just True@ iff one of the rigid variables in @v@ is
not in @xs@.
-- Actually we can only prune if a bad variable is in the head. See issue 458.
-- Or in a non-eliminateable position (see succeed/PruningNonMillerPattern).
--
-- @hasBadRigid xs v = Nothing@ means that
-- we cannot prune at all as one of the meta args is matchable.
-- (See issue 1147.)
hasBadRigid :: [Nat] -> Term -> ExceptT () TCM Bool
hasBadRigid xs t = do
...
case ignoreSharing t of
-- The following types of arguments cannot be eliminated by a pattern
-- match: data, record, Pi, levels, sorts
-- Thus, their offending rigid variables are bad.
v@(Def f es) -> ifNotM (isNeutral tb f es) failure $ {- else -} do
return $ es `rigidVarsNotContainedIn` xs
-- Andreas, 2012-05-03: There is room for further improvement.
-- We could also consider a defined f which is not blocked by a meta.
Pi a b -> return $ (a,b) `rigidVarsNotContainedIn` xs
Level v -> return $ v `rigidVarsNotContainedIn` xs
Sort s -> return $ s `rigidVarsNotContainedIn` xs
...Original issue reported on code.google.com by [email protected] on 7 Dec 2014 at 11:57
Activity
Refactor: removed dead argument in foldRigid (re #1386).