bors [Mon, 11 Jan 2016 15:26:57 +0000 (15:26 +0000)]
Auto merge of #30676 - nikomatsakis:issue-29857, r=arielb1
This is an alternative to https://github.com/rust-lang/rust/pull/29954 for fixing #29857 that seems to me to be more inline with the general strategy around `TyError`. It also includes the fix for #30589 -- in fact, just the minimal change of making `ty_is_local` tolerate `TyError` avoids the ICE, but you get a lot of duplicate error reports, so in the case where the impl's trait reference already includes `TyError`, we just ignore the impl altogether.
bors [Mon, 11 Jan 2016 10:19:44 +0000 (10:19 +0000)]
Auto merge of #30490 - ipetkov:unix-spawn, r=alexcrichton
* If the requested descriptors to inherit are stdio descriptors there
are situations where they will not be set correctly
* Example: parent's stdout --> child's stderr
parent's stderr --> child's stdout
* Solution: if the requested descriptors for the child are stdio
descriptors, `dup` them before overwriting the child's stdio
Example of a program which exhibits the bug:
```rust
// stdio.rs
use std::io::Write;
use std::io::{stdout, stderr};
use std::process::{Command, Stdio};
use std::os::unix::io::FromRawFd;
bors [Mon, 11 Jan 2016 08:32:46 +0000 (08:32 +0000)]
Auto merge of #27807 - pczarn:arena-internals, r=bluss
Fixes #18037 "TypedArena cannot handle zero-sized types".
Closes #17931 "improve chunk allocation scheme used by Arena / TypedArena".
Closes #22847 "TypedArena should implement Send". - N.B. Arena cannot implement Send, since it may contain non-Send values.
Closes #18471 "`Arena::alloc_copy_inner` (at least) should be renamed and made public." - Added `Arena::alloc_bytes`.
Closes #18261 "support clearing TypedArena with the chunks preserved". - Only the largest chunk is preserved.
bors [Mon, 11 Jan 2016 06:40:58 +0000 (06:40 +0000)]
Auto merge of #30295 - jseyfried:fix_extern_crate_duplicate, r=nrc
Fix a bug allowing an item and an external crate to collide so long as the external crate is declared after the item. For example,
```rust
mod core { pub fn f() {} } // This would be an error if it followed the `extern crate`
extern crate core; // This declaration is shadowed by the preceding module
fn main() { core::f(); }
```
This is a [breaking-change], but it looks unlikely to cause breakage in practice, and any breakage can be fixed by removing colliding `extern crate` declarations, which are shadowed and hence unused.
Steve Klabnik [Sat, 9 Jan 2016 19:04:20 +0000 (14:04 -0500)]
Rollup merge of #30771 - tsion:mir-text-terminator-fix, r=eddyb
This just removes the `Some()` that appeared around terminators in MIR text output after https://github.com/rust-lang/rust/pull/30481 (cc @nagisa). The graphviz is already fixed.
Ariel Ben-Yehuda [Wed, 25 Nov 2015 16:17:16 +0000 (18:17 +0200)]
improve cast handling - this fixes test failures
the problem is that now "type_is_known_to_be_sized" now returns
false when called on a type with ty_err inside - this prevents
spurious errors (we may want to move the check to check::cast
anyway - see #12894).
Steve Klabnik [Fri, 8 Jan 2016 18:02:31 +0000 (13:02 -0500)]
Rollup merge of #30760 - jonastepe:nomicon_vec_insert_remove_len, r=apasel422
len needs to be prefixed by self for this to work. That is something which trips me up all the time. It's reassuring to see that happening to seasoned Rust programmers.
Steve Klabnik [Fri, 8 Jan 2016 18:02:31 +0000 (13:02 -0500)]
Rollup merge of #30755 - datagrok:master, r=steveklabnik
I'm working my way through TRPL beginning at "Syntax and Semantics" as was recommended in a previous version.
I'm expecting the chapter to incrementally build up my knowledge of the language section by section, assuming no prior Rust experience. So it was a bit of a speed-bump to encounter references and the vector type in a code example long before they had been defined and explained.
Another commit in this PR tries to make consistent what is a "chapter" of TRPL versus a "section." Just a nit-pick, but not thinking about that stuff keeps my focus on the important material.
My background: Python programmer since ~2000, with moderate exposure to C, C++, assembly, operating systems, and system architecture in university several years ago.
For your kind consideration, feel welcome to use or drop or rework any part of this.
Steve Klabnik [Fri, 8 Jan 2016 18:02:30 +0000 (13:02 -0500)]
Rollup merge of #30747 - nagisa:mir-reenable-test, r=nikomatsakis
Fixes #30674
The test seems to work fine and assertion passes. The test seems to also be generated from MIR (LLVM IR has footprint of MIR translator), thus I’m reenabling it.
bors [Thu, 7 Jan 2016 22:54:22 +0000 (22:54 +0000)]
Auto merge of #30757 - michaelwoerister:mir-visitor-cleanup, r=jroesch
After a call to `visit_def_id()` missing in `mir::visit::Visitor` but not `mir::visit::MutVisitor` has caused me a couple hours of error hunting, I decided I'd take the time to get rid of the code duplication between the two implementations.
bors [Thu, 7 Jan 2016 14:22:49 +0000 (14:22 +0000)]
Auto merge of #30734 - tsion:mir-pretty, r=nikomatsakis
* Put `const` in front of every `ConstVal`.
* Pretty-print bytestrings as they appear in Rust source.
* Pretty-print `ConstVal::{Struct, Tuple, Array, Repeat}` by pretty-printing the `ast::NodeId`. This is a temporary measure, and probably not perfect, but I'm avoiding anything more complex since I hear the const evaluator might not be AST-based in the near future.
```rust
struct Point {
x: i32,
y: i32,
}
fn consts() {
let _float = 3.14159;
let _non_const_int = -42;
const INT: i32 = -42;
let _int = INT;
let _uint = 42u32;
let _str = "a string";
let _bytestr = b"a bytes\xFF\n\ttri\'\"\\ng";
let _bool = true;
const STRUCT: Point = Point { x: 42, y: 42 };
let _struct = STRUCT;
const EXTERNAL_STRUCT: std::sync::atomic::AtomicUsize = std::sync::atomic::ATOMIC_USIZE_INIT;
let _external_struct = EXTERNAL_STRUCT;
const TUPLE: (i32, &'static str, &'static [u8; 5]) = (1, "two", b"three");
let _tuple = TUPLE;
const FUNC: fn() = consts;
let _function = FUNC;
let _non_const_function = consts;
const ARRAY: [&'static str; 3] = ["a", "b", "c"];
let _array = ARRAY;
const REPEAT: [&'static [u8; 3]; 10] = [b"foo"; 10];
let _repeat = REPEAT;
}
```
```diff
--- consts-old.mir 2016-01-05 23:23:14.163807017 -0600
+++ consts-new.mir 2016-01-05 23:04:51.121386151 -0600
@@ -1,45 +1,45 @@
fn() -> () {
let var0: f64; // _float
let var1: i32; // _non_const_int
let var2: i32; // _int
let var3: u32; // _uint
let var4: &str; // _str
let var5: &[u8; 18]; // _bytestr
let var6: bool; // _bool
let var7: Point; // _struct
let var8: core::sync::atomic::AtomicUsize; // _external_struct
let var9: (i32, &str, &[u8; 5]); // _tuple
let var10: fn(); // _function
let var11: fn() {consts}; // _non_const_function
let var12: [&str; 3]; // _array
let var13: [&[u8; 3]; 10]; // _repeat
let mut tmp0: ();
bors [Thu, 7 Jan 2016 11:48:35 +0000 (11:48 +0000)]
Auto merge of #30317 - jseyfried:refactor_type_folder, r=nikomatsakis
`TypeFoldable`s can currently be visited inefficiently with an identity folder that is run only for its side effects. This creates a more efficient visitor for `TypeFoldable`s and uses it to implement `RegionEscape` and `HasProjectionTypes`, fixing cleanup issue #20298.
This is a pure refactoring.
bors [Thu, 7 Jan 2016 06:32:56 +0000 (06:32 +0000)]
Auto merge of #30724 - nikomatsakis:feature-gate-defaulted-type-parameters, r=pnkfelix
It was recently realized that we accept defaulted type parameters everywhere, without feature gate, even though the only place that we really *intended* to accept them were on types. This PR adds a lint warning unless the "type-parameter-defaults" feature is enabled. This should eventually become a hard error.
This is a [breaking-change] in that new feature gates are required (or simply removing the defaults, which is probably a better choice as they have little effect at this time). Results of a [crater run][crater] suggest that approximately 5-15 crates are affected. I didn't do the measurement quite right so that run cannot distinguish "true" regressions from "non-root" regressions, but even the upper bound of 15 affected crates seems relatively minimal.
Michael F. Lamb [Thu, 7 Jan 2016 00:02:03 +0000 (16:02 -0800)]
Link to references section when they first appear
In a straight-through read of "Syntax and Semantics," the concept of a
"reference" is used here before it is explained. Mention that and link to
the section explaining references.
Michael F. Lamb [Wed, 6 Jan 2016 23:46:58 +0000 (15:46 -0800)]
Explain surprising new syntax appearing in example code
In a straight-through read of "Syntax and Semantics," the first time we
meet a generic, and the first time we meet a vector, is when a Vec<T> shows
up in this example. I'm not sure that I could argue that the whole section
should appear later in the book than the ones on vectors and generics, so
instead just give the reader a brief introduction to both and a promise to
follow up later.
Steve Klabnik [Wed, 6 Jan 2016 23:31:58 +0000 (18:31 -0500)]
Rollup merge of #30735 - jonastepe:nomicon_vec_dealloc_pointer_type, r=steveklabnik
heap::deallocate expects a *mut u8, but here a *mut T is given as the type of the argument. This would not compile. The final code is correct, however.
Steve Klabnik [Wed, 6 Jan 2016 23:31:58 +0000 (18:31 -0500)]
Rollup merge of #30729 - huonw:delete-bad-comment, r=sanxiyn
The fundamental problem of duplication was fixed in https://github.com/rust-lang/rust/pull/10891, but the comment was preserved. Closes https://github.com/rust-lang/rust/issues/9762.
Steve Klabnik [Wed, 6 Jan 2016 23:31:58 +0000 (18:31 -0500)]
Rollup merge of #30727 - tbu-:pr_doc_escaped_newline, r=steveklabnik
Rust differs in that behavior from C: In C, the newline escapes are resolved
before anything else, and in Rust this depends on whether the backslash is
escaped itself.
A difference can be observed in the following two programs:
```c
int main()
{
printf("\\
n\n");
return 0;
}
```
```rust
fn main() {
println!("\\
n");
}
```
The first program prints two newlines, the second one prints a backslash, a
newline, the latin character n and a final newline.
Steve Klabnik [Wed, 6 Jan 2016 23:31:56 +0000 (18:31 -0500)]
Rollup merge of #30683 - LawrenceWoodman:patch-1, r=steveklabnik
I noticed the alignment was off in the error handling part of the book. This was caused because two tabs had crept into the file. I have changed these for spaces.
bors [Wed, 6 Jan 2016 18:37:57 +0000 (18:37 +0000)]
Auto merge of #30532 - nikomatsakis:cross-item-dependencies, r=mw
This is roughly the same as my previous PR that created a dependency graph, but that:
1. The dependency graph is only optionally constructed, though this doesn't seem to make much of a difference in terms of overhead (see measurements below).
2. The dependency graph is simpler (I combined a lot of nodes).
3. The dependency graph debugging facilities are much better: you can now use `RUST_DEP_GRAPH_FILTER` to filter the dep graph to just the nodes you are interested in, which is super help.
4. The tests are somewhat more elaborate, including a few known bugs I need to fix in a second pass.
This is potentially a `[breaking-change]` for plugin authors. If you are poking about in tcx state or something like that, you probably want to add `let _ignore = tcx.dep_graph.in_ignore();`, which will cause your reads/writes to be ignored and not affect the dep-graph.
After this, or perhaps as an add-on to this PR in some cases, what I would like to do is the following:
- [x] Write-up a little guide to how to use this system, the debugging options available, and what the possible failure modes are.
- [ ] Introduce read-only and perhaps the `Meta` node
- [x] Replace "memoization tasks" with node from the map itself
- [ ] Fix the shortcomings, obviously! Notably, the HIR map needs to register reads, and there is some state that is not yet tracked. (Maybe as a separate PR.)
- [x] Refactor the dep-graph code so that the actual maintenance of the dep-graph occurs in a parallel thread, and the main thread simply throws things into a shared channel (probably a fixed-size channel). There is no reason for dep-graph construction to be on the main thread. (Maybe as a separate PR.)
Regarding performance: adding this tracking does add some overhead, approximately 2% in my measurements (I was comparing the build times for rustdoc). Interestingly, enabling or disabling tracking doesn't seem to do very much. I want to poke at this some more and gather a bit more data -- in some tests I've seen that 2% go away, but on others it comes back. It's not entirely clear to me if that 2% is truly due to constructing the dep-graph at all.
The next big step after this is write some code to dump the dep-graph to disk and reload it.
bors [Wed, 6 Jan 2016 13:11:18 +0000 (13:11 +0000)]
Auto merge of #30481 - nagisa:mir-calls-2, r=nikomatsakis
r? @nikomatsakis
This is a pretty big PR conflating changes to a few different block terminators (Call, DivergingCall, Panic, Resume, Diverge), because they are somewhat closely related.
Each commit has a pretty good description on what is being changed in each commit. The end result is greatly simplified CFG and translation for calls (no success branch if the function is diverging, no cleanup branch if there’s nothing to cleanup etc).
This considerably simplifies code around calling functions and translation of Resume itself. This
removes requirement that a block containing Resume terminator is always translated after something
which creates a landing pad, thus allowing us to actually translate some valid MIRs we could not
translate before.
However, an assumption is added that translator is correct (in regards to landing pad generation)
and code will never reach the Resume terminator without going through a landing pad first. Breaking
these assumptions would pass an `undef` value into the personality functions.
This merges two separate Call terminators and uses a separate CallKind sub-enum instead.
A little bit unrelatedly, copying into destination value for a certain kind of invoke, is also
implemented here. See the associated comment in code for various details that arise with this
implementation.
DivergingCall is different enough from the regular converging Call to warrant the split. This also
inlines CallData struct and creates a new CallTargets enum in order to have a way to differentiate
between calls that do not have an associated cleanup block.
Note, that this patch still does not produce DivergingCall terminator anywhere. Look for that in
the next patches.
jonastepe [Wed, 6 Jan 2016 11:13:47 +0000 (12:13 +0100)]
heap::deallocate expects a *mut u8 but here a *mut T is given. The final code is correct, the example here would not compile without the cast. I used *mut _ instead of *mut u8 to be consistent with the final code.
bors [Wed, 6 Jan 2016 09:00:57 +0000 (09:00 +0000)]
Auto merge of #30692 - michaelwoerister:mir-overloaded-fn-calls, r=nikomatsakis
So far, calls going through `Fn::call`, `FnMut::call_mut`, or `FnOnce::call_once` have not been translated properly into MIR:
The call `f(a, b, c)` where `f: Fn(T1, T2, T3)` would end up in MIR as:
```
call `f` with arguments `a`, `b`, `c`
```
What we really want is:
```
call `Fn::call` with arguments `f`, `a`, `b`, `c`
```
This PR transforms these kinds of overloaded calls during `HIR -> HAIR` translation.
What's still a bit funky is that the `Fn` traits expect arguments to be tupled but due to special handling type-checking and trans, we do not actually tuple arguments and everything still checks out fine. So, after this PR we end up with MIR containing calls where function signature and arguments seemingly don't match:
```
call Fn::call(&self, args: (T1, T2, T3)) with arguments `f`, `a`, `b`, `c`
```
instead of
```
call Fn::call(&self, args: (T1, T2, T3)) with arguments `f`, (`a`, `b`, `c`) // <- args tupled!
```
It would be nice if the call traits could go without special handling in MIR and later on.
Niko Matsakis [Tue, 22 Dec 2015 22:17:57 +0000 (17:17 -0500)]
Refactor overlap checker so that it walks the HIR instead of poking into
random tables. The old code was weird anyway because it would
potentially walk traits from other crates etc. The new code fits
seamlessly with the dependency tracking.