| Age | Commit message (Collapse) | Author | Lines | |
|---|---|---|---|---|
| 2022-11-22 | Rollup merge of #83608 - Kimundi:index_many, r=Mark-Simulacrum | Manish Goregaokar | -0/+1 | |
| Add slice methods for indexing via an array of indices. Disclaimer: It's been a while since I contributed to the main Rust repo, apologies in advance if this is large enough already that it should've been an RFC. --- # Update: - Based on feedback, removed the `&[T]` variant of this API, and removed the requirements for the indices to be sorted. # Description This adds the following slice methods to `core`: ```rust impl<T> [T] { pub unsafe fn get_many_unchecked_mut<const N: usize>(&mut self, indices: [usize; N]) -> [&mut T; N]; pub fn get_many_mut<const N: usize>(&mut self, indices: [usize; N]) -> Option<[&mut T; N]>; } ``` This allows creating multiple mutable references to disjunct positions in a slice, which previously required writing some awkward code with `split_at_mut()` or `iter_mut()`. For the bound-checked variant, the indices are checked against each other and against the bounds of the slice, which requires `N * (N + 1) / 2` comparison operations. This has a proof-of-concept standalone implementation here: https://crates.io/crates/index_many Care has been taken that the implementation passes miri borrow checks, and generates straight-forward assembly (though this was only checked on x86_64). # Example ```rust let v = &mut [1, 2, 3, 4]; let [a, b] = v.get_many_mut([0, 2]).unwrap(); std::mem::swap(a, b); *v += 100; assert_eq!(v, &[3, 2, 101, 4]); ``` # Codegen Examples <details> <summary>Click to expand!</summary> Disclaimer: Taken from local tests with the standalone implementation. ## Unchecked Indexing: ```rust pub unsafe fn example_unchecked(slice: &mut [usize], indices: [usize; 3]) -> [&mut usize; 3] { slice.get_many_unchecked_mut(indices) } ``` ```nasm example_unchecked: mov rcx, qword, ptr, [r9] mov r8, qword, ptr, [r9, +, 8] mov r9, qword, ptr, [r9, +, 16] lea rcx, [rdx, +, 8*rcx] lea r8, [rdx, +, 8*r8] lea rdx, [rdx, +, 8*r9] mov qword, ptr, [rax], rcx mov qword, ptr, [rax, +, 8], r8 mov qword, ptr, [rax, +, 16], rdx ret ``` ## Checked Indexing (Option): ```rust pub unsafe fn example_option(slice: &mut [usize], indices: [usize; 3]) -> Option<[&mut usize; 3]> { slice.get_many_mut(indices) } ``` ```nasm mov r10, qword, ptr, [r9, +, 8] mov rcx, qword, ptr, [r9, +, 16] cmp rcx, r10 je .LBB0_7 mov r9, qword, ptr, [r9] cmp rcx, r9 je .LBB0_7 cmp rcx, r8 jae .LBB0_7 cmp r10, r9 je .LBB0_7 cmp r9, r8 jae .LBB0_7 cmp r10, r8 jae .LBB0_7 lea r8, [rdx, +, 8*r9] lea r9, [rdx, +, 8*r10] lea rcx, [rdx, +, 8*rcx] mov qword, ptr, [rax], r8 mov qword, ptr, [rax, +, 8], r9 mov qword, ptr, [rax, +, 16], rcx ret .LBB0_7: mov qword, ptr, [rax], 0 ret ``` ## Checked Indexing (Panic): ```rust pub fn example_panic(slice: &mut [usize], indices: [usize; 3]) -> [&mut usize; 3] { let len = slice.len(); match slice.get_many_mut(indices) { Some(s) => s, None => { let tmp = indices; index_many::sorted_bound_check_failed(&tmp, len) } } } ``` ```nasm example_panic: sub rsp, 56 mov rax, qword, ptr, [r9] mov r10, qword, ptr, [r9, +, 8] mov r9, qword, ptr, [r9, +, 16] cmp r9, r10 je .LBB0_6 cmp r9, rax je .LBB0_6 cmp r9, r8 jae .LBB0_6 cmp r10, rax je .LBB0_6 cmp rax, r8 jae .LBB0_6 cmp r10, r8 jae .LBB0_6 lea rax, [rdx, +, 8*rax] lea r8, [rdx, +, 8*r10] lea rdx, [rdx, +, 8*r9] mov qword, ptr, [rcx], rax mov qword, ptr, [rcx, +, 8], r8 mov qword, ptr, [rcx, +, 16], rdx mov rax, rcx add rsp, 56 ret .LBB0_6: mov qword, ptr, [rsp, +, 32], rax mov qword, ptr, [rsp, +, 40], r10 mov qword, ptr, [rsp, +, 48], r9 lea rcx, [rsp, +, 32] mov edx, 3 call index_many::bound_check_failed ud2 ``` </details> # Extensions There are multiple optional extensions to this. ## Indexing With Ranges This could easily be expanded to allow indexing with `[I; N]` where `I: SliceIndex<Self>`. I wanted to keep the initial implementation simple, so I didn't include it yet. ## Panicking Variant We could also add this method: ```rust impl<T> [T] { fn index_many_mut<const N: usize>(&mut self, indices: [usize; N]) -> [&mut T; N]; } ``` This would work similar to the regular index operator and panic with out-of-bound indices. The advantage would be that we could more easily ensure good codegen with a useful panic message, which is non-trivial with the `Option` variant. This is implemented in the standalone implementation, and used as basis for the codegen examples here and there. | ||||
| 2022-11-21 | dont attempt strict provenance in SGX | Ralf Jung | -0/+1 | |
| 2022-11-21 | reflow the stack size story | Tshepang Mbambo | -2/+4 | |
| 2022-11-20 | enable fuzzy_provenance_casts lint in libstd | Ralf Jung | -4/+7 | |
| 2022-11-20 | Rollup merge of #104558 - thomcc:unalign-diriter, r=ChrisDenton | Matthias Krüger | -10/+23 | |
| Don't assume `FILE_ID_BOTH_DIR_INFO` will be aligned Fixes #104530. See that issue for info. r? `@ChrisDenton` | ||||
| 2022-11-20 | Rollup merge of #104537 - HintringerFabian:docs_default_min_stack_size, ↵ | Matthias Krüger | -3/+2 | |
| r=the8472 fix std::thread docs are unclear regarding stack sizes Improves the documentation about the default stack size of a spawned thread Fixes #102671 | ||||
| 2022-11-20 | Add get_many_mut methods to slice | Marvin Löbel | -0/+1 | |
| 2022-11-20 | cfg(miri) no longer needed in sys/unix/time.rs | Ralf Jung | -2/+2 | |
| 2022-11-20 | Improve documentation of Stack size | Fabian Hintringer | -3/+2 | |
| 2022-11-19 | Add unstable `type_ascribe` macro | Nilstrieb | -0/+8 | |
| This macro serves as a placeholder for future type ascription syntax to make sure that the semantic implementation keeps working. | ||||
| 2022-11-19 | Rollup merge of #104553 - mwillsey:asinh-acosh-accuracy, r=thomcc | Dylan DPC | -4/+32 | |
| Improve accuracy of asinh and acosh This PR addresses the inaccuracy of `asinh` and `acosh` identified by the [Herbie](http://herbie.uwplse.org/) tool, `@pavpanchekha,` `@finnbear` in #104548. It also adds a couple tests that failed in the existing implementations and now pass. Closes #104548 r? rust-lang/libs | ||||
| 2022-11-19 | Rollup merge of #104528 - WaffleLapkin:lazy_lock_docfix, r=matklad | Dylan DPC | -3/+7 | |
| Properly link `{Once,Lazy}{Cell,Lock}` in docs See https://github.com/rust-lang/rust/issues/74465#issuecomment-1317947443 | ||||
| 2022-11-18 | Rollup merge of #103594 - maniwani:fix-issue-91417, r=thomcc | Matthias Krüger | -9/+24 | |
| Fix non-associativity of `Instant` math on `aarch64-apple-darwin` targets This is a duplicate of #94100 (since the original author is unresponsive), which resolves #91417. On `aarch64-apple-darwin` targets, the internal resolution of `Instant` is lower than that of `Duration`, so math between them becomes non-associative with small-enough durations. This PR makes this target use the standard Unix implementation (where `Instant` has 1ns resolution), but with `CLOCK_UPTIME_RAW` so it still returns the same values as `mach_absolute_time`[^1]. (Edit: I need someone to confirm that this still works, I do not have access to an M1 device.) [^1]: https://www.manpagez.com/man/3/clock_gettime/ | ||||
| 2022-11-18 | Handle the case that even the filename array is unaligned. | Thom Chiovoloni | -5/+14 | |
| 2022-11-17 | Don't assume `FILE_ID_BOTH_DIR_INFO` will be aligned | Thom Chiovoloni | -5/+9 | |
| 2022-11-17 | Improve accuracy of asinh and acosh | Max Willsey | -4/+32 | |
| 2022-11-17 | Properly link `{Once,Lazy}{Cell,Lock}` in docs | Maybe Waffle | -3/+7 | |
| 2022-11-16 | available_parallelism: Handle 0 cfs_period_us | Adam Casey | -2/+2 | |
| There seem to be some scenarios where `cpu.cfs_period_us` can contain `0` This causes a panic when calling `std::thread::available_parallelism()` as is done so from binaries built by `cargo test`, which was how the issue was discovered. I don't feel like `0` is a good value for `cpu.cfs_period_us`, but I also don't think applications should panic if this value is seen. This case is handled by other projects which read this information: - num_cpus: https://github.com/seanmonstar/num_cpus/blob/e437b9d9083d717692e35d917de8674a7987dd06/src/linux.rs#L207-L210 - ninja: https://github.com/ninja-build/ninja/pull/2174/files - dotnet: https://github.com/dotnet/runtime/blob/c4341d45acca3ea662cd8d71e7d71094450dd045/src/coreclr/pal/src/misc/cgroup.cpp#L481-L483 Before this change, this panic could be seen in environments setup as described above: ``` $ RUST_BACKTRACE=1 cargo test Finished test [unoptimized + debuginfo] target(s) in 3.55s Running unittests src/main.rs (target/debug/deps/x-9a42e145aca2934d) thread 'main' panicked at 'attempt to divide by zero', library/std/src/sys/unix/thread.rs:546:70 stack backtrace: 0: rust_begin_unwind 1: core::panicking::panic_fmt 2: core::panicking::panic 3: std::sys::unix::thread::cgroups::quota 4: std::sys::unix::thread::available_parallelism 5: std::thread::available_parallelism 6: test::helpers::concurrency::get_concurrency 7: test::console::run_tests_console 8: test::test_main 9: test::test_main_static 10: x::main at ./src/main.rs:1:1 11: core::ops::function::FnOnce::call_once at /tmp/rust-1.64-1.64.0-1/library/core/src/ops/function.rs:248:5 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. error: test failed, to rerun pass '--bin local-rabmq-amqpprox' ``` I've tested this change in an environment which has the bad setup and rebuilding the test executable against a fixed std library fixes the panic. | ||||
| 2022-11-16 | Rollup merge of #104401 - RalfJung:mpsc-leak, r=Amanieu | Matthias Krüger | -2/+3 | |
| avoid memory leak in mpsc test r? ```@Amanieu``` | ||||
| 2022-11-15 | Rollup merge of #103734 - Mark-Simulacrum:fix-version-stabilized, r=JohnTitor | Matthias Krüger | -2/+2 | |
| Adjust stabilization version to 1.65.0 for wasi fds See https://github.com/rust-lang/rust/pull/103308#issuecomment-1292277645 for this ask. Backport of that PR to beta (1.65.0) will include a similar patch. | ||||
| 2022-11-15 | Auto merge of #104428 - matthiaskrgr:rollup-jo3078i, r=matthiaskrgr | bors | -2/+0 | |
| Rollup of 13 pull requests Successful merges: - #103842 (Adding Fuchsia compiler testing script, docs) - #104354 (Remove leading newlines from `NonZero*` doc examples) - #104372 (Update compiler-builtins) - #104380 (rustdoc: remove unused CSS `code { opacity: 1 }`) - #104381 (Remove dead NoneError diagnostic handling) - #104383 (Remove unused symbols and diagnostic items) - #104391 (Deriving cleanups) - #104403 (Specify language of code comment to generate document) - #104404 (Fix missing minification for static files) - #104413 ([llvm-wrapper] adapt for LLVM API change) - #104415 (rustdoc: fix corner case in search keyboard commands) - #104422 (Fix suggest associated call syntax) - #104426 (Add test for #102154) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup | ||||
| 2022-11-15 | Rollup merge of #104383 - WaffleLapkin:rustc_undiagnostic_item, ↵ | Matthias Krüger | -2/+0 | |
| r=compiler-errors Remove unused symbols and diagnostic items As the title suggests, this removes unused symbols from `sym::` and `#[rustc_diagnostic_item]` annotations that weren't mentioned anywhere. Originally I tried to use grep, to find symbols and item names that are never mentioned via `sym::name`, however this produced a lot of false positives (?), for example clippy matching on `Symbol::as_str` or macros "implicitly" adding `sym::`. I ended up fixing all these false positives (?) by hand, but tbh I'm not sure if it was worth it... | ||||
| 2022-11-14 | Rollup merge of #101967 - jmillikin:linux-abstract-socket-addr, r=joshtriplett | Matthias Krüger | -95/+140 | |
| Move `unix_socket_abstract` feature API to `SocketAddrExt`. The pre-stabilized API for abstract socket addresses exposes methods on `SocketAddr` that are only enabled for `cfg(any(target_os = "android", target_os = "linux"))`. Per discussion in <https://github.com/rust-lang/rust/issues/85410>, moving these methods to an OS-specific extension trait is required before stabilization can be considered. This PR makes four changes: 1. The internal module `std::os::net` contains logic for the unstable feature `tcp_quickack` (https://github.com/rust-lang/rust/issues/96256). I moved that code into `linux_ext/tcp.rs` and tried to adjust the module tree so it could accommodate a second unstable feature there. 2. Moves the public API out of `impl SocketAddr`, into `impl SocketAddrExt for SocketAddr` (the headline change). 3. The existing function names and docs for `unix_socket_abstract` refer to addresses as being created from abstract namespaces, but a more accurate description is that they create sockets in *the* abstract namespace. I adjusted the function signatures correspondingly and tried to update the docs to be clearer. 4. I also tweaked `from_abstract_name` so it takes an `AsRef<[u8]>` instead of `&[u8]`, allowing `b""` literals to be passed directly. Issues: 1. The public module `std::os::linux::net` is marked as part of `tcp_quickack`. I couldn't figure out how to mark a module as being part of two unstable features, so I just left the existing attributes in place. My hope is that this will be fixed as a side-effect of stabilizing either feature. | ||||
| 2022-11-14 | macos, aarch64, and not(miri) | Cameron | -2/+2 | |
| 2022-11-14 | std: move `ReentrantMutex` to `sync` | joboet | -4/+5 | |
| 2022-11-14 | avoid memory leak in mpsc test | Ralf Jung | -2/+3 | |
| 2022-11-14 | Auto merge of #104387 - Manishearth:rollup-9e551p5, r=Manishearth | bors | -1/+12 | |
| Rollup of 9 pull requests Successful merges: - #103709 (ci: Upgrade dist-x86_64-netbsd to NetBSD 9.0) - #103744 (Upgrade cc for working is_flag_supported on cross-compiles) - #104105 (llvm: dwo only emitted when object code emitted) - #104158 (Return .efi extension for EFI executable) - #104181 (Add a few known-bug tests) - #104266 (Regression test for coercion of mut-ref to dyn-star) - #104300 (Document `Path::parent` behavior around relative paths) - #104304 (Enable profiler in dist-s390x-linux) - #104362 (Add `delay_span_bug` to `AttrWrapper::take_for_recovery`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup | ||||
| 2022-11-13 | Rollup merge of #104300 - tbu-:pr_path_parent_caveats, r=Mark-Simulacrum | Manish Goregaokar | -1/+12 | |
| Document `Path::parent` behavior around relative paths A relative path with just one component will return `Some("")` as its parent, which wasn't clear to me from the documentation. The parent of `""` is `None`, which was missing from the documentation as well. | ||||
| 2022-11-14 | Auto merge of #103858 - Mark-Simulacrum:bump-bootstrap, r=pietroalbini | bors | -1/+1 | |
| Bump bootstrap compiler to 1.66 This PR: - Bumps version placeholders to release - Bumps to latest beta - cfg-steps code r? `@pietroalbini` | ||||
| 2022-11-13 | Auto merge of #103894 - mati865:gnullvm-libunwind-changes, r=thomcc | bors | -1/+1 | |
| Change the way libunwind is linked for *-windows-gnullvm targets I have no idea why previous way works for `x86_64-fortanix-unknown-sgx` (assuming it actually works...) but not for `gnullvm`. It fails when linking libtest during Rust build (unless somebody adds `RUSTFLAGS='-Clinkarg=-lunwind'`). Also fixes exception handling on AArch64. | ||||
| 2022-11-13 | just use `libc::clockid_t` | Cameron | -8/+3 | |
| 2022-11-13 | Fix non-associativity of `Instant` math on `aarch64-apple-darwin` targets | Joy | -3/+23 | |
| 2022-11-13 | Remove unused diagnostic items | Maybe Waffle | -2/+0 | |
| 2022-11-13 | Auto merge of #93563 - ibraheemdev:crossbeam-channel, r=Amanieu | bors | -2848/+2739 | |
| Merge crossbeam-channel into `std::sync::mpsc` This PR imports the [`crossbeam-channel`](https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-channel#crossbeam-channel) crate into the standard library as a private module, `sync::mpmc`. `sync::mpsc` is now implemented as a thin wrapper around `sync::mpmc`. The primary purpose of this PR is to resolve https://github.com/rust-lang/rust/issues/39364. The public API intentionally remains the same. The reason https://github.com/rust-lang/rust/issues/39364 has not been fixed in over 5 years is that the current channel is *incredibly* complex. It was written many years ago and has sat mostly untouched since. `crossbeam-channel` has become the most popular alternative on crates.io, amassing over 30 million downloads. While crossbeam's channel is also complex, like all fast concurrent data structures, it avoids some of the major issues with the current implementation around dynamic flavor upgrades. The new implementation decides on the datastructure to be used when the channel is created, and the channel retains that structure until it is dropped. Replacing `sync::mpsc` with a simpler, less performant implementation has been discussed as an alternative. However, Rust touts itself as enabling *fearless concurrency*, and having the standard library feature a subpar implementation of a core concurrency primitive doesn't feel right. The argument is that slower is better than broken, but this PR shows that we can do better. As mentioned before, the primary purpose of this PR is to fix https://github.com/rust-lang/rust/issues/39364, and so the public API intentionally remains the same. *After* that problem is fixed, the fact that `sync::mpmc` now exists makes it easier to fix the primary limitation of `mpsc`, the fact that it only supports a single consumer. spmc and mpmc are two other common concurrency patterns, and this change enables a path to deprecating `mpsc` and exposing a general `sync::channel` module that supports multiple consumers. It also implements other useful methods such as `send_timeout`. That said, exposing MPMC and other new functionality is mostly out of scope for this PR, and it would be helpful if discussion stays on topic :) For what it's worth, the new implementation has also been shown to be more performant in [some basic benchmarks](https://github.com/crossbeam-rs/crossbeam/tree/master/crossbeam-channel/benchmarks#results). cc `@taiki-e` r? rust-lang/libs | ||||
| 2022-11-12 | avoid using channels in thread-local tests | Ibraheem Ahmed | -22/+44 | |
| 2022-11-12 | avoid calling `thread::current` in channel destructor | Ibraheem Ahmed | -13/+11 | |
| 2022-11-12 | Use correct EH personality on `*-windows-gnu-*` | Mateusz Mikuła | -1/+1 | |
| 2022-11-12 | Rollup merge of #102049 - fee1-dead-contrib:derive_const, r=oli-obk | Dylan DPC | -0/+4 | |
| Add the `#[derive_const]` attribute Closes #102371. This is a minimal patchset for the attribute to work. There are no restrictions on what traits this attribute applies to. r? `````@oli-obk````` | ||||
| 2022-11-12 | Auto merge of #103150 - joboet:remove_lock_wrappers, r=m-ou-se | bors | -653/+404 | |
| Remove lock wrappers in `sys_common` This moves the lazy allocation to `sys` (SGX and UNIX). While this leads to a bit more verbosity, it will simplify future improvements by making room in `sys_common` for platform-independent implementations. This also removes the condvar check on SGX as it is not necessary for soundness and will be removed anyway once mutex has been made movable. For simplicity's sake, `libunwind` also uses lazy allocation now on SGX. This will require an update to the C definitions before merging this (CC `@raoulstrackx).` r? `@m-ou-se` | ||||
| 2022-11-11 | Document `Path::parent` behavior around relative paths | Tobias Bucher | -1/+12 | |
| A relative path with just one component will return `Some("")` as its parent, which wasn't clear to me from the documentation. The parent of `""` is `None`, which was missing from the documentation as well. | ||||
| 2022-11-10 | Rollup merge of #104060 - ink-feather-org:const_hash, r=fee1-dead | Manish Goregaokar | -3/+7 | |
| Make `Hash`, `Hasher` and `BuildHasher` `#[const_trait]` and make `Sip` const `Hasher` This PR enables using Hashes in const context. r? ``@fee1-dead`` | ||||
| 2022-11-09 | tidy | Ibraheem Ahmed | -5/+4 | |
| 2022-11-09 | spin less in `mpsc::SyncSender::send` | Ibraheem Ahmed | -1/+1 | |
| 2022-11-09 | remove extra spinning from `mpsc` parker | Ibraheem Ahmed | -15/+0 | |
| 2022-11-09 | `sync::mpsc`: quadratic backoff | Ibraheem Ahmed | -2/+3 | |
| 2022-11-09 | `sync::mpsc`: reload state after spinning on CAS failure | Ibraheem Ahmed | -8/+8 | |
| 2022-11-09 | remove extra spinning from `mpsc::Receiver::recv` | Ibraheem Ahmed | -26/+6 | |
| 2022-11-09 | remove mention of rust-lang#39364 from mpsc docs | Ibraheem Ahmed | -28/+0 | |
| 2022-11-09 | add test case for rust-lang#39364 | Ibraheem Ahmed | -0/+14 | |
| 2022-11-09 | implement `sync::mpsc` as a wrapper around `sync::mpmc` | Ibraheem Ahmed | -2798/+24 | |
