check_purity: the Kernel calls nothing it is given but _decision, and what fills _decision is a Kernel function (#588)

Merged
DO
11d ago
+684-6

Closes #588. tools/check_purity.py now refuses a Kernel call of anything it was handed, except _decision. What fills _decision must be a Kernel function. Main passes as it is. Its record is NNNN, numbered at enqueue, so checks, verify and some mutant shards are red until then.

Not to be enqueued until the Factory Builder says so.

What changes

PartChange
tools/check_purity.pyInside kernel/, these calls are refused: a parameter other than one CALLABLE_PARAMETERS names (_decision); a name the function binds otherwise (from context.get, a loop, a comprehension, a walrus); a method whose name is not in BUILTIN_METHODS, an exact list of the 16 the Kernel uses, unless it is a call of a function of a module the Kernel imports; and anything called that is not a name or an attribute. What key=, map or filter is handed to call is held to the same rule. Only a function at a module's top takes _decision, and it is only called, never named another way. What fills _decision, by name or by place, is a function at the top of a Kernel module or the caller's own _decision; a spread that might fill it is refused. callable joins FORBIDDEN_NAMES
tests/test_tools.pyThree tests in Purity. The first covers each refused form, and the forms that pass: _decision, a local function or lambda, a module's function, a listed method, a builtin. The second covers what fills _decision, both sides. The third, on the real Kernel, names the eight functions that take _decision and finds every call of one filled by a Kernel function. One existing test passed None as _decision; it now passes a Kernel function
tools/mutants.py23 mutants, one for each part of the rule, each killed by an assertion
docs/decisions/NNNN-…The widened rule and what it does not hold: a handed value's own special methods, and a listed method on a value that is not of a built-in type. The facts are JSON
AGENTS.md, kernel/AGENTS.mdThe purity row says the Kernel calls nothing it is given but _decision; kernel/ gets a row for the call rule

Before the rule: what the Kernel calls on main

Every call in kernel/, by callee: 335 builtins, 308 functions of the module itself, 96 imported functions, 10 functions of an imported module (brakes.*), and 1 local function. 18 are of a parameter, all of them _decision, in kernel/brakes.py and kernel/derive.py's run_deferral. None is of a bound value, and none of any other shape. The methods called are the 16 now listed. key= is given only top-level functions and lambdas.

Wider than the issue

The issue held "what fills _decision" with a test on main. The check holds it on every module instead, along with the two rules that keep it from being dodged: a function that takes _decision sits at a module's top and is only called. Handing a value to key=, map or filter is held too, since each calls what it is handed.

Protected paths

None. kernel/brakes.py is read, not changed.

Reviews

Pending.

Verify

Pending.

šŸ¤– Generated with Claude Code