29. Editor and LSP (2026-11-21)
29.1. Hover shows the declaration's /// doc, wherever it is declared. Hover gains doc, read
from the lines above the definition definition_location finds (decorators skipped), so a stdlib name
shows the doc that states its cost. A member access records its owner type (HoverEntry::owner), so
hover and go-to-definition on bit.prefix reach the method in stdlib/fenwick.cp. The doc is the one
place a cost is written today; a computed cost line can join it later. Reverse: drop Hover::doc and
HoverEntry::owner in crates/cpl-check/src/{hover,check}.rs.
29.2. Neovim, Emacs and Helix get thin setups over cpl lsp, smoke-tested in the gate. Each
setup is the editor's own idiom (a Neovim runtime folder, an Emacs major mode registering with eglot
and lsp-mode, a Helix languages.toml) and holds no logic beyond highlighting and starting the
server, so a feature lands once, in the server. Their keyword lists are checked against
TokenKind::keyword by editors/smoke.sh, which scripts/check.sh --full runs, skipping (and
saying so) an editor that is not installed. Zed waits on a tree-sitter grammar, which it requires for
any language. Reverse: delete editors/{neovim,emacs,helix,smoke.sh} and the --full step.
29.3. The LSP latency budgets hold at the median, with the 90th percentile within twice the
budget. They were asserted on the slowest sample, and one descheduled request under the fast gate's
fully parallel load turned main red with no slow path in the server. The median of many warm samples
is what a user feels on each keystroke; the 90th-percentile bound still fails a slow path hit on more
than one keystroke in ten. Opening a file is now nine samples, not one. Reverse: assert max < budget
in report in crates/cpl-lsp/tests/latency.rs.
29.4. Semantic tokens come from the checker's resolved names, not from a second lexer. Each
name the checker recorded is a token, typed by what it resolved to (a domain is a type), so a client
colours what syntax can't tell: types against values, var against let. Keywords, literals and
comments stay with each editor's grammar, which already has them, and a name the checker could not
resolve gets no token, so the grammar's colour shows. Reverse: drop semantic_tokens and the
semanticTokensProvider capability in crates/cpl-lsp/src/server.rs.
29.5. Workspace symbols search the open files and the modules they use, not the disk. The
server has no project root of its own (a contest folder is a pile of single files), and what a
contestant looks for is in what they have open or import; a library module offers only its pub
names, so its tests and helpers don't crowd the picker. Matching is an in-order subsequence, as
editors' pickers expect. Reverse: walk the workspace folders from initialize instead of docs
in the workspace/symbol arm of crates/cpl-lsp/src/server.rs.
29.6. The server's run lenses are cpl argument lists, opted into by the client. A lens's command
is cpl.exec with the arguments to pass to cpl (run <file> <input> --trace), so a client needs one
generic handler (Neovim: a terminal split) rather than a command per action, and the server stays
the one place that finds samples and decides which lenses a file gets. It answers only when
initializationOptions.codeLens is true, because VS Code draws richer lenses of its own (results
inline, the trace panel) and would show both. Reverse: drop code_lenses, the codeLens arm and the
capability in crates/cpl-lsp/src/server.rs, and the handler in editors/neovim/plugin/cplang.lua.
29.7. Range inlay hints reuse the lint's bounds, top level only, for now. cpl_lint::proven_ranges
exposes what rules/bounds.rs already proves from declared input bounds (let n: 1..=100 makes
let m = n * n + 1 lie in 2..=10001), so the hint and the lint that warns about overflow can't
disagree; a single-value range (a literal) gets no hint. The general version is a range analysis in
the checker that hover, hints, widths and overflow proofs all read, which this should move onto.
Reverse: drop the proven lookup in the inlayHint arm of crates/cpl-lsp/src/server.rs and
proven_ranges in crates/cpl-lint.
29.8. Completion ranks by the expected type as text. The expected type comes from where the
cursor is (the parameter an argument is for, by name or position; a let x: T =; the variable an
= or op= assigns), and an item fits when its type, or the return type of a fn, is the same
text. Fits sort first; the rest keep their order. Comparing printed types misses fits through
generics and range-to-Int widening, but needs no inference at the cursor, which is usually
mid-edit and unparsed. The general version asks the checker for the expected type of a hole and
for assignability. Reverse: drop expected_type and rank in crates/cpl-lsp/src/complete.rs.
29.9. Signature help writes parameters as the declaration does. A default shows as = 1 and
named-only parameters follow a ;, so the label reads like the fn line. The active parameter is
the one an argument names (back: |), else the positional one at its place; named-only ones are
never positional, so past the last positional one none is active. Reverse: drop default and
named_only from SigParam in crates/cpl-lsp/src/complete.rs.
29.10. Rename edits every open file and the user library that declares the name. The files are
the open ones plus the declaring file, read from disk when it is not open; a contest folder has no
project root to scan, as with workspace symbols (29.5). A use is renamed when go-to-definition
takes it to the declaration, and a use m.{name} when it imports the name from that file. The
standard library's names are refused, and so is a new name already declared or imported at the top
level of a file the rename edits. Shadowing inside a fn is not checked yet. Reverse: put back the
target.path != uri refusal in the textDocument/rename arm of crates/cpl-lsp/src/server.rs.
29.11. Quick fixes go to the errors the broken ports hit first most often. The broken-ports
benchmark (crates/cpl-cli/tests/recovery.rs) now prints each first error's code and how often it
carries a fix: E0101 unclosed delimiter (1579, all fixed), E0102 expected a value (1413, none),
E0103 expected a token (790, 771) and E0004 unknown character (398, none). E0102 after an operator
and before a value is a doubled operator, so its fix removes the second one (584 of the 1413); E0004
replaces # with //, a Unicode ≤ ≥ ≠ × − with its ASCII operator and removes anything else. The
fix is on the diagnostic, so cpl check, the LSP and every editor get it, and the LSP test applies
each to a real port broken that way. Reverse: drop doubled_operator in
crates/cpl-syntax/src/parser/expr.rs and the with_fix after UNKNOWN_CHAR in lexer.rs.
29.12. An unclosed bracket's fix inserts the closer where it was most likely dropped. With one
bracket open, the fix goes before the first = or assignment, the first : that ends the line or
sits in a [, or a for inside an index (if a[i] == b[i: becomes b[i]:); otherwise, and in a
type ([0..nInt), it stays where recovery closes. Recovery itself is unchanged: the token stream
still closes at the end, because closing earlier left the rest of the line outside any bracket and
raised the benchmark's cascaded errors from 194 to 259. recovery.rs now also counts whether a
first fix restores the port's line and leaves no error: E0101 restores 451 → 582 of 1612 and checks
clean 814 → 950; cascades stay 194. Reverse: use close_at for the fix in close_unclosed.
29.13. The trace viewer talks to the editor through two messages. In a webview the viewer posts
{type: "step", line} when the shown step moves to another line and {type: "reveal", line} when
a source line is clicked (TraceCore.editorLink in tools/trace/index.html); in a browser it posts
nothing. VS Code keeps one trace panel per file, reused by the next trace, highlights the step's
line in the file and moves the cursor on a click. Any editor with a webview (JetBrains' JCEF) can
speak the same two messages. A unit test feeds what the real viewer posts to the extension's
parser, so the two sides can't drift. Reverse: drop editorLink and src/traceView.ts and create
a fresh panel per trace in Runner.trace.
29.14. A checker error whose span takes in poisoned code is dropped. f(a[i, j) closes the (
and reports the [ as unclosed, but the call then sees two arguments in a[i, j and one in the
call, and reported E0303 or E0305 before the real cause on the same line. Sinks already dropped
errors inside a poisoned span; Checker::error now also drops those whose span contains one
(Sink::encloses_poison), since an error about all of an expression that holds unreadable code is
an echo of the syntax error. Broken ports: cascaded errors 187 → 145 of 4319, first error on the
right line 99.7% before and after, E0303 17 → 0 and E0305 13 → 0 as first errors (now the
E0101 with its fix). Reverse: drop the encloses_poison check in Checker::error.
29.15. The JetBrains plugin uses the IntelliJ Platform's own LSP API. It starts cpl lsp through
platform.lsp.serverSupportProvider, so every server feature reaches it with no client code, and
it adds only what the server can't: a highlighting lexer (keywords checked against the compiler by
editors/smoke.sh), run configurations, a run marker and the trace viewer in a JCEF editor tab.
That API ships only in the commercial IDEs from 2024.3, so Community and Android Studio get
nothing; LSP4IJ would reach them but is a third-party plugin and a second client to keep working.
--full runs buildPlugin when java is installed; the platform tests join it once they have run.
Reverse: delete editors/jetbrains/ and its block in editors/smoke.sh.
29.16. The server publishes the lints, and cpl fix is its fix-all. After the checker's
diagnostics it publishes what cpl lint reports under the file's cp.toml, each lint's fix a
quick fix, and a source.fixAll.cpl action applies cpl fix to the buffer (the same
apply_fixes loop to a fixed point), so an editor's fix-on-save and the command line rewrite
alike. Lints run on the whole file on every edit: 492 lines open in 10 ms and a keystroke
reaches diagnostics in 5 ms (debug build). The playground's build leaves them out: the lint
rules added 85,600 B to dist/cp-lang.html and took it over its 2,600,000 B cap. Reverse: drop lints from diagnostics and
codeAction in crates/cpl-lsp/src/server.rs.
The fix-all is cpl_lint::fix, the same function cpl fix runs: first the removed-syntax
rewrites the parser offers (where as a filter, --- multitest ---), since a file that
does not parse gets no lints, then the lints; so a file with where and xs.len() comes out
with if and xs.len in one action. The replaced spellings (.pow as L0205, getter () as
L0206, the removed syntax as E0503) reach the editor as quick fixes with no editor code of
their own. Reverse: inline fix_removed_syntax back into crates/cpl-lint/src/cli.rs.
29.17. Every member read hovers. Hover entries were recorded only on the struct path of
Checker::field; a built-in member (xs.len, a position's next) returned earlier and had no
hover. field now wraps the lookup and records the entry when the lookup did not, so a getter
read without parentheses hovers its type whatever owns it. Reverse: inline field_ty back
into field in crates/cpl-check/src/check/expr.rs.
29.18. Hover states the documented cost and the proven range. A hover on a fn or member
whose /// doc (stdlib) or catalog line (built-in members) states an O(...) adds a
cost: line with the first one, so the cost is read without parsing prose; a built-in
method whose call is typed later (xs.sorted()) hovers its catalog signature. A top-level
let hovers the range cpl_lint::proven_ranges proves, the same one its inlay hint shows.
The cost comes from the docs because the docs already state every stdlib cost (AGENTS.md); a
computed cost would need a cost analysis the checker does not have. Reverse: drop cost_of
in crates/cpl-check/src/hover.rs and the range branch of textDocument/hover.
29.19. Proven ranges reach into fns and loops. cpl_lint::proven_ranges walks fn bodies,
for, while, unchecked and plain if blocks with a copy of the top-level bounds: a typed
range parameter (k: 1..=n) and a loop over lo..hi bind their range, a let binds what its
value proves, and any other binding of a name forgets its bound, so a shadowing local never
inherits one. Intervals stay non-relational (5 * k - 4 * k is not k), the same arithmetic the
lint already proves overflow with. vars get no range: a later assignment would make it a lie.
Hover adds the range only to a binding typed Int; a loop variable already hovers i: 0..k.
Reverse: restore the top-level loop in rules::proven_ranges.
29.20. A misspelled option is a quick fix; signature help points at the next option. The
checker's "did you mean" for an unknown argument name (E0310) and for a trait fn now carries
the same change to fix an unknown field already had, so xs.reach(cylic: true) is one click
from cyclic:. Past the positional parameters signature help marks the first named-only
parameter not given yet, instead of none: for reach(while:, cyclic:), where every parameter
is named-only, nothing was ever marked after the first. Reverse: drop the two fixes.push in
check/call.rs and check/stmt.rs, and the fallback in complete.rs::active_param.
29.21. A token-level tree-sitter grammar, for highlighting only. editors/tree-sitter-cp
gives Helix, Neovim and Zed highlighting from one grammar: a flat sequence of tokens with
fn names, calls, members, types and constants picked out. It has no blocks, so it needs no
indentation scanner, and a half-typed line cannot turn the rest of the file into an error;
every port and library parses without one. Folding and semantics come from cpl lsp, which
already folds and sends semantic tokens. The parser is generated at ABI 14, which Neovim 0.10
and Helix 25.01 load (15 they do not). Each editor's capture names differ, so each has its own
copy of the queries, and the smoke test checks the patterns stay the same. Reverse: a full
grammar with an external scanner for indentation would add folds, indents and text objects.
29.22. Each editor's smoke test drives the server its setup starts. Neovim and Emacs run
headless, so their tests are the editor itself (Emacs over jsonrpc.el, what eglot is built on,
since Emacs 27 has no eglot). Helix has no headless mode: its test checks hx --health and
the grammar build, then editors/lsp-smoke.py starts the command its languages.toml names
and checks initialize and the published error. Reverse: drop lsp-smoke.py and keep
--health.
29.23. Zed gets an extension that pins the grammar's commit. A Zed language comes only from
an extension, and Zed builds an extension's grammar from a git repository at a fixed commit, so
editors/zed/extension.toml names the commit that last changed editors/tree-sitter-cp, and
editors/zed/smoke.sh fails when the tree's grammar differs from that commit's (move rev
forward in the same push). The extension starts cpl lsp from the PATH unless Zed's
lsp.cpl.binary setting names another. zed_extension_api pulls smallvec, pinned in its
Cargo.lock to a release old enough for the package proxy. Reverse: delete editors/zed.
29.24. A lambda passed to a built-in method gets its parameter types from the catalog. In
xs.map(x => ...) the checker types the call from the receiver, and inferred the lambda with
untyped parameters, so x, and every let in a block body after =>, hovered as _ and got
no inlay hint. Now the catalog row's parameter type (f: T -> U, while: (T, T) -> Bool)
gives each unwritten parameter its type, with T the receiver's element, before the lambda is
inferred: one rule for every built-in method that takes a lambda, and the body is checked with
real types. Reverse: drop catalog_lambda_params and the lambda_params field.
29.25. The editor's overflow warning names inputs the prover found, and is a note. An
interval hull that leaves Int is only a suspicion (a - b with a >= b known, a var's
hull), so the editor asks cpl-prover for inputs in their declared ranges that overflow the
operation and shows a soft note only when it finds some: area * area overflows Int when n = 55109. Only names it can follow take part (range-typed inputs and params, immutable lets of
arithmetic over them); a narrowed name, a loop variable or a var makes it say nothing, so a
note is never a false alarm. It is a note in the editor, not a lint, until the checker owns
ranges; it fires on none of the 305 ports and examples. Reverse: drop Bounds::overflow and
overflows in the server.
29.26. vars that read each other get one joint hull. A binary search's lo = mid + 1
reads mid, a let in the loop, and mid reads hi, a later var, so solving one var at a
time gave none of them a range. Now each var's hull is solved with every var and let in
its scope that one place in the file binds (so each use reads that binding), iterating to the
least fixed point (up to 72 rounds, enough to halve a gap of 10^18). A var that never settles
is dropped and the rest solved again. Top-level statements now keep the ranges of names bound
above them; fn and impl bodies still see only declared ranges, since they may run anywhere.
Reverse: restore var_range's one-name solve and the per-statement Bounds clone.
29.27. A loop with no break leaves its condition false, and a fn's writes block narrowing.
After while w > 9: with no break and no else, the statements that follow see w <= 9,
unless they assign w. A name that any fn or lambda body assigns is never narrowed, by a loop or
an if, since a call can change it between the test and the use. Reverse: drop the post-loop
narrow call, breaks and Bounds::fn_writes.
29.28. An assignment in a while body reads the names its condition bounds. c += 1 under
while c < n: sees c < n, so c keeps 0..=n instead of having no range. Only assignments
directly in the body, and only names no earlier statement there assigns. Hulls now grow until a
round of assignments stays inside them, jumping to the edge of Int after 64 rounds, then shrink
while each round stays inside: a guarded counter's first hull is wider than it needs. Reverse:
drop guarded and its lookup in var_range's round.
29.29. Completion offers stdlib names that need a use, and adds it. Before, a name outside
the prelude completed only after its use was written, so the contestant had to know the module.
Now names of two or more letters complete from every stdlib module, ranked after what is in
scope, with the module shown and the use as an extra edit. The unresolved-name quick fix had put
its use at the start of the item holding the name, possibly mid-file; both now share
cpl_check::import_edit, which joins the module's existing use line or goes below the last one.
Reverse: drop the STD_NAMES loop in scope_completion and the fix rewrite in Database.
29.30. Rename reaches files on disk that import the name. A contest folder holds one solution
per problem, most of them closed, all importing the same lib. Renaming a library fn from one file
left the closed ones broken. Rename now also edits each .cp file of the project (the folder of
the nearest cp.toml, else the file's own) with a use line naming the old name, checked by the
same go-to-definition test as open files. The scan reads at most 5000 entries and skips hidden
folders, target, dist and node_modules. Reverse: drop rename::project_files.
29.31. A comparison of two names bounds their difference. Intervals alone give n - a in
-8..=100 inside if a < n:, though it is at least 1. The bounds now keep, per pair of names, an
interval for a - b that a condition proved, and a - b is cut to it. A pair is forgotten when
either name is bound again, and never recorded for a name the branch or any fn assigns, so the
relation holds wherever it is read. Only a difference of two plain names reads it, which keeps the
analysis linear (no closure over chains like a < b < c). Reverse: drop Bounds::diffs.
29.32. A for loop's head hovers how often it runs, with no warning. plan/60 asks for the
estimate and for a soft warning on likely TLE. The count is the size of the range or domain the
loop walks, times the counts of the fors around it; a while or a walk over a list makes the
total unknown, and a fn body counts from 1, since its callers are not followed. On the ports and
examples 12 of 1307 counted loops pass 1e10 in all, in solutions that pass their tests, so the
bound overstates the work there and a warning on it would be a false alarm; the warning waits for
a cost the checker derives. Reverse: drop proven_loops and loop_hover.
29.33. A relation holds until a statement assigns one of its names. 29.31 recorded no relation
for a name the block assigns anywhere, so a binary search's body, which always assigns lo or
hi, got none. A loop's condition holds at the top of each pass, so the relation is now recorded
regardless and dropped before the first statement that assigns either name (a compound statement
counts as a whole, so a nested loop that writes the name drops it before it is entered). let m = (x + y) / 2 relates m to both ends: m - x is half of y - x rounded down, y - m half rounded
up. Reverse: pass the block back to relate and drop relate_midpoint.
29.34. Relations follow assignments, ifs and while loops. After x = y + c (also x += c),
x - z is y - z shifted by c for each relation of y. The branches of an if start from what
held before it, and after it each relation every branch (and the fall-through) proves holds, as their
hull; names a branch declares are left out. A while that compares two names its body assigns
starts from their difference on entry (a var holds its initial value until assigned), runs its
body again until that stops widening, at most three times, and keeps the result as an invariant
inside the loop and, with no break, after it, where the failed condition then narrows it: a
binary search ends with lo - hi = 0. A body with continue gets no invariant, since continue
returns to the condition without the rest of the body. A test that narrows a name now keeps its
relations. A difference that is a constant only because of a relation hovers as = 0. The extra
body passes cost at most four times a loop's analysis, more for nested searches; the latency gate
still passes. Reverse: drop carried, join and loop_invariant.
29.35. Rename is refused when it would change what a name means. Before answering, the server
applies the edits to every file it renames in, re-checks them, and asks go-to-definition again at
each use of the old and the new name; if any resolves to a different declaration than before (two
locals merged, x captured by a nearer let y once x becomes y, a global shadowed), the rename
is refused with the line of the first such use. With that check, the old blanket refusal of a name
already declared at the top level applies only when the renamed declaration is itself top-level, so
a local may take a global's name it doesn't use. Uses in files the rename doesn't edit are not
re-checked. Reverse by dropping rename::changed_meaning and the top_level condition.
29.36. Hover shows why an index is in bounds. xs.len becomes a name the relations track
(xs.len) when xs is bound once and never assigned, lent, passed mut or the receiver of a
method call anywhere in the file, so its length never changes; it is in 0..=i64::MAX. Then
var hi = xs.len relates hi to it, var (lo, hi) = (0, xs.len) binds each name as its own var,
let mid = (lo + hi) / 2 relates mid to whatever lo and hi are related to, and for i in 0..xs.len keeps i < xs.len. An index xs[i] with i at least 0 and i - xs.len below 0 hovers
the chain that proves it (0 <= lo <= mid < hi <= ys.len). Ranges a .len bounds only by that
type limit are not shown. Two changes came with it: a while invariant that still moves after two
rounds widens to what the names' values allow instead of being dropped, and a write in a fn to a
name that fn declared earlier no longer counts as a write some call could make, so a fn's own locals
get relations; an if test is read before the branches' assignments clear relations. Reverse by
dropping Bounds::fixed/atom (back to plain names), in_bounds and index_hover.
29.37. A list's length is fixed once nothing changes it any more. A sequence bound once whose
length some statement changes (push, assignment, mut argument, any method call on it) has its
.len tracked from the end of its last change, or of the outermost loop around that change which
its declaration is outside of, since the loop's next turn could change it again. A change inside a
fn or lambda body declared outside the sequence's own scope could happen at any call, so that
sequence gets no fixed length. A .len read before that point is not a name the relations know,
so no fact about it is made where it could still move: xs[i] followed by xs.push gets no proof,
even though the push comes after the use. Ports and examples with an index proof: 64 to 121, none
lost. Reverse by dropping Bounds::stable (back to sequences no statement ever changes).
29.38. A row's length is a name too. g[u].len joins the relations when g is bound once,
u is a plain name, and nothing changes the length of any row of g from that point on: a change
to g itself or to some g[e] (assignment, mut argument, method call such as g[e].push) counts,
a change to an element g[e][f] does not. The rows are tracked as one sequence, so pushing to any
row stops every g[_].len proof, even for a different row. A fact about g[u].len is dropped
wherever u is assigned or bound again. for j in 0..g[u].len: g[u][j] gets 0 <= j < g[u].len;
ports and examples with an index proof: 121 to 137. Reverse by dropping the Index arm of
Bounds::atom and row_of.
29.39. A length is a name that statements change, like a var. Supersedes the offsets of
29.37: xs.len of a tracked sequence (bound once, changed only by statements of its own scope) is
in the relations everywhere, and a statement that assigns, lends, passes mut or calls a method on
xs (g or g[e] for g[u].len) drops what was known about it, the way an assignment drops a
var's. A length changed inside a statement is dropped before anything in that statement reads it,
so q.pop()! + q[head] gets no proof. This proves the breadth-first queue, while head < q.len: let u = q[head] followed by pushes, and a search re-run after each pop. A method call counts as a change
unless every built-in list or string method of that name leaves its receiver alone (contains,
sum; not sort, whose length stays but which the catalog marks as mutating; on wasm, every call
counts). Ports and examples with an index proof: 137 to 177, none lost.
Reverse by restoring Bounds::stable from 29.37.
29.40. A domain array's index is proven by its type. The checker records each index of a
[V]T or [R, C]T whose every index is a V (a domain position, or the same type parameter in a
generic fn), and hover shows xs[v]: in bounds, v: V, the index space of xs. The type is the
proof, so no range analysis is involved; an index whose type is unknown (tree.parent(v) today)
or a slice gets nothing. dp[v, k] over domain State = (V, K) and g[p] with p: (R, C)
count too; a subdomain position does not, since its name alone is not the array's domain.
Reverse by dropping TypedIndex and the fallback in the LSP's index_hover.
29.41. A fn's hover counts the loop iterations of one call. Hovering a fn with a loop shows
loops: at most 1600000 (1.6e6) iterations per call, with the fns it calls; methods and the stdlib not counted: the sum over its for loops of how often each body runs, nested loops
multiplied, from the same proven counts as a loop's own hover, plus for each call by name of a fn
in the file how often the call runs times that fn's count. A while, a for with no proven
count, recursion, or a call inside a lambda, table or comprehension makes the total unknown, and
then nothing is shown; of the 1,334 fns in the ports and examples with a loop or such a call, 106 get
a count (147 of 1,095 before calls were followed, when a call to a fn that never stops was simply
left out). Method calls, stdlib costs and comprehensions themselves are not counted,
which the text says; this is an iteration count, not the O(..) estimate plan/60 asks for. Reverse by dropping
proven_fns and its use in the LSP hover.
29.42. A loop's count is named in the source's terms. The for hover reads runs at most k = 7 times and n * k = 1400000 (1.4e6) times in all: a range 0..q or 1..=q counts as q,
a domain declared 1..=n (or 0..n) as n, and any other range as its number, so 2..q + 1
shows 999, not q - 1. A count that is only numbers is not repeated. A fn's hover writes its
count the same way, as a sum with equal terms gathered (3 + 3 * n + 3 * n * k = 4800003), and
only the number past six terms. Reverse by dropping
ProvenLoop::count and total_count.
29.43. A fn's hover lists its calls' documented costs, not a sum. Each call in the fn's body
whose doc states a cost above O(1) (the same cost: its own hover shows) is listed with how
often it runs per call: once, a loop's count (n = 200000 (2e5) times), or an unknown number of times inside a while, an unbounded loop, a lambda, a table or a comprehension; calls in a
nested fn are left to that fn. The cost's n is written as the receiver's size (ys.sorted O(ys.len log ys.len)), since the n of a doc is not the input n. They are not added into one
O(..) with steps at max input: most receivers' sizes have no proven bound, and 102 of the 152
built-in methods document no cost, so a sum would silently leave them out. At most four are
listed, then and k more. Reverse by dropping Database::costs_in and fn_call_costs.
29.44. A call on an array of bounded size shows its steps at max input. When the receiver is
a let or param whose declared type is an array over domains or ranges the bounds size ([V]Int,
[0..q]Int, [R, C]Int), the cost's n is written as that size in the source's terms (O(n log n), O((n * 3) log (n * 3))) and evaluated at the size's maximum, logs base 2, as about 3521929 (3.5e6) steps each. Only costs built from n, numbers, log, ^, *, + and parentheses are
evaluated; any other name (deg u, |D|) leaves the cost unevaluated. A List receiver has no
size, since pushes change it: 9 of the 627 listed calls in the ports and examples get steps. The
steps are not multiplied by how often the call runs, nor summed into the fn's. Hovering such a call
anywhere, top level included, adds the same steps to its cost: line (about 3521929 (3.5e6) steps: cells has at most n = 200000 (2e5) items). Reverse by dropping proven_sizes and steps_of.
29.45. A list built by pushes in counted loops has that many items at most. A list bound once
as var xs: List<T> = [], whose length only push and pop change, all in its own scope (no fn,
lambda, assignment, lend or mut argument touches it), has at most the sum over its push calls
of how often each runs: 2 * n for two pushes in for k in 0..n, n + n * q + 1 across nested
loops. A push inside a while, an unbounded for or a lambda leaves the list unsized, and so does
a count that reaches LEN_MAX (a loop over 0..xs.len). The size feeds the steps of 29.44: of the
1,278 calls with a documented cost in the ports and examples, 56 get steps, 17 of them on lists.
Along with it, sort, reverse, swap and fill count as keeping a list's length (amending
29.39): the catalog marks them mutating, but they only move or overwrite elements, so a sort no
longer drops an index proof. Reverse by dropping Bounds::pushed and keeps_len's IN_PLACE.
29.46. A fn's hover estimates one call's steps only when nothing is left out. When every loop
of the fn has a count and every call outside the fns of the file has a documented cost that can be
evaluated, the hover shows estimated cost: O(n + n log n), about 3721929 (3.7e6) steps at max input in place of the loop line: its loop iterations, plus each documented call's steps times how
often it runs, an O(1) call counting one step. The O(..) is the sum of those terms in the
source's terms, dropped past 100 characters. Any uncounted part (a lambda, table or comprehension;
a call whose doc states no cost, such as print, min or push; a cost on a receiver of unknown
size; a call through an expression) means no estimate, so the number is never an undercount of
what it names. Operators and getters count as one step each: no doc states otherwise, and a string
+ is the one known exception. Only 13 of the 2,142 fns in the ports and examples get one: of the
694 whose loops all have a count, the calls most often left without a cost are push (66 fns),
min (33), read (31), max (30), print (27) and type constructors (Node, Int, some).
Reverse by dropping ProvenFn::callees and fn_total.
29.47. The compiler's own prelude fns hover with a doc and the cost of their call's shape.
abs, min, max, minmax, choose2, popcount, ctz, bit_width, bit_ceil, isqrt,
swap and some have no cp source, so they hovered nothing; prelude::value_doc now gives each a
one-line doc with its cost, and push and pop document O(1) in the built-in catalog. The cost
follows the call's shape: min(a, b) is O(1) per argument, min(xs) walks xs in O(n). With
these, fn spread in the hover fixture (a loop of min(least, abs(cells[v]))) gets estimated cost: O(n), about 600001 (6e5) steps at max input. Assumption: comparing two values counts as
O(1), like an operator, though min of two lists compares them element by element. print,
read and type constructors still document no cost, since what they cost depends on the size of
what they write, read or build. Reverse by dropping value_doc and its fallback in
Database::hover.
29.48. Building a struct declared in the file counts as one step. A call Span(lo, hi) to a
struct of the file only moves its arguments into the fields, so ProvenFn::builds lists it and a
fn's estimate adds one step per time it runs, instead of leaving the fn without an estimate.
fn widest in the hover fixture (a loop building a Span from min and max) gets estimated cost: O(n), about 800001 (8e5) steps at max input. Assumption: a field default is a constant, so
building costs nothing beyond the arguments, which are counted where they are written. A generic
struct (Pair<Int>(..)), a variant and a built-in type such as List(xs), which copies, stay
uncounted. Reverse by dropping builds.
29.49. print and read cost O(1) when their values have a fixed size. The checker records
in ItemCheck::fixed_io a print whose arguments are all numbers, characters, tuples of them or
strings of fixed text around them (print(a + b, "and {a * b}")), and a let of a declared fixed
type bound to read() (let (a, b): (Int, 1..=9) = read()); their hover says cost: O(1), so a
fn's estimate counts them as one step. Any other print or read hovers a doc with no cost and
still leaves the fn without an estimate. Fns in the ports and examples with an estimate went from
25 to 28 of 2,150; ask (20 fns), print and read of lists or strings, and Int(..) are now
the calls that most often block one. Assumption: a position counts as not fixed, since its label
may be a string. Reverse by dropping fixed_io.
29.50. ask, scalar conversions and rand cost O(1) too. ask bound by a let of a
declared fixed type, with fixed-size arguments (let r: 0..=1 = ask("?", c)), joins read in
fixed_io, and so do Int(..), I128, U64, F64, Char and Bool of one fixed-size
value; rand() and rand(lo, hi) are always O(1). Fns in the ports and examples with an
estimate went from 28 to 35 of 2,158. Assumption: ask's cost leaves out the judge's own time,
which the contestant does not pay for in steps; an ask whose reply is not bound with a declared
type still blocks the estimate. Reverse by dropping the ask, conversion and rand cases.
29.51. A method's cost may name its struct's domains. A doc's |D| or D.K, for a type
parameter D of the method's struct, is written as the receiver's domain: bit.sum on a
Fenwick<V, Int> hovers cost: O(log |V|), and a fn's estimate evaluates |V| at the most
positions the bounds give V. The Fenwick trees' methods now state their cost this way, e.g.
O(log |D|) for add; a doc's bare n is still evaluated only as the receiver's length, since
it means different things on different structs. Fns in the ports and examples with an estimate
went from 35 to 39 of 2,161. Building a stdlib struct (Fenwick<V, Int>(a)) still blocks an
estimate. Reverse by dropping in_receiver_domains and domain_steps.
29.52. The built-in catalog states the cost of 79 more methods. Each is the cost of the
interpreter and runtime it lowers to: sorted searches (first_ge, last_lt, ..) on a list,
string or array are O(log n); contains, count, sum, fold, copy, reverse and the
like are O(n); Map and Set lookups, inserts and removals are O(log n), as are
Set.min/max, which the interpreter's ordered set finds by descending the tree. A method that
takes a fn (fold, all, filter) states the cost with an O(1) fn; a fn's estimate already
counts a lambda as unknown work. 43 methods still state no cost, most of them getters. No fn in
the ports and examples gains an estimate (39 of 2,166): every fn first_ge blocked is also
blocked by something else. Reverse by dropping the added O(..) sentences.