Skip to content
This repository was archived by the owner on Jan 7, 2022. It is now read-only.

Conversation

vext01
Copy link
Member

@vext01 vext01 commented Jan 10, 2019

This shows that we can store MIR locations into a thread local vector at runtime.

It's a quick and dirty implementation that disables tracing for a bunch of crates that ideally we probably do want to trace at some point. As discussed on IRC, we are going to live with this compromise until a later date, where we might (e.g.) implement the trace recorder in another language that the MIR pass can't see.

I've added some tests of our own too.

I've run the smoke test subset of the rustc tests at stage one and fixed a few failures. Let's see what happens in a full run.

Any comments in the meantime?

@vext01
Copy link
Member Author

vext01 commented Jan 10, 2019

bors try

bors bot added a commit that referenced this pull request Jan 10, 2019
@@ -18,6 +18,11 @@ use rustc::hir;
use rustc::hir::def_id::{DefIndex, LOCAL_CRATE};
use rustc::hir::map::blocks::FnLikeNode;

// Crates the trace recorder depends upon.
// This is effectively libstd and its dependencies (from its Cargo manifest).
static RECORDER_DEPS: &'static [&'static str] = &["std", "alloc", "panic_unwind",
Copy link
Member

Choose a reason for hiding this comment

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

I think it might be clearer to call this something like CRATES_TRACE_BLACKLIST: in a sense, the fact that the crate is a dependency is less relevant than that we're going to avoid tracing it?

Copy link
Member Author

Choose a reason for hiding this comment

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

OK.

pub bb_idx: u32,
}

impl fmt::Debug for MirLoc {
Copy link
Member

Choose a reason for hiding this comment

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

Is it worth this manual code vs. #[derive(Debug)]?

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason I did a custom one was because the derived one is quite long, with the names of the fields etc.

I wanted a shorter representation.

Copy link
Member

Choose a reason for hiding this comment

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

OK, but let's only do this sparingly, just because it's that bit more code to read and maintain.

}

// FIXME Anything used in `rec_loc` below cannot itself be traced, or we get infinite recursion. To
// work sround this, many crates are ignored by the software tracing MIR pass (see
Copy link
Member

Choose a reason for hiding this comment

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

"Around".

Copy link
Member Author

Choose a reason for hiding this comment

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

oopsy!

let mut trace_o = rc.borrow_mut();
match trace_o.as_mut() {
Some(trace) => trace.push(MirLoc{crate_hash, def_idx, bb_idx}),
None => (), // Tracing is disabled, do nothing.
Copy link
Member

Choose a reason for hiding this comment

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

"Disabled" or "not active"?

Copy link
Member Author

Choose a reason for hiding this comment

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

Both I guess. How about:

"We are not currently tracing, do nothing"

Copy link
Member

Choose a reason for hiding this comment

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

Agreed.

Copy link
Member Author

Choose a reason for hiding this comment

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

We are only resolving threads when I have pushed the fixes, right? This one was marked resolved.

Copy link
Member

Choose a reason for hiding this comment

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

We had resolved the discussion (and I trust you to do what you'd suggested you would do). No point having things hanging around in such a case I think?

Copy link
Member Author

@vext01 vext01 Jan 11, 2019

Choose a reason for hiding this comment

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

Ah I see. This isn't quite what I thought. The problem with this strategy is that I have to go unfolding threads to see if I've addressed them or not (in code). I thought you would only resolve them when you saw the commit that addresses them.

But that might also be sub-optimal?

#[cfg_attr(not(stage0), no_trace)]
pub fn stop_tracing() -> Vec<MirLoc> {
TRACE.with(|rc| {
let trace_o = rc.borrow_mut().take();
Copy link
Member

Choose a reason for hiding this comment

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

Can't this be something like:

rc.borrow_mut().take.expect("tracing not started on this thread")

?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it could, yeah. Thanks.


#[inline(never)]
fn work() -> u64{
let mut res = 47;
Copy link
Member

Choose a reason for hiding this comment

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

Any reason for the unusual numbers?

Copy link
Member Author

Choose a reason for hiding this comment

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

Arbitrary.

Copy link
Member

Choose a reason for hiding this comment

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

Can I suggest we choose less weird numbers? Otherwise it makes me think there's something specific about these (perhaps some threshold needs to be exceeded). I am a big fan of numbers < 10, or multiples of 10 ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

Can do, yeah.

@vext01
Copy link
Member Author

vext01 commented Jan 10, 2019

Thanks for the comments. I'm going to wait for buildbot before applying changes.

@ltratt
Copy link
Member

ltratt commented Jan 10, 2019

You can, I think, push changes even before buildbot has finished without affecting it. But it's up to you -- I'm easy either way!

@vext01
Copy link
Member Author

vext01 commented Jan 10, 2019

I configured it to run a build for each push. So perhaps I'll make the changes locally and wait for the push.

@ltratt
Copy link
Member

ltratt commented Jan 10, 2019

I configured it to run a build for each push. So perhaps I'll make the changes locally and wait for the push.

Dumb question: what's the point of manually doing "try" then? I assumed we had to manually kick it to get it to do anything...

@vext01
Copy link
Member Author

vext01 commented Jan 10, 2019

You are right, I think I must be wrong.

@bors
Copy link
Contributor

bors bot commented Jan 10, 2019

try

Build failed

@vext01
Copy link
Member Author

vext01 commented Jan 10, 2019

I'll start looking at the test failures first thing tomorrow. Cheers.

// FIXME Anything which the trace recorder depends upon cannot be traced or we will get
// infinite recursion at runtime..
if RECORDER_DEPS.contains(&&*tcx.crate_name(LOCAL_CRATE).as_str()) {
// Don't transform any crate which is blacklisted. See the comment against BLACKLISTED_CRATES.
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need this comment (it just says what the line of code below does, and the line of code is very clear IMHO).

@ltratt
Copy link
Member

ltratt commented Jan 21, 2019

Is this one still moving?

@vext01
Copy link
Member Author

vext01 commented Jan 25, 2019

This was rendered dead by #4

@vext01 vext01 closed this Jan 25, 2019
bors bot pushed a commit that referenced this pull request Jul 9, 2020
update from origin 2020-06-15
vext01 pushed a commit to vext01/ykrustc that referenced this pull request Oct 12, 2020
This is a combination of 18 commits.

Commit softdevteam#2:

Additional examples and some small improvements.

Commit softdevteam#3:

fixed mir-opt non-mir extensions and spanview title elements

Corrected a fairly recent assumption in runtest.rs that all MIR dump
files end in .mir. (It was appending .mir to the graphviz .dot and
spanview .html file names when generating blessed output files. That
also left outdated files in the baseline alongside the files with the
incorrect names, which I've now removed.)

Updated spanview HTML title elements to match their content, replacing a
hardcoded and incorrect name that was left in accidentally when
originally submitted.

Commit softdevteam#4:

added more test examples

also improved Makefiles with support for non-zero exit status and to
force validation of tests unless a specific test overrides it with a
specific comment.

Commit softdevteam#5:

Fixed rare issues after testing on real-world crate

Commit softdevteam#6:

Addressed PR feedback, and removed temporary -Zexperimental-coverage

-Zinstrument-coverage once again supports the latest capabilities of
LLVM instrprof coverage instrumentation.

Also fixed a bug in spanview.

Commit softdevteam#7:

Fix closure handling, add tests for closures and inner items

And cleaned up other tests for consistency, and to make it more clear
where spans start/end by breaking up lines.

Commit softdevteam#8:

renamed "typical" test results "expected"

Now that the `llvm-cov show` tests are improved to normally expect
matching actuals, and to allow individual tests to override that
expectation.

Commit softdevteam#9:

test coverage of inline generic struct function

Commit softdevteam#10:

Addressed review feedback

* Removed unnecessary Unreachable filter.
* Replaced a match wildcard with remining variants.
* Added more comments to help clarify the role of successors() in the
CFG traversal

Commit softdevteam#11:

refactoring based on feedback

* refactored `fn coverage_spans()`.
* changed the way I expand an empty coverage span to improve performance
* fixed a typo that I had accidently left in, in visit.rs

Commit softdevteam#12:

Optimized use of SourceMap and SourceFile

Commit softdevteam#13:

Fixed a regression, and synched with upstream

Some generated test file names changed due to some new change upstream.

Commit softdevteam#14:

Stripping out crate disambiguators from demangled names

These can vary depending on the test platform.

Commit softdevteam#15:

Ignore llvm-cov show diff on test with generics, expand IO error message

Tests with generics produce llvm-cov show results with demangled names
that can include an unstable "crate disambiguator" (hex value). The
value changes when run in the Rust CI Windows environment. I added a sed
filter to strip them out (in a prior commit), but sed also appears to
fail in the same environment. Until I can figure out a workaround, I'm
just going to ignore this specific test result. I added a FIXME to
follow up later, but it's not that critical.

I also saw an error with Windows GNU, but the IO error did not
specify a path for the directory or file that triggered the error. I
updated the error messages to provide more info for next, time but also
noticed some other tests with similar steps did not fail. Looks
spurious.

Commit softdevteam#16:

Modify rust-demangler to strip disambiguators by default

Commit softdevteam#17:

Remove std::process::exit from coverage tests

Due to Issue #77553, programs that call std::process::exit() do not
generate coverage results on Windows MSVC.

Commit softdevteam#18:

fix: test file paths exceeding Windows max path len
vext01 pushed a commit to vext01/ykrustc that referenced this pull request Dec 2, 2020
Don't run `resolve_vars_if_possible` in `normalize_erasing_regions`

Neither `@eddyb` nor I could figure out what this was for. I changed it to `assert_eq!(normalized_value, infcx.resolve_vars_if_possible(&normalized_value));` and it passed the UI test suite.

<details><summary>

Outdated, I figured out the issue - `needs_infer()` needs to come _after_ erasing the lifetimes

</summary>

Strangely, if I change it to `assert!(!normalized_value.needs_infer())` it panics almost immediately:

```
query stack during panic:
#0 [normalize_generic_arg_after_erasing_regions] normalizing `<str::IsWhitespace as str::pattern::Pattern>::Searcher`
#1 [needs_drop_raw] computing whether `str::iter::Split<str::IsWhitespace>` needs drop
softdevteam#2 [mir_built] building MIR for `str::<impl str>::split_whitespace`
softdevteam#3 [unsafety_check_result] unsafety-checking `str::<impl str>::split_whitespace`
softdevteam#4 [mir_const] processing MIR for `str::<impl str>::split_whitespace`
softdevteam#5 [mir_promoted] processing `str::<impl str>::split_whitespace`
softdevteam#6 [mir_borrowck] borrow-checking `str::<impl str>::split_whitespace`
softdevteam#7 [analysis] running analysis passes on this crate
end of query stack
```

I'm not entirely sure what's going on - maybe the two disagree?

</details>

For context, this came up while reviewing rust-lang/rust#77467 (cc `@lcnr).`

Possibly this needs a crater run?

r? `@nikomatsakis`
cc `@matthewjasper`
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants