-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add an ability to convert between Span
and visit::Location
#129170
Conversation
Sorry for the delay. I'm not sure we want to necessary convert
The compiler MIR Visitor, for example, is a combination of the index of the basic block and the index of the instruction within the basic block [1]. I would be more comfortable creating an interface that allows you to create a pub fn new(body: &Body, bb: BasicBlockIdx, idx: usize) -> Location {} Maybe you can provide a bit more background on your use case and see if that would work for you. |
Thanks for the detailed explanation! I am working on an MIR transformation in Stable MIR, which could be significantly simplified if we traversed the basic block in the reverse direction. However, the only option to achieve that seems to be to implement Currently, we were able to circumvent this by visiting the basic block to collect instructions that need instrumentation and then applying the instrumentation in reverse order. However, it seems that being able to call |
Would my suggestion work in this case? Maybe we can add a few methods: /// Location of the first instruction of the BB
fn basic_block_location(body: &Body, bb: &BasicBlockIdx);
/// Location of the statement at the given index
fn statement_location(body: &Body, bb: &BasicBlockIdx, stmt_indx: usize);
/// Location of the terminator
fn terminator_location(body: &Body, bb: &BasicBlockIdx); Feel free to tweak with the idea / naming. |
I think it would. I believe |
Awesome! Thanks @bors r+ rollup |
…celinval Add an ability to convert between `Span` and `visit::Location` AFAIK, there is no way to create a `Location` from a `Span` because its only field is private. This makes it impossible to use visitor methods like `visit_statement` or `visit_terminator`. This PR adds an implementation for`From<Span>` for `Location` to fix this. r? `@celinval`
…iaskrgr Rollup of 11 pull requests Successful merges: - rust-lang#128166 (Improved `checked_isqrt` and `isqrt` methods) - rust-lang#129170 (Add an ability to convert between `Span` and `visit::Location`) - rust-lang#129366 (linker: Synchronize native library search in rustc and linker) - rust-lang#129467 (derive(SmartPointer): assume pointee from the single generic and better error messages) - rust-lang#129494 (format code in tests/ui/threads-sendsync) - rust-lang#129527 (Don't use `TyKind` in a lint) - rust-lang#129617 (Update books) - rust-lang#129673 (Add fmt::Debug to sync::Weak<T, A>) - rust-lang#129683 (copysign with sign being a NaN can have non-portable results) - rust-lang#129689 (Move `'tcx` lifetime off of impl and onto methods for `CrateMetadataRef`) - rust-lang#129695 (Fix path to run clippy on rustdoc) r? `@ghost` `@rustbot` modify labels: rollup
…celinval Add an ability to convert between `Span` and `visit::Location` AFAIK, there is no way to create a `Location` from a `Span` because its only field is private. This makes it impossible to use visitor methods like `visit_statement` or `visit_terminator`. This PR adds an implementation for`From<Span>` for `Location` to fix this. r? ``@celinval``
…kingjubilee Rollup of 14 pull requests Successful merges: - rust-lang#128192 (rustc_target: Add various aarch64 features) - rust-lang#129170 (Add an ability to convert between `Span` and `visit::Location`) - rust-lang#129343 (Emit specific message for time<=0.3.35) - rust-lang#129378 (Clean up cfg-gating of ProcessPrng extern) - rust-lang#129401 (Partially stabilize `feature(new_uninit)`) - rust-lang#129467 (derive(SmartPointer): assume pointee from the single generic and better error messages) - rust-lang#129494 (format code in tests/ui/threads-sendsync) - rust-lang#129617 (Update books) - rust-lang#129673 (Add fmt::Debug to sync::Weak<T, A>) - rust-lang#129683 (copysign with sign being a NaN can have non-portable results) - rust-lang#129689 (Move `'tcx` lifetime off of impl and onto methods for `CrateMetadataRef`) - rust-lang#129695 (Fix path to run clippy on rustdoc) - rust-lang#129712 (Correct trusty targets to be tier 3) - rust-lang#129715 (Update `compiler_builtins` to `0.1.123`) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#129170 - artemagvanian:span-to-location, r=celinval Add an ability to convert between `Span` and `visit::Location` AFAIK, there is no way to create a `Location` from a `Span` because its only field is private. This makes it impossible to use visitor methods like `visit_statement` or `visit_terminator`. This PR adds an implementation for`From<Span>` for `Location` to fix this. r? ```@celinval```
AFAIK, there is no way to create a
Location
from aSpan
because its only field is private. This makes it impossible to use visitor methods likevisit_statement
orvisit_terminator
.This PR adds an implementation for
From<Span>
forLocation
to fix this.r? @celinval