Skip to content

Commit f40f292

Browse files
committed
Explicitly support context modification
1 parent cf477e9 commit f40f292

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

node-graph/rfcs/fine-grained-context-caching.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,53 @@ pub trait InjectVarArgs {
127127
}
128128
```
129129

130+
## Context Feature Modification Traits
131+
132+
The modification system provides marker traits for nodes that transform context features without necessarily depending on them:
133+
134+
```rust
135+
pub trait ModifyFootprint: ExtractFootprint + InjectFootprint {}
136+
pub trait ModifyTime: ExtractTime + InjectTime {}
137+
pub trait ModifyIndex: ExtractIndex + InjectIndex {}
138+
pub trait ModifyVarArgs: ExtractVarArgs + InjectVarArgs {}
139+
```
140+
141+
### Conditional Context Dependencies
142+
Modify* traits represent a special case in context analysis:
143+
144+
```rust
145+
// Transform node example - modifies footprint but doesn't need it unless downstream requires it
146+
#[node_macro::node(category("Transform"))]
147+
fn transform(
148+
ctx: impl Ctx + ModifyFootprint,
149+
input: Vector,
150+
transform: Transform2D
151+
) -> Vector {
152+
// This node can extract the footprint, modify it, and inject the result
153+
// But if no downstream node needs the footprint, this node doesn't need it either
154+
let modified_footprint = ctx.footprint().transform(transform);
155+
// ... transform logic ...
156+
}
157+
```
158+
159+
### Optimization Implications for Modify* Traits
160+
1. **Conditional Requirements**: Modify* nodes only require their features if downstream nodes extract them
161+
2. **Pass-through Optimization**: If no downstream extraction occurs, the Modify* node can be treated as if it has no context requirements
162+
3. **Transform Chains**: Multiple Modify* nodes can be chained together, with requirements only propagating if there's a final Extract* consumer
163+
164+
Example optimization:
165+
```
166+
[Node A] -> [ModifyFootprint] -> [ModifyFootprint] -> [ExtractTime]
167+
↑ ↑ ↑
168+
No footprint needed No footprint needed Only time needed
169+
170+
[Node A] -> [ModifyFootprint] -> [ModifyFootprint] -> [ExtractFootprint]
171+
↑ ↑ ↑
172+
Footprint needed Footprint needed Footprint needed
173+
```
174+
175+
This allows transform chains to be highly optimized when their modifications aren't actually consumed downstream.
176+
130177
Note that "downstream" in this context refers to nodes that are called later in the function call stack building phase, which is inverted compared to the usual data flow direction.
131178

132179
This can be implemented as a compiler pass similar to the compose node insertion.

0 commit comments

Comments
 (0)