Safe Haskell | None |
---|---|
Language | Haskell98 |
Agda.Termination.Monad
Contents
Description
The monad for the termination checker.
The termination monad TerM
is an extension of
the type checking monad TCM
by an environment
with information needed by the termination checker.
- type MutualNames = [QName]
- type Target = QName
- type Guarded = Order
- data TerEnv = TerEnv {
- terUseDotPatterns :: Bool
- terGuardingTypeConstructors :: Bool
- terInlineWithFunctions :: Bool
- terSizeSuc :: Maybe QName
- terSharp :: Maybe QName
- terCutOff :: CutOff
- terCurrent :: QName
- terMutual :: MutualNames
- terUserNames :: [QName]
- terTarget :: Maybe Target
- terDelayed :: Delayed
- terMaskArgs :: [Bool]
- terMaskResult :: Bool
- _terSizeDepth :: Int
- terPatterns :: MaskedDeBruijnPats
- terPatternsRaise :: !Int
- terGuarded :: !Guarded
- terUseSizeLt :: Bool
- terUsableVars :: VarSet
- defaultTerEnv :: TerEnv
- class (Functor m, Monad m) => MonadTer m where
- newtype TerM a = TerM {}
- runTer :: TerEnv -> TerM a -> TCM a
- runTerDefault :: TerM a -> TCM a
- terGetGuardingTypeConstructors :: TerM Bool
- terGetInlineWithFunctions :: TerM Bool
- terGetUseDotPatterns :: TerM Bool
- terSetUseDotPatterns :: Bool -> TerM a -> TerM a
- terGetSizeSuc :: TerM (Maybe QName)
- terGetCurrent :: TerM QName
- terSetCurrent :: QName -> TerM a -> TerM a
- terGetSharp :: TerM (Maybe QName)
- terGetCutOff :: TerM CutOff
- terGetMutual :: TerM MutualNames
- terGetUserNames :: TerM [QName]
- terGetTarget :: TerM (Maybe Target)
- terSetTarget :: Maybe Target -> TerM a -> TerM a
- terGetDelayed :: TerM Delayed
- terSetDelayed :: Delayed -> TerM a -> TerM a
- terGetMaskArgs :: TerM [Bool]
- terSetMaskArgs :: [Bool] -> TerM a -> TerM a
- terGetMaskResult :: TerM Bool
- terSetMaskResult :: Bool -> TerM a -> TerM a
- terGetPatterns :: TerM MaskedDeBruijnPats
- terSetPatterns :: MaskedDeBruijnPats -> TerM a -> TerM a
- terRaise :: TerM a -> TerM a
- terGetGuarded :: TerM Guarded
- terModifyGuarded :: (Order -> Order) -> TerM a -> TerM a
- terSetGuarded :: Order -> TerM a -> TerM a
- terUnguarded :: TerM a -> TerM a
- terPiGuarded :: TerM a -> TerM a
- terSizeDepth :: Lens' Int TerEnv
- terGetUsableVars :: TerM VarSet
- terModifyUsableVars :: (VarSet -> VarSet) -> TerM a -> TerM a
- terSetUsableVars :: VarSet -> TerM a -> TerM a
- terGetUseSizeLt :: TerM Bool
- terModifyUseSizeLt :: (Bool -> Bool) -> TerM a -> TerM a
- terSetUseSizeLt :: Bool -> TerM a -> TerM a
- withUsableVars :: UsableSizeVars a => a -> TerM b -> TerM b
- conUseSizeLt :: QName -> TerM a -> TerM a
- projUseSizeLt :: QName -> TerM a -> TerM a
- isProjectionButNotCoinductive :: MonadTCM tcm => QName -> tcm Bool
- isCoinductiveProjection :: MonadTCM tcm => Bool -> QName -> tcm Bool
- type DeBruijnPats = [DeBruijnPat]
- type DeBruijnPat = DeBruijnPat' Int
- data DeBruijnPat' a
- patternDepth :: DeBruijnPat' a -> Int
- unusedVar :: DeBruijnPat
- raiseDBP :: Int -> DeBruijnPats -> DeBruijnPats
- class UsableSizeVars a where
- usableSizeVars :: a -> TerM VarSet
- type MaskedDeBruijnPats = [Masked DeBruijnPat]
- data Masked a = Masked {}
- masked :: a -> Masked a
- notMasked :: a -> Masked a
- newtype CallPath = CallPath {}
- terSetSizeDepth :: Telescope -> TerM a -> TerM a
Documentation
type MutualNames = [QName]
The mutual block we are checking.
The functions are numbered according to their order of appearance in this list.
data TerEnv
The termination environment.
Constructors
TerEnv | |
Fields
|
An empty termination environment.
Values are set to a safe default meaning that with these initial values the termination checker will not miss termination errors it would have seen with better settings of these values.
Values that do not have a safe default are set to
IMPOSSIBLE
.
class (Functor m, Monad m) => MonadTer m where
Termination monad service class.
newtype TerM a
Termination monad.
runTerDefault :: TerM a -> TCM a
Run TerM computation in default environment (created from options).
Termination monad is a MonadTCM
.
Modifiers and accessors for the termination environment in the monad.
terSetUseDotPatterns :: Bool -> TerM a -> TerM a
terGetSizeSuc :: TerM (Maybe QName)
terSetCurrent :: QName -> TerM a -> TerM a
terGetSharp :: TerM (Maybe QName)
terGetUserNames :: TerM [QName]
terGetTarget :: TerM (Maybe Target)
terSetTarget :: Maybe Target -> TerM a -> TerM a
terSetDelayed :: Delayed -> TerM a -> TerM a
terGetMaskArgs :: TerM [Bool]
terSetMaskArgs :: [Bool] -> TerM a -> TerM a
terSetMaskResult :: Bool -> TerM a -> TerM a
terSetPatterns :: MaskedDeBruijnPats -> TerM a -> TerM a
terModifyGuarded :: (Order -> Order) -> TerM a -> TerM a
terSetGuarded :: Order -> TerM a -> TerM a
terUnguarded :: TerM a -> TerM a
terPiGuarded :: TerM a -> TerM a
Should the codomain part of a function type preserve guardedness?
terSizeDepth :: Lens' Int TerEnv
Lens for _terSizeDepth
.
terGetUsableVars :: TerM VarSet
Lens for terUsableVars
.
terModifyUsableVars :: (VarSet -> VarSet) -> TerM a -> TerM a
terSetUsableVars :: VarSet -> TerM a -> TerM a
Lens for terUseSizeLt
.
terModifyUseSizeLt :: (Bool -> Bool) -> TerM a -> TerM a
terSetUseSizeLt :: Bool -> TerM a -> TerM a
withUsableVars :: UsableSizeVars a => a -> TerM b -> TerM b
Compute usable vars from patterns and run subcomputation.
conUseSizeLt :: QName -> TerM a -> TerM a
Set terUseSizeLt
when going under constructor c
.
projUseSizeLt :: QName -> TerM a -> TerM a
Set terUseSizeLt
for arguments following projection q
.
We disregard j<i after a non-coinductive projection.
However, the projection need not be recursive (Issue 1470).
isProjectionButNotCoinductive :: MonadTCM tcm => QName -> tcm Bool
For termination checking purposes flat should not be considered a projection. That is, it flat doesn't preserve either structural order or guardedness like other projections do. Andreas, 2012-06-09: the same applies to projections of recursive records.
isCoinductiveProjection :: MonadTCM tcm => Bool -> QName -> tcm Bool
Check whether a projection belongs to a coinductive record and is actually recursive. E.g. @ isCoinductiveProjection (Stream.head) = return False
isCoinductiveProjection (Stream.tail) = return True @
De Bruijn patterns.
type DeBruijnPats = [DeBruijnPat]
type DeBruijnPat = DeBruijnPat' Int
Patterns with variables as de Bruijn indices.
data DeBruijnPat' a
Constructors
VarDBP a | De Bruijn Index. |
ConDBP QName [DeBruijnPat' a] | The name refers to either an ordinary constructor or the successor function on sized types. |
LitDBP Literal | Literal. Also abused to censor part of a pattern. |
TermDBP Term | Part of dot pattern that cannot be converted into a pattern. |
ProjDBP QName | Projection pattern. |
patternDepth :: DeBruijnPat' a -> Int
How long is the path to the deepest variable?
A dummy pattern used to mask a pattern that cannot be used for structural descent.
raiseDBP :: Int -> DeBruijnPats -> DeBruijnPats
raiseDBP n ps
increases each de Bruijn index in ps
by n
.
Needed when going under a binder during analysis of a term.
class UsableSizeVars a where
Extract variables from DeBruijnPat
s that could witness a decrease
via a SIZELT constraint.
These variables must be under an inductive constructor (with no record constructor in the way), or after a coinductive projection (with no inductive one in the way).
Methods
usableSizeVars :: a -> TerM VarSet
Masked patterns (which are not eligible for structural descent, only for size descent)
type MaskedDeBruijnPats = [Masked DeBruijnPat]
data Masked a
Constructors
Masked | |
Instances
Functor Masked | |
Foldable Masked | |
Traversable Masked | |
Decoration Masked | |
UsableSizeVars MaskedDeBruijnPats | |
Eq a => Eq (Masked a) | |
Ord a => Ord (Masked a) | |
Show a => Show (Masked a) | |
PrettyTCM a => PrettyTCM (Masked a) | Print masked things in double parentheses. |
UsableSizeVars (Masked DeBruijnPat) |
Call pathes
newtype CallPath
The call information is stored as free monoid
over CallInfo
. As long as we never look at it,
only accumulate it, it does not matter whether we use
Set
, (nub) list, or Tree
.
Internally, due to lazyness, it is anyway a binary tree of
mappend
nodes and singleton leafs.
Since we define no order on CallInfo
(expensive),
we cannot use a Set
or nub list.
Performance-wise, I could not see a difference between Set and list.
Size depth estimation
terSetSizeDepth :: Telescope -> TerM a -> TerM a
A very crude way of estimating the SIZELT
chains
i > j > k
in context. Returns 3 in this case.
Overapproximates.