Clarify debugging graph dependency (#1862)
This commit is contained in:
parent
4c7c97aad1
commit
e6de7e3ac2
|
|
@ -2,13 +2,16 @@
|
||||||
|
|
||||||
## Testing the dependency graph
|
## Testing the dependency graph
|
||||||
|
|
||||||
There are various ways to write tests against the dependency graph.
|
There are various ways to write tests against the dependency graph. The
|
||||||
The simplest mechanisms are the `#[rustc_if_this_changed]` and
|
simplest mechanisms are the `#[rustc_if_this_changed]` and
|
||||||
`#[rustc_then_this_would_need]` annotations. These are used in ui tests
|
`#[rustc_then_this_would_need]` annotations. These are used in [ui] tests to test
|
||||||
to test whether the expected set of paths exist in the dependency graph.
|
whether the expected set of paths exist in the dependency graph.
|
||||||
As an example, see `tests/ui/dep-graph/dep-graph-caller-callee.rs`.
|
|
||||||
|
|
||||||
The idea is that you can annotate a test like:
|
[`tests/ui/dep-graph/dep-graph-caller-callee.rs`]: https://github.com/rust-lang/rust/blob/master/tests/ui/dep-graph/dep-graph-caller-callee.rs
|
||||||
|
[ui]: tests/ui.html
|
||||||
|
|
||||||
|
As an example, see [`tests/ui/dep-graph/dep-graph-caller-callee.rs`], or the
|
||||||
|
tests below.
|
||||||
|
|
||||||
```rust,ignore
|
```rust,ignore
|
||||||
#[rustc_if_this_changed]
|
#[rustc_if_this_changed]
|
||||||
|
|
@ -16,16 +19,24 @@ fn foo() { }
|
||||||
|
|
||||||
#[rustc_then_this_would_need(TypeckTables)] //~ ERROR OK
|
#[rustc_then_this_would_need(TypeckTables)] //~ ERROR OK
|
||||||
fn bar() { foo(); }
|
fn bar() { foo(); }
|
||||||
|
```
|
||||||
|
|
||||||
|
This should be read as
|
||||||
|
> If this (`foo`) is changed, then this (i.e. `bar`)'s TypeckTables would need
|
||||||
|
to be changed. Also, this
|
||||||
|
|
||||||
|
You could also add the lines
|
||||||
|
|
||||||
|
```rust,ignore
|
||||||
#[rustc_then_this_would_need(TypeckTables)] //~ ERROR no path
|
#[rustc_then_this_would_need(TypeckTables)] //~ ERROR no path
|
||||||
fn baz() { }
|
fn baz() { }
|
||||||
```
|
```
|
||||||
|
|
||||||
This will check whether there is a path in the dependency graph from `Hir(foo)`
|
Whose meaning is
|
||||||
to `TypeckTables(bar)`. An error is reported for each
|
> If `foo` is changed, then `baz`'s TypeckTables does not need to be changed, as there is no path.
|
||||||
`#[rustc_then_this_would_need]` annotation that indicates whether a path
|
|
||||||
exists. `//~ ERROR` annotations can then be used to test if a path is found (as
|
Recall that the `//~ ERROR OK` is a comment from the point of view of the Rust
|
||||||
demonstrated above).
|
code we test, but is meaningful from the point of view of the test itself.
|
||||||
|
|
||||||
## Debugging the dependency graph
|
## Debugging the dependency graph
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue