Skip to content
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
43 changes: 37 additions & 6 deletions src/v4/compiler/06_translate.dag
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ import v4.std.target_model {
target_type_expr_emitted_kind,
target_type_expr_record_emitted,
target_type_expr_sum_emitted,
type_expr_projection_row_closedness_from_target
type_expr_projection_graft_substrate_in_row_slot,
type_expr_projection_row_closedness_from_target,
type_expr_projection_graft_witness_gate
}
import v4.std.target_model {
TargetAtomRealization,
Expand Down Expand Up @@ -2413,14 +2415,43 @@ fn project_type_expression_connective_bounded(
),
f: fn(original_split) {
bind_outcome(
o: project_type_expression_arrow_emitted_from_original_split(
o: translate_project_arrow_split_types(
original_split: original_split,
anchor: node,
target: target,
projection: projection
projection: projection,
anchor: node
),
f: fn(emitted) {
Accepted { value: emitted, diagnostics: None }
f: fn(split) {
bind_outcome(
o: type_expr_projection_graft_substrate_in_row_slot(
projection: projection,
connective: Arrow,
node: node,
projected_positional: list_append(
left: split.inputs,
right: Cons { head: split.output, tail: Empty }
)
),
f: fn(grafted) {
bind_outcome(
o: type_expr_projection_graft_witness_gate(
source_facts: grafted,
projection: projection,
connective: Arrow
),
f: fn(_) {
Accepted {
value: target_type_expr_arrow_emitted(
form: projection.arrow_form,
inputs: split.inputs,
output: split.output
),
diagnostics: None
}
}
)
}
)
}
)
}
Expand Down
13 changes: 12 additions & 1 deletion src/v4/std/find_witness.dag
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ import v4.std.project_to_core_predicate {
project_to_core_preservation_holds
}
import v4.std.refinement_widening_predicate { refinement_widening_preservation_holds }
import v4.std.type_expr_projection_discipline_zip_fold_predicate {
type_expr_projection_discipline_zip_fold_preservation_holds
}
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
Expand All @@ -40,6 +43,7 @@ data preservation_rule_constraint_satisfaction: Symbol = preservation_rule_const
data preservation_rule_exact_structural_equality_zip_fold: Symbol = preservation_rule_exact_structural_equality_zip_fold
data preservation_rule_refinement_widening: Symbol = preservation_rule_refinement_widening
data preservation_rule_project_to_core: Symbol = preservation_rule_project_to_core
data preservation_rule_type_expr_projection_discipline_zip_fold: Symbol = preservation_rule_type_expr_projection_discipline_zip_fold
type CandidateSet {
candidates: List<Node>
closedness: StructuralPropertyWitness
Expand Down Expand Up @@ -78,7 +82,8 @@ fn realized_preservation_rules() -> List<Symbol> {
preservation_rule_constraint_satisfaction,
preservation_rule_exact_structural_equality_zip_fold,
preservation_rule_refinement_widening,
preservation_rule_project_to_core
preservation_rule_project_to_core,
preservation_rule_type_expr_projection_discipline_zip_fold
]
}
fn find_witness_no_candidate_diagnostic(source_facts: Node) -> Diagnostic {
Expand Down Expand Up @@ -147,6 +152,12 @@ fn preservation_predicate_holds(
candidate: candidate,
algebra: predicate.algebra
)
} else if predicate.preservation_rule == preservation_rule_type_expr_projection_discipline_zip_fold {
type_expr_projection_discipline_zip_fold_preservation_holds(
source_facts: source_facts,
candidate: candidate,
algebra: predicate.algebra
)
} else {
false
}
Expand Down
64 changes: 63 additions & 1 deletion src/v4/std/node_query.dag
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ import v4.std.diagnostic {
outcome_accepted,
outcome_rejected
}
import v4.std.algebra { Empty, list_snoc_item }
import v4.std.algebra { Cons, Empty, FreeMonoid, list_snoc_item }
import v4.std.collection {
List,
Optional,
optional_absent,
optional_present
}
import v4.std.type_expr_projection_row_schema {
target_type_expr_field_child_slots
}
import v4.std.node {
Ambiguous,
Arrow,
Expand Down Expand Up @@ -54,6 +63,59 @@ fn node_labeled_child_edges(node: Node) -> List<Edge> {
})
}

// 🟡 gated — predicate-dissolution interim (docs/modeling-discipline.md Practice 10) — feature: node-envelope-without-named-coordinate — bind node://adhoc-sg2-envelope-peel — dissolve-on-arrival: substrate canonical peel of ≤1 named coordinate from a Conj envelope edge list; forbidden: parallel edge-label Bool filters outside std/node_query.
fn node_envelope_without_named_coordinate_go(
xs: FreeMonoid<Edge>,
coordinate: Symbol,
acc: FreeMonoid<Edge>,
saw_coordinate: Bool
) -> Optional<FreeMonoid<Edge>> {
match xs {
Empty => optional_present(value: acc)
Cons { head: h, tail: t } =>
match h.label {
Named { name: n } =>
if n == coordinate {
if saw_coordinate {
optional_absent()
} else {
node_envelope_without_named_coordinate_go(
xs: t,
coordinate: coordinate,
acc: acc,
saw_coordinate: true
)
}
} else {
node_envelope_without_named_coordinate_go(
xs: t,
coordinate: coordinate,
acc: list_snoc_item(xs: acc, item: h),
saw_coordinate: saw_coordinate
)
}
Positional =>
node_envelope_without_named_coordinate_go(
xs: t,
coordinate: coordinate,
acc: list_snoc_item(xs: acc, item: h),
saw_coordinate: saw_coordinate
)
}
}
}

fn node_envelope_without_named_coordinate(
children: FreeMonoid<Edge>,
coordinate: Symbol
) -> Optional<FreeMonoid<Edge>> {
node_envelope_without_named_coordinate_go(
xs: children,
coordinate: coordinate,
acc: Empty,
saw_coordinate: false
)
}

// 🟢 grounded — canonical single-named-edge-target lookup via name_occurrences uniqueness gate
// (Practice 10: no parallel EdgeLabel walker). Misses and ambiguities fail closed via Outcome.
Expand Down
103 changes: 100 additions & 3 deletions src/v4/std/target_model.dag
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ import v4.std.find_witness {
PreservationPredicate,
UniqueOnly,
find_witness,
preservation_rule_exact_structural_equality_zip_fold
preservation_rule_exact_structural_equality_zip_fold,
preservation_rule_type_expr_projection_discipline_zip_fold
}
import v4.std.node {
Arrow,
Expand Down Expand Up @@ -79,7 +80,8 @@ import v4.std.type_expr_projection_row_schema {
target_type_expr_discipline_labeled,
target_type_expr_discipline_no_edges,
target_type_expr_discipline_positional,
target_type_expr_field_child_slot_discipline
target_type_expr_field_child_slot_discipline,
target_type_expr_field_child_slots
}
import v4.std.node_query { find_named_child, node_labeled_child_edges, node_positional_child_targets }
import v4.std.logic { Bool }
Expand Down Expand Up @@ -3590,6 +3592,26 @@ fn type_expr_projection_row_shape_envelope(
}
}

// SG-2 fold — substrate child slots as named coordinate (substrate TypeNode authority; not flat Conj mix).
fn type_expr_projection_graft_child_slots_coordinate(
envelope: Node,
facts: Node
) -> Node {
Node {
kind: envelope.kind,
children: list_append(
left: envelope.children,
right: Cons {
head: target_model_named_edge(
name: target_type_expr_field_child_slots,
target: facts
),
tail: Empty
}
)
}
}

// P2 row-shape authority — consumed by *type_expression_projection_bundle_node in language targets.
fn type_expr_projection_step_algebra(projection: TargetTypeExpressionProjection) -> Node {
Node {
Expand Down Expand Up @@ -3714,6 +3736,67 @@ fn type_expr_projection_candidate_for_connective(
)
}

// SG-2 fold — anchored substrate TypeNode with projected positional children (checkpoint 3).
// Labeled Conj/Disj substrates keep node.children; positional connectives pass projected list.
fn type_expr_projection_substrate_facts(
node: Node,
projected_positional: List<Node>
) -> Node {
match node.kind {
TypeNode { connective: Conj } =>
Node {
kind: node.kind,
children: node.children
}
TypeNode { connective: Disj } =>
Node {
kind: node.kind,
children: node.children
}
_ =>
Node {
kind: node.kind,
children: fold_list(
xs: projected_positional,
empty: Empty,
cons: fn(acc, child) {
list_snoc_item(
xs: acc,
item: Edge { label: Positional, target: child }
)
}
)
}
}
}

// SG-2 fold — graft substrate child slots into row envelope (discipline + delimiter metadata).
fn type_expr_projection_graft_substrate_in_row_slot(
projection: TargetTypeExpressionProjection,
connective: Connective,
node: Node,
projected_positional: List<Node>
) -> Outcome<Node> {
let facts = type_expr_projection_substrate_facts(
node: node,
projected_positional: projected_positional
)
bind_outcome(
o: type_expr_projection_shape_for_connective(
projection: projection,
connective: connective
),
f: fn(envelope) {
outcome_accepted(
type_expr_projection_graft_child_slots_coordinate(
envelope: envelope,
facts: facts
)
)
}
)
}

fn type_expr_projection_row_witness_gate_with_rule(
source_facts: Node,
projection: TargetTypeExpressionProjection,
Expand Down Expand Up @@ -3757,7 +3840,21 @@ fn type_expr_projection_row_shape_witness_gate(
)
}

// SG-2 fold — connective → step_algebra row slot field (uniform key for bundle decode).
// SG-2 fold — grafted substrate witness gate (requires child_slots coordinate; discipline zip-fold).
fn type_expr_projection_graft_witness_gate(
source_facts: Node,
projection: TargetTypeExpressionProjection,
connective: Connective
) -> Outcome<Node> {
type_expr_projection_row_witness_gate_with_rule(
source_facts: source_facts,
projection: projection,
connective: connective,
preservation_rule: preservation_rule_type_expr_projection_discipline_zip_fold
)
}

// SG-2 fold — connective → step_algebra row slot field (uniform key for graft + bundle decode).
fn type_expr_projection_row_field_for_connective(connective: Connective) -> Symbol {
match connective {
Atom { identity: _ } => target_type_expr_field_atom
Expand Down
Loading