nk
1.0.0
C++ Numerical Computing Runtime
Toggle main menu visibility
Loading...
Searching...
No Matches
dependency_graph.hpp
1
34
35
#pragma once
36
37
#include <nk/core/ast.hpp>
38
#include <nk/core/elem_regions.hpp>
39
40
#include <set>
41
#include <string>
42
#include <vector>
43
44
namespace
nk {
45
55
inline
constexpr
char
kFigureStateVar[] =
"__nk_figstate__"
;
56
57
struct
StatementFacts
58
{
59
bool
wildcardReads =
false
;
// Reads = * (opaque statement)
60
std::set<std::string> reads;
61
std::set<std::string> writes;
62
63
// Fine-grained element access (portion B1): variable → regions
64
// touched on the READ side / WRITE side. All accesses that are not
65
// statically literal collapse to VarRegions::all (conservative).
66
// Coarse `reads`/`writes` stay authoritative; the maps refine them.
67
ElemAccessMap elemReads;
68
ElemAccessMap elemWrites;
69
70
// Variables whose coarse `reads` entry came ONLY from a merge-write
71
// LHS (`C{5,2} = v` — the LHS does NOT read the old value; the
72
// coarse read exists for portion-A dirtySetFor compatibility).
73
// Element-level dirty sets use this to skip cell definitions.
74
std::set<std::string> lhsMergeBases;
75
};
76
79
std::vector<StatementFacts> computeStatementFacts(
const
ASTNode
*program);
80
84
class
DependencyGraph
85
{
86
public
:
90
explicit
DependencyGraph
(std::vector<StatementFacts> facts);
91
97
std::vector<size_t>
dirtySetFor
(
const
std::string &var)
const
;
98
103
std::vector<size_t>
dirtySetFor
(
104
const
std::string &var,
105
const
std::set<std::string> &externalDefs)
const
;
106
113
std::vector<size_t>
dirtySetForElement
(
const
std::string &var,
114
size_t
r,
size_t
c)
const
;
115
std::vector<size_t>
dirtySetForElement
(
116
const
std::string &var,
size_t
r,
size_t
c,
117
const
std::set<std::string> &externalDefs)
const
;
118
119
const
std::vector<StatementFacts> &facts()
const
{
return
facts_; }
120
size_t
size()
const
{
return
facts_.size(); }
123
const
std::vector<size_t> &
downstreamOf
(
size_t
i)
const
124
{
125
return
downstream_[i];
126
}
127
128
private
:
129
std::vector<StatementFacts> facts_;
130
std::vector<std::vector<size_t>> downstream_;
// i → dependents
131
};
132
133
}
// namespace nk
nk::DependencyGraph::DependencyGraph
DependencyGraph(std::vector< StatementFacts > facts)
Build from facts.
nk::DependencyGraph::dirtySetForElement
std::vector< size_t > dirtySetForElement(const std::string &var, size_t r, size_t c) const
Element-level variant: external write of ONE CELL (the table editor's setParamElement).
nk::DependencyGraph::dirtySetFor
std::vector< size_t > dirtySetFor(const std::string &var) const
Indices that must re-run when var is assigned externally.
nk::DependencyGraph::dirtySetFor
std::vector< size_t > dirtySetFor(const std::string &var, const std::set< std::string > &externalDefs) const
With the set of EXTERNALLY-DEFINED params (ReactiveSession): the wildcard-prefix rule additionally sk...
nk::DependencyGraph::downstreamOf
const std::vector< size_t > & downstreamOf(size_t i) const
Direct dependents of statement i (edges i → j).
Definition
dependency_graph.hpp:123
nk::ASTNode
Definition
ast.hpp:66
nk::StatementFacts
Definition
dependency_graph.hpp:58
src
core
include
nk
core
dependency_graph.hpp
Generated by
1.17.0