Status: accepted (CMD-485, from the inbox's IN-7, CR-227, 2026-11-29), for 0.14.
What a host learns of the paths an expression reads under a root, md.doc say, through comprehension variables too. Today compmd::cel::Program::selections(path) and indexings(path) list the fields read by dot and by index directly under a fixed path; in md.doc.tasks.map(t, t.hours) neither says that t.hours reads hours of the elements of md.doc.tasks, and a host can't work it out safely, since comprehensions nest and a variable may hide another of its name.
A host whose records hold records needs it to:
- rename a field wherever an expression reads it (
hoursint.hours, inmd.doc.tasks[0].hours); - read only what an expression reads, as deep as it is written (
md.doc.book.author.name, thehoursof each ofmd.doc.tasks); - type records only along those paths, since a
cel::Typehas no recursive or named records, and a schema with cycles (a task's parent task) can't be typed whole.
-
A method of its own,
Program::paths(root).selectionsandindexingsstay as they are, for their callers (the language server's key rename).paths("md.doc")gives each path the expression reads undermd.doc, in the order written, each a list of segments:Field { name, range, by }: a field by dot (.title,.?title,has(x.title)), or by a string literal index (["title"],[?"title"]);rangeis where the name is written in code points: the name after the dot, or the whole literal, its prefix and quotes with it, so a host rewrites it as a literal;byisDotorIndex.Index { at }: an index that isn't a string literal, a number ([0]) or computed ([i],[name]): a list's element or a map's value, whichever the value is.Each { at }: what a comprehension over it binds its variable to: a list's elements, or a map's keys (CEL iterates a map's keys);atis where the macro's name is written.
-
A path is as deep as written, and one is given for each place it ends.
md.doc.book.author.nameis one path,book,author,name; it ends where the chain of dots and indexes does: at an operator, a call (md.doc.title.size()readstitle), or the expression's end.md.docread whole is a path with no segments. -
A comprehension's variable carries its range's path. In
md.doc.tasks.map(t, t.hours),tstands fortasks,Each, sot.hoursis the pathtasks,Each,hours. The range itself isn't given as a path of its own when the variable is read, since the variable's paths say how far it is read; it is when the variable isn't (md.doc.tasks.all(t, true)readstasks,Each). Variables nest (t.subtasks.map(s, s.hours)istasks,Each,subtasks,Each,hours), and a variable hides one of its name, and the root's first name, inside its comprehension, as inselections.optMapandoptFlatMapbind theirs to the optional's value, so it stands for the optional's path itself:md.doc.?book.optMap(b, b.author)isbook,author(settled in building it). The paths come in the order they end in the expression. -
filterpasses its range's elements on.md.doc.tasks.filter(t, t.done)is a list oftasks' elements, so what is read of its elements is read oftasks' elements:- a comprehension over it binds its variable to them: in
md.doc.tasks.filter(t, t.done).map(u, u.hours),u.hoursistasks,Each,hours; - an index of it, plain or optional, is one of them, though not the element of
tasksat that index: inmd.doc.tasks.filter(t, !t.done)[0].hours, the first open task's hours, the path istasks,Each,hours, and so it is for[?0].?hours; - the list read whole (
.size(), an operator) readstasks.
A
map's result is new values, and no other macro's result is a list of the range's, so nothing read of them is oftasks. - a comprehension over it binds its variable to them: in
-
What is read of a value with no path isn't given. A variable whose range has no path under the root (a
map's result, a list built by+or?:, a list literal) is a value of its own: inmd.doc.tasks.map(t, t.owner).map(o, o.name),t.owneristasks,Each,owner, buto.nameis no path, and isn't given. A host that types records along the paths an expression reads types such a variable asdyn, so its fields aren't checked. -
checkis unchanged. Typing records lazily, by path, would change the checker'sScopefor every caller; withpaths, a host builds its types along the paths an expression reads, before it checks it. A host that types a record with only the fields read can't suggest the field meant for a misspelt one (t.hors), so it types each record on a path with all of its own fields and stops at the records it links to that no path reaches; that is the host's, and needs nothing more of the processor (settled with the requester in CR-227). A follow-up, if a host still needs lazy types. -
Rust only. The WebAssembly package doesn't give
selectionstoday, and the host that asks uses the crate.
| Expression | paths("md.doc") |
|---|---|
md.doc.price * 2 |
price |
md.doc["due"] < md.today() |
due (by index) |
md.doc.book.author.name |
book, author, name |
md.doc.tasks.map(t, t.hours).size() |
tasks, Each, hours |
md.doc.tasks.filter(t, t.done).map(u, u.hours) |
tasks, Each, done; tasks, Each, hours |
md.doc.tasks.filter(t, !t.done)[0].hours |
tasks, Each, done; tasks, Each, hours |
md.doc.tasks.map(t, t.owner).map(o, o.name) |
tasks, Each, owner (o.name reads a value with no path) |
md.doc.tasks.exists(t, t.parent.done) |
tasks, Each, parent, done |
has(md.doc.book.author) |
book, author |
md.doc.tasks[0].hours + md.doc.tasks[i].hours |
tasks, Index, hours; tasks, Index, hours |
md.doc.tasks.all(t, true) |
tasks, Each |
md.doc.tasks.map(md, md.doc.x) |
tasks, Each, doc, x (the variable md hides the root: it is the element) |
size(md.doc.tags) |
tags |
md.doc |
(no segments) |
crates/processor/src/cel/paths.rs: the walk,ReadPathandSegment, besideselections.rs;Program::pathsincel.rs, documented with an example.- Tests: each row above, nesting, shadowing, optional selection and indexing, ranges in code points.
- The processor's README, 0.14.0's entry.