Matthew Jasper [Sat, 11 Jan 2020 14:12:39 +0000 (14:12 +0000)]
Improve opaque type lifetime errors
* Use better span for member constraint errors
* Avoid a bad suggestion
* Don't report member constraint errors if we have other universal
region errors.
Dylan DPC [Thu, 13 Feb 2020 20:28:09 +0000 (21:28 +0100)]
Rollup merge of #69126 - RalfJung:exact-div, r=oli-obk
miri: fix exact_div
Turns out `exact_div` was relying on the broken behavior of `Rem` for `int_min % -1` that was fixed in https://github.com/rust-lang/rust/pull/69002. This PR fixes `exact_div`.
Inside rustc, `exact_div` is only used in a single place where the divisor is always positive (in `ptr_offset_from`), so we cannot test the fix in rustc. The Miri test suite covers this through the `exact_div` intrinsic, though (and it is how I found out).
One step to https://github.com/rust-lang/rust/issues/69117 (then we also need to address build failures introduced by https://github.com/rust-lang/rust/pull/68969)
Dylan DPC [Thu, 13 Feb 2020 20:27:58 +0000 (21:27 +0100)]
Rollup merge of #68728 - Centril:towards-fn-merge, r=petrochenkov
parse: merge `fn` syntax + cleanup item parsing
Here we continue the work in https://github.com/rust-lang/rust/pull/67131 in particular to merge the grammars of `fn` items in various positions.
A list of *language level* changes (as sanctioned by the language team in https://github.com/rust-lang/rust/issues/65041#issuecomment-538105286 and https://github.com/rust-lang/rust/pull/67131):
- `self` parameters are now *syntactically* allowed as the first parameter irrespective of item context (and in function pointers). Instead, semantic validation (`ast_validation`) is used.
- Syntactically, `fn` items in `extern { ... }` blocks can now have bodies (`fn foo() { ... }` as opposed to `fn foo();`). As above, we use semantic restrictions instead.
- Syntactically, `fn` items in free contexts (directly in a file or a module) can now be without bodies (`fn foo();` as opposed to `fn foo() { ... }`. As above, we use semantic restrictions instead, including for non-ident parameter patterns.
- `const extern fn` feature gating is now done post-expansion such that we do not have conditional compatibilities of function qualifiers *in parsing*.
That is, all item contexts now *syntactically* allow `const async unsafe extern "C" fn` and use semantic restrictions to rule out combinations previously prevented syntactically. The semantic restrictions include in particular:
- `fn`s in `extern { ... }` can have no qualifiers.
- `const` and `async` cannot be combined.
- To fuse the list-of-items parsing in the 4 contexts that items are allowed, we now must permit inner attributes (`#![attr]`) inside `trait Foo { ... }` definitions. That is, we now allow e.g. `trait Foo { #![attr] }`. This was probably an oversight due to not using a uniform parsing mechanism, which we now do have (`fn parse_item_list`). The semantic support (including e.g. for linting) falls out directly from the attributes infrastructure. To ensure this, we include a test for lints.
Put together, these grammar changes allow us to substantially reduce the complexity of item parsing and its grammar. There are however some other non-language improvements that allow the compression to take place.
A list of *compiler-internal* changes (in particular noting the parser-external data-structure changes):
- We use `enum AllowPlus/RecoverQPath/AllowCVariadic { Yes, No }` in `parser/ty.rs` instead of passing around 3 different `bool`s. I felt this was necessary as it was becoming mentally taxing to track which-is-which.
- `fn visit_trait_item` and `fn visit_impl_item` are merged into `fn visit_assoc_item` which now is passed an `AssocCtxt` to check which one it is.
This is then taken advantage of in tweaking the various semantic restrictions as well as in pretty printing.
- In `ItemKind::Fn`, we change `P<Block>` to `Option<P<Block>>`.
- In `ForeignItemKind::Fn`, we change `P<FnDecl>` to `FnSig` and `P<Block>` to `Option<P<Block>>`.
- We change `ast::{Unsafety, Spanned<Constness>}>` into `enum ast::{Unsafe, Const} { Yes(Span), No }` respectively. This change in formulation allow us to exclude `Span` in the case of `No`, which facilitates parsing. Moreover, we also add a `Span` to `IsAsync` which is renamed to `Async`. The new `Span`s in `Unsafety` and `Async` are then taken advantage of for better diagnostics. A reason this change was made is to have a more uniform and clear naming scheme.
The HIR keeps the structures in AST (with those definitions moved into HIR) for now to avoid regressing perf.
- Various cleanups, bug fixes, and diagnostics improvements are made along the way. It is probably best to understand those via the diffs.
I would recommend reviewing this commit-by-commit with whitespace changes hidden.
bors [Thu, 13 Feb 2020 12:53:43 +0000 (12:53 +0000)]
Auto merge of #68969 - RalfJung:dont-panic, r=oli-obk
remove Panic variant from InterpError
The interpreter engine itself does not raise `Panic` errors any more, so remove them from the error enum. Instead, const-prop and const-eval have to do their own handling of panics.
I used the opportunity to refactor the const-eval error handling a bit to use the `MachineStop` variant.
Also, in const-prop I could do some cleanup as now, no more lints are being reported in `use_ecx`. However, I am quite puzzled by why exactly the linting there works the way it does -- the code can certainly be cleaned up more, but I don't know enough of the intent to do that. I left some questions for the most confusing parts, but for now behavior should be unchanged by this PR (so, all that weirdness I am asking about is pre-existing and merely maintained here). Cc @wesleywiser
bors [Thu, 13 Feb 2020 09:42:10 +0000 (09:42 +0000)]
Auto merge of #69023 - Centril:parse_fn, r=petrochenkov
parse: unify function front matter parsing
Part of https://github.com/rust-lang/rust/pull/68728.
- `const extern fn` feature gating is now done post-expansion such that we do not have conditional compatibilities of function qualifiers *in parsing*.
That is, all item contexts now *syntactically* allow `const async unsafe extern "C" fn` and use semantic restrictions to rule out combinations previously prevented syntactically. The semantic restrictions include in particular:
- `fn`s in `extern { ... }` can have no qualifiers.
- `const` and `async` cannot be combined.
- We change `ast::{Unsafety, Spanned<Constness>}>` into `enum ast::{Unsafe, Const} { Yes(Span), No }` respectively. This change in formulation allow us to exclude `Span` in the case of `No`, which facilitates parsing. Moreover, we also add a `Span` to `IsAsync` which is renamed to `Async`. The new `Span`s in `Unsafety` and `Async` are then taken advantage of for better diagnostics. A reason this change was made is to have a more uniform and clear naming scheme.
The HIR keeps the structures in AST (with those definitions moved into HIR) for now to avoid regressing perf.
bors [Thu, 13 Feb 2020 04:57:41 +0000 (04:57 +0000)]
Auto merge of #69118 - Dylan-DPC:rollup-7hpm1fj, r=Dylan-DPC
Rollup of 9 pull requests
Successful merges:
- #67642 (Relax bounds on HashMap/HashSet)
- #68848 (Hasten macro parsing)
- #69008 (Properly use parent generics for opaque types)
- #69048 (Suggestion when encountering assoc types from hrtb)
- #69049 (Optimize image sizes)
- #69050 (Micro-optimize the heck out of LEB128 reading and writing.)
- #69068 (Make the SGX arg cleanup implementation a NOP)
- #69082 (When expecting `BoxFuture` and using `async {}`, suggest `Box::pin`)
- #69104 (bootstrap: Configure cmake when building sanitizer runtimes)
Dylan DPC [Thu, 13 Feb 2020 01:52:59 +0000 (02:52 +0100)]
Rollup merge of #69104 - tmiasko:configure-cmake, r=Mark-Simulacrum
bootstrap: Configure cmake when building sanitizer runtimes
Configure cmake before building sanitizer runtimes in similar way it is already
configured elsewhere, to ensure that they are built with expected compiler
flags.
Previously this step has been intentionally omitted since sanitizer runtimes
are built as universal binaries on Darwin targets, which in turn are
unsupported by sccache which is also configured there. To avoid the issue
everything but the compiler launcher is configured.
Dylan DPC [Thu, 13 Feb 2020 01:52:54 +0000 (02:52 +0100)]
Rollup merge of #69050 - nnethercote:micro-optimize-leb128, r=michaelwoerister
Micro-optimize the heck out of LEB128 reading and writing.
This commit makes the following writing improvements:
- Removes the unnecessary `write_to_vec` function.
- Reduces the number of conditions per loop from 2 to 1.
- Avoids a mask and a shift on the final byte.
And the following reading improvements:
- Removes an unnecessary type annotation.
- Fixes a dangerous unchecked slice access. Imagine a slice `[0x80]` --
the current code will read past the end of the slice some number of
bytes. The bounds check at the end will subsequently trigger, unless
something bad (like a crash) happens first. The cost of doing bounds
check in the loop body is negligible.
- Avoids a mask on the final byte.
And the following improvements for both reading and writing:
- Changes `for` to `loop` for the loops, avoiding an unnecessary
condition on each iteration. This also removes the need for
`leb128_size`.
All of these changes give significant perf wins, up to 5%.
Dylan DPC [Thu, 13 Feb 2020 01:52:53 +0000 (02:52 +0100)]
Rollup merge of #69049 - pthariensflame:improvement/imgbot, r=GuillaumeGomez
Optimize image sizes
This was done by [ImgBot](https://imgbot.net/) on my own fork, which I then immediately merged and turned into this manual pull request. Below is reproduced [ImgBot's own message](https://github.com/pthariensflame/rust/pull/3#issue-373452394) on the content of this PR.
r? @steveklabnik since this is a documentation PR, I guess.
Dylan DPC [Thu, 13 Feb 2020 01:52:51 +0000 (02:52 +0100)]
Rollup merge of #69048 - estebank:hrlt-assoc, r=nagisa
Suggestion when encountering assoc types from hrtb
When encountering E0212, detect whether this is a representable case or
not, i.e. if it's happening on an `fn` or on an ADT. If the former,
provide a structured suggestion, otherwise note that this can't be
represented in Rust.