@@ -17,18 +17,17 @@ use self::SawExprComponent::*;
1717use self :: SawAbiComponent :: * ;
1818use syntax:: ast:: { self , Name , NodeId , Attribute } ;
1919use 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 } ;
2221use rustc:: hir;
2322use rustc:: hir:: * ;
2423use rustc:: hir:: def:: { Def , PathResolution } ;
2524use rustc:: hir:: def_id:: DefId ;
2625use rustc:: hir:: intravisit as visit;
2726use rustc:: ty:: TyCtxt ;
28- use std:: rc:: Rc ;
2927use std:: hash:: { Hash , SipHasher } ;
3028
3129use super :: def_path_hash:: DefPathHashes ;
30+ use super :: caching_codemap_view:: CachingCodemapView ;
3231
3332const IGNORED_ATTRIBUTES : & ' static [ & ' static str ] = & [ "cfg" ,
3433 "rustc_clean" ,
@@ -40,100 +39,22 @@ pub struct StrictVersionHashVisitor<'a, 'hash: 'a, 'tcx: 'hash> {
4039 // collect a deterministic hash of def-ids that we have seen
4140 def_path_hashes : & ' a mut DefPathHashes < ' hash , ' tcx > ,
4241 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 > ,
12343}
12444
12545impl < ' a , ' hash , ' tcx > StrictVersionHashVisitor < ' a , ' hash , ' tcx > {
12646 pub fn new ( st : & ' a mut SipHasher ,
12747 tcx : TyCtxt < ' hash , ' tcx , ' tcx > ,
12848 def_path_hashes : & ' a mut DefPathHashes < ' hash , ' tcx > ,
49+ codemap : & ' a mut CachingCodemapView < ' tcx > ,
12950 hash_spans : bool )
13051 -> Self {
13152 StrictVersionHashVisitor {
13253 st : st,
13354 tcx : tcx,
13455 def_path_hashes : def_path_hashes,
13556 hash_spans : hash_spans,
136- codemap : CachingCodemapView :: new ( tcx ) ,
57+ codemap : codemap ,
13758 }
13859 }
13960
@@ -178,7 +99,8 @@ impl<'a, 'hash, 'tcx> StrictVersionHashVisitor<'a, 'hash, 'tcx> {
17899 expansion_kind) . hash ( self . st ) ;
179100
180101 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) ;
182104 }
183105 }
184106
0 commit comments