Skip to content
Closed
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
013f5e8
WIP: Compiler pipeline correctness and scaffold dissolution (AI-5 Inf…
briansrls May 23, 2026
230eef2
WIP: Compiler pipeline correctness and scaffold dissolution (AI-5 Inf…
briansrls May 23, 2026
c586c5f
WIP: Compiler pipeline correctness and scaffold dissolution (AI-5 Inf…
briansrls May 23, 2026
ea0ac43
WIP: Compiler pipeline correctness and scaffold dissolution (AI-5 Inf…
briansrls May 23, 2026
bb3c2d2
WIP: Compiler pipeline correctness and scaffold dissolution (AI-5 Inf…
briansrls May 23, 2026
b9da4d7
WIP: Compiler pipeline correctness and scaffold dissolution (AI-5 Inf…
briansrls May 23, 2026
4d4831a
WIP: Compiler pipeline correctness and scaffold dissolution (AI-5 Inf…
briansrls May 23, 2026
d3bb794
WIP: Compiler pipeline correctness and scaffold dissolution (AI-5 Inf…
briansrls May 23, 2026
7e14044
WIP: Compiler pipeline correctness and scaffold dissolution (AI-5 Inf…
briansrls May 23, 2026
202fb1c
docs(constraints): document solve_constraints as sole CanonicalGround…
briansrls May 23, 2026
ac4307d
chore(compiler): upgrade remaining CP-1b bare scaffold marks in token…
briansrls May 23, 2026
28f10d6
merge: resolve PR #3587 conflict with origin/main
briansrls May 23, 2026
98b7be5
WIP: Compiler pipeline correctness and scaffold dissolution (AI-5 Inf…
briansrls May 23, 2026
b29268d
fix(compiler): import non_empty from v4.std.algebra in 05_eval
briansrls May 23, 2026
90322a5
WIP: Compiler pipeline correctness and scaffold dissolution (AI-5 Inf…
briansrls May 24, 2026
5d5a2dd
fix(compiler): fail-closed eval boundary on incoherent CanonicalGroun…
briansrls May 24, 2026
16ccbfb
merge: resolve PR #3587 conflict with origin/main
briansrls May 24, 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
1 change: 1 addition & 0 deletions src/v4/compiler/00_compile.dag
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ fn compile_eval_not_realized_diagnostic(at: Locus) -> Diagnostic {
}


// 🟡 gated — feature:T-23-lens-application-migration — bind src/v4/lens/application.dag TASKS.md T-23 — dissolve-on: delete local Lens type and apply_lens stub when v4.lens.application.apply_lens is canonical; forbidden: callers treating compile.apply_lens as permanent surface or diverging from application.dag contract.
// T-23 migration stub: identical contract to v4.lens.application apply_lens when that module fills.
// LensEnforce and LensIntrospect both call gate today; introspect demotion lands with application.dag.
fn apply_lens(
Expand Down
2 changes: 1 addition & 1 deletion src/v4/compiler/01_tokenize.dag
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type LexCharClass
| IdentContinueChar


// 🟡 coproduct dissolution — CP-1b item 13b (LexPattern).
// 🟡 gated — feature:CP-1b-bidirectional-grammar-carrier — bind TASKS.md T-6/T-7 — dissolve-on: LexPattern converges with GrammarExpr on single declarative bidirectional grammar model; forbidden: parallel production algebras without explicit structural justification.
type LexPattern
= EmptyPattern
| LiteralPattern { text: String }
Expand Down
3 changes: 1 addition & 2 deletions src/v4/compiler/02_parse.dag
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import v4.std.diagnostic {Correction, Diagnostic, ExternalContractUnknown, Locus
import v4.std.node { Atom, Conj, Edge, Named, Node, Symbol, TypeNode, well_formed }


// 🟡 coproduct dissolution — CP-1b/T-7 grammar-as-data; typed production alternatives, Node projection only.
// 🟡 gated — feature:CP-1b-bidirectional-grammar-carrier — bind TASKS.md T-6/T-7 — dissolve-on: GrammarExpr converges with LexPattern on single declarative bidirectional grammar model; forbidden: parallel production algebras without explicit structural justification.
type GrammarExpr
// 🟡 coproduct dissolution — CP-1b/T-7 grammar-as-data; typed production alternatives, Node projection only.
= Terminal { token_class: Symbol }
| Sequence { left: GrammarExpr, right: GrammarExpr }
| Choice { left: GrammarExpr, right: GrammarExpr }
Expand Down
3 changes: 2 additions & 1 deletion src/v4/compiler/03_normalize.dag
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ data normalize_reason_malformed_sugar: Symbol = normalize_reason_malformed_sugar
data normalize_reason_post_normalize_not_well_formed: Symbol = normalize_reason_post_normalize_not_well_formed


// 🟡 coproduct dissolution — CP-1b item 4 (SurfaceSugarKind).
// 🟡 gated — feature:CP-1b-surface-sugar-language-model — bind TASKS.md T-8 / LanguageModel — dissolve-on: surface-to-kernel sugar mapping owned by language-model substrate facts, not compiler-local Atom identity comparison in classify_sugar; forbidden: persistent local SurfaceSugarKind taxonomy without structural LanguageModel carrier.
type SurfaceSugarKind
= ServiceSugar
| FnSugar
Expand All @@ -64,6 +64,7 @@ fn no_surface_sugar_kind() -> SurfaceSugarKind? {
}


// 🟡 gated — feature:CP-1b-surface-sugar-language-model — bind TASKS.md T-8 — dissolve-on: classify_sugar reads modeled LanguageModel sugar facts; forbidden: Atom identity string/symbol comparison as permanent authority.
fn classify_sugar(n: Node) -> SurfaceSugarKind? {
match n.kind {
TypeNode { connective: Atom { identity: id } } =>
Expand Down
121 changes: 67 additions & 54 deletions src/v4/compiler/04_infer.dag
Original file line number Diff line number Diff line change
Expand Up @@ -56,46 +56,46 @@ type AlgebraRef {
}


// RULING-1: needs-more-work — inhabitance coordinates remain T-9 bridged.
// Practice 2: InferredFacts bundles CanonicalGrounding + descent. std/constraints.dag
// CanonicalGrounding is not yet proof-by-construction (scaffold:T-9-ground) — infer
// enforces admission at construction and re-export via canonical_grounding_admits_infer_facts
// until std/constraints lands a structural carrier for node/witness/closedness alignment.
type InferredFacts {
resolved_type: Node
inhabits: AlgebraRef
grounding: CanonicalGrounding
descent: Witness<TerminationProof>
canonical: CanonicalGroundingWitness
}


// RULING-1: needs-more-work — per-node fact table shape is present; producer semantics are T-9.
type InferredTree {
root: Node
facts: Map<Node, InferredFacts>
fn inferred_facts_resolved_type(facts: InferredFacts) -> Node {
facts.grounding.node
}


type InferredFactsEntry {
node: Node
facts: InferredFacts
fn inferred_facts_algebra_ref(facts: InferredFacts) -> AlgebraRef {
algebra_ref_from_grounding(grounding: facts.grounding)
}


fn inferred_facts_resolved_type_matches(
facts: InferredFacts,
candidate_type: Node
) -> Bool {
candidate_type == facts.resolved_type
fn inferred_facts_canonical_witness(facts: InferredFacts) -> CanonicalGroundingWitness {
facts.grounding.witness
}


fn inferred_facts_descent(facts: InferredFacts) -> Witness<TerminationProof> {
facts.descent
}


fn inferred_facts_inhabitance_well_grounded(facts: InferredFacts) -> Bool {
(facts.inhabits.witness == facts.resolved_type)
&& (facts.inhabits.algebra == facts.canonical.structural.evidence)
// RULING-1: needs-more-work — per-node fact table shape is present; producer semantics are T-9.
type InferredTree {
root: Node
facts: Map<Node, InferredFacts>
}


fn inferred_facts_canonical_well_grounded(facts: InferredFacts) -> Bool {
(facts.canonical.structural.property == constraint_property_being_canonical)
&& (facts.canonical.closedness.property == constraint_property_candidate_set_closedness)
&& (facts.canonical.closedness.evidence == facts.resolved_type)
type InferredFactsEntry {
node: Node
facts: InferredFacts
}


Expand Down Expand Up @@ -149,25 +149,46 @@ fn algebra_ref_from_grounding(grounding: CanonicalGrounding) -> AlgebraRef {
}


fn infer_constraint_graph(n: Node) -> ConstraintGraph {
ConstraintGraph { root: n }
// Infer admission gate — not a post-hoc InferredFacts field patch. Validates the
// algebra_ref_from_grounding / closedness alignment CanonicalGrounding must satisfy
// before infer accepts or re-exports grounding as authoritative.
fn canonical_grounding_admits_infer_facts(grounding: CanonicalGrounding) -> Bool {
well_formed(n: grounding.node)
&& well_formed(n: grounding.witness.structural.evidence)
&& (grounding.witness.structural.property == constraint_property_being_canonical)
&& (grounding.witness.closedness.property == constraint_property_candidate_set_closedness)
&& (grounding.witness.closedness.evidence == grounding.node)
}


fn inferred_facts_from_grounding(
n: Node,
fn inferred_facts_construction(
grounding: CanonicalGrounding,
descent: Witness<TerminationProof>,
) -> InferredFacts {
InferredFacts {
resolved_type: grounding.node,
inhabits: algebra_ref_from_grounding(grounding: grounding),
descent: descent,
canonical: grounding.witness
) -> Outcome<InferredFacts> {
if canonical_grounding_admits_infer_facts(grounding: grounding) {
Accepted {
value: InferredFacts {
grounding: grounding,
descent: descent
},
diagnostics: None
}
} else {
outcome_rejected(
infer_canonical_grounding_incoherent_diagnostic(node: grounding.node)
)
}
}


fn inferred_facts_from_grounding(
grounding: CanonicalGrounding,
descent: Witness<TerminationProof>,
) -> Outcome<InferredFacts> {
inferred_facts_construction(grounding: grounding, descent: descent)
}


fn concat_inferred_facts_entries(
a: List<InferredFactsEntry>,
b: List<InferredFactsEntry>,
Expand All @@ -178,6 +199,11 @@ fn concat_inferred_facts_entries(
}


fn infer_constraint_graph(n: Node) -> ConstraintGraph {
ConstraintGraph { root: n }
}


fn infer_node_facts(n: Node) -> Outcome<InferredFacts> {
match infer_descent_witness_for_node(n: n) {
Violates { diagnostic: d } =>
Expand All @@ -190,14 +216,10 @@ fn infer_node_facts(n: Node) -> Outcome<InferredFacts> {
}
),
f: fn(grounding) {
Accepted {
value: inferred_facts_from_grounding(
n: n,
grounding: grounding,
descent: Holds { value: descent_proof }
),
diagnostics: None
}
inferred_facts_from_grounding(
grounding: grounding,
descent: Holds { value: descent_proof }
)
}
)
}
Expand Down Expand Up @@ -240,24 +262,15 @@ fn facts_map_from_entries(entries: List<InferredFactsEntry>) -> Map<Node, Inferr
fn inferred_facts_witness_for_node(tree: InferredTree, node: Node) -> Witness<InferredFacts> {
tree.facts.lookup(node)
}
// P2: InferredFacts fields are independently constructible; reject illegal pairings before export.
fn inferred_facts_canonical_grounding_coherent(facts: InferredFacts) -> Bool {
well_formed(n: facts.resolved_type)
&& well_formed(n: facts.inhabits.witness)
&& well_formed(n: facts.inhabits.algebra)
&& (facts.resolved_type == facts.inhabits.witness)
&& (facts.canonical.structural.evidence == facts.inhabits.algebra)
}


fn canonical_grounding_from_inferred_facts(
node: Node,
facts: InferredFacts,
) -> Outcome<CanonicalGrounding> {
if inferred_facts_canonical_grounding_coherent(facts: facts) {
if canonical_grounding_admits_infer_facts(grounding: facts.grounding) {
Accepted {
value: CanonicalGrounding {
node: facts.resolved_type,
witness: facts.canonical
},
value: facts.grounding,
diagnostics: None
}
} else {
Expand Down
57 changes: 27 additions & 30 deletions src/v4/compiler/05_eval.dag
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ module v4.compiler.eval
import v4.compiler.infer {
InferredFacts,
InferredTree,
inferred_facts_canonical_well_grounded,
inferred_facts_inhabitance_well_grounded,
inferred_facts_resolved_type_matches
inferred_facts_descent,
inferred_facts_resolved_type
}
import v4.std.collection { List, Map, non_empty }
import v4.std.runtime {
Expand Down Expand Up @@ -105,15 +104,21 @@ type TestClaimEvalSubject<T> {
}


// RULING-1: needs-more-work — hash slots dissolve to B1 content_hash facts.
type TestClaimCacheKey<T> {
eval_subject: TestClaimEvalSubject<T>
// 🟡 gated — feature:T22-EVAL-CACHE-HASHES — bind IRT-4 / TASKS.md T-22 — dissolve-on: B1 content_hash of the whole TestClaim evaluation subgraph replaces staging placeholders; forbidden: caller-supplied hash parameters acting as cache-validating authority before B1 content_hash lands.
type TestClaimCacheKeyStagingPlaceholder {
claim_hash: Hash
interpretation_hash: Hash
}


// RULING-1: needs-more-work — receipt remains hash-scaffolded until cache hashes derive.
// 🟡 gated — feature:T22-EVAL-CACHE-HASHES — bind IRT-4 / TASKS.md T-22 — dissolve-on: cache key derived from content_hash(eval_subject); hash_staging is NOT cache-validating authority until B1 lands.
type TestClaimCacheKey<T> {
eval_subject: TestClaimEvalSubject<T>
hash_staging: TestClaimCacheKeyStagingPlaceholder
}


// 🟡 gated — feature:T22-EVAL-CACHE-HASHES — bind IRT-4 / TASKS.md T-22 — dissolve-on: receipt keyed by derived content_hash; forbidden: treating hash_staging as authoritative cache boundary.
type TestClaimCacheReceipt<T> {
key: TestClaimCacheKey<T>
}
Expand Down Expand Up @@ -152,8 +157,10 @@ fn test_claim_cache_receipt<T>(
TestClaimCacheReceipt {
key: TestClaimCacheKey {
eval_subject: subject,
claim_hash: claim_hash,
interpretation_hash: interpretation_hash
hash_staging: TestClaimCacheKeyStagingPlaceholder {
claim_hash: claim_hash,
interpretation_hash: interpretation_hash
}
}
}
}
Expand Down Expand Up @@ -216,7 +223,7 @@ fn inferred_facts_witness_for_eval(tree: InferredTree, node: Node) -> Witness<In
fn inferred_facts_for_eval(tree: InferredTree, node: Node) -> Outcome<InferredFacts> {
match inferred_facts_witness_for_eval(tree: tree, node: node) {
Holds { value: facts } =>
match facts.descent {
match inferred_facts_descent(facts: facts) {
Holds { value: _ } =>
Accepted { value: facts, diagnostics: None }
Violates { diagnostic: d } =>
Expand All @@ -238,7 +245,7 @@ fn eval_structural_node_for_eval(tree: InferredTree, node: Node) -> Outcome<Node
}


// 🟡 gated — feature:T22-outcome-accumulation-policy — bind node://adhoc-6a2e599a-cc2 — dissolve-on: Outcome traverse/zip accumulation policy carries rejected-with-pending diagnostics merge; forbidden: local Rejected/Accepted ladders per eval accumulator.
// 🟡 gated — feature:T22-outcome-accumulation-policy — bind node://adhoc-6a2e599a-cc2 — migrate-to: std/diagnostic Outcome traverse/zip accumulation — dissolve-on: rejected-with-pending diagnostics merge owned by std/diagnostic; forbidden: local Rejected/Accepted ladders per eval accumulator.
fn eval_absorb_structural_child(
acc: Outcome<Node>,
child: Outcome<Node>
Expand All @@ -261,7 +268,7 @@ fn eval_absorb_structural_child(
}


// 🟡 gated — feature:T22-runtime-control-terminalization — bind node://adhoc-6a2e599a-cc2 — dissolve-on: ControlSemantics exposes terminalization/disposition for ControlTransfer; forbidden: each eval consumer locally deciding whether Continue/Return/Raise/Suspend is terminal.
// 🟡 gated — feature:T22-runtime-control-terminalization — bind node://adhoc-6a2e599a-cc2 — migrate-to: std/runtime ControlSemantics terminalization — dissolve-on: ControlTransfer disposition owned by std/runtime; forbidden: eval-local terminalization of Continue/Return/Raise/Suspend.
fn control_transfer_value(control: ControlTransfer, node: Node) -> Outcome<RuntimeValue> {
match control {
Continue { value: v } =>
Expand All @@ -280,35 +287,24 @@ fn control_transfer_value(control: ControlTransfer, node: Node) -> Outcome<Runti
}


// 🟡 gated — feature:T22-eval-runtime-value-acceptance-witness — bind node://adhoc-6a2e599a-cc2 — dissolve-on: eval consumes a modeled acceptance witness/product tying RuntimeValue resolved type, inhabitance, and canonical grounding to InferredFacts; forbidden: permanent Bool-ladder proof erasure.
// 🟡 gated — feature:T22-eval-runtime-value-acceptance-witness — bind node://adhoc-6a2e599a-cc2 — dissolve-on: std/runtime owns runtime-value acceptance witness tying RuntimeValue to InferredFacts construction; forbidden: permanent Bool-ladder proof erasure in eval.
fn eval_accept_runtime_value_with_facts(
node: Node,
facts: InferredFacts,
value: RuntimeValue
) -> Outcome<RuntimeValue> {
let candidate_type = runtime_value_resolved_type(value: value)
if !inferred_facts_resolved_type_matches(
facts: facts,
candidate_type: candidate_type
) {
if candidate_type != inferred_facts_resolved_type(facts: facts) {
outcome_rejected(
d: eval_diagnostic(reason: eval_rejected_resolved_type_mismatch, node: node)
)
} else if !inferred_facts_inhabitance_well_grounded(facts: facts) {
outcome_rejected(
d: eval_diagnostic(reason: eval_rejected_inhabitance_mismatch, node: node)
)
} else if !inferred_facts_canonical_well_grounded(facts: facts) {
outcome_rejected(
d: eval_diagnostic(reason: eval_rejected_canonical_mismatch, node: node)
)
} else {
Accepted { value: value, diagnostics: None }
}
}


// 🟡 gated — feature:T22-runtime-behavior-interpreter-dispatch — bind node://adhoc-6a2e599a-cc2 — dissolve-on: InterpretationAlgebra exposes a canonical Behavior-indexed interpreter/disposition so eval builds one input and consumes the runtime-owned behavior algebra; forbidden: downstream consumers owning divergent Behavior match tables.
// 🟡 gated — feature:T22-runtime-behavior-interpreter-dispatch — bind node://adhoc-6a2e599a-cc2 — migrate-to: std/runtime Behavior-indexed interpreter dispatch — dissolve-on: InterpretationAlgebra exposes canonical behavior algebra; forbidden: divergent Behavior match tables outside std/runtime.
fn eval_computation_node(
behavior: Behavior,
node: Node,
Expand Down Expand Up @@ -381,7 +377,7 @@ fn empty_runtime_values() -> List<RuntimeValue> {
}


// 🟡 gated — feature:T22-eval-runtime-edge-role — bind node://adhoc-6a2e599a-cc2 — dissolve-on: std/node exposes canonical EdgeLabel runtime-argument role query/accessor; forbidden: making Named structural edges into runtime arguments.
// 🟡 gated — feature:T22-eval-runtime-edge-role — bind node://adhoc-6a2e599a-cc2 — migrate-to: std/node EdgeLabel runtime-argument role query — dissolve-on: canonical edge-role accessor in std/node; forbidden: eval-local Named-vs-Positional runtime argument derivation.
fn eval_edge_is_runtime_argument(edge: Edge) -> Bool {
match edge.label {
Positional => true
Expand All @@ -395,7 +391,7 @@ fn eval_fold_state_value(state: EvalFoldState) -> Outcome<RuntimeValue> {
}


// 🟡 gated — feature:T22-outcome-accumulation-policy — bind node://adhoc-6a2e599a-cc2 — dissolve-on: Outcome traverse/zip accumulation policy carries rejected-with-pending diagnostics merge; forbidden: local Rejected/Accepted ladders per eval accumulator.
// 🟡 gated — feature:T22-outcome-accumulation-policy — bind node://adhoc-6a2e599a-cc2 — migrate-to: std/diagnostic — dissolve-on: child diagnostic absorption policy in std/diagnostic; forbidden: eval-local Outcome merge ladders.
fn eval_absorb_child_diagnostics(
acc: Outcome<List<RuntimeValue>>,
child: Outcome<Node>
Expand All @@ -418,7 +414,7 @@ fn eval_absorb_child_diagnostics(
}


// 🟡 gated — feature:T22-outcome-accumulation-policy — bind node://adhoc-6a2e599a-cc2 — dissolve-on: Outcome traverse/zip accumulation policy carries rejected-with-pending diagnostics merge and list append combine; forbidden: local Rejected/Accepted ladders per eval accumulator.
// 🟡 gated — feature:T22-outcome-accumulation-policy — bind node://adhoc-6a2e599a-cc2 — migrate-to: std/diagnostic — dissolve-on: list-append + Outcome merge in std/diagnostic; forbidden: eval-local append ladders.
fn eval_append_child_value(
acc: Outcome<List<RuntimeValue>>,
child: Outcome<RuntimeValue>
Expand Down Expand Up @@ -677,7 +673,7 @@ fn runtime_value_eq(a: RuntimeValue, b: RuntimeValue) -> Bool {
}


// 🟡 gated — feature:T22-parameterized-outcome-eq — bind node://adhoc-c5a6fb4b-8cc — dissolve-on: v4.std.diagnostic owns a parameterized Outcome equality surface with payload comparator; forbidden: adding more payload-specific Outcome equality helpers.
// 🟡 gated — feature:T22-parameterized-outcome-eq — bind node://adhoc-c5a6fb4b-8cc — migrate-to: std/diagnostic parameterized Outcome equality — dissolve-on: payload-comparator Outcome eq in std/diagnostic; forbidden: eval-local Outcome equality helpers.
fn outcome_runtime_value_eq(a: Outcome<RuntimeValue>, b: Outcome<RuntimeValue>) -> Bool {
match a {
Accepted { value: av, diagnostics: ad } => match b {
Expand Down Expand Up @@ -768,6 +764,7 @@ fn aggregate_verdicts<T>(rs: List<Verdict<T>>, at: Node) -> Verdict<T> {
}


// 🟡 gated — feature:T22-EVAL-CACHE-HASHES — bind IRT-4 — claim_hash/interpretation_hash are staging placeholders, NOT cache-validating authority; dissolve-on: B1 content_hash derivation replaces caller-supplied hashes.
fn run_test_claim(
subject: TestClaimEvalSubject<Node>,
claim_hash: Hash,
Expand Down
Loading
Loading