Skip to content
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

Merged
merged 10 commits into from
Sep 7, 2019
Merged

Conversation

matthewjasper
Copy link
Contributor

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 #60869, #61019

r? @petrochenkov

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 26, 2019
@rust-highfive

This comment has been minimized.

@Kixiron Kixiron added A-parser Area: The parsing of Rust source code to an AST S-blocked Status: Blocked on something else such as an RFC or other implementation work. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 26, 2019
@rust-highfive

This comment has been minimized.

@petrochenkov
Copy link
Contributor

Nice, nice. The end of gensyms is closer with every day.

}
visible_path.extend_from_slice(path);
visible_path
}
Copy link
Contributor

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.

Copy link
Contributor

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.)

@petrochenkov
Copy link
Contributor

I've left some high-level comments, but didn't read the code in detail, will do that somewhere this week.

@rust-highfive

This comment has been minimized.

@matthewjasper matthewjasper added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 31, 2019
src/librustc_resolve/macros.rs Outdated Show resolved Hide resolved
src/libsyntax_pos/hygiene.rs Outdated Show resolved Hide resolved
src/librustc_privacy/lib.rs Outdated Show resolved Hide resolved
src/libsyntax_ext/proc_macro_harness.rs Outdated Show resolved Hide resolved
src/libsyntax_ext/proc_macro_harness.rs Outdated Show resolved Hide resolved
@petrochenkov
Copy link
Contributor

(Still need to review test harness and stdlib injection.)

}
visible_path.extend_from_slice(path);
visible_path
}
Copy link
Contributor

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.)

src/libsyntax_ext/standard_library_imports.rs Outdated Show resolved Hide resolved
src/libsyntax_ext/standard_library_imports.rs Outdated Show resolved Hide resolved
// 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;
Copy link
Contributor

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)

Copy link
Contributor Author

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.

src/libsyntax_ext/standard_library_imports.rs Outdated Show resolved Hide resolved
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 5, 2019
matthewjasper and others added 4 commits September 5, 2019 15:07
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.
@rust-highfive

This comment has been minimized.

@rust-highfive

This comment has been minimized.

@matthewjasper matthewjasper added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Sep 6, 2019
@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Sep 6, 2019

📌 Commit 3f3fc52 has been approved by petrochenkov

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 6, 2019
Centril added a commit to Centril/rust that referenced this pull request Sep 7, 2019
…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
@bors
Copy link
Contributor

bors commented Sep 7, 2019

⌛ Testing commit 3f3fc52 with merge bf5f7249fbcdf5ff7d91909fee0b4dc09ff5326a...

@Centril
Copy link
Contributor

Centril commented Sep 7, 2019

@bors retry rolled up.

@rust-highfive
Copy link
Collaborator

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.
2019-09-07T06:07:34.0822965Z ##[command]git config gc.auto 0
2019-09-07T06:07:34.1479006Z ##[command]git config --get-all http.https://github.com/rust-lang/rust.extraheader
2019-09-07T06:07:34.1926917Z ##[command]git config --get-all http.proxy
2019-09-07T06:07:34.2427780Z ##[command]git -c http.extraheader="AUTHORIZATION: basic ***" fetch --force --tags --prune --progress --no-recurse-submodules --depth=2 origin
2019-09-07T06:07:37.1476362Z fatal: remote error: upload-pack: not our ref bf5f7249fbcdf5ff7d91909fee0b4dc09ff5326ac_lib
2019-09-07T06:07:37.1566861Z fatal: the remote end hung up unexpectedly
2019-09-07T06:07:37.2696929Z ##[warning]Git fetch failed with exit code 128, back off 1.954 seconds before retry.

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 @TimNN. (Feature Requests)

bors added a commit that referenced this pull request Sep 7, 2019
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
@bors bors merged commit 3f3fc52 into rust-lang:master Sep 7, 2019
@matthewjasper matthewjasper deleted the remove-gensymmed branch September 7, 2019 20:28
Comment on lines 86 to 87
// We don't want to recurse into anything other than mods, since
// mods or tests inside of functions will break things
Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants