Repository navigation
Commit a98630b
feat(quotations): tell the values of a quotation from its shape
Two runs of one query differ only in the values the quotation was
written with, so a query has to be translated once, and a later run
only has to find that translation and supply the values. The
parameterizer tells the two apart for a quotation in normal form:
- the values that become parameters, each at a numbered place, a slot;
- the key, ShapeKey: every node of the quotation without those values,
in a form that can be compared and hashed. A quotation cannot be its
own key: it compares its variables by identity, and every evaluation
of a quotation literal creates new ones;
- the template, for a query that has no translation yet: the quotation
with a variable at the place of every slot.
The rules:
- a literal is a part of the key: a boolean, a character, a string, an
integer or floating-point number, a value of an enumeration, unit and
null. The ADR made literals parameters and wrote a value declared
with Literal into the text, but the compiler writes such a value into
a quotation exactly as it writes 18, so the two cannot be told apart.
A decimal is no literal here: the compiler writes 18m as a call that
makes the decimal, so it is computed and is a slot, which keeps its
digits;
- a captured value is a slot named after its variable;
- a part that reads nothing of the document, the largest one at its
place, is computed by the evaluator and is a slot without a name;
- a tuple, record, union case or array that the quotation builds stays
what it is, because the translator has to see that Some limit is an
option with a value and that a list is written item by item;
- Query.constant and Query.parameter, two new public functions, say the
opposite for their argument.
The uses of one captured variable share a slot: same name, same type,
same value. A value bound by let is written at every place it is used
by the normalizer and is one node there, so it is computed once.
A choice whose condition is known before the query runs computes only
the parts of the branch it takes, as compiled code does: in
filter.IsNone || p.Name = filter.Value.Trim () nothing is trimmed
without a filter. The parts of the other branch are slots without a
value, and the key does not depend on which branch is taken. A
condition under Query.constant decides its branch the same way.
A function value that would have to be a parameter or a constant is
reported as CapturedFunctionValue, also when it is passed as an object
and the type of the part does not say what it is. An error about a part
that has no place in the source of its own, as a captured value has
none, gets the place of the nearest node around it.
The template is built only when it is asked for: building a node of a
quotation costs microseconds, and a quotation whose translation is
known needs no node built.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>1 parent 2322f3d commit a98630b
5 files changed
Lines changed: 978 additions & 4 deletions
File tree
- .github
- src/Cosmos.Quotations
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
19 | 21 | | |
20 | 22 | | |
21 | 23 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
| 28 | + | |
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| |||
0 commit comments