Commit Graph

49224 Commits

Author SHA1 Message Date
Steve Klabnik
05874de412 Link Nomicon in PhantomData's docs
Fixes #30069
2016-01-07 14:18:15 -05:00
bors
03f4950239 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: ();

     bb0: {
-        var0 = 3.14159;
-        var1 = Neg(42);
-        var2 = -42;
-        var3 = 42;
-        var4 = Str("a string");
-        var5 = ByteStr[97, 32, 98, 121, 116, 101, 115, 255, 10, 9, 116, 114, 105, 39, 34, 92, 110, 103];
-        var6 = true;
-        var7 = Struct(51);
+        var0 = const 3.14159;
+        var1 = Neg(const 42);
+        var2 = const -42;
+        var3 = const 42;
+        var4 = const "a string";
+        var5 = const b"a bytes\xff\n\ttri\'\"\\ng";
+        var6 = const true;
+        var7 = const expr Point{x: 42, y: 42,};
         var8 = consts::EXTERNAL_STRUCT;
-        var9 = Tuple(78);
-        var10 = Function(DefId { krate: 0, node: DefIndex(7) => consts });
+        var9 = const expr (1, "two", b"three");
+        var10 = const consts;
         var11 = consts;
-        var12 = Array(105, 3);
-        var13 = Repeat(122, 10);
+        var12 = const expr ["a", "b", "c"];
+        var13 = const expr [b"foo"; 10];
         drop var8;
         drop var7;
         goto -> bb1;
     }

     bb1: {
         return;
     }

     bb2: {
         diverge;
     }
 }
```
2016-01-07 14:22:49 +00:00
bors
1e8350387c 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.
2016-01-07 11:48:35 +00:00
bors
2edb1d9b96 Auto merge of #30728 - athaeryn:mention-warning-lint-group, r=Manishearth
Fixes #30203.

This is my first time writing Rust, and I think this code could be a bit better. Any suggestions?
2016-01-07 08:24:36 +00:00
bors
91b27ec9be 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.

[crater]: https://gist.github.com/nikomatsakis/760c6a67698bd24253bf

cc @rust-lang/lang
r? @pnkfelix
2016-01-07 06:32:56 +00:00
bors
440671751e Auto merge of #30723 - nrc:macro-err-bug, r=Manishearth
Fixes #30715
2016-01-07 04:44:14 +00:00
bors
3ed6e9e6f0 Auto merge of #30557 - sfackler:panic-propagate, r=aturon
See rust-lang/rfcs#1413.

r? @alexcrichton
2016-01-07 01:26:45 +00:00
Jeffrey Seyfried
6327563963 Rename fold_subitems_with to super_fold_with 2016-01-07 00:42:30 +00:00
Jeffrey Seyfried
76021d84b3 Refactor away extension traits RegionEscape and HasTypeFlags 2016-01-07 00:42:12 +00:00
Jeffrey Seyfried
f9808ea4b4 Create a visitor for TypeFoldables and use it to implement RegionEscape and HasTypeFlags (fixes #20298) 2016-01-07 00:40:18 +00:00
Steven Fackler
022c9c70c4 Add std::panic::propagate 2016-01-06 16:06:11 -08:00
bors
43403b4169 Auto merge of #30750 - steveklabnik:rollup, r=steveklabnik
- Successful merges: #30683, #30698, #30699, #30700, #30716, #30720, #30727, #30729, #30735, #30749
- Failed merges:
2016-01-06 23:35:13 +00:00
Steve Klabnik
6cca775865 Rollup merge of #30749 - andgra2:patch-1, r=steveklabnik 2016-01-06 18:31:58 -05:00
Steve Klabnik
e78de13783 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.
2016-01-06 18:31:58 -05:00
Steve Klabnik
d91518b9c4 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.
2016-01-06 18:31:58 -05:00
Steve Klabnik
fcb1ccf8c0 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.
2016-01-06 18:31:58 -05:00
Steve Klabnik
eb41060ce2 Rollup merge of #30720 - BChip:patch-1, r=steveklabnik
Declare what LIFO stands for
2016-01-06 18:31:57 -05:00
Steve Klabnik
23c88ff013 Rollup merge of #30716 - kraai:fix-hexicdecimal, r=apasel422 2016-01-06 18:31:57 -05:00
Steve Klabnik
48e9d192c0 Rollup merge of #30700 - steveklabnik:gh28581, r=brson
Fixes #28581
2016-01-06 18:31:57 -05:00
Steve Klabnik
ba41e3c292 Rollup merge of #30699 - steveklabnik:gh30254, r=apasel422
Fixes #30254
2016-01-06 18:31:57 -05:00
Steve Klabnik
9239b64cd6 Rollup merge of #30698 - steveklabnik:gh29649, r=brson
Fixes #29649

r? @retep998 @alexcrichton
2016-01-06 18:31:57 -05:00
Steve Klabnik
4c90f5dc9f 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.
2016-01-06 18:31:56 -05:00
Anders Granlund
7205d6b580 Fix error in example code 2016-01-07 00:09:26 +01:00
bors
5daa75373d Auto merge of #30654 - nrc:panictry, r=brson
The motivation (other than removing boilerplate) is that this is a baby step towards a parser with error recovery.

[breaking-change] if you use any of the changed functions, you'll need to remove a try! or panictry!
2016-01-06 20:30:55 +00:00
bors
e8c337b5ca 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.

r? @michaelwoerister
2016-01-06 18:37:57 +00:00
Niko Matsakis
93996b160c Fix dependency graph test cases to have correct commments and use -Z incr-comp 2016-01-06 11:29:00 -05:00
Niko Matsakis
876de6e495 Fix tidy errors 2016-01-06 11:28:53 -05:00
Niko Matsakis
0c8ee65020 Use memoized helper more often. 2016-01-06 10:16:58 -05:00
bors
21b025f55f Auto merge of #30733 - ubsan:wrapping_op_assign, r=eddyb
Fix a breaking change in #30523

While this does fix a breaking change, it is also, technically, a
[breaking-change] to go back to our original way
2016-01-06 15:00:17 +00:00
Niko Matsakis
a9d7e36668 Fix numerous typos, renamings, and minor nits raised by mw. 2016-01-06 09:19:19 -05:00
bors
d5ac1a1da3 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).

Fixes https://github.com/rust-lang/rust/issues/30480
Fixes https://github.com/rust-lang/rust/issues/29767
Partialy solves https://github.com/rust-lang/rust/issues/29575
Fixes https://github.com/rust-lang/rust/issues/29573
2016-01-06 13:11:18 +00:00
Simonas Kazlauskas
36b3951c73 Create personality slot when translating Resume
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.
2016-01-06 13:57:52 +02:00
Simonas Kazlauskas
f9814242dc panic/panic_bounds_check to destructure tys
Not any more beautiful.
2016-01-06 13:57:52 +02:00
Simonas Kazlauskas
d1c644c1e9 Merge Call and DivergingCall diffs into CallKind
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.
2016-01-06 13:57:52 +02:00
Simonas Kazlauskas
50107034c0 Add tests 2016-01-06 13:57:52 +02:00
Simonas Kazlauskas
cef6aee369 Don’t generate landing-pads if -Z no-landing-pads 2016-01-06 13:57:52 +02:00
Simonas Kazlauskas
20ec53a0d3 Fix ReturnPointer generation for void return types
Fixes #30480
2016-01-06 13:57:52 +02:00
Simonas Kazlauskas
924bb1e5eb Refine call terminator translation
* Implement landing pads; and
* Implement DivergingCall translation; and
* Modernise previous implementation of Call somewhat.
2016-01-06 13:57:51 +02:00
Simonas Kazlauskas
a1e13983f7 Have a cached unreachable block inside MIR state
It is useful for various cases where direct unreachable cannot be translated and a separate block
is necessary.
2016-01-06 13:57:51 +02:00
Simonas Kazlauskas
4e86dcdb72 Remove diverge terminator
Unreachable terminator can be contained all within the trans.
2016-01-06 13:57:51 +02:00
Simonas Kazlauskas
5b34690842 Remove the Panic block terminator 2016-01-06 13:57:51 +02:00
Simonas Kazlauskas
ecf4d0e3ad Add Resume Terminator which corresponds to resume
Diverge should eventually go away
2016-01-06 13:57:51 +02:00
Simonas Kazlauskas
6f18b559df Generate DivergingCall terminator
This simplifies CFG greatly for some cases :)
2016-01-06 13:57:47 +02:00
Simonas Kazlauskas
893a66d7a1 Split Call into Call and DivergingCall
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.
2016-01-06 13:40:57 +02:00
jonastepe
eb30c661c0 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. 2016-01-06 12:13:47 +01:00
bors
7312e0a163 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.
2016-01-06 09:00:57 +00:00
Mike Anderson
5038d4e8ef std::cmp::max -> max 2016-01-06 00:42:19 -06:00
Nicholas Mazzuca
14e1e2aee8 Fix a breaking change in #30523
While this does fix a breaking change, it is also, technically, a
[breaking-change] to go back to our original way
2016-01-05 22:16:03 -08:00
Scott Olson
b2903d87c9 Improve pretty-printing for ConstVals in MIR. 2016-01-05 23:08:16 -06:00
Niko Matsakis
11c671b59c Workaround stage0 bug 2016-01-05 21:05:51 -05:00