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

Avoid normalizing SyntaxContext ids in test output #74800

Closed
Aaron1011 opened this issue Jul 27, 2020 · 0 comments · Fixed by #75345
Closed

Avoid normalizing SyntaxContext ids in test output #74800

Aaron1011 opened this issue Jul 27, 2020 · 0 comments · Fixed by #75345
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@Aaron1011
Copy link
Member

PR #72121 affects the output of any test which includes debug-printed Spans in its stdout, since the printed SyntaxContext id will now depend on which foreign SyntaxContexts have been imported. However, the precise id assigned depends on what macros were expanded inside libcore/libstd, which depends on the platform we are targeting. As a result, including raw SyntaxContext in test output makes that test platform-dependent.

Currently, we strip out all SyntaxContext ids to make the test output platform-independent. However, it would be good to perform a more fine-grained normalization: e.g. distinguishing between root and non-root SyntaxContexts, which should hopefully not be platform dependent.

@Aaron1011 Aaron1011 added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 27, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Aug 9, 2020
…chenkov

Remove normalization of `Span` debug output in proc-macro tests

Fixes rust-lang#74800

The definition of `is_x86_feature_detected!` (and similar macros)
depends on the platform - it is produced by a `cfg_if!` invocation on
x86, and a plain `#[cfg]` on other platforms. Since it is part of the
prelude, we will end up importing different hygiene information
depending on the platform. This previously required us to avoid printing raw
`SyntaxContext` ids in any tests that uses the standard library, since
the captured output will be platform-dependent.

Previously, we replaced all `SyntaxContext` ids with "#CTXT", and the
raw `Span` lo/hi bytes with "LO..HI".

This commit adds `#![no_std]` and `extern crate std` to all proc-macro
tests that print spans. This suppresses the prelude import, while
still using lang items from `std` (which gives us a buildable binary).
With this apporach, we will only load hygiene information for things
which we explicitly import. This lets us re-add
`-Z unpretty=expanded,hygiene`, since its output can now be made stable
across all platforms.

Additionally, we use `-Z span-debug` in more places, which lets us avoid
the "LO..HI" normalization hack.
@bors bors closed this as completed in db6b3c1 Aug 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant