| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
Rzk.TypeCheck.Context
Description
The typing context on free-foil.
The successor of Rzk.TypeCheck's Context var. Two things change, and they
are the point of the migration.
- A variable is a name, and so is a top-level entry.
- A free-foil term refers to
a variable by
Name(anInt), and by nothing else: there is no way to put aVarIdentinside a term. So a top-level definition is a name too, bound in the outermost scope with no binder above it, and the hypotheses — global and local alike — are oneNameMap, looked up in constant time. The old context was an association list keyed by avarwhose equality walked anS-chain;lookupVarInfoalone was 11.5% of the checker's time. The surface name of an entry is resolved throughctxNamed.
This also gives sections their natural shape. A #assumed assumption is an
ordinary binder, so the definitions of a section are checked in its scope, and
closing the section abstracts the assumption by pairing its binder with the
body — no rewrite of the elaborated terms (see Rzk.TypeCheck.Decl).
- Entering a binder rebuilds nothing.
enterBinderextends the scope and sinks the rest of the context by coercion, so it costs O(1) rather than a walk of the context. The oldenterScopeContextmappedS <$>over the whole context, rebuilding every elaborated term it held; the heap profile showed those forced copies retaining most of the live heap, andGlobalScopeInfo/globalEmbed(PR #277) exist only to keep that shift off the ~1500 top-level entries. All of that machinery is gone.
Synopsis
- data Covariance
- data RenderBackend
- data Verbosity
- data LocationInfo = LocationInfo {}
- atPosition :: RzkPosition -> LocationInfo -> LocationInfo
- data VarInfo (n :: S) = VarInfo {
- varType :: TermT n
- varValue :: Maybe (TermT n)
- varModality :: TModality
- varModAccum :: TModality
- varOrig :: Binder
- varIsAssumption :: Bool
- varIsTopLevel :: Bool
- varDeclaredAssumptions :: [Name n]
- varLocation :: Maybe LocationInfo
- varDataRole :: Maybe (DataRole n)
- varMetaPrefix :: Int
- data DataRole (n :: S) = DataRole {}
- data DataRoleKind
- data ConSort
- data ElimKind
- bumpDataRoleParams :: forall (n :: S). DataRole n -> DataRole n
- data ModalTope (n :: S) = ModalTope {}
- data Action (n :: S)
- = ActionTypeCheck (Term n) (TermT n)
- | ActionUnify (TermT n) (TermT n) (TermT n)
- | ActionUnifyTerms (TermT n) (TermT n)
- | ActionInfer (Term n)
- | ActionContextEntailedBy [TermT n] (TermT n)
- | ActionContextEntails [TermT n] (TermT n)
- | ActionContextEntailsUnion [TermT n] [TermT n]
- | ActionWHNF (TermT n)
- | ActionNF (TermT n)
- | ActionCheckCoherence (TermT n, TermT n) (TermT n, TermT n)
- | ActionCloseSection (Maybe SectionName)
- | ActionCheckLetValue (Maybe VarIdent)
- data CachedSaturation (n :: S)
- = SaturationUncached
- | SaturationCached (Maybe [[ModalTope n]])
- data Context (n :: S) = Context {
- ctxScope :: Scope n
- ctxVars :: NameMap n (VarInfo n)
- ctxNamed :: Map VarIdent (Name n)
- ctxBound :: [Name n]
- ctxSections :: [SectionInfo n]
- ctxDiscreteTopes :: [ModalTope n]
- ctxTopes :: [ModalTope n]
- ctxTopesNF :: [ModalTope n]
- ctxTopesNFUnion :: [[ModalTope n]]
- ctxTopesEntailBottom :: Maybe Bool
- ctxTopesSaturated :: CachedSaturation n
- ctxShadow :: Map VarIdent [VarIdent]
- ctxActionStack :: [Action n]
- ctxActionStackDepth :: Int
- ctxCurrentCommand :: Maybe Command
- ctxLocation :: Maybe LocationInfo
- ctxVerbosity :: Verbosity
- ctxCovariance :: Covariance
- ctxRenderBackend :: Maybe RenderBackend
- ctxRenderHideTerm :: Bool
- ctxHolesAreErrors :: Bool
- ctxDeferHoleMismatches :: Bool
- ctxHintLemmas :: [VarIdent]
- ctxWarnOverhang :: Bool
- ctxMetaPrefixSensitivity :: MetaPrefixSensitivity
- data MetaPrefixSensitivity
- data SectionInfo (n :: S) = SectionInfo {
- sectionName :: Maybe SectionName
- sectionEntries :: [Name n]
- emptyContext :: Context 'VoidS
- emptyTopeContext :: forall (n :: S). [ModalTope n]
- sinkContextUnchecked :: forall (n :: S) (l :: S). DExt n l => Context n -> Context l
- enterBinder :: forall (n :: S) (l :: S). DExt n l => NameBinder n l -> VarInfo n -> [ModalTope l] -> Context n -> Context l
- withFreshBinder :: forall (n :: S) r. Distinct n => Context n -> VarInfo n -> (forall (l :: S). DExt n l => NameBinder n l -> Context l -> r) -> r
- addBinderNames :: Binder -> Map VarIdent [VarIdent] -> Map VarIdent [VarIdent]
- shadowedBy :: forall (n :: S). VarIdent -> Context n -> [VarIdent]
- sinkVars :: forall (n :: S) (l :: S). DExt n l => NameMap n (VarInfo n) -> NameMap n (VarInfo l)
- sinkTopes :: forall (n :: S) (l :: S). DExt n l => [ModalTope n] -> [ModalTope l]
- sinkNamed :: forall (n :: S) (l :: S). DExt n l => Map VarIdent (Name n) -> Map VarIdent (Name l)
- sinkNames :: forall (n :: S) (l :: S). DExt n l => [Name n] -> [Name l]
- lookupVarInfo :: forall (n :: S). Name n -> Context n -> VarInfo n
- varInfos :: forall (n :: S). Context n -> [VarInfo n]
- varsInScope :: forall (n :: S). Context n -> [(Name n, VarInfo n)]
- lookupNamed :: forall (n :: S). VarIdent -> Context n -> Maybe (Name n)
- binderOfName :: forall (n :: S). Name n -> Context n -> Binder
- class ModeTheory m where
- applyModality :: forall (n :: S). TModality -> Context n -> Context n
- mapNameMap :: forall a b (n :: S). (a -> b) -> NameMap n a -> NameMap n b
- insertVarInfo :: forall (n :: S). Name n -> VarInfo n -> Context n -> Context n
- isAccessible :: forall (n :: S). ModalTope n -> Bool
- filterAccessible :: forall (n :: S). [ModalTope n] -> [ModalTope n]
- accessibleTopes :: forall (n :: S). [ModalTope n] -> [TermT n]
- plainTope :: forall (n :: S). TermT n -> ModalTope n
- availableTopes :: forall (n :: S). Context n -> [TermT n]
- availableTopesNF :: forall (n :: S). Context n -> [TermT n]
- allowHoles :: forall (n :: S). Context n -> Context n
- withHintLemmas :: forall (n :: S). [VarIdent] -> Context n -> Context n
- structuralHoleUnify :: forall (n :: S). Context n -> Context n
The pieces of a context
data Covariance Source #
Constructors
| Covariant | Positive position. |
| Contravariant | Negative position. |
| Invariant | Unknown position. |
data RenderBackend Source #
Constructors
| RenderSVG | |
| RenderLaTeX |
Instances
| Eq Verbosity Source # | |
| Ord Verbosity Source # | |
data LocationInfo Source #
Where a diagnostic points.
The line and column are the start of whatever the diagnostic is about: the
declaration being checked, narrowed to the sub-term as the checker descends
into it (see narrowLocation in Rzk.TypeCheck.Monad). The surface syntax
records the start of a node and not its extent, so there is no end position
to carry.
Constructors
| LocationInfo | |
Fields | |
Instances
| Show LocationInfo Source # | |
Defined in Rzk.TypeCheck.Context Methods showsPrec :: Int -> LocationInfo -> ShowS # show :: LocationInfo -> String # showList :: [LocationInfo] -> ShowS # | |
| Eq LocationInfo Source # | |
Defined in Rzk.TypeCheck.Context | |
atPosition :: RzkPosition -> LocationInfo -> LocationInfo Source #
Point a location at a position in the same file.
data VarInfo (n :: S) Source #
What is known about a hypothesis, local or top-level.
Constructors
| VarInfo | |
Fields
| |
data DataRole (n :: S) Source #
The role a top-level entry plays for a #data declaration. The ι-rule
(in Eval) recognises an eliminator head and a
constructor-headed scrutinee by these; both entries are otherwise opaque
(they carry no value).
The argument counts speak of the entry's elaborated type: a constructor
takes the datatype's parameters and then its own fields; an eliminator
takes the parameters, the motive, one method per constructor (in
declaration order), and the scrutinee. Closing a section prepends the
section's assumptions uniformly to all entries of a declaration, so
abstractOver bumps the parameter counts.
Constructors
| DataRole | |
Fields
| |
data DataRoleKind Source #
Constructors
| DataConKind ConSort Int Int [Int] | a constructor: its sort, its 0-based position among the constructors (= the method index), the number of its own fields after the parameters, and the 0-based positions of its recursive fields (each contributes an induction hypothesis right after the field in the method) |
| DataElimKind Int Int ElimKind | an eliminator: the number of methods (one per constructor, in declaration order) and the number of indices of the family; the spine is parameters, motive, methods, indices, scrutinee |
A point constructor inhabits the datatype and the ι-rule dispatches on
it as a scrutinee head. A path constructor inhabits an identity type over
the datatype, so it can never head a well-typed scrutinee, and the ι-rule
must not fire on it: its computation rule is the propositional
compute- lemma generated alongside the eliminators.
Which eliminator; the ι-rule is the same for both.
bumpDataRoleParams :: forall (n :: S). DataRole n -> DataRole n Source #
Add one leading parameter (a section assumption made explicit).
The judgement being performed, for tracing and for the error report.
Constructors
| ActionTypeCheck (Term n) (TermT n) | |
| ActionUnify (TermT n) (TermT n) (TermT n) | |
| ActionUnifyTerms (TermT n) (TermT n) | |
| ActionInfer (Term n) | |
| ActionContextEntailedBy [TermT n] (TermT n) | |
| ActionContextEntails [TermT n] (TermT n) | |
| ActionContextEntailsUnion [TermT n] [TermT n] | |
| ActionWHNF (TermT n) | |
| ActionNF (TermT n) | |
| ActionCheckCoherence (TermT n, TermT n) (TermT n, TermT n) | |
| ActionCloseSection (Maybe SectionName) | |
| ActionCheckLetValue (Maybe VarIdent) |
data CachedSaturation (n :: S) Source #
The state of the tope-saturation cache in a Context
(see ctxTopesSaturated).
Constructors
| SaturationUncached | No cache was installed for this tope context (entailment falls back to the per-query pipeline). |
| SaturationCached (Maybe [[ModalTope n]]) | A deferred pipeline run: forced by the first query under this context.
|
The context
data Context (n :: S) Source #
Constructors
| Context | |
Fields
| |
data MetaPrefixSensitivity Source #
The sensitivity levels of the meta-parameter layer check.
Constructors
| MetaPrefixOff | no meta-prefix warnings |
| MetaPrefixStructural | warn only at structurally object-level positions |
| MetaPrefixStrict | additionally require an unsaturated schema argument to sit within a top-level receiver's meta prefix (the default) |
Instances
| Show MetaPrefixSensitivity Source # | |
Defined in Rzk.TypeCheck.Context Methods showsPrec :: Int -> MetaPrefixSensitivity -> ShowS # show :: MetaPrefixSensitivity -> String # showList :: [MetaPrefixSensitivity] -> ShowS # | |
| Eq MetaPrefixSensitivity Source # | |
Defined in Rzk.TypeCheck.Context Methods (==) :: MetaPrefixSensitivity -> MetaPrefixSensitivity -> Bool # (/=) :: MetaPrefixSensitivity -> MetaPrefixSensitivity -> Bool # | |
data SectionInfo (n :: S) Source #
An open section: the entries declared in it, newest first.
Constructors
| SectionInfo | |
Fields
| |
emptyContext :: Context 'VoidS Source #
emptyTopeContext :: forall (n :: S). [ModalTope n] Source #
The tope context of an empty context: ⊤ holds under every modality.
Entering a binder
Everything in a context that mentions the scope is a term, or a container of
terms, and so is sinkable: a term whose free names lie in n has its free
names in any l that extends n. free-foil sinks such a value by coercion
(sink = unsafeCoerce, sound because DExt n l makes the renaming the
identity on raw names; see §3.5 of the Foil paper), and the same argument
applies to a whole record of them: renaming every field along the identity is
the identity on the representation.
Two fields are not sinkable, and enterBinder restores both in the same
breath, which is why the coercion below is not exported:
ctxScopeis the set of names inn. It has to grow, not coerce — tellingly, free-foil givesScopenoSinkableinstance.ctxVarsmust stay total on the names in scope (lookupNameassumes it), so the new binder's entry has to be added.
sinkContextUnchecked :: forall (n :: S) (l :: S). DExt n l => Context n -> Context l Source #
Sink a context along a scope extension. Unsound on its own: leaves ctxScope
and ctxVars describing the old scope, and the caller must fix both. See the
note above; enterBinder is the only caller.
Arguments
| :: forall (n :: S) (l :: S). DExt n l | |
| => NameBinder n l | |
| -> VarInfo n | its type, value and modality |
| -> [ModalTope l] | discreteness axioms the binder brings (a flat cube point, which are about the variable itself, hence at its scope) |
| -> Context n | |
| -> Context l |
Enter the scope of a binder: extend the scope with it, record what it is called and what it stands for, and carry the rest of the context in.
withFreshBinder :: forall (n :: S) r. Distinct n => Context n -> VarInfo n -> (forall (l :: S). DExt n l => NameBinder n l -> Context l -> r) -> r Source #
Enter a fresh binder: one the checker invents rather than one a term carries (to look under a Π when comparing two of them, say).
addBinderNames :: Binder -> Map VarIdent [VarIdent] -> Map VarIdent [VarIdent] Source #
Record the name a binder introduces (if any), for the shadowing check.
shadowedBy :: forall (n :: S). VarIdent -> Context n -> [VarIdent] Source #
The identifiers in scope spelled like this one.
Sinking the parts
sinkVars :: forall (n :: S) (l :: S). DExt n l => NameMap n (VarInfo n) -> NameMap n (VarInfo l) Source #
sinkNamed :: forall (n :: S) (l :: S). DExt n l => Map VarIdent (Name n) -> Map VarIdent (Name l) Source #
Lookup
lookupVarInfo :: forall (n :: S). Name n -> Context n -> VarInfo n Source #
What a name stands for. Total: every name in scope has an entry.
varInfos :: forall (n :: S). Context n -> [VarInfo n] Source #
What every name in scope stands for, in no particular order.
varsInScope :: forall (n :: S). Context n -> [(Name n, VarInfo n)] Source #
Every hypothesis in scope, oldest binding first (see ctxBound: the ids
themselves do not tell us this).
lookupNamed :: forall (n :: S). VarIdent -> Context n -> Maybe (Name n) Source #
The name a surface identifier resolves to, if any.
binderOfName :: forall (n :: S). Name n -> Context n -> Binder Source #
The display binder of a name (the whole pattern, for projection folding).
Modalities
applyModality :: forall (n :: S). TModality -> Context n -> Context n Source #
Accumulate a modality (a lock) over the hypotheses and the topes.
Note that top-level entries are not touched: a top-level variable is exempt
from the accessibility check (see infer), so accumulating a modality over
them was work with no observable effect. The old context did it to all ~1500
of them on every modal binder.
mapNameMap :: forall a b (n :: S). (a -> b) -> NameMap n a -> NameMap n b Source #
Map the values of a name map, keeping its keys.
insertVarInfo :: forall (n :: S). Name n -> VarInfo n -> Context n -> Context n Source #
Replace what a name stands for.
Closing a section rewrites the definitions made in it, so that each takes the section's assumptions as explicit parameters; this is how the rewritten entries go back into the context.
Topes
Hole modes
allowHoles :: forall (n :: S). Context n -> Context n Source #
Switch to lenient hole mode: record each hole's goal and context instead of reporting it as an error.
withHintLemmas :: forall (n :: S). [VarIdent] -> Context n -> Context n Source #
Allow a hole's candidate list to draw on the given named top-level definitions, in addition to the local hypotheses.
structuralHoleUnify :: forall (n :: S). Context n -> Context n Source #
Within the given action, a hole unifies only as a leaf of an otherwise
matching structure: a structural mismatch around a hole stays an error rather
than being deferred (see ctxDeferHoleMismatches).