Skip to content

Commit

Permalink
Merge branch '⬆️-nightly-2022-08-11' into 🦆
Browse files Browse the repository at this point in the history
  • Loading branch information
yvt committed Aug 13, 2022
2 parents 588c1bc + 0299502 commit 3d64ddb
Show file tree
Hide file tree
Showing 102 changed files with 160 additions and 348 deletions.
35 changes: 2 additions & 33 deletions doc/toolchain_limitations.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,22 +158,6 @@ const fn clone_projection<T: ~const Trait>(p: &T::Proj) -> T::Proj {
```


### `[tag:const_supertraits]` Supertraits can't have `~const`

*Upstream PR:* [rust-lang/rust#93429](https://github.com/rust-lang/rust/pull/93429) might resolve this

```rust
#![feature(const_trait_impl)]
trait Trait: Clone {}
```

```rust,compile_fail
#![feature(const_trait_impl)]
// error: `~const` is not allowed here
trait Trait: ~const Clone {}
```


### `[tag:impl_block_const_bounds]` The trait bounds of an `impl` block can't include `~const`

```rust,compile_fail
Expand Down Expand Up @@ -486,10 +470,10 @@ use core::any::TypeId;
assert!(TypeId::of::<()>() == TypeId::of::<()>());
```

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

Expand Down Expand Up @@ -578,21 +562,6 @@ const _: () = f::<()>();
```


### `[tag:int_const_ord]` `<integer>: !const Ord`

The standard library doesn't provide `const` trait implementations of `Ord` for the built-in integer types.

```rust
assert!(2i32.max(3) == 3);
```

```rust,compile_fail,E0277
#![feature(const_trait_impl)]
// error[E0277]: the trait bound `i32: ~const Ord` is not satisfied
const _: () = assert!(2i32.max(3) == 3);
```


### `[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 examples/basic_wio_terminal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ mod queue {
impl<System: SupportedSystem, T: Init + Copy + Send + 'static> Queue<System, T> {
pub const fn new<C>(cfg: &mut Cfg<C>) -> Self
where
C: ~const traits::CfgBase<System = System> + ~const traits::CfgMutex,
C: ~const traits::CfgMutex<System = System>,
{
Self {
st: StaticMutex::define()
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2022-06-26
nightly-2022-08-11
14 changes: 5 additions & 9 deletions src/r3/src/bind/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
/// # type Objects = ();
/// const fn configure_app<C>(cfg: &mut Cfg<C>)
/// where
/// C: ~const traits::CfgBase<System = System> +
/// ~const traits::CfgTask +
/// C: ~const traits::CfgTask<System = System> +
/// ~const traits::CfgTimer,
/// {
/// // Create a binding and give the timer an exclusive access
Expand Down Expand Up @@ -97,8 +96,7 @@
/// # type Objects = ();
/// const fn configure_app<C>(cfg: &mut Cfg<C>)
/// where
/// C: ~const traits::CfgBase<System = System> +
/// ~const traits::CfgTask +
/// C: ~const traits::CfgTask<System = System> +
/// ~const traits::CfgTimer,
/// {
/// let count = bind((), || 0).finish(cfg);
Expand All @@ -119,7 +117,7 @@
/// ```
)]
#![doc = include_str!("../common.md")]
use r3_core::kernel::{cfg, raw_cfg};
use r3_core::kernel::cfg;

pub use r3_core::bind::{
fn_bind_map, Bind, BindBorrow, BindBorrowMut, BindDefiner, BindRef, BindTable, BindTake,
Expand Down Expand Up @@ -196,8 +194,7 @@ pub const fn bind_uninit<'pool, T, C>(
) -> Bind<'pool, C::System, core::mem::MaybeUninit<T>>
where
T: 'static,
// `~const CfgBase` not implied due to [ref:const_supertraits]
C: ~const raw_cfg::CfgBase + ~const cfg::CfgStatic,
C: ~const cfg::CfgStatic,
{
// Safety: `MaybeUninit` is safe to leave uninitialized
unsafe { Bind::define().uninit_unchecked().finish(cfg) }
Expand Down Expand Up @@ -234,8 +231,7 @@ where
pub const fn bind_default<'pool, T, C>(cfg: &mut cfg::Cfg<'pool, C>) -> Bind<'pool, C::System, T>
where
T: Default + 'static,
// `~const CfgBase` not implied due to [ref:const_supertraits]
C: ~const raw_cfg::CfgBase + ~const cfg::CfgStatic,
C: ~const cfg::CfgStatic,
{
Bind::define().init(Default::default).finish(cfg)
}
7 changes: 2 additions & 5 deletions src/r3/src/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ pub struct GenericMutex<Cell, Mutex> {
///
/// const fn configure_app<C>(cfg: &mut Cfg<C>) -> Objects
/// where
/// C: ~const traits::CfgBase<System = System> +
/// ~const traits::CfgTask +
/// C: ~const traits::CfgTask<System = System> +
/// ~const traits::CfgMutex,
/// {
/// StaticTask::define()
Expand Down Expand Up @@ -272,9 +271,7 @@ where
System: traits::KernelMutex + traits::KernelStatic,
{
/// Complete the definition of a mutex, returning a reference to the mutex.
// `CfgMutex` can't have `~const CfgBase` as a supertrait because of
// [ref:const_supertraits], hence we need to specify `~const CfgBase` here
pub const fn finish<C: ~const traits::CfgMutex<System = System> + ~const traits::CfgBase>(
pub const fn finish<C: ~const traits::CfgMutex<System = System>>(
self,
cfg: &mut Cfg<C>,
) -> StaticMutex<System, Source::Target>
Expand Down
7 changes: 2 additions & 5 deletions src/r3/src/sync/recursive_mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ pub struct GenericRecursiveMutex<Cell, Mutex> {
///
/// const fn configure_app<C>(cfg: &mut Cfg<C>) -> Objects
/// where
/// C: ~const traits::CfgBase<System = System> +
/// ~const traits::CfgTask +
/// C: ~const traits::CfgTask<System = System> +
/// ~const traits::CfgMutex,
/// {
/// StaticTask::define()
Expand Down Expand Up @@ -310,9 +309,7 @@ where
System: traits::KernelMutex + traits::KernelStatic,
{
/// Complete the definition of a mutex, returning a reference to the mutex.
// `CfgMutex` can't have `~const CfgBase` as a supertrait because of
// [ref:const_supertraits], hence we need to specify `~const CfgBase` here
pub const fn finish<C: ~const traits::CfgMutex<System = System> + ~const traits::CfgBase, T>(
pub const fn finish<C: ~const traits::CfgMutex<System = System>, T>(
self,
cfg: &mut Cfg<C>,
) -> StaticRecursiveMutex<System, T>
Expand Down
1 change: 1 addition & 0 deletions src/r3_core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added

- The new blanket-implemented `CfgStatic` trait can be used to simplify some trait bounds of configuration functions.
- The `Cfg*` traits now include `~const` in their supertraits ([rust-lang/rust#93429](https://github.com/rust-lang/rust/pull/93429)), making `~const CfgBase` trait bound unnecessary if it's implied by others.

### Fixed

Expand Down
46 changes: 29 additions & 17 deletions src/r3_core/src/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,7 @@ impl<'pool, System, T> DivideBind<'pool, System, T> {
///
/// const fn configure_app<C>(cfg: &mut Cfg<C>)
/// where
// `~const CfgBase` not implied due to [ref:const_supertraits]
/// C: ~const traits::CfgBase + ~const traits::CfgStatic,
/// C: ~const traits::CfgStatic,
/// {
/// let values = Bind::define().init(|| (12, 34)).finish(cfg);
/// let (value0, value1) = values.unzip();
Expand Down Expand Up @@ -818,8 +817,7 @@ impl<'pool, const LEN: usize, System, T> const UnzipBind for Bind<'pool, System,
///
/// const fn configure_app<C>(cfg: &mut Cfg<C>)
/// where
/// C: ~const traits::CfgBase +
/// ~const traits::CfgTask,
/// C: ~const traits::CfgTask,
/// C::System: traits::KernelStatic,
/// {
/// let foo = Bind::define().init(|| {
Expand Down Expand Up @@ -1339,31 +1337,45 @@ where
{
type Output = NewOutput;

// This opaque type must be defined outside this trait to
// prevent the unintended capturing of `Binder`.
// [ref:opaque_type_extraneous_capture]
type BoundFn = MappedBoundFn<InnerBoundFn, Output, Mapper, NewOutput>;
type BoundFn = MappedBoundFn<InnerBoundFn, Mapper>;

fn bind(self, binder: Binder, ctx: &mut CfgBindCtx<'_>) -> Self::BoundFn {
map_bind_inner(self.inner.bind(binder, ctx), self.mapper)
MappedBoundFn {
inner_bound_fn: self.inner.bind(binder, ctx),
mapper: self.mapper,
}
}
}

type MappedBoundFn<InnerBoundFn, Output, Mapper, NewOutput>
where
InnerBoundFn: FnOnce() -> Output + Copy + Send + 'static,
Mapper: FnOnce(Output) -> NewOutput + Copy + Send + 'static,
= impl FnOnce() -> NewOutput + Copy + Send + 'static;
// // This opaque type must be defined outside this trait to
// // prevent the unintended capturing of `Binder`.
// // [ref:opaque_type_extraneous_capture]
// type MappedBoundFn<InnerBoundFn, Output, Mapper, NewOutput>
// where
// InnerBoundFn: FnOnce() -> Output + Copy + Send + 'static,
// Mapper: FnOnce(Output) -> NewOutput + Copy + Send + 'static,
// = impl FnOnce() -> NewOutput + Copy + Send + 'static;

const fn map_bind_inner<InnerBoundFn, Output, Mapper, NewOutput>(
// FIXME: This is supposed to be a TAIT like the one above, but
// [ref:rust_99793_tait] prevents that
#[doc(hidden)]
#[derive(Copy, Clone)]
pub struct MappedBoundFn<InnerBoundFn, Mapper> {
inner_bound_fn: InnerBoundFn,
mapper: Mapper,
) -> MappedBoundFn<InnerBoundFn, Output, Mapper, NewOutput>
}

impl<InnerBoundFn, Output, Mapper, NewOutput> FnOnce<()> for MappedBoundFn<InnerBoundFn, Mapper>
where
InnerBoundFn: FnOnce() -> Output + Copy + Send + 'static,
Mapper: FnOnce(Output) -> NewOutput + Copy + Send + 'static,
{
move || (mapper)(inner_bound_fn())
type Output = NewOutput;

#[inline]
extern "rust-call" fn call_once(self, (): ()) -> Self::Output {
(self.mapper)((self.inner_bound_fn)())
}
}

// Binder traits
Expand Down
10 changes: 4 additions & 6 deletions src/r3_core/src/bind/sorter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
// restricted to "comptime" anymore
use core::{
marker::Destruct,
ops::{Deref, DerefMut, Index, IndexMut},
ops::{Index, IndexMut},
};

use super::{BindBorrowType, BindUsage};
Expand Down Expand Up @@ -149,8 +149,8 @@ pub(super) const fn sort_bindings<Callback, SorterUseInfoList, VertexList>(
temp_vertices: &mut VertexList,
) where
Callback: ~const SorterCallback,
SorterUseInfoList: ~const VecLike<Element = SorterUseInfo> + ~const Deref + ~const DerefMut,
VertexList: ~const VecLike<Element = Vertex> + ~const Deref + ~const DerefMut,
SorterUseInfoList: ~const VecLike<Element = SorterUseInfo>,
VertexList: ~const VecLike<Element = Vertex>,
{
// Preconditions
let num_binds = cb.num_binds();
Expand Down Expand Up @@ -605,9 +605,7 @@ where
Graph::SuccessorIter<'a>: ~const MyIterator + ~const Destruct,
VertexRef: Copy,
VertexRefLessThan: ~const FnMut(&VertexRef, &VertexRef) -> bool,
// `~const Deref[Mut]` isn't implied because of
// [ref:veclike_const_supertrait]
ReadyVertexQueue: ~const VecLike<Element = VertexRef> + ~const Deref + ~const DerefMut,
ReadyVertexQueue: ~const VecLike<Element = VertexRef>,
for<'index> VertexInfoMap: ~const Index<&'index VertexRef, Output = TopologicalSortVertexInfo>
+ ~const IndexMut<&'index VertexRef>,
OutputSink: ~const TopologicalSortOutputSink<VertexRef>,
Expand Down
13 changes: 2 additions & 11 deletions src/r3_core/src/hunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ impl<System: raw::KernelBase + cfg::KernelStatic, T, InitTag: HunkIniter<T>>
) -> Hunk<System, T> {
let untyped_hunk = kernel::Hunk::<System>::define()
.len(mem::size_of::<T>())
.align(max(mem::align_of::<T>(), self.align))
.align(mem::align_of::<T>().max(self.align))
.finish(cfg);

assert!(self.len == 1, "Non-array hunk must have `len` of `1`");
Expand Down Expand Up @@ -195,7 +195,7 @@ impl<System: raw::KernelBase + cfg::KernelStatic, T, InitTag: HunkIniter<T>>

let untyped_hunk = kernel::Hunk::<System>::define()
.len(mem::size_of::<T>() * self.len)
.align(max(mem::align_of::<T>(), self.align))
.align(mem::align_of::<T>().max(self.align))
.finish(cfg);

let start = untyped_hunk.offset();
Expand Down Expand Up @@ -347,12 +347,3 @@ unsafe impl<System: raw::KernelBase + cfg::KernelStatic, T: ?Sized>
stable_deref_trait::CloneStableDeref for Hunk<System, T>
{
}

// `Ord::max` is not available in `const fn` [ref:int_const_ord]
const fn max(x: usize, y: usize) -> usize {
if x > y {
x
} else {
y
}
}
6 changes: 2 additions & 4 deletions src/r3_core/src/kernel/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,8 +742,7 @@ macro array_item_from_fn($(
/// #
/// const fn configure<C>(cfg: &mut C)
/// where
// `~const CfgBase` not implied due to [ref:const_supertraits]
/// C: ~const traits::CfgBase + ~const traits::CfgStatic,
/// C: ~const traits::CfgStatic,
/// {
/// todo!()
/// }
Expand All @@ -764,8 +763,7 @@ macro array_item_from_fn($(
/// todo!()
/// }
/// ```
// The supertrait can't be `~const` due to [ref:const_supertraits]
pub trait CfgStatic: raw_cfg::CfgBase<System: KernelStatic> {}
pub trait CfgStatic: ~const raw_cfg::CfgBase<System: KernelStatic> {}

impl<C> const CfgStatic for C
where
Expand Down
18 changes: 6 additions & 12 deletions src/r3_core/src/kernel/raw_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ pub unsafe trait CfgBase {
/// [2]: crate::kernel::cfg::KernelStatic
/// [3]: self#stability
/// [4]: self#safety
// The supertrait can't be `~const` due to [ref:const_supertraits]
pub unsafe trait CfgTask: CfgBase {
pub unsafe trait CfgTask: ~const CfgBase {
fn task_define<Properties: ~const Bag>(
&mut self,
descriptor: TaskDescriptor<Self::System>,
Expand Down Expand Up @@ -115,8 +114,7 @@ pub struct TaskDescriptor<System> {
/// [2]: crate::kernel::cfg::KernelStatic
/// [3]: self#stability
/// [4]: self#safety
// The supertrait can't be `~const` due to [ref:const_supertraits]
pub unsafe trait CfgEventGroup: CfgBase<System: raw::KernelEventGroup> {
pub unsafe trait CfgEventGroup: ~const CfgBase<System: raw::KernelEventGroup> {
fn event_group_define<Properties: ~const Bag>(
&mut self,
descriptor: EventGroupDescriptor<Self::System>,
Expand Down Expand Up @@ -147,8 +145,7 @@ pub struct EventGroupDescriptor<System> {
/// [2]: crate::kernel::cfg::KernelStatic
/// [3]: self#stability
/// [4]: self#safety
// The supertrait can't be `~const` due to [ref:const_supertraits]
pub unsafe trait CfgMutex: CfgBase<System: raw::KernelMutex> {
pub unsafe trait CfgMutex: ~const CfgBase<System: raw::KernelMutex> {
fn mutex_define<Properties: ~const Bag>(
&mut self,
descriptor: MutexDescriptor<Self::System>,
Expand Down Expand Up @@ -178,8 +175,7 @@ pub struct MutexDescriptor<System> {
/// [2]: crate::kernel::cfg::KernelStatic
/// [3]: self#stability
/// [4]: self#safety
// The supertrait can't be `~const` due to [ref:const_supertraits]
pub unsafe trait CfgSemaphore: CfgBase<System: raw::KernelSemaphore> {
pub unsafe trait CfgSemaphore: ~const CfgBase<System: raw::KernelSemaphore> {
fn semaphore_define<Properties: ~const Bag>(
&mut self,
descriptor: SemaphoreDescriptor<Self::System>,
Expand Down Expand Up @@ -211,8 +207,7 @@ pub struct SemaphoreDescriptor<System> {
/// [2]: crate::kernel::cfg::KernelStatic
/// [3]: self#stability
/// [4]: self#safety
// The supertrait can't be `~const` due to [ref:const_supertraits]
pub unsafe trait CfgTimer: CfgBase<System: raw::KernelTimer> {
pub unsafe trait CfgTimer: ~const CfgBase<System: raw::KernelTimer> {
fn timer_define<Properties: ~const Bag>(
&mut self,
descriptor: TimerDescriptor<Self::System>,
Expand Down Expand Up @@ -245,8 +240,7 @@ pub struct TimerDescriptor<System> {
/// [2]: crate::kernel::cfg::KernelStatic
/// [3]: self#stability
/// [4]: self#safety
// The supertrait can't be `~const` due to [ref:const_supertraits]
pub unsafe trait CfgInterruptLine: CfgBase<System: raw::KernelInterruptLine> {
pub unsafe trait CfgInterruptLine: ~const CfgBase<System: raw::KernelInterruptLine> {
fn interrupt_line_define<Properties: ~const Bag>(
&mut self,
descriptor: InterruptLineDescriptor<Self::System>,
Expand Down
Loading

0 comments on commit 3d64ddb

Please sign in to comment.