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
Greatly speed up doctests by compiling compatible doctests in one file #123974
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
bff1867
to
2188a37
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
48e04f4
to
4c766eb
Compare
Seems like where there are enough tests, |
This comment has been minimized.
This comment has been minimized.
7796f3f
to
df03145
Compare
This comment has been minimized.
This comment has been minimized.
df03145
to
b4b72ca
Compare
This comment has been minimized.
This comment has been minimized.
b4b72ca
to
76c9ae6
Compare
This comment has been minimized.
This comment has been minimized.
Some changes occurred in run-make tests. cc @jieyouxu |
This comment has been minimized.
This comment has been minimized.
There should probably be some opt out from this merging. There are numerous reasons why two pieces of code may cause issues when combined together (they should compete for some common resource, in general, and that is not always detectable by a compiler). |
How does this affect env_logger? |
c7e80be
to
b3261d5
Compare
It fails in multiple tests:
I implemented a fallback in case compilation fails. I could do the same for failing tests. Like that, we can support both current doctests with shared context and others who don't have have this shared context issue can enjoy having doctests running much faster. What do you think? EDIT: Another solution would be to add a new codeblock attribute like "standalone" to say that a doctest should not be combined with others, but I'm not a big fan of this approach. |
That only helps with spurious failure. Spurious success is an even worse problem, if a test case accidentally relies on a global resource that another test set up. Any kind of merging has this problem, but it gets worse if the merging only happens sometimes. This is also a problem with |
The logic currently is as follows: we merge tests, if the compilation of the combined tests failed, we fallback to the current behaviour. One thing I thought though: we could spawn a new process for each test. That would prevent them from using "in program" common resources.
Yes it's the current issue with |
The troublesome possibility that I'm thinking of is:
|
What about changing the default way to run doctests starting the 2024 edition? EDIT: With a new |
That's better than implicit fallbacks. |
Agreed. Should I add the new |
☔ The latest upstream changes (presumably #125120) made this pull request unmergeable. Please resolve the merge conflicts. |
34ebc92
to
9f1abb4
Compare
Fixed merge conflict (it was in the |
☔ The latest upstream changes (presumably #125254) made this pull request unmergeable. Please resolve the merge conflicts. |
…valid code for combined doctests
…pdate associated test to check both combined and non-combined doctests
To do so, AST error detection was improved in order to not filter out too many doctests.
9f1abb4
to
2e3c2aa
Compare
Fixed merge conflict. |
Fixes #75341.
I split the changes as much as possible to make it as easy as possible to review (even though it's a huge lot of code changes...).
The following tests are not included into the combined doctests:
compile_fail
#![no_std]
test_harness
--show-output
(because the output is nicer without the extra code surrounding it)Everything else is merged into one file. If this one file fails to compile, we go back to the current strategy: compile each doctest separately.
Because of the
edition
codeblock attribute, I couldn't make them all into one file directly so I grouped them by edition, but it should be pretty anecdotic.Now the interesting part, I ran it on a few crates and here are the results (with
--doc
to only include doctests):r? @notriddle