-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Tidy: Allow inline tests in the compiler #110619
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
Do you have a pointer to what fixed the reason this was done? I believe cargo without this will recompile the base library and then compile the tests even if only the tests are changed. I'm not aware of what has changed to make that not true (though would love to be pleasantly surprised!) |
@Mark-Simulacrum hm, I'm not sure, but I do not see how #[cfg(test)]
mod tests { /* ... */ } and #[cfg(test)]
mod tests; might be different, iirc rustc expands the latter into the former. #61097 looked like it was caused by the migration from unit tests to UI tests, which I thought was complete, but now re-reading it, maybe there is a problem with incremental re-builds 🤔 |
#[cfg(test)]
mod tests; is different in that during a normal build, Cargo will ignore any changes to the |
I see... This is weird though, |
That seems like an extremely difficult thing to accomplish. Cargo needs some way to very quickly determine if a file has changed and should trigger a rebuild. I can only imagine that to do intra-file change detection would require parsing the entire crate and doing name resolution and expansion to determine if only content within some |
@ehuss I'd imagine that the compiler output after a change under From your words I assume that |
It might be feasible to hash and compare the outputs, but that might require a significant rewrite of how Cargo does change tracking. It also assumes a few factors, such as reproducible builds, that the source changes don't materially change span locations, and that Cargo knows all the outputs from rustc (which it currently doesn't, it just guesses in most cases). |
Note that even if we solved the reverse dependency problem, we would still do ~2x the work since we'd compile both the cfg=test crate and the non-cfg=test crate (just to detect it hasn't changed). |
I'm going to close this since it would regress compile times today. Feel free to reopen if you want to add a comment documenting why this change exists. If you want to pursue changing cargo's cache invalidation algorithm, it sounds like that would need fairly close consultation with the cargo team and I think Zulip is a better place for that than this PR. |
It seems like the original reason for this check is irrelevant now, so let's just remove it.
TL;DR: this allows using
#[cfg(test)] mod tests { ... }
(inline module instead ofmod tests;
)