Commit Graph

124553 Commits

Author SHA1 Message Date
Xavier Denis
f07607f47a Move mir-opt tests to toplevel 2020-07-29 17:36:03 +02:00
Rich Kadel
5b2e2b25e4 Moved structs/enums with repr(C) to LLVM types into ffi.rs crates
Some were in librustc_codegen_llvm, but others are not tied to LLVM, so
I put them in a new crate: librustc_codegen_ssa/coverageinfo/ffi.rs
2020-07-29 08:22:17 -07:00
Takayuki Nakata
ab166cfffa Fix broken link in unstable book plugin 2020-07-29 23:21:56 +09:00
bors
584e83dd5a Auto merge of #72049 - mati865:mingw-lld, r=petrochenkov
MinGW: enable dllexport/dllimport

Fixes (only when using LLD) https://github.com/rust-lang/rust/issues/50176
Fixes https://github.com/rust-lang/rust/issues/72319

This makes `windows-gnu` on pair with `windows-msvc` when it comes to symbol exporting.
For MinGW it means both good things like correctly working dllimport/dllexport, ability to link with LLD and bad things like https://github.com/rust-lang/rust/issues/27438.

Not sure but maybe this should land behind unstable compiler option (`-Z`) or environment variable?
2020-07-29 13:58:19 +00:00
Ralf Jung
897149a883 fence docs: fix example Mutex 2020-07-29 15:45:42 +02:00
Mateusz Mikuła
87abd656da Add test for #50176 2020-07-29 14:19:58 +02:00
Mateusz Mikuła
db9a84a1af MinGW: emit dllexport/dllimport by rustc
This fixes various cases where LD could not guess dllexport correctly and greatly improves compatibility with LLD which is not going to support linker scripts anytime soon
2020-07-29 14:19:57 +02:00
Guillaume Gomez
759de11f53 Clean up E0740 explanation 2020-07-29 14:06:29 +02:00
Xavier Denis
86be22ebcd add crate name to mir dumps 2020-07-29 13:41:11 +02:00
bors
06e7b93f6a Auto merge of #74900 - tmiasko:doc-open, r=Mark-Simulacrum
Fix opening docs for std crates with ./x.py doc --open library/*

The directories for core, alloc, std, proc_macro, and test crates now
correspond directly to the crate name, and stripping the "lib" prefix is
no longer necessary.
2020-07-29 11:19:36 +00:00
Lzu Tao
0374006d79 Avoid bool-like naming 2020-07-29 10:48:00 +00:00
Tomasz Miąsko
6b4c739f92 Fix opening docs for std crates with ./x.py doc --open library/*
The directories for core, alloc, std, proc_macro, and test crates now
correspond directly to the crate name and stripping the "lib" prefix is
no longer necessary.
2020-07-29 12:46:04 +02:00
Josh Triplett
82766cb78a Fix some typos in src/librustdoc/clean/auto_trait.rs 2020-07-29 03:25:38 -07:00
Tim Diekmann
b01fbc437e Simplify implementations of AllocRef for Global and System 2020-07-29 11:41:36 +02:00
Oliver Scherer
b81d164f61 Address review comments 2020-07-29 11:37:33 +02:00
Simon Sapin
1fb67363bf Remove deprecated unstable {Box,Rc,Arc}::into_raw_non_null functions
FCP: https://github.com/rust-lang/rust/issues/47336#issuecomment-619369613
2020-07-29 11:00:31 +02:00
Simon Sapin
7d759f539f Stabilize Vec::leak 2020-07-29 10:53:55 +02:00
Simon Sapin
d8bcf75206 Make Vec::leak a method instead of an associated function.
The reason for `Box::leak` not to be a method (`Deref` to an arbitrary `T`
which might have its own, different `leak` method) does not apply.
2020-07-29 10:53:55 +02:00
bors
0dd362ec17 Auto merge of #74896 - imbolc:patch-1, r=kennytm
Update `fs::remove_file` docs

Mention that absence of file causes an error
2020-07-29 08:52:01 +00:00
Tomasz Miąsko
1b4a6a5183 Link to syntax section when referencing it 2020-07-29 10:43:40 +02:00
Paul Sajna
7baa87fccf bump libc version to 0.2.74 2020-07-29 01:10:57 -07:00
Lzu Tao
27e1b0632c Explain why inline default ToString impl 2020-07-29 07:38:06 +00:00
Imbolc
c4e44d7373
Update fs::remove_file docs
Mention that absence of file causes an error
2020-07-29 08:18:01 +03:00
bors
10c375700c Auto merge of #74887 - Mark-Simulacrum:cache-non-exhaustive, r=petrochenkov
Cache non-exhaustive separately from attributes

This prevents cross-crate attribute loading from metadata just for non_exhaustive checking; cross-crate attribute loading implies disk reading and is relatively slow.
2020-07-29 04:59:37 +00:00
bors
517385b31b Auto merge of #74894 - JohnTitor:rollup-4ine62a, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #74266 (Clean up E0720 explanation)
 - #74671 (add const generics array coercion test)
 - #74707 (Add str::[r]split_once)
 - #74814 (Fix RefUnwindSafe & UnwinsSafe impls for lazy::SyncLazy)
 - #74859 (Update outdated readme)
 - #74864 (ayu theme: Change doccomment color to `#a1ac88`)
 - #74872 (Enable to ping RISC-V group via triagebot)
 - #74891 (handle ConstEquate in rustdoc)

Failed merges:

r? @ghost
2020-07-29 01:38:00 +00:00
Rich Kadel
b58afc088f FunctionCoverage: improve type checking with newtype_index types 2020-07-28 17:45:58 -07:00
Yuki Okushi
2b4ae49f2e
Rollup merge of #74891 - lcnr:auto-trait-finder, r=varkor
handle ConstEquate in rustdoc

fixes #74882

r? @varkor cc @eddyb
2020-07-29 09:24:25 +09:00
Yuki Okushi
18bb8355df
Rollup merge of #74872 - JohnTitor:ping-risc-v, r=Mark-Simulacrum
Enable to ping RISC-V group via triagebot

We have the RISC-V group (https://github.com/rust-lang/team/blob/master/teams/risc-v.toml) but don't enable to ping on this repository (https://github.com/rust-lang/rust/pull/74813#issuecomment-664841177).
We don't have the instructions on the rustc-dev-guide yet but I'll create it soonish.
2020-07-29 09:24:24 +09:00
Yuki Okushi
1de0211d8e
Rollup merge of #74864 - lzutao:ayu-doccolor, r=GuillaumeGomez
ayu theme: Change doccomment color to `#a1ac88`

Before:
![image](https://user-images.githubusercontent.com/15225902/88621499-d1cbff80-d0ca-11ea-99c3-5e2632709274.png)

After:
![image](https://user-images.githubusercontent.com/15225902/88621471-bf51c600-d0ca-11ea-9455-9c297f50f15f.png)

Close #74788
2020-07-29 09:24:22 +09:00
Yuki Okushi
451ed88b8b
Rollup merge of #74859 - mark-i-m:patch-1, r=JohnTitor
Update outdated readme
2020-07-29 09:24:20 +09:00
Yuki Okushi
bd91877636
Rollup merge of #74814 - matklad:unwind-safe, r=KodrAus
Fix RefUnwindSafe & UnwinsSafe impls for lazy::SyncLazy

I *think* we should implement those unconditionally with respect to `F`.

The user code can't observe the closure in any way, and we poison lazy if the closure itself panics.

But I've never fully wrapped my head around `UnwindSafe` traits, so 🤷‍♂️
2020-07-29 09:24:19 +09:00
Yuki Okushi
6968b75bd0
Rollup merge of #74707 - matklad:split_once, r=dtolnay
Add str::[r]split_once

This is useful for quick&dirty parsing of key: value config pairs. Used a bunch in Cargo and rust-analyzer:

* https://github.com/rust-lang/cargo/search?q=splitn%282&unscoped_q=splitn%282
* https://github.com/rust-analyzer/rust-analyzer/search?q=split_delim&unscoped_q=split_delim

In theory, once const-generics are done, this functionality could be achieved without a dedicated method with

```rust
match s.splitn(delimier, 2).collect_array::<2>() {
  Some([prefix, suffix]) => todo!(),
  None => todo!(),
}
```

Even in that world, having a dedicated method seems clearer on the intention.

I am not sure about naming -- this is something I've just came up with yesterday, I don't know off the top of my head analogs in other languages.

If T-libs thinks this is a reasonable API to have, I'll open a tracking issue and add more thorough tests.
2020-07-29 09:24:17 +09:00
Yuki Okushi
157975c6c4
Rollup merge of #74671 - rust-lang:const-generics-coerce-unsized, r=nikomatsakis
add const generics array coercion test
2020-07-29 09:24:15 +09:00
Yuki Okushi
1ed74eeef9
Rollup merge of #74266 - GuillaumeGomez:cleanup-e0720, r=Dylan-DPC
Clean up E0720 explanation

r? @Dylan-DPC
2020-07-29 09:24:13 +09:00
bors
4cca9505ea Auto merge of #74791 - tmiasko:raw-waker-inline, r=LukasKalbertodt
Add #[inline] to RawWaker::new

`RawWaker::new` is used when creating a new waker or cloning an existing one,
for example as in code below. The `RawWakerVTable::new` can be const evaluated,
but `RawWaker::new` itself cannot since waker pointer is not known at compile
time. Add `#[inline]` to avoid overhead of a function call.

```rust
unsafe fn clone_waker<W: Wake + Send + Sync + 'static>(waker: *const ()) -> RawWaker {
    unsafe { Arc::incr_strong_count(waker as *const W) };
    RawWaker::new(
        waker as *const (),
        &RawWakerVTable::new(clone_waker::<W>, wake::<W>, wake_by_ref::<W>, drop_waker::<W>),
    )
}
```
2020-07-28 23:45:05 +00:00
Alex Crichton
06d565c967 std: Switch from libbacktrace to gimli
This commit is a proof-of-concept for switching the standard library's
backtrace symbolication mechanism on most platforms from libbacktrace to
gimli. The standard library's support for `RUST_BACKTRACE=1` requires
in-process parsing of object files and DWARF debug information to
interpret it and print the filename/line number of stack frames as part
of a backtrace.

Historically this support in the standard library has come from a
library called "libbacktrace". The libbacktrace library seems to have
been extracted from gcc at some point and is written in C. We've had a
lot of issues with libbacktrace over time, unfortunately, though. The
library does not appear to be actively maintained since we've had
patches sit for months-to-years without comments. We have discovered a
good number of soundness issues with the library itself, both when
parsing valid DWARF as well as invalid DWARF. This is enough of an issue
that the libs team has previously decided that we cannot feed untrusted
inputs to libbacktrace. This also doesn't take into account the
portability of libbacktrace which has been difficult to manage and
maintain over time. While possible there are lots of exceptions and it's
the main C dependency of the standard library right now.

For years it's been the desire to switch over to a Rust-based solution
for symbolicating backtraces. It's been assumed that we'll be using the
Gimli family of crates for this purpose, which are targeted at safely
and efficiently parsing DWARF debug information. I've been working
recently to shore up the Gimli support in the `backtrace` crate. As of a
few weeks ago the `backtrace` crate, by default, uses Gimli when loaded
from crates.io. This transition has gone well enough that I figured it
was time to start talking seriously about this change to the standard
library.

This commit is a preview of what's probably the best way to integrate
the `backtrace` crate into the standard library with the Gimli feature
turned on. While today it's used as a crates.io dependency, this commit
switches the `backtrace` crate to a submodule of this repository which
will need to be updated manually. This is not done lightly, but is
thought to be the best solution. The primary reason for this is that the
`backtrace` crate needs to do some pretty nontrivial filesystem
interactions to locate debug information. Working without `std::fs` is
not an option, and while it might be possible to do some sort of
trait-based solution when prototyped it was found to be too unergonomic.
Using a submodule allows the `backtrace` crate to build as a submodule
of the `std` crate itself, enabling it to use `std::fs` and such.

Otherwise this adds new dependencies to the standard library. This step
requires extra attention because this means that these crates are now
going to be included with all Rust programs by default. It's important
to note, however, that we're already shipping libbacktrace with all Rust
programs by default and it has a bunch of C code implementing all of
this internally anyway, so we're basically already switching
already-shipping functionality to Rust from C.

* `object` - this crate is used to parse object file headers and
  contents. Very low-level support is used from this crate and almost
  all of it is disabled. Largely we're just using struct definitions as
  well as convenience methods internally to read bytes and such.

* `addr2line` - this is the main meat of the implementation for
  symbolication. This crate depends on `gimli` for DWARF parsing and
  then provides interfaces needed by the `backtrace` crate to turn an
  address into a filename / line number. This crate is actually pretty
  small (fits in a single file almost!) and mirrors most of what
  `dwarf.c` does for libbacktrace.

* `miniz_oxide` - the libbacktrace crate transparently handles
  compressed debug information which is compressed with zlib. This crate
  is used to decompress compressed debug sections.

* `gimli` - not actually used directly, but a dependency of `addr2line`.

* `adler32`- not used directly either, but a dependency of
  `miniz_oxide`.

The goal of this change is to improve the safety of backtrace
symbolication in the standard library, especially in the face of
possibly malformed DWARF debug information. Even to this day we're still
seeing segfaults in libbacktrace which could possibly become security
vulnerabilities. This change should almost entirely eliminate this
possibility whilc also paving the way forward to adding more features
like split debug information.

Some references for those interested are:

* Original addition of libbacktrace - #12602
* OOM with libbacktrace - #24231
* Backtrace failure due to use of uninitialized value - #28447
* Possibility to feed untrusted data to libbacktrace - #21889
* Soundness fix for libbacktrace - #33729
* Crash in libbacktrace - #39468
* Support for macOS, never merged - ianlancetaylor/libbacktrace#2
* Performance issues with libbacktrace - #29293, #37477
* Update procedure is quite complicated due to how many patches we
  need to carry - #50955
* Libbacktrace doesn't work on MinGW with dynamic libs - #71060
* Segfault in libbacktrace on macOS - #71397

Switching to Rust will not make us immune to all of these issues. The
crashes are expected to go away, but correctness and performance may
still have bugs arise. The gimli and `backtrace` crates, however, are
actively maintained unlike libbacktrace, so this should enable us to at
least efficiently apply fixes as situations come up.
2020-07-28 16:34:01 -07:00
Rich Kadel
20f55c193d Refactor MIR coverage instrumentation
Lays a better foundation for injecting more counters in each function.
2020-07-28 15:08:19 -07:00
Bastian Kauschke
2a16bb085e handle ConstEquate in rustdoc 2020-07-29 00:00:55 +02:00
bors
a7eff79135 Auto merge of #74861 - mark-i-m:mv-std-followup, r=Mark-Simulacrum
Re-enable linkcheck after moving std
2020-07-28 21:48:22 +00:00
Mark Rousskov
13ad2322ca Cache non-exhaustive separately from attributes 2020-07-28 16:26:38 -04:00
bors
2caf854f7a Auto merge of #74471 - da-x:string-type-diagnostic-item, r=petrochenkov
librustc_typeck: use diag item instead of string compare
2020-07-28 20:00:37 +00:00
Erik Desjardins
c596e01b8e add track_caller to RefCell::{borrow, borrow_mut}
So panic messages point at the offending borrow.
2020-07-28 15:45:25 -04:00
Mark Rousskov
6726ca2b28 Collect library features from library/ 2020-07-28 13:03:59 -05:00
mark
856f68fa14 reenable tests after moving std 2020-07-28 13:03:59 -05:00
bors
98efae8760 Auto merge of #74482 - alexcrichton:update-stdarch, r=hanna-kruppe
Update stdarch submodule

This commit updates the src/stdarch submodule primarily to include
rust-lang/stdarch#874 which updated and revamped WebAssembly SIMD
intrinsics and renamed WebAssembly atomics intrinsics. This is all
unstable surface area of the standard library so the changes should be
ok here. The SIMD updates also enable SIMD intrinsics to be used by any
program any any time, yay!

cc #74372, a tracking issue I've opened for the stabilization of SIMD
intrinsics
2020-07-28 17:39:39 +00:00
Alex Crichton
2c1b0467e0 rustc: Improving safe wasm float->int casts
This commit improves code generation for WebAssembly targets when
translating floating to integer casts. This improvement is only relevant
when the `nontrapping-fptoint` feature is not enabled, but the feature
is not enabled by default right now. Additionally this improvement only
affects safe casts since unchecked casts were improved in #74659.

Some more background for this issue is present on #73591, but the
general gist of the issue is that in LLVM the `fptosi` and `fptoui`
instructions are defined to return an `undef` value if they execute on
out-of-bounds values; they notably do not trap. To implement these
instructions for WebAssembly the LLVM backend must therefore generate
quite a few instructions before executing `i32.trunc_f32_s` (for
example) because this WebAssembly instruction traps on out-of-bounds
values. This codegen into wasm instructions happens very late in the
code generator, so what ends up happening is that rustc inserts its own
codegen to implement Rust's saturating semantics, and then LLVM also
inserts its own codegen to make sure that the `fptosi` instruction
doesn't trap. Overall this means that a function like this:

    #[no_mangle]
    pub unsafe extern "C" fn cast(x: f64) -> u32 {
        x as u32
    }

will generate this WebAssembly today:

    (func $cast (type 0) (param f64) (result i32)
      (local i32 i32)
      local.get 0
      f64.const 0x1.fffffffep+31 (;=4.29497e+09;)
      f64.gt
      local.set 1
      block  ;; label = @1
        block  ;; label = @2
          local.get 0
          f64.const 0x0p+0 (;=0;)
          local.get 0
          f64.const 0x0p+0 (;=0;)
          f64.gt
          select
          local.tee 0
          f64.const 0x1p+32 (;=4.29497e+09;)
          f64.lt
          local.get 0
          f64.const 0x0p+0 (;=0;)
          f64.ge
          i32.and
          i32.eqz
          br_if 0 (;@2;)
          local.get 0
          i32.trunc_f64_u
          local.set 2
          br 1 (;@1;)
        end
        i32.const 0
        local.set 2
      end
      i32.const -1
      local.get 2
      local.get 1
      select)

This PR improves the situation by updating the code generation for
float-to-int conversions in rustc, specifically only for WebAssembly
targets and only for some situations (float-to-u8 still has not great
codegen). The fix here is to use basic blocks and control flow to avoid
speculatively executing `fptosi`, and instead LLVM's raw intrinsic for
the WebAssembly instruction is used instead. This effectively extends
the support added in #74659 to checked casts. After this commit the
codegen for the above Rust function looks like:

    (func $cast (type 0) (param f64) (result i32)
      (local i32)
      block  ;; label = @1
        local.get 0
        f64.const 0x0p+0 (;=0;)
        f64.ge
        local.tee 1
        i32.const 1
        i32.xor
        br_if 0 (;@1;)
        local.get 0
        f64.const 0x1.fffffffep+31 (;=4.29497e+09;)
        f64.le
        i32.eqz
        br_if 0 (;@1;)
        local.get 0
        i32.trunc_f64_u
        return
      end
      i32.const -1
      i32.const 0
      local.get 1
      select)

For reference, in Rust 1.44, which did not have saturating
float-to-integer casts, the codegen LLVM would emit is:

    (func $cast (type 0) (param f64) (result i32)
      block  ;; label = @1
        local.get 0
        f64.const 0x1p+32 (;=4.29497e+09;)
        f64.lt
        local.get 0
        f64.const 0x0p+0 (;=0;)
        f64.ge
        i32.and
        i32.eqz
        br_if 0 (;@1;)
        local.get 0
        i32.trunc_f64_u
        return
      end
      i32.const 0)

So we're relatively close to the original codegen, although it's
slightly different because the semantics of the function changed where
we're emulating the `i32.trunc_sat_f32_s` instruction rather than always
replacing out-of-bounds values with zero.

There is still work that could be done to improve casts such as `f32` to
`u8`. That form of cast still uses the `fptosi` instruction which
generates lots of branch-y code. This seems less important to tackle now
though. In the meantime this should take care of most use cases of
floating-point conversion and as a result I'm going to speculate that
this...

Closes #73591
2020-07-28 10:17:11 -07:00
Oliver Scherer
7d67a1b871 Replace write-to-vec hack by introducing a display renderer for allocations 2020-07-28 19:16:09 +02:00
Alexis Bourget
36bb5e8a42 Clarify the doc for MaybeUninit::zeroed on incorrect use 2020-07-28 18:54:15 +02:00
Alexis Bourget
90d00527d1 Add note to clearly mark the RFC as rejected 2020-07-28 18:53:35 +02:00
Alexis Bourget
dcce6cb511 Remove links to rejected errata 4406 for RFC 4291 2020-07-28 18:53:35 +02:00