@@ -2136,18 +2136,24 @@ fn prefetch_mir(tcx: TyCtxt<'_>) {
21362136
21372137#[ derive( Encodable , Decodable ) ]
21382138pub struct EncodedMetadata {
2139- raw_data : Vec < u8 > ,
2139+ full : Vec < u8 > ,
2140+ reference : Option < Vec < u8 > > ,
21402141}
21412142
21422143impl EncodedMetadata {
21432144 #[ inline]
21442145 pub fn new ( ) -> EncodedMetadata {
2145- EncodedMetadata { raw_data : Vec :: new ( ) }
2146+ EncodedMetadata { full : Vec :: new ( ) , reference : None }
21462147 }
21472148
21482149 #[ inline]
2149- pub fn raw_data ( & self ) -> & [ u8 ] {
2150- & self . raw_data
2150+ pub fn full ( & self ) -> & [ u8 ] {
2151+ & self . full
2152+ }
2153+
2154+ #[ inline]
2155+ pub fn maybe_reference ( & self ) -> & [ u8 ] {
2156+ self . reference . as_ref ( ) . unwrap_or ( & self . full )
21512157 }
21522158}
21532159
@@ -2173,20 +2179,26 @@ pub fn encode_metadata(tcx: TyCtxt<'_>) -> EncodedMetadata {
21732179 . 0
21742180}
21752181
2176- fn encode_metadata_impl ( tcx : TyCtxt < ' _ > ) -> EncodedMetadata {
2182+ fn encode_metadata_header < ' a , ' tcx > (
2183+ tcx : TyCtxt < ' tcx > ,
2184+ hygiene_ctxt : & ' a HygieneEncodeContext ,
2185+ ) -> EncodeContext < ' a , ' tcx > {
21772186 let mut encoder = opaque:: Encoder :: new ( vec ! [ ] ) ;
21782187 encoder. emit_raw_bytes ( METADATA_HEADER ) . unwrap ( ) ;
21792188
2189+ encoder. emit_raw_bytes ( & tcx. crate_hash ( LOCAL_CRATE ) . as_u64 ( ) . to_le_bytes ( ) ) . unwrap ( ) ;
2190+
21802191 // Will be filled with the root position after encoding everything.
21812192 encoder. emit_raw_bytes ( & [ 0 , 0 , 0 , 0 ] ) . unwrap ( ) ;
21822193
2194+ // Reserved for future extension
2195+ encoder. emit_raw_bytes ( & [ 0 , 0 , 0 , 0 ] ) . unwrap ( ) ;
2196+
21832197 let source_map_files = tcx. sess . source_map ( ) . files ( ) ;
21842198 let source_file_cache = ( source_map_files[ 0 ] . clone ( ) , 0 ) ;
21852199 let required_source_files = Some ( GrowableBitSet :: with_capacity ( source_map_files. len ( ) ) ) ;
21862200 drop ( source_map_files) ;
21872201
2188- let hygiene_ctxt = HygieneEncodeContext :: default ( ) ;
2189-
21902202 let mut ecx = EncodeContext {
21912203 opaque : encoder,
21922204 tcx,
@@ -2199,27 +2211,43 @@ fn encode_metadata_impl(tcx: TyCtxt<'_>) -> EncodedMetadata {
21992211 interpret_allocs : Default :: default ( ) ,
22002212 required_source_files,
22012213 is_proc_macro : tcx. sess . crate_types ( ) . contains ( & CrateType :: ProcMacro ) ,
2202- hygiene_ctxt : & hygiene_ctxt ,
2214+ hygiene_ctxt,
22032215 } ;
22042216
22052217 // Encode the rustc version string in a predictable location.
22062218 rustc_version ( ) . encode ( & mut ecx) . unwrap ( ) ;
22072219
2220+ ecx
2221+ }
2222+
2223+ fn encode_metadata_impl ( tcx : TyCtxt < ' _ > ) -> EncodedMetadata {
2224+ let hygiene_ctxt = HygieneEncodeContext :: default ( ) ;
2225+ let mut ecx = encode_metadata_header ( tcx, & hygiene_ctxt) ;
2226+
22082227 // Encode all the entries and extra information in the crate,
22092228 // culminating in the `CrateRoot` which points to all of it.
22102229 let root = ecx. encode_crate_root ( ) ;
22112230
22122231 let mut result = ecx. opaque . into_inner ( ) ;
22132232
22142233 // Encode the root position.
2215- let header = METADATA_HEADER . len ( ) ;
2234+ let header = METADATA_HEADER . len ( ) + 8 ;
22162235 let pos = root. position . get ( ) ;
22172236 result[ header..header + 4 ] . copy_from_slice ( & pos. to_le_bytes ( ) ) ;
22182237
22192238 // Record metadata size for self-profiling
22202239 tcx. prof . artifact_size ( "crate_metadata" , "crate_metadata" , result. len ( ) as u64 ) ;
22212240
2222- EncodedMetadata { raw_data : result }
2241+ let reference_result = if tcx. sess . opts . debugging_opts . split_metadata {
2242+ let hygiene_ctxt = HygieneEncodeContext :: default ( ) ;
2243+ let ecx = encode_metadata_header ( tcx, & hygiene_ctxt) ;
2244+ // Don't fill in the root position for reference metadata
2245+ Some ( ecx. opaque . into_inner ( ) )
2246+ } else {
2247+ None
2248+ } ;
2249+
2250+ EncodedMetadata { full : result, reference : reference_result }
22232251}
22242252
22252253pub fn provide ( providers : & mut Providers ) {
0 commit comments