Skip to content

Commit 96e3e96

Browse files
authored
Merge pull request #26 from nnethercote/inline-get_root_key
Inline `get_root_key`
2 parents 313af7a + 4493977 commit 96e3e96

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

src/snapshot_vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<D> fmt::Debug for SnapshotVec<D>
4949
D::Undo: fmt::Debug,
5050
D::Value: fmt::Debug
5151
{
52-
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
52+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
5353
fmt.debug_struct("SnapshotVec")
5454
.field("values", &self.values)
5555
.field("undo_log", &self.undo_log)

src/unify/mod.rs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -321,15 +321,19 @@ impl<S: UnificationStore> UnificationTable<S> {
321321
///
322322
/// NB. This is a building-block operation and you would probably
323323
/// prefer to call `probe` below.
324-
fn get_root_key(&mut self, vid: S::Key) -> S::Key {
324+
///
325+
/// This is an always-inlined version of this function for the hot
326+
/// callsites. `uninlined_get_root_key` is the never-inlined version.
327+
#[inline(always)]
328+
fn inlined_get_root_key(&mut self, vid: S::Key) -> S::Key {
325329
let redirect = {
326330
match self.value(vid).parent(vid) {
327331
None => return vid,
328332
Some(redirect) => redirect,
329333
}
330334
};
331335

332-
let root_key: S::Key = self.get_root_key(redirect);
336+
let root_key: S::Key = self.uninlined_get_root_key(redirect);
333337
if root_key != redirect {
334338
// Path compression
335339
self.update_value(vid, |value| value.parent = root_key);
@@ -338,6 +342,13 @@ impl<S: UnificationStore> UnificationTable<S> {
338342
root_key
339343
}
340344

345+
// This is a never-inlined version of this function for cold callsites.
346+
// 'inlined_get_root_key` is the always-inlined version.
347+
#[inline(never)]
348+
fn uninlined_get_root_key(&mut self, vid: S::Key) -> S::Key {
349+
self.inlined_get_root_key(vid)
350+
}
351+
341352
fn update_value<OP>(&mut self, key: S::Key, op: OP)
342353
where
343354
OP: FnOnce(&mut VarValue<S::Key>),
@@ -422,7 +433,7 @@ impl<S: UnificationStore> UnificationTable<S> {
422433
/// ////////////////////////////////////////////////////////////////////////
423434
/// Public API
424435
425-
impl<'tcx, S, K, V> UnificationTable<S>
436+
impl<S, K, V> UnificationTable<S>
426437
where
427438
S: UnificationStore<Key = K, Value = V>,
428439
K: UnifyKey<Value = V>,
@@ -466,7 +477,7 @@ where
466477
K1: Into<K>,
467478
{
468479
let id = id.into();
469-
self.get_root_key(id)
480+
self.uninlined_get_root_key(id)
470481
}
471482

472483
/// Unions together two variables, merging their values. If
@@ -480,8 +491,8 @@ where
480491
let a_id = a_id.into();
481492
let b_id = b_id.into();
482493

483-
let root_a = self.get_root_key(a_id);
484-
let root_b = self.get_root_key(b_id);
494+
let root_a = self.uninlined_get_root_key(a_id);
495+
let root_b = self.uninlined_get_root_key(b_id);
485496

486497
if root_a == root_b {
487498
return Ok(());
@@ -499,7 +510,7 @@ where
499510
K1: Into<K>,
500511
{
501512
let a_id = a_id.into();
502-
let root_a = self.get_root_key(a_id);
513+
let root_a = self.uninlined_get_root_key(a_id);
503514
let value = V::unify_values(&self.value(root_a).value, &b)?;
504515
self.update_value(root_a, |node| node.value = value);
505516
Ok(())
@@ -508,11 +519,20 @@ where
508519
/// Returns the current value for the given key. If the key has
509520
/// been union'd, this will give the value from the current root.
510521
pub fn probe_value<K1>(&mut self, id: K1) -> V
522+
where
523+
K1: Into<K>,
524+
{
525+
self.inlined_probe_value(id)
526+
}
527+
528+
// An always-inlined version of `probe_value`, for hot callsites.
529+
#[inline(always)]
530+
pub fn inlined_probe_value<K1>(&mut self, id: K1) -> V
511531
where
512532
K1: Into<K>,
513533
{
514534
let id = id.into();
515-
let id = self.get_root_key(id);
535+
let id = self.inlined_get_root_key(id);
516536
self.value(id).value.clone()
517537
}
518538
}

0 commit comments

Comments
 (0)