@@ -678,6 +678,8 @@ pub struct FileMap {
678678 pub src : Option < Rc < String > > ,
679679 /// The source code's hash
680680 pub src_hash : u128 ,
681+ /// The stable id used during incr. comp.
682+ pub stable_id : StableFilemapId ,
681683 /// The external source code (used for external crates, which will have a `None`
682684 /// value as `self.src`.
683685 pub external_src : RefCell < ExternalSource > ,
@@ -693,15 +695,37 @@ pub struct FileMap {
693695 pub non_narrow_chars : RefCell < Vec < NonNarrowChar > > ,
694696}
695697
698+ // This is a FileMap identifier that is used to correlate FileMaps between
699+ // subsequent compilation sessions (which is something we need to do during
700+ // incremental compilation).
701+ #[ derive( Copy , Clone , PartialEq , Eq , Hash , RustcEncodable , RustcDecodable , Debug ) ]
702+ pub struct StableFilemapId ( pub u128 ) ;
703+
704+ impl StableFilemapId {
705+ pub fn new ( name : & FileName ,
706+ name_was_remapped : bool ,
707+ unmapped_path : & FileName )
708+ -> StableFilemapId {
709+ use std:: hash:: Hash ;
710+
711+ let mut hasher = StableHasher :: new ( ) ;
712+ name. hash ( & mut hasher) ;
713+ name_was_remapped. hash ( & mut hasher) ;
714+ unmapped_path. hash ( & mut hasher) ;
715+ StableFilemapId ( hasher. finish ( ) )
716+ }
717+ }
718+
696719impl Encodable for FileMap {
697720 fn encode < S : Encoder > ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
698721 s. emit_struct ( "FileMap" , 8 , |s| {
699722 s. emit_struct_field ( "name" , 0 , |s| self . name . encode ( s) ) ?;
700723 s. emit_struct_field ( "name_was_remapped" , 1 , |s| self . name_was_remapped . encode ( s) ) ?;
701- s. emit_struct_field ( "src_hash" , 6 , |s| self . src_hash . encode ( s) ) ?;
702- s. emit_struct_field ( "start_pos" , 2 , |s| self . start_pos . encode ( s) ) ?;
703- s. emit_struct_field ( "end_pos" , 3 , |s| self . end_pos . encode ( s) ) ?;
704- s. emit_struct_field ( "lines" , 4 , |s| {
724+ s. emit_struct_field ( "src_hash" , 2 , |s| self . src_hash . encode ( s) ) ?;
725+ s. emit_struct_field ( "stable_id" , 3 , |s| self . stable_id . encode ( s) ) ?;
726+ s. emit_struct_field ( "start_pos" , 4 , |s| self . start_pos . encode ( s) ) ?;
727+ s. emit_struct_field ( "end_pos" , 5 , |s| self . end_pos . encode ( s) ) ?;
728+ s. emit_struct_field ( "lines" , 6 , |s| {
705729 let lines = self . lines . borrow ( ) ;
706730 // store the length
707731 s. emit_u32 ( lines. len ( ) as u32 ) ?;
@@ -747,10 +771,10 @@ impl Encodable for FileMap {
747771
748772 Ok ( ( ) )
749773 } ) ?;
750- s. emit_struct_field ( "multibyte_chars" , 5 , |s| {
774+ s. emit_struct_field ( "multibyte_chars" , 7 , |s| {
751775 ( * self . multibyte_chars . borrow ( ) ) . encode ( s)
752776 } ) ?;
753- s. emit_struct_field ( "non_narrow_chars" , 7 , |s| {
777+ s. emit_struct_field ( "non_narrow_chars" , 8 , |s| {
754778 ( * self . non_narrow_chars . borrow ( ) ) . encode ( s)
755779 } )
756780 } )
@@ -765,11 +789,13 @@ impl Decodable for FileMap {
765789 let name_was_remapped: bool =
766790 d. read_struct_field ( "name_was_remapped" , 1 , |d| Decodable :: decode ( d) ) ?;
767791 let src_hash: u128 =
768- d. read_struct_field ( "src_hash" , 6 , |d| Decodable :: decode ( d) ) ?;
792+ d. read_struct_field ( "src_hash" , 2 , |d| Decodable :: decode ( d) ) ?;
793+ let stable_id: StableFilemapId =
794+ d. read_struct_field ( "stable_id" , 3 , |d| Decodable :: decode ( d) ) ?;
769795 let start_pos: BytePos =
770- d. read_struct_field ( "start_pos" , 2 , |d| Decodable :: decode ( d) ) ?;
771- let end_pos: BytePos = d. read_struct_field ( "end_pos" , 3 , |d| Decodable :: decode ( d) ) ?;
772- let lines: Vec < BytePos > = d. read_struct_field ( "lines" , 4 , |d| {
796+ d. read_struct_field ( "start_pos" , 4 , |d| Decodable :: decode ( d) ) ?;
797+ let end_pos: BytePos = d. read_struct_field ( "end_pos" , 5 , |d| Decodable :: decode ( d) ) ?;
798+ let lines: Vec < BytePos > = d. read_struct_field ( "lines" , 6 , |d| {
773799 let num_lines: u32 = Decodable :: decode ( d) ?;
774800 let mut lines = Vec :: with_capacity ( num_lines as usize ) ;
775801
@@ -798,9 +824,9 @@ impl Decodable for FileMap {
798824 Ok ( lines)
799825 } ) ?;
800826 let multibyte_chars: Vec < MultiByteChar > =
801- d. read_struct_field ( "multibyte_chars" , 5 , |d| Decodable :: decode ( d) ) ?;
827+ d. read_struct_field ( "multibyte_chars" , 7 , |d| Decodable :: decode ( d) ) ?;
802828 let non_narrow_chars: Vec < NonNarrowChar > =
803- d. read_struct_field ( "non_narrow_chars" , 7 , |d| Decodable :: decode ( d) ) ?;
829+ d. read_struct_field ( "non_narrow_chars" , 8 , |d| Decodable :: decode ( d) ) ?;
804830 Ok ( FileMap {
805831 name,
806832 name_was_remapped,
@@ -813,6 +839,7 @@ impl Decodable for FileMap {
813839 end_pos,
814840 src : None ,
815841 src_hash,
842+ stable_id,
816843 external_src : RefCell :: new ( ExternalSource :: AbsentOk ) ,
817844 lines : RefCell :: new ( lines) ,
818845 multibyte_chars : RefCell :: new ( multibyte_chars) ,
@@ -840,6 +867,10 @@ impl FileMap {
840867 hasher. write ( src. as_bytes ( ) ) ;
841868 let src_hash = hasher. finish ( ) ;
842869
870+ let stable_id = StableFilemapId :: new ( & name,
871+ name_was_remapped,
872+ & unmapped_path) ;
873+
843874 let end_pos = start_pos. to_usize ( ) + src. len ( ) ;
844875
845876 FileMap {
@@ -849,6 +880,7 @@ impl FileMap {
849880 crate_of_origin : 0 ,
850881 src : Some ( Rc :: new ( src) ) ,
851882 src_hash,
883+ stable_id,
852884 external_src : RefCell :: new ( ExternalSource :: Unneeded ) ,
853885 start_pos,
854886 end_pos : Pos :: from_usize ( end_pos) ,
0 commit comments