-
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
Use hygiene for AST passes #63919
Use hygiene for AST passes #63919
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Nice, nice. The end of gensyms is closer with every day. |
} | ||
visible_path.extend_from_slice(path); | ||
visible_path | ||
} |
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.
I see the test harness is rewritten significantly.
Could you document what is generated now?
If identifiers with carefully located def-site spans are used instead of reexports, then we should be able to support #[test]
attributes everywhere, including inside functions, blocks etc.
This also should obviate the need in #[test_case]
, the whole purpose of which is to add pub
which is no longer necessary if the privacy check is performed from the new def-site span's point of view.
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.
Ok, looks like with the new hygienic ident approach the test infrastructure can indeed be simplified and improved further, but nothing prevents landing it in the current intermediate state.
(I think I'll going to investigate this myself a bit later, I still don't like that apply_mark
has to be used.)
I've left some high-level comments, but didn't read the code in detail, will do that somewhere this week. |
This comment has been minimized.
This comment has been minimized.
a93b68f
to
b992aec
Compare
(Still need to review test harness and stdlib injection.) |
} | ||
visible_path.extend_from_slice(path); | ||
visible_path | ||
} |
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.
Ok, looks like with the new hygienic ident approach the test infrastructure can indeed be simplified and improved further, but nothing prevents landing it in the current intermediate state.
(I think I'll going to investigate this myself a bit later, I still don't like that apply_mark
has to be used.)
// Should not be used for the prelude import - not a concern in the 2015 edition | ||
// because `std` is already declared in the crate root. | ||
#[cfg(rust2018)] | ||
extern crate not_libstd as std; |
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.
Well, this is kinda arguable.
If we can reroute standard library (including prelude imports) to somewhere else with --extern std=/path/to/my_std
, then why can't we do the same thing in source code with extern crate my_std as std
.
cc #63687 (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.
I see it the other way --extern std=/path/to/my_std
means that there doesn't need to be a way to override std
in source code, especially one that only works on the 2018 edition.
Looking at the linked issue, the crate in question isn't #![no_std]
and uses the 2015 edition, so it's not overriding anything there.
`gensym_if_underscore` still exists. The symbol interner can still create arbitray gensyms, this is just not exposed publicly.
Use these to create call-site spans for AST passes when needed.
Also ensure that we're consistently using the def-site span when appropriate.
b992aec
to
ff45e72
Compare
This comment has been minimized.
This comment has been minimized.
ff45e72
to
b299c4d
Compare
This comment has been minimized.
This comment has been minimized.
@bors r+ |
📌 Commit 3f3fc52 has been approved by |
…etrochenkov Use hygiene for AST passes AST passes are now able to have resolve consider their expansions as if they were opaque macros defined either in some module in the current crate, or a fake empty module with `#[no_implicit_prelude]`. * Add an ExpnKind for AST passes. * Remove gensyms in AST passes. * Remove gensyms in`#[test]`, `#[bench]` and `#[test_case]`. * Allow opaque macros to define tests. * Move tests for unit tests to their own directory. * Remove `Ident::{gensym, is_gensymed}` - `Ident::gensym_if_underscore` still exists. cc rust-lang#60869, rust-lang#61019 r? @petrochenkov
⌛ Testing commit 3f3fc52 with merge bf5f7249fbcdf5ff7d91909fee0b4dc09ff5326a... |
@bors retry rolled up. |
Your PR failed (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 |
Rollup of 10 pull requests Successful merges: - #63919 (Use hygiene for AST passes) - #63927 (Filter linkcheck spurious failure) - #64149 (rustc_codegen_llvm: give names to non-alloca variable values.) - #64192 (Bail out when encountering likely missing turbofish in parser) - #64231 (Move the HIR CFG to `rustc_ast_borrowck`) - #64233 (Correct pluralisation of various diagnostic messages) - #64236 (reduce visibility) - #64240 (Include compiler-rt in the source tarball) - #64241 ([doc] Added more prereqs and note about default directory) - #64243 (Move injection of attributes from command line to `libsyntax_ext`) Failed merges: r? @ghost
// We don't want to recurse into anything other than mods, since | ||
// mods or tests inside of functions will break things |
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.
Doesn't this PR solve this problem entirely?
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.
I think that it should work for modules inside expressions of we visited them. Is a bit more work for tests that are directly in blocks.
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.
Mostly, but it looks like some bits are still missing, see https://internals.rust-lang.org/t/allowing-test-on-inner-functions/11765.
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.
Ah that's what @matthewjasper was mentioning, i.e. ast::Block
's NodeId
not being usable as the parent.
AST passes are now able to have resolve consider their expansions as if they were opaque macros defined either in some module in the current crate, or a fake empty module with
#[no_implicit_prelude]
.#[test]
,#[bench]
and#[test_case]
.Ident::{gensym, is_gensymed}
-Ident::gensym_if_underscore
still exists.cc #60869, #61019
r? @petrochenkov