Skip to content

Non hashable args like fdebug-prefix-map & related #2409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/compiler/c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1435,6 +1435,13 @@ static CACHED_ENV_VARS: Lazy<HashSet<&'static OsStr>> = Lazy::new(|| {
.collect()
});

const NON_HASHABLE_ARGS: &[&str] = &[
"-fdebug-prefix-map",
"-fmacro-prefix-map",
"-ffile-prefix-map",
"-fdebug-compilation-dir",
];

/// Compute the hash key of `compiler` compiling `preprocessor_output` with `args`.
pub fn hash_key(
compiler_digest: &str,
Expand All @@ -1453,7 +1460,13 @@ pub fn hash_key(
m.update(&[plusplus as u8]);
m.update(CACHE_VERSION);
m.update(language.as_str().as_bytes());
for arg in arguments {
'arg_loop: for arg in arguments {
for non_hashable in NON_HASHABLE_ARGS {
if arg.to_string_lossy().starts_with(non_hashable) {
// Skip non-hashable arguments.
continue 'arg_loop;
}
}
arg.hash(&mut HashToDigest { digest: &mut m });
}
for hash in extra_hashes {
Expand Down Expand Up @@ -1567,6 +1580,30 @@ mod test {
);
}

#[test]
fn test_hash_key_non_hashable_args() {
let digest = "abcd";
const PREPROCESSED: &[u8] = b"hello world";

let args = ovec!["arg1", "arg2", "arg3"];
let mut args_with_non_hashable: Vec<OsString> =
NON_HASHABLE_ARGS.iter().map(OsString::from).collect();

args_with_non_hashable.extend(args.clone());
assert_eq!(
hash_key(digest, Language::C, &args, &[], &[], PREPROCESSED, false),
hash_key(
digest,
Language::C,
&args_with_non_hashable,
&[],
&[],
PREPROCESSED,
false
)
);
}

#[test]
fn test_hash_key_preprocessed_content_differs() {
let args = ovec!["a", "b", "c"];
Expand Down
Loading