Skip to content
Merged
Changes from 3 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d11e768
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
25812e4
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
bf3a3f2
Merge remote-tracking branch 'origin/main' into session/nimble-dove-181
briansrls May 15, 2026
ee6e454
Merge remote-tracking branch 'origin/main' into session/nimble-dove-181
briansrls May 15, 2026
0bce650
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
e7de984
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
2920ffb
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
ade5b7f
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
b131afe
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
710e059
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
77158b7
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
d666844
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
e061d2a
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
a4dc9c6
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
7e9bd8a
chore(cost lens): tighten lens_cost_symbolic rustdoc before gate #104…
briansrls May 15, 2026
5322ded
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
69dede9
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
79d981d
chore: apply rustfmt to lens_cost_symbolic symbolic_cost_of (fixes CI…
briansrls May 15, 2026
f2a0b78
fix(cost lens): BindCycle Violates anchors at resolver detected_at node
briansrls May 15, 2026
b68a01b
Merge remote-tracking branch 'origin/main' into session/nimble-dove-181
briansrls May 15, 2026
b871d65
Merge remote-tracking branch 'origin/main' into session/nimble-dove-181
briansrls May 15, 2026
6d6bcaa
docs(cost): clarify dual lens read contracts (gate #104)
briansrls May 15, 2026
120c78c
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
6c40146
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
d539052
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
3b4c1c5
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
05f6b45
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
a63b801
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
12d5fae
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
0fe5041
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
8ce8481
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
8e68a30
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
61ee85c
Merge remote-tracking branch 'origin/main' into session/nimble-dove-181
briansrls May 15, 2026
ee77a79
docs(dimension): classify ViolatesSubject TERMINAL per Practice 4
briansrls May 15, 2026
bac0c01
Merge remote-tracking branch 'origin/main' into session/nimble-dove-181
briansrls May 15, 2026
cda5de4
docs(lens_cost_symbolic): align module rustdoc with ViolatesSubject v…
briansrls May 15, 2026
acf0291
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
deaa49c
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
8d2a267
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
1830219
feat(v3): ground ProducerLookup violates diagnostic spans via query port
briansrls May 15, 2026
5b1c973
Merge remote-tracking branch 'origin/main' into session/nimble-dove-181
briansrls May 15, 2026
6f4d3b0
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
f0158a7
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
644d9a8
WIP: Gate #104 lens_read_witness_shape_dissolved is DECLARED-status w…
briansrls May 15, 2026
b86430c
chore(bootstrap): resync snapshots for regen_bootstrap --verify
briansrls May 15, 2026
1bd80ff
docs(emit): note ViolatesSubject::AtBehavior tuple bridge parallels L…
briansrls May 15, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 94 additions & 15 deletions src/v3/lenses/cost.dag
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// outside this lens's target-agnostic abstract `SymbolicCost` scope.
// See docs/v3-lens-capability-register.md.
//
// Produces `Lookup<SymbolicCost>` per port using `SymbolicCost`
// Produces `Witness<SymbolicCost>` facts per port using `SymbolicCost`
// combinators (`sequential`, `iterate`, `max_path`) from
// `std.algebra`, whose `SizeVariable` carrier is `source_port: PortId` +
// `display_name: String?` (presentation-only label; identity is `source_port`
Expand Down Expand Up @@ -47,19 +47,18 @@
// `cost_lens_symbolic_consumer_test` pins the generated `symbolic_cost_of` consumer on
// `compile_to_dag` fixtures.
//
// Shared carrier: `v3.std.lookup.Lookup` (compiler-std consolidation;
// see docs/thesis/compiler-std-consolidation.md). The prior lens-local
// `SymbolicCostLookup = MissingCost | FoundCost(SymbolicCost)` enum
// was a parallel `Missing|Found(T)` sum that dissolved into `Lookup<T>`
// per the strict two-variant ratchet; the Rust surface keeps a
// `SymbolicCostLookup` *type alias* for embedders.
// Gate #104 (R3 §1.8): folded costs use `Witness<SymbolicCost>` end-to-end
// (`Inhabits` / `Violates { reason, at }`). Port-only callers use `symbolic_cost_of`
// with `resolve_producer` for attribution; lens read pins `Lens.read` attribution
// to the passed `Behavior` via `cost_lens_read`.

module lenses.cost

import std.list { List, empty, fold, cons }
import std.substrate {
Dag, Behavior, BranchPath, LoopNode, LoopBound, NodeId, PortId, node,
TransformNode, TransformTarget, OperatorKind, ArithmeticOp
TransformNode, TransformTarget, OperatorKind, ArithmeticOp,
resolve_producer
}
import std.algebra {
MethodContract,
Expand All @@ -70,9 +69,7 @@ import std.algebra {
unnamed_size_variable,
sequential,
iterate,
max_path,
miss_symbolic_cost_lookup,
hit_symbolic_cost_lookup
max_path
}
import std.computation {
CallPattern,
Expand All @@ -87,7 +84,6 @@ import std.computation {
per_call_pattern_at,
per_call_descent_operand_port
}
import v3.std.lookup { Lookup }
import v3.std.substrate { SourceSpan }
import v3.std.dimensions { Witness, OptionalDiagnostic }
import v3.std.lens { Lens }
Expand Down Expand Up @@ -155,11 +151,94 @@ type CostBasisDeclaration {

type SymbolicCostEntry {
port: PortId
cost: Lookup<SymbolicCost>
cost: Witness<SymbolicCost>

This comment was marked as resolved.

}

fn symbolic_cost_of(d: Dag, port_id: PortId) -> Lookup<SymbolicCost> =
lookup_cost(compute_symbolic_costs(d), port_id)
fn symbolic_cost_fallback_subject_for_unresolved_port(d: Dag) -> Behavior =
match d.nodes {
Cons(payload) => payload.head
}

fn symbolic_cost_of(d: Dag, port_id: PortId) -> Witness<SymbolicCost> =
match resolve_producer(d, port_id) {
Some(subject) =>
lookup_cost_with_subject(

This comment was marked as resolved.

compute_symbolic_costs(d),
port_id,
subject
)
None =>
Violates {
reason: "symbolic_cost_of: unresolved producer for port"
at: symbolic_cost_fallback_subject_for_unresolved_port(d)

This comment was marked as resolved.

}
}

fn wc_inhabits(cost: SymbolicCost) -> Witness<SymbolicCost> =
Inhabits(cost)

fn witness_combine_sequential(
wa: Witness<SymbolicCost>,
wb: Witness<SymbolicCost>
) -> Witness<SymbolicCost> =
match wa {
Inhabits(ax) =>
match wb {
Inhabits(bx) => wc_inhabits(sequential(ax, bx))
Violates(reason = rbody, at = abody) =>
Violates {
reason: rbody
at: abody
}
}
Violates(reason = rax, at = aax) =>
Violates {
reason: rax
at: aax
}
}

fn witness_combine_iterate(
bound_w: Witness<SymbolicCost>,
body_w: Witness<SymbolicCost>
) -> Witness<SymbolicCost> =
match bound_w {
Inhabits(b) =>
match body_w {
Inhabits(y) => wc_inhabits(iterate(b, y))
Violates(reason = ry, at = ay) =>
Violates {
reason: ry
at: ay
}
}
Violates(reason = rx, at = ax) =>
Violates {
reason: rx
at: ax
}
}

fn witness_combine_max(
wa: Witness<SymbolicCost>,
wb: Witness<SymbolicCost>
) -> Witness<SymbolicCost> =
match wa {
Inhabits(ax) =>
match wb {
Inhabits(bx) => wc_inhabits(dominant(ax, bx))
Violates(reason = r2, at = a2) =>
Violates {
reason: r2
at: a2
}
}
Violates(reason = r1, at = a1) =>
Violates {
reason: r1
at: a1
}
}

// §6a Option 3 demo consumer: cost analysis reads per-method metadata from
// the unified carrier keyed by `(algebra_id, method_id)`, keeping the
Expand Down