-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Track whether module declarations are inline (fixes #12590) #52319
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Woops, forgot to run tidy |
src/libsyntax/parse/parser.rs
Outdated
self.eval_src_mod(path, directory_ownership, id.to_string(), id_span)?; | ||
// Record that we fetched the mod from an external file | ||
module.inline = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a relatively minor point, but: You might as well move this line into the body of fn eval_src_mod
, right? We might as well have it fully encapsulate setting up all the state related to reading a file as a module, rather than leaving this one step for its caller...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was afraid maybe someone would call eval_src_mod
from somewhere else, but later I discovered this is the only place it is called.
A more important issue: I actually am in the camp that regards the current behavior as a feature, not a bug. I like getting a single file with the whole module tree in it... Having said that, I guess I'd be okay if the semantics of "one file with whole module tree" were restricted to Can you tell me off hand how your PR handles
|
Good point, I'll add a test for expanded to verify that it works for expanded. |
@pnkfelix I made the behavior as you described, but for some reason the test suite doesn't pick it up. I tried to debug by adding printlines to the parser, but that breaks compilation of stage0, and for some reason It's hard to keep a nice development pace when it's interspersed by these 15 minute+ compilation bouts, I spent 4 hours on finding out that my println!'s were breaking the stage0 compilation, just because I get distracted between invocations and go do other tasks. Do you have some trick to be productive while working on rustc? |
@tinco I'll check out your repo and take a look. Out of curiosity, in your attempt to instrument the code, why did you use |
@tinco I think I see what you mean: when I run I'll keep digging for a bit. Not sure whether this is some |
OH! The That's why, for example, if you add
I don't even know if we specify how So, what now?! We can either:
|
I bet the reason that |
If you want to try to tackle changing rust/src/tools/compiletest/src/runtest.rs Line 393 in 025e04e
The iterative loop I described is starts here: rust/src/tools/compiletest/src/runtest.rs Line 416 in 025e04e
The actual invocations of the compiler are driven by the calls to rust/src/tools/compiletest/src/runtest.rs Line 424 in 025e04e
... whose source code is right below, here: rust/src/tools/compiletest/src/runtest.rs Line 498 in 025e04e
and you can see the spot where we are feeding in rust/src/tools/compiletest/src/runtest.rs Line 503 in 025e04e
So I might suggest changing |
In fact, after writing up those instructions above, I figured it would be easiest if I just went ahead and made the necessary change to your PR myself. |
@bors r+ |
📌 Commit fcbb3dd has been approved by |
hi @pnkfelix thanks a lot for chiming in on this PR! I would've probably taken a couple days to figure out how compiletest worked :) I used println! instead of debug! because I didn't know/forgot it existed :P I had a 2 year break from rust, and although I'm still ok with the general idea and semantics, I'm a bit rusty (hehe) with many workflow details. Working on these compiler bugs is fun because I read through loads of rust and get back into it :) I found this bug just by filtering a little bit and sorting on oldest first, and looking at the first one that didn't have many people theorizing on what to do. If you know of any other bug that's ready for someone to dive in to that has slightly more relevance to the real world than this one please let me know! |
⌛ Testing commit fcbb3dd with merge bc234f177bb2202a1a56d62c09dffb3f4737e0a0... |
💔 Test failed - status-appveyor |
Alright, so there's two bugs at play here. The first is that for some reason for this The second is that the diff thingy hangs on windows when the two files that are compared are too large it seems. I have narrowed the test case down to three test functions, and removing either of them leads to a test that fails, instead of hanging. It might be that this is actually also the case on linux, but that we simply haven't seen it fail this way yet on linux. |
Hmm no, the line ending thing was a red herring. I added a newline at the end of the file I'm testing with, and now if I remove any of the three tests I have left the suite passes. So there's something fishy going on with the comparison, regardless of whether it's going to fail or not. This is the file I've made that hangs on Windows, and if you remove any of the three test functions it passes:
|
I narrowed it down to where just removing 1 character makes it pass. The character can be inside a comment. |
BAM! I got it :D so the thing was, @pnkfelix added this option to read source from a file instead of reading it from standard in. This works, but for some reason the variable that's supposed to hold the string to be written to standard in is still filled. This is no problem on Linux and OSX, because when you write to the stdin of a command that's not reading any stdin, it just gets infinitely buffered or thrown away or something. On Windows however there is apparently only a very small buffer for stdin, so when you write a large file to the stdin of a command that's not reading from stdin (even though that command has exited) it blocks indefinitely! So the fix is to not write to stdin, if we told it to read from a file. It reveals a different bug though, why do we pass in a populated src, if we're trying to read from a file? I'll see what's going on, maybe that's a bug as well. |
…en they *have* to. This allows us to test expansion of files that use `mod foo;` syntax.
Ping from triage @pnkfelix: It looks like this PR is ready for your review. |
@bors r+ |
📌 Commit b985e91 has been approved by |
Track whether module declarations are inline (fixes #12590) To track whether module declarations are inline I added a field `inline: bool` to `ast::Mod`. The main use case is for pretty to know whether it should render the items associated with the module, but perhaps there are use cases for this information to not be forgotten in the AST.
yessss.... 🥁 |
☀️ Test successful - status-appveyor, status-travis |
Nice, this PR will make rustfmt's life a bit easier 🙌 |
To track whether module declarations are inline I added a field
inline: bool
toast::Mod
. The main use case is for pretty to know whether it should render the items associated with the module, but perhaps there are use cases for this information to not be forgotten in the AST.