Lean2Js.Traps
Which traps one exported function can actually reach #
Reads off the syntax the trap codes a call of one exported function can throw.
The .d.ts is where a consumer decides whether to write a try. One line naming every code the subset
has tells them nothing: a function that only adds and multiplies carries divByZero beside a function
that divides, so the comment stops being a reason to catch anything. What is worth reading is the codes
this function can reach.
Reaching is read off the syntax, the way the fuel bound is. Each operation contributes the codes its case
in Eval can return, a call contributes the callee's, and a declaration handed over as a function
contributes its own at the call that hands it over -- which is where the invariant lives: a function-typed
parameter is only ever bound to a declared name passed as an argument, so a call through such a parameter
adds nothing the caller has not already counted.
noMatchingAlternative is not among them. Exhaustive proves a match the compiler accepted has an arm
for every value the entry check lets through, and a fold's alternatives one for every node its walk
rebuilds, so the generated chain never runs off the end.
This is not proved, and emit does not take it on trust: every vector generated for a declaration is
checked to trap only with a code this reads off it.
Lean2Js.Traps.allCodes
sourceEvery code the generated code throws, in the order a @throws line names them.
Instances For
Used by
Lean2Js.Traps.canonical
sourceThe codes of a set, deduplicated and in that order, so two declarations that reach the same traps carry the same line.
Equations
Instances For
Used by
Lean2Js.Traps.exprCodes
sourceThe codes an expression can reach, given what the declarations before it reach. A call to a name the table does not hold is a call through a function-typed parameter, which the caller counted when it named the declaration.
Equations
- Lean2Js.Traps.exprCodes table (Lean2Js.Core.Expr.lit l) = []
- Lean2Js.Traps.exprCodes table (Lean2Js.Core.Expr.var name) = []
- Lean2Js.Traps.exprCodes table (Lean2Js.Core.Expr.fnRef name) = []
- Lean2Js.Traps.exprCodes table (Lean2Js.Core.Expr.noneE elem) = []
- Lean2Js.Traps.exprCodes table (Lean2Js.Core.Expr.un op x_1) = Lean2Js.Traps.unCodes✝ op ++ Lean2Js.Traps.exprCodes table x_1
- Lean2Js.Traps.exprCodes table (Lean2Js.Core.Expr.bin op a b) = Lean2Js.Traps.arithCodes✝ op ++ Lean2Js.Traps.exprCodes table a ++ Lean2Js.Traps.exprCodes table b
- Lean2Js.Traps.exprCodes table x_1.length = "int53Overflow" :: Lean2Js.Traps.exprCodes table x_1
- Lean2Js.Traps.exprCodes table (Lean2Js.Core.Expr.strBin op a b) = Lean2Js.Traps.strBinCodes✝ op ++ Lean2Js.Traps.exprCodes table a ++ Lean2Js.Traps.exprCodes table b
- Lean2Js.Traps.exprCodes table (a.index b) = "indexOutOfBounds" :: (Lean2Js.Traps.exprCodes table a ++ Lean2Js.Traps.exprCodes table b)
- Lean2Js.Traps.exprCodes table (a.substring b c) = "indexOutOfBounds" :: (Lean2Js.Traps.exprCodes table a ++ Lean2Js.Traps.exprCodes table b ++ Lean2Js.Traps.exprCodes table c)
- Lean2Js.Traps.exprCodes table (a.arraySlice b c) = "indexOutOfBounds" :: (Lean2Js.Traps.exprCodes table a ++ Lean2Js.Traps.exprCodes table b ++ Lean2Js.Traps.exprCodes table c)
- Lean2Js.Traps.exprCodes table x_1.someE = Lean2Js.Traps.exprCodes table x_1
- Lean2Js.Traps.exprCodes table (Lean2Js.Core.Expr.okE err x_1) = Lean2Js.Traps.exprCodes table x_1
- Lean2Js.Traps.exprCodes table (Lean2Js.Core.Expr.errorE ok x_1) = Lean2Js.Traps.exprCodes table x_1
- Lean2Js.Traps.exprCodes table (x_1.proj field) = Lean2Js.Traps.exprCodes table x_1
- Lean2Js.Traps.exprCodes table (Lean2Js.Core.Expr.strUn op x_1) = Lean2Js.Traps.exprCodes table x_1
- Lean2Js.Traps.exprCodes table x_1.arrayReverse = Lean2Js.Traps.exprCodes table x_1
- Lean2Js.Traps.exprCodes table x_1.dictKeys = Lean2Js.Traps.exprCodes table x_1
- Lean2Js.Traps.exprCodes table x_1.dictValues = Lean2Js.Traps.exprCodes table x_1
- Lean2Js.Traps.exprCodes table (a.dictGet b) = Lean2Js.Traps.exprCodes table a ++ Lean2Js.Traps.exprCodes table b
- Lean2Js.Traps.exprCodes table (a.dictHas b) = Lean2Js.Traps.exprCodes table a ++ Lean2Js.Traps.exprCodes table b
- Lean2Js.Traps.exprCodes table (a.dictDelete b) = Lean2Js.Traps.exprCodes table a ++ Lean2Js.Traps.exprCodes table b
- Lean2Js.Traps.exprCodes table (Lean2Js.Core.Expr.letE name ty a b) = Lean2Js.Traps.exprCodes table a ++ Lean2Js.Traps.exprCodes table b
- Lean2Js.Traps.exprCodes table (a.mapE binder b) = Lean2Js.Traps.exprCodes table a ++ Lean2Js.Traps.exprCodes table b
- Lean2Js.Traps.exprCodes table (a.filterE binder b) = Lean2Js.Traps.exprCodes table a ++ Lean2Js.Traps.exprCodes table b
- Lean2Js.Traps.exprCodes table (a.findE binder b) = Lean2Js.Traps.exprCodes table a ++ Lean2Js.Traps.exprCodes table b
- Lean2Js.Traps.exprCodes table (Lean2Js.Core.Expr.quantE op a binder b) = Lean2Js.Traps.exprCodes table a ++ Lean2Js.Traps.exprCodes table b
- Lean2Js.Traps.exprCodes table (a.sortByKeyE binder b) = Lean2Js.Traps.exprCodes table a ++ Lean2Js.Traps.exprCodes table b
- Lean2Js.Traps.exprCodes table (a.cond b c) = Lean2Js.Traps.exprCodes table a ++ Lean2Js.Traps.exprCodes table b ++ Lean2Js.Traps.exprCodes table c
- Lean2Js.Traps.exprCodes table (a.dictSet b c) = Lean2Js.Traps.exprCodes table a ++ Lean2Js.Traps.exprCodes table b ++ Lean2Js.Traps.exprCodes table c
- Lean2Js.Traps.exprCodes table (a.reduceE b accName elemName c) = Lean2Js.Traps.exprCodes table a ++ Lean2Js.Traps.exprCodes table b ++ Lean2Js.Traps.exprCodes table c
- Lean2Js.Traps.exprCodes table (Lean2Js.Core.Expr.ctor typeName tyArgs ctorName args) = Lean2Js.Traps.exprCodesList table args
- Lean2Js.Traps.exprCodes table (Lean2Js.Core.Expr.arrayLit elem args) = Lean2Js.Traps.exprCodesList table args
- Lean2Js.Traps.exprCodes table (Lean2Js.Core.Expr.dictLit value obj entries) = Lean2Js.Traps.exprCodesEntries table entries
- Lean2Js.Traps.exprCodes table (scrut.matchE alts) = Lean2Js.Traps.exprCodes table scrut ++ Lean2Js.Traps.exprCodesAlts table alts
- Lean2Js.Traps.exprCodes table (scrut.foldE typeName tyArgs result alts) = Lean2Js.Traps.exprCodes table scrut ++ Lean2Js.Traps.exprCodesAlts table alts
- Lean2Js.Traps.exprCodes table (Lean2Js.Core.Expr.call fn args) = (List.lookup fn table).getD [] ++ Lean2Js.Traps.exprCodesArgs table args ++ Lean2Js.Traps.exprCodesList table args
Instances For
Used by
Lean2Js.Traps.exprCodesList
sourceEquations
- Lean2Js.Traps.exprCodesList table [] = []
- Lean2Js.Traps.exprCodesList table (e :: rest) = Lean2Js.Traps.exprCodes table e ++ Lean2Js.Traps.exprCodesList table rest
Instances For
Used by
Lean2Js.Traps.exprCodesArgs
sourceEquations
- Lean2Js.Traps.exprCodesArgs table [] = []
- Lean2Js.Traps.exprCodesArgs table (e :: rest) = Lean2Js.Traps.fnRefCodes✝ table e ++ Lean2Js.Traps.exprCodesArgs table rest
Instances For
Used by
Lean2Js.Traps.exprCodesAlts
sourceEquations
- Lean2Js.Traps.exprCodesAlts table [] = []
- Lean2Js.Traps.exprCodesAlts table (a :: rest) = Lean2Js.Traps.exprCodes table a.snd ++ Lean2Js.Traps.exprCodesAlts table rest
Instances For
Used by
Lean2Js.Traps.exprCodesEntries
sourceEquations
- Lean2Js.Traps.exprCodesEntries table [] = []
- Lean2Js.Traps.exprCodesEntries table (e :: rest) = Lean2Js.Traps.exprCodes table e.snd ++ Lean2Js.Traps.exprCodesEntries table rest
Instances For
Used by
Lean2Js.Traps.table
sourceThe table, built in declaration order. Every call reaches backwards, so a callee's codes are already in it by the time the caller is read.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Used by
Lean2Js.Traps.forDecl
sourceWhat one declaration's @throws names. The entry check is what puts typeError there: it reads the
arguments a JavaScript caller passed, and a declaration that takes none has nothing to refuse.
The .d.ts and the check emit runs against every vector both go through here, so the line a consumer
reads and the line the build stands behind cannot come apart.
Equations
- Lean2Js.Traps.forDecl traps d = Lean2Js.Traps.canonical ((if d.params.isEmpty = true then [] else ["typeError"]) ++ (List.lookup d.name traps).getD Lean2Js.Traps.allCodes)
Instances For
Used by
Lean2Js.Traps.forName
sourceEquations
- Lean2Js.Traps.forName p traps fn = match p.find? fn with | none => Lean2Js.Traps.allCodes | some d => Lean2Js.Traps.forDecl traps d