Skip to content

Update the target compiler version #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
22 changes: 0 additions & 22 deletions doc/toolchain_limitations.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,28 +366,6 @@ const _: () = { b"".iter(); };
```


### `[tag:const_array_assume_init]` `MaybeUninit::array_assume_init` is not `const fn`

```rust
#![feature(maybe_uninit_array_assume_init)]
use core::mem::MaybeUninit;
assert!(matches!(
unsafe { MaybeUninit::array_assume_init([MaybeUninit::new(42)]) },
[42]
));
```

```rust,compile_fail,E0015
#![feature(maybe_uninit_array_assume_init)]
use core::mem::MaybeUninit;
const _: () = assert!(matches!(
// error[E0015]: cannot call non-const fn `MaybeUninit::<i32>::
// array_assume_init::<1_usize>` in constants
unsafe { MaybeUninit::array_assume_init([MaybeUninit::new(42)]) },
[42]
));
```

### `[tag:const_uninit_array]` `MaybeUninit::uninit_array` is unstable

```rust,compile_fail,E0658
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2022-03-30
nightly-2022-05-20
7 changes: 4 additions & 3 deletions src/r3_core/src/bind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1216,7 +1216,8 @@ macro_rules! impl_fn_bind {
type BoundFn<T, Output, $( $RuntimeBinderI, )*>
where
$( $RuntimeBinderI: RuntimeBinder, )*
T: Copy + Send + 'static,
T: for<'call> FnOnce($( $RuntimeBinderI::Target<'call>, )*)
-> Output + Copy + Send + 'static,
= impl FnOnce() -> Output + Copy + Send + 'static;

const fn bind_inner<
Expand Down Expand Up @@ -1345,8 +1346,8 @@ where

type MappedBoundFn<InnerBoundFn, Output, Mapper, NewOutput>
where
InnerBoundFn: Copy + Send + 'static,
Mapper: Copy + Send + 'static,
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>(
Expand Down
3 changes: 3 additions & 0 deletions src/r3_core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#![feature(const_maybe_uninit_array_assume_init)]
#![feature(const_fn_floating_point_arithmetic)]
#![feature(const_nonnull_slice_from_raw_parts)]
#![feature(const_maybe_uninit_uninit_array)]
#![feature(const_maybe_uninit_assume_init)]
#![feature(maybe_uninit_array_assume_init)]
#![feature(const_maybe_uninit_as_mut_ptr)]
#![feature(nonnull_slice_from_raw_parts)]
#![feature(arbitrary_enum_discriminant)]
Expand Down
2 changes: 1 addition & 1 deletion src/r3_core/src/time/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ impl TryFrom<Duration> for core::time::Duration {

impl fmt::Debug for Duration {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let abs_dur = core::time::Duration::from_micros((self.micros as i64).abs() as u64);
let abs_dur = core::time::Duration::from_micros(self.micros.unsigned_abs().into());
if self.micros < 0 {
write!(f, "-")?;
}
Expand Down
17 changes: 2 additions & 15 deletions src/r3_core/src/utils/for_times.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,8 @@ macro_rules! const_array_from_fn {
))
}

// `MaybeUninit::array_assume_init` is not `const fn` yet
// [ref:const_array_assume_init]
const unsafe fn __assume_init<
$($iter_gparam $($iter_gparam_bounds)*,)*
const LEN: usize
>(array: [MaybeUninit<$ty>; LEN]) -> [$ty; LEN] {
// Safety: This is equivalent to `transmute_copy(&array)`. The
// memory layout of `[MaybeUninit<T>; $len]` is identical to `[T; $len]`.
// We initialized all elements in `array[0..$len]`, so it's safe to
// reinterpret that range as `[T; $len]`.
unsafe { *(array.as_ptr() as *const _ as *const [$ty; LEN]) }
}

// Safety: See the body of `__assume_init`.
unsafe { __assume_init::<$($ctx_t,)* {$len_value}>(array) }
// Safety: All elements of `array` are initialized
unsafe { MaybeUninit::array_assume_init(array) }
}};
}

Expand Down
8 changes: 2 additions & 6 deletions src/r3_core/src/utils/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,8 @@ impl<T: Init, const LEN: usize> Init for [T; LEN] {
i += 1;
}

// `MaybeUninit::array_assume_init` is not `const fn` yet
// [ref:const_array_assume_init]
// Safety: The memory layout of `[MaybeUninit<T>; LEN]` is
// identical to `[T; LEN]`. We initialized all elements, so it's
// safe to reinterpret that range as `[T; LEN]`.
unsafe { super::mem::transmute(array) }
// Safety: `array`'s elements are fully initialized
unsafe { mem::MaybeUninit::array_assume_init(array) }
};
}

Expand Down
4 changes: 1 addition & 3 deletions src/r3_core/src/utils/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ mod tests {
MaybeUninit::new(2),
MaybeUninit::new(3),
];
// `MaybeUninit::array_assume_init` is not `const fn`
// [ref:const_array_assume_init]
unsafe { transmute(array) }
unsafe { MaybeUninit::array_assume_init(array) }
};
assert_eq!(ARRAY1, [1, 2, 3]);
}
Expand Down
3 changes: 3 additions & 0 deletions src/r3_kernel/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
#![feature(const_maybe_uninit_array_assume_init)]
#![feature(const_maybe_uninit_uninit_array)]
#![feature(const_maybe_uninit_assume_init)]
#![feature(maybe_uninit_array_assume_init)]
#![feature(const_slice_from_raw_parts)]
#![feature(maybe_uninit_uninit_array)]
#![feature(const_precise_live_drops)]
Expand Down
1 change: 1 addition & 0 deletions src/r3_port_riscv/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.
### Changed

- **Breaking (semver-exempt):** Change the target compiler version to `nightly-2022-03-30`
- **Breaking:** `use_rt!` is now gated behind `riscv-rt` Cargo feature.

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion src/r3_port_riscv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ unstringify = { version = "0.1.4" }
seq-macro = { version = "0.3.0" }
svgbobdoc = { version = "0.3.0" }
macropol = { version = "0.1.3" }
riscv-rt = { version = ">= 0.6.0, < 0.9.0" }
riscv-rt = { version = ">= 0.6.0, < 0.9.0", optional = true }
riscv = { version = ">= 0.5.0, < 0.8.0" }

[package.metadata.docs.rs]
Expand Down
2 changes: 1 addition & 1 deletion src/r3_port_riscv/src/lib.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ The RISC-V port for [the R3 kernel](::r3_kernel).

# Startup code

[`use_rt!`] hooks up the entry points ([`EntryPoint`]) using `#[`[`::riscv_rt::entry`]`]`. If this is not desirable for some reason, you can opt not to use it and call the entry points in other ways.
[`use_rt!`] hooks up the entry points ([`EntryPoint`]) using `#[`[`::riscv_rt::entry`]`]` (requires the **`riscv-rt`** Cargo feature). If this is not desirable for some reason, you can opt not to use it and call the entry points in other ways.

# Interrupts

Expand Down
4 changes: 4 additions & 0 deletions src/r3_port_riscv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#![feature(raw_ref_op)]
#![feature(asm_const)]
#![feature(asm_sym)]
#![feature(doc_cfg)]
#![deny(unsafe_op_in_unsafe_fn)]
#![cfg_attr(
feature = "doc",
Expand Down Expand Up @@ -55,6 +56,8 @@ pub mod plic {

/// The binding for [`::riscv_rt`].
#[doc(hidden)]
#[cfg(feature = "riscv-rt")]
#[doc(cfg(feature = "riscv-rt"))]
pub mod rt {
pub mod cfg;
#[cfg(target_os = "none")]
Expand Down Expand Up @@ -85,6 +88,7 @@ pub mod sbi_timer {

pub use self::mtime::cfg::*;
pub use self::plic::cfg::*;
#[cfg(feature = "riscv-rt")]
pub use self::rt::cfg::*;
pub use self::sbi_timer::cfg::*;
pub use self::threading::cfg::*;
Expand Down
1 change: 1 addition & 0 deletions src/r3_port_riscv_test_driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ run = [
boot-minimal-s = []
# Use `riscv-rt` for the startup code
boot-rt = [
"r3_port_riscv/riscv-rt",
"riscv-rt",
]

Expand Down
14 changes: 7 additions & 7 deletions src/r3_portkit/src/sym.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub macro sym_static {
.dc.a {2}
",
sym Self::$sym_name,
const $crate::sym::mem::align_of::<&'static $ty>().trailing_zeros(),
const $crate::sym::mem::align_of::<*const $ty>().trailing_zeros(),
sym $static,
options(noreturn),
);
Expand All @@ -170,23 +170,23 @@ mod tests {
static S1: u32 = 1;
static S2: u32 = 2;

impl Tr for &'static u8 {
impl Tr for u8 {
sym_static!(
#[sym(p_var)]
fn var() -> &u32 {
&S0
}
);
}
impl Tr for &'static u16 {
impl Tr for u16 {
sym_static!(
#[sym(p_var)]
fn var() -> &u32 {
&S1
}
);
}
impl Tr for &'static u32 {
impl Tr for u32 {
sym_static!(
#[sym(p_var)]
fn var() -> &u32 {
Expand All @@ -197,9 +197,9 @@ mod tests {

#[test]
fn uniqueness() {
let var1 = dbg!(<&'static u8>::var() as *const u32);
let var2 = dbg!(<&'static u16>::var() as *const u32);
let var3 = dbg!(<&'static u32>::var() as *const u32);
let var1 = dbg!(<u8>::var() as *const u32);
let var2 = dbg!(<u16>::var() as *const u32);
let var3 = dbg!(<u32>::var() as *const u32);
assert_ne!(var1, var2);
assert_ne!(var2, var3);
assert_ne!(var1, var3);
Expand Down
4 changes: 1 addition & 3 deletions src/r3_test_suite/src/kernel_benchmarks/timer_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ impl<System: SupportedSystem> AppInner<System> {
i += 1;
}

// `MaybeUninit::array_assume_init` is not `const fn` yet
// [ref:const_array_assume_init]
unsafe { core::mem::transmute_copy(&timers) }
unsafe { MaybeUninit::array_assume_init(timers) }
};

Self { timers }
Expand Down
2 changes: 2 additions & 0 deletions src/r3_test_suite/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![feature(const_maybe_uninit_array_assume_init)]
#![feature(const_fn_floating_point_arithmetic)]
#![feature(maybe_uninit_array_assume_init)]
#![feature(cfg_target_has_atomic)]
#![feature(const_transmute_copy)]
#![feature(const_refs_to_cell)]
Expand Down