Repository navigation
Description
DONE. The branch is READ, which was Carl's call between the two
answers below. Explored in a worktree first.
Before the fix: pyerrors.entries and pyerrors.chain read tree.body, so
they see TOP-LEVEL classes only. pyerrors.module copies the whole
document. A class under if NIX_VERSION >= ... therefore reaches the
emitted errors.py and reaches nothing else.
Measured on 2026-09-02, while closing #609. The perturbation
was six lines appended to decl/errors.py:
if NIX_VERSION >= (99, 0):
class NeverImports(NixError):
"""A perturbation: the tree names it, the import does not."""
cxx = "nix::NeverImports"
nix run --file . check said all checks passed, and the emitted
module carried this:
if NIX_VERSION >= (99, 0):
class NeverImports(NixError):
"""A perturbation: the tree names it, the import does not."""
cxx = 'nix::NeverImports'
Three things are wrong there and each is its own hole.
-
The class is in no manifest entry and in no catch clause.
entries()iteratestree.body, so the nested ClassDef is
invisible. A caller canexcept NeverImportsand nothing will
ever raise it, and the wire has noNeverImportsFaultto carry
one. -
The
cxxline is copied through.module()strips acxx
assignment from a top-level class body and nothing walks into an
If, so the emitted class keeps an attribute that names a C++
type - in a module whose whole point is to be plain Python. -
The emitted module imported
huggorm_dsl. The perturbation
neededfrom huggorm_dsl.declare import NIX_VERSIONto parse, and
module()copied that import into the runtime package. It IMPORTED
at test time, which is the part worth noticing: the build-time DSL
is reachable from the emitted bindings, so nothing failed.
Why it is worth doing
A version branch is a shape the DSL invites. declare.py documents
it for a method, and read.py imports every declaration precisely so
Python resolves the branch. An error declaration is a declaration, so
the branch is legal there and means nothing.
The failure mode is the quiet one. Nothing crashes: a caller gets a
class that cannot be raised, and the day upstream splits an error
behind a version is the day someone writes this and believes it.
What to do
Decide which of two answers is right, and both are defensible.
- REFUSE the branch.
entries()raises if any ClassDef is nested,
saying an error declaration is flat. Cheapest, and honest: no
declaration needs the branch today. - READ the branch. Walk into an
Ifthe way the import already
does, and take the classes the IMPORT defines rather than the ones
the tree names.entries()already has the module - it uses it for
__bases__- so this is the reading it half does.
Whichever it is, PROVE it: the perturbation above must stop the build.
Found because #609 asked for a gate to be shown failing and
the closest thing to one was measured instead of assumed.
What was done, 2026-09-02
Carl chose READ the branch. The reader has resolved a version
branch since it was written, and pyerrors was the one emitter that
parsed the file a second time and got a raw tree. So this is not new
machinery; it is one emitter asking the reader instead of the parser.
The change, in four pieces
-
read.resolved(path)hands back the tree with itsifarms
already chosen. Four lines that_readalready ran - parse,
_live,_reconcile,_resolve- now sit in_chosen, which
both callers share. Stating that twice was the alternative, and
the fact stated would have been which arm this build is looking
at. -
Corpus.resolved(name), cached besideCorpus.tree. Both
stay, because they answer different questions:treeis the
document as WRITTEN, which is what a docstring's exact text and
the marker scan want, andresolvedis the document as this build
READS it. -
pyerrorsreads one body. All three readings went through
tree.bodyon their own, which is how they came to disagree - two
read the top level andmodule()copied the whole document. They
share_body(tree)now. -
module()drops the declaration LANGUAGE's imports. A branch
has to spellNIX_VERSIONto be written at all, and the arm is
chosen by the time this runs - so the name is unreferenced and
carrying the import would make the emitted package depend on a
build-time one. The package name is read offread's own module
rather than spelled. Anything ELSE a declaration imports stays: a
class body may legitimately nametyping, and only the language
is knowably build-time.
The gate, and it is TWO gates
The wiring and the mechanism fail differently, so they are caught
differently.
_body REFUSES a raw parse. An ast.If cannot survive
read.resolved, so a surviving one means the caller passed the wrong
tree. This is the only thing that can catch a revert to
Corpus.tree: for a declaration that does not branch the two trees
are identical, and no declaration in this repo branches.
tests/test_declarations.py is new, and it is the first suite
that drives the reader and an emitter on declarations written for the
test. It can state the case the real corpus does not have. Four
tests: the branch resolves before an emitter sees it, the emitted
module keeps no trace of it, all three readings refuse a raw parse,
and a declaration that does not branch reads the same either way.
PERTURBED, four ways
resolved()stops flattening. Two tests fail with the
emitter's own refusal - which is the two gates meeting, and the
right answer: an unresolved tree is refused wherever it comes
from.module()stops dropping the language import.assert 'huggorm_dsl' not in ...fails.generate.pyreverts tohave.tree(have.errors), with a
branch in the real declaration: the BUILD stops, at
bindings-src, saying "this exception declaration still has a
version branch in it".- A real class moved behind a live branch.
Unsupportedwas
put underif NIX_VERSION >= (2, 0):indecl/errors.pyand the
whole build was run: 236 tests pass andchecksays all checks
passed. The emitted module carries it flat with thecxxline
stripped and noNIX_VERSIONimport,store.cppandpath.cpp
catch it, and the dead arm reaches nothing.
That fourth one is the positive proof, and it is what the first
version of this work lacked. The other three prove the gates.
What did NOT change
Every emitted file, for the declarations this repo actually has.
read.resolved is a raw parse when nothing branches, which is the
claim the whole fix rests on - so it is a test rather than a remark
(test_a_declaration_that_does_not_branch_reads_the_same_either_way).
Migrated from tasks/073-a-version-branched-error-class-reaches-nothing.md.done.
Assisted-By: Opus 5
Activity