-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Remove use of decl_macro by using a different hack. #964
Conversation
I think that this is intended, pr that implemented this #rust-lang/rust#56759 was reviewed by many rust team members. |
0376829
to
5867389
Compare
As an alternative to random generation, we could hash the source file path + line + column of a function available via |
Yes!
If the |
Awesome, thanks for the confirmation!
The proc macro crate is actually still 2015 edition. I will try all the combinations with a minimal test case to double check, and I'll come back to this PR after #1013 is taken care of. |
a0003ce
to
5212107
Compare
5212107
to
e8268c1
Compare
I think this is ready for a review. I'm not happy with the way the documentation looks - I wanted the real, ugly-named macro to be |
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 phenomenal! I'm so excited to get rid of decl_macro
!
My biggest concern is that we've increased our use of unstable APIs from proc_macro_span
in the generation of the pseudo-random hash. In particular, through the use of SourceFile
, start()
, and source_file()
. Why isn't hashing the function name sufficient? Two functions in the same scope must necessary have different function names. Does doing this result in poor error messages?
More procedurally, I'd like to see this PR split into two commits: one to implement the hack, and the other to remove the decl_macro
feature flag everywhere.
core/codegen/tests/compile-test.rs
Outdated
@@ -85,6 +85,7 @@ fn run_mode(mode: &'static str, path: &'static str) { | |||
config.clean_rmeta(); | |||
|
|||
config.target_rustcflags = Some([ | |||
"--edition=2018".into(), |
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.
Do we actually need this? This is more of a curiosity level question than a "change this" comment.
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.
No, it's not needed anymore. This might have been because rocket_codegen
was itself a 2015 edition crate when I started working on this, and edition hygiene is a bit wonky sometimes. I'll make sure we have appropriate test coverage.
Which macros are you referring to? I don't see any issues with the docs, but I may be missing or, or I may be expecting to see neither macro. |
The same function name might be used in two different modules, and two macros with I only saw three ways out: 1) get rid of the Unfortunately these all have downsides: 1) means we have to reexport with a
In the past a macro was visible in the docs for the crate the routes were defined in (maybe only if the route was |
e8268c1
to
415e88b
Compare
Got it. Thanks for explaining this.
Why does the random part need to be deterministic? Don't we simply need it to be unique? If so, a |
It's more of an inconvenience - it makes reproducible builds impossible, assuming a reproducible build is possible already.
I am really nervous about doing that because of incremental or parallel compilation: I'm afraid we would get name collisions because of a reused "_1" from a previous build and a new "_1" from a current build. If we can be guaranteed not to run into that kind of problem now (or in the future), I would be on board with this. |
I don't think this has any effect on reproducibility. Macro names should/would not be part of the compiled binary.
I would agree, though I've inquired about this in the past and learned that a single proc macro is "guaranteed" not to be run in parallel with itself. That is, the static would work as desired. This is, of course, simply an ad-hoc conversation I had (with eddyb), though I do believe existing proc-macros depend on this behavior for correctness. Nevertheless, it isn't documented or specified, so I understand your concern. We could either ask for this to be specified or do something else, though I feel like trading off one bit of unstableness for another isn't gaining us much. |
It sounds like our best options are to either get a guarantee that any time a given |
The generated helper macros for `uri!` are now re-exports of regular macro_rules macros, made possible by the "uniform paths" feature.
Also removes one internal usage in 'core/codegen/tests/typed-uris.rs'.
415e88b
to
b405dbe
Compare
Did you take a look at what causes the error messages to be reversed? I'm concerned that this will result in error messages being more confusing, due to ordering, for users. I think we can do this using the file/line/column based approach for now. We'll need something that will definitely be stabilized eventually; perhaps that's this interface, or something entirely different (say, |
I'm going to merge this now, but I would like to know if we can get error messages back to the original ordering. |
Awesome. I will try to reproduce the error message reversal with a reduced test case. And I believe the credit for pointing out this was possible goes to @macpp! |
I've found some kind of a pattern here. The errors always appear in this sequence: all of category 1, all of category 2 in reverse order, and finally all of category 3. This makes some sense: category 1 errors are emitted in the invocation of Switching the macro generation to |
Unfortunately this changes name resolution. If a route wants to accept a |
This removes the use of
decl_macro
in generated routes, removing it from the list of unstable features rocket depends on. This is done according to the strategy outlined in #19 (comment), which became possible whenuniform_paths
was implemented and/or stabilized.However, it requires that crates that use
#[route]
are compiled with the 2018 edition - see https://play.rust-lang.org/?version=stable&mode=debug&edition=2015&gist=17ec58c07d13f2309458dcf9060e642a, a smaller reproduction that works in the 2018 edition but fails on 2015 for the same reason as this approach.Unresolved:
It almost seems like an accident, and it doesn't seem to be communicated/documented very well.Yes, it is.rocket_codegen
itself is 2018 edition and we use the right spans the "hack" will work for both 2015 and 2018 application crates.#[macro_export]
+pub use
, because all macros globally exported withmacro_export
must be unambiguous. It looks like we can skip#[macro_export]
and do apub(crate) use
instead, making the random generation unnecessary. However, I believe that would restrict theuri!
macro to being called from the same crate where the route was defined.blah blah 2015 2018 worryingWill wait for Rust 2018 #1013 to be merged, androcket_codegen
is 2018 edition and this PR will be much easier.#[doc(hidden)]
if possible.try_from
, but this iscodegen
andtry_from
is incore
)