You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some nodes need to provide context features for their downstream dependencies (in the function call stack building phase). This is accomplished through `Inject*` traits that complement the `Extract*` traits:
60
+
61
+
```rust
62
+
// A node that injects index information for downstream map operations
The different `Extract*` traits are exported by the node macro and could thus be included as part of the document node definition to inform the compiler about features extracted in every node. Note that the `ExtractAll` will be ignored in this analysis. Any usages of partial context data are propagated downstream and all nodes are identified in which the number of extracted features changes between the upstream and downstream. At these locations a context modification needs to be inserted which "zeros" the data no longer used in the upstream part of the graph.
61
-
Note that the number of features extracted can usually only increase except for cases where a node decides to inject data into the call chain.
62
-
This will be the case when building lambda expressions, the node driving the lambda evaluation (e.g. a map or a fold node) would insert data such as the index into the call chain.
63
-
We might consider adding a special `Inject*` annotation in the future to indicate that the downstream of this node does not need to provide the feature even though the upstream does need it.
94
+
The different `Extract*` and `Inject*` traits are exported by the node macro and are included as part of the document node definition to inform the compiler about features extracted and injected by every node. Note that the `ExtractAll` will be ignored in this analysis.
95
+
96
+
## Context Nullification Analysis
97
+
98
+
The compiler determines where to insert context nullification nodes through branch analysis:
99
+
100
+
1.**Extract Requirement Tracking**: For each branch in the graph, track the extract requirements all the way back to their corresponding inject nodes. Every extracted feature must have a corresponding inject node somewhere upstream, otherwise this is a compile error.
101
+
102
+
2.**Branch Convergence Analysis**: When two branches with different extract requirements meet (at a node that takes multiple inputs), one or both branches can have their context nullified to remove features only needed in the other branch.
103
+
104
+
3.**Post-Injection Nullification**: After an inject node, the extract needs of downstream nodes are satisfied for that inject type. At this point we can check if all the features that the inject node provides are actually used downstream, and if not, nullify them immediately.
105
+
106
+
4.**Injection Scope Optimization**: After every inject node, analyze whether all injected features are actually consumed by downstream nodes. Unused injected features can be nullified right at the injection point.
107
+
108
+
## Inject* Trait System
109
+
110
+
The injection system provides these complementary traits to Extract*:
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.
131
+
64
132
This can be implemented as a compiler pass similar to the compose node insertion.
65
133
66
134
# Drawbacks
@@ -84,4 +152,4 @@ This is expected to have the biggest impact on real time applications such as an
84
152
# Future possibilities
85
153
[future-possibilities]: #future-possibilities
86
154
87
-
Adding `Inject*` annotation to complement the `Extract*` ones to provide even more fine grained control over caching.
155
+
~Adding `Inject*` annotation to complement the `Extract*` ones to provide even more fine grained control over caching.~
0 commit comments