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

Make SourceMap available for early debug-printing of Spans #72618

Merged
merged 1 commit into from
Jun 4, 2020

Conversation

Aaron1011
Copy link
Member

Normally, we debug-print Spans using the SourceMap retrieved from
the global TyCtxt. However, we fall back to printing out the Span's
raw fields (instead of a file and line number) when we try to print a
Span before a TyCtxt is available. This makes debugging early phases
of the compile, such as parsing, much more difficult.

This commit stores a SourceMap in rustc_span::GlOBALS as a fallback.
When a TyCtxt is not available, we try to retrieve one from GLOBALS

  • only if this is not available do we fall back to the raw field output.

I'm not sure how to write a test for this - however, this can be
verified locally by setting RUSTC_LOG="rustc_parse=debug", and
verifying that the output contains filenames and line numbers.

@rust-highfive
Copy link
Collaborator

r? @ecstatic-morse

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 26, 2020
@petrochenkov petrochenkov self-assigned this May 26, 2020
@petrochenkov
Copy link
Contributor

cc #72669

Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request May 28, 2020
…crum

rustc_session: Cleanup session creation

Noticed while reviewing rust-lang#72618.
RalfJung added a commit to RalfJung/rust that referenced this pull request May 30, 2020
…crum

rustc_session: Cleanup session creation

Noticed while reviewing rust-lang#72618.
@petrochenkov
Copy link
Contributor

This is a bit hacky, but we don't have much choice here, I guess.
I'll approve this once #72669 lands.

@petrochenkov petrochenkov added S-blocked Status: Blocked on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 30, 2020
@ecstatic-morse ecstatic-morse removed their assignment May 30, 2020
RalfJung added a commit to RalfJung/rust that referenced this pull request May 30, 2020
…crum

rustc_session: Cleanup session creation

Noticed while reviewing rust-lang#72618.
@bors
Copy link
Contributor

bors commented May 31, 2020

☔ The latest upstream changes (presumably #72794) made this pull request unmergeable. Please resolve the merge conflicts.

@Aaron1011 Aaron1011 force-pushed the feature/early-sourcemap branch from a1149ff to d13b3f0 Compare May 31, 2020 04:25
@Aaron1011
Copy link
Member Author

@petrochenkov: Rebased

@Aaron1011 Aaron1011 added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-blocked Status: Blocked on something else such as an RFC or other implementation work. labels May 31, 2020
@petrochenkov
Copy link
Contributor

r=me after the cleanup (#72618 (comment)) and squashing commits.

@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 May 31, 2020
@petrochenkov
Copy link
Contributor

petrochenkov commented May 31, 2020

Actually I need to look at #72799 first.
UPD: Done.

@Aaron1011 Aaron1011 force-pushed the feature/early-sourcemap branch 2 times, most recently from f836cf2 to 5909611 Compare May 31, 2020 19:59
@Aaron1011
Copy link
Member Author

@bors r=petrochenkov

@bors
Copy link
Contributor

bors commented May 31, 2020

📌 Commit 5909611eb1e9c1ac0207ec631dee8f51217fe1d8 has been approved by petrochenkov

@bors bors removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label May 31, 2020
@bors bors added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label May 31, 2020
Normally, we debug-print `Spans` using the `SourceMap` retrieved from
the global `TyCtxt`. However, we fall back to printing out the `Span`'s
raw fields (instead of a file and line number) when we try to print a
`Span` before a `TyCtxt` is available. This makes debugging early phases
of the compile, such as parsing, much more difficult.

This commit stores a `SourceMap` in `rustc_span::GlOBALS` as a fallback.
When a `TyCtxt` is not available, we try to retrieve one from `GLOBALS`
- only if this is not available do we fall back to the raw field output.

I'm not sure how to write a test for this - however, this can be
verified locally by setting `RUSTC_LOG="rustc_parse=debug"`, and
verifying that the output contains filenames and line numbers.
@Aaron1011 Aaron1011 force-pushed the feature/early-sourcemap branch from 5909611 to 717fd66 Compare May 31, 2020 21:31
@Aaron1011
Copy link
Member Author

Forgot to run tidy

@bors r- r=petrochenkov

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 31, 2020
@bors
Copy link
Contributor

bors commented May 31, 2020

📌 Commit 717fd66 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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels May 31, 2020
RalfJung added a commit to RalfJung/rust that referenced this pull request Jun 1, 2020
…r=petrochenkov

Make `SourceMap` available for early debug-printing of `Span`s

Normally, we debug-print `Spans` using the `SourceMap` retrieved from
the global `TyCtxt`. However, we fall back to printing out the `Span`'s
raw fields (instead of a file and line number) when we try to print a
`Span` before a `TyCtxt` is available. This makes debugging early phases
of the compile, such as parsing, much more difficult.

This commit stores a `SourceMap` in `rustc_span::GlOBALS` as a fallback.
When a `TyCtxt` is not available, we try to retrieve one from `GLOBALS`
- only if this is not available do we fall back to the raw field output.

I'm not sure how to write a test for this - however, this can be
verified locally by setting `RUSTC_LOG="rustc_parse=debug"`, and
verifying that the output contains filenames and line numbers.
@bors
Copy link
Contributor

bors commented Jun 2, 2020

⌛ Testing commit 717fd66 with merge b6d3f6ea8c95f4d6d9d16f428c79df5e0342db1a...

@Dylan-DPC-zz
Copy link

@bors retry yield

@bors
Copy link
Contributor

bors commented Jun 3, 2020

⌛ Testing commit 717fd66 with merge c0c40d8ccada6a3ecbbbd09e4e88b7082588dbb8...

@Dylan-DPC-zz
Copy link

@bors retry

@bors
Copy link
Contributor

bors commented Jun 4, 2020

⌛ Testing commit 717fd66 with merge 6279571...

@bors
Copy link
Contributor

bors commented Jun 4, 2020

☀️ Test successful - checks-azure
Approved by: petrochenkov
Pushing 6279571 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jun 4, 2020
@bors bors merged commit 6279571 into rust-lang:master Jun 4, 2020
Aaron1011 added a commit to Aaron1011/rust that referenced this pull request Jun 4, 2020
Currently, the `Debug` impl for `proc_macro::Span` just prints out
the byte range. This can make debugging proc macros (either as a crate
author or as a compiler developer) very frustrating, since neither the
actual filename nor the `SyntaxContext` is displayed.

This commit adds a perma-unstable flag `-Z span-debug`. When enabled,
the `Debug` impl for `proc_macro::Span` simply forwards directly to
`rustc_span::Span`. Once rust-lang#72618 is merged, this will start displaying
actual line numbers.

While `Debug` impls are not subject to Rust's normal stability
guarnatees, we probably shouldn't expose any additional information on
stable until `#![feature(proc_macro_span)]` is stabilized. Otherwise,
we would be providing a 'backdoor' way to access information that's
supposed be behind unstable APIs.
RalfJung added a commit to RalfJung/rust that referenced this pull request Jun 6, 2020
…rochenkov

Add `-Z span-debug` to allow for easier debugging of proc macros

Currently, the `Debug` impl for `proc_macro::Span` just prints out
the byte range. This can make debugging proc macros (either as a crate
author or as a compiler developer) very frustrating, since neither the
actual filename nor the `SyntaxContext` is displayed.

This commit adds a perma-unstable flag `-Z span-debug`. When enabled,
the `Debug` impl for `proc_macro::Span` simply forwards directly to
`rustc_span::Span`. Once rust-lang#72618 is merged, this will start displaying
actual line numbers.

While `Debug` impls are not subject to Rust's normal stability
guarnatees, we probably shouldn't expose any additional information on
stable until `#![feature(proc_macro_span)]` is stabilized. Otherwise,
we would be providing a 'backdoor' way to access information that's
supposed be behind unstable APIs.
RalfJung added a commit to RalfJung/rust that referenced this pull request Jun 6, 2020
…rochenkov

Add `-Z span-debug` to allow for easier debugging of proc macros

Currently, the `Debug` impl for `proc_macro::Span` just prints out
the byte range. This can make debugging proc macros (either as a crate
author or as a compiler developer) very frustrating, since neither the
actual filename nor the `SyntaxContext` is displayed.

This commit adds a perma-unstable flag `-Z span-debug`. When enabled,
the `Debug` impl for `proc_macro::Span` simply forwards directly to
`rustc_span::Span`. Once rust-lang#72618 is merged, this will start displaying
actual line numbers.

While `Debug` impls are not subject to Rust's normal stability
guarnatees, we probably shouldn't expose any additional information on
stable until `#![feature(proc_macro_span)]` is stabilized. Otherwise,
we would be providing a 'backdoor' way to access information that's
supposed be behind unstable APIs.
RalfJung added a commit to RalfJung/rust that referenced this pull request Jun 8, 2020
…rochenkov

Add `-Z span-debug` to allow for easier debugging of proc macros

Currently, the `Debug` impl for `proc_macro::Span` just prints out
the byte range. This can make debugging proc macros (either as a crate
author or as a compiler developer) very frustrating, since neither the
actual filename nor the `SyntaxContext` is displayed.

This commit adds a perma-unstable flag `-Z span-debug`. When enabled,
the `Debug` impl for `proc_macro::Span` simply forwards directly to
`rustc_span::Span`. Once rust-lang#72618 is merged, this will start displaying
actual line numbers.

While `Debug` impls are not subject to Rust's normal stability
guarnatees, we probably shouldn't expose any additional information on
stable until `#![feature(proc_macro_span)]` is stabilized. Otherwise,
we would be providing a 'backdoor' way to access information that's
supposed be behind unstable APIs.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. 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.

6 participants