Commit Graph

8626 Commits

Author SHA1 Message Date
Yuki Okushi
9b3f49f1bd
Rollup merge of #99781 - workingjubilee:demo-string-from-cstr, r=thomcc
Use String::from_utf8_lossy in CStr demo

Fixes rust-lang/rust#99755.
2022-07-29 15:40:00 +09:00
Dylan DPC
48efd30c9d
Rollup merge of #99689 - dtolnay:write, r=Mark-Simulacrum
Revert `write!` and `writeln!` to late drop temporaries

Closes (on master, but not on beta) #99684 by reverting the `write!` and `writeln!` parts of #96455.

argument position | before<br>#94868 | after<br>#94868 | after<br>#96455 | after<br>this PR | desired<br>(unimplementable)
--- |:---:|:---:|:---:|:---:|:---:
`write!($tmp, "…", …)` | **⸺late** | **⸺late** | *early⸺* | **⸺late** | **⸺late**
`write!(…, "…", $tmp)` | **⸺late** | **⸺late** | *early⸺* | **⸺late** | *early⸺*
`writeln!($tmp, "…", …)` | **⸺late** | **⸺late** | *early⸺* | **⸺late** | **⸺late**
`writeln!(…, "…", $tmp)` | **⸺late** | **⸺late** | *early⸺* | **⸺late** | *early⸺*
`print!("…", $tmp)` | **⸺late** | **⸺late** | *early⸺* | *early⸺* | *early⸺*
`println!("…", $tmp)` | *early⸺* | **⸺late** | *early⸺* | *early⸺* | *early⸺*
`eprint!("…", $tmp)` | **⸺late** | **⸺late** | *early⸺* | *early⸺* | *early⸺*
`eprintln!("…", $tmp)` | *early⸺* | **⸺late**| *early⸺* | *early⸺* | *early⸺*
`panic!("…", $tmp)` | *early⸺* | *early⸺* | *early⸺* | *early⸺* | *early⸺*

"Late drop" refers to dropping temporaries at the nearest semicolon **outside** of the macro invocation.

"Early drop" refers to dropping temporaries inside of the macro invocation.
2022-07-28 22:14:46 +05:30
Dylan DPC
a479cab09a
Rollup merge of #99628 - vincenzopalazzo:macros/is_number_doc, r=joshtriplett
add more docs regarding ideographic numbers

This was discussed in the last lib meeting and I try to avoid forgetting to open a PR because I think having some docs can help people.

However, I think we need to discuss a little bit if this is enough or if we need to add more clarification? Maybe an example?

Inspiration Source: https://github.com/rust-lang/rust/issues/84056#issuecomment-1184725924

Including suggestion https://github.com/rust-lang/rust/pull/99626#issuecomment-1192983043 my bad command git close the PR
2022-07-28 22:14:46 +05:30
Vincenzo Palazzo
47a0a56c1d add more docs regarding ideographic numbers
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2022-07-28 15:52:18 +00:00
Dylan DPC
f3266923fe
Rollup merge of #99723 - bstrie:wasifd, r=yaahc
Allow using stable os::fd::raw items through unstable os::wasi module

This fixes a regression from stable to nightly.

Closes #99502.
2022-07-28 16:38:31 +05:30
bors
48316dfea1 Auto merge of #99182 - RalfJung:mitigate-uninit, r=scottmcm
mem::uninitialized: mitigate many incorrect uses of this function

Alternative to https://github.com/rust-lang/rust/pull/98966: fill memory with `0x01` rather than leaving it uninit. This is definitely bitewise valid for all `bool` and nonnull types, and also those `Option<&T>` that we started putting `noundef` on. However it is still invalid for `char` and some enums, and on references the `dereferenceable` attribute is still violated, so the generated LLVM IR still has UB -- but in fewer cases, and `dereferenceable` is hopefully less likely to cause problems than clearly incorrect range annotations.

This can make using `mem::uninitialized` a lot slower, but that function has been deprecated for years and we keep telling everyone to move to `MaybeUninit` because it is basically impossible to use `mem::uninitialized` correctly. For the cases where that hasn't helped (and all the old code out there that nobody will ever update), we can at least mitigate the effect of using this API. Note that this is *not* in any way a stable guarantee -- it is still UB to call `mem::uninitialized::<bool>()`, and Miri will call it out as such.

This is somewhat similar to https://github.com/rust-lang/rust/pull/87032, which proposed to make `uninitialized` return a buffer filled with 0x00. However
- That PR also proposed to reduce the situations in which we panic, which I don't think we should do at this time.
- The 0x01 bit pattern means that nonnull requirements are satisfied, which (due to references) is the most common validity invariant.

`@5225225` I hope I am using `cfg(sanitize)` the right way; I was not sure for which ones to test here.
Cc https://github.com/rust-lang/rust/issues/66151
Fixes https://github.com/rust-lang/rust/issues/87675
2022-07-28 01:11:10 +00:00
Guillaume Gomez
ef81fca760
Rollup merge of #94247 - saethlin:chunksmut-aliasing, r=the8472
Fix slice::ChunksMut aliasing

Fixes https://github.com/rust-lang/rust/issues/94231, details in that issue.
cc `@RalfJung`

This isn't done just yet, all the safety comments are placeholders. But otherwise, it seems to work.

I don't really like this approach though. There's a lot of unsafe code where there wasn't before, but as far as I can tell the only other way to uphold the aliasing requirement imposed by `__iterator_get_unchecked` is to use raw slices, which I think require the same amount of unsafe code. All that would do is tie the `len` and `ptr` fields together.

Oh I just looked and I'm pretty sure that `ChunksExactMut`, `RChunksMut`, and `RChunksExactMut` also need to be patched. Even more reason to put up a draft.
2022-07-27 17:55:01 +02:00
bstrie
0eb28abcc9 Allow using stable os::fd::raw items through unstable os::wasi module
This fixes a regression from stable to nightly.

Closes #99502.
2022-07-27 10:25:13 -04:00
bors
2a220937c2 Auto merge of #99802 - JohnTitor:rollup-uaklql1, r=JohnTitor
Rollup of 5 pull requests

Successful merges:

 - #99079 (Check that RPITs constrained by a recursive call in a closure are compatible)
 - #99704 (Add `Self: ~const Trait` to traits with `#[const_trait]`)
 - #99769 (Sync rustc_codegen_cranelift)
 - #99783 (rustdoc: remove Clean trait impls for more items)
 - #99789 (Refactor: use `pluralize!`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-27 12:32:54 +00:00
Yuki Okushi
28b44ff5d4
Rollup merge of #99704 - fee1-dead-contrib:add_self_tilde_const_trait, r=oli-obk
Add `Self: ~const Trait` to traits with `#[const_trait]`

r? `@oli-obk`
2022-07-27 19:05:33 +09:00
bors
50166d5e5e Auto merge of #98748 - saethlin:optimize-bufreader, r=Mark-Simulacrum
Remove some redundant checks from BufReader

The implementation of BufReader contains a lot of redundant checks. While any one of these checks is not particularly expensive to execute, especially when taken together they dramatically inhibit LLVM's ability to make subsequent optimizations by confusing data flow increasing the code size of anything that uses BufReader.

In particular, these changes have a ~2x increase on the benchmark that this adds a `black_box` to. I'm adding that `black_box` here just in case LLVM gets clever enough to remove the reads entirely. Right now it can't, but these optimizations are really setting it up to do so.

We get this optimization by factoring all the actual buffer management and bounds-checking logic into a new module inside `bufreader` with a new `Buffer` type. This makes it much easier to ensure that we have correctly encapsulated the management of the region of the buffer that we have read bytes into, and it lets us provide a new faster way to do small reads. `Buffer::consume_with` lets a caller do a read from the buffer with a single bounds check, instead of the double-check that's required to use `buffer` + `consume`.

Unfortunately I'm not aware of a lot of open-source usage of `BufReader` in perf-critical environments. Some time ago I tweaked this code because I saw `BufReader` in a profile at work, and I contributed some benchmarks to the `bincode` crate which exercise `BufReader::buffer`. These changes appear to help those benchmarks at little, but all these sorts of benchmarks are kind of fragile so I'm wary of quoting anything specific.
2022-07-27 09:49:06 +00:00
bors
e33cc71a61 Auto merge of #99792 - JohnTitor:rollup-20i7ewx, r=JohnTitor
Rollup of 8 pull requests

Successful merges:

 - #98583 (Stabilize Windows `FileTypeExt` with `is_symlink_dir` and `is_symlink_file`)
 - #99698 (Prefer visibility map parents that are not `doc(hidden)` first)
 - #99700 (Add a clickable link to the layout section)
 - #99712 (passes: port more of `check_attr` module)
 - #99759 (Remove dead code from cg_llvm)
 - #99765 (Don't build std for *-uefi targets)
 - #99771 (Update pulldown-cmark version to 0.9.2 (fixes url encoding for some chars))
 - #99775 (rustdoc: do not allocate String when writing path full name)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
2022-07-27 04:18:49 +00:00
Yuki Okushi
1ff84f09b2
Rollup merge of #98583 - joshtriplett:stabilize-windows-symlink-types, r=thomcc
Stabilize Windows `FileTypeExt` with `is_symlink_dir` and `is_symlink_file`

These calls allow detecting whether a symlink is a file or a directory,
a distinction Windows maintains, and one important to software that
wants to do further operations on the symlink (e.g. removing it).
2022-07-27 11:52:52 +09:00
Ben Kimock
746afe8952 Clarify safety comments 2022-07-26 21:25:56 -04:00
bors
b573e10d21 Auto merge of #98553 - the8472:next_chunk_opt, r=Mark-Simulacrum
Optimized vec::IntoIter::next_chunk impl

```
x86_64v1, default
test vec::bench_next_chunk                               ... bench:         696 ns/iter (+/- 22)
x86_64v1, pr
test vec::bench_next_chunk                               ... bench:         309 ns/iter (+/- 4)

znver2, default
test vec::bench_next_chunk                               ... bench:      17,272 ns/iter (+/- 117)
znver2, pr
test vec::bench_next_chunk                               ... bench:         211 ns/iter (+/- 3)
```

On znver2 the default impl seems to be slow due to different inlining decisions. It goes through `core::array::iter_next_chunk`
which has a deep call tree.
2022-07-27 01:12:30 +00:00
Ben Kimock
5fa1926634 Add Buffer::consume_with to enable direct buffer access with one check 2022-07-26 20:16:55 -04:00
Ben Kimock
e2e3a88771 Explain how *mut [T] helps, and how we rely on the check in split_at_mut 2022-07-26 18:37:00 -04:00
Jubilee Young
d48a869b9d Force the Cow into a String 2022-07-26 14:45:28 -07:00
Jubilee Young
79e0543060 Use String::from_utf8_lossy in CStr demo 2022-07-26 13:26:05 -07:00
The 8472
4ba7cac359 add test for vec::IntoIter::next_chunk() impl
an adaption of the default impl's doctest
2022-07-26 21:43:25 +02:00
bors
4d6d601c8a Auto merge of #99574 - durin42:allocator-patch-redux, r=nikic
codegen: use new {re,de,}allocator annotations in llvm

This obviates the patch that teaches LLVM internals about
_rust_{re,de}alloc functions by putting annotations directly in the IR
for the optimizer.

The sole test change is required to anchor FileCheck to the body of the
`box_uninitialized` method, so it doesn't see the `allocalign` on
`__rust_alloc` and get mad about the string `alloca` showing up. Since I
was there anyway, I added some checks on the attributes to prove the
right attributes got set.

r? `@nikic`
2022-07-26 19:35:57 +00:00
The 8472
2f9f2e507e Optimized vec::IntoIter::next_chunk impl
```
test vec::bench_next_chunk                               ... bench:         696 ns/iter (+/- 22)
x86_64v1, pr
test vec::bench_next_chunk                               ... bench:         309 ns/iter (+/- 4)

znver2, default
test vec::bench_next_chunk                               ... bench:      17,272 ns/iter (+/- 117)
znver2, pr
test vec::bench_next_chunk                               ... bench:         211 ns/iter (+/- 3)
```

The znver2 default impl seems to be slow due to inlining decisions. It goes through `core::array::iter_next_chunk`
which has a deeper call tree.
2022-07-26 20:31:43 +02:00
Matthias Krüger
a739e28aea
Rollup merge of #99757 - asquared31415:patch-1, r=Dylan-DPC
Make `transmute_copy` docs read better
2022-07-26 16:57:52 +02:00
Matthias Krüger
ea299e8f31
Rollup merge of #99716 - sourcelliu:iomut, r=Mark-Simulacrum
remove useless mut from examples

remove useless mut from examples
2022-07-26 16:57:48 +02:00
Deadbeef
a6f9826979 Add Self: ~const Trait to traits with #[const_trait] 2022-07-26 14:14:21 +00:00
Augie Fackler
130a1df71e codegen: use new {re,de,}allocator annotations in llvm
This obviates the patch that teaches LLVM internals about
_rust_{re,de}alloc functions by putting annotations directly in the IR
for the optimizer.

The sole test change is required to anchor FileCheck to the body of the
`box_uninitialized` method, so it doesn't see the `allocalign` on
`__rust_alloc` and get mad about the string `alloca` showing up. Since I
was there anyway, I added some checks on the attributes to prove the
right attributes got set.

While we're here, we also emit allocator attributes on
__rust_alloc_zeroed. This should allow LLVM to perform more
optimizations for zeroed blocks, and probably fixes #90032. [This
comment](https://github.com/rust-lang/rust/issues/24194#issuecomment-308791157)
mentions "weird UB-like behaviour with bitvec iterators in
rustc_data_structures" so we may need to back this change out if things
go wrong.

The new test cases require LLVM 15, so we copy them into LLVM
14-supporting versions, which we can delete when we drop LLVM 14.
2022-07-26 09:43:28 -04:00
asquared31415
e241d5a093
Make transmute_copy docs read better 2022-07-26 05:59:44 -04:00
Dylan DPC
deab13c681
Rollup merge of #99692 - RalfJung:too-far, r=oli-obk
interpret, ptr_offset_from: refactor and test too-far-apart check

We didn't have any tests for the "too far apart" message, and indeed that check mostly relied on the in-bounds check and was otherwise probably not entirely correct... so I rewrote that check, and it is before the in-bounds check so we can test it separately.
2022-07-26 14:26:58 +05:30
Yuki Okushi
d3acd0069d
Rollup merge of #98211 - devnexen:get_path_freebsd, r=Mark-Simulacrum
Implement `fs::get_path` for FreeBSD.

Using `F_KINFO` fcntl flag, the kf_structsize field
needs to be set beforehand for that effect.
2022-07-26 13:12:18 +09:00
David CARLIER
e39b44a076 Implement fs::get_path for FreeBSD.
Using `F_KINFO` fcntl flag, the kf_structsize field
needs to be set beforehand for that effect.
2022-07-25 23:25:15 +01:00
Yuki Okushi
5bbdf65996
Rollup merge of #99703 - dtolnay:tokenstreamsizehint, r=petrochenkov
Expose size_hint() for TokenStream's iterator

The iterator for `proc_macro::TokenStream` is a wrapper around a `Vec` iterator:

babff2211e/library/proc_macro/src/lib.rs (L363-L371)

so it can cheaply provide a perfectly precise size hint, with just a pointer subtraction:

babff2211e/library/alloc/src/vec/into_iter.rs (L170-L177)

I need the size hint in syn (https://github.com/dtolnay/syn/blob/1.0.98/src/buffer.rs) to reduce allocations when converting TokenStream into syn's internal TokenBuffer representation.

Aside from `size_hint`, the other non-default methods in `std::vec::IntoIter`'s `Iterator` impl are `advance_by`, `count`, and `__iterator_get_unchecked`. I've included `count` in this PR since it is trivial. I did not include `__iterator_get_unchecked` because it is spoopy and I did not feel like dealing with that. Lastly, I did not include `advance_by` because that requires `feature(iter_advance_by)` (https://github.com/rust-lang/rust/issues/77404) and I noticed this comment at the top of libproc_macro:

babff2211e/library/proc_macro/src/lib.rs (L20-L22)
2022-07-26 07:14:50 +09:00
Yuki Okushi
aeca079d7e
Rollup merge of #99084 - RalfJung:write_bytes, r=thomcc
clarify how write_bytes can lead to UB due to invalid values

Fixes https://github.com/rust-lang/unsafe-code-guidelines/issues/330

Cc ``@5225225``
2022-07-26 07:14:46 +09:00
Yuki Okushi
b8aab9781a
Rollup merge of #98710 - mojave2:string, r=JohnTitor
correct the output of a `capacity` method example

The output of this example in std::alloc is different from which shown in the comment. I have tested it on both Linux and Windows.
2022-07-26 07:14:45 +09:00
Yuki Okushi
c1647e10ad
Rollup merge of #92390 - fee1-dead-contrib:const_cmp, r=oli-obk
Constify a few `(Partial)Ord` impls

Only a few `impl`s are constified for now, as #92257 has not landed in the bootstrap compiler yet and quite a few impls would need that fix.

This unblocks #92228, which unblocks marking iterator methods as `default_method_body_is_const`.
2022-07-26 07:14:43 +09:00
Yuki Okushi
d1e4342d11
Rollup merge of #99690 - RalfJung:miri-track-caller, r=Mark-Simulacrum
add miri-track-caller to more intrinsic-exposing methods

Follow-up to https://github.com/rust-lang/rust/pull/98674: I went through the Miri test suite to find more functions that would benefit from Miri backtrace pruning, and this is what I found.

Basically anything that just exposes a potentially-UB intrinsic to the user should get this treatment.
2022-07-25 18:46:55 +09:00
Yuki Okushi
e726af8dd4
Rollup merge of #95916 - solid-rs:feat-kmc-solid-abort, r=Mark-Simulacrum
kmc-solid: Use `libc::abort` to abort a program

This PR updates the target-specific abort subroutine for the [`*-kmc-solid_*`](https://doc.rust-lang.org/nightly/rustc/platform-support/kmc-solid.html) Tier 3 targets.

The current implementation uses a `hlt` instruction, which is the most direct way to notify a connected debugger but is not the most flexible way. This PR changes it to call the `abort` libc function, making it possible for a system designer to override its behavior as they see fit.
2022-07-25 18:46:48 +09:00
Yuki Okushi
0ecbcbb0ac
Rollup merge of #95040 - frank-king:fix/94981, r=Mark-Simulacrum
protect `std::io::Take::limit` from overflow in `read`

Resolves #94981
2022-07-25 18:46:47 +09:00
sourcelliu
7ada7c8de4 remove useless mut from examples 2022-07-25 17:04:51 +08:00
David Tolnay
63e74aba81
Expose size_hint() for TokenStream's iterator 2022-07-24 20:36:22 -07:00
bors
babff2211e Auto merge of #97581 - AngelicosPhosphoros:improve_calloc_check_in_vec_macro_for_tuples, r=Mark-Simulacrum
Support vec zero-alloc optimization for tuples and byte arrays

* Implement IsZero trait for tuples up to 8 IsZero elements;
* Implement IsZero for u8/i8, leading to implementation of it for arrays of them too;
* Add more codegen tests for this optimization.
* Lower size of array for IsZero trait because it fails to inline checks
2022-07-25 00:20:43 +00:00
Ralf Jung
58f2ede15f interpret, ptr_offset_from: refactor and test too-far-apart check 2022-07-24 19:35:40 -04:00
AngelicosPhosphoros
86d445eda8 Support vec zero-alloc optimization for tuples and byte arrays
* Implement IsZero trait for tuples up to 8 IsZero elements;
* Implement IsZero for u8/i8, leading to implementation of it for arrays of them too;
* Add more codegen tests for this optimization.
* Lower size of array for IsZero trait because it fails to inline checks
2022-07-24 15:56:39 -04:00
Ralf Jung
d10a7b1243 add miri-track-caller to some intrinsic-exposing methods 2022-07-24 14:49:33 -04:00
David Tolnay
f1ca69d245
Revert write! and writeln! to late drop temporaries 2022-07-24 11:12:00 -07:00
Ralf Jung
51b3d51cf4
Rollup merge of #99657 - Phosra:patch-1, r=Dylan-DPC
Docs - remove unnecessary `mut` that gives a warning

Fixes #99654.

A trivial linting fix for a Stdio example.

`@rustbot` label +T-lib
2022-07-24 14:04:27 -04:00
Ben Kimock
5e5ce4327a Rename and document the new BufReader internals 2022-07-24 13:51:09 -04:00
Ben Kimock
b9497be7d0 Allow Buffer methods to inline 2022-07-24 12:50:05 -04:00
Ben Kimock
761ddf3e7f Remove some redundant checks from BufReader
The implementation of BufReader contains a lot of redundant checks.
While any one of these checks is not particularly expensive to execute,
especially when taken together they dramatically inhibit LLVM's ability
to make subsequent optimizations.
2022-07-24 12:50:05 -04:00
Deadbeef
65fca6db19 add const hack comment 2022-07-24 12:01:23 +00:00
Deadbeef
a89510e5f9 Add issue numbers 2022-07-24 12:01:22 +00:00