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

Improve Span in smir #115772

Merged
merged 1 commit into from
Sep 14, 2023
Merged

Improve Span in smir #115772

merged 1 commit into from
Sep 14, 2023

Conversation

ouz-a
Copy link
Contributor

@ouz-a ouz-a commented Sep 12, 2023

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 12, 2023
@rustbot
Copy link
Collaborator

rustbot commented Sep 12, 2023

This PR changes Stable MIR

cc @oli-obk, @celinval, @spastorino

@@ -139,6 139,10 @@ impl<'tcx> Tables<'tcx> {
stable_mir::ty::Prov(self.create_alloc_id(aid))
}

pub fn span(&mut self, span: Span) -> stable_mir::ty::Span {
self.create_span(span)
Copy link
Contributor

@oli-obk oli-obk Sep 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be the body of a Stable impl, so instead of removing the impl, put this logic into it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can remove the span function now, it's not needed anymore

fn span_of_an_item(&mut self, def_id: stable_mir::DefId) -> stable_mir::ty::Span {
self.span(self.tcx.def_span(self[def_id]))
fn span_of_an_item(&mut self, def_id: stable_mir::DefId) -> String {
opaque(&self.tcx.def_span(self[def_id])).to_string()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. The confusion was my inability to use github correctly.

Lemme try again:

With this change, there is no way to obtain a span anymore. Before this PR this function returned Opaque, now it returns String, which is the same thing.

If I understand it correctly, this commit is because you were unable to meaningfully debug print Span. If you wanna fix that, I think, instead of this commit, you should do something similar to Span's Debug impl as was done to DefId's Debug impl

Comment on lines 46 to 48
self.tcx.def_span(self[def_id]).stable(self)
fn span_of_an_item(&mut self, def_id: stable_mir::DefId) -> Span {
self.span(self.tcx.def_span(self[def_id]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep using the stable method for consistency

Comment on lines 1497 to 1506
impl<'tcx> Stable<'tcx> for rustc_span::Span {
type T = stable_mir::ty::Span;

fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
// FIXME: add a real implementation of stable spans
opaque(self)
}
}

impl<T> From<ErrorGuaranteed> for CompilerError<T> {
fn from(_error: ErrorGuaranteed) -> Self {
CompilerError::CompilationFailed
}
}

impl<'tcx> Stable<'tcx> for rustc_span::Span {
type T = stable_mir::ty::Span;

fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
tables.span(*self)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move the impl back up to where it was to keep the diff simpler

@@ -160,7 160,7 @@ pub trait Context {
/// Prints the name of given `DefId`
fn name_of_def_id(&self, def_id: DefId) -> String;

/// `Span` of an item
/// `Span` of an item in `Opaque` form.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not anymore 😆

Comment on lines 76 to 78
pub fn get_rustc_span(span: stable_mir::ty::Span) -> rustc_span::Span {
with_tables(|t| t.spans[span.0])
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inline this function in its one use site, just like we did with DefId

Copy link
Contributor

@oli-obk oli-obk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please squash all commits once the review comments have been addressed

@ouz-a ouz-a force-pushed the smir_span2 branch 3 times, most recently from 39116f1 to 549b677 Compare September 13, 2023 21:30
@oli-obk
Copy link
Contributor

oli-obk commented Sep 14, 2023

@bors r rollup

@bors
Copy link
Contributor

bors commented Sep 14, 2023

📌 Commit fa57a48 has been approved by oli-obk

It is now in the queue for this repository.

@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 14, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Sep 14, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Sep 14, 2023
…iaskrgr

Rollup of 4 pull requests

Successful merges:

 - rust-lang#115772 (Improve Span in smir)
 - rust-lang#115832 (Fix the error message for `#![feature(no_coverage)]`)
 - rust-lang#115834 (Properly consider binder vars in `HasTypeFlagsVisitor`)
 - rust-lang#115844 (Paper over an accidental regression)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 4f90a52 into rust-lang:master Sep 14, 2023
11 checks passed
@rustbot rustbot added this to the 1.74.0 milestone Sep 14, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Sep 14, 2023
Rollup merge of rust-lang#115772 - ouz-a:smir_span2, r=oli-obk

Improve Span in smir

Addressing rust-lang/project-stable-mir#31

r? ``@oli-obk``
@ouz-a ouz-a deleted the smir_span2 branch September 20, 2023 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants