Coverage¶
GADT branch refinement and coverage checking.
coverage
¶
GADT branch refinement and conservative coverage interfaces.
CoverageStatus
¶
Bases: str, Enum
Whether a set of branch patterns covers a family.
Reachability
¶
Bases: str, Enum
Whether a branch can be entered, as far as its equalities decide.
BranchPattern
dataclass
¶
BranchPattern(constructor: ConstructorId | None, guarded: bool = False)
The shape of one case branch, as coverage sees it.
| PARAMETER | DESCRIPTION |
|---|---|
constructor
|
The constructor the branch matches, or
TYPE:
|
guarded
|
Whether the branch carries a guard that may reject a matching value, which keeps it from counting toward completeness.
TYPE:
|
CoverageResult
dataclass
¶
CoverageResult(status: CoverageStatus, missing: tuple[ConstructorId, ...] = (), duplicates: tuple[ConstructorId, ...] = ())
The outcome of checking branch patterns against a family.
| PARAMETER | DESCRIPTION |
|---|---|
status
|
Whether the patterns cover the family.
TYPE:
|
missing
|
Constructors no pattern matches.
TYPE:
|
duplicates
|
Constructors more than one pattern matches.
TYPE:
|
BranchRefinement
dataclass
¶
BranchRefinement(skolems: tuple[str, ...], givens: tuple[BranchGiven, ...], reachability: Reachability = UNKNOWN)
Rigid skolems and local equalities available inside one branch.
| PARAMETER | DESCRIPTION |
|---|---|
skolems
|
The names of the branch's rigid static variables.
TYPE:
|
givens
|
The equalities the branch's constructor makes available.
TYPE:
|
reachability
|
Whether the givens are jointly satisfiable, as far as the unifier decides.
TYPE:
|
check_coverage
¶
check_coverage(family: FamilyDecl, patterns: tuple[BranchPattern, ...], *, certified_impossible: frozenset[ConstructorId] = frozenset()) -> CoverageResult
Check constructor coverage without pretending opaque cases are total.
| PARAMETER | DESCRIPTION |
|---|---|
family
|
The family being matched on.
TYPE:
|
patterns
|
The branch patterns written, in source order.
TYPE:
|
certified_impossible
|
Constructors an equality solver has proven cannot occur, which may therefore be omitted without making the match incomplete.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CoverageResult
|
The status, the constructors still missing, and any matched
twice. The status is |
Source code in src/quivers/qiec/coverage.py
refine_branch
¶
refine_branch(family: FamilyDecl, constructor: ConstructorDecl, scrutinee: TypeApplication, constructor_arguments: tuple[StaticArgument, ...]) -> BranchRefinement
Introduce constructor skolems and index equalities for a branch.
The equality solver is intentionally conservative. Syntactically equal
indices are reachable; contradictory closed literals are impossible; all
other equations remain UNKNOWN and must still contribute branch
effects and coverage.
| PARAMETER | DESCRIPTION |
|---|---|
family
|
The family being matched on.
TYPE:
|
constructor
|
The constructor this branch matches.
TYPE:
|
scrutinee
|
The applied family type being scrutinised, supplying the parameters and the indices to be refined.
TYPE:
|
constructor_arguments
|
Arguments instantiating the constructor's local telescope,
normally the rigid skolems from
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
BranchRefinement
|
The skolems in scope, the equalities the match makes available, and whether the branch is reachable. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If the constructor belongs to another family, if the scrutinee does not inhabit the matched family, or if the scrutinee supplies the wrong number of arguments. |
Source code in src/quivers/qiec/coverage.py
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 | |
constructor_skolems
¶
constructor_skolems(constructor: ConstructorDecl, scope: StaticScopeId) -> tuple[StaticArgument, ...]
Create rigid static variables for a constructor's local telescope.
| PARAMETER | DESCRIPTION |
|---|---|
constructor
|
The constructor whose telescope to instantiate.
TYPE:
|
scope
|
Identity of the branch scope. It enters each variable's identity, so skolems from two branches are never confused and cannot be mistaken for one another when a type escapes.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[StaticArgument, ...]
|
One rigid variable per binder, in telescope order. |
Source code in src/quivers/qiec/coverage.py
check_indexed_coverage
¶
check_indexed_coverage(family: FamilyDecl, constructors: tuple[ConstructorDecl, ...], scrutinee: TypeApplication, patterns: tuple[BranchPattern, ...]) -> CoverageResult
Coverage with omissions justified by closed-index contradiction.
Only constructors that the small equality solver certifies as impossible may be omitted. An unknown result remains a required case.
| PARAMETER | DESCRIPTION |
|---|---|
family
|
The family being matched on.
TYPE:
|
constructors
|
Declarations of the family's constructors, needed to refine each one against the scrutinee.
TYPE:
|
scrutinee
|
The applied family type being matched.
TYPE:
|
patterns
|
The branch patterns written.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
CoverageResult
|
Coverage judged against the constructors that remain possible. |
| RAISES | DESCRIPTION |
|---|---|
TypeError
|
If a constructor belongs to another family, or the scrutinee does not inhabit the matched family. |
Source code in src/quivers/qiec/coverage.py
join_branch_rows
¶
join_branch_rows(branches: tuple[tuple[Reachability, EffectRow], ...]) -> EffectRow
Union effects of every possibly reachable branch.
UNKNOWN is intentionally treated as reachable. Dropping it would make
an incomplete equality solver unsound for effect inference.
| PARAMETER | DESCRIPTION |
|---|---|
branches
|
Each branch's reachability and the row its body performs.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
EffectRow
|
The union over every branch not certified impossible. Only a proven contradiction removes a branch's effects from the result. |
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If two reachable branches bind one instance to different interfaces, or their open tails cannot merge. |