Skip to content

Commit

Permalink
Merge branch '⬆️-nightly-2023-03-18' into 🦆
Browse files Browse the repository at this point in the history
  • Loading branch information
yvt committed Mar 18, 2023
2 parents bad3292 + 1d49486 commit 079e2f8
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 97 deletions.
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
cargo-features = ["profile-rustflags"]

[workspace]
members = [
"examples/basic",
Expand Down Expand Up @@ -117,3 +119,8 @@ rev = "2a74b62c26724ff9c67e4e3ad05378a1af53f195"

[profile.release]
debug = true

# FIXME: Work-around for undefined symbol errors that occur with the
# combination of `-Zbuild-std`, `opt-level = "s"`, and `lto = true`
# <https://github.com/rust-lang/rust/issues/108853>
rustflags = ["-Zshare-generics=off"]
38 changes: 1 addition & 37 deletions doc/toolchain_limitations.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ type Alias<T> = Struct<{<T as Trait>::N}>;

### `[tag:const_for]` `for` loops are unusable in `const fn`

Technically it's available under the compiler feature `const_for`, but the lack of essential trait implementations (e.g., `[ref:range_const_iterator]`, `[ref:const_slice_iter]`) and above all the inability of implementing `const Iterator` (`[ref:iterator_const_default]`) make it unusable.
Technically it's available under the compiler feature `const_for`, but the lack of essential trait implementations (e.g., `[ref:range_const_iterator]`, `[ref:const_slice_iter]`) makes it unusable in many cases.


### `[tag:const_static_item_ref]` `const`s and `const fn`s can't refer to `static`s
Expand Down Expand Up @@ -430,23 +430,6 @@ const _: () = assert!(PartialEq::eq(&(A..A), &(A..A)));
```


### `[tag:type_id_partial_eq]` `TypeId: !const PartialEq`

The standard library doesn't provide a `const` trait implementation of `PartialEq` for `core::any::TypeId`.

```rust
use core::any::TypeId;
assert!(TypeId::of::<()>() == TypeId::of::<()>());
```

```rust,compile_fail,E0277
#![feature(const_type_id)]
use core::any::TypeId;
// error[E0277]: can't compare `TypeId` with `_` in const contexts
const _: () = assert!(TypeId::of::<()>() == TypeId::of::<()>());
```


### `[tag:range_const_iterator]` `Range<T>: !~const Iterator`

The standard library doesn't provide a `const` trait implementation of `Range<T>: Iterator`.
Expand All @@ -466,25 +449,6 @@ const _: () = assert!(matches!((2..4).next(), Some(2)));
```


### `[tag:iterator_const_default]` `Iterator` lack `#[const_trait]`

```rust,compile_fail
#![feature(const_trait_impl)]
#![feature(const_mut_refs)]
struct MyIterator;
// error: const `impl` for trait `Iterator` which is not marked with `#[const_trait]`
impl const Iterator for MyIterator {
type Item = u32;
fn next(&mut self) -> Option<Self::Item> {
Some(42)
}
}
```


### `[tag:const_assert_eq]` `assert_eq!` and similar macros are unusable in `const fn`

```rust,compile_fail,E0015
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2023-01-10"
channel = "nightly-2023-03-18"
components = ["rustfmt", "rust-src", "clippy"]
39 changes: 1 addition & 38 deletions src/r3_core/src/bag.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! A heterogeneous collection to store property values.
use core::mem::transmute;
use core::{any::TypeId, mem::transmute};

/// A heterogeneous collection to store property values.
#[const_trait]
Expand Down Expand Up @@ -88,40 +88,3 @@ mod private {
impl<Head: 'static, Tail: ~const Bag> const Sealed for super::List<Head, Tail> {}
impl<Left: ~const Bag, Right: ~const Bag> const Sealed for super::Either<Left, Right> {}
}

// `TypeId` doesn't implement `const PartialEq` [ref:type_id_partial_eq]
/// A wrapper of [`core::any::TypeId`] that is usable in a constant context.
struct TypeId {
inner: core::any::TypeId,
}

impl TypeId {
#[inline]
const fn of<T: 'static>() -> Self {
Self {
inner: core::any::TypeId::of::<T>(),
}
}

#[inline]
const fn eq(&self, other: &Self) -> bool {
// This relies on the implementation details of `TypeId`, but I think
// we're are okay judging by the fact that WebRender is doing the same
// <https://github.com/rust-lang/rust/pull/75923#issuecomment-683090745>
unsafe {
type TypeIdBytes = [u8; core::mem::size_of::<core::any::TypeId>()];
let x: TypeIdBytes = transmute(self.inner);
let y: TypeIdBytes = transmute(other.inner);
// Can't just do `x == y` due to [ref:array_const_partial_eq].
// A non-idiomatic loop must be used due to [ref:const_for].
let mut i = 0;
while i < x.len() {
if x[i] != y[i] {
return false;
}
i += 1;
}
true
}
}
}
17 changes: 4 additions & 13 deletions src/r3_core/src/bind/sorter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ pub(super) const fn sort_bindings<Callback, SorterUseInfoList, VertexList>(
End,
}

impl const MyIterator for VertexIter<'_> {
impl const Iterator for VertexIter<'_> {
type Item = Vertex;

fn next(&mut self) -> Option<Self::Item> {
Expand Down Expand Up @@ -369,7 +369,7 @@ pub(super) const fn sort_bindings<Callback, SorterUseInfoList, VertexList>(
End,
}

impl<Callback> const MyIterator for SuccessorIter<'_, Callback>
impl<Callback> const Iterator for SuccessorIter<'_, Callback>
where
Callback: ~const SorterCallback,
{
Expand Down Expand Up @@ -533,23 +533,14 @@ pub(super) const fn sort_bindings<Callback, SorterUseInfoList, VertexList>(
// Helper traits
// --------------------------------------------------------------------------

// `const Iterator` is currently very hard to implement
// [ref:iterator_const_default]
/// An [`Iterator`][] usable in `const fn`.
#[const_trait]
trait MyIterator {
type Item;
fn next(&mut self) -> Option<Self::Item>;
}

#[const_trait]
trait GraphAccess<VertexRef> {
type VertexIter<'a>: ~const MyIterator<Item = VertexRef> + ~const Destruct + 'a
type VertexIter<'a>: ~const Iterator<Item = VertexRef> + ~const Destruct + 'a
where
Self: 'a;
fn vertices(&self) -> Self::VertexIter<'_>;

type SuccessorIter<'a>: ~const MyIterator<Item = VertexRef> + ~const Destruct + 'a
type SuccessorIter<'a>: ~const Iterator<Item = VertexRef> + ~const Destruct + 'a
where
Self: 'a;
fn successors(&self, v: &VertexRef) -> Self::SuccessorIter<'_>;
Expand Down
1 change: 0 additions & 1 deletion src/r3_kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#![feature(const_swap)]
#![feature(never_type)] // `!`
#![feature(decl_macro)]
#![feature(pin_macro)]
#![feature(doc_cfg)] // `#[doc(cfg(...))]`
#![deny(unsafe_op_in_unsafe_fn)]
#![cfg_attr(
Expand Down
2 changes: 1 addition & 1 deletion src/r3_kernel/src/utils/ctz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ mod tests {
} else {
let low = i & 31;
let high = i >> 5;
low | (high << (bits - 5))
low | high.checked_shl((bits - 5) as u32).unwrap()
} as usize;

let got = $func(in_value);
Expand Down
1 change: 0 additions & 1 deletion src/r3_port_std/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![feature(cfg_target_has_atomic)] // `#[cfg(target_has_atomic_load_store)]`
#![feature(atomic_mut_ptr)]
#![feature(thread_local)]
#![feature(deadline_api)]
#![feature(once_cell)]
Expand Down
8 changes: 4 additions & 4 deletions src/r3_port_std/src/threading_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ pub fn park() {
while token_count < 0 {
unsafe {
synchapi::WaitOnAddress(
token_count_cell.as_mut_ptr().cast(), // location to watch
token_count_cell.as_ptr().cast(), // location to watch
addr_of!(token_count).cast_mut().cast(), // undesired value
std::mem::size_of::<isize>(), // value size
INFINITE, // timeout
Expand All @@ -116,7 +116,7 @@ impl Thread {
let _guard = self.data.remote_op_mutex.lock().unwrap();
let token_count_cell = &self.data.token_count;
if token_count_cell.fetch_add(1, Ordering::Relaxed) == -1 {
unsafe { synchapi::WakeByAddressAll(token_count_cell.as_mut_ptr().cast()) };
unsafe { synchapi::WakeByAddressAll(token_count_cell.as_ptr().cast()) };
unsafe { processthreadsapi::ResumeThread(self.data.hthread) };
}
}
Expand Down Expand Up @@ -256,7 +256,7 @@ mod mutex {
{
unsafe {
synchapi::WaitOnAddress(
self.locked.as_mut_ptr().cast(), // location to watch
self.locked.as_ptr().cast(), // location to watch
[true].as_ptr().cast_mut().cast(), // undesired value
std::mem::size_of::<bool>(), // value size
INFINITE, // timeout
Expand All @@ -283,7 +283,7 @@ mod mutex {
#[inline]
fn drop(&mut self) {
self.locked.store(false, Ordering::Release);
unsafe { synchapi::WakeByAddressSingle(self.locked.as_mut_ptr().cast()) };
unsafe { synchapi::WakeByAddressSingle(self.locked.as_ptr().cast()) };
}
}

Expand Down
1 change: 0 additions & 1 deletion src/r3_test_runner/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#![feature(lint_reasons)]
#![feature(decl_macro)] // `macro`
#![feature(once_cell)]
#![feature(pin_macro)] // `core::pin::pin!`
#![warn(must_not_suspend)]
use anyhow::{bail, Context};
use clap::Parser;
Expand Down

0 comments on commit 079e2f8

Please sign in to comment.