@@ -3,7 +3,6 @@ use crate::ty::{DefId, DefIdTree};
3
3
use rustc_span:: def_id:: CRATE_DEF_ID ;
4
4
use smallvec:: SmallVec ;
5
5
use std:: mem;
6
- use std:: sync:: Arc ;
7
6
8
7
use DefIdForest :: * ;
9
8
@@ -18,14 +17,13 @@ use DefIdForest::*;
18
17
/// We store the minimal set of `DefId`s required to represent the whole set. If A and B are
19
18
/// `DefId`s in the `DefIdForest`, and A is a parent of B, then only A will be stored. When this is
20
19
/// 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 > {
23
22
Empty ,
24
23
Single ( DefId ) ,
25
24
/// This variant is very rare.
26
25
/// 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 ] ) ,
29
27
}
30
28
31
29
/// 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 {
34
32
slice. iter ( ) . any ( |root_id| tcx. is_descendant_of ( id, * root_id) )
35
33
}
36
34
37
- impl < ' tcx > DefIdForest {
35
+ impl < ' tcx > DefIdForest < ' tcx > {
38
36
/// Creates an empty forest.
39
- pub fn empty ( ) -> DefIdForest {
37
+ pub fn empty ( ) -> DefIdForest < ' tcx > {
40
38
DefIdForest :: Empty
41
39
}
42
40
43
41
/// Creates a forest consisting of a single tree representing the entire
44
42
/// crate.
45
43
#[ inline]
46
- pub fn full ( ) -> DefIdForest {
44
+ pub fn full ( ) -> DefIdForest < ' tcx > {
47
45
DefIdForest :: from_id ( CRATE_DEF_ID . to_def_id ( ) )
48
46
}
49
47
50
48
/// 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 > {
52
50
DefIdForest :: Single ( id)
53
51
}
54
52
@@ -61,11 +59,11 @@ impl<'tcx> DefIdForest {
61
59
}
62
60
63
61
// 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[ .. ] {
66
64
[ ] => Empty ,
67
65
[ id] => Single ( * id) ,
68
- _ => DefIdForest :: Multiple ( root_ids . into ( ) ) ,
66
+ _ => DefIdForest :: Multiple ( tcx . arena . alloc_from_iter ( root_ids ) ) ,
69
67
}
70
68
}
71
69
@@ -88,9 +86,9 @@ impl<'tcx> DefIdForest {
88
86
}
89
87
90
88
/// 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 >
92
90
where
93
- I : IntoIterator < Item = DefIdForest > ,
91
+ I : IntoIterator < Item = DefIdForest < ' tcx > > ,
94
92
{
95
93
let mut iter = iter. into_iter ( ) ;
96
94
let mut ret: SmallVec < [ _ ; 1 ] > = if let Some ( first) = iter. next ( ) {
@@ -114,13 +112,13 @@ impl<'tcx> DefIdForest {
114
112
mem:: swap ( & mut next_ret, & mut ret) ;
115
113
next_ret. clear ( ) ;
116
114
}
117
- DefIdForest :: from_slice ( & ret)
115
+ DefIdForest :: from_vec ( tcx , ret)
118
116
}
119
117
120
118
/// 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 >
122
120
where
123
- I : IntoIterator < Item = DefIdForest > ,
121
+ I : IntoIterator < Item = DefIdForest < ' tcx > > ,
124
122
{
125
123
let mut ret: SmallVec < [ _ ; 1 ] > = SmallVec :: new ( ) ;
126
124
let mut next_ret: SmallVec < [ _ ; 1 ] > = SmallVec :: new ( ) ;
@@ -142,6 +140,6 @@ impl<'tcx> DefIdForest {
142
140
mem:: swap ( & mut next_ret, & mut ret) ;
143
141
next_ret. clear ( ) ;
144
142
}
145
- DefIdForest :: from_slice ( & ret)
143
+ DefIdForest :: from_vec ( tcx , ret)
146
144
}
147
145
}
0 commit comments