@@ -17,18 +17,17 @@ use self::SawExprComponent::*;
17
17
use self :: SawAbiComponent :: * ;
18
18
use syntax:: ast:: { self , Name , NodeId , Attribute } ;
19
19
use syntax:: parse:: token;
20
- use syntax:: codemap:: CodeMap ;
21
- use syntax_pos:: { Span , NO_EXPANSION , COMMAND_LINE_EXPN , BytePos , FileMap } ;
20
+ use syntax_pos:: { Span , NO_EXPANSION , COMMAND_LINE_EXPN , BytePos } ;
22
21
use rustc:: hir;
23
22
use rustc:: hir:: * ;
24
23
use rustc:: hir:: def:: { Def , PathResolution } ;
25
24
use rustc:: hir:: def_id:: DefId ;
26
25
use rustc:: hir:: intravisit as visit;
27
26
use rustc:: ty:: TyCtxt ;
28
- use std:: rc:: Rc ;
29
27
use std:: hash:: { Hash , SipHasher } ;
30
28
31
29
use super :: def_path_hash:: DefPathHashes ;
30
+ use super :: caching_codemap_view:: CachingCodemapView ;
32
31
33
32
const IGNORED_ATTRIBUTES : & ' static [ & ' static str ] = & [ "cfg" ,
34
33
"rustc_clean" ,
@@ -40,100 +39,22 @@ pub struct StrictVersionHashVisitor<'a, 'hash: 'a, 'tcx: 'hash> {
40
39
// collect a deterministic hash of def-ids that we have seen
41
40
def_path_hashes : & ' a mut DefPathHashes < ' hash , ' tcx > ,
42
41
hash_spans : bool ,
43
- codemap : CachingCodemapView < ' tcx > ,
44
- }
45
-
46
- #[ derive( Clone ) ]
47
- struct CacheEntry {
48
- time_stamp : usize ,
49
- line_number : usize ,
50
- line_start : BytePos ,
51
- line_end : BytePos ,
52
- file : Rc < FileMap > ,
53
- }
54
-
55
- struct CachingCodemapView < ' tcx > {
56
- codemap : & ' tcx CodeMap ,
57
- line_cache : [ CacheEntry ; 3 ] ,
58
- time_stamp : usize ,
59
- }
60
-
61
- impl < ' tcx > CachingCodemapView < ' tcx > {
62
- fn new < ' a > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ) -> CachingCodemapView < ' tcx > {
63
- let codemap = tcx. sess . codemap ( ) ;
64
- let first_file = codemap. files . borrow ( ) [ 0 ] . clone ( ) ;
65
- let entry = CacheEntry {
66
- time_stamp : 0 ,
67
- line_number : 0 ,
68
- line_start : BytePos ( 0 ) ,
69
- line_end : BytePos ( 0 ) ,
70
- file : first_file,
71
- } ;
72
-
73
- CachingCodemapView {
74
- codemap : codemap,
75
- line_cache : [ entry. clone ( ) , entry. clone ( ) , entry. clone ( ) ] ,
76
- time_stamp : 0 ,
77
- }
78
- }
79
-
80
- fn byte_pos_to_line_and_col ( & mut self ,
81
- pos : BytePos )
82
- -> ( Rc < FileMap > , usize , BytePos ) {
83
- self . time_stamp += 1 ;
84
-
85
- // Check if the position is in one of the cached lines
86
- for cache_entry in self . line_cache . iter_mut ( ) {
87
- if pos >= cache_entry. line_start && pos < cache_entry. line_end {
88
- cache_entry. time_stamp = self . time_stamp ;
89
- return ( cache_entry. file . clone ( ) ,
90
- cache_entry. line_number ,
91
- pos - cache_entry. line_start ) ;
92
- }
93
- }
94
-
95
- // No cache hit ...
96
- let mut oldest = 0 ;
97
- for index in 1 .. self . line_cache . len ( ) {
98
- if self . line_cache [ index] . time_stamp < self . line_cache [ oldest] . time_stamp {
99
- oldest = index;
100
- }
101
- }
102
-
103
- let cache_entry = & mut self . line_cache [ oldest] ;
104
-
105
- // If the entry doesn't point to the correct file, fix it up
106
- if pos < cache_entry. file . start_pos || pos >= cache_entry. file . end_pos {
107
- let file_index = self . codemap . lookup_filemap_idx ( pos) ;
108
- cache_entry. file = self . codemap . files . borrow ( ) [ file_index] . clone ( ) ;
109
- }
110
-
111
- let line_index = cache_entry. file . lookup_line ( pos) . unwrap ( ) ;
112
- let line_bounds = cache_entry. file . line_bounds ( line_index) ;
113
-
114
- cache_entry. line_number = line_index + 1 ;
115
- cache_entry. line_start = line_bounds. 0 ;
116
- cache_entry. line_end = line_bounds. 1 ;
117
- cache_entry. time_stamp = self . time_stamp ;
118
-
119
- return ( cache_entry. file . clone ( ) ,
120
- cache_entry. line_number ,
121
- pos - cache_entry. line_start ) ;
122
- }
42
+ codemap : & ' a mut CachingCodemapView < ' tcx > ,
123
43
}
124
44
125
45
impl < ' a , ' hash , ' tcx > StrictVersionHashVisitor < ' a , ' hash , ' tcx > {
126
46
pub fn new ( st : & ' a mut SipHasher ,
127
47
tcx : TyCtxt < ' hash , ' tcx , ' tcx > ,
128
48
def_path_hashes : & ' a mut DefPathHashes < ' hash , ' tcx > ,
49
+ codemap : & ' a mut CachingCodemapView < ' tcx > ,
129
50
hash_spans : bool )
130
51
-> Self {
131
52
StrictVersionHashVisitor {
132
53
st : st,
133
54
tcx : tcx,
134
55
def_path_hashes : def_path_hashes,
135
56
hash_spans : hash_spans,
136
- codemap : CachingCodemapView :: new ( tcx ) ,
57
+ codemap : codemap ,
137
58
}
138
59
}
139
60
@@ -178,7 +99,8 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
178
99
expansion_kind) . hash ( self . st ) ;
179
100
180
101
if expansion_kind == SawSpanExpnKind :: SomeExpansion {
181
- self . hash_span ( self . codemap . codemap . source_callsite ( span) ) ;
102
+ let call_site = self . codemap . codemap ( ) . source_callsite ( span) ;
103
+ self . hash_span ( call_site) ;
182
104
}
183
105
}
184
106
0 commit comments