Skip to content

Commit f6b40b0

Browse files
authored
Merge pull request #630 from Veykril/veykril/push-mwwmzmpskxnr
Give Durability niches
2 parents 5cd2b63 + 7efee65 commit f6b40b0

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

src/active_query.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ impl ActiveQuery {
8686

8787
pub(super) fn add_untracked_read(&mut self, changed_at: Revision) {
8888
self.untracked_read = true;
89-
self.durability = Durability::LOW;
89+
self.durability = Durability::MIN;
9090
self.changed_at = changed_at;
9191
}
9292

src/durability.rs

+27-6
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,54 @@
1616
/// frequently editing. Medium or high durabilities are used for
1717
/// configuration, the source from library crates, or other things
1818
/// that are unlikely to be edited.
19-
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
20-
pub struct Durability(u8);
19+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
20+
pub struct Durability(DurabilityVal);
21+
22+
impl std::fmt::Debug for Durability {
23+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
24+
f.debug_tuple("Durability")
25+
.field(&(self.0 as usize))
26+
.finish()
27+
}
28+
}
29+
30+
// We use an enum here instead of a u8 for niches.
31+
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
32+
enum DurabilityVal {
33+
Low = 0,
34+
Medium = 1,
35+
High = 2,
36+
}
2137

2238
impl Durability {
2339
/// Low durability: things that change frequently.
2440
///
2541
/// Example: part of the crate being edited
26-
pub const LOW: Durability = Durability(0);
42+
pub const LOW: Durability = Durability(DurabilityVal::Low);
2743

2844
/// Medium durability: things that change sometimes, but rarely.
2945
///
3046
/// Example: a Cargo.toml file
31-
pub const MEDIUM: Durability = Durability(1);
47+
pub const MEDIUM: Durability = Durability(DurabilityVal::Medium);
3248

3349
/// High durability: things that are not expected to change under
3450
/// common usage.
3551
///
3652
/// Example: the standard library or something from crates.io
37-
pub const HIGH: Durability = Durability(2);
53+
pub const HIGH: Durability = Durability(DurabilityVal::High);
54+
55+
/// The minimum possible durability; equivalent to LOW but
56+
/// "conceptually" distinct (i.e., if we add more durability
57+
/// levels, this could change).
58+
pub(crate) const MIN: Durability = Self::LOW;
3859

3960
/// The maximum possible durability; equivalent to HIGH but
4061
/// "conceptually" distinct (i.e., if we add more durability
4162
/// levels, this could change).
4263
pub(crate) const MAX: Durability = Self::HIGH;
4364

4465
/// Number of durability levels.
45-
pub(crate) const LEN: usize = 3;
66+
pub(crate) const LEN: usize = Self::HIGH.0 as usize + 1;
4667

4768
pub(crate) fn index(self) -> usize {
4869
self.0 as usize

src/input.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl<C: Configuration> IngredientImpl<C> {
150150

151151
let stamp = &mut r.stamps[field_index];
152152

153-
if stamp.durability != Durability::LOW {
153+
if stamp.durability != Durability::MIN {
154154
runtime.report_tracked_write(stamp.durability);
155155
}
156156

src/runtime.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub struct Runtime {
3535
/// revisions[i + 1]`, for all `i`. This is because when you
3636
/// modify a value with durability D, that implies that values
3737
/// with durability less than D may have changed too.
38-
revisions: Box<[AtomicRevision; Durability::LEN]>,
38+
revisions: [AtomicRevision; Durability::LEN],
3939

4040
/// The dependency graph tracks which runtimes are blocked on one
4141
/// another, waiting for queries to terminate.
@@ -81,7 +81,7 @@ impl<V> StampedValue<V> {
8181
impl Default for Runtime {
8282
fn default() -> Self {
8383
Runtime {
84-
revisions: Box::new([const { AtomicRevision::start() }; Durability::LEN]),
84+
revisions: [const { AtomicRevision::start() }; Durability::LEN],
8585
revision_canceled: Default::default(),
8686
dependency_graph: Default::default(),
8787
table: Default::default(),

0 commit comments

Comments
 (0)