-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
[WIP] Allow global_allocators in submodules #49320
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
☔ The latest upstream changes (presumably #49279) made this pull request unmergeable. Please resolve the merge conflicts. |
I could review this if forced, but I'm not super familiar with what's going on here. @alexcrichton -- are you the right person? |
Sure yeah I don't mind reviewing this. @mark-i-m mind explaning a bit what the change here is doing? |
@alexcrichton Thanks! The problem: Proposed solution: Rather than hard-coding |
Ok thanks! I was actually the original author of all this code so I'm mostly curious in the delta from the previous instantiation :) I think, though that |
TBH, I don't really know that much about how hygiene works in macro expansion (the rustc-guide chapter has yet to be written). Do you have any hints of how to get started? |
I'm not so sure myself (hence why this has never been fixed), but AFAIK it's all tied to identifiers/spans. It may not be necessary at all to even use |
I get the following error:
|
Ah if that doesn't work then it may mean that a special span needs to be used for |
Unfortunately, I don't know enough about name resolution or hygiene to know how to do that. Do you have any suggested resources for learning more? Unfortunately, the rustc-guide section is a bit incomplete. |
Hm ok, an alternative is to change how things are expanded. Currently a |
Thanks @alexcrichton! I will give that a try. Quick question: What does the following line (112) do exactly? let module = f.cx.monotonic_expander().fold_item(module).pop().unwrap(); |
A good question! I'm... not actually sure. I may have copy/pasted that from somewhere else originally, and it may be safe to remove. |
It seems that we have the same hygiene problems with
I feel like (2) already exists but we are doing it wrong? |
Ok, I think I'm onto something: when we create the new I also set the I am now getting "no |
Sorry I'm getting pretty mixed up in the diff right now, call the rustfmt changes get backed out for a future run later? |
This in general sounds plausible though! Want to add a test to make sure if it passes CI it's good to go? |
Sorry, I will pull out rustfmt and comments to another PR... It doesn't work yet, but if I'm right, then it might make like easier. I have a UI test I've been using locally. I will add it too... I'm on mobile at the moment, but when I get to my computer, I will do this... |
Also, I believe that last commit is the only one with any actual changes (for the moment)... Will update a bit later... |
@alexcrichton I have factored out the formatting and commenting into PR #49969. There are now two commits in this PR. The first makes the change to use the call-site for hygiene. The second adds a test for allocators in submodules (it should fail). |
Your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. 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 |
Your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem. 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 |
@alexcrichton Sorry for the delay, I was in a bit of a time crunch. Let me check. (also, I rebased so the branch doesn't fall too far behind, but there are no changes, and it still doesn't work) |
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 |
@alexcrichton Ok, so here's what I have. If I don't generate an If I generate an $ cargo +stage1 expand
Compiling my_test v0.1.0 (file:///tmp/my_test)
warning: ignoring --out-dir flag due to -o flag
warning: ignoring -C extra-filename flag due to -o flag
error[E0463]: can't find crate for `core`
--> src/main.rs:21:5
|
21 | static MY_HEAP: MyAlloc = MyAlloc;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
error: aborting due to previous error
For more information about this error, try `rustc --explain E0463`.
error: Could not compile `my_test`.
To learn more, run the command again with --verbose.
cat: /tmp/cargo-expand.UUz20ChlwC2T/expanded: No such file or directory |
@alexcrichton: Do you have any ideas about the error above? |
Ah unfortunately I don't recognize the error nor know the best way to fix it :( |
Hmm... ok so what would be the best path to take? I'm not really sure that I have the knowledge to proceed productively on this issue, so it might be best to leave this for someone else? IMHO, we should disallow allocators in submodules for now, making it a hard error. That would unblock stabilization, right? Then, we should leave notes in #44113 for the next intrepid explorer? |
Yes until this is fixed I think it's fine to just disallow this with a hard error |
Ok, I will try to implement that this week. Would that be done by just keep track in the Folder if we ever try to fold a submodule? I will also leaves some comments on the issue about some of the things we tried. |
I believe so yeah that should work out well enough |
Ping from triage, @mark-i-m ! Will you have time to revisit this soon? |
@shepmaster Sorry, I'm without a computer for the next few days. If you want to close this to keep the issue tracker clean, feel free. I will try to do it soon. |
Hmm... I actually did get a chance to revisit this (unexpectedly). I pushed what I have so far. I'm getting the following errors:
I haven't really gotten to investigate further but my guess is that imported crates are treated like submodules? @alexcrichton Any ideas? |
Ugh, you have to open a new PR since you force-pushed the branch... |
Really? Why? I do that every time I rebase |
GitHub oddities. Once a PR is closed (which happened above) it cannot be re-opened once there has been a force push to the underlying branch. |
Oh, good to know... |
Prohibit `global_allocator` in submodules Background: #44113 is caused by weird interactions with hygiene. Hygiene is hard. After a lot of playing around, we decided that the best path forward would be to prohibit `global_allocator`s from being in submodules for now. When somebody gets it working, we can re-enable it. This PR contains the following - Some hygiene "fixes" -- things I suspect are the correct thing to do that will make life easier in the future. This includes using call_site hygiene for the generated module and passing the correct crate name to the expansion config. - Comments and minor formatting fixes - Some debugging code - Code to prohibit `global_allocator` in submodules - Test checking that the proper error occurs. cc #44113 #49320 #51241 r? @alexcrichton
First commit is rustfmt.
Is this even the right approach? Right now it's just breaking everything...
Fix #44113