@@ -321,15 +321,19 @@ impl<S: UnificationStore> UnificationTable<S> {
321
321
///
322
322
/// NB. This is a building-block operation and you would probably
323
323
/// 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 {
325
329
let redirect = {
326
330
match self . value ( vid) . parent ( vid) {
327
331
None => return vid,
328
332
Some ( redirect) => redirect,
329
333
}
330
334
} ;
331
335
332
- let root_key: S :: Key = self . get_root_key ( redirect) ;
336
+ let root_key: S :: Key = self . uninlined_get_root_key ( redirect) ;
333
337
if root_key != redirect {
334
338
// Path compression
335
339
self . update_value ( vid, |value| value. parent = root_key) ;
@@ -338,6 +342,13 @@ impl<S: UnificationStore> UnificationTable<S> {
338
342
root_key
339
343
}
340
344
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
+
341
352
fn update_value < OP > ( & mut self , key : S :: Key , op : OP )
342
353
where
343
354
OP : FnOnce ( & mut VarValue < S :: Key > ) ,
@@ -422,7 +433,7 @@ impl<S: UnificationStore> UnificationTable<S> {
422
433
/// ////////////////////////////////////////////////////////////////////////
423
434
/// Public API
424
435
425
- impl < ' tcx , S , K , V > UnificationTable < S >
436
+ impl < S , K , V > UnificationTable < S >
426
437
where
427
438
S : UnificationStore < Key = K , Value = V > ,
428
439
K : UnifyKey < Value = V > ,
@@ -466,7 +477,7 @@ where
466
477
K1 : Into < K > ,
467
478
{
468
479
let id = id. into ( ) ;
469
- self . get_root_key ( id)
480
+ self . uninlined_get_root_key ( id)
470
481
}
471
482
472
483
/// Unions together two variables, merging their values. If
@@ -480,8 +491,8 @@ where
480
491
let a_id = a_id. into ( ) ;
481
492
let b_id = b_id. into ( ) ;
482
493
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) ;
485
496
486
497
if root_a == root_b {
487
498
return Ok ( ( ) ) ;
@@ -499,7 +510,7 @@ where
499
510
K1 : Into < K > ,
500
511
{
501
512
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) ;
503
514
let value = V :: unify_values ( & self . value ( root_a) . value , & b) ?;
504
515
self . update_value ( root_a, |node| node. value = value) ;
505
516
Ok ( ( ) )
@@ -508,11 +519,20 @@ where
508
519
/// Returns the current value for the given key. If the key has
509
520
/// been union'd, this will give the value from the current root.
510
521
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
511
531
where
512
532
K1 : Into < K > ,
513
533
{
514
534
let id = id. into ( ) ;
515
- let id = self . get_root_key ( id) ;
535
+ let id = self . inlined_get_root_key ( id) ;
516
536
self . value ( id) . value . clone ( )
517
537
}
518
538
}
0 commit comments