flow_runner/common/limits.rs
1//! Every limit: the fixed ones, and [`Limits`], which a host sets per run.
2
3/// Largest `.flow` source accepted, in bytes.
4pub const MAX_SOURCE_BYTES: usize = 4 << 20;
5
6/// Longest name, in bytes: of a flow, node, param, let, event, ask or
7/// annotation. Names travel in tokens, so this bounds a token's size.
8pub(crate) const MAX_NAME_BYTES: usize = 256;
9
10/// Deepest value a token stores or a param takes. Storing, copying and
11/// comparing a value recurse once per level.
12pub(crate) const MAX_VALUE_DEPTH: usize = 128;
13
14/// Deepest value an edit writes as a literal: temple parses no deeper.
15pub(crate) const MAX_LITERAL_DEPTH: usize = 63;
16
17/// Longest expression or value, in bytes. The flow hash formats each with
18/// temple, which formats templates of up to 1 MiB, the unit included.
19pub(crate) const MAX_UNIT_BYTES: usize = 512 << 10;
20
21/// Most bytes of node arguments and params, with their names, that a token
22/// carries. Typical tokens hold about a hundred bytes; instance data belongs
23/// with the host.
24pub(crate) const MAX_TOKEN_STATE: usize = 1 << 20;
25
26/// Longest token read at all: the state, the flow, node and ask names, and
27/// room for the fixed fields.
28pub(crate) const MAX_TOKEN_BYTES: usize = MAX_TOKEN_STATE + 3 * MAX_NAME_BYTES + 128;
29
30/// Deepest nesting a token's CBOR may have. Each level of a stored object
31/// takes three (its tag, its entries, and the entry), and the token's own
32/// fields a few more.
33pub(crate) const MAX_TOKEN_NESTING: usize = 3 * MAX_VALUE_DEPTH + 16;
34
35/// Longest decimal a token stores, as text: a sign, 29 digits and a point.
36/// Longer text is refused unread, since parsing it recurses per digit.
37pub(crate) const MAX_DECIMAL_TEXT: usize = 31;
38
39/// Did-you-mean searches per compile, and the edit-distance table cells they
40/// may fill between them. A search runs only if the most it could fill still
41/// fits, so a file full of unknown names, or of long and alike ones, gets
42/// hints on its first ones only.
43pub(crate) const MAX_HINTS: usize = 100;
44pub(crate) const MAX_HINT_CELLS: u64 = 10_000_000;
45
46/// Node names a diagnostic lists before it says "and N more".
47pub(crate) const MAX_LISTED_NAMES: usize = 10;
48
49/// Lines longer than this, in bytes, are shown in a report as a window
50/// around the span, so reports stay small however the file is laid out.
51pub(crate) const MAX_REPORT_LINE: usize = 160;
52
53/// How much of a long line a report shows before and after the span's start.
54pub(crate) const REPORT_BEFORE: usize = 60;
55pub(crate) const REPORT_AFTER: usize = 100;
56
57/// Work limits for one run.
58#[derive(Debug, Clone, Copy, PartialEq, Eq)]
59pub struct Limits {
60 /// Evaluation steps, shared by every expression in the run. A step is one
61 /// expression, one element a builtin touches, builds or copies, or 64
62 /// bytes of text copied or built, so steps bound memory as well as time:
63 /// the default is about 30 ms of work and at most a few hundred
64 /// megabytes, whatever the flow does.
65 pub steps: u64,
66 /// Jumps from node to node within one run.
67 pub jumps: u64,
68 /// Asks over the whole life of an instance.
69 pub asks: u64,
70}
71
72impl Default for Limits {
73 fn default() -> Self {
74 Limits {
75 steps: 2_000_000,
76 jumps: 1_000,
77 asks: 100_000,
78 }
79 }
80}