ADR 0074: The frontend's lowering domains are objects the lifter holds¶
Status: Final Type: Architecture Created: 2026-11-06 Related-ADRs: 0014 (the verifier, which every step left unchanged), 0054 (structural facts declared once, the principle this applies to the frontend's own state)
Context¶
The frontend lowers a function with FunctionLifter, which was 24 lowering mixins, one per lower_* module, over a typed base, _LifterState. The mixins call across each other freely: a measurement on 2026-11-06 counted 2472 calls from one module to a method another defines, each module reaching between 6 and 20 others. A type checker cannot see from one mixin into another, so state.py declared every method of every mixin a second time, as a stub raising NotImplementedError, 607 of them, and a test held the stubs one-to-one with the methods. Every new lowering method was therefore written twice. A signature that moved on in one place and not the other made make lint prove things about a stub that never ran.
The coupling is the shape of a recursive-descent lowerer and stays: lowering xs.append(f(x)) goes from lists to expressions to calls and back. The way one domain reaches another can change.
Decision¶
Each lower_* module holds one class, <Domain>Lowering, constructed with the lifter and keeping it as self.lifter. The lifter builds every domain in __init__ and holds it as an attribute (self.lists, self.maps, self.exprs, …). A domain reaches the lifter's state as self.lifter.members, self.lifter.builder, and another domain as self.lifter.tuples.lower_tuple_value(...). FunctionLifter declares its own attributes, the domains among them, and inherits nothing.
A name that crosses from one domain to another, or from a domain to the lifter, is public. Ruff's SLF001 refuses a private name reached through another object, so the move made every such name public; a method still named with an underscore is called only by its own domain. The type checkers resolve every access through the lifter's declarations, so there is no mirror to keep.
Consequences¶
state.pywent from 2885 lines to 385; it holdsJoband the small records the domains share. The 607 stubs and the test that held them one-to-one are gone;tests/a_unit/test_lifter_declarations.pyholds the lifter's own declarations in both directions, keeps them typed, and checks that everylower_*module is a domain the lifter holds.- A new lowering method is written once. One called from another domain is public; its call reads
self.lifter.<domain>.<method>, which says where it lives. - The move was mechanical and gated at each batch: generated IR byte-identical on 329 programs and 1316 compiles (
tools/ir_fingerprint.py), the unit suite, and the three type checkers. - Not done: the domains still reach one another through the lifter at about the same rate. The lifter's shared state is still one set of attributes every domain can read. Narrowing what each domain may touch is possible now, one domain at a time, and was not part of this change.