@@ -3,7 +3,6 @@ use crate::ty::{DefId, DefIdTree};
33use rustc_span:: def_id:: CRATE_DEF_ID ;
44use smallvec:: SmallVec ;
55use std:: mem;
6- use std:: sync:: Arc ;
76
87use DefIdForest :: * ;
98
@@ -18,14 +17,13 @@ use DefIdForest::*;
1817/// We store the minimal set of `DefId`s required to represent the whole set. If A and B are
1918/// `DefId`s in the `DefIdForest`, and A is a parent of B, then only A will be stored. When this is
2019/// used with `type_uninhabited_from`, there will very rarely be more than one `DefId` stored.
21- #[ derive( Clone , HashStable , Debug ) ]
22- pub enum DefIdForest {
20+ #[ derive( Copy , Clone , HashStable , Debug ) ]
21+ pub enum DefIdForest < ' a > {
2322 Empty ,
2423 Single ( DefId ) ,
2524 /// This variant is very rare.
2625 /// Invariant: >1 elements
27- /// We use `Arc` because this is used in the output of a query.
28- Multiple ( Arc < [ DefId ] > ) ,
26+ Multiple ( & ' a [ DefId ] ) ,
2927}
3028
3129/// Tests whether a slice of roots contains a given DefId.
@@ -34,21 +32,21 @@ fn slice_contains<'tcx>(tcx: TyCtxt<'tcx>, slice: &[DefId], id: DefId) -> bool {
3432 slice. iter ( ) . any ( |root_id| tcx. is_descendant_of ( id, * root_id) )
3533}
3634
37- impl < ' tcx > DefIdForest {
35+ impl < ' tcx > DefIdForest < ' tcx > {
3836 /// Creates an empty forest.
39- pub fn empty ( ) -> DefIdForest {
37+ pub fn empty ( ) -> DefIdForest < ' tcx > {
4038 DefIdForest :: Empty
4139 }
4240
4341 /// Creates a forest consisting of a single tree representing the entire
4442 /// crate.
4543 #[ inline]
46- pub fn full ( ) -> DefIdForest {
44+ pub fn full ( ) -> DefIdForest < ' tcx > {
4745 DefIdForest :: from_id ( CRATE_DEF_ID . to_def_id ( ) )
4846 }
4947
5048 /// Creates a forest containing a `DefId` and all its descendants.
51- pub fn from_id ( id : DefId ) -> DefIdForest {
49+ pub fn from_id ( id : DefId ) -> DefIdForest < ' tcx > {
5250 DefIdForest :: Single ( id)
5351 }
5452
@@ -61,11 +59,11 @@ impl<'tcx> DefIdForest {
6159 }
6260
6361 // Only allocates in the rare `Multiple` case.
64- fn from_slice ( root_ids : & [ DefId ] ) -> DefIdForest {
65- match root_ids {
62+ fn from_vec ( tcx : TyCtxt < ' tcx > , root_ids : SmallVec < [ DefId ; 1 ] > ) -> DefIdForest < ' tcx > {
63+ match & root_ids[ .. ] {
6664 [ ] => Empty ,
6765 [ id] => Single ( * id) ,
68- _ => DefIdForest :: Multiple ( root_ids . into ( ) ) ,
66+ _ => DefIdForest :: Multiple ( tcx . arena . alloc_from_iter ( root_ids ) ) ,
6967 }
7068 }
7169
@@ -88,9 +86,9 @@ impl<'tcx> DefIdForest {
8886 }
8987
9088 /// Calculate the intersection of a collection of forests.
91- pub fn intersection < I > ( tcx : TyCtxt < ' tcx > , iter : I ) -> DefIdForest
89+ pub fn intersection < I > ( tcx : TyCtxt < ' tcx > , iter : I ) -> DefIdForest < ' tcx >
9290 where
93- I : IntoIterator < Item = DefIdForest > ,
91+ I : IntoIterator < Item = DefIdForest < ' tcx > > ,
9492 {
9593 let mut iter = iter. into_iter ( ) ;
9694 let mut ret: SmallVec < [ _ ; 1 ] > = if let Some ( first) = iter. next ( ) {
@@ -114,13 +112,13 @@ impl<'tcx> DefIdForest {
114112 mem:: swap ( & mut next_ret, & mut ret) ;
115113 next_ret. clear ( ) ;
116114 }
117- DefIdForest :: from_slice ( & ret)
115+ DefIdForest :: from_vec ( tcx , ret)
118116 }
119117
120118 /// Calculate the union of a collection of forests.
121- pub fn union < I > ( tcx : TyCtxt < ' tcx > , iter : I ) -> DefIdForest
119+ pub fn union < I > ( tcx : TyCtxt < ' tcx > , iter : I ) -> DefIdForest < ' tcx >
122120 where
123- I : IntoIterator < Item = DefIdForest > ,
121+ I : IntoIterator < Item = DefIdForest < ' tcx > > ,
124122 {
125123 let mut ret: SmallVec < [ _ ; 1 ] > = SmallVec :: new ( ) ;
126124 let mut next_ret: SmallVec < [ _ ; 1 ] > = SmallVec :: new ( ) ;
@@ -142,6 +140,6 @@ impl<'tcx> DefIdForest {
142140 mem:: swap ( & mut next_ret, & mut ret) ;
143141 next_ret. clear ( ) ;
144142 }
145- DefIdForest :: from_slice ( & ret)
143+ DefIdForest :: from_vec ( tcx , ret)
146144 }
147145}
0 commit comments