Skip to content
This repository was archived by the owner on Oct 27, 2024. It is now read-only.

Commit da8c542

Browse files
authored
Merge pull request #6 from davidbarsky/david/switch-to-tracing-from-log
internal: switch salsa over to `tracing` from `log`
2 parents d9ff034 + d10b7ba commit da8c542

File tree

13 files changed

+35
-36
lines changed

13 files changed

+35
-36
lines changed

Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ name = "salsa"
1313
[dependencies]
1414
indexmap = "2.1.0"
1515
lock_api = "0.4"
16-
log = "0.4.5"
16+
tracing = "0.1"
1717
parking_lot = "0.12.1"
1818
rustc-hash = "1.0"
1919
smallvec = "1.0.0"
@@ -24,7 +24,6 @@ rust-analyzer-salsa-macros = { version = "0.17.0-pre.5", path = "components/sals
2424

2525
[dev-dependencies]
2626
diff = "0.1.0"
27-
env_logger = "0.7"
2827
linked-hash-map = "0.5.2"
2928
rand = "0.7"
3029
rand_distr = "0.2.1"

src/derived/slot.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ use crate::runtime::StampedValue;
1414
use crate::runtime::WaitResult;
1515
use crate::Cycle;
1616
use crate::{Database, DatabaseKeyIndex, Event, EventKind, QueryDb};
17-
use log::{debug, info};
1817
use parking_lot::{RawRwLock, RwLock};
1918
use std::marker::PhantomData;
2019
use std::ops::Deref;
2120
use std::sync::atomic::{AtomicBool, Ordering};
21+
use tracing::{debug, info};
2222

2323
pub(super) struct Slot<Q, MP>
2424
where
@@ -228,7 +228,7 @@ where
228228
panic_guard: PanicGuard<'_, Q, MP>,
229229
old_memo: Option<Memo<Q::Value>>,
230230
) -> StampedValue<Q::Value> {
231-
log::info!("{:?}: executing query", self.database_key_index.debug(db));
231+
tracing::info!("{:?}: executing query", self.database_key_index.debug(db));
232232

233233
db.salsa_event(Event {
234234
runtime_id: db.salsa_runtime().id(),
@@ -242,7 +242,7 @@ where
242242
let value = match Cycle::catch(|| Q::execute(db, self.key.clone())) {
243243
Ok(v) => v,
244244
Err(cycle) => {
245-
log::debug!(
245+
tracing::debug!(
246246
"{:?}: caught cycle {:?}, have strategy {:?}",
247247
self.database_key_index.debug(db),
248248
cycle,
@@ -441,7 +441,7 @@ where
441441
}
442442

443443
pub(super) fn invalidate(&self, new_revision: Revision) -> Option<Durability> {
444-
log::debug!("Slot::invalidate(new_revision = {:?})", new_revision);
444+
tracing::debug!("Slot::invalidate(new_revision = {:?})", new_revision);
445445
match &mut *self.state.write() {
446446
QueryState::Memoized(memo) => {
447447
memo.revisions.inputs = QueryInputs::Untracked;

src/input.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use crate::Query;
1212
use crate::Runtime;
1313
use crate::{DatabaseKeyIndex, QueryDb};
1414
use indexmap::map::Entry;
15-
use log::debug;
1615
use parking_lot::RwLock;
1716
use std::convert::TryFrom;
17+
use tracing::debug;
1818

1919
/// Input queries store the result plus a list of the other queries
2020
/// that they invoked. This means we can avoid recomputing them when
@@ -160,7 +160,7 @@ where
160160
Q: Query,
161161
{
162162
fn set(&self, runtime: &mut Runtime, key: &Q::Key, value: Q::Value, durability: Durability) {
163-
log::debug!(
163+
tracing::debug!(
164164
"{:?}({:?}) = {:?} ({:?})",
165165
Q::default(),
166166
key,

src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub trait Database: plumbing::DatabaseOps {
7979

8080
let current_revision = runtime.current_revision();
8181
let pending_revision = runtime.pending_revision();
82-
log::debug!(
82+
tracing::debug!(
8383
"unwind_if_cancelled: current_revision={:?}, pending_revision={:?}",
8484
current_revision,
8585
pending_revision
@@ -682,7 +682,7 @@ impl Cycle {
682682
}
683683

684684
pub(crate) fn throw(self) -> ! {
685-
log::debug!("throwing cycle {:?}", self);
685+
tracing::debug!("throwing cycle {:?}", self);
686686
std::panic::resume_unwind(Box::new(self))
687687
}
688688

src/lru.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,19 +106,19 @@ where
106106

107107
/// Records that `node` was used. This may displace an old node (if the LRU limits are
108108
pub fn record_use(&self, node: &Arc<Node>) -> Option<Arc<Node>> {
109-
log::debug!("record_use(node={:?})", node);
109+
tracing::debug!("record_use(node={:?})", node);
110110

111111
// Load green zone length and check if the LRU cache is even enabled.
112112
let green_zone = self.green_zone.load(Ordering::Acquire);
113-
log::debug!("record_use: green_zone={}", green_zone);
113+
tracing::debug!("record_use: green_zone={}", green_zone);
114114
if green_zone == 0 {
115115
return None;
116116
}
117117

118118
// Find current index of list (if any) and the current length
119119
// of our green zone.
120120
let index = node.lru_index().load();
121-
log::debug!("record_use: index={}", index);
121+
tracing::debug!("record_use: index={}", index);
122122

123123
// Already a member of the list, and in the green zone -- nothing to do!
124124
if index < green_zone {
@@ -170,9 +170,9 @@ where
170170
self.end_red_zone = self.end_yellow_zone + len_red_zone;
171171
let entries = std::mem::replace(&mut self.entries, Vec::with_capacity(self.end_red_zone));
172172

173-
log::debug!("green_zone = {:?}", self.green_zone());
174-
log::debug!("yellow_zone = {:?}", self.yellow_zone());
175-
log::debug!("red_zone = {:?}", self.red_zone());
173+
tracing::debug!("green_zone = {:?}", self.green_zone());
174+
tracing::debug!("yellow_zone = {:?}", self.yellow_zone());
175+
tracing::debug!("red_zone = {:?}", self.red_zone());
176176

177177
// We expect to resize when the LRU cache is basically empty.
178178
// So just forget all the old LRU indices to start.
@@ -188,7 +188,7 @@ where
188188
/// list may displace an old member of the red zone, in which case
189189
/// that is returned.
190190
fn record_use(&mut self, node: &Arc<Node>) -> Option<Arc<Node>> {
191-
log::debug!("record_use(node={:?})", node);
191+
tracing::debug!("record_use(node={:?})", node);
192192

193193
// NB: When this is invoked, we have typically already loaded
194194
// the LRU index (to check if it is in green zone). But that
@@ -220,15 +220,15 @@ where
220220
if len < self.end_red_zone {
221221
self.entries.push(node.clone());
222222
node.lru_index().store(len);
223-
log::debug!("inserted node {:?} at {}", node, len);
223+
tracing::debug!("inserted node {:?} at {}", node, len);
224224
return self.record_use(node);
225225
}
226226

227227
// Harder case: no capacity. Create some by evicting somebody from red
228228
// zone and then promoting.
229229
let victim_index = self.pick_index(self.red_zone());
230230
let victim_node = std::mem::replace(&mut self.entries[victim_index], node.clone());
231-
log::debug!("evicting red node {:?} from {}", victim_node, victim_index);
231+
tracing::debug!("evicting red node {:?} from {}", victim_node, victim_index);
232232
victim_node.lru_index().clear();
233233
self.promote_red_to_green(node, victim_index);
234234
Some(victim_node)
@@ -249,7 +249,7 @@ where
249249
// going to invoke `self.promote_yellow` next, and it will get
250250
// updated then.
251251
let yellow_index = self.pick_index(self.yellow_zone());
252-
log::debug!(
252+
tracing::debug!(
253253
"demoting yellow node {:?} from {} to red at {}",
254254
self.entries[yellow_index],
255255
yellow_index,
@@ -273,7 +273,7 @@ where
273273

274274
// Pick a yellow at random and switch places with it.
275275
let green_index = self.pick_index(self.green_zone());
276-
log::debug!(
276+
tracing::debug!(
277277
"demoting green node {:?} from {} to yellow at {}",
278278
self.entries[green_index],
279279
green_index,
@@ -283,7 +283,7 @@ where
283283
self.entries[yellow_index].lru_index().store(yellow_index);
284284
node.lru_index().store(green_index);
285285

286-
log::debug!("promoted {:?} to green index {}", node, green_index);
286+
tracing::debug!("promoted {:?} to green index {}", node, green_index);
287287
}
288288

289289
fn pick_index(&mut self, zone: std::ops::Range<usize>) -> usize {

src/runtime.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ use crate::hash::FxIndexSet;
33
use crate::plumbing::CycleRecoveryStrategy;
44
use crate::revision::{AtomicRevision, Revision};
55
use crate::{Cancelled, Cycle, Database, DatabaseKeyIndex, Event, EventKind};
6-
use log::debug;
76
use parking_lot::lock_api::{RawRwLock, RawRwLockRecursive};
87
use parking_lot::{Mutex, RwLock};
98
use std::hash::Hash;
109
use std::panic::panic_any;
1110
use std::sync::atomic::{AtomicUsize, Ordering};
11+
use tracing::debug;
1212
use triomphe::Arc;
1313

1414
mod dependency_graph;
@@ -178,7 +178,7 @@ impl Runtime {
178178
where
179179
F: FnOnce(Revision) -> Option<Durability>,
180180
{
181-
log::debug!("increment_revision()");
181+
tracing::debug!("increment_revision()");
182182

183183
if !self.permits_increment() {
184184
panic!("increment_revision invoked during a query computation");

src/runtime/local_state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use log::debug;
1+
use tracing::debug;
22

33
use crate::durability::Durability;
44
use crate::runtime::ActiveQuery;

tests/cycles.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ fn cycle_appears() {
298298
// ^ |
299299
// +-----+
300300
db.set_b_invokes(CycleQuery::A);
301-
log::debug!("Set Cycle Leaf");
301+
tracing::debug!("Set Cycle Leaf");
302302
assert!(db.cycle_a().is_err());
303303
}
304304

tests/parallel/parallel_cycle_all_recover.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,22 @@ pub(crate) trait TestDatabase: Knobs {
6363
}
6464

6565
fn recover_a1(_db: &dyn TestDatabase, _cycle: &salsa::Cycle, key: &i32) -> i32 {
66-
log::debug!("recover_a1");
66+
tracing::debug!("recover_a1");
6767
key * 10 + 1
6868
}
6969

7070
fn recover_a2(_db: &dyn TestDatabase, _cycle: &salsa::Cycle, key: &i32) -> i32 {
71-
log::debug!("recover_a2");
71+
tracing::debug!("recover_a2");
7272
key * 10 + 2
7373
}
7474

7575
fn recover_b1(_db: &dyn TestDatabase, _cycle: &salsa::Cycle, key: &i32) -> i32 {
76-
log::debug!("recover_b1");
76+
tracing::debug!("recover_b1");
7777
key * 20 + 1
7878
}
7979

8080
fn recover_b2(_db: &dyn TestDatabase, _cycle: &salsa::Cycle, key: &i32) -> i32 {
81-
log::debug!("recover_b2");
81+
tracing::debug!("recover_b2");
8282
key * 20 + 2
8383
}
8484

tests/parallel/parallel_cycle_mid_recover.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ pub(crate) trait TestDatabase: Knobs {
6464
}
6565

6666
fn recover_b1(_db: &dyn TestDatabase, _cycle: &salsa::Cycle, key: &i32) -> i32 {
67-
log::debug!("recover_b1");
67+
tracing::debug!("recover_b1");
6868
key * 20 + 2
6969
}
7070

7171
fn recover_b3(_db: &dyn TestDatabase, _cycle: &salsa::Cycle, key: &i32) -> i32 {
72-
log::debug!("recover_b1");
72+
tracing::debug!("recover_b1");
7373
key * 200 + 2
7474
}
7575

0 commit comments

Comments
 (0)