Pietro Albini [Sun, 25 Nov 2018 16:05:02 +0000 (17:05 +0100)]
Rollup merge of #56100 - RalfJung:visiting-generators, r=oli-obk
generator fields are not necessarily initialized
Looking at the MIR we generate for generators, I think we deliberately leave fields of the generator uninitialized in ways that would be illegal if this was a normal struct (or rather, one would have to use `MaybeUninit`). Consider [this example](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=417b4a2950421b726dd7b307e9ee3bec):
```rust
#![feature(generators, generator_trait)]
fn main() {
let generator = || {
let mut x = Box::new(5);
{
let y = &mut *x;
*y = 5;
yield *y;
*y = 10;
}
*x
};
let _gen = generator;
}
```
It generates the MIR
```
fn main() -> (){
let mut _0: (); // return place
scope 1 {
scope 3 {
}
scope 4 {
let _2: [generator@src/main.rs:4:21: 13:6 for<'r> {std::boxed::Box<i32>, i32, &'r mut i32, ()}]; // "_gen" in scope 4 at src/main.rs:14:9: 14:13
}
}
scope 2 {
let _1: [generator@src/main.rs:4:21: 13:6 for<'r> {std::boxed::Box<i32>, i32, &'r mut i32, ()}]; // "generator" in scope 2 at src/main.rs:4:9: 4:18
}
bb1: {
StorageDead(_2); // bb1[0]: scope 1 at src/main.rs:15:1: 15:2
StorageDead(_1); // bb1[1]: scope 0 at src/main.rs:15:1: 15:2
return; // bb1[2]: scope 0 at src/main.rs:15:2: 15:2
}
}
```
Notice how we only initialize the first field of `_1` (even though it contains a `Box`!), and then assign it to `_2`. This violates the rule "on assignment, all data must satisfy the validity invariant", and hence miri complains about this code.
What this PR effectively does is to change the validity invariant for generators such that it says nothing about the fields of the generator. We behave as if every field of the generator was wrapped in a `MaybeUninit`.
r? @oli-obk
Cc @nikomatsakis @eddyb @cramertj @withoutboats @Zoxc
Pietro Albini [Sun, 25 Nov 2018 16:05:01 +0000 (17:05 +0100)]
Rollup merge of #56075 - alexcrichton:wasm-producer-section, r=estebank
Encode a custom "producers" section in wasm files
This commit implements WebAssembly/tool-conventions#65 for wasm files
produced by the Rust compiler. This adds a bit of metadata to wasm
modules to indicate that the file's language includes Rust and the
file's "processed-by" tools includes rustc.
The thinking with this section is to eventually have telemetry in
browsers tracking all this.
Pietro Albini [Sun, 25 Nov 2018 16:04:58 +0000 (17:04 +0100)]
Rollup merge of #56045 - qnighy:additional-sizedness, r=cramertj
Check arg/ret sizedness at ExprKind::Path
This PR solves three problems:
- #50940: ICE on casting unsized tuple struct constructors
- Unsized tuple struct constructors were callable in presence of `unsized_locals`.
- https://github.com/rust-lang/rust/issues/48055#issuecomment-437178966: we cannot relax `Sized` bounds on stable functions because of fn ptr casting
These are caused by lack of `Sized`ness checks for arguments/retvals at **reference sites of `FnDef` items** (not call sites of the functions). Therefore we can basically add more `Sized` obligations on typeck. However, adding `Sized` obligations arbitrarily breaks type inference; to prevent that I added a new method `require_type_is_sized_deferred` which doesn't interfere usual type inference.
bors [Sun, 25 Nov 2018 12:20:18 +0000 (12:20 +0000)]
Auto merge of #55906 - nnethercote:rm-OpenSnapshot-CommittedSnapshot, r=nikomatsakis
Clean up and streamline snapshot data structures
These commits clean up the snapshot structures a bit, so they are more consistent with each other and with the `ena` crate.
They also remove the `OpenSnapshot` and `CommittedSnapshot` entries in the undo log, just like I did for the `ena` crate in https://github.com/rust-lang-nursery/ena/pull/14. This PR in combination with that `ena` PR reduces instruction counts by up to 6% on benchmarks.
r? @nikomatsakis. Note that this isn't quite ready for landing, because the `ena` dependency in the first commit needs to be updated once https://github.com/rust-lang-nursery/ena/pull/14 lands. But otherwise it should be good.
Remove `OpenSnapshot` and `CommittedSnapshot` markers from `RegionConstraintCollector`.
They're not strictly necessary, and they result in the `Vec` being
allocated even for the trivial (and common) case where a
`start_snapshot` is immediately followed by a `commit` or `rollback_to`.
The commit also removes a now-unnecessary argument of
`pop_placeholders()`.
Remove `OpenSnapshot` and `CommittedSnapshot` markers from `SnapshotMap`.
They're not strictly necessary, and they result in the `Vec` being
allocated even for the trivial (and common) case where a
`start_snapshot` is immediately followed by a `commit` or `rollback_to`.
This commit also renames `UndoLog::Noop` as `UndoLog::Purged`, because
(a) that's a more descriptive name and (b) it matches the name used in
similar code in `librustc/infer/region_constraints/mod.rs`.
bors [Sun, 25 Nov 2018 03:00:30 +0000 (03:00 +0000)]
Auto merge of #55959 - matthewjasper:remove-end-region, r=nikomatsakis
Cleanup from lexical MIR borrowck removal
Lexical MIR borrowck was removed months ago now, and `EndRegion`s are no longer used for MIRI verification.
* Remove `rustc::mir::StatementKind::EndRegion` and the `-Zemit_end_regions` flag
* Use `RegionVid` instead of `Region` in BorrowSet
* Rewrite drop generation to create fewer goto terminators.
We suspect this causes the spurious failure in https://github.com/rust-lang/rust/pull/55906#issuecomment-441365922 and https://github.com/rust-lang/rust/pull/55915#issuecomment-441377543.
bors [Fri, 23 Nov 2018 23:12:11 +0000 (23:12 +0000)]
Auto merge of #55935 - alexcrichton:vs2017, r=Mark-Simulacrum
appveyor: Use VS2017 for all our images
This was [recommended by AppVeyor][1] to see if it has any impact on our
build times, hopefully on the beneficial side of things! This shouldn't
affect our binary compatibility for generated compilers like it would
normally do for Linux.
bors [Fri, 23 Nov 2018 18:42:20 +0000 (18:42 +0000)]
Auto merge of #56186 - kennytm:rollup, r=kennytm
Rollup of 14 pull requests
Successful merges:
- #55767 (Disable some pretty-printers when gdb is rust-enabled)
- #55838 (Fix #[cfg] for step impl on ranges)
- #55869 (Add std::iter::unfold)
- #55945 (Ensure that the argument to `static_assert` is a `bool`)
- #56022 (When popping in CTFE, perform validation before jumping to next statement to have a better span for the error)
- #56048 (Add rustc_codegen_ssa to sysroot)
- #56091 (Fix json output in the self-profiler)
- #56097 (Fix invalid bitcast taking bool out of a union represented as a scalar)
- #56116 (ci: Download clang/lldb from tarballs)
- #56120 (Add unstable Literal::subspan().)
- #56154 (Pass additional linker flags when targeting Fuchsia)
- #56162 (std::str Adapt documentation to reality)
- #56163 ([master] Backport 1.30.1 release notes)
- #56168 (Fix the tracking issue for hash_raw_entry)
kennytm [Fri, 23 Nov 2018 17:31:59 +0000 (01:31 +0800)]
Rollup merge of #56154 - petrhosek:fuchsia-linker-args, r=alexcrichton
Pass additional linker flags when targeting Fuchsia
This is a follow up to 8aa9267 which changed the driver to use lld
directly rather than invoking it through Clang. This change ensures
we pass all the necessary flags to lld.
kennytm [Fri, 23 Nov 2018 17:31:50 +0000 (01:31 +0800)]
Rollup merge of #55869 - SimonSapin:iterate, r=alexcrichton
Add std::iter::unfold
This adds an **unstable** ~`std::iter::iterate`~ `std::iter::unfold` function and ~`std::iter::Iterate`~ `std::iter::Unfold` type that trivially wrap a ~`FnMut() -> Option<T>`~ `FnMut(&mut State) -> Option<T>` closure to create an iterator. ~Iterator state can be kept in the closure’s environment or captures.~
This is intended to help reduce amount of boilerplate needed when defining an iterator that is only created in one place. Compare the existing example of the `std::iter` module: (explanatory comments elided)
This also add unstable `std::iter::successors` which takes an (optional) initial item and a closure that takes an item and computes the next one (its successor).
kennytm [Fri, 23 Nov 2018 17:31:47 +0000 (01:31 +0800)]
Rollup merge of #55767 - tromey:disable-some-pretty-printers, r=alexcrichton
Disable some pretty-printers when gdb is rust-enabled
A rust-enabled gdb already knows how to display string slices,
structs, tuples, and enums (and after #54004, the pretty-printers
can't handle enums at all). This patch disables these pretty-printers
when gdb is rust-enabled.
The "gdb-pretty-struct-and-enums-pre-gdb-7-7.rs" test is renamed,
because it does not seem to depend on any behavior of that version of
gdb, and because gdb 7.7 is 4 years old now.
bors [Fri, 23 Nov 2018 11:26:48 +0000 (11:26 +0000)]
Auto merge of #55808 - estebank:type-arguments, r=petrochenkov
Suggest correct syntax when writing type arg instead of assoc type
- When confusing an associated type with a type argument, suggest the appropriate syntax. Given `Iterator<isize>`, suggest `Iterator<Item = isize>`.
- When encountering multiple missing associated types, emit only one diagnostic.
- Point at associated type def span for context.
- Point at each extra type argument.
bors [Fri, 23 Nov 2018 01:02:21 +0000 (01:02 +0000)]
Auto merge of #54071 - eddyb:alignsssss, r=oli-obk
rustc_target: separate out an individual alignment quantity type from Align.
Before this PR, `rustc_target::abi::Align` combined "power-of-two alignment quantity" semantics, with a distinction between ABI (required) and preferred alignment (by having two quantities).
After this PR, `Align` is only *one* such quantity, and a new `AbiAndPrefAlign` type is introduced to hold the pair of ABI and preferred `Align` quantities.
`Align` is used everywhere one quantity is necessary/sufficient, simplifying some of the code in codegen/miri, while `AbiAndPrefAlign` only in layout computation (to propagate preferred alignment).
bors [Thu, 22 Nov 2018 20:29:51 +0000 (20:29 +0000)]
Auto merge of #56143 - nikomatsakis:issue-56128-segment-id-ice-nightly, r=petrochenkov
Issue 56128 segment id ice nightly
Tentative fix for #56128
From what I can tell, the problem is that if you have `pub(super) use foo::{a, b}`, then when we explode the `a` and `b`, the segment ids from the `super` path were not getting cloned. However, once I fixed *that*, then I ran into a problem that the "visibility" node-ids were not present in the final HIR -- this is because the visibility of the "stem" that is returned in this case was getting reset to inherited. I don't *think* it is a problem to undo that, so that the visibility is returned unmodified.