Repository navigation
T-13 — lens family expansion: lens/parallelism.dag + lens/effect.dag + lens/ownership.dag + lens/idempotency.dag (one mechanism, projection-only per Practice 11; lens-over-substrate enforced; reads InferredTree + dependency-graph projection; produces Witness<dimension>; canonical reference = T-12 PR #3468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
2cc01cd
799190a
46e61fb
f3ca9ae
3bfa3c8
c7fffd8
1b1f691
16ecf88
0daecbc
ff87fa0
993c8ff
eefc5a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,3 +69,133 @@ | |
|
|
||
|
|
||
| module v4.lens.effect | ||
|
|
||
| import v4.compiler.infer { InferredFacts, InferredTree } | ||
| import v4.std.dependency { | ||
| BarrierBefore, | ||
| DataDependsOn, | ||
| DependencyView, | ||
| EffectDependsOn, | ||
| ResourceDependsOn | ||
| } | ||
| import v4.std.node { Node } | ||
| import v4.std.witness { Holds, Witness } | ||
|
|
||
| // 🟢 projection carrier — Practice 11: effect facts are read from the | ||
| // dependency projection and the inferred root, not authored as a second | ||
| // OperationEffect taxonomy. | ||
| type EffectKind | ||
| = PureEffect | ||
| | ReadEffect | ||
| | WriteEffect | ||
| | BarrierEffect | ||
|
|
||
| type EffectDependencyFact { | ||
| at: Node | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BLOCKING: EffectDependencyFact stores at beside dependency.source, so the substrate can represent a fact whose location disagrees with its dependency edge, violating P2 illegal states unrepresentable/single authority. |
||
| dependency: DependencyView | ||
| source_facts: Witness<InferredFacts> | ||
| dependent_facts: Witness<InferredFacts> | ||
| effect: EffectKind | ||
| } | ||
|
|
||
| type EffectFact { | ||
| dependencies: List<EffectDependencyFact> | ||
| } | ||
|
|
||
| fn effect_kind_for_dependency(view: DependencyView) -> EffectKind { | ||
| match view.kind { | ||
| DataDependsOn => ReadEffect | ||
| EffectDependsOn => WriteEffect | ||
| ResourceDependsOn => WriteEffect | ||
| BarrierBefore => BarrierEffect | ||
| _ => PureEffect | ||
|
briansrls marked this conversation as resolved.
Resolved
|
||
| } | ||
| } | ||
|
|
||
| fn inferred_facts_for_node(tree: InferredTree, node: Node) -> Witness<InferredFacts> { | ||
| tree.facts.lookup(node) | ||
| } | ||
|
|
||
| fn effect_dependency_fact(tree: InferredTree, view: DependencyView) -> EffectDependencyFact { | ||
| EffectDependencyFact { | ||
| at: view.source, | ||
| dependency: view, | ||
| source_facts: inferred_facts_for_node(tree: tree, node: view.source), | ||
| dependent_facts: inferred_facts_for_node(tree: tree, node: view.dependent), | ||
| effect: effect_kind_for_dependency(view: view) | ||
| } | ||
| } | ||
|
|
||
| fn effect_fact_from_dependencies(tree: InferredTree, dependencies: List<DependencyView>) -> EffectFact { | ||
| EffectFact { | ||
| dependencies: fold(dependencies, init: [], f: fn(acc, view) { | ||
| list_push(acc, effect_dependency_fact(tree: tree, view: view)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| fn effect_fact(tree: InferredTree, dependencies: List<DependencyView>) -> EffectFact { | ||
| effect_fact_from_dependencies(tree: tree, dependencies: dependencies) | ||
| } | ||
|
|
||
| fn effect_witness(tree: InferredTree, dependencies: List<DependencyView>) -> Witness<EffectFact> { | ||
| Holds { | ||
| value: effect_fact(tree: tree, dependencies: dependencies) | ||
| } | ||
| } | ||
|
|
||
| fn effect_kind_eq(a: EffectKind, b: EffectKind) -> Bool { | ||
|
briansrls marked this conversation as resolved.
Resolved
|
||
| match a { | ||
| PureEffect => match b { | ||
| PureEffect => true | ||
| _ => false | ||
| } | ||
| ReadEffect => match b { | ||
| ReadEffect => true | ||
| _ => false | ||
| } | ||
| WriteEffect => match b { | ||
| WriteEffect => true | ||
| _ => false | ||
| } | ||
| BarrierEffect => match b { | ||
| BarrierEffect => true | ||
| _ => false | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn effect_dependency_fact_eq(a: EffectDependencyFact, b: EffectDependencyFact) -> Bool { | ||
| (a.at == b.at) | ||
| && (a.dependency == b.dependency) | ||
| && (a.source_facts == b.source_facts) | ||
| && (a.dependent_facts == b.dependent_facts) | ||
| && effect_kind_eq(a: a.effect, b: b.effect) | ||
| } | ||
|
|
||
| fn effect_dependency_count(xs: List<EffectDependencyFact>, item: EffectDependencyFact) -> Int { | ||
| fold(xs, init: 0, f: fn(acc, candidate) { | ||
| if effect_dependency_fact_eq(a: candidate, b: item) { | ||
| acc + 1 | ||
| } else { | ||
| acc | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| fn effect_dependency_facts_eq( | ||
| left: List<EffectDependencyFact>, | ||
| right: List<EffectDependencyFact> | ||
| ) -> Bool { | ||
| if count(left) != count(right) { | ||
| false | ||
| } else { | ||
| fold(left, init: true, f: fn(acc, item) { | ||
| acc && (effect_dependency_count(xs: left, item: item) == effect_dependency_count(xs: right, item: item)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| fn effect_fact_eq(a: EffectFact, b: EffectFact) -> Bool { | ||
| effect_dependency_facts_eq(left: a.dependencies, right: b.dependencies) | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,3 +18,137 @@ | |
|
|
||
| module v4.lens.ownership | ||
|
|
||
| import v4.compiler.infer { InferredFacts, InferredTree } | ||
| import v4.std.dependency { | ||
| BindsTo, | ||
| Contains, | ||
| DataDependsOn, | ||
| DependencyView, | ||
| EffectDependsOn, | ||
| ResourceDependsOn | ||
| } | ||
| import v4.std.node { Node } | ||
| import v4.std.witness { Holds, Witness } | ||
|
|
||
| // 🟢 projection carrier — ownership is read from dependency/resource shape. | ||
| // This lens does not model a target-specific borrow checker; emit/eval | ||
| // consume this map when they realize the target memory model. | ||
| type OwnershipMode | ||
| = OwnedContainment | ||
| | SharedRead | ||
| | ExclusiveMutation | ||
| | BorrowedDependency | ||
|
|
||
| type OwnershipDependencyFact { | ||
| owner: Node | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BLOCKING: OwnershipDependencyFact duplicates owner and subject beside dependency.source and dependency.dependent, so ownership facts can drift from the edge they claim to project from. |
||
| subject: Node | ||
| dependency: DependencyView | ||
| owner_facts: Witness<InferredFacts> | ||
| subject_facts: Witness<InferredFacts> | ||
| mode: OwnershipMode | ||
| } | ||
|
|
||
| type OwnershipFact { | ||
| dependencies: List<OwnershipDependencyFact> | ||
| } | ||
|
|
||
| fn ownership_mode_for_dependency(view: DependencyView) -> OwnershipMode { | ||
| match view.kind { | ||
| Contains => OwnedContainment | ||
| BindsTo => BorrowedDependency | ||
| DataDependsOn => SharedRead | ||
| EffectDependsOn => ExclusiveMutation | ||
| ResourceDependsOn => ExclusiveMutation | ||
|
briansrls marked this conversation as resolved.
Resolved
|
||
| _ => BorrowedDependency | ||
| } | ||
| } | ||
|
|
||
| fn ownership_inferred_facts_for_node(tree: InferredTree, node: Node) -> Witness<InferredFacts> { | ||
| tree.facts.lookup(node) | ||
| } | ||
|
|
||
| fn ownership_dependency_fact(tree: InferredTree, view: DependencyView) -> OwnershipDependencyFact { | ||
| OwnershipDependencyFact { | ||
| owner: view.source, | ||
| subject: view.dependent, | ||
| dependency: view, | ||
| owner_facts: ownership_inferred_facts_for_node(tree: tree, node: view.source), | ||
| subject_facts: ownership_inferred_facts_for_node(tree: tree, node: view.dependent), | ||
| mode: ownership_mode_for_dependency(view: view) | ||
| } | ||
| } | ||
|
|
||
| fn ownership_fact_from_dependencies(tree: InferredTree, dependencies: List<DependencyView>) -> OwnershipFact { | ||
| OwnershipFact { | ||
| dependencies: fold(dependencies, init: [], f: fn(acc, view) { | ||
| list_push(acc, ownership_dependency_fact(tree: tree, view: view)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| fn ownership_fact(tree: InferredTree, dependencies: List<DependencyView>) -> OwnershipFact { | ||
| ownership_fact_from_dependencies(tree: tree, dependencies: dependencies) | ||
| } | ||
|
|
||
| fn ownership_witness(tree: InferredTree, dependencies: List<DependencyView>) -> Witness<OwnershipFact> { | ||
| Holds { | ||
| value: ownership_fact(tree: tree, dependencies: dependencies) | ||
| } | ||
| } | ||
|
|
||
| fn ownership_mode_eq(a: OwnershipMode, b: OwnershipMode) -> Bool { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. BLOCKING: ownership_mode_eq hand-rolls equality over the new OwnershipMode coproduct even though structural identity is derived and the helper has no Practice 10 disposition/receipt. |
||
| match a { | ||
| OwnedContainment => match b { | ||
| OwnedContainment => true | ||
| _ => false | ||
| } | ||
| SharedRead => match b { | ||
| SharedRead => true | ||
| _ => false | ||
| } | ||
| ExclusiveMutation => match b { | ||
| ExclusiveMutation => true | ||
| _ => false | ||
| } | ||
| BorrowedDependency => match b { | ||
| BorrowedDependency => true | ||
| _ => false | ||
| } | ||
| } | ||
| } | ||
|
|
||
| fn ownership_dependency_fact_eq(a: OwnershipDependencyFact, b: OwnershipDependencyFact) -> Bool { | ||
| (a.owner == b.owner) | ||
| && (a.subject == b.subject) | ||
| && (a.dependency == b.dependency) | ||
| && (a.owner_facts == b.owner_facts) | ||
| && (a.subject_facts == b.subject_facts) | ||
| && ownership_mode_eq(a: a.mode, b: b.mode) | ||
| } | ||
|
|
||
| fn ownership_dependency_count(xs: List<OwnershipDependencyFact>, item: OwnershipDependencyFact) -> Int { | ||
| fold(xs, init: 0, f: fn(acc, candidate) { | ||
| if ownership_dependency_fact_eq(a: candidate, b: item) { | ||
| acc + 1 | ||
| } else { | ||
| acc | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| fn ownership_dependency_facts_eq( | ||
| left: List<OwnershipDependencyFact>, | ||
| right: List<OwnershipDependencyFact> | ||
| ) -> Bool { | ||
| if count(left) != count(right) { | ||
| false | ||
| } else { | ||
| fold(left, init: true, f: fn(acc, item) { | ||
| acc && (ownership_dependency_count(xs: left, item: item) == ownership_dependency_count(xs: right, item: item)) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| fn ownership_fact_eq(a: OwnershipFact, b: OwnershipFact) -> Bool { | ||
| ownership_dependency_facts_eq(left: a.dependencies, right: b.dependencies) | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.