1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//! Resource ceilings shared by Go project loading, snapshots, and resolution.
use crate::resolution::read::ByteCeilings;
/// Explicit bounds on everything a Go project, snapshot, or resolution may
/// traverse.
///
/// Every field has a documented default. A caller may lower a value to prove a
/// bound, or raise one for a large repository; nothing is truncated silently.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct GoResolutionLimits {
/// Module manifests one project may read. Default 1,024.
///
/// A Go project reads one `go.mod` per admitted module, and a module enters
/// only through a required local replacement, so this bounds the module
/// graph rather than the source tree.
pub max_module_manifests: u32,
/// Directory entries one snapshot may visit while discovering packages.
/// Default 65,536.
pub max_directory_entries: u32,
/// Resolution units one snapshot may hold. Default 4,096.
pub max_units: u32,
/// Distinct source files one snapshot may hold. Default 65,536.
pub max_source_files: u32,
/// Bytes one source file may hold. Default 8 MiB.
pub max_source_file_bytes: u64,
/// Bytes all distinct source text may hold. Default 512 MiB.
pub max_total_source_bytes: u64,
/// Local replacement hops followed from the main module. Default 64.
///
/// The main module sits at depth zero, so a ceiling of zero admits it and
/// refuses the first replacement it requires.
pub max_dependency_depth: u32,
/// Syntax nesting depth accepted while extracting Go facts. Default 256.
pub max_syntax_depth: u32,
/// Grammar facts one source may yield. Default 262,144.
pub max_facts_per_source: u32,
/// Candidates one reference may carry. Default 1,024.
pub max_candidates_per_reference: u32,
/// Concrete-type-to-interface comparisons one resolution may make.
/// Default 1,048,576.
pub max_interface_comparisons: u32,
}
/// The two fields the shared byte rule reads, named once for every seam that
/// charges Go source bytes against these ceilings.
impl ByteCeilings for GoResolutionLimits {
fn source_bytes(&self) -> u64 {
self.max_source_file_bytes
}
fn total_bytes(&self) -> u64 {
self.max_total_source_bytes
}
}
impl Default for GoResolutionLimits {
fn default() -> Self {
Self {
max_module_manifests: 1_024,
max_directory_entries: 65_536,
max_units: 4_096,
max_source_files: 65_536,
max_source_file_bytes: 8 * 1_024 * 1_024,
max_total_source_bytes: 512 * 1_024 * 1_024,
max_dependency_depth: 64,
max_syntax_depth: 256,
max_facts_per_source: 262_144,
max_candidates_per_reference: 1_024,
max_interface_comparisons: 1_048_576,
}
}
}