@@ -31,6 +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 ;
34
35
use std:: iter:: { self , FromIterator } ;
35
36
use std:: path:: { Path , PathBuf } ;
36
37
use std:: str:: { self , FromStr } ;
@@ -325,12 +326,11 @@ impl Default for TrimmedDefPaths {
325
326
326
327
/// Use tree-based collections to cheaply get a deterministic `Hash` implementation.
327
328
/// *Do not* switch `BTreeMap` out for an unsorted container type! That would break
328
- /// dependency tracking for command-line arguments.
329
- #[ derive( Clone , Hash , Debug ) ]
329
+ /// dependency tracking for command-line arguments. Also only hash keys, since tracking
330
+ /// should only depend on the output types, not the paths they're written to.
331
+ #[ derive( Clone , Debug , Hash ) ]
330
332
pub struct OutputTypes ( BTreeMap < OutputType , Option < PathBuf > > ) ;
331
333
332
- impl_stable_hash_via_hash ! ( OutputTypes ) ;
333
-
334
334
impl OutputTypes {
335
335
pub fn new ( entries : & [ ( OutputType , Option < PathBuf > ) ] ) -> OutputTypes {
336
336
OutputTypes ( BTreeMap :: from_iter ( entries. iter ( ) . map ( |& ( k, ref v) | ( k, v. clone ( ) ) ) ) )
@@ -2426,8 +2426,8 @@ crate mod dep_tracking {
2426
2426
use super :: LdImpl ;
2427
2427
use super :: {
2428
2428
CFGuard , CrateType , DebugInfo , ErrorOutputType , InstrumentCoverage , LinkerPluginLto ,
2429
- LtoCli , OptLevel , OutputTypes , Passes , SourceFileHashAlgorithm , SwitchWithOptPath ,
2430
- SymbolManglingVersion , TrimmedDefPaths ,
2429
+ LtoCli , OptLevel , OutputType , OutputTypes , Passes , SourceFileHashAlgorithm ,
2430
+ SwitchWithOptPath , SymbolManglingVersion , TrimmedDefPaths ,
2431
2431
} ;
2432
2432
use crate :: lint;
2433
2433
use crate :: options:: WasiExecModel ;
@@ -2443,25 +2443,35 @@ crate mod dep_tracking {
2443
2443
use std:: path:: PathBuf ;
2444
2444
2445
2445
pub trait DepTrackingHash {
2446
- 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
+ ) ;
2447
2452
}
2448
2453
2449
2454
macro_rules! impl_dep_tracking_hash_via_hash {
2450
2455
( $( $t: ty) ,+ $( , ) ?) => { $(
2451
2456
impl DepTrackingHash for $t {
2452
- fn hash( & self , hasher: & mut DefaultHasher , _: ErrorOutputType ) {
2457
+ fn hash( & self , hasher: & mut DefaultHasher , _: ErrorOutputType , _for_crate_hash : bool ) {
2453
2458
Hash :: hash( self , hasher) ;
2454
2459
}
2455
2460
}
2456
2461
) +} ;
2457
2462
}
2458
2463
2459
2464
impl < T : DepTrackingHash > DepTrackingHash for Option < T > {
2460
- 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
+ ) {
2461
2471
match self {
2462
2472
Some ( x) => {
2463
2473
Hash :: hash ( & 1 , hasher) ;
2464
- DepTrackingHash :: hash ( x, hasher, error_format) ;
2474
+ DepTrackingHash :: hash ( x, hasher, error_format, for_crate_hash ) ;
2465
2475
}
2466
2476
None => Hash :: hash ( & 0 , hasher) ,
2467
2477
}
@@ -2491,7 +2501,6 @@ crate mod dep_tracking {
2491
2501
LtoCli ,
2492
2502
DebugInfo ,
2493
2503
UnstableFeatures ,
2494
- OutputTypes ,
2495
2504
NativeLib ,
2496
2505
NativeLibKind ,
2497
2506
SanitizerSet ,
@@ -2505,18 +2514,24 @@ crate mod dep_tracking {
2505
2514
SourceFileHashAlgorithm ,
2506
2515
TrimmedDefPaths ,
2507
2516
Option <LdImpl >,
2517
+ OutputType ,
2508
2518
) ;
2509
2519
2510
2520
impl < T1 , T2 > DepTrackingHash for ( T1 , T2 )
2511
2521
where
2512
2522
T1 : DepTrackingHash ,
2513
2523
T2 : DepTrackingHash ,
2514
2524
{
2515
- 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
+ ) {
2516
2531
Hash :: hash ( & 0 , hasher) ;
2517
- DepTrackingHash :: hash ( & self . 0 , hasher, error_format) ;
2532
+ DepTrackingHash :: hash ( & self . 0 , hasher, error_format, for_crate_hash ) ;
2518
2533
Hash :: hash ( & 1 , hasher) ;
2519
- DepTrackingHash :: hash ( & self . 1 , hasher, error_format) ;
2534
+ DepTrackingHash :: hash ( & self . 1 , hasher, error_format, for_crate_hash ) ;
2520
2535
}
2521
2536
}
2522
2537
@@ -2526,22 +2541,49 @@ crate mod dep_tracking {
2526
2541
T2 : DepTrackingHash ,
2527
2542
T3 : DepTrackingHash ,
2528
2543
{
2529
- 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
+ ) {
2530
2550
Hash :: hash ( & 0 , hasher) ;
2531
- DepTrackingHash :: hash ( & self . 0 , hasher, error_format) ;
2551
+ DepTrackingHash :: hash ( & self . 0 , hasher, error_format, for_crate_hash ) ;
2532
2552
Hash :: hash ( & 1 , hasher) ;
2533
- DepTrackingHash :: hash ( & self . 1 , hasher, error_format) ;
2553
+ DepTrackingHash :: hash ( & self . 1 , hasher, error_format, for_crate_hash ) ;
2534
2554
Hash :: hash ( & 2 , hasher) ;
2535
- DepTrackingHash :: hash ( & self . 2 , hasher, error_format) ;
2555
+ DepTrackingHash :: hash ( & self . 2 , hasher, error_format, for_crate_hash ) ;
2536
2556
}
2537
2557
}
2538
2558
2539
2559
impl < T : DepTrackingHash > DepTrackingHash for Vec < T > {
2540
- 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
+ ) {
2541
2566
Hash :: hash ( & self . len ( ) , hasher) ;
2542
2567
for ( index, elem) in self . iter ( ) . enumerate ( ) {
2543
2568
Hash :: hash ( & index, hasher) ;
2544
- 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
+ }
2545
2587
}
2546
2588
}
2547
2589
}
@@ -2551,13 +2593,14 @@ crate mod dep_tracking {
2551
2593
sub_hashes : BTreeMap < & ' static str , & dyn DepTrackingHash > ,
2552
2594
hasher : & mut DefaultHasher ,
2553
2595
error_format : ErrorOutputType ,
2596
+ for_crate_hash : bool ,
2554
2597
) {
2555
2598
for ( key, sub_hash) in sub_hashes {
2556
2599
// Using Hash::hash() instead of DepTrackingHash::hash() is fine for
2557
2600
// the keys, as they are just plain strings
2558
2601
Hash :: hash ( & key. len ( ) , hasher) ;
2559
2602
Hash :: hash ( key, hasher) ;
2560
- sub_hash. hash ( hasher, error_format) ;
2603
+ sub_hash. hash ( hasher, error_format, for_crate_hash ) ;
2561
2604
}
2562
2605
}
2563
2606
}
0 commit comments