Commit Graph

72501 Commits

Author SHA1 Message Date
Felix S. Klock II
b75248ef4e Address review note: AccessErrorsReported meant to track whether error reported at *any* point in past. 2017-12-14 09:03:04 -06:00
Oliver Schneider
7a2bff7f1a
Do not produce debuginfo for tools 2017-12-14 15:40:51 +01:00
varkor
7b5981aad4 Fix division-by-zero ICE in -Z perf-stats
An invalid average now simply prints “N/A”. Fixes #46725.
2017-12-14 14:19:57 +00:00
bors
8624ea5117 Auto merge of #46335 - oli-obk:cleanups, r=jseyfried
Use PathBuf instead of String where applicable

r? @jseyfried
2017-12-14 12:50:00 +00:00
Oliver Schneider
1ba46dc378
Move mir validation out of tree 2017-12-14 11:36:28 +01:00
Oliver Schneider
d732da813b
Use PathBuf instead of String where applicable 2017-12-14 11:22:08 +01:00
bors
75a02a919c Auto merge of #46633 - estebank:arg-mismatch, r=arielb1
Point at whole method call instead of args

To avoid confusion in cases where the code is

```rust
fn foo() {}
/ foo(
|     bar()
|     ^^^ current diagnostics point here for arg count mismatch
| );
|_^ new diagnostic span points here
```

as this leads to confusion making people think that the diagnostic is
talking about `bar`'s arg count, not `foo`'s.

Point at `fn`s definition on arg mismatch, just like we do for closures.

Re #42855, Fix #45633.
2017-12-14 10:08:48 +00:00
bors
8954b16beb Auto merge of #46605 - estebank:macro-backtrace-spans, r=pnkfelix
Use spans for -Z external-macro-backtrace

```
% rustc ui/type-check/cannot_infer_local_or_vec.rs -Z external-macro-backtrace
error[E0282]: type annotations needed
  --> <vec macros>:3:1
   |
1  | / ( $ elem : expr ; $ n : expr ) => (
2  | | $ crate :: vec :: from_elem ( $ elem , $ n ) ) ; ( $ ( $ x : expr ) , * ) => (
3  | | < [ _ ] > :: into_vec ( box [ $ ( $ x ) , * ] ) ) ; ( $ ( $ x : expr , ) * )
   | | ^^^^^^^^^^^^^^^^^^^^^
   | | |
   | | cannot infer type for `T`
4  | | => ( vec ! [ $ ( $ x ) , * ] )
   | |______________________________- in this expansion of `vec!`
   |
  ::: ui/type-check/cannot_infer_local_or_vec.rs
   |
12 |       let x = vec![];
   |           -   ------ in this macro invocation
   |           |
   |           consider giving `x` a type

error: aborting due to previous error
```
2017-12-14 07:06:02 +00:00
bors
f03e06762e Auto merge of #46582 - nikomatsakis:nll-master-to-rust-master-4, r=arielb1
make MIR type checker handle a number of other cases

The existing type checker was primarily used to verify types, but was skipping over a number of details. For example, it was not checking that the predicates on functions were satisfied and so forth. This meant that the NLL region checker was not getting a lot of the constraints it needed. This PR closes those gaps. It also includes a bit of refactoring for the way that we store region values, encapsulating the bit matrix over into its own module and improving the data structures in use.

This is mostly work by @spastorino being ported over from nll-master.

r? @arielb1 or @pnkfelix
2017-12-14 04:32:14 +00:00
Felix S. Klock II
f96777c9ff After discussion with ariel, replacing a guard within kill_loans_out_of_scope_at_location.
Instead we are "just" careful to invoke it (which sets up a bunch of kill bits)
before we go into the code that sets up the gen bits.

That way, when the gen bits are set up, they will override any
previously set kill-bits for those reservations or activations.
2017-12-13 18:10:37 -06:00
Felix S. Klock II
3c7d9ff90a Address review comment: use .get instead of indexing to cope w/ terminators.
(Same net effect as code from before; just cleaner way to get there.)
2017-12-13 18:07:02 -06:00
Sunjay Varma
f701b4cca0 Added test to make sure that undeclared lifetimes are in fact detected 2017-12-13 18:50:45 -05:00
Sunjay Varma
b90e9c9b2c Added test to make sure we can refer to the declared traits of a generic associated type 2017-12-13 18:50:22 -05:00
bors
0142781ad1 Auto merge of #46708 - pnkfelix:fix-issue-46112, r=arielb1
Fix visible_parent_map to choose globally minimal paths

Fix #46112: visible_parent_map construction needs a BFS over whole crate forest to get globally minimal paths.

(There are other latent bugs that were e.g. causing this test case to have weirdness like `<unnamed>` in the diagnostic output. Those bugs are not fixed here, since they are issues long-standing in the stable channel.)
2017-12-13 23:43:56 +00:00
Sunjay Varma
4f90eacbfe Updating tests to remove all "undeclared lifetime" errors (since those should no longer occur) 2017-12-13 18:27:53 -05:00
Felix S. Klock II
5cae7a0469 Check activation points as the place where mutable borrows become relevant.
Since we are now checking activation points, I removed one of the
checks at the reservation point. (You can see the effect this had on
two-phase-reservation-sharing-interference-2.rs)

Also, since we now have checks at both the reservation point and the
activation point, we sometimes would observe duplicate errors (since
either one independently interferes with another mutable borrow).  To
deal with this, I used a similar strategy to one used as discussed on
issue #45360: keep a set of errors reported (in this case for
reservations), and then avoid doing the checks for the corresponding
activations. (This does mean that some errors could get masked, namely
for conflicting borrows that start after the reservation but still
conflict with the activation, which is unchecked when there was an
error for the reservation. But this seems like a reasonable price to
pay.)
2017-12-13 15:48:21 -06:00
Felix S. Klock II
18aedf6b23 Sidestep ICE from MirBorrowckCtxt::find_closure_span. 2017-12-13 15:48:21 -06:00
Felix S. Klock II
9cb92ac27d two-phase-reservation-sharing-interference.rs variant that is perhaps more surprising. 2017-12-13 15:48:21 -06:00
Felix S. Klock II
db5420b6f2 test describing a currently unsupported corner case. 2017-12-13 15:48:20 -06:00
Felix S. Klock II
dbbec4d62d tests transcribed from nikos blog post. 2017-12-13 15:48:20 -06:00
Felix S. Klock II
5f759a90e3 the minimal test for two-phase borrows: the core example from niko's blog post on it. 2017-12-13 15:48:20 -06:00
Felix S. Klock II
36216456a6 Incorporate active-borrows dataflow into MIR borrow check, yielding
two-phase `&mut`-borrow support.

This (new) support sits under `-Z two-phase-borrows` debugflag.

(Still needs tests. That's coming next.)
2017-12-13 15:48:20 -06:00
Felix S. Klock II
1334638144 Add some doc to struct Borrows. 2017-12-13 15:48:20 -06:00
Felix S. Klock II
658ed79700 Add some doc to each_borrow_involving_path iteration function. 2017-12-13 15:48:20 -06:00
Felix S. Klock II
ced5a701ff New ActiveBorrows dataflow for two-phase &mut; not yet borrowed-checked.
High-level picture: The old `Borrows` analysis is now called
`Reservations` (implemented as a newtype wrapper around `Borrows`);
this continues to compute whether a `Rvalue::Ref` can reach a
statement without an intervening `EndRegion`. In addition, we also
track what `Place` each such `Rvalue::Ref` was immediately assigned
to in a given borrow (yay for MIR-structural properties!).

The new `ActiveBorrows` analysis then tracks the initial use of any of
those assigned `Places` for a given borrow. I.e. a borrow becomes
"active" immediately after it starts being "used" in some way. (This
is conservative in the sense that we will treat a copy `x = y;` as a
use of `y`; in principle one might further delay activation in such
cases.)

The new `ActiveBorrows` analysis needs to take the `Reservations`
results as an initial input, because the reservation state influences
the gen/kill sets for `ActiveBorrows`. In particular, a use of `a`
activates a borrow `a = &b` if and only if there exists a path (in the
control flow graph) from the borrow to that use. So we need to know if
the borrow reaches a given use to know if it really gets a gen-bit or
not.

 * Incorporating the output from one dataflow analysis into the input
   of another required more changes to the infrastructure than I had
   expected, and even after those changes, the resulting code is still
   a bit subtle.

 * In particular, Since we need to know the intrablock reservation
   state, we need to dynamically update a bitvector for the
   reservations as we are also trying to compute the gen/kills
   bitvector for the active borrows.

 * The way I ended up deciding to do this (after also toying with at
   least two other designs) is to put both the reservation state and
   the active borrow state into a single bitvector. That is why we now
   have separate (but related) `BorrowIndex` and
   `ReserveOrActivateIndex`: each borrow index maps to a pair of
   neighboring reservation and activation indexes.

As noted above, these changes are solely adding the active borrows
dataflow analysis (and updating the existing code to cope with the
switch from `Borrows` to `Reservations`). The code to process the
bitvector in the borrow checker currently just skips over all of the
active borrow bits.

But atop this commit, one *can* observe the analysis results by
looking at the graphviz output, e.g. via

```rust
 #[rustc_mir(borrowck_graphviz_preflow="pre_two_phase.dot",
             borrowck_graphviz_postflow="post_two_phase.dot")]
```

Includes doc for `FindPlaceUses`, as well as `Reservations` and
`ActiveBorrows` structs, which are wrappers are the `Borrows` struct
that dictate which flow analysis should be performed.
2017-12-13 15:48:15 -06:00
bors
f8af59d952 Auto merge of #46715 - kennytm:download-crosstool-ng-from-github, r=TimNN
Download crosstool-ng from GitHub

Workaround the current problem where http://crosstool-ng.org was done, causing all non-x86 jobs to fail spuriously (cc #40474).

If http://crosstool-ng.org becomes online before this PR is merged, this PR should be closed and the tree should be reopened.
2017-12-13 20:55:53 +00:00
kennytm
bf0653ea8e
Download the crosstool from GitHub instead of crosstool-ng.org
Temporary workaround since crosstool-ng.org was down. Consider mirroring
the release tarball as a more permanent solution.
2017-12-14 04:50:13 +08:00
Felix S. Klock II
ef64ace8aa Allow mir::Place to be used as a key in hashtables. 2017-12-13 13:50:40 -06:00
Felix S. Klock II
e437e499d1 Implement Borrow/BorrowMut/ToOwned relationships betweed IdxSetBuf and IdxSet. 2017-12-13 13:50:40 -06:00
Felix S. Klock II
39e126c001 Refactoring alpha-rename place (BorrowData field) to borrowed_place. 2017-12-13 13:50:40 -06:00
Felix S. Klock II
e123117cb7 Refactoring: Allow BlockSets.on_entry to denote locally accumulated intrablock state.
(Still musing about whether it could make sense to revise the design
here to make these constraints on usage explicit.)
2017-12-13 13:50:39 -06:00
Felix S. Klock II
d4add5d52a Refactoring: pull bitvector initialization out from other parts of dataflow.
This is meant to ease development of multi-stage dataflow analyses
where the output from one analysis is used to initialize the state
for the next; in such a context, you cannot start with `bottom_value`
for all the bits.
2017-12-13 13:50:39 -06:00
Esteban Küber
d4b8e99540 Move error checks out of span for easier to follow .stderr 2017-12-13 11:27:18 -08:00
Niko Matsakis
237dd41211 correct comment in test 2017-12-13 12:20:29 -05:00
Niko Matsakis
51847a1b18 add FIXME related to constant well-formedness 2017-12-13 12:20:28 -05:00
Niko Matsakis
abd6d0d76e comments for defining_ty and compute_indices
Plus an extra assertion.
2017-12-13 12:20:28 -05:00
Niko Matsakis
75ac071cd6 document return value of add_live_point 2017-12-13 12:20:28 -05:00
Niko Matsakis
f6723a9592 improve comments on safe_to_unsafe_fn_ty and coerce_closure_fn_ty 2017-12-13 12:20:28 -05:00
Niko Matsakis
7a20a3f161 change to use an O(1) data structure for looking up point indices
Converting a `RegionElementIndex` to a `Location` is O(n) though could
trivially be O(log n), but we don't do it that much anyhow -- just on
error and debugging.
2017-12-13 12:20:28 -05:00
Niko Matsakis
77663a677d refactor region value bitmatrix 2017-12-13 12:20:27 -05:00
Niko Matsakis
a30e2259da fix closure tests now that MIR typeck works properly
These tests had FIXMEs for errors that were not previously being
reported.
2017-12-13 12:20:27 -05:00
Konrad Borowski
524c3ff472
Remove Sync and Send implementation for RawTable
The implementation was introduced when changing hash storage from
Unique to *mut, but it was changed back to Unique.
2017-12-13 14:53:39 +01:00
bors
3dfbc88a62 Auto merge of #46550 - jseyfried:cleanup_builtin_hygiene, r=nrc
macros: hygienize use of `core`/`std` in builtin macros

Today, if a builtin macro wants to access an item from `core` or `std` (depending `#![no_std]`), it generates `::core::path::to::item` or `::std::path::to::item` respectively (c.f. `fn std_path()` in `libsyntax/ext/base.rs`).

This PR refactors the builtin macros to instead always emit `$crate::path::to::item` here. That is, the def site of builtin macros is taken to be in `extern crate core;` or `extern crate std;`. Since builtin macros are macros 1.0 (i.e. mostly unhygienic), changing the def site can only effect the resolution of `$crate`.

r? @nrc
2017-12-13 11:09:55 +00:00
Niko Matsakis
decbbb3fc0 when reifying a safe fn as an unsafe fn ptr, insert two casts
Otherwise, `run-pass/typeck-fn-to-unsafe-fn-ptr.rs` fails the MIR type checker.
2017-12-13 06:03:28 -05:00
Niko Matsakis
d5cff0740f normalize fn sig as part of reification 2017-12-13 06:03:28 -05:00
Santiago Pastorino
0c26d8fcd1 Mir typeck Cast for Unsize value 2017-12-13 06:03:28 -05:00
Santiago Pastorino
14700e58b4 Mir typeck Cast for ClosureFnPtr value 2017-12-13 06:03:27 -05:00
Santiago Pastorino
ae035cb731 Extract coerce_closure_fn_ty function 2017-12-13 06:03:27 -05:00
Santiago Pastorino
900d4d5bda Mir typeck Cast for UnsafeFnPtr value 2017-12-13 06:03:27 -05:00
Santiago Pastorino
7d56131e83 Mir typeck Cast for ReifyFnPtr value 2017-12-13 06:03:27 -05:00