Repository navigation
Closed
Description
Summary
Axiom §§2, 20–21 separate intent (transform Spectrum from Frame) from implementations (scalar_fft / simd_fft / gpu_fft) with cost models; the compiler picks under hard/soft constraints (require / prefer / deploy profiles).
Flow already has a thin version of this for ordering:
- Intent:
xs |> sort/sortBy … - Policies parsed but ignored:
adaptive,gpu,parallel,with entropy - Phase 2 open in
docs/project/Questions.md - Sortedness hints tracked in Ordering Phase 2: carry sortedness / positivity hints for adaptive sort #145
The same pattern should become a general language mechanism, not a sort special-case—especially for DSP (FFT, filters), ML (tiny vs large model), and numerics (insertion vs radix).
Proposal
- Intent surface (existing or small sugar): name what must hold (
Sorted,Spectrum,Prediction). - Implementation registry: multiple lowerings with:
supports(cpu / simd / gpu)- symbolic or annotated
cost(time / memory / transfer) - optional
whenguards (e.g.n < 32)
- Constraint vocabulary (start minimal):
- hard:
require latency < …,require memory < …,@rt_safe/ no_allocation - soft:
prefer minimise latency | energy | memory(profiles later)
- hard:
- First consumers after sort: one audio transform and/or one ML path already in-tree.
Why not “become Axiom”
Flow’s primary abstraction remains evolution through time (VISION.md). This issue only steals Axiom’s intent ≠ implementation ≠ plan split where Flow already needs adaptive selection.
Acceptance
- Design sketch: how impls are declared (attribute?
implementblock? stdlib registry?) - Ordering Phase 2 uses the same selector API as the general mechanism
- At least two impls for one non-sort transform with a constraint that flips the choice
- Soft
prefermay stay parsed-only until a cost IR exists - Record syntax/design choice in
docs/project/Questions.mdbefore shipping sugar
Related
- Ordering Phase 2: carry sortedness / positivity hints for adaptive sort #145 ordering hints
- Define NaN / float total-order semantics for declarative sort and equality #144 NaN / sort total order
- Closed RT-safety: compile-time no-alloc enforcement for audio threads #134
@rt_safe docs/language/ordering.mdLater / PRD
Metadata
Metadata
Assignees
Labels
No labels
Activity
godofecht commentedon Aug 6, 2026
Landed on branch
lang/plans-and-ordering.The mechanism
src/flow/plan_selector.pyknows nothing about sorting. It holds:Facts: the immutable bag of what the compiler knows at one site.Implementation: one lowering, declaring an applicability predicate, a scratch claim, a cost model, a tie-break rank, and a resolution string.select(facts, location, detail): runs every implementation registered for the construct, applies the hard resource budget, keeps the cheapest survivor, and returns a record of the whole decision.The applicability predicate returns
Noneto mean yes, and otherwise the sentence the report prints:Writing the rejection as a sentence rather than a boolean is the design. A constraint that cannot explain itself is not worth having, and it is what makes #146 possible at all.
Two constructs
src/flow/ordering_plans.pyregisters eight implementations across two constructs.sort, six lowerings:
already_ordered,reverse_in_place,counting,insertion,natural_merge,bottom_up_merge.search, new surface
xs |> find(t)yielding the first matching index or-1, two lowerings:linear_scanandbinary_search.They deliberately share facts.
input_orderis produced by the ordering-hints pass (#145) forsortand consumed bysearch:That is the constraint flipping the choice this issue asks for. Insert a call taking
xsbetween those lines and the fact is gone, the search drops back to a linear scan, and--explainsays so.Constraint vocabulary, so far
Hard, and enforced:
Soft: cost minimisation only. Costs are estimated element operations from an annotated model, comparable within one construct and meaningless across constructs. The report says "not measurements" on every run so nobody quotes them as timings. Where a model was calibrated against a real measurement, the constant carries a comment pointing at the benchmark.
Two escape hatches on the sort surface:
adaptiveasserts the input has structure and shifts the run estimate;generalpins the general-purpose plan and drops every hint, which is what makes an honest benchmark baseline possible.Deliberately not built:
require latency < …,prefer minimise energy, deploy profiles, and asupports cpu / simd / gpuaxis. Those need a cost IR with real units. The current model has one dimension and admits it.Acceptance
register(Implementation(...)), documented indocs/language/explainable-compilation.md"How a construct joins in"search, flipped byinput_orderpreferstays unbuilt until a cost IR existsdocs/project/Questions.md. The only new surface isxs |> find(t)plus thegeneralpolicy word; both are documented indocs/language/ordering.mdbut not yet in Questions.md.What is left
The first consumer outside ordering. An audio transform or an ML path would exercise the parts a sort cannot: a
supportsaxis, transfer costs, a second cost dimension. Until then this is a working mechanism on two constructs, which was the point of keeping it small.Tests:
tests/unit/test_plan_selector.py, 30 cases. Roughly half run against implementations invented in the test file so the selector's own contract is tested without any sort in the picture.Total-order float comparison plus a cost-based plan selector for sort…
fix+docs: close resolved issues; ILP32 sizeof_ptr; Homebrew; linguist…
feat: if-expressions + flowc-v0.10.0 closes self-hosting E (#154) (#262)
feat(plans): generalise multi-implementation selection beyond sort (#147
feat(flowc): scientific notation, attribute skip, type aliases (#438)