Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e87f3d9
WIP: Wave-4-A — find_witness/solve_constraints/coercion_fold BODY fil…
briansrls May 21, 2026
88fe2d2
WIP: Wave-4-A — find_witness/solve_constraints/coercion_fold BODY fil…
briansrls May 21, 2026
e6b9c07
fix(v4): keep witness predicates fail-closed
briansrls May 21, 2026
f387b7a
WIP: Wave-4-A — find_witness/solve_constraints/coercion_fold BODY fil…
briansrls May 21, 2026
35784a8
Merge origin/main into Wave-4-A
briansrls May 21, 2026
a6abe14
Tighten find_witness predicate evidence
briansrls May 21, 2026
20db35f
Gate equality witness by preservation rule
briansrls May 21, 2026
a9570c3
Mark narrowed find_witness predicate scaffold
briansrls May 21, 2026
1273d23
Flatten declared inhabitant candidates
briansrls May 21, 2026
d5e292a
WIP: Wave-4-A — find_witness/solve_constraints/coercion_fold BODY fil…
briansrls May 21, 2026
684ee62
Route declared candidates through coercion surface
briansrls May 21, 2026
625f2e6
WIP: Wave-4-A — find_witness/solve_constraints/coercion_fold BODY fil…
briansrls May 21, 2026
fc74b0a
WIP: Wave-4-A — find_witness/solve_constraints/coercion_fold BODY fil…
briansrls May 21, 2026
bd676d4
Assert find_witness identity MVP behavior claims
briansrls May 21, 2026
96c8e92
Merge remote-tracking branch 'origin/main' into session/swift-lark-412
briansrls May 21, 2026
9d8141f
WIP: Wave-4-A — find_witness/solve_constraints/coercion_fold BODY fil…
briansrls May 21, 2026
59b6d9f
WIP: Wave-4-A — find_witness/solve_constraints/coercion_fold BODY fil…
briansrls May 21, 2026
46f6599
WIP: Wave-4-A — find_witness/solve_constraints/coercion_fold BODY fil…
briansrls May 21, 2026
10f0ca2
WIP: Wave-4-A — find_witness/solve_constraints/coercion_fold BODY fil…
briansrls May 21, 2026
83208c5
WIP: Wave-4-A — find_witness/solve_constraints/coercion_fold BODY fil…
briansrls May 21, 2026
f091757
Resolve translate conflict markers
briansrls May 21, 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
11 changes: 8 additions & 3 deletions src/v4/compiler/06_translate.dag
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
// Consumes: compiler/04_infer.dag, compiler/00_compile.dag, std/coercion.dag, std/constraints.dag,
// std/find_witness.dag, std/diagnostic.dag, std/node.dag, std/witness.dag, std/collection.dag.
// Status: W-T-10-impl staging — fold_node + coercion_fold call-shape; canonical_grounding and
// coercion_fold bodies fail closed until T-9 (#3464) + find_witness + T-4 rust.dag land.
// coercion_fold now delegates to find_witness; translate still fails closed where canonical grounding
// or target serialization scaffolds lack substrate facts.
// Anchor: docs/design-v4-compiler-homomorphism.md Stage 5a; Ratified Q14.


Expand All @@ -20,6 +21,7 @@ module v4.compiler.translate

import v4.compiler.compile { TargetModel, TargetSource }
import v4.compiler.infer { InferredTree }
import v4.std.collection { List }
import v4.std.coercion {
CoercionCandidateSet,
CoercionResult,
Expand Down Expand Up @@ -176,8 +178,11 @@ fn target_selection_policy_from_model(target: TargetModel) -> Outcome<TargetSele
}
)
}
fn declared_inhabitant_candidates(inhabitants_root: Node) -> List<Node> {
map(inhabitants_root.children, fn(e) { e.target })
}
// `declared_inhabitants` edge names one closed candidate-set root Node on the target bundle;
// find_witness enumerates inside that root when its body lands — not container-child traversal here.
// translate flattens that root's children into the closed candidate list consumed by find_witness.
fn coercion_candidates_from_target_model(
target: TargetModel,
closedness_evidence: Node
Expand All @@ -188,7 +193,7 @@ fn coercion_candidates_from_target_model(
Accepted {
value: CoercionCandidateSet {
set: CandidateSet {
candidates: [inhabitants_root],
candidates: declared_inhabitant_candidates(inhabitants_root: inhabitants_root),
closedness: StructuralPropertyWitness {
property: target_model_edge_declared_inhabitants,
evidence: closedness_evidence
Expand Down
45 changes: 32 additions & 13 deletions src/v4/std/coercion.dag
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,24 @@ import v4.std.diagnostic {
Outcome,
Rejected,
Unavailable,
diagnostics_singleton,
outcome_rejected,
rejected_with_pending
outcome_rejected
}
import v4.std.find_witness {
CandidateSet,
FindWitnessResult,
PreservationPredicate,
TargetSelection,
TargetSelectionPolicy,
find_witness,
preservation_rule_exact_structural_equality_zip_fold
}
import v4.std.node { Node, Symbol }
import v4.std.node { Conj, Edge, Named, Node, Symbol, TypeNode }
import v4.std.witness { HomomorphismWitness, StructuralPropertyWitness }
data coercion_property_closed_candidate_set: Symbol = coercion_property_closed_candidate_set
data coercion_property_candidate_set_closedness: Symbol = coercion_property_candidate_set_closedness
data coercion_homomorphism_evidence_source: Symbol = coercion_homomorphism_evidence_source
data coercion_homomorphism_evidence_candidate: Symbol = coercion_homomorphism_evidence_candidate
data coercion_homomorphism_evidence_find_witness: Symbol = coercion_homomorphism_evidence_find_witness
data homomorphism_rule_exact_structural_equality: Symbol = homomorphism_rule_exact_structural_equality
data coercion_not_realized: Symbol = coercion_not_realized
data coercion_mismatch_no_target: Symbol = coercion_mismatch_no_target
Expand Down Expand Up @@ -104,6 +106,19 @@ fn declared_candidates_for_algebra(
)
)
}
fn coercion_homomorphism_evidence(
source: CanonicalGrounding,
fw: FindWitnessResult,
) -> Node {
Node {
kind: TypeNode { connective: Conj },
children: [
Edge { label: Named { name: coercion_homomorphism_evidence_source }, target: source.node },
Edge { label: Named { name: coercion_homomorphism_evidence_candidate }, target: fw.candidate },
Edge { label: Named { name: coercion_homomorphism_evidence_find_witness }, target: fw.witness.evidence }
]
}
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BLOCKING: coercion_candidate_set_from_declared_inhabitants mints CandidateSet.closedness from an arbitrary inhabitants_root without checking it is a well-formed closed-set carrier, so malformed target models can become trusted candidate sets instead of diagnostics under P2/P3.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified valid and fixed on current PR head 46f65997.

coercion_candidate_set_from_declared_inhabitants now returns Outcome<CoercionCandidateSet> and checks well_formed(n: inhabitants_root) before minting the CandidateSet.closedness witness. Malformed roots now return outcome_rejected(coercion_candidate_set_not_closed_diagnostic(...)) instead of becoming trusted candidate sets. 06_translate.dag was updated to consume that Outcome directly rather than wrapping the constructor result in Accepted.

Verification run for this fix:

  • python3 scripts/test_strict_deprose_dag.py: PASS
  • python3 scripts/strict_deprose_dag.py --check: PASS
  • git diff --check: PASS
  • rg -n "import v4\\.lens" src/v4/compiler src/v4/std: no matches
  • cargo test -p v3-compiler --test integration v4_bin_main_dag_smoke_test::v4_bin_main_dag_tokenizes_and_parses_with_trampoline_source_anchor -- --exact --quiet: PASS remotely
  • cargo test -p v3-compiler --test integration v4_compiler_emit_translate_smoke_test -- --quiet: PASS remotely

— sent from swift-lark-412

fn coercion_fold(
source: CanonicalGrounding,
candidates: CoercionCandidateSet,
Expand All @@ -118,15 +133,19 @@ fn coercion_fold(
},
multiplicity_policy: TargetSelection { policy: policy }
) {
// Scaffold only while find_witness rejects: W-T-10 must lift FindWitnessResult → CoercionResult here.
Accepted { value: _, diagnostics: fw_d } =>
Rejected {
diagnostics: rejected_with_pending(
pending: fw_d,
rejected: diagnostics_singleton(
d: coercion_not_realized_diagnostic(source: source, kind: NoTargetCandidate)
)
)
Accepted { value: fw, diagnostics: fw_d } =>
Accepted {
value: CoercionResult {
target: fw.candidate,
quality: if fw.candidate == source.node { Identity } else { Exact },
witness: CoercionWitness {
homomorphism: HomomorphismWitness {
rule: homomorphism_rule_exact_structural_equality,
evidence: coercion_homomorphism_evidence(source: source, fw: fw)
}
}
},
diagnostics: fw_d
}
Rejected { diagnostics: r } => Rejected { diagnostics: r }
}
Expand Down
155 changes: 152 additions & 3 deletions src/v4/std/find_witness.dag
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ module v4.std.find_witness

import v4.std.collection { List }
import v4.std.diagnostic {
Accepted,
Diagnostic,
ExternalContractUnknown,
None,
NodeLocus,
Outcome,
Unavailable,
outcome_rejected
}
import v4.std.node { Node, Symbol }
import v4.std.node { Node, Symbol, well_formed }
import v4.std.witness { StructuralPropertyWitness }
data find_witness_reason_no_candidate: Symbol = find_witness_reason_no_candidate
data find_witness_reason_ambiguous_candidate: Symbol = find_witness_reason_ambiguous_candidate
Expand Down Expand Up @@ -70,19 +72,166 @@ fn find_witness_not_realized_diagnostic(source_facts: Node) -> Diagnostic {
correction: Unavailable { reason: ExternalContractUnknown }
}
}
// 🟡 coproduct dissolution — scaffold:exact-structural-preservation-identity-mvp · dissolve-on: W-T-10 structural zip-fold predicate algebra; exact_structural_equality accepts only source-identical Node evidence and other preservation rules fail closed.
fn preservation_predicate_holds(
source_facts: Node,
candidate: Node,
predicate: PreservationPredicate,
) -> Bool {
well_formed(n: source_facts)
&& well_formed(n: predicate.algebra)
&& well_formed(n: candidate)
&& (predicate.preservation_rule == preservation_rule_exact_structural_equality_zip_fold)
&& (predicate.algebra == source_facts)
&& (candidate == source_facts)
}
fn passing_candidate_count(
source_facts: Node,
candidates: CandidateSet,
predicate: PreservationPredicate,
) -> Int {
fold(candidates.candidates, init: 0, f: fn(acc, candidate) {
if preservation_predicate_holds(
source_facts: source_facts,
candidate: candidate,

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against current PR head 96c8e922: this is already addressed by the later Option-A + concept-home fix.

find_witness intentionally folds candidates.candidates, but translate no longer supplies the declared-inhabitants root as that flat list. coercion_candidates_from_target_model obtains inhabitants_root and delegates to std/coercion.coercion_candidate_set_from_declared_inhabitants(...). That helper constructs CandidateSet { candidates: declared_inhabitant_candidates(inhabitants_root), ... }, where declared_inhabitant_candidates maps inhabitants_root.children to e.target. So the root’s children are flattened before find_witness consumes the set.

Relevant current-head locations:

  • src/v4/std/coercion.dag: declared_inhabitant_candidates maps inhabitants_root.children to candidate targets.
  • src/v4/std/coercion.dag: coercion_candidate_set_from_declared_inhabitants stores that flattened list in CandidateSet.candidates.
  • src/v4/compiler/06_translate.dag: coercion_candidates_from_target_model calls the coercion concept-home helper rather than passing the root directly.

No code change needed for this stale finding.

— sent from swift-lark-412

predicate: predicate
) {
acc + 1
} else {
acc
}
})
}
fn only_passing_candidate(
source_facts: Node,
candidates: CandidateSet,
predicate: PreservationPredicate,
) -> Node {
fold(candidates.candidates, init: source_facts, f: fn(acc, candidate) {

This comment was marked as resolved.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against current PR head 46f65997: this is already addressed. only_passing_candidate now returns Outcome<Node> and folds through the typed PassingCandidateFold coproduct (NoPassingCandidate | OnePassingCandidate | ManyPassingCandidates) rather than seeding with source_facts.

Current behavior:

  • zero passing candidates -> Rejected { find_witness_no_candidate_diagnostic(...) }
  • one passing candidate -> Accepted { value: only, ... }
  • multiple passing candidates -> Rejected { find_witness_ambiguous_candidate_diagnostic(...) }

So the helper no longer has a fabricated source-node fallback and cannot return a node that was not selected from the closed candidate set.

— sent from swift-lark-412

if preservation_predicate_holds(
source_facts: source_facts,
candidate: candidate,
predicate: predicate
) {
candidate
} else {
acc
}
})
}
fn selected_candidate_count(
source_facts: Node,
candidates: CandidateSet,
predicate: PreservationPredicate,
selection: Node,
) -> Int {
fold(candidates.candidates, init: 0, f: fn(acc, candidate) {
if (candidate == selection) && preservation_predicate_holds(
source_facts: source_facts,
candidate: candidate,
predicate: predicate
) {
acc + 1
} else {
acc
}
})
}
fn accepted_witness_result(
candidate: Node,
candidates: CandidateSet,
predicate: PreservationPredicate,
) -> Outcome<FindWitnessResult> {
Accepted {
value: FindWitnessResult {
candidate: candidate,
witness: StructuralPropertyWitness {
property: predicate.preservation_rule,
evidence: candidate
},
closedness: candidates.closedness
},
diagnostics: None
}
}
fn resolve_selected_candidate(
source_facts: Node,
candidates: CandidateSet,
predicate: PreservationPredicate,
selection: Node,
) -> Outcome<FindWitnessResult> {
match selected_candidate_count(
source_facts: source_facts,
candidates: candidates,
predicate: predicate,
selection: selection
) {
1 => accepted_witness_result(
candidate: selection,
candidates: candidates,
predicate: predicate
)
0 => outcome_rejected(find_witness_no_candidate_diagnostic(source_facts: source_facts))
_ => outcome_rejected(find_witness_ambiguous_candidate_diagnostic(source_facts: source_facts))
}
}
fn find_witness(
source_facts: Node,
candidates: CandidateSet,
predicate: PreservationPredicate,
multiplicity_policy: MultiplicityPolicy,
) -> Outcome<FindWitnessResult> {
outcome_rejected(find_witness_not_realized_diagnostic(source_facts: source_facts))
let passing_count = passing_candidate_count(
source_facts: source_facts,
candidates: candidates,
predicate: predicate
)
match passing_count {
0 => outcome_rejected(find_witness_no_candidate_diagnostic(source_facts: source_facts))
1 => accepted_witness_result(
candidate: only_passing_candidate(
source_facts: source_facts,
candidates: candidates,
predicate: predicate
),
candidates: candidates,
predicate: predicate
)
_ => match multiplicity_policy {
UniqueOnly =>
outcome_rejected(find_witness_ambiguous_candidate_diagnostic(source_facts: source_facts))
TargetSelection { policy: p } => match p {
TargetDeclaredPriority { priority: priority } =>
resolve_selected_candidate(
source_facts: source_facts,
candidates: candidates,
predicate: predicate,
selection: priority
)
UserSelected { selection: selection } =>
resolve_selected_candidate(
source_facts: source_facts,
candidates: candidates,
predicate: predicate,
selection: selection
)
}
}
}
}
fn verify_witness(
source_facts: Node,
candidate: Node,
predicate: PreservationPredicate,
witness: StructuralPropertyWitness,
) -> Outcome<StructuralPropertyWitness> {
outcome_rejected(find_witness_not_realized_diagnostic(source_facts: source_facts))
if preservation_predicate_holds(
source_facts: source_facts,
candidate: candidate,
predicate: predicate
) && (witness.property == predicate.preservation_rule) && (witness.evidence == candidate) {
Accepted { value: witness, diagnostics: None }
} else {
outcome_rejected(find_witness_no_candidate_diagnostic(source_facts: source_facts))
}
}
2 changes: 1 addition & 1 deletion src/v4/test/claim/manual/mvp1_rust_add_translate.dag
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Scope: MVP-1 T-10 receipt — structural TestClaim anchors for translate/emit substrate.
// Owns: mvp_add_arrow_node, claim_mvp1_translate_module_compiles, claim_mvp1_emit_module_compiles.
// Consumes: compiler/05_emit.dag, compiler/06_translate.dag, std/verification.dag, std/diagnostic.dag, std/node.dag.
// Status: parse-surface receipt; full InferredTree(add)->Accepted emit blocked on std/find_witness body.
// Status: parse-surface receipt; full InferredTree(add)->Accepted emit remains blocked on compiler-stage canonical grounding and target serialization scaffolds.
// Anchor: docs/design-v4-compiler-homomorphism.md MVP-1 worked example.


Expand Down
Loading