@@ -31,7 +31,7 @@ use std::collections::btree_map::{
31
31
} ;
32
32
use std:: collections:: { BTreeMap , BTreeSet } ;
33
33
use std:: fmt;
34
- use std:: hash:: { Hash , Hasher } ;
34
+ use std:: hash:: Hash ;
35
35
use std:: iter:: { self , FromIterator } ;
36
36
use std:: path:: { Path , PathBuf } ;
37
37
use std:: str:: { self , FromStr } ;
@@ -328,19 +328,9 @@ impl Default for TrimmedDefPaths {
328
328
/// *Do not* switch `BTreeMap` out for an unsorted container type! That would break
329
329
/// dependency tracking for command-line arguments. Also only hash keys, since tracking
330
330
/// should only depend on the output types, not the paths they're written to.
331
- #[ derive( Clone , Debug ) ]
331
+ #[ derive( Clone , Debug , Hash ) ]
332
332
pub struct OutputTypes ( BTreeMap < OutputType , Option < PathBuf > > ) ;
333
333
334
- impl Hash for OutputTypes {
335
- fn hash < H : Hasher > ( & self , hasher : & mut H ) {
336
- for k in self . keys ( ) {
337
- k. hash ( hasher) ;
338
- }
339
- }
340
- }
341
-
342
- impl_stable_hash_via_hash ! ( OutputTypes ) ;
343
-
344
334
impl OutputTypes {
345
335
pub fn new ( entries : & [ ( OutputType , Option < PathBuf > ) ] ) -> OutputTypes {
346
336
OutputTypes ( BTreeMap :: from_iter ( entries. iter ( ) . map ( |& ( k, ref v) | ( k, v. clone ( ) ) ) ) )
@@ -2436,8 +2426,8 @@ crate mod dep_tracking {
2436
2426
use super :: LdImpl ;
2437
2427
use super :: {
2438
2428
CFGuard , CrateType , DebugInfo , ErrorOutputType , InstrumentCoverage , LinkerPluginLto ,
2439
- LtoCli , OptLevel , OutputTypes , Passes , SourceFileHashAlgorithm , SwitchWithOptPath ,
2440
- SymbolManglingVersion , TrimmedDefPaths ,
2429
+ LtoCli , OptLevel , OutputType , OutputTypes , Passes , SourceFileHashAlgorithm ,
2430
+ SwitchWithOptPath , SymbolManglingVersion , TrimmedDefPaths ,
2441
2431
} ;
2442
2432
use crate :: lint;
2443
2433
use crate :: options:: WasiExecModel ;
@@ -2453,25 +2443,35 @@ crate mod dep_tracking {
2453
2443
use std:: path:: PathBuf ;
2454
2444
2455
2445
pub trait DepTrackingHash {
2456
- fn hash ( & self , hasher : & mut DefaultHasher , error_format : ErrorOutputType ) ;
2446
+ fn hash (
2447
+ & self ,
2448
+ hasher : & mut DefaultHasher ,
2449
+ error_format : ErrorOutputType ,
2450
+ for_crate_hash : bool ,
2451
+ ) ;
2457
2452
}
2458
2453
2459
2454
macro_rules! impl_dep_tracking_hash_via_hash {
2460
2455
( $( $t: ty) ,+ $( , ) ?) => { $(
2461
2456
impl DepTrackingHash for $t {
2462
- fn hash( & self , hasher: & mut DefaultHasher , _: ErrorOutputType ) {
2457
+ fn hash( & self , hasher: & mut DefaultHasher , _: ErrorOutputType , _for_crate_hash : bool ) {
2463
2458
Hash :: hash( self , hasher) ;
2464
2459
}
2465
2460
}
2466
2461
) +} ;
2467
2462
}
2468
2463
2469
2464
impl < T : DepTrackingHash > DepTrackingHash for Option < T > {
2470
- fn hash ( & self , hasher : & mut DefaultHasher , error_format : ErrorOutputType ) {
2465
+ fn hash (
2466
+ & self ,
2467
+ hasher : & mut DefaultHasher ,
2468
+ error_format : ErrorOutputType ,
2469
+ for_crate_hash : bool ,
2470
+ ) {
2471
2471
match self {
2472
2472
Some ( x) => {
2473
2473
Hash :: hash ( & 1 , hasher) ;
2474
- DepTrackingHash :: hash ( x, hasher, error_format) ;
2474
+ DepTrackingHash :: hash ( x, hasher, error_format, for_crate_hash ) ;
2475
2475
}
2476
2476
None => Hash :: hash ( & 0 , hasher) ,
2477
2477
}
@@ -2501,7 +2501,6 @@ crate mod dep_tracking {
2501
2501
LtoCli ,
2502
2502
DebugInfo ,
2503
2503
UnstableFeatures ,
2504
- OutputTypes ,
2505
2504
NativeLib ,
2506
2505
NativeLibKind ,
2507
2506
SanitizerSet ,
@@ -2515,18 +2514,24 @@ crate mod dep_tracking {
2515
2514
SourceFileHashAlgorithm ,
2516
2515
TrimmedDefPaths ,
2517
2516
Option <LdImpl >,
2517
+ OutputType ,
2518
2518
) ;
2519
2519
2520
2520
impl < T1 , T2 > DepTrackingHash for ( T1 , T2 )
2521
2521
where
2522
2522
T1 : DepTrackingHash ,
2523
2523
T2 : DepTrackingHash ,
2524
2524
{
2525
- fn hash ( & self , hasher : & mut DefaultHasher , error_format : ErrorOutputType ) {
2525
+ fn hash (
2526
+ & self ,
2527
+ hasher : & mut DefaultHasher ,
2528
+ error_format : ErrorOutputType ,
2529
+ for_crate_hash : bool ,
2530
+ ) {
2526
2531
Hash :: hash ( & 0 , hasher) ;
2527
- DepTrackingHash :: hash ( & self . 0 , hasher, error_format) ;
2532
+ DepTrackingHash :: hash ( & self . 0 , hasher, error_format, for_crate_hash ) ;
2528
2533
Hash :: hash ( & 1 , hasher) ;
2529
- DepTrackingHash :: hash ( & self . 1 , hasher, error_format) ;
2534
+ DepTrackingHash :: hash ( & self . 1 , hasher, error_format, for_crate_hash ) ;
2530
2535
}
2531
2536
}
2532
2537
@@ -2536,22 +2541,49 @@ crate mod dep_tracking {
2536
2541
T2 : DepTrackingHash ,
2537
2542
T3 : DepTrackingHash ,
2538
2543
{
2539
- fn hash ( & self , hasher : & mut DefaultHasher , error_format : ErrorOutputType ) {
2544
+ fn hash (
2545
+ & self ,
2546
+ hasher : & mut DefaultHasher ,
2547
+ error_format : ErrorOutputType ,
2548
+ for_crate_hash : bool ,
2549
+ ) {
2540
2550
Hash :: hash ( & 0 , hasher) ;
2541
- DepTrackingHash :: hash ( & self . 0 , hasher, error_format) ;
2551
+ DepTrackingHash :: hash ( & self . 0 , hasher, error_format, for_crate_hash ) ;
2542
2552
Hash :: hash ( & 1 , hasher) ;
2543
- DepTrackingHash :: hash ( & self . 1 , hasher, error_format) ;
2553
+ DepTrackingHash :: hash ( & self . 1 , hasher, error_format, for_crate_hash ) ;
2544
2554
Hash :: hash ( & 2 , hasher) ;
2545
- DepTrackingHash :: hash ( & self . 2 , hasher, error_format) ;
2555
+ DepTrackingHash :: hash ( & self . 2 , hasher, error_format, for_crate_hash ) ;
2546
2556
}
2547
2557
}
2548
2558
2549
2559
impl < T : DepTrackingHash > DepTrackingHash for Vec < T > {
2550
- fn hash ( & self , hasher : & mut DefaultHasher , error_format : ErrorOutputType ) {
2560
+ fn hash (
2561
+ & self ,
2562
+ hasher : & mut DefaultHasher ,
2563
+ error_format : ErrorOutputType ,
2564
+ for_crate_hash : bool ,
2565
+ ) {
2551
2566
Hash :: hash ( & self . len ( ) , hasher) ;
2552
2567
for ( index, elem) in self . iter ( ) . enumerate ( ) {
2553
2568
Hash :: hash ( & index, hasher) ;
2554
- DepTrackingHash :: hash ( elem, hasher, error_format) ;
2569
+ DepTrackingHash :: hash ( elem, hasher, error_format, for_crate_hash) ;
2570
+ }
2571
+ }
2572
+ }
2573
+
2574
+ impl DepTrackingHash for OutputTypes {
2575
+ fn hash (
2576
+ & self ,
2577
+ hasher : & mut DefaultHasher ,
2578
+ error_format : ErrorOutputType ,
2579
+ for_crate_hash : bool ,
2580
+ ) {
2581
+ Hash :: hash ( & self . 0 . len ( ) , hasher) ;
2582
+ for ( key, val) in & self . 0 {
2583
+ DepTrackingHash :: hash ( key, hasher, error_format, for_crate_hash) ;
2584
+ if !for_crate_hash {
2585
+ DepTrackingHash :: hash ( val, hasher, error_format, for_crate_hash) ;
2586
+ }
2555
2587
}
2556
2588
}
2557
2589
}
@@ -2561,13 +2593,14 @@ crate mod dep_tracking {
2561
2593
sub_hashes : BTreeMap < & ' static str , & dyn DepTrackingHash > ,
2562
2594
hasher : & mut DefaultHasher ,
2563
2595
error_format : ErrorOutputType ,
2596
+ for_crate_hash : bool ,
2564
2597
) {
2565
2598
for ( key, sub_hash) in sub_hashes {
2566
2599
// Using Hash::hash() instead of DepTrackingHash::hash() is fine for
2567
2600
// the keys, as they are just plain strings
2568
2601
Hash :: hash ( & key. len ( ) , hasher) ;
2569
2602
Hash :: hash ( key, hasher) ;
2570
- sub_hash. hash ( hasher, error_format) ;
2603
+ sub_hash. hash ( hasher, error_format, for_crate_hash ) ;
2571
2604
}
2572
2605
}
2573
2606
}
0 commit comments