Repository navigation
Description
DONE. Where each declaration
marker is legal, how many times, and what it conflicts with - as
DATA, driving validation and emission instead of being restated in
prose and in scattered ifs.
Where it comes from
Carl found akoen/nanobindgen (alpha) and asked whether it had
anything for us. It runs the OPPOSITE direction - tree-sitter over C++
headers, reading @nb_* Doxygen tags the author added, emitting
nanobind - so it cannot bind Nix at all: we do not own
nix/store/store-api.hh and cannot annotate it. Nothing to adopt
wholesale.
One idea is worth taking, and it is tags.py:
TAG_SCHEMA: dict[str, Tag] = {
"nb_static": Tag(target=_t("method"), arity="flag",
takes_value=False,
excludes=_e("nb_init", "nb_new")),
"nb_prop_ro": Tag(target=_t("method"), arity="once",
excludes=_e("nb_init", "nb_new",
"nb_prop_rw", "nb_name")),
}
One table, driving BOTH validation and emission. Its validate.py is
then a generic loop over the table rather than one hand-written check
per rule.
What we have instead
Nineteen decorators in declare.py, each a function that sets a field
on a Decl or writes an attribute on a function. Where each is legal
is stated in PROSE, in that decorator's docstring, and enforced
nowhere - or enforced by a bespoke if somewhere in read.py, which
carries 28 DeclarationError raises.
derives abstract tree startup translator header produced words
binding wire_value custom cxx_name blocks local reads needs
instant threading binds
One marker means two things, and the case that separates them is
real. @abstract says "the C++ type has pure virtuals" in the
declaration. Three emitters read it as "Python may not construct one":
nbemit skips the constructor, emitter.py refuses Async<X>() and
skips the wrapper, and smoke_test requires the refusal.
nix::Store is both abstract AND opened through nix::openStore, so
declaring the true fact about it breaks all three - verified, 24
tests. Every store this repo hands back is really a nix::LocalStore
or a nix::UDSRemoteStore, and the declaration cannot say so today.
The fix is the shape this task is about: the declaration states the
FACT, and the manifest carries the DERIVED question each layer asks -
"is there a door" - computed once instead of re-interpreted three
times.
Rules that exist and are not data:
@readswith parameters - refused by one hand-written check,
written only when a declaration first hit it.@needson a CLASS - worked by accident, then on purpose, and
nothing says which targets it takes.@instanton a class whoseblocking=False- meaningless, and
unchecked.@pureexcluded nothing while it existed;@virtualhad no target
restriction. Both are gone now (060), and neither absence was
noticed by anything.@localon a method of a class that is not a wire value - harmless
and silent.
This is the same class of bug the union arms hit, where "what may be
an arm" needed four separate refusals written by hand.
What it would look like
A MARKERS table in declare.py, keyed by decorator name:
target which of class / method / free / module
arity flag, once, repeatable
excludes markers it cannot appear with
requires markers it needs (`@pure` needed `@virtual`)
read.py's _apply already runs every decorator against a stand-in
and reads what was written, so it is one loop away from checking the
table at the same time. The 28 raises do not all go - some are about
SHAPE rather than markers, like "a declaration body is a docstring
then at most one Cxx" - but the marker ones collapse into the loop.
Two smaller things from the same file
Diagnostics carry path:line:col. Ours carry a line number and
the text. A path matters once a declaration imports another and the
error is in the imported one.
Errors are COLLECTED, not raised. ErrorCollector gathers every
diagnostic and reports them together; ours raises on the first. Fine
for a build gate, worse for a person fixing three mistakes in one
declaration.
Their unknown-tag error also runs difflib for a "did you mean
@nb_name?" suggestion. Cheap, and it is the kind of thing that pays
for itself the first time somebody writes @read for @reads.
When
AFTER the store hierarchy (060 step 3). That step adds markers -
@derives and @abstract on a real C++ base, where today they exist
only for the mock - and a schema written against what the markers
actually need beats one written against a guess. Doing it first would
mean designing the table for markers that are about to change.
That precondition is dead, and waiting on it is waiting for
nothing. 060 closed by DELETING the mock rather than porting the
hierarchy. @derives is gone from declare.py entirely, and
@abstract has no users at all. There is no step coming that adds
them, so the table was right to be built without it - and the
@abstract split is now blocked on a DECISION rather than on work.
Done
The table exists. declare.MARKERS is 23 entries keyed by decorator
name, each carrying target / arity / excludes / requires, and
every marker in declare.py has one.
read._check_markers is the generic loop the task asked for, called
from _apply, so every marker on every target passes through it
once. It checks the legal target, flag-vs-called arity, "may appear
once", and both directions of excludes / requires - reporting a
conflicting pair once rather than from both ends.
The unknown-marker suggestion is in: difflib.get_close_matches, so
@read for @reads says which was meant.
The marker set grew while this was open. 19 became 23: tagged,
produces, fills, names and guard arrived, derives, pure
and virtual went with the mock. All 23 are in the table, which is
what the loop's unknown-marker branch enforces the moment one is
used.
census_markers now prints, beside census_cpp, which markers no
declaration carries. It names two: @abstract and @custom. That is
the measurement the rest of this task turns on - @abstract's three
emitter branches and its smoke-test assertion have never run, and the
only place that said so was a comment inside the branch that never
fires.
Left
The @abstract split - DONE. It was the design question and the
reason this file stayed open.
Class.constructs is the derived question, computed once beside
is_produced: a declared __init__, and either a factory or a
concrete type. A FACTORY answers abstractness, which is the case the
old reading had no room for. Six readers switched to it - the
manifest carries constructs beside abstract, nbemit picks the
constructor shape by it, emitter.py reads it in four places - and
abstract keeps its one honest reader, the _abstract marker.
decl/store.py now says @abstract, and Store("dummy://") still
works.
The breakage this file predicted is now demonstrated rather than
reasoned about. Reverting nbemit to key on the fact removes
nb::new_ from store.cpp entirely and gives Store a refusing
__init__.
Two things fell out. @abstract left the unused-marker census, which
it had been in since the mock went. And
test_an_abstract_class_refuses_to_be_built stopped sleeping: it
looped over zero classes and said so in a comment, and now covers the
five produced types - Realisation, PathInfo, StoreLocation,
MissingPaths and Value - with Store correctly excluded.
The refusal sentence is derived too. There are three ways to have no
door and it used to say "is abstract" for all of them.
path:line:col in diagnostics - DONE. It said "line 183:" and
left a reader to work out which of nine declarations that was.
_READING is a stack of paths
8EC1
that read pushes and
DeclarationError reads, so all 36 raise sites in read.py are
unchanged - threading a path through 36 signatures to print it in one
place is the shape this repo spends its effort removing. A stack
rather than one path, because _uses calls read for every
declaration a file imports.
The column is 1-based. ast counts columns from 0 and lines from 1,
which is nobody's convention on either count.
reading() exposes the stack for an emitter that refuses a tree the
corpus already parsed. pyerrors.entries was the only one and had
been printing <declaration>.
Proved by renaming @header to @headerr in decl/path.py and
asking the corpus for store:
.../decl/path.py:32:2: unknown marker @headerr - did you mean
@header?
The file named is the IMPORTED one, not the one asked for, and column
2 is the h past the @.
Collected errors, not the first one - DONE.
Carl asked the right question first: "considering that we're
supporting imports now which can tie different modules together I
believe it'll be hard to have multiple errors collected without the
possibility of bogus errors?" I had recommended closing the item for
that reason. Measuring it changed the answer.
The reader has exactly ONE cross-class check: _check_arms, over
the resolvable map read builds from its own classes plus
_uses. Every other refusal is about a single class, a single
method, or this file's own vocabulary. So bogus errors have one
source, and the cure is one precise rule rather than a blanket.
The rule: an arm whose class FAILED to read is UNKNOWN, not wrong,
and says nothing. Diagnostics.unsound is the set of those names. A
union with one unsound arm and one genuinely bad arm still reports
the bad one - verified, not assumed.
Imports get their own answer. When one does not read, blind is set,
because this file then cannot know what the other declared and every
type it owned would otherwise be reported as undeclared.
Boundaries are the siblings: per class and per free function in
read, per method in _class, per union, per import. Deduplicated,
because _uses calls read per import and nothing caches it, so
decl/path.py is read by five declarations.
Opt-in. _COLLECTING is None by default, so a caller reading one
declaration still gets the exception and every test asserting a
refusal is unchanged. Corpus.read_all is what a generator calls,
and both do, before emitting anything.
Proved by breaking three unrelated things across two files - one of
which imports the other - and building:
3 declaration errors:
.../decl/derived_path.py:181:6: @reads: reads() takes 1
positional argument but 2 were given
.../decl/store.py:181:6: @instant may appear once
.../decl/store.py:194:6: unknown marker @cxx_namez - did you
mean @cxx_name?
And by the converse: breaking a class that two unions name as an arm
reports ONE error, not three.
Two diagnostics improved on the way, both pre-existing. A decorator
called with the wrong argument count raised a bare TypeError with no
position at all. And a union arm refusal pointed at the file rather
than the line, because _unions builds a Class and a Class
carries no position.
Migrated from tasks/061-one-table-for-the-markers.md.done.
Assisted-By: Opus 5
Activity