Skip to main content

pedant_types/resolution/
report.rs

1//! The validated result one resolution run produces.
2
3use serde::{Deserialize, Deserializer, Serialize};
4
5use super::builder::ResolutionReportLimits;
6use super::definition::SymbolDefinition;
7use super::record::ResolutionRecord;
8use super::reference::SymbolReference;
9use super::unit::ResolutionUnit;
10
11/// Which mechanism produced a report.
12///
13/// Data-flow analysis is not a resolution tier.
14#[derive(Serialize, Deserialize, Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
15#[serde(rename_all = "snake_case")]
16pub enum ResolutionTier {
17    /// Parse-only resolution.
18    Syntactic,
19    /// Resolution promoted through a verified semantic database.
20    Semantic,
21}
22
23/// A complete, validated resolution result.
24///
25/// Every value of this type has passed the shared validator, whether it came
26/// from [`super::ResolutionReportBuilder::finish`] or from deserialization, so
27/// a consumer may read the slices positionally: an identifier is its own index.
28#[derive(Serialize, Clone, Debug, PartialEq, Eq)]
29pub struct ResolutionReport {
30    tier: ResolutionTier,
31    units: Box<[ResolutionUnit]>,
32    definitions: Box<[SymbolDefinition]>,
33    references: Box<[SymbolReference]>,
34    resolutions: Box<[ResolutionRecord]>,
35}
36
37impl ResolutionReport {
38    /// Deserialize one report while bounding every retained top-level record.
39    ///
40    /// Resolution records share `limits.max_references`: a validated report
41    /// carries exactly one record per reference. Ordinary [`Deserialize`]
42    /// delegates here with [`ResolutionReportLimits::default`].
43    pub fn deserialize_with_limits<'de, D>(
44        deserializer: D,
45        limits: ResolutionReportLimits,
46    ) -> Result<Self, D::Error>
47    where
48        D: Deserializer<'de>,
49    {
50        super::wire::deserialize_with_limits(deserializer, limits)
51    }
52
53    pub(crate) fn new(
54        tier: ResolutionTier,
55        units: Box<[ResolutionUnit]>,
56        definitions: Box<[SymbolDefinition]>,
57        references: Box<[SymbolReference]>,
58        resolutions: Box<[ResolutionRecord]>,
59    ) -> Self {
60        Self {
61            tier,
62            units,
63            definitions,
64            references,
65            resolutions,
66        }
67    }
68
69    /// Which mechanism produced this report.
70    pub fn tier(&self) -> ResolutionTier {
71        self.tier
72    }
73
74    /// The report's units, sorted by their stable key.
75    pub fn units(&self) -> &[ResolutionUnit] {
76        &self.units
77    }
78
79    /// The report's definitions, sorted by unit, span, kind, and name.
80    pub fn definitions(&self) -> &[SymbolDefinition] {
81        &self.definitions
82    }
83
84    /// The report's references, sorted by unit, span, kind, and text.
85    pub fn references(&self) -> &[SymbolReference] {
86        &self.references
87    }
88
89    /// One record per reference, in reference order.
90    pub fn resolutions(&self) -> &[ResolutionRecord] {
91        &self.resolutions
92    }
93}