315
315
use std:: collections:: hash_map:: { Entry , HashMap } ;
316
316
use std:: convert:: TryInto ;
317
317
use std:: env;
318
- use std:: hash:: { self , Hasher } ;
318
+ use std:: hash:: { self , Hash , Hasher } ;
319
319
use std:: path:: { Path , PathBuf } ;
320
320
use std:: str;
321
321
use std:: sync:: { Arc , Mutex } ;
@@ -334,7 +334,7 @@ use crate::core::Package;
334
334
use crate :: util;
335
335
use crate :: util:: errors:: CargoResult ;
336
336
use crate :: util:: interning:: InternedString ;
337
- use crate :: util:: { internal, path_args, profile} ;
337
+ use crate :: util:: { internal, path_args, profile, StableHasher } ;
338
338
use crate :: CARGO_ENV ;
339
339
340
340
use super :: custom_build:: BuildDeps ;
@@ -502,7 +502,7 @@ struct DepFingerprint {
502
502
/// as a fingerprint (all source files must be modified *before* this mtime).
503
503
/// This dep-info file is not generated, however, until after the crate is
504
504
/// compiled. As a result, this structure can be thought of as a fingerprint
505
- /// to-be. The actual value can be calculated via `hash ()`, but the operation
505
+ /// to-be. The actual value can be calculated via `hash_u64 ()`, but the operation
506
506
/// may fail as some files may not have been generated.
507
507
///
508
508
/// Note that dependencies are taken into account for fingerprints because rustc
@@ -594,7 +594,7 @@ impl Serialize for DepFingerprint {
594
594
& self . pkg_id ,
595
595
& self . name ,
596
596
& self . public ,
597
- & self . fingerprint . hash ( ) ,
597
+ & self . fingerprint . hash_u64 ( ) ,
598
598
)
599
599
. serialize ( ser)
600
600
}
@@ -812,7 +812,7 @@ impl Fingerprint {
812
812
* self . memoized_hash . lock ( ) . unwrap ( ) = None ;
813
813
}
814
814
815
- fn hash ( & self ) -> u64 {
815
+ fn hash_u64 ( & self ) -> u64 {
816
816
if let Some ( s) = * self . memoized_hash . lock ( ) . unwrap ( ) {
817
817
return s;
818
818
}
@@ -956,13 +956,13 @@ impl Fingerprint {
956
956
return Err ( e) ;
957
957
}
958
958
959
- if a. fingerprint . hash ( ) != b. fingerprint . hash ( ) {
959
+ if a. fingerprint . hash_u64 ( ) != b. fingerprint . hash_u64 ( ) {
960
960
let e = format_err ! (
961
961
"new ({}/{:x}) != old ({}/{:x})" ,
962
962
a. name,
963
- a. fingerprint. hash ( ) ,
963
+ a. fingerprint. hash_u64 ( ) ,
964
964
b. name,
965
- b. fingerprint. hash ( )
965
+ b. fingerprint. hash_u64 ( )
966
966
)
967
967
. context ( "unit dependency information changed" ) ;
968
968
return Err ( e) ;
@@ -1145,7 +1145,7 @@ impl hash::Hash for Fingerprint {
1145
1145
name. hash ( h) ;
1146
1146
public. hash ( h) ;
1147
1147
// use memoized dep hashes to avoid exponential blowup
1148
- h. write_u64 ( Fingerprint :: hash ( fingerprint) ) ;
1148
+ h. write_u64 ( fingerprint. hash_u64 ( ) ) ;
1149
1149
}
1150
1150
}
1151
1151
}
@@ -1318,12 +1318,17 @@ fn calculate_normal(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Finger
1318
1318
// Include metadata since it is exposed as environment variables.
1319
1319
let m = unit. pkg . manifest ( ) . metadata ( ) ;
1320
1320
let metadata = util:: hash_u64 ( ( & m. authors , & m. description , & m. homepage , & m. repository ) ) ;
1321
- let mut config = 0u64 ;
1321
+ let mut config = StableHasher :: new ( ) ;
1322
+ if let Some ( linker) = cx. bcx . linker ( unit. kind ) {
1323
+ linker. hash ( & mut config) ;
1324
+ }
1322
1325
if unit. mode . is_doc ( ) && cx. bcx . config . cli_unstable ( ) . rustdoc_map {
1323
- config = config. wrapping_add ( cx. bcx . config . doc_extern_map ( ) . map_or ( 0 , util:: hash_u64) ) ;
1326
+ if let Ok ( map) = cx. bcx . config . doc_extern_map ( ) {
1327
+ map. hash ( & mut config) ;
1328
+ }
1324
1329
}
1325
1330
if let Some ( allow_features) = & cx. bcx . config . cli_unstable ( ) . allow_features {
1326
- config = config . wrapping_add ( util :: hash_u64 ( allow_features ) ) ;
1331
+ allow_features . hash ( & mut config ) ;
1327
1332
}
1328
1333
let compile_kind = unit. kind . fingerprint_hash ( ) ;
1329
1334
Ok ( Fingerprint {
@@ -1338,7 +1343,7 @@ fn calculate_normal(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Finger
1338
1343
local : Mutex :: new ( local) ,
1339
1344
memoized_hash : Mutex :: new ( None ) ,
1340
1345
metadata,
1341
- config,
1346
+ config : config . finish ( ) ,
1342
1347
compile_kind,
1343
1348
rustflags : extra_flags,
1344
1349
fs_status : FsStatus :: Stale ,
@@ -1570,14 +1575,14 @@ fn write_fingerprint(loc: &Path, fingerprint: &Fingerprint) -> CargoResult<()> {
1570
1575
// fingerprint::new().rustc == 0, make sure it doesn't make it to the file system.
1571
1576
// This is mostly so outside tools can reliably find out what rust version this file is for,
1572
1577
// as we can use the full hash.
1573
- let hash = fingerprint. hash ( ) ;
1578
+ let hash = fingerprint. hash_u64 ( ) ;
1574
1579
debug ! ( "write fingerprint ({:x}) : {}" , hash, loc. display( ) ) ;
1575
1580
paths:: write ( loc, util:: to_hex ( hash) . as_bytes ( ) ) ?;
1576
1581
1577
1582
let json = serde_json:: to_string ( fingerprint) . unwrap ( ) ;
1578
1583
if cfg ! ( debug_assertions) {
1579
1584
let f: Fingerprint = serde_json:: from_str ( & json) . unwrap ( ) ;
1580
- assert_eq ! ( f. hash ( ) , hash) ;
1585
+ assert_eq ! ( f. hash_u64 ( ) , hash) ;
1581
1586
}
1582
1587
paths:: write ( & loc. with_extension ( "json" ) , json. as_bytes ( ) ) ?;
1583
1588
Ok ( ( ) )
@@ -1621,7 +1626,7 @@ fn compare_old_fingerprint(
1621
1626
paths:: set_file_time_no_err ( loc, t) ;
1622
1627
}
1623
1628
1624
- let new_hash = new_fingerprint. hash ( ) ;
1629
+ let new_hash = new_fingerprint. hash_u64 ( ) ;
1625
1630
1626
1631
if util:: to_hex ( new_hash) == old_fingerprint_short && new_fingerprint. fs_status . up_to_date ( ) {
1627
1632
return Ok ( ( ) ) ;
@@ -1632,7 +1637,10 @@ fn compare_old_fingerprint(
1632
1637
. with_context ( || internal ( "failed to deserialize json" ) ) ?;
1633
1638
// Fingerprint can be empty after a failed rebuild (see comment in prepare_target).
1634
1639
if !old_fingerprint_short. is_empty ( ) {
1635
- debug_assert_eq ! ( util:: to_hex( old_fingerprint. hash( ) ) , old_fingerprint_short) ;
1640
+ debug_assert_eq ! (
1641
+ util:: to_hex( old_fingerprint. hash_u64( ) ) ,
1642
+ old_fingerprint_short
1643
+ ) ;
1636
1644
}
1637
1645
let result = new_fingerprint. compare ( & old_fingerprint) ;
1638
1646
assert ! ( result. is_err( ) ) ;
0 commit comments