88// option. This file may not be copied, modified, or distributed
99// except according to those terms.
1010
11- use ty:: TyCtxt ;
11+ use dep_graph:: { DepGraph , DepNode } ;
12+ use hir:: def_id:: { DefId , CrateNum , CRATE_DEF_INDEX } ;
13+ use rustc_data_structures:: bitvec:: BitVector ;
1214use std:: rc:: Rc ;
15+ use std:: sync:: Arc ;
1316use syntax:: codemap:: CodeMap ;
1417use syntax_pos:: { BytePos , FileMap } ;
18+ use ty:: TyCtxt ;
1519
1620#[ derive( Clone ) ]
1721struct CacheEntry {
@@ -20,30 +24,37 @@ struct CacheEntry {
2024 line_start : BytePos ,
2125 line_end : BytePos ,
2226 file : Rc < FileMap > ,
27+ file_index : usize ,
2328}
2429
2530pub struct CachingCodemapView < ' tcx > {
2631 codemap : & ' tcx CodeMap ,
2732 line_cache : [ CacheEntry ; 3 ] ,
2833 time_stamp : usize ,
34+ dep_graph : DepGraph ,
35+ dep_tracking_reads : BitVector ,
2936}
3037
3138impl < ' tcx > CachingCodemapView < ' tcx > {
3239 pub fn new < ' a > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ) -> CachingCodemapView < ' tcx > {
3340 let codemap = tcx. sess . codemap ( ) ;
34- let first_file = codemap. files . borrow ( ) [ 0 ] . clone ( ) ;
41+ let files = codemap. files_untracked ( ) ;
42+ let first_file = files[ 0 ] . clone ( ) ;
3543 let entry = CacheEntry {
3644 time_stamp : 0 ,
3745 line_number : 0 ,
3846 line_start : BytePos ( 0 ) ,
3947 line_end : BytePos ( 0 ) ,
4048 file : first_file,
49+ file_index : 0 ,
4150 } ;
4251
4352 CachingCodemapView {
53+ dep_graph : tcx. dep_graph . clone ( ) ,
4454 codemap : codemap,
4555 line_cache : [ entry. clone ( ) , entry. clone ( ) , entry. clone ( ) ] ,
4656 time_stamp : 0 ,
57+ dep_tracking_reads : BitVector :: new ( files. len ( ) ) ,
4758 }
4859 }
4960
@@ -56,6 +67,10 @@ impl<'tcx> CachingCodemapView<'tcx> {
5667 for cache_entry in self . line_cache . iter_mut ( ) {
5768 if pos >= cache_entry. line_start && pos < cache_entry. line_end {
5869 cache_entry. time_stamp = self . time_stamp ;
70+ if self . dep_tracking_reads . insert ( cache_entry. file_index ) {
71+ self . dep_graph . read ( dep_node ( cache_entry) ) ;
72+ }
73+
5974 return Some ( ( cache_entry. file . clone ( ) ,
6075 cache_entry. line_number ,
6176 pos - cache_entry. line_start ) ) ;
@@ -75,14 +90,15 @@ impl<'tcx> CachingCodemapView<'tcx> {
7590 // If the entry doesn't point to the correct file, fix it up
7691 if pos < cache_entry. file . start_pos || pos >= cache_entry. file . end_pos {
7792 let file_valid;
78- let files = self . codemap . files . borrow ( ) ;
93+ let files = self . codemap . files_untracked ( ) ;
7994
8095 if files. len ( ) > 0 {
8196 let file_index = self . codemap . lookup_filemap_idx ( pos) ;
8297 let file = files[ file_index] . clone ( ) ;
8398
8499 if pos >= file. start_pos && pos < file. end_pos {
85100 cache_entry. file = file;
101+ cache_entry. file_index = file_index;
86102 file_valid = true ;
87103 } else {
88104 file_valid = false ;
@@ -104,8 +120,21 @@ impl<'tcx> CachingCodemapView<'tcx> {
104120 cache_entry. line_end = line_bounds. 1 ;
105121 cache_entry. time_stamp = self . time_stamp ;
106122
123+ if self . dep_tracking_reads . insert ( cache_entry. file_index ) {
124+ self . dep_graph . read ( dep_node ( cache_entry) ) ;
125+ }
126+
107127 return Some ( ( cache_entry. file . clone ( ) ,
108128 cache_entry. line_number ,
109129 pos - cache_entry. line_start ) ) ;
110130 }
111131}
132+
133+ fn dep_node ( cache_entry : & CacheEntry ) -> DepNode < DefId > {
134+ let def_id = DefId {
135+ krate : CrateNum :: from_u32 ( cache_entry. file . crate_of_origin ) ,
136+ index : CRATE_DEF_INDEX ,
137+ } ;
138+ let name = Arc :: new ( cache_entry. file . name . clone ( ) ) ;
139+ DepNode :: FileMap ( def_id, name)
140+ }
0 commit comments