SaTeX v0.2.7

Abstract domains

satex runs TeX's machine over values that stand for sets of what a real run could hold. Each domain below says what it abstracts and how it joins, narrows and widens. When those happen is in SEMANTICS § 14.

This chapter builds on what TeX does. The formal model states both in Lean.

One invariant holds everywhere: a construct is followed exactly, or its result is over-approximated and a diagnostic says so. satex never guesses one outcome.

Value: what a control sequence or register holds

src/engine/value.rs: every kind has an exact value, a hull, a bounded set of either, and a top.

Kind Exact Hull Top
count (\count, \numexpr) Int(i64) Num { lo, hi } the word [-2^31, 2^31-1]
dimension (\dimen, \dimexpr) Dimen(Scaled) Num, in sp the word [-2^31, 2^31-1] stored (Dim::ANY): box sums and \advance pass \maxdimen (tex.web §§ 656, 1238), [-MAX_DIMEN, MAX_DIMEN] scanned (tex.web § 461)
glue, muglue (\skip, \muskip) Glue GlueHull: one Num per component (tex.web § 150) GlueHull::full()
token list (\toks) Toks common start and end around one typed unknown token Unknown
color (\color@⟨name⟩) Color, every component a point Colors, one Num per component the model's full range

The bounded set is OneOf for every kind (below). Code that does not inspect the abstract value reads a hull or set as Unknown (Env::value).

The set lift: OneOf

Value::OneOf is the one set lift Set_k(D) for every kind: a few values, each exact or a hull. {[0pt,10pt], [100pt,110pt]} stays two ranges, not [0pt,110pt].

Operation What it does
join union of the members. Overlapping or touching intervals merge. At most limits.value_set (8) exact members, limits.interval_set (4) with an interval among them.
widening past k, or with an Unknown side: the hull of all members (Value::join_hulls). Only the gaps are lost.
test \ifnum/\ifdim decide member by member. When members disagree, each arm keeps the narrowed part that passes (Num::narrow). The arms rejoin at \fi. A test of an expression that is one register plus a constant (\numexpr\count1-10) narrows that register by the bound minus the constant, in \ifnum and in each \ifcase arm.
arithmetic Num::lift on the hull: exact at a point, else the interval's corners (cut at zero). An overflow clips, a 32-bit wraparound (tex.web § 1238) widens to the whole word range.

Macro bodies use the same lift as meaning sets (limits.meaning_set).

Category codes

Every character has one of TeX's sixteen category codes (The TeXbook, chapter 7). Pages here link each "category N" to its row.

Code Category
0 escape character
1 begin group
2 end group
3 math shift
4 alignment tab
5 end of line
6 parameter
7 superscript
8 subscript
9 ignored
10 space
11 letter
12 other character
13 active character
14 comment
15 invalid

Category sets as a lattice element

A character whose category is not pinned keeps the set of categories it may have, one bit each (CatcodeTable::unknown, tex.web § 232). A join unions the sets, the save stack restores them (per group, only the first save of a slot on each path joins: it is what the group's end leaves), and \the\catcode reads them as a set of numbers. Callers ask cats or is_unknown before trusting get.

The table a LaTeX format hands to the document is the kernel run's own for ASCII: latex.ltx's loops make ^^@ invalid (15), the control characters 1-31 active, tab a space, ^^J other and ^^L active. The format cache stores these codes. Codes 128-255 stay letters, a named limit: satex reads characters, where utf8.def makes the bytes active.

Character codes as sets

Code table entries (\lccode, \uccode, \sfcode, \mathcode, \delcode, tex.web § 1232) hold a Value, joined like registers.

Colors: Color and Colors

An xcolor color is Color { model, components }, one Num per component in xcolor's units. A binding holds Colors, a component-wise hull.

Meaning sets: what a control sequence may mean

After a join of paths that disagree, a Binding (src/engine/env.rs) keeps the possible meanings in may (at most limits.meaning_set). Code that does not look at the set reads the meaning as unknown.

Operation What it does
\ifx, \ifdefined decided when every member agrees
execute splits the run into one path per meaning, limits.meaning_splits levels deep. Deeper, or inside an \edef, the meaning is unknown.
\ifx against one meaning splits by answer, each side keeping the members that give it
\if, \ifcat each member gives its operand, behind \noexpand too: a character its code and category, any other meaning a control sequence (tex.web § 506). Decided when every member agrees. Without \noexpand an expandable member leaves the operand unknown.
expand (\expandafter, \edef) a set of meanings none of which expands (fonts, \relax, registers) keeps the token as it is
\let copies the whole set
format cache stores the set with the meaning: installed without it, a kernel name such as LuaLaTeX's para/end hook would be unknown, and a maybe-undefined one certainly defined
widening only where a later pass runs from the join, see the list below

A widened macro whose members all hold a token holds one too, so \ifx can still tell it from a primitive, a character or a macro with parameters. Typed text that may be empty does not count as a token, and a token for one of several texts joins by the class of those texts.

Example: after \ifx\a\b \let\next\foo \else \let\next\bar \fi, \next may be \foo or \bar. \ifx\next\relax is undecided. Executing \next splits into two paths that join again later.

Modes and box dimensions

Modes (src/engine/mode.rs) is the set of TeX's six modes the run may be in (tex.web § 211). \ifvmode, \ifhmode, \ifmmode and \ifinner are decided when every mode agrees. Paths join by union.

Dim { lo, hi } is one length: box sizes, added up as hpack (tex.web § 649) and vpack (tex.web § 668) do. An item satex cannot follow widens the size to Dim::ANY. It is never left out.

The list's tail (Last) is what \lastskip, \lastkern, \lastpenalty and \lastnodetype read:

Tail item Kept
glue width as Dim, specification as GlueHull, whether it is mu glue (tex.web § 424)
character its box, and whether it is a ligature (exact where the font's lig/kern program was followed, §§ 1034–1040)
rule, insert, adjust, whatsit, math, noad its \lastnodetype (3, 4, 6, 9, 10, 15)
box hbox or vbox where the packing tells it, which \lastbox takes back (tex.web § 1080), also after \unvbox. A paragraph's last line is an hbox unless a mark, insertion or \vadjust may follow it (tex.web § 655). A box of unknown kind, or an item that may be a box, is never read as no box.
mixed kinds Last::Unknown, still holding the join of each reading (zero where of another kind)

Where the tail is not known at all, an engine quantity is still in its own range, never any word: \lastnodetype from -1, \badness 0..1000000, \currentifbranch -1..1, a glue order 0..4, each bound wide enough for every engine's codes (last_item_range).

A list also counts the items it holds at least, so an internal vertical list with items left never reads -1 (tex.web §§ 1080, 1105).

The tail is a window of the last four items. A box before another on a vertical list brings its interline glue (tex.web § 679). A box register keeps the window too: the last item, and the glue, kerns and penalties right under it (an inexact glue keeps its kind and hull). \unvbox and \unhbox put the window back, \box and \copy carry it, and \box255 takes the main list's at a break. So \unskip, \unkern, \unpenalty and \lastbox after an \unvbox see what TeX uncovers (tex.web §§ 1105, 1110).

Each item of a vertical list's window can hold the list's size before it. Glue and kerns appended to the list have it. So have the items of a recorded list that \unvbox put on. Taking such an item off restores that size exactly (tex.web § 668). Glue or a kern over glue or a kern takes its width alone, the depth under it being zero. Any other removal leaves the size unknown.

Boxes

A box register holds width, height and depth as Dims, read by \wd, \ht, \dp.

Material How its size is followed
characters TFM width, height, depth, kerns and ligatures. A font without metrics widens.
native characters XeTeX and LuaTeX (luaotfload) fonts by file ([file]:features). See the list below the table.
hpack / vpack height, depth (resp. width) start at zero (tex.web §§ 649, 668). vpack moves depth past \boxmaxdepth into the height. \vtop (tex.web § 1087), \vcenter (tex.web § 736).
inline math characters, \mathchardef atoms, italic corrections, class spacing (tex.web §§ 752–766), \mathsurround (tex.web § 1196). Operators on the axis, with scripts or limits (§§ 749–751), \left…\right with delimiters sized by var_delimiter and extensible recipes (§§ 706–714, 760–762), math accents (§ 738), groups as boxes a script sits on (§ 1186). Delimiters around a list of unknown height hull every variant a height in its interval picks. A delimiter or accent that paths join apart, \middle, and lost groups widen.
display math the paragraph's lines before it (tex.web § 1145), then the penalties, skips and the formula's box in display style (§§ 1199–1205), \prevgraf plus three. \predisplaysize is not followed: each skip is the join of the normal and the short one. A number beside the formula joins with one on its own line unless it surely fits. Display style takes an operator's successor and limits, sup1, \mathchoice's first list. A display-style fraction widens.
\unhbox, \unvbox the natural size recorded at packing (tex.web § 1110), the tail kept, an hbox's recorded items go back onto the list, so a paragraph breaks them
\write, \openout, \closeout nothing when \immediate, else a whatsit (tex.web §§ 1352, 1375)
\pdfextension a whatsit or nothing, of no size (LuaTeX manual, "PDF extensions")
\discretionary its unbroken text (tex.web §§ 651, 1119)
unknown box Dim::ANY for all sizes

Marks

Marks are exact where the lists are recorded: \topmarks, \firstmarks, \botmarks per class from the page lists, the split marks from the part \vsplit took (tex.web §§ 979, 1012–1014). Otherwise a class holds a OneOf of the texts given so far or empty. A mark of a class satex cannot name makes every class unknown.

Paragraphs and line breaking

A paragraph in a vertical box is broken as line_break does it (tex.web §§ 813–890). Para holds the range of lines made so far.

Case Result
forced breaks (penalty ≤ -10000) exact (tex.web §§ 851, 879)
all items known, plain parameters Knuth-Plass in all three passes (tex.web § 863, src/engine/linebreak.rs): line count, sizes and \prevgraf exact
fits with infinite stretch, or badness bound low enough one line (tex.web §§ 817, 851–859)
otherwise one line up to one per breakpoint, that bound rounded up to a power of two, sizes between zero and the text's. The rounding keeps the bound, and the page's length with it, as it was when a word is typed into the line: the run after the edit meets the last one past the paragraph

Unknown text: the TextClass lattice

Unknown text has a class: the set of token kinds it may hold (src/engine/tex.rs). Classes are ordered by inclusion.

Kind Letter Tokens
DIGIT d 0–9, category 12
SIGN s + - . ,, category 12
LETTER l category 11
OTHER o other characters that open no group
SPACE _ category 10
BRACE b balanced braces
CS c control sequences and active characters: anything
HEX h a restriction: its letters and other characters are 0–9, A–F, a–f
unknown text     all kinds (top)
cs-free text     d s l o _ b
dimension text   d s l
number text      d s
typed digits     d, with an interval [lo, hi]

Stubs name these elements: nothing, number / { number: [lo, hi] }, dimen, { text: digits | number | dimension | cs-free | any }, box / { box: { width, height, depth } }.

Unknown characters and digits

Character May be
UNKNOWN_CHAR a digit or - (the first character \the prints for a number)
UNKNOWN_DIGIT 0–9
UNKNOWN_NONZERO 1–9
UNKNOWN_HEX_OTHER 0–9, A–F, a–f, category 12
UNKNOWN_HEX_LETTER A–F, a–f, category 11

\the never prints an integer with a leading zero (tex.web § 65). Reading the first digit of an unknown number splits into - (digits follow), 0 (nothing follows) and 1–9 (one digit fewer may follow), so a digit-stripping loop ends.

One-of tokens

A one-of token stands for one of a few texts (a joined \@currenvir, v plus a or b).

Length bounds on typed text

Typed text may carry a maximum token count (LEN_MARK, at most 20).

Source Bound
\the/\number of a count 11 (tex.web § 65)
\the of a dimension 14 (tex.web § 103)
a value in an interval the digits of its larger end
the rest after reading one token one less, 0 is no text
a join the larger bound, a collapsed run sums them

A loop pass that has strictly less left to read is not counted against limits.widen_after (pass_bound), so such loops run exactly to their end. Less means fewer lines left in the open \read streams, or as many and less pending bounded input. Typed text counts by its bound, one of several texts by its longest text. So a loop that peels records off a list joined from lists of several lengths (l3str's c \s__str N \s__str records of a string of unknown length) reads every record exactly, and no pass widens the list to text that lost its separators. A loop over a file satex wrote (scrlayer-notecolumn's .slnc read-back) thus reads each line exactly, and no join of its passes turns a line's text into code. A loop summary widens what its passes wrote against the loop's start: bounds no pass moved stay, moved ones go to the end of their range, and a widened token list keeps its frame.

Names from unknown text

Wild (src/analysis/machine.rs) holds the families of names a definition of a partly unknown name may have made (tex.web § 372): the known text around the unknown part, as in \csname MT@inh@\x\endcsname.

Argument types: the Ty lattice

src/analysis/roles.rs types each argument of a command by what TeX read it as. The record numbers them by their place in the usage line, optional ones counted. A type stands for the texts an argument may hold, so a type is below another when every text it admits the other admits too. The order follows tex.web's scanners: scan_int (tex.web § 440), scan_dimen (tex.web § 448), scan_glue (tex.web § 461), a register an assignment names (tex.web § 1224), a box number (tex.web § 1079), get_r_token (tex.web § 1215). A register's name is text of its value's kind, because a scanner reads the register's value there (tex.web § 413). A dimension is glue without stretch.

flowchart LR
  t0["any"]:::top
  t1["quantity"]:::quantity
  t2["number"]:::quantity
  t3["dimen"]:::quantity
  t4["glue"]:::quantity
  t5["muglue"]:::quantity
  t6["box"]:::quantity
  t7["register"]:::register
  t8["control sequence"]:::cs
  t9["conditional"]:::cs
  t10["options"]:::key
  t11["date, at least"]:::text
  t12["text"]:::text
  t13["name"]:::text
  t14["definition body"]:::text
  t15["overlay specification"]:::text
  t16["tl variable"]:::expl3
  t17["str variable"]:::expl3
  t18["clist variable"]:::expl3
  t19["seq variable"]:::expl3
  t20["prop variable"]:::expl3
  t21["fp variable"]:::expl3
  t22["bool variable"]:::expl3
  t23["regex variable"]:::expl3
  t24["coffin variable"]:::expl3
  t25["flag variable"]:::expl3
  t26["intarray variable"]:::expl3
  t27["cctab variable"]:::expl3
  t28["count register"]:::register
  t29["dimen register"]:::register
  t30["skip register"]:::register
  t31["muskip register"]:::register
  t32["toks register"]:::register
  t33["box register"]:::register
  t34["read register"]:::register
  t35["write register"]:::register
  t36["counter"]:::register
  t37["dimen name"]:::register
  t38["skip name"]:::register
  t39["muskip name"]:::register
  t40["toks name"]:::register
  t41["box name"]:::register
  t42["read name"]:::register
  t43["write name"]:::register
  t44["key"]:::key
  t45["label"]:::key
  t46["citation key"]:::key
  t47["option key"]:::key
  t48["pgf key"]:::key
  t49["environment name"]:::key
  t50["declared key"]:::key
  t51["index entry"]:::key
  t52["color name"]:::key
  t53["code language"]:::key
  t54["file"]:::file
  t55["TeX file (.tex)"]:::file
  t56["package (.sty)"]:::file
  t57["class (.cls)"]:::file
  t58["bibliography database (.bib)"]:::file
  t59["bibliography style (.bst)"]:::file
  t60["biblatex bibliography style (.bbx)"]:::file
  t61["biblatex citation style (.cbx)"]:::file
  t62["theme (.sty)"]:::file
  t63["graphic file"]:::file
  subgraph g0_register[" "]
    direction LR
    t7
    t32
    t33
    t34
    t35
  end
  t0 --> g0_register
  subgraph g8_expl3[" "]
    direction LR
    t19
    t20
    t21
    t22
    t23
    t24
    t25
    t26
    t27
  end
  t8 --> g8_expl3
  subgraph g12_text[" "]
    direction LR
    t11
    t14
    t15
  end
  t12 --> g12_text
  subgraph g13_register[" "]
    direction LR
    t36
    t37
    t38
    t39
    t40
    t41
    t42
    t43
  end
  t13 --> g13_register
  subgraph g44_key[" "]
    direction LR
    t45
    t46
    t47
    t48
    t49
    t50
    t51
    t52
    t53
  end
  t44 --> g44_key
  subgraph g54_file[" "]
    direction LR
    t55
    t56
    t57
    t58
    t59
    t60
    t61
    t62
    t63
  end
  t54 --> g54_file
  t0 --> t1
  t1 --> t2
  t4 --> t3
  t1 --> t4
  t1 --> t5
  t2 --> t6
  t0 --> t8
  t8 --> t9
  t0 --> t10
  t0 --> t12
  t12 --> t13
  t8 --> t16
  t16 --> t17
  t16 --> t18
  t2 --> t28
  t3 --> t29
  t4 --> t30
  t5 --> t31
  t13 --> t44
  t13 --> t54
  classDef top fill:#eef0f2,stroke:#8a8f98,color:#1f2328
  classDef quantity fill:#dbeafe,stroke:#3b82f6,color:#1f2328
  classDef register fill:#ffedd5,stroke:#f97316,color:#1f2328
  classDef key fill:#ede9fe,stroke:#8b5cf6,color:#1f2328
  classDef file fill:#ccfbf1,stroke:#14b8a6,color:#1f2328
  classDef cs fill:#fee2e2,stroke:#ef4444,color:#1f2328
  classDef expl3 fill:#fef9c3,stroke:#ca8a04,color:#1f2328
  classDef text fill:#dcfce7,stroke:#22c55e,color:#1f2328

The diagram follows Ty::parent, one colour per family: the top any (grey), quantities (blue), registers (orange), keys and options (purple), files (teal), control sequences (red), expl3 variables (yellow) and text (green). Each type is its own node. Three or more types below one parent, with none below them, stand in one stacked cluster. nothing is below every type and left out. The labels are the ones signatures and hovers show. In each example the ⟨…⟩ part has the type. The table names the type above only where the label does not show it.

Label Meaning Example
any no information, the join of unrelated types
quantity a number, dimen, glue or muglue \numexpr1+⟨\dimexpr 1pt\relax⟩ is read as a quantity
number ⟨number⟩, read by scan_int \penalty⟨100⟩
dimen ⟨dimen⟩, read by scan_dimen, below glue \kern⟨2pt⟩
glue ⟨glue⟩, a dimen with optional stretch and shrink \hskip⟨1pt plus 1fil⟩
muglue ⟨mudimen⟩ or ⟨muglue⟩ \mskip⟨3mu⟩
count register a count register an assignment names, below number \advance⟨\count@⟩ by 1
box a box register's number, below number \setbox⟨0⟩\hbox{}
dimen register a dimen register an assignment names, below dimen \advance⟨\parindent⟩ by 1pt
skip register a skip register an assignment names, below glue \advance⟨\parskip⟩ by 1pt
muskip register a muskip register an assignment names, below muglue \advance⟨\medmuskip⟩ by 1mu
toks register, read register, write register the other registers an assignment names ⟨\toks@⟩={a}
register a register of a kind the text does not fix, what a body assigns #1 to \def\x#1#2{\advance⟨#1⟩ by #2}
text balanced text of any kind \textbf{⟨a name or code⟩}
name characters forming a name, below text \csname ⟨foo⟩\endcsname
counter the name of a LaTeX counter, c@⟨counter⟩, below name \setcounter{⟨section⟩}{1}
⟨kind⟩ name the name of a register of that kind a \csname forms \csname dimen⟨foo⟩\endcsname
key a key of no known kind, below name \mykey{⟨x⟩} of unknown role
label a label a command defines or references, below key \ref{⟨sec:intro⟩}
citation key a bibliography entry's key \cite{⟨knuth84⟩}
option key an option or key a key list names \usepackage[⟨draft⟩]{x}
pgf key a key pgfkeys stores under its family's path, below option key \draw[⟨thick⟩] is /tikz/thick
environment name an environment's name, below key \begin{⟨itemize⟩}
declared key a key a document command declares and others read by its name, below key \gls{⟨graph⟩} after \newglossaryentry{graph}
index entry a term an index or glossary program sorts, below key \index{⟨source⟩}
file a file of no known kind, below name \input{⟨a⟩} read as .bib and .tex
TeX file (.tex) a file read as TeX source \input{⟨chapter1⟩}
package (.sty) a package \usepackage{⟨amsmath⟩}
class (.cls) a document class \documentclass{⟨article⟩}
bibliography database (.bib) a BibTeX database \bibliography{⟨refs⟩}
bibliography style (.bst) a BibTeX style \bibliographystyle{⟨plain⟩}
biblatex bibliography style (.bbx) a biblatex bibliography style \usepackage[style=⟨authoryear⟩]{biblatex}
biblatex citation style (.cbx) a biblatex citation style \usepackage[citestyle=⟨numeric⟩]{biblatex}
theme (.sty) a package the code names by a prefix around the text, below file \usetheme{⟨Madrid⟩}
graphic file a figure, its extension decided by the run \includegraphics{⟨fig⟩}
control sequence a control sequence an assignment defines \def⟨\foo⟩{}
conditional a conditional \newif defines, \if⟨name⟩, below control sequence \newif⟨\ifdraft⟩
tl variable, seq variable, prop variable, fp variable, bool variable, regex variable, coffin variable, flag variable, intarray variable, cctab variable an expl3 variable, by the module of the function that made or set it in the run (\tl_set:Nn, \seq_new:N) \tl_set:Nn⟨\l_my_tl⟩{x}
str variable, clist variable a string or comma list, which expl3 keeps as token lists, below tl variable \str_set:Nn⟨\l_my_str⟩{x}
options the key list a load takes in its optional argument \usepackage⟨[a,b]⟩{x}
overlay specification text a command reads between < and >, beamer's overlay specification, below text \only<⟨2-⟩>{x}
definition body a definition's replacement text, code, below text \def\x{⟨\kern1pt⟩}
nothing no text, below every type

Files written in the run

satex writes nothing to disk. A run's written files live per path in Outputs (src/analysis/machine.rs).

State How it arises
known text \immediate\openout empties it, each \write appends a line. An \immediate \write token for one of several texts parts the path per text, so each writes it exactly. Other unknown parts are written as one character per class, which reads back as that class. \scantokens reads its text back the same way: it is a file the run wrote.
deferred a \write, \openout or \closeout without \immediate is a whatsit (Whatsit): its stream is read now, its text kept unexpanded (tex.web § 1352). \shipout, a page without output routine (tex.web § 1023) and the end of the run (tex.web § 1054) run the whatsits in order, a text expanded in the environment then (tex.web §§ 1370, 1374), after the shipout hooks ran. A token for one of several texts writes each text, the files joined.
unknown text a \write to a stream number not pinned adds a line of unknown text to every open file
any file, text outside the run a \write18 program whose command line names no output (-o, --outfile) may write any file (ANY_OUTPUT): from then on any file name may exist, its text unknown. An \input of it is not followed, and the path is marked read_outside: no later error on it is certain.
a set of texts paths that wrote it differently: texts whose lines pair one by one join line by line (join_written), so each differing line keeps its values and the file is not kept once per combination of them. Texts that set different things stay apart, up to limits.meaning_set. A read parts the path per text. Past an \input of such a file every path has the same source progress (the file's length), so the paths join where they meet again.

Call summaries: what a call did twice

src/analysis/machine/calls.rs summarizes a call by its effect, so parsers that read unknown text one token at a time (pgfmath, l3fp, calc, listings) converge after two runs.

Step Rule
key the macro's definition, the call site, the control sequences in its arguments
record the first limits.call_summary_after (2) runs over unknown operands run the real body and record the names written and read. Runs over known operands are not recorded. Calls a scan expands are not recorded either.
apply from the third call, if an operand is unknown text or a meaning set: the recorded writes are joined, widened (widen_slot) and assigned. The body is skipped. One call-summarized imprecision per key. A name a run read but did not write, with a precise value then, must hold that value now for at least one run, else the call runs. Any name counts, not only count registers.
relate a name every run left as the same text of its own arguments' typed numbers (slices spelling one whole count as it) gets that text of this call's numbers, not the widened join. \pgfmath@bgroup@strip of a new number thus keeps it whole and typed.
own the key ignores characters, so \cnt+1 and max(\cnt,10) share one. A write that holds tokens of its run's arguments, where this call's arguments differ, describes no other call: the call runs.
never runs that read on in the file, change a catcode, leave a group, conditional or mode, add to a list, write different names, accumulate (x then x…), update a macro or token list they read before writing it (a stack push or pop: what it held below differs per call, and runs that agree say nothing of it. A register they update is no reason: its joined value widens to its range), or leave code rather than data. Such a key always runs the real body.

A macro that peels unknown text at a delimiter puts the rest back and splits it again on the next level. Past limits.rest_splits (8) splits of one rest at one site, that rest counts as having no more delimiters, so the loop ends.

Learned effects: what a definition's runs teach

A parser that reads an unknown number forks at each digit, and no digit model ends that. Its runs on other values already show what it leaves, and each is a run of the real code. So a run of a definition that keeps forking stops there and leaves what those runs left. A call whose operands are known forks nowhere, so it always runs for real. An unknown operand reached through a register, a macro or \the is found where it first decides something, with no look at the arguments.

Step Rule
key the definition's code, not its name or site: \let copies share it
learn every run the main loop expands is recorded until limits.call_learn_after (2) runs on different arguments have ended. A run may close the group around its call, and may end in \ignorespaces. A run that forked counts too, each arm that ends it apart, or their join: the arms decided on different values. A run with a loop summary inside counts as well (a soft record): the summary over-approximates the loop, so the run over-approximates the call. Such a run only teaches its definition, it is never a site summary.
writes the names a run left changed at its end. A local write made deeper than the groups open at the end was undone by a group end (tex.web § 283), whatever stamp a resume gave the name. Groups merged by a widening move their writes down with them. The writes are read from a log. A token read from a file starts it over, and past limits.write_log entries it is folded to each name's first write and every later one made less deep: a run that began before either teaches nothing, a loop met again widens every name in it.
refuse a run that teaches nothing, for good. See the list below the table.
cut at the limits.call_learn_forksth (2) undecided choice of a run: the outermost running call with a learned effect ends there (learned_cut). Its text goes, what it opened closes, what it wrote in the closed groups goes back.
apply number text becomes a printed number (printed_dimen), a register any value, a flag the runs disagree on either meaning. What all runs left the same stays.

This is the named assumption call-learned-effect (analysis.assume_call_learned_effect): the call writes what its runs wrote, and raises nothing on the unknown value. If no run has taught it anything, the call runs as before. Sampling the type's values instead would need a machine snapshot and a run per sample at each call. The runs a document makes anyway cost nothing.

Kept effects: exact replay of a repeated call

A drawing calls the same producers again and again: a key handler, a point computation, a loop over the same list. A run on known values is a function of what it read. So a main-loop call that ran limits.call_memo_steps steps (200 by default) keeps its effect, and a later call of the same code on the same arguments, while every name the run read holds what it held, makes the run's assignments instead of running. Nothing is approximated: a replay leaves the state the run would leave.

Step Rule
where the document's body, by LaTeX's own test (\@nodocument is \relax), so the front matter counts and the preamble does not: its facts go into package caches, which a replay must not tell apart from a read. Plain TeX is all body. Only a call the main loop expands itself: one that \expandafter or a scan expands runs its text later or never, so its effect does not stand where it is called.
key the code and the argument tokens. A token of the user's own file matches only at its own place, since the kept values may carry it.
record every name the run read, raw slot reads included, with what it held before the run's first write to it.
keep a run that ended whole, met no choice, named no unknown value of its own and changed only names. See the list below the table.
replay where the mode, the lists, the categories, the pending prefixes and the certainty are as the run met them. The conditionals open around the call and its group's \aftergroup tokens are not compared: a run cannot read them (\currentiflevel is a side effect that keeps nothing), only a run that closes the group needs its tokens. The brace count is compared inside an alignment cell, where it is read against the cell's.
end its caller's group a run that closes the group its caller opened (pgfmath's \pgfmathparse opens it, its parser ends it with \endgroup and hands the result out) keeps its effect up to that \endgroup, when the group held no box or \aftergroup tokens, nothing below its text was read, and its text has only tokens left. Only global writes outlive the group. A replay makes them, closes the group and reads the tokens left.
apply each name the run left written is assigned again, global if the run wrote it only globally, local if only locally. A name written locally and then globally is assigned globally: the global value holds at every level (tex.web § 283). A local write after a global one would need both values and is refused. The records around the call see the reads the run gave them, no more: a run reads some names only for its own key (raw slots, the analysis's own looks), and a summary that saw those would take the run for one over unknown values. A kept occurrence holds only where the call raises it at the same place and it is still said just before. The build-cost findings count the steps a replay stands for.
verify limits.call_memo_verify runs each call a kept effect stands for and prints where the run's writes, read log or steps differ.
bound limits.call_memo_variants (4) states per key, the oldest giving way, limits.call_memo_bytes (256 MiB) in all, all dropped at once past it. A definition whose first limits.call_memo_probes (8) runs all were short or unclean is no longer recorded.

Inside a package that is cached, nothing is kept: a replayed load runs no calls, so a cold and a warm run see the same.

Package caches: a load as a function of what it found

A package cache stores a load in segments. Each segment is a function of the state it found. Three kinds of dependence, from weak to strong:

The load Stored as Served where
passes a value on: a count set from another, \advance/\multiply/\divide on it, \the of it or an engine text (\jobname, \pdfcreationdate) inside an \edef an expression over the values found (its leaves), or a hole in the text everywhere the expression has a value. It is computed again there
tests such a value with \ifnum the relation and its outcome (a guard) where the guard comes out the same
looks at it any other way (a macro argument, a name built from it, \ifx) the exact value (a digest) where the value is the same

The line guard: termination

One check bounds every run, whatever the precision: Machine::check_budget charges every step (token read, driver pass, replay) to the source line being read, summed over all paths. A replayed package charges no line.

Overrun of the line's budget Effect
first the expansion unwinds, what it wrote widens to typed unknowns, an unknown token stands for its output, the line reads on (line-budget-cut)
later the rest of the line is skipped (stalled-line-skipped), and the run goes on with the next line
later, no line to skip to the run stops (budget-exhausted)

A line's budget is limits.line_steps in the preamble, where a line loads a package, and at most limits.text_line_steps in the body, where it typesets. A file holds finitely many lines, so a run spends a bounded amount per line read, plus a constant. Every bound is a fixed count, never a share of the total budget, so cuts land in the same places.

A widened expl3 variable keeps the shape of its kind. Its name gives the kind (\l_x_fp is an fp). The ends that all the kind's constants share (\c_zero_fp, \c_nan_fp, ...) stay, around typed text of the classes between them. So an fp stays \s__fp \__fp_chk:w … ;, and the module's parsers find their delimiters. This is the named assumption variable-kind-shape (analysis.assume_variable_kind_shape): only the module's functions write such a variable. A kind whose constants share no end (tl) widens as before.

Pages: one arm past a budget

A float of unknown height parts the output routine at every \ifdim that tries to place it. Followed, the routine ran once per arm of every float, tens of paths stood side by side inside one shipout, and a thesis never ended. Widening there was no better: it made what the routine wrote unknown, fonts and file lists included.

So where floats and page parts land is assumed, not followed. Past limits.output_forks choices in a run (0 by default), a choice undecided inside an output routine, or in the text of a \clearpage around one, takes its first arm and parts no path: a float fits where it is tried, a loop around a page clear ends (analysis.assume_page_one_arm, reported as page-one-arm). What the other arms would do is not followed, so an error only they raise is not reported. The arm taken learns no value from its test (no path took the other arm): a page count compared with the last page's number stays the interval it was, where it had become that number and was written to the .aux as such.

Calls nested deeper than limits.call_rec_depth are neither learned from nor summarized: the record stack is shared between paths, so its length is the cost of a call. A choice inside a value scan counts against limits.site_forks times limits.scan_site_factor: a scan's arms join where it ends, but a walker over unknown text forks per token.

Rules that keep cuts sound and convergent:

After an edit: the last run's rest

An edit reruns little. The run resumes at the last saved state whose input is unchanged. It stops where its state meets the last run's again: from there the last run's rest is this run's. Nothing is approximated, the result is the full run's.

Step Rule
resume at the last saved state that read nothing changed. A file it has open must begin as it did. A project file's size is one unknown number per file, 1 to 2³¹-1, or 0 for an empty one: \IfFileExists and \include ask for it before they open the file (l3file's \file_full_name:n), and an edit must not change what they read. Two reads of one file are one token, so the test of name against name.tex is decided.
place the first edit at a place finds no state of the last run nearby. The old text is run again from the state before it, only to save states: one at the edit's line, limits.checkpoints_after_edit on the first lines past it between paragraphs. It is the last run again, checked by the files it reads. It looks at most limits.checkpoint_meet_steps steps past the edit, and no further than the last run's next state between paragraphs (one inside a paragraph cannot be met). The language server does this ahead, while idle, for the line of the last request at the caret (a code action, a highlight, a completion): the edit that follows finds its states placed (placedSteps 0 in satex/runInfo). The run stops for any message.
meet at a line start between paragraphs where the last run saved a state with the same text left to read. Modes, lists, conditionals, groups, saves, files written and held, names, facts and the graph must be equal. Counts that are absolute (source read, assignments, groups) compare by how long ago when made since the runs parted.
delta bindings may differ. Per name the run keeps the step of its last read or write. A name the last run's rest never touched keeps this run's binding to the end. One it touched ends the reuse, and the run goes on.
lists a recorded list (a paragraph's items, a page's boxes) is named by where it was made. The run begins with every list the last run made, each under its name, so one list has one name in both and its own new lists come after. Without that the runs do not meet.
names a name is numbered at its first use. The run begins with the last run's names too, so a name both runs use has one number and a name only this run makes comes after. A name is only ever asked for its meaning (tex.web § 259), so more names change nothing. Typed digits are still named by the step they were made at, so an edit before them renames them and that stretch runs again.
records what the run keeps outside its analysis for its end (lines written, names read, names defined from keys) is spliced like the fact rows. A row raised in a package's file by a call on an edited line is that line's. The places the run keeps of what it read last must stand off the edited lines. The splice works on a copy of the last run's end: where a row does not splice at one line, a later line may still meet.
rest reused only when every file the last run read after the meeting line still holds. An edit the rest has yet to read is run.
splice the last run's records after the meeting line follow this run's. Character offsets move by the edit's length: the characters set alike before and after the edited ones align. Rows and graph vertices on the edited lines are this run's.
bound limits.checkpoints, limits.checkpoint_steps, limits.checkpoint_body_share, limits.checkpoint_memory. They change how far a rerun resumes, never a result.

An edit that adds a fact row or a graph vertex (a new \label, a typed command) does not meet: later rows are numbered by position. The run then goes on to the end. The page that holds the edited paragraph meets once it has shipped.

The join, in general

Every domain joins the same way: hull plus bounded union. Keep the exact members while they fit the limit, else take the hull. Never fail.

Arms kept paired

A join that is not widened keeps its arms paired (Corr, src/engine/env.rs): per arm, the bindings of the names that differ. pgfmath's operation stack and its top differ together. Joined apart, a later split pairs neg with a stack that never held it (a false missing number).

Stacks as intervals

A group or conditional frame may stand for any number of copies (many). A loop that opens a group per pass would otherwise never meet itself: [G] and [G, G] widen to [G, G*].

Joins at \fi

Arms of an undecided conditional that reach its \fi go on as one path (fi_mark, partner in src/analysis/machine/explore.rs). The conditional is identified by its \if… and the stack depth below it (tex.web §§ 489, 498).

Joins at the limits

Limit Past it
limits.choices per command the conditional is widened: both arms skipped, one unknown token in their place (undecided-condition)
limits.choices inside an expanding scan of text (\edef, \expanded) the scan ends as a whole: its pending expansions go, what it opened is closed, and the rest of its text is one unknown token for all its paths (undecided-condition). An expanding scan assigns nothing, so the token covers every arm. Skipping only the conditional would let the code after \fi (l3fp's parser) run on text no arm made
limits.alike waiting paths at one place paths whose input differs only in text join
limits.paths the two furthest back are cut to their shared input levels and joined
fork backstop at a hot site no new arm, except for paths a look-ahead parted that cannot be joined (other input): they get their arms, since following one would be unsound. Under a cut one is followed and the cut summarizes the region
fork backstop at an argument end a delimited argument that may end at a place or read on. For the call's last parameter one path reads on: the argument from that place is unknown text covering both ends, and what the other end leaves to run, its delimiter too, may run (unforked-argument-end). Before another parameter, and at a literal of the parameter text, the arms leave the input at different places, which no path covers: the hot site does not refuse that fork, a one-of split there either. A one-of whose split is refused at the call's last parameter is read on like unknown text, its end covered alike

Paths join between two commands where they stand alike: same input, conditionals, groups and scans (absorb). Measured on a TikZ node with unknown height, limits.alike 8 takes 2.8k forks, 16 takes 5.1k.

Code a join makes unknown

Joining pending code into unknown text keeps what it may do (may_run):

Precision limits: where the domains stop being precise

The limits: settings in satex.yaml trade precision for a bounded search (src/project/config.rs, details in Configuration). Past each, the value moves up the lattice and a diagnostic says so. Time, memory and thread limits never coarsen a result: they only stop a run.

setting default what it bounds
limits.choices 8 How many undecided \if one command may split into paths. Past them the command's result is unknown text, reported as an assumption. Higher keeps more combinations apart and costs time.
limits.site_forks 64 How many paths one place in a source line may start, counted over all paths. Past them an \if there is no longer followed both ways: the run takes the effects either branch may have (site-forks-widened). Lower finishes a \foreach with unknown bounds sooner but knows less. 0 turns it off.
limits.digit_lengths 3 How many digit counts a number of unknown digits is read apart into, one path each, when TeX reads it digit by digit (\the\count of 0..214: one, two, three digits). Past them the longer counts are one path whose count stays open. Higher is more precise where code compares or prints the count, and forks more for wide ranges (\int_rand:n {16777215}).
limits.parshape_lines 64 How many lines of a \parshape satex keeps, each its indent and length. TeX reads every line the count names (tex.web § 1248). The lines past these are read but unknown. A count no budget reads to its end leaves the shape unknown. Higher keeps long shapes.
limits.paths 16 How many alternative paths satex keeps at once. Past them the two oldest at one place are merged into one. Higher is more precise, slower and takes more memory.
limits.meaning_splits 4 How often one command may split the run per meaning of a name that has several, such as \x defined differently in two branches. Past them, and with 0, the name reads as unknown.
limits.widen_after 3 How many rounds a loop is followed exactly before values that still change become ranges (SEMANTICS § 14). A \loop counting to an unknown bound has its counter as a range after these rounds.
limits.recursion_depth 100 How deep a macro that calls itself while an \if is undecided is followed before the recursion is assumed to end there.
limits.loop_heads 512 How many loops one run remembers with their merged states. Past them the oldest is forgotten, and summarized when it comes back.
limits.call_summary_after 2 After this many runs of one call at one place, a call with unknown arguments reuses their merged result instead of running again. \pgfmathparse{\x} with an unknown \x is then one step. 0 never does.
limits.rest_splits 8 How often a macro that peels unknown text may split one rest it put back at a delimiter before the rest counts as holding no more.
limits.call_learn_after 2 How many runs on different arguments teach what a definition's calls leave, with analysis.assume_call_learned_effect. 0 never.
limits.call_learn_forks 2 How many undecided choices a run of a definition that was taught may meet before it ends with the learned effect.
limits.meaning_set 8 How many possible meanings a name keeps after branches merge. Past them its meaning is unknown.
limits.value_set 8 How many exact values a count or length keeps after branches merge. Past them only its range is kept, so {1, 5} becomes 1..5. Also the places an \openin stream keeps apart (texts and their lines) before it is unknown.

Writes through an unknown index

Registers behind an unpinned index

A write through an index not pinned to one number (\count#1=…) must hold for every register it may name (weaken_registers, src/engine/exec.rs):

Code tables behind an unknown character

A \catcode, \lccode, \uccode, \sfcode, \mathcode or \delcode write through an unknown character (tex.web § 1232) leaves every entry it may name at {old, new}.

Known limits

Where satex does not yet reach the invariant:

Limit What can be missed
executing a character of unknown category only an active character runs code (tex.web §§ 232, 344), and only its bindings are joined in. Groups, modes, files and \writes it would make are not. A name built from unknown text (\csname) may be any control sequence. Executing it is reported as unknown-text-run, assumed to change no state.
a recursion cut at its bound assignments are widened. A category the region changed is its old or its new one. Groups the region opened stand for any number of them (many), or are closed if they differ in kind (region-groups). Lines the rest would write to open files are assumed not written (region-writes): their top, unknown text in every open file, would make each later read of it unknown
a file the run wrote with unknown text that is also on disk read as on disk
the category of a control character, or of one from 128 to 255 under pdfTeX a LaTeX format's table is a fixed one: \the\catcode0 reads INITEX's 9 and ^^L 12, where latex.ltx sets 15 and 13 (control characters active or invalid). Text is read as characters, not as the bytes utf8.def makes active: \the\catcode128 reads 12 where pdfLaTeX gives 13
loops spanning call sites met again only through an undecided conditional, otherwise left to the stall limit
paths in different modes joined at \fi a vertical-mode and a horizontal-mode path join their lists as one, so text set after the join may be lost on both. Red test differential::text_past_a_par_ending_a_paragraph_on_one_path_is_set_on_every_path.
a definition site first run before the document starts or in a cached load counted as the first path's: a later run on that path replaces the text another path gave it there.
a list of names widened where no pass is checked (Reach::Havoc) holds only the names seen, as the class hull holds only the classes seen: a pass not run that adds another name is not covered

Soundness invariant

Every domain answers exactly or with an over-approximation that contains every real outcome. A construct satex cannot follow moves up the lattice and records why. It is never skipped or guessed. So a finding can be a false alarm at a stated limit, but nothing is silently missed.

When a finding is certain

An error is certain only if every run of the document has it. One mechanism decides that for every rule.

the facts at the place the finding its note
all certain, no row before error
on an undecided path warning "on a path the run could not decide: TeX may raise it"
after an assumption warning "holds if the assumption at ... holds"
after a gap info "may follow from the analysis gap at ...: check that first"

Why rows hold for the whole rest of the run: the path's approximated mark is cleared once the run is alone at top level, since unknown values mark their own reads. An assumption leaves no unknown value behind. Unknown text that ran as a no-op may have defined a name or ended the job. So the row itself is the mark, and it never clears.

The document's end follows the same rule. A missing \end{document} after such a row is the analysis' end (analysis-ended-early), not a certain missing-end.