@@ -485,32 +485,15 @@ impl<'tcx> fmt::Display for FrameInfo<'tcx> {
485
485
}
486
486
}
487
487
488
- #[ derive( Clone , Copy , Debug ) ]
489
- pub enum ConstDedupResult < T : Clone + Copy + Debug > {
490
- Selection ( T ) ,
491
- UserFacing ( T ) ,
492
- All ( T ) ,
493
- }
494
-
495
- impl < T : Clone + Copy + Debug > ConstDedupResult < T > {
496
- pub fn new ( reveal : Reveal , val : T ) -> Self {
497
- match reveal {
498
- Reveal :: Selection => ConstDedupResult :: Selection ( val) ,
499
- Reveal :: UserFacing => ConstDedupResult :: UserFacing ( val) ,
500
- Reveal :: All => ConstDedupResult :: All ( val) ,
501
- }
502
- }
503
- }
504
-
505
488
/// Used to store results of calls to `eval_to_allocation_raw` and
506
489
/// `eval_to_const_value_raw`.
507
490
#[ derive( Debug ) ]
508
491
pub struct ConstDedupMap < ' tcx > {
509
492
// interning for deduplication of `eval_to_allocation_raw`
510
- pub alloc_map : RefCell < FxHashMap < GlobalId < ' tcx > , ConstDedupResult < ConstAlloc < ' tcx > > > > ,
493
+ pub alloc_map : RefCell < FxHashMap < GlobalId < ' tcx > , Reveal > > ,
511
494
512
495
// interning for deduplication of `eval_to_const_value_raw`
513
- pub const_val_map : RefCell < FxHashMap < GlobalId < ' tcx > , ConstDedupResult < ConstValue < ' tcx > > > > ,
496
+ pub const_val_map : RefCell < FxHashMap < GlobalId < ' tcx > , Reveal > > ,
514
497
}
515
498
516
499
impl < ' tcx > ConstDedupMap < ' tcx > {
@@ -519,14 +502,14 @@ impl<'tcx> ConstDedupMap<'tcx> {
519
502
}
520
503
521
504
#[ instrument( skip( self ) , level = "debug" ) ]
522
- fn insert_alloc ( & self , id : GlobalId < ' tcx > , val : ConstDedupResult < ConstAlloc < ' tcx > > ) {
505
+ fn insert_alloc ( & self , id : GlobalId < ' tcx > , val : Reveal ) {
523
506
let mut alloc_map = self . alloc_map . borrow_mut ( ) ;
524
507
alloc_map. insert ( id, val) ;
525
508
debug ! ( "alloc_map after update: {:#?}" , alloc_map) ;
526
509
}
527
510
528
511
#[ instrument( skip( self ) , level = "debug" ) ]
529
- fn insert_const_val ( & self , id : GlobalId < ' tcx > , val : ConstDedupResult < ConstValue < ' tcx > > ) {
512
+ fn insert_const_val ( & self , id : GlobalId < ' tcx > , val : Reveal ) {
530
513
let mut const_val_map = self . const_val_map . borrow_mut ( ) ;
531
514
const_val_map. insert ( id, val) ;
532
515
debug ! ( "const_val_map after update: {:#?}" , const_val_map) ;
@@ -645,19 +628,15 @@ impl<'tcx> TyCtxt<'tcx> {
645
628
/// Store the result of a call to `eval_to_allocation_raw` in order to
646
629
/// allow deduplication.
647
630
#[ instrument( skip( self ) , level = "debug" ) ]
648
- pub fn save_alloc_for_dedup ( self , id : GlobalId < ' tcx > , val : ConstDedupResult < ConstAlloc < ' tcx > > ) {
631
+ pub fn save_alloc_for_dedup ( self , id : GlobalId < ' tcx > , val : Reveal ) {
649
632
let dedup_const_map = self . dedup_const_map . lock ( ) ;
650
633
dedup_const_map. insert_alloc ( id, val) ;
651
634
debug ! ( "dedup_const_map after insert: {:#?}" , dedup_const_map) ;
652
635
}
653
636
654
637
/// Store the result of a call to `eval_to_const_value_raw` in order to deduplicate it.
655
638
#[ instrument( skip( self ) , level = "debug" ) ]
656
- pub fn save_const_value_for_dedup (
657
- self ,
658
- id : GlobalId < ' tcx > ,
659
- val : ConstDedupResult < ConstValue < ' tcx > > ,
660
- ) {
639
+ pub fn save_const_value_for_dedup ( self , id : GlobalId < ' tcx > , val : Reveal ) {
661
640
let dedup_const_map = self . dedup_const_map . lock ( ) ;
662
641
dedup_const_map. insert_const_val ( id, val) ;
663
642
debug ! ( "dedup_const_map after insert: {:#?}" , dedup_const_map) ;
@@ -671,31 +650,72 @@ impl<'tcx> TyCtxt<'tcx> {
671
650
key : ty:: ParamEnvAnd < ' tcx , GlobalId < ' tcx > > ,
672
651
opt_span : Option < Span > ,
673
652
) -> EvalToAllocationRawResult < ' tcx > {
674
- use ConstDedupResult :: * ;
675
-
676
653
let ( param_env, id) = key. into_parts ( ) ;
677
654
let dedup_const_map = self . dedup_const_map . lock ( ) ;
678
655
debug ! ( "dedup_const_map: {:#?}" , dedup_const_map) ;
679
656
let alloc_map = dedup_const_map. alloc_map . borrow ( ) ;
680
657
debug ! ( "alloc_map: {:#?}" , alloc_map) ;
681
658
682
- let dedup_result = alloc_map. get ( & id) ;
683
- debug ! ( ?dedup_result ) ;
659
+ let dedup_reveal = alloc_map. get ( & id) ;
660
+ debug ! ( ?dedup_reveal ) ;
684
661
685
662
match param_env. reveal ( ) {
686
- Reveal :: Selection => match dedup_result {
687
- Some ( Selection ( alloc) | UserFacing ( alloc) ) => return Ok ( * alloc) ,
663
+ Reveal :: Selection => match dedup_reveal {
664
+ Some ( Reveal :: Selection ) => {
665
+ drop ( alloc_map) ;
666
+ drop ( dedup_const_map) ;
667
+
668
+ // Use cached result of query
669
+ return self . eval_to_allocation_raw ( key) ;
670
+ }
671
+ Some ( Reveal :: UserFacing ) => {
672
+ drop ( alloc_map) ;
673
+ drop ( dedup_const_map) ;
674
+
675
+ // can deduplicate query with Reveal::Selection from Reveal::UserFacing
676
+ // since these only differ in the way errors are reported, but successful
677
+ // query calls are equivalent.
678
+ let new_key = param_env. with_user_facing ( ) . and ( id) ;
679
+ return self . eval_to_allocation_raw ( new_key) ;
680
+ }
688
681
_ => { }
689
682
} ,
690
- Reveal :: UserFacing => match dedup_result {
691
- Some ( Selection ( alloc) | UserFacing ( alloc) ) => {
692
- return Ok ( * alloc) ;
683
+ Reveal :: UserFacing => match dedup_reveal {
684
+ Some ( Reveal :: UserFacing ) => {
685
+ drop ( alloc_map) ;
686
+ drop ( dedup_const_map) ;
687
+
688
+ return self . eval_to_allocation_raw ( key) ;
689
+ }
690
+ Some ( Reveal :: Selection ) => {
691
+ drop ( alloc_map) ;
692
+ drop ( dedup_const_map) ;
693
+
694
+ let new_key = param_env. with_reveal_selection ( ) . and ( id) ;
695
+ return self . eval_to_allocation_raw ( new_key) ;
693
696
}
694
697
_ => { }
695
698
} ,
696
- Reveal :: All => match dedup_result {
697
- Some ( Selection ( alloc) | UserFacing ( alloc) | All ( alloc) ) => {
698
- return Ok ( * alloc) ;
699
+ Reveal :: All => match dedup_reveal {
700
+ Some ( Reveal :: Selection ) => {
701
+ drop ( alloc_map) ;
702
+ drop ( dedup_const_map) ;
703
+
704
+ let new_key = param_env. with_reveal_selection ( ) . and ( id) ;
705
+ return self . eval_to_allocation_raw ( new_key) ;
706
+ }
707
+ Some ( Reveal :: UserFacing ) => {
708
+ drop ( alloc_map) ;
709
+ drop ( dedup_const_map) ;
710
+
711
+ let new_key = param_env. with_user_facing ( ) . and ( id) ;
712
+ return self . eval_to_allocation_raw ( new_key) ;
713
+ }
714
+ Some ( Reveal :: All ) => {
715
+ drop ( alloc_map) ;
716
+ drop ( dedup_const_map) ;
717
+
718
+ return self . eval_to_allocation_raw ( key) ;
699
719
}
700
720
_ => { }
701
721
} ,
@@ -722,31 +742,72 @@ impl<'tcx> TyCtxt<'tcx> {
722
742
key : ty:: ParamEnvAnd < ' tcx , GlobalId < ' tcx > > ,
723
743
opt_span : Option < Span > ,
724
744
) -> EvalToConstValueResult < ' tcx > {
725
- use ConstDedupResult :: * ;
726
-
727
745
let ( param_env, id) = key. into_parts ( ) ;
728
746
let dedup_const_map = self . dedup_const_map . lock ( ) ;
729
747
debug ! ( "dedup_const_map: {:#?}" , dedup_const_map) ;
730
748
let const_val_map = dedup_const_map. const_val_map . borrow ( ) ;
731
749
debug ! ( "const_val_map: {:#?}" , const_val_map) ;
732
750
733
- let dedup_result = const_val_map. get ( & id) ;
734
- debug ! ( ?dedup_result ) ;
751
+ let dedup_reveal = const_val_map. get ( & id) ;
752
+ debug ! ( ?dedup_reveal ) ;
735
753
736
754
match param_env. reveal ( ) {
737
- Reveal :: Selection => match dedup_result {
738
- Some ( Selection ( const_val) | UserFacing ( const_val) ) => return Ok ( * const_val) ,
755
+ Reveal :: Selection => match dedup_reveal {
756
+ Some ( Reveal :: Selection ) => {
757
+ drop ( const_val_map) ;
758
+ drop ( dedup_const_map) ;
759
+
760
+ // Use cached result of query
761
+ return self . eval_to_const_value_raw ( key) ;
762
+ }
763
+ Some ( Reveal :: UserFacing ) => {
764
+ drop ( const_val_map) ;
765
+ drop ( dedup_const_map) ;
766
+
767
+ // can deduplicate query with Reveal::Selection from Reveal::UserFacing
768
+ // since these only differ in the way errors are reported, but successful
769
+ // query calls are equivalent.
770
+ let new_key = param_env. with_user_facing ( ) . and ( id) ;
771
+ return self . eval_to_const_value_raw ( new_key) ;
772
+ }
739
773
_ => { }
740
774
} ,
741
- Reveal :: UserFacing => match dedup_result {
742
- Some ( Selection ( const_value) | UserFacing ( const_value) ) => {
743
- return Ok ( * const_value) ;
775
+ Reveal :: UserFacing => match dedup_reveal {
776
+ Some ( Reveal :: UserFacing ) => {
777
+ drop ( const_val_map) ;
778
+ drop ( dedup_const_map) ;
779
+
780
+ return self . eval_to_const_value_raw ( key) ;
781
+ }
782
+ Some ( Reveal :: Selection ) => {
783
+ drop ( const_val_map) ;
784
+ drop ( dedup_const_map) ;
785
+
786
+ let new_key = param_env. with_reveal_selection ( ) . and ( id) ;
787
+ return self . eval_to_const_value_raw ( new_key) ;
744
788
}
745
789
_ => { }
746
790
} ,
747
- Reveal :: All => match dedup_result {
748
- Some ( Selection ( const_value) | UserFacing ( const_value) | All ( const_value) ) => {
749
- return Ok ( * const_value) ;
791
+ Reveal :: All => match dedup_reveal {
792
+ Some ( Reveal :: Selection ) => {
793
+ drop ( const_val_map) ;
794
+ drop ( dedup_const_map) ;
795
+
796
+ let new_key = param_env. with_reveal_selection ( ) . and ( id) ;
797
+ return self . eval_to_const_value_raw ( new_key) ;
798
+ }
799
+ Some ( Reveal :: UserFacing ) => {
800
+ drop ( const_val_map) ;
801
+ drop ( dedup_const_map) ;
802
+
803
+ let new_key = param_env. with_user_facing ( ) . and ( id) ;
804
+ return self . eval_to_const_value_raw ( new_key) ;
805
+ }
806
+ Some ( Reveal :: All ) => {
807
+ drop ( const_val_map) ;
808
+ drop ( dedup_const_map) ;
809
+
810
+ return self . eval_to_const_value_raw ( key) ;
750
811
}
751
812
_ => { }
752
813
} ,
0 commit comments