Commit graph

3026 commits

Author SHA1 Message Date
bors 704e47f78b Auto merge of #78407 - oli-obk:ub_checkable_ctfe, r=RalfJung,pnkfelix
Make CTFE able to check for UB...

... by not doing any optimizations on the `const fn` MIR used in CTFE. This means we duplicate all `const fn`'s MIR now, once for CTFE, once for runtime. This PR is for checking the perf effect, so we have some data when talking about https://github.com/rust-lang/const-eval/blob/master/rfcs/0000-const-ub.md

To do this, we now have two queries for obtaining mir: `optimized_mir` and `mir_for_ctfe`. It is now illegal to invoke `optimized_mir` to obtain the MIR of a const/static item's initializer, an array length, an inline const expression or an enum discriminant initializer. For `const fn`, both `optimized_mir` and `mir_for_ctfe` work, the former returning the MIR that LLVM should use if the function is called at runtime. Similarly it is illegal to invoke `mir_for_ctfe` on regular functions.

This is all checked via appropriate assertions and I don't think it is easy to get wrong, as there should be no `mir_for_ctfe` calls outside the const evaluator or metadata encoding. Almost all rustc devs should keep using `optimized_mir` (or `instance_mir` for that matter).
2021-01-12 17:26:56 +00:00
oli 53e3a23572 Coverage computation needs access to the MIR, too 2021-01-12 15:12:03 +00:00
bors 497c9a256b Auto merge of #80517 - wabain:issue-77880-infer-error-try-conversion-msg, r=davidtwco
Enhance type inference errors involving the `?` operator

This patch adds a special-cased note on type inference errors when the error span points to a `?` return. It also makes the primary label for such errors "cannot infer type of `?` error" in cases where before we would have only said "cannot infer type".

One beneficiary of this change is async blocks, where we can't explicitly annotate the return type and so may not generate any other help (#77880); this lets us at least print the error type we're converting from and anything we know about the type we can't fully infer. More generally, it signposts that an implicit conversion is happening that may have impeded type inference the user was expecting. We already do something similar for [mismatched type errors](2987785df3/src/test/ui/try-block/try-block-bad-type.stderr (L7)).

The check for a relevant `?` operator is built into the existing HIR traversal which looks for places that could be annotated to resolve the error. That means we could identify `?` uses anywhere in the function that output the type we can't infer, but this patch just sticks to adding the note if the primary span given for the error has the operator; if there are other expressions where the type occurs and one of them is selected for the error instead, it's more likely that the `?` operator's implicit conversion isn't the sole cause of the inference failure and that adding an additional diagnostic would just be noise. I added a ui test for one such case.

The data about the `?` conversion is passed around in a `UseDiagnostic` enum that in theory could be used to add more of this kind of note in the future. It was also just easier to pass around than something with a more specific name. There are some follow-up refactoring commits for the code that generates the error label, which was already pretty involved and made a bit more complicated by this change.
2021-01-12 14:42:37 +00:00
bors fc9944fe84 Auto merge of #80499 - matthiaskrgr:red_clos, r=estebank
remove redundant closures (clippy::redundant_closure)
2021-01-12 11:20:47 +00:00
bors b6b461652a Auto merge of #80939 - JohnTitor:rollup-pymns4q, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #79757 (Replace tabs earlier in diagnostics)
 - #80600 (Add `MaybeUninit` method `array_assume_init`)
 - #80880 (Move some tests to more reasonable directories)
 - #80897 (driver: Use `atty` instead of rolling our own)
 - #80898 (Add another test case for #79808)
 - #80917 (core/slice: remove doc comment about scoped borrow)
 - #80927 (Replace a simple `if let` with the `matches` macro)
 - #80930 (fix typo in trait method mutability mismatch help)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-01-12 08:38:47 +00:00
Yuki Okushi 139daf564e
Rollup merge of #80930 - euclio:trait-method-mutability-help, r=estebank
fix typo in trait method mutability mismatch help
2021-01-12 16:13:35 +09:00
Yuki Okushi 8c342da22e
Rollup merge of #80927 - LingMan:matches, r=estebank
Replace a simple `if let` with the `matches` macro

`@rustbot` modify labels +C-cleanup +T-compiler
2021-01-12 16:13:33 +09:00
Yuki Okushi d682a6834d
Rollup merge of #80897 - camelid:atty, r=jyn514
driver: Use `atty` instead of rolling our own

Fixes #80888.

Rationale:

- `atty` is widely used in the Rust ecosystem
- We already use it (in `rustc_errors` and other places)
- We shouldn't be rolling our own TTY detector when there's a
  widely-used, well-tested package that we can use
2021-01-12 16:13:28 +09:00
Yuki Okushi 86b900a3ea
Rollup merge of #79757 - jryans:long-line-tab-handling-early-expand, r=estebank
Replace tabs earlier in diagnostics

This replaces tabs earlier in the diagnostics emitting process, which allows various margin calculations to ignore the existence of tabs. It does add a string copy for the source lines that are emitted.

Fixes https://github.com/rust-lang/rust/issues/78438

r? `@estebank`
2021-01-12 16:13:15 +09:00
bors 8234db5bc7 Auto merge of #80463 - tgnottingham:incr_comp_serial_mem_usage, r=oli-obk
Serialize incr comp structures to file via fixed-size buffer

Reduce a large memory spike that happens during serialization by writing
the incr comp structures to file by way of a fixed-size buffer, rather
than an unbounded vector.

Effort was made to keep the instruction count close to that of the
previous implementation. However, buffered writing to a file inherently
has more overhead than writing to a vector, because each write may
result in a handleable error. To reduce this overhead, arrangements are
made so that each LEB128-encoded integer can be written to the buffer
with only one capacity and error check. Higher-level optimizations in
which entire composite structures can be written with one capacity and
error check are possible, but would require much more work.

The performance is mostly on par with the previous implementation, with
small to moderate instruction count regressions. The memory reduction is
significant, however, so it seems like a worth-while trade-off.
2021-01-12 05:51:40 +00:00
Camelid 8c43160744 driver: Use atty instead of rolling our own
Rationale:

- `atty` is widely used in the Rust ecosystem
- We already use it (in `rustc_errors` and other places)
- We shouldn't be rolling our own TTY detector when there's a
  widely-used, well-tested package that we can use
2021-01-11 19:59:25 -08:00
bors 467f5e99a5 Auto merge of #76580 - rokob:iss76011, r=estebank
Suggest async {} for async || {}

Fixes #76011

This adds support for adding help diagnostics to the feature gating checks and
then uses it for the async_closure gate to add the extra bit of help
information as described in the issue.
2021-01-12 02:56:51 +00:00
LingMan 6bd661ef17 Replace a simple if let with the matches macro 2021-01-12 01:49:36 +01:00
Andy Russell b6dc03b93d
fix typo in trait method mutability mismatch help 2021-01-11 19:28:25 -05:00
bors 0406441664 Auto merge of #80928 - JohnTitor:rollup-sgerm3j, r=JohnTitor
Rollup of 9 pull requests

Successful merges:

 - #79997 (Emit a reactor for cdylib target on wasi)
 - #79998 (Use correct ABI for wasm32 by default)
 - #80042 (Split a func into cold/hot parts, reducing binary size)
 - #80324 (Explain method-call move errors in loops)
 - #80864 (std/core docs: fix wrong link in PartialEq)
 - #80870 (resolve: Simplify built-in macro table)
 - #80885 (rustdoc: Resolve `&str` as `str`)
 - #80904 (Fix small typo)
 - #80923 (Merge different function exits)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-01-12 00:14:46 +00:00
Yuki Okushi 4e69c5d0fa
Rollup merge of #80923 - LingMan:exits, r=varkor
Merge different function exits

`@rustbot` modify labels +C-cleanup +T-compiler
2021-01-12 07:59:18 +09:00
Yuki Okushi f553a0fe59
Rollup merge of #80904 - camelid:fix-small-typo, r=jonas-schievink
Fix small typo

transmutting -> transmuting
2021-01-12 07:59:16 +09:00
Yuki Okushi fd02c83bfe
Rollup merge of #80870 - petrochenkov:bmactable, r=oli-obk
resolve: Simplify built-in macro table

We don't use full `SyntaxExtension`s from the table, only `SyntaxExtensionKind`s, and `Ident` in `register_builtin_macro` always had dummy span. This PR removes unnecessary data from the table and related function signatures.

Noticed when reviewing #80850.
2021-01-12 07:59:13 +09:00
Yuki Okushi 8e6472fe32
Rollup merge of #80324 - Aaron1011:loop-move-fn-self, r=oli-obk
Explain method-call move errors in loops

PR #73708 added a more detailed explanation of move errors that occur
due to a call to a method that takes `self`. This PR extends that logic
to work when a move error occurs due to a method call in the previous
iteration of a loop.
2021-01-12 07:59:10 +09:00
Yuki Okushi 56504a00f2
Rollup merge of #80042 - sivadeilra:cold_bits, r=oli-obk
Split a func into cold/hot parts, reducing binary size

I noticed that the Size::bits function is called in many places,
and is inlined into them. On x86_64-pc-windows-msvc, this function
is inlined 527 times, and compiled separately (non-inlined) 3 times.

Each of those inlined calls contains code that panics. This commit
moves the `panic!` call into a separate function and marks that
function with `#[cold]`.

This reduces binary size by 24 KB. Not much, but it's something.
Changes like this often reduce pressure on instruction-caches,
since it reduces the amount of code that is inlined into hot code
paths. Or more precisely, it removes cold code from hot cache lines.
2021-01-12 07:59:08 +09:00
Yuki Okushi edcfe7b629
Rollup merge of #79998 - devsnek:wasm32-bindgen-compat, r=alexcrichton
Use correct ABI for wasm32 by default

Introduces `wasm32-unknown-bindgen` for those wishing to use the bindgen compat abi. `wasm32-*` now uses the correct abi by default.

Fixes https://github.com/rustwasm/team/issues/291
2021-01-12 07:59:06 +09:00
Yuki Okushi 1d83f9828f
Rollup merge of #79997 - coolreader18:wasm-reactor, r=alexcrichton
Emit a reactor for cdylib target on wasi

Fixes #79199, and relevant to #73432

Implements wasi reactors, as described in WebAssembly/WASI#13 and [`design/application-abi.md`](https://github.com/WebAssembly/WASI/blob/master/design/application-abi.md)

Empty `lib.rs`, `lib.crate-type = ["cdylib"]`:

```shell
$ cargo +reactor build --release --target wasm32-wasi
   Compiling wasm-reactor v0.1.0 (/home/coolreader18/wasm-reactor)
    Finished release [optimized] target(s) in 0.08s
$ wasm-dis target/wasm32-wasi/release/wasm_reactor.wasm >reactor.wat
```
`reactor.wat`:
```wat
(module
 (type $none_=>_none (func))
 (type $i32_=>_none (func (param i32)))
 (type $i32_i32_=>_i32 (func (param i32 i32) (result i32)))
 (type $i32_=>_i32 (func (param i32) (result i32)))
 (type $i32_i32_i32_=>_i32 (func (param i32 i32 i32) (result i32)))
 (import "wasi_snapshot_preview1" "fd_prestat_get" (func $__wasi_fd_prestat_get (param i32 i32) (result i32)))
 (import "wasi_snapshot_preview1" "fd_prestat_dir_name" (func $__wasi_fd_prestat_dir_name (param i32 i32 i32) (result i32)))
 (import "wasi_snapshot_preview1" "proc_exit" (func $__wasi_proc_exit (param i32)))
 (import "wasi_snapshot_preview1" "environ_sizes_get" (func $__wasi_environ_sizes_get (param i32 i32) (result i32)))
 (import "wasi_snapshot_preview1" "environ_get" (func $__wasi_environ_get (param i32 i32) (result i32)))
 (memory $0 17)
 (table $0 1 1 funcref)
 (global $global$0 (mut i32) (i32.const 1048576))
 (global $global$1 i32 (i32.const 1049096))
 (global $global$2 i32 (i32.const 1049096))
 (export "memory" (memory $0))
 (export "_initialize" (func $_initialize))
 (export "__data_end" (global $global$1))
 (export "__heap_base" (global $global$2))
 (func $__wasm_call_ctors
  (call $__wasilibc_initialize_environ_eagerly)
  (call $__wasilibc_populate_preopens)
 )
 (func $_initialize
  (call $__wasm_call_ctors)
 )
 (func $malloc (param $0 i32) (result i32)
  (call $dlmalloc
   (local.get $0)
  )
 )
 ;; lots of dlmalloc, memset/memcpy, & libpreopen code
)
```

I went with repurposing cdylib because I figured that it doesn't make much sense to have a wasi shared library that can't be initialized, and even if someone was using it adding an `_initialize` export is a very small change.
2021-01-12 07:58:59 +09:00
bors fe531d5a5f Auto merge of #79012 - tgnottingham:span_data_to_lines_and_cols, r=estebank
rustc_span: add span_data_to_lines_and_cols to caching source map view
2021-01-11 21:32:50 +00:00
Gus Caplan 5ba3be1d60
squash! fix wasi 2021-01-11 15:31:52 -06:00
Gus Caplan 8f64cec022
new target 2021-01-11 14:22:41 -06:00
Gus Caplan 94bf59ea34
Use correct ABI for wasm32 by default
Introduces `RUSTC_USE_WASM32_BINDGEN_COMPAT_ABI` env var to use the
compat ABI if need.
2021-01-11 14:22:38 -06:00
Tyson Nottingham f15fae822e rustc_serialize: fix incorrect signed LEB128 decoding
The signed LEB128 decoding function used a hardcoded constant of 64
instead of the number of bits in the type of integer being decoded,
which resulted in incorrect results for some inputs. Fix this, make the
decoding more consistent with the unsigned version, and increase the
LEB128 encoding and decoding test coverage.
2021-01-11 12:13:26 -08:00
Tyson Nottingham 52f21791fb Serialize incr comp structures to file via fixed-size buffer
Reduce a large memory spike that happens during serialization by writing
the incr comp structures to file by way of a fixed-size buffer, rather
than an unbounded vector.

Effort was made to keep the instruction count close to that of the
previous implementation. However, buffered writing to a file inherently
has more overhead than writing to a vector, because each write may
result in a handleable error. To reduce this overhead, arrangements are
made so that each LEB128-encoded integer can be written to the buffer
with only one capacity and error check. Higher-level optimizations in
which entire composite structures can be written with one capacity and
error check are possible, but would require much more work.

The performance is mostly on par with the previous implementation, with
small to moderate instruction count regressions. The memory reduction is
significant, however, so it seems like a worth-while trade-off.
2021-01-11 12:13:22 -08:00
oli e90b521a15 --emit=mir now emits both mir_for_ctfe and optimized_mir for const fn 2021-01-11 17:24:41 +00:00
bors 6526e5c772 Auto merge of #80889 - cjgillot:asa, r=oli-obk
Do not query the HIR directly in `opt_associated_item`.

Papercut found by `@Aaron1011.`
2021-01-11 14:54:52 +00:00
Yuki Okushi 293a491935
Rollup merge of #80887 - camelid:fix-log-color-auto, r=RalfJung
log-color: Detect TTY based on stderr, not stdout

Fixes #78435 (again).

Logging goes to stderr, not stdout, so we should base our automated
detection on stderr instead of stdout.

Thanks to Ralf Jung for noticing and reporting the bug!

r? `@oli-obk`
cc `@RalfJung`
2021-01-11 14:34:52 +09:00
Yuki Okushi 95a6279de7
Rollup merge of #80878 - unseddd:abi, r=RalfJung
Add ABI argument to `find_mir_or_eval_fn`

Add ABI argument for called function in `find_mir_or_eval_fn` and
`call_extra_fn`. Useful for comparing with expected ABI in interpreters.

Related to [miri/1631](https://github.com/rust-lang/miri/issues/1631)

r? `@RalfJung`
2021-01-11 14:34:49 +09:00
Yuki Okushi dcd46bfd31
Rollup merge of #80809 - camelid:rust-call-abi-msg, r=lcnr
Use standard formatting for "rust-call" ABI message

Nearly all error messages start with a lowercase letter and don't use
articles - instead they refer to the plural case.
2021-01-11 14:34:40 +09:00
Camelid e2d3a25161 Fix small typo
transmutting -> transmuting
2021-01-10 21:24:32 -08:00
William Bain d46c3e3411 Tweak ? inference error messages 2021-01-10 19:48:11 -05:00
William Bain 62a39ed526 Extract parent def handling for infer failure err 2021-01-10 19:48:11 -05:00
William Bain b9d9776fea Refactor cannot infer ... message rendering 2021-01-10 19:48:10 -05:00
William Bain 0496fdee4f Note inference failures using ? conversion 2021-01-10 19:47:57 -05:00
bors 26d451f4b3 Auto merge of #80782 - petrochenkov:viscopes, r=matthewjasper
resolve: Scope visiting doesn't need an `Ident`

Resolution scope visitor (`fn visit_scopes`) currently takes an `Ident` parameter, but it doesn't need a full identifier, or even its span, it only needs the `SyntaxContext` part.
The `SyntaxContext` part is necessary because scope visitor has to jump to macro definition sites, so it has to be directed by macro expansion information somehow.

I think it's clearer to pass only the necessary part.
Yes, usually visiting happens as a part of an identifier resolution, but in cases like collecting traits in scope (#80765) or collecting typo suggestions that's not the case.

r? `@matthewjasper`
2021-01-10 23:36:33 +00:00
Camille GILLOT 21e1963e9c Do not query the HIR in opt_associated_item. 2021-01-10 22:41:50 +01:00
Camelid 7af29abbc1 log-color: Detect TTY based on stderr, not stdout
Logging goes to stderr, not stdout, so we should base our automated
detection on stderr instead of stdout.

Thanks to Ralf Jung for noticing and reporting the bug!
2021-01-10 13:22:15 -08:00
bors c97f11af7b Auto merge of #79414 - sasurau4:feature/add-suggestion-for-pattern-in-fns-without-body, r=matthewjasper
Add suggestion for PATTERNS_IN_FNS_WITHOUT_BODY

## Overview

Fix #78927
2021-01-10 20:48:27 +00:00
Camelid 6488aecb74 Use standard formatting for "rust-call" ABI message
Nearly all error messages start with a lowercase letter and don't use
articles - instead they refer to the plural case.
2021-01-10 12:17:24 -08:00
bors 080ee6f5d7 Auto merge of #80789 - Aaron1011:fix/stmt-empty, r=petrochenkov
Synthesize a `TokenStream` for `StmtKind::Empty`

Fixes #80760
2021-01-10 17:58:38 +00:00
Nym Seddon 06fd212d6a
Add ABI argument to find_mir_or_eval_fn
Add ABI argument for called function in `find_mir_or_eval_fn` and
`call_extra_fn`. Useful for comparing with expected ABI in interpreters.

Related to [miri/1631](https://github.com/rust-lang/miri/issues/1631)
2021-01-10 15:12:50 +00:00
LingMan 578da998af Merge different function exits 2021-01-10 14:38:14 +01:00
Vadim Petrochenkov f9b5859173 resolve: Simplify built-in macro table 2021-01-10 14:48:47 +03:00
bors 34628e5b53 Auto merge of #80867 - JohnTitor:rollup-tvqw555, r=JohnTitor
Rollup of 9 pull requests

Successful merges:

 - #79502 (Implement From<char> for u64 and u128.)
 - #79968 (Improve core::ptr::drop_in_place debuginfo)
 - #80774 (Fix safety comment)
 - #80801 (Use correct span for structured suggestion)
 - #80803 (Remove useless `fill_in` function)
 - #80820 (Support `download-ci-llvm` on NixOS)
 - #80825 (Remove under-used ImplPolarity enum)
 - #80850 (Allow #[rustc_builtin_macro = "name"])
 - #80857 (Add comment to `Vec::truncate` explaining `>` vs `>=`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2021-01-10 08:01:12 +00:00
Yuki Okushi 3e735c6e93
Rollup merge of #80850 - m-ou-se:rustc-builtin-macro-name, r=petrochenkov
Allow #[rustc_builtin_macro = "name"]

This adds the option of specifying the name of a builtin macro in the `#[rustc_builtin_macro]` attribute: `#[rustc_builtin_macro = "name"]`.

This makes it possible to have both `std::panic!` and `core::panic!` as a builtin macro, by using different builtin macro names for each. This is needed to implement the edition-specific behaviour of the panic macros of RFC 3007.

Also removes `SyntaxExtension::is_derive_copy`, as the macro name (e.g. `sym::Copy`) is now tracked and provides that information directly.

r? ``@petrochenkov``
2021-01-10 16:56:05 +09:00
Yuki Okushi 700f3f23d8
Rollup merge of #80801 - estebank:correct-binding-sugg-span, r=petrochenkov
Use correct span for structured suggestion

On structured suggestion for `let` -> `const`  and `const` -> `let`, use
a proper `Span` and update tests to check the correct application.

Follow up to #80012.
2021-01-10 16:55:59 +09:00