Commit graph

2390 commits

Author SHA1 Message Date
bors fa55f668e5 Auto merge of #79721 - Aaron1011:fix/reuse-def-path-hash, r=wesleywiser
Properly re-use def path hash in incremental mode

Fixes #79661

In incremental compilation mode, we update a `DefPathHash -> DefId`
mapping every time we create a `DepNode` for a foreign `DefId`.
This mapping is written out to the on-disk incremental cache, and is
read by the next compilation session to allow us to lazily decode
`DefId`s.

When we decode a `DepNode` from the current incremental cache, we need
to ensure that any previously-recorded `DefPathHash -> DefId` mapping
gets recorded in the new mapping that we write out. However, PR #74967
didn't do this in all cases, leading to us being unable to decode a
`DefPathHash` in certain circumstances.

This PR refactors some of the code around `DepNode` deserialization to
prevent this kind of mistake from happening again.
2020-12-09 13:54:07 +00:00
bors cc03ee6702 Auto merge of #78679 - oli-obk:temp_lifetime, r=eddyb
Also generate `StorageDead` in constants

r? `@eddyb`

None of this special casing is actually necessary since we started promoting within constants and statics.

We may want to keep some of it around out of perf reasons, but it's not required for user visible behaviour

somewhat related: #68622
2020-12-09 11:31:32 +00:00
oli 84fe7cf24e Also generate StorageDead in constants 2020-12-09 10:59:10 +00:00
bors c0bfe3485f Auto merge of #78363 - RalfJung:promotion, r=oli-obk
remove this weird special case from promotion

Promotion has a special case to ignore interior mutability under some specific circumstances. The purpose of this PR is to figure out what changes if we remove that. Since `Cell::new` and friends only get promoted inside `const`/`static` initializers these days, it actually is not easy to exploit this case: you need something like
```rust
const TEST_INTERIOR_MUT: () = {
    // The "0." case is already ruled out by not permitting any interior mutability in `const`.
    let _val: &'static _ = &(Cell::new(1), 2).1;
};
```

I assume something like `&Some(&(Cell::new(1), 2).1)` would hit the nested case inside `validate_rvalue`... though I am not sure why that would not just trigger nested promotion, first promoting the inner reference and then the outer one?

Fixes https://github.com/rust-lang/rust/issues/67534 (by simply rejecting that code^^)

r? `@oli-obk` (but for now this is not meant to be merged!)
Cc `@rust-lang/wg-const-eval`
2020-12-09 09:13:54 +00:00
Ralf Jung 99a44ed086 remove a hack that seems to only benefit a few very special cases 2020-12-09 09:46:22 +01:00
bors db85512bd8 Auto merge of #79767 - tmiasko:malformed-required-const, r=matthewjasper
Don't ICE on malformed `rustc_args_required_const` attribute
2020-12-09 06:31:49 +00:00
bors 1700ca07c6 Auto merge of #79727 - tmiasko:8bit-rwu, r=lcnr
Compress RWU from at least 32 bits to 4 bits

The liveness uses a mixed representation of RWUs based on the
observation that most of them have invalid reader and invalid
writer. The packed variant uses 32 bits and unpacked 96 bits.
Unpacked data contains reader live node and writer live node.

Since live nodes are used only to determine their validity,
RWUs can always be stored in a packed form with four bits for
each: reader bit, writer bit, used bit, and one extra padding
bit to simplify packing and unpacking operations.
2020-12-08 20:58:20 +00:00
bors 5e6e1e33a1 Auto merge of #79817 - LingMan:if_map, r=lcnr
Replace simple `if let` constructs with Option::map

Replaces a few constructs of the form

```
if let Some(x) = var {
    Some(...)
} else {
    None
}
```

with calls to `Option::map`.

`@rustbot` modify labels +C-cleanup +T-compiler
2020-12-08 13:58:15 +00:00
bors 5019791e2d Auto merge of #79752 - cjgillot:dead-alien, r=lcnr
Visit ForeignItems when marking dead code

Follow-up to #79318

r? `@lcnr`
2020-12-08 11:16:19 +00:00
bors 4fd4a98d47 Auto merge of #79806 - LeSeulArtichaut:fixup-filter-is-none, r=jyn514
Fixup: `filter().is_none()` -> `!any()`
2020-12-08 08:51:51 +00:00
Camille GILLOT 37853f925f Visit ForeignItems when marking dead code. 2020-12-08 08:07:55 +01:00
LingMan af9402af0f Replace simple if let constructs with Option::map
Replaces a few constructs of the form

if let Some(x) = var {
    Some(...)
} else {
    None
}

with calls to Option::map.
2020-12-08 02:40:14 +01:00
bors bda05cc471 Auto merge of #79653 - tmiasko:naked-functions, r=Amanieu
Validate naked functions definitions

Validate that naked functions are defined in terms of a single inline assembly
block that uses only `const` and `sym` operands and has `noreturn` option.

Implemented as future incompatibility lint with intention to migrate it into
hard error. When it becomes a hard error it will ensure that naked functions are
either unsafe or contain an unsafe block around the inline assembly. It will
guarantee that naked functions do not reference functions parameters (obsoleting
part of existing checks from #79411). It will limit the definitions of naked
functions to what can be reliably supported. It will also reject naked functions
implemented using legacy LLVM style assembly since it cannot satisfy those
conditions.

https://github.com/rust-lang/rfcs/pull/2774
https://github.com/rust-lang/rfcs/pull/2972
2020-12-07 22:47:20 +00:00
LeSeulArtichaut 9cc563b70b Fixup: filter().is_none() -> !any() 2020-12-07 21:40:20 +01:00
bors b5ff9c3d05 Auto merge of #79773 - lcnr:type-visitor, r=oli-obk
small `TypeVisitor` refactor

cc `@LeSeulArtichaut` `@scottmcm`

adds `ControlFlow::map_break`
2020-12-07 15:07:09 +00:00
Bastian Kauschke e3e4870bce small TypeVisitor refactor 2020-12-07 15:52:59 +01:00
bors 2b76c48328 Auto merge of #79772 - ethanboxx:79760-wrongly-speaks-of-methods, r=oli-obk
smarter E0390

Should fix #79760

I am fairly new to the compiler so am hoping I did things correctly :).
2020-12-07 09:28:25 +00:00
Tomasz Miąsko 8065dabd17 Validate naked functions definitions 2020-12-07 00:00:00 +00:00
Ethan Brierley 67db0ea4a7 suggestions from camelid review 2020-12-06 21:30:30 +00:00
Ethan Brierley 0c13a9c020 smarter E0390 2020-12-06 20:30:07 +00:00
Tomasz Miąsko 91fe548825 Retain assembly operands span when lowering AST to HIR 2020-12-06 20:48:08 +01:00
bors d577c535b4 Auto merge of #78609 - lcnr:rustdoc-const-eval, r=matthewjasper
extend `WithOptConstParam` docs, move rustdoc test

This should hopefully make things a bit clearer, feel free to comment on anything which can still be improved.

cc `@ecstatic-morse` `@nikomatsakis` `@RalfJung`
2020-12-06 13:03:45 +00:00
bors a68864b688 Auto merge of #79734 - ethanboxx:inferred_const_note, r=varkor
Const parameters can not be inferred with `_` help note

This should close: #79557

# Example output
```
error[E0747]: type provided when a constant was expected
 --> inferred_const_note.rs:6:19
  |
6 |     let a = foo::<_, 2>([0, 1, 2]);
  |                   ^
  |
  = help: Const parameters can not be inferred with `_`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0747`.
```

r? `@lcnr`
2020-12-06 08:08:05 +00:00
bors 4d26de6891 Auto merge of #79729 - matthiaskrgr:clones_, r=jyn514
remove redundant clones
2020-12-06 03:38:56 +00:00
Tomasz Miąsko 50c6fd6dd5 Don't ICE on malformed rustc_args_required_const attribute 2020-12-06 00:00:00 +00:00
Tomasz Miąsko bc8317a12a Compress RWU from at least 32 bits to 4 bits
The liveness uses a mixed representation of RWUs based on the
observation that most of them have invalid reader and invalid
writer. The packed variant uses 32 bits and unpacked 96 bits.
Unpacked data contains reader live node and writer live node.

Since live nodes are used only to determine their validity,
RWUs can always be stored in a packed form with four bits for
each: reader bit, writer bit, used bit, and one extra padding
bit to simplify packing and unpacking operations.
2020-12-06 00:00:00 +00:00
bors bb0d481b5a Auto merge of #79697 - rylev:clearer-const-diagnostic, r=oli-obk
A slightly clearer diagnostic when misusing const

Fixes #79598

This produces the following diagnostic:
"expected one of `>`, a const expression, lifetime, or type, found keyword `const`"

Instead of the previous, more confusing:
"expected one of `>`, const, lifetime, or type, found keyword `const`"

This might not be completely clear as some users might not understand what a const expression is, but I do believe this is an improvement.
2020-12-05 22:47:37 +00:00
bors 5bb68c31f8 Auto merge of #79445 - SNCPlay42:struct-tail-recursion-limit, r=oli-obk
check the recursion limit when finding a struct's tail

fixes #79437

This does a `delay_span_bug` (via `ty_error_with_message`) rather than emit a new error message, under the assumption that there will be an error elsewhere (even if the type isn't infinitely recursive, just deeper than the recursion limit, this appears to be the case).
2020-12-05 15:58:06 +00:00
Ethan Brierley 6845e22bba Const parameters can not be inferred with _
Small improvement. Thanks varkor

Co-authored-by: varkor <github@varkor.com>

Bless
2020-12-05 15:37:59 +00:00
Matthias Krüger 1734f9c291 remove redundant clones 2020-12-05 12:59:54 +01:00
Aaron Hill c2946402ff
Properly re-use def path hash in incremental mode
Fixes #79661

In incremental compilation mode, we update a `DefPathHash -> DefId`
mapping every time we create a `DepNode` for a foreign `DefId`.
This mapping is written out to the on-disk incremental cache, and is
read by the next compilation session to allow us to lazily decode
`DefId`s.

When we decode a `DepNode` from the current incremental cache, we need
to ensure that any previously-recorded `DefPathHash -> DefId` mapping
gets recorded in the new mapping that we write out. However, PR #74967
didn't do this in all cases, leading to us being unable to decode a
`DefPathHash` in certain circumstances.

This PR refactors some of the code around `DepNode` deserialization to
prevent this kind of mistake from happening again.
2020-12-04 22:16:40 -05:00
Matthew Jasper 4fef39113a Avoid leaking block expression values 2020-12-04 23:07:46 +00:00
Matthew Jasper 7f3e8551dd Use record_operands_moved more aggresively 2020-12-04 22:22:52 +00:00
Matthew Jasper b766abc88f Simplify unscheduling of drops after moves 2020-12-04 22:19:28 +00:00
SNCPlay42 98fc02d6fa check the recursion limit when finding struct tail 2020-12-04 16:37:23 +00:00
bors 2218520b8a Auto merge of #79680 - Nadrieril:fix-regression-79284, r=jonas-schievink
Fix perf regression caused by #79284

https://github.com/rust-lang/rust/pull/79284 only moved code around but this changed inlining and caused a large perf regression. This fixes it for me, though I'm less confident than usual because the regression was not observable with my usual (i.e. incremental) compilation settings.

r? `@Mark-Simulacrum`
2020-12-04 11:21:35 +00:00
Ryan Levick 823f64532c A slightly clearer diagnostic when misusing 2020-12-04 11:33:30 +01:00
bors e6225434ff Auto merge of #78177 - benjaminp:cleanups, r=jyn514
A few miscellaneous comment fixes and a tiny code clarification.
2020-12-04 07:11:41 +00:00
Benjamin Peterson 504f136c74 Writeback walks the HIR not the AST. 2020-12-03 23:38:36 -06:00
Benjamin Peterson 76ff0f408a The details of higher-rank sub are in the rustc book not a doc module. 2020-12-03 23:38:36 -06:00
Benjamin Peterson 4d8a7c2829 Unnest some .chain calls, so it's clearer what's going on. 2020-12-03 23:37:26 -06:00
Benjamin Peterson cb56b1a7e9 Fix comment that refers to dead enforce_object_limitations function. 2020-12-03 23:37:26 -06:00
bors e9dd18ca74 Auto merge of #79686 - Dylan-DPC:rollup-leama5f, r=Dylan-DPC
Rollup of 11 pull requests

Successful merges:

 - #77686 (Render Markdown in search results)
 - #79541 (Doc keyword lint pass)
 - #79602 (Fix SGX CI)
 - #79611 (Use more std:: instead of core:: in docs for consistency)
 - #79623 (Pass around Symbols instead of Idents in doctree)
 - #79627 (Update cargo)
 - #79631 (disable a ptr equality test on Miri)
 - #79638 (Use `item_name` instead of pretty printing for resolving `Self` on intra-doc links)
 - #79646 (rustc_metadata: Remove some dead code)
 - #79664 (move interpret::MemoryKind::Heap to const eval)
 - #79678 (Fix some clippy lints)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2020-12-04 04:51:49 +00:00
bors 6513f50291 Auto merge of #79109 - richkadel:llvm-coverage-counters-2.0.5, r=tmandry
Coverage tests for remaining TerminatorKinds and async, improve Assert

Tested and validate results for panic unwind, panic abort, assert!()
macro, TerminatorKind::Assert (for example, numeric overflow), and
async/await.

Implemented a previous documented idea to change Assert handling to be
the same as FalseUnwind and Goto, so it doesn't get its own
BasicCoverageBlock anymore. This changed a couple of coverage regions,
but I validated those changes are not any worse than the prior results,
and probably help assure some consistency (even if some people might
disagree with how the code region is consistently computed).

Fixed issue with async/await. AggregateKind::Generator needs to be
handled like AggregateKind::Closure; coverage span for the outer async
function should not "cover" the async body, which is actually executed
in a separate "closure" MIR.
2020-12-04 02:31:11 +00:00
Dylan DPC 5cebbaa6a1
Rollup merge of #79678 - jyn514:THE-PAPERCLIP-COMETH, r=varkor
Fix some clippy lints

Happy to revert these if you think they're less readable, but personally I like them better now (especially the `else { if { ... } }` to `else if { ... }` change).
2020-12-04 03:30:39 +01:00
Dylan DPC a2aa3d6e49
Rollup merge of #79664 - vn-ki:move-memkind-heap, r=oli-obk
move interpret::MemoryKind::Heap to const eval

r? ``@oli-obk``
2020-12-04 03:30:37 +01:00
Dylan DPC 0fbbe94662
Rollup merge of #79646 - petrochenkov:inclean, r=davidtwco
rustc_metadata: Remove some dead code

Follow up to https://github.com/rust-lang/rust/pull/74967
2020-12-04 03:30:36 +01:00
Dylan DPC f4060521a9
Rollup merge of #79541 - GuillaumeGomez:doc-keyword-lint-pass, r=lcnr
Doc keyword lint pass

`x.py test` doesn't seem to work locally for multiple reasons so simpler to just run CI...
2020-12-04 03:30:19 +01:00
Nadrieril 793c40e0bd Inline is_covered_by 2020-12-04 01:45:34 +00:00
Joshua Nelson 0ad3dce83a Fix some clippy lints 2020-12-03 17:08:19 -05:00