@@ -31,6 +31,7 @@ use std::collections::btree_map::{
3131} ;
3232use std:: collections:: { BTreeMap , BTreeSet } ;
3333use std:: fmt;
34+ use std:: hash:: Hash ;
3435use std:: iter:: { self , FromIterator } ;
3536use std:: path:: { Path , PathBuf } ;
3637use std:: str:: { self , FromStr } ;
@@ -325,12 +326,11 @@ impl Default for TrimmedDefPaths {
325326
326327/// Use tree-based collections to cheaply get a deterministic `Hash` implementation.
327328/// *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 ) ]
330332pub struct OutputTypes ( BTreeMap < OutputType , Option < PathBuf > > ) ;
331333
332- impl_stable_hash_via_hash ! ( OutputTypes ) ;
333-
334334impl OutputTypes {
335335 pub fn new ( entries : & [ ( OutputType , Option < PathBuf > ) ] ) -> OutputTypes {
336336 OutputTypes ( BTreeMap :: from_iter ( entries. iter ( ) . map ( |& ( k, ref v) | ( k, v. clone ( ) ) ) ) )
@@ -2426,8 +2426,8 @@ crate mod dep_tracking {
24262426 use super :: LdImpl ;
24272427 use super :: {
24282428 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 ,
24312431 } ;
24322432 use crate :: lint;
24332433 use crate :: options:: WasiExecModel ;
@@ -2443,25 +2443,35 @@ crate mod dep_tracking {
24432443 use std:: path:: PathBuf ;
24442444
24452445 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+ ) ;
24472452 }
24482453
24492454 macro_rules! impl_dep_tracking_hash_via_hash {
24502455 ( $( $t: ty) ,+ $( , ) ?) => { $(
24512456 impl DepTrackingHash for $t {
2452- fn hash( & self , hasher: & mut DefaultHasher , _: ErrorOutputType ) {
2457+ fn hash( & self , hasher: & mut DefaultHasher , _: ErrorOutputType , _for_crate_hash : bool ) {
24532458 Hash :: hash( self , hasher) ;
24542459 }
24552460 }
24562461 ) +} ;
24572462 }
24582463
24592464 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+ ) {
24612471 match self {
24622472 Some ( x) => {
24632473 Hash :: hash ( & 1 , hasher) ;
2464- DepTrackingHash :: hash ( x, hasher, error_format) ;
2474+ DepTrackingHash :: hash ( x, hasher, error_format, for_crate_hash ) ;
24652475 }
24662476 None => Hash :: hash ( & 0 , hasher) ,
24672477 }
@@ -2491,7 +2501,6 @@ crate mod dep_tracking {
24912501 LtoCli ,
24922502 DebugInfo ,
24932503 UnstableFeatures ,
2494- OutputTypes ,
24952504 NativeLib ,
24962505 NativeLibKind ,
24972506 SanitizerSet ,
@@ -2505,18 +2514,24 @@ crate mod dep_tracking {
25052514 SourceFileHashAlgorithm ,
25062515 TrimmedDefPaths ,
25072516 Option <LdImpl >,
2517+ OutputType ,
25082518 ) ;
25092519
25102520 impl < T1 , T2 > DepTrackingHash for ( T1 , T2 )
25112521 where
25122522 T1 : DepTrackingHash ,
25132523 T2 : DepTrackingHash ,
25142524 {
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+ ) {
25162531 Hash :: hash ( & 0 , hasher) ;
2517- DepTrackingHash :: hash ( & self . 0 , hasher, error_format) ;
2532+ DepTrackingHash :: hash ( & self . 0 , hasher, error_format, for_crate_hash ) ;
25182533 Hash :: hash ( & 1 , hasher) ;
2519- DepTrackingHash :: hash ( & self . 1 , hasher, error_format) ;
2534+ DepTrackingHash :: hash ( & self . 1 , hasher, error_format, for_crate_hash ) ;
25202535 }
25212536 }
25222537
@@ -2526,22 +2541,49 @@ crate mod dep_tracking {
25262541 T2 : DepTrackingHash ,
25272542 T3 : DepTrackingHash ,
25282543 {
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+ ) {
25302550 Hash :: hash ( & 0 , hasher) ;
2531- DepTrackingHash :: hash ( & self . 0 , hasher, error_format) ;
2551+ DepTrackingHash :: hash ( & self . 0 , hasher, error_format, for_crate_hash ) ;
25322552 Hash :: hash ( & 1 , hasher) ;
2533- DepTrackingHash :: hash ( & self . 1 , hasher, error_format) ;
2553+ DepTrackingHash :: hash ( & self . 1 , hasher, error_format, for_crate_hash ) ;
25342554 Hash :: hash ( & 2 , hasher) ;
2535- DepTrackingHash :: hash ( & self . 2 , hasher, error_format) ;
2555+ DepTrackingHash :: hash ( & self . 2 , hasher, error_format, for_crate_hash ) ;
25362556 }
25372557 }
25382558
25392559 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+ ) {
25412566 Hash :: hash ( & self . len ( ) , hasher) ;
25422567 for ( index, elem) in self . iter ( ) . enumerate ( ) {
25432568 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+ }
25452587 }
25462588 }
25472589 }
@@ -2551,13 +2593,14 @@ crate mod dep_tracking {
25512593 sub_hashes : BTreeMap < & ' static str , & dyn DepTrackingHash > ,
25522594 hasher : & mut DefaultHasher ,
25532595 error_format : ErrorOutputType ,
2596+ for_crate_hash : bool ,
25542597 ) {
25552598 for ( key, sub_hash) in sub_hashes {
25562599 // Using Hash::hash() instead of DepTrackingHash::hash() is fine for
25572600 // the keys, as they are just plain strings
25582601 Hash :: hash ( & key. len ( ) , hasher) ;
25592602 Hash :: hash ( key, hasher) ;
2560- sub_hash. hash ( hasher, error_format) ;
2603+ sub_hash. hash ( hasher, error_format, for_crate_hash ) ;
25612604 }
25622605 }
25632606}
0 commit comments