Skip to content

Conversation

@zetanumbers
Copy link
Contributor

@zetanumbers zetanumbers commented Oct 30, 2025

Fixes debug assertion failure as described in #141540 (comment)

Essentially failure happens during the race while decoding one ExpnId from different threads. This ICE doesn't happen with single threaded thread_pool due to early return within decode_expn_id with the same condition:

if let Some(expn_id) = ExpnId::from_hash(hash) {
return expn_id;
}

However I believe this race does not hurt because register_expn_id is pretty much idempotent:

pub fn register_expn_id(
krate: CrateNum,
local_id: ExpnIndex,
data: ExpnData,
hash: ExpnHash,
) -> ExpnId {
debug_assert!(data.parent == ExpnId::root() || krate == data.parent.krate);
let expn_id = ExpnId { krate, local_id };
HygieneData::with(|hygiene_data| {
let _old_data = hygiene_data.foreign_expn_data.insert(expn_id, data);
let _old_hash = hygiene_data.foreign_expn_hashes.insert(expn_id, hash);
debug_assert!(_old_hash.is_none() || _old_hash == Some(hash));
let _old_id = hygiene_data.expn_hash_to_expn_id.insert(hash, expn_id);
debug_assert!(_old_id.is_none() || _old_id == Some(expn_id));
});
expn_id
}

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 30, 2025
@rustbot
Copy link
Collaborator

rustbot commented Oct 30, 2025

r? @nnethercote

rustbot has assigned @nnethercote.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@Kivooeo
Copy link
Member

Kivooeo commented Oct 30, 2025

@nnethercote
Copy link
Contributor

Fixes #141540 (comment)

I'm surprised you're seeing a debug assertion failure. Did you build your own compiler?

As for the fix, it seems plausible, but I'm not familiar with this code. @Zoxc or @Mark-Simulacrum, can you evaluate this change?

@zetanumbers
Copy link
Contributor Author

I'm surprised you're seeing a debug assertion failure. Did you build your own compiler?

Yes, I did. I am trying to solve #141540, it is the most active A-parallel-compiler issue. Got this debug assertion failure while trying to reproduce that bug, so I've investigated it.

I usually keep rust.debug = true set in my bootstrap.toml file to make sure my code is good. But even if I turned it off, strangely that debug assertion kept failing even after ./x clean. Checked everything, still no clue. But anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

4 participants