]> git.proxmox.com Git - rustc.git/blob - vendor/salsa/src/durability.rs
New upstream version 1.48.0+dfsg1
[rustc.git] / vendor / salsa / src / durability.rs
1 /// Describes how likely a value is to change -- how "durable" it is.
2 /// By default, inputs have `Durability::LOW` and interned values have
3 /// `Durability::HIGH`. But inputs can be explicitly set with other
4 /// durabilities.
5 ///
6 /// We use durabilities to optimize the work of "revalidating" a query
7 /// after some input has changed. Ordinarily, in a new revision,
8 /// queries have to trace all their inputs back to the base inputs to
9 /// determine if any of those inputs have changed. But if we know that
10 /// the only changes were to inputs of low durability (the common
11 /// case), and we know that the query only used inputs of medium
12 /// durability or higher, then we can skip that enumeration.
13 ///
14 /// Typically, one assigns low durabilites to inputs that the user is
15 /// frequently editing. Medium or high durabilities are used for
16 /// configuration, the source from library crates, or other things
17 /// that are unlikely to be edited.
18 #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
19 pub struct Durability(u8);
20
21 impl Durability {
22 /// Low durability: things that change frequently.
23 ///
24 /// Example: part of the crate being edited
25 pub const LOW: Durability = Durability(0);
26
27 /// Medium durability: things that change sometimes, but rarely.
28 ///
29 /// Example: a Cargo.toml file
30 pub const MEDIUM: Durability = Durability(1);
31
32 /// High durability: things that are not expected to change under
33 /// common usage.
34 ///
35 /// Example: the standard library or something from crates.io
36 pub const HIGH: Durability = Durability(2);
37
38 /// The maximum possible durability; equivalent to HIGH but
39 /// "conceptually" distinct (i.e., if we add more durability
40 /// levels, this could change).
41 pub(crate) const MAX: Durability = Self::HIGH;
42
43 /// Number of durability levels.
44 pub(crate) const LEN: usize = 3;
45
46 pub(crate) fn index(self) -> usize {
47 self.0 as usize
48 }
49 }