A11 (C++ runtime)
Native C++ implementation of the A11 streaming action runtime
Loading...
Searching...
No Matches
resolve.h
Go to the documentation of this file.
1/*
2 * Copyright 2026 The A11 Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef A11_FLOW_RESOLVE_H_
18#define A11_FLOW_RESOLVE_H_
19
20#include <optional>
21#include <string>
22#include <string_view>
23#include <vector>
24
25#include <absl/container/flat_hash_map.h>
26
27#include "a11/flow/diagnostic.h"
28#include "a11/flow/graph.h"
29#include "a11/flow/parser.h"
30#include "a11/flow/plan.h"
31#include "a11/flow/syntax.h"
32
33namespace a11::flow {
34
36enum class SymbolKind {
38 kSink,
46 kHeader,
48 kCall,
50 kNode,
58 kCarry,
63 kValue,
64};
65
72struct Symbol {
74 std::string name;
78 bool implicit = false;
81
82 [[nodiscard]] bool VisibleAt(size_t offset) const {
83 return visibility.end <= visibility.start ||
85 }
86
88 bool readable = true;
90 bool writable = false;
93 std::string action;
94 bool tolerant = false;
95 const FlowPlan* absl_nullable target = nullptr;
97 int reads = 0;
98 int writes = 0;
111 bool data_dependency = false;
121 std::string pattern;
122 std::string shape;
123 std::optional<syntax::TypeExpression> value_type;
124};
125
128 kSink,
129 kUnknown,
130 kValue,
131 kStream,
132 kCall,
133 kNode,
135};
136
142 std::string type;
143 std::string action;
144 std::string port;
145 std::string description;
146 const FlowPlan* absl_nullable callable = nullptr;
147 const DtoPlan* absl_nullable shape = nullptr;
148 std::vector<std::string> fields;
149 bool unary = false;
150 bool cardinality_known = false;
151 bool writable = false;
152};
153
157 std::optional<FlowPlan> implementation;
158 std::vector<FlowPlan> contracts;
159 bool ambiguous = false;
169 std::vector<Symbol> symbols;
170 absl::flat_hash_map<const syntax::Node*, ExpressionInfo> expressions;
174 const syntax::FlowDeclaration* absl_nullable declaration = nullptr;
175};
176
180 std::vector<ResolvedFlow> flows;
181 std::vector<Diagnostic> diagnostics;
182
183 [[nodiscard]] bool HasErrors() const;
184 [[nodiscard]] const Diagnostic* absl_nullable FirstError() const;
185};
186
190ResolveResult Resolve(std::string_view source, const ParseResult& parsed,
191 bool build_graph = false,
192 const Program* absl_nullable context = nullptr,
194 CompilationBudget* absl_nullable budget = nullptr);
195
197std::string_view SymbolKindName(SymbolKind kind);
198
199} // namespace a11::flow
200
201#endif // A11_FLOW_RESOLVE_H_
TokenKind kind
Definition format.cc:1372
CompilationLimits limits
Definition main.cc:148
CompilationBudget budget
Definition lsp.cc:289
ParseResult parsed
Definition module.cc:50
constexpr size_t kNone
Sentinel for an absent graph ID.
Definition graph.h:45
size_t RefId
Graph IDs are indices into the owning graph's vectors.
Definition graph.h:39
size_t StepId
Definition graph.h:40
@ kSink
A virtual continuation destination and its attached writer group.
Definition catalogue.cc:29
@ kCall
A bound run/call step.
@ kHeader
A header, under its alias.
@ kNode
A node of the flow's own.
@ kBarrier
A bound wait/close.
ExpressionCategory
Native result categories used by resolution and editor queries.
Definition resolve.h:127
std::string_view SymbolKindName(SymbolKind kind)
The name of a symbol kind, for a message and for the JSON.
Definition resolve.cc:6638
SymbolKind
What a name means inside a flow.
Definition resolve.h:36
@ kOutputPort
An out port: written, never read... except by this flow, which may read back what it wrote to one onl...
@ kInputPort
An in port: read, never written.
@ kLoopVariable
A for variable, or the index every loop binds.
@ kValue
One value, read from a stream and given a name by value.
@ kCarry
What a repeat carries.
ResolveResult Resolve(std::string_view source, const ParseResult &parsed, bool build_graph, const Program *context, CompilationLimits limits, CompilationBudget *budget)
Definition resolve.cc:6666
std::uint32_t offset
Definition runtime_streams.cc:36
Host-controlled bounds shared by parsing, linking and semantic analysis.
Definition limits.h:24
Flow problem rendered by the CLI, JSON and SARIF writers, and editors.
Definition diagnostic.h:99
One compiled struct: a shape a port may be typed with.
Definition plan.h:87
The statically known interface of one expression, borrowing its program.
Definition resolve.h:138
size_t symbol
The lexical binding of a Name, when resolution establishes one.
Definition resolve.h:140
const FlowPlan *absl_nullable callable
Definition resolve.h:146
ExpressionCategory category
Definition resolve.h:141
bool writable
Definition resolve.h:151
std::string type
Definition resolve.h:142
std::string port
Definition resolve.h:144
std::vector< std::string > fields
Definition resolve.h:148
std::string description
Definition resolve.h:145
bool cardinality_known
Definition resolve.h:150
const DtoPlan *absl_nullable shape
Definition resolve.h:147
bool unary
Definition resolve.h:149
std::string action
Definition resolve.h:143
One compiled flow: what a caller sees, and what the runtime will do.
Definition plan.h:157
The flows a file declares, and everything wrong with it.
Definition parser.h:34
Every flow and shape one source file declares.
Definition plan.h:200
A whole file, resolved.
Definition resolve.h:178
Program program
Definition resolve.h:179
std::vector< ResolvedFlow > flows
Definition resolve.h:180
std::vector< Diagnostic > diagnostics
Definition resolve.h:181
const Diagnostic *absl_nullable FirstError() const
Definition resolve.cc:6634
bool HasErrors() const
Definition resolve.cc:6630
One flow, resolved: its plan, its names, and what is wrong with it.
Definition resolve.h:155
std::optional< FlowPlan > implementation
Definition resolve.h:157
absl::flat_hash_map< const syntax::Node *, ExpressionInfo > expressions
Definition resolve.h:170
const syntax::FlowDeclaration *absl_nullable declaration
The declaration this came from, borrowed.
Definition resolve.h:174
graph::FlowGraph graph
The executable graph, when [Resolve] was asked for one.
Definition resolve.h:165
bool ambiguous
Definition resolve.h:159
FlowPlan plan
Definition resolve.h:156
std::vector< Symbol > symbols
Every symbol the flow bound, in the order it bound them.
Definition resolve.h:169
std::vector< FlowPlan > contracts
Definition resolve.h:158
One name, what it is, and what became of it.
Definition resolve.h:72
syntax::Location location
Definition resolve.h:75
bool tolerant
Definition resolve.h:94
bool writable
Whether a pipe may write it.
Definition resolve.h:90
int status_reads
For a call: whether anything read its status – wait x, status x, or a bound wait.
Definition resolve.h:102
bool VisibleAt(size_t offset) const
Definition resolve.h:82
graph::StepId step
The graph step this name is: a call, or a bound wait/close.
Definition resolve.h:109
bool readable
Whether a pipeline may read it.
Definition resolve.h:88
std::string pattern
The match pattern this value came out of, where it came out of a literal one.
Definition resolve.h:121
const FlowPlan *absl_nullable target
Definition resolve.h:95
std::optional< syntax::TypeExpression > value_type
Definition resolve.h:123
graph::RefId ref
The graph ref this name reads and writes, when a graph was built: a port, a node, a header,...
Definition resolve.h:107
bool implicit
Whether the language bound it rather than the author: the index every loop provides.
Definition resolve.h:78
SymbolKind kind
Definition resolve.h:73
std::string shape
Definition resolve.h:122
std::string action
For a call: the action named, whether it was try, and the sibling flow it resolves to if it is one.
Definition resolve.h:93
std::string name
Definition resolve.h:74
int writes
Definition resolve.h:98
bool data_dependency
Whether reading this lazy value can read a data or completion stream.
Definition resolve.h:111
syntax::Location visibility
A branch-local binding's visibility, absent for unrestricted symbols.
Definition resolve.h:80
int reads
How many times something read it, wrote it, or waited for it.
Definition resolve.h:97
The executable graph of one flow.
Definition graph.h:394
One flow name { ... } declaration, or the one flow { ... } entry point.
Definition syntax.h:694
The start token's byte span, line, and code-point column.
Definition syntax.h:39
size_t end
Definition syntax.h:41
size_t start
Definition syntax.h:40