@@ -678,6 +678,8 @@ pub struct FileMap {
678
678
pub src : Option < Rc < String > > ,
679
679
/// The source code's hash
680
680
pub src_hash : u128 ,
681
+ /// The stable id used during incr. comp.
682
+ pub stable_id : StableFilemapId ,
681
683
/// The external source code (used for external crates, which will have a `None`
682
684
/// value as `self.src`.
683
685
pub external_src : RefCell < ExternalSource > ,
@@ -693,15 +695,37 @@ pub struct FileMap {
693
695
pub non_narrow_chars : RefCell < Vec < NonNarrowChar > > ,
694
696
}
695
697
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
+
696
719
impl Encodable for FileMap {
697
720
fn encode < S : Encoder > ( & self , s : & mut S ) -> Result < ( ) , S :: Error > {
698
721
s. emit_struct ( "FileMap" , 8 , |s| {
699
722
s. emit_struct_field ( "name" , 0 , |s| self . name . encode ( s) ) ?;
700
723
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| {
705
729
let lines = self . lines . borrow ( ) ;
706
730
// store the length
707
731
s. emit_u32 ( lines. len ( ) as u32 ) ?;
@@ -747,10 +771,10 @@ impl Encodable for FileMap {
747
771
748
772
Ok ( ( ) )
749
773
} ) ?;
750
- s. emit_struct_field ( "multibyte_chars" , 5 , |s| {
774
+ s. emit_struct_field ( "multibyte_chars" , 7 , |s| {
751
775
( * self . multibyte_chars . borrow ( ) ) . encode ( s)
752
776
} ) ?;
753
- s. emit_struct_field ( "non_narrow_chars" , 7 , |s| {
777
+ s. emit_struct_field ( "non_narrow_chars" , 8 , |s| {
754
778
( * self . non_narrow_chars . borrow ( ) ) . encode ( s)
755
779
} )
756
780
} )
@@ -765,11 +789,13 @@ impl Decodable for FileMap {
765
789
let name_was_remapped: bool =
766
790
d. read_struct_field ( "name_was_remapped" , 1 , |d| Decodable :: decode ( d) ) ?;
767
791
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) ) ?;
769
795
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| {
773
799
let num_lines: u32 = Decodable :: decode ( d) ?;
774
800
let mut lines = Vec :: with_capacity ( num_lines as usize ) ;
775
801
@@ -798,9 +824,9 @@ impl Decodable for FileMap {
798
824
Ok ( lines)
799
825
} ) ?;
800
826
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) ) ?;
802
828
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) ) ?;
804
830
Ok ( FileMap {
805
831
name,
806
832
name_was_remapped,
@@ -813,6 +839,7 @@ impl Decodable for FileMap {
813
839
end_pos,
814
840
src : None ,
815
841
src_hash,
842
+ stable_id,
816
843
external_src : RefCell :: new ( ExternalSource :: AbsentOk ) ,
817
844
lines : RefCell :: new ( lines) ,
818
845
multibyte_chars : RefCell :: new ( multibyte_chars) ,
@@ -840,6 +867,10 @@ impl FileMap {
840
867
hasher. write ( src. as_bytes ( ) ) ;
841
868
let src_hash = hasher. finish ( ) ;
842
869
870
+ let stable_id = StableFilemapId :: new ( & name,
871
+ name_was_remapped,
872
+ & unmapped_path) ;
873
+
843
874
let end_pos = start_pos. to_usize ( ) + src. len ( ) ;
844
875
845
876
FileMap {
@@ -849,6 +880,7 @@ impl FileMap {
849
880
crate_of_origin : 0 ,
850
881
src : Some ( Rc :: new ( src) ) ,
851
882
src_hash,
883
+ stable_id,
852
884
external_src : RefCell :: new ( ExternalSource :: Unneeded ) ,
853
885
start_pos,
854
886
end_pos : Pos :: from_usize ( end_pos) ,
0 commit comments