Skip to content

Commit

Permalink
Upgrade to const-type-layout v0.2.0 and MSRV to 1.75-nightly
Browse files Browse the repository at this point in the history
  • Loading branch information
juntyr committed Dec 10, 2023
1 parent 6cd2783 commit d1d6144
Show file tree
Hide file tree
Showing 72 changed files with 343 additions and 333 deletions.
358 changes: 181 additions & 177 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions necsim/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ cuda = ["rust-cuda"]
necsim-core-maths = { path = "maths" }
necsim-core-bond = { path = "bond" }

const-type-layout = { git = "https://github.com/juntyr/const-type-layout", rev = "e163b36" }
const-type-layout = { version = "0.2.0", features = ["derive"] }
contracts = "0.6.3"
serde = { version = "1.0", default-features = false, features = ["derive"] }

[target.'cfg(target_os = "cuda")'.dependencies]
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "5d5cd02", features = ["derive"], optional = true }
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "b26635f", features = ["derive"], optional = true }

[target.'cfg(not(target_os = "cuda"))'.dependencies]
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "5d5cd02", features = ["derive", "host"], optional = true }
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "b26635f", features = ["derive", "host"], optional = true }
2 changes: 1 addition & 1 deletion necsim/core/bond/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ default = []
[dependencies]
necsim-core-maths = { path = "../maths" }

const-type-layout = { git = "https://github.com/juntyr/const-type-layout", rev = "e163b36" }
const-type-layout = { version = "0.2.0", features = ["derive"] }
serde = { version = "1.0", default-features = false, features = ["derive"] }
2 changes: 1 addition & 1 deletion necsim/core/bond/src/closed_open_unit_f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl Eq for ClosedOpenUnitF64 {}

impl PartialOrd for ClosedOpenUnitF64 {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.0.partial_cmp(&other.0)
Some(self.cmp(other))
}
}

Expand Down
2 changes: 1 addition & 1 deletion necsim/core/bond/src/closed_unit_f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl Eq for ClosedUnitF64 {}

impl PartialOrd for ClosedUnitF64 {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.0.partial_cmp(&other.0)
Some(self.cmp(other))
}
}

Expand Down
4 changes: 1 addition & 3 deletions necsim/core/bond/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
#![feature(const_fn_floating_point_arithmetic)]
#![feature(const_float_bits_conv)]
#![feature(const_float_classify)]
#![feature(const_trait_impl)]
#![feature(const_type_name)]
#![feature(const_mut_refs)]
#![feature(const_num_from_num)]
#![feature(offset_of)]

#[macro_use]
extern crate const_type_layout;
Expand Down
2 changes: 1 addition & 1 deletion necsim/core/bond/src/non_negative_f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl Eq for NonNegativeF64 {}

impl PartialOrd for NonNegativeF64 {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.0.partial_cmp(&other.0)
Some(self.cmp(other))
}
}

Expand Down
2 changes: 1 addition & 1 deletion necsim/core/bond/src/non_positive_f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Eq for NonPositiveF64 {}

impl PartialOrd for NonPositiveF64 {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.0.partial_cmp(&other.0)
Some(self.cmp(other))
}
}

Expand Down
24 changes: 15 additions & 9 deletions necsim/core/bond/src/off_by_one_u32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ impl OffByOneU32 {
///
/// Returns `OffByOneU32Error` if not `1 <= value <= 2^32`
pub const fn new(value: u64) -> Result<Self, OffByOneU32Error> {
match u32::try_from(value.wrapping_sub(1)) {
Ok(value) => Ok(Self(value)),
Err(_) => Err(OffByOneU32Error(value)),
// match u32::try_from(value.wrapping_sub(1)) {
// Ok(value) => Ok(Self(value)),
// Err(_) => Err(OffByOneU32Error(value)),
// }
match value.wrapping_sub(1) {
#[allow(clippy::cast_possible_truncation)]
value if value <= (u32::MAX as u64) => Ok(Self(value as u32)),
_ => Err(OffByOneU32Error(value)),
}
}

Expand All @@ -47,7 +52,8 @@ impl OffByOneU32 {

#[must_use]
pub const fn get(self) -> u64 {
u64::from(self)
// u64::from(self)
(self.0 as u64) + 1_u64
}

#[must_use]
Expand Down Expand Up @@ -84,32 +90,32 @@ impl TryFrom<u64> for OffByOneU32 {
}
}

impl const From<OffByOneU32> for u64 {
impl From<OffByOneU32> for u64 {
fn from(val: OffByOneU32) -> Self {
u64::from(val.0) + 1_u64
}
}

impl const From<OffByOneU32> for NonZeroU64 {
impl From<OffByOneU32> for NonZeroU64 {
fn from(val: OffByOneU32) -> Self {
// Safety: always at least 1
unsafe { NonZeroU64::new_unchecked(u64::from(val)) }
}
}

impl const From<OffByOneU32> for i64 {
impl From<OffByOneU32> for i64 {
fn from(val: OffByOneU32) -> Self {
i64::from(val.0) + 1_i64
}
}

impl const From<OffByOneU32> for f64 {
impl From<OffByOneU32> for f64 {
fn from(val: OffByOneU32) -> Self {
f64::from(val.0) + 1.0_f64
}
}

impl const From<OffByOneU32> for usize {
impl From<OffByOneU32> for usize {
fn from(val: OffByOneU32) -> Self {
(val.0 as usize) + 1_usize
}
Expand Down
26 changes: 16 additions & 10 deletions necsim/core/bond/src/off_by_one_u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ impl OffByOneU64 {
///
/// Returns `OffByOneU64Error` if not `1 <= value <= 2^64`
pub const fn new(value: u128) -> Result<Self, OffByOneU64Error> {
match u64::try_from(value.wrapping_sub(1)) {
Ok(value) => Ok(Self(value)),
Err(_) => Err(OffByOneU64Error(value)),
// match u64::try_from(value.wrapping_sub(1)) {
// Ok(value) => Ok(Self(value)),
// Err(_) => Err(OffByOneU64Error(value)),
// }
match value.wrapping_sub(1) {
#[allow(clippy::cast_possible_truncation)]
value if value < (u64::MAX as u128) => Ok(Self(value as u64)),
_ => Err(OffByOneU64Error(value)),
}
}

Expand All @@ -54,7 +59,8 @@ impl OffByOneU64 {

#[must_use]
pub const fn get(self) -> u128 {
u128::from(self)
// u128::from(self)
(self.0 as u128) + 1_u128
}

#[must_use]
Expand Down Expand Up @@ -91,39 +97,39 @@ impl TryFrom<u128> for OffByOneU64 {
}
}

impl const From<NonZeroU32> for OffByOneU64 {
impl From<NonZeroU32> for OffByOneU64 {
fn from(val: NonZeroU32) -> Self {
Self(u64::from(val.get()) - 1)
}
}

impl const From<OffByOneU32> for OffByOneU64 {
impl From<OffByOneU32> for OffByOneU64 {
fn from(val: OffByOneU32) -> Self {
Self(val.get() - 1)
}
}

impl const From<NonZeroU64> for OffByOneU64 {
impl From<NonZeroU64> for OffByOneU64 {
fn from(val: NonZeroU64) -> Self {
Self(val.get() - 1)
}
}

impl const From<OffByOneU64> for NonZeroU64 {
impl From<OffByOneU64> for NonZeroU64 {
fn from(val: OffByOneU64) -> Self {
// Safety: always at least 1, max case undefined behaviour
unsafe { NonZeroU64::new_unchecked(val.0 + 1) }
}
}

impl const From<OffByOneU64> for f64 {
impl From<OffByOneU64> for f64 {
#[allow(clippy::cast_precision_loss)]
fn from(val: OffByOneU64) -> Self {
(val.0 as f64) + 1.0_f64
}
}

impl const From<OffByOneU64> for u128 {
impl From<OffByOneU64> for u128 {
fn from(val: OffByOneU64) -> Self {
u128::from(val.0) + 1_u128
}
Expand Down
2 changes: 1 addition & 1 deletion necsim/core/bond/src/open_closed_unit_f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Eq for OpenClosedUnitF64 {}

impl PartialOrd for OpenClosedUnitF64 {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.0.partial_cmp(&other.0)
Some(self.cmp(other))
}
}

Expand Down
2 changes: 1 addition & 1 deletion necsim/core/bond/src/positive_f64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ impl Eq for PositiveF64 {}

impl PartialOrd for PositiveF64 {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
self.0.partial_cmp(&other.0)
Some(self.cmp(other))
}
}

Expand Down
9 changes: 9 additions & 0 deletions necsim/core/src/landscape/extent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ impl LandscapeExtent {
}
}

impl IntoIterator for &LandscapeExtent {
type IntoIter = LocationIterator;
type Item = Location;

fn into_iter(self) -> Self::IntoIter {
self.iter()
}
}

#[derive(Debug, PartialEq, Eq)]
pub struct LocationIterator {
x: u32,
Expand Down
4 changes: 1 addition & 3 deletions necsim/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#![deny(clippy::pedantic)]
#![no_std]
#![feature(const_trait_impl)]
#![feature(const_type_name)]
#![feature(const_mut_refs)]
#![feature(const_refs_to_cell)]
#![feature(offset_of)]
#![feature(control_flow_enum)]
#![feature(min_specialization)]

Expand Down
4 changes: 3 additions & 1 deletion necsim/core/src/reporter/combinator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ where
});

fn initialise(&mut self) -> Result<(), alloc::string::String> {
self.front.initialise().and_then(|_| self.tail.initialise())
self.front
.initialise()
.and_then(|()| self.tail.initialise())
}
}
6 changes: 3 additions & 3 deletions necsim/impls/cuda/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ edition = "2018"
[dependencies]
necsim-core = { path = "../../core", features = ["cuda"] }

const-type-layout = { git = "https://github.com/juntyr/const-type-layout", rev = "e163b36" }
const-type-layout = { version = "0.2.0", features = ["derive"] }
contracts = "0.6.3"
serde = { version = "1.0", default-features = false, features = ["derive"] }

[target.'cfg(target_os = "cuda")'.dependencies]
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "5d5cd02", features = ["derive"] }
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "b26635f", features = ["derive"] }

[target.'cfg(not(target_os = "cuda"))'.dependencies]
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "5d5cd02", features = ["derive", "host"] }
rust-cuda = { git = "https://github.com/juntyr/rust-cuda", rev = "b26635f", features = ["derive", "host"] }
16 changes: 7 additions & 9 deletions necsim/impls/cuda/src/cogs/rng.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[cuda(free = "M", free = "R")]
pub struct CudaRng<M: MathsCore, R>
where
R: RngCore<M> + StackOnly + ~const TypeGraphLayout,
R: RngCore<M> + StackOnly + TypeGraphLayout,
{
inner: R,
marker: PhantomData<M>,
}

impl<M: MathsCore, R: RngCore<M> + StackOnly + ~const TypeGraphLayout> Clone for CudaRng<M, R> {
impl<M: MathsCore, R: RngCore<M> + StackOnly + TypeGraphLayout> Clone for CudaRng<M, R> {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
Expand All @@ -27,7 +27,7 @@ impl<M: MathsCore, R: RngCore<M> + StackOnly + ~const TypeGraphLayout> Clone for
}
}

impl<M: MathsCore, R: RngCore<M> + StackOnly + ~const TypeGraphLayout> From<R> for CudaRng<M, R> {
impl<M: MathsCore, R: RngCore<M> + StackOnly + TypeGraphLayout> From<R> for CudaRng<M, R> {
#[must_use]
#[inline]
fn from(rng: R) -> Self {
Expand All @@ -38,9 +38,7 @@ impl<M: MathsCore, R: RngCore<M> + StackOnly + ~const TypeGraphLayout> From<R> f
}
}

impl<M: MathsCore, R: RngCore<M> + StackOnly + ~const TypeGraphLayout> RngCore<M>
for CudaRng<M, R>
{
impl<M: MathsCore, R: RngCore<M> + StackOnly + TypeGraphLayout> RngCore<M> for CudaRng<M, R> {
type Seed = <R as RngCore<M>>::Seed;

#[must_use]
Expand All @@ -59,7 +57,7 @@ impl<M: MathsCore, R: RngCore<M> + StackOnly + ~const TypeGraphLayout> RngCore<M
}
}

impl<M: MathsCore, R: PrimeableRng<M> + StackOnly + ~const TypeGraphLayout> PrimeableRng<M>
impl<M: MathsCore, R: PrimeableRng<M> + StackOnly + TypeGraphLayout> PrimeableRng<M>
for CudaRng<M, R>
{
#[inline]
Expand All @@ -68,13 +66,13 @@ impl<M: MathsCore, R: PrimeableRng<M> + StackOnly + ~const TypeGraphLayout> Prim
}
}

impl<M: MathsCore, R: RngCore<M> + StackOnly + ~const TypeGraphLayout> Serialize for CudaRng<M, R> {
impl<M: MathsCore, R: RngCore<M> + StackOnly + TypeGraphLayout> Serialize for CudaRng<M, R> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
self.inner.serialize(serializer)
}
}

impl<'de, M: MathsCore, R: RngCore<M> + StackOnly + ~const TypeGraphLayout> Deserialize<'de>
impl<'de, M: MathsCore, R: RngCore<M> + StackOnly + TypeGraphLayout> Deserialize<'de>
for CudaRng<M, R>
{
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
Expand Down
4 changes: 2 additions & 2 deletions necsim/impls/cuda/src/event_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub struct EventBuffer<ReportSpeciation: Boolean, ReportDispersal: Boolean> {

pub trait EventType {
type Event: 'static
+ ~const rust_cuda::const_type_layout::TypeGraphLayout
+ rust_cuda::const_type_layout::TypeGraphLayout
+ rust_cuda::safety::StackOnly
+ Into<TypedEvent>
+ Into<PackedEvent>
Expand Down Expand Up @@ -79,7 +79,7 @@ impl<ReportSpeciation: Boolean, ReportDispersal: Boolean> fmt::Debug
fmt.debug_struct("EventBuffer")
.field("max_events", &self.max_events)
.field("event_counter", &self.event_counter)
.finish()
.finish_non_exhaustive()
}
}

Expand Down
4 changes: 1 addition & 3 deletions necsim/impls/cuda/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
#![deny(clippy::pedantic)]
#![no_std]
#![feature(core_intrinsics)]
#![feature(const_trait_impl)]
#![feature(const_type_name)]
#![feature(const_mut_refs)]
#![feature(const_refs_to_cell)]
#![feature(offset_of)]
#![cfg_attr(target_os = "cuda", feature(asm_experimental_arch))]
#![cfg_attr(target_os = "cuda", feature(asm_const))]
#![cfg_attr(target_os = "cuda", feature(const_float_bits_conv))]
Expand Down
Loading

0 comments on commit d1d6144

Please sign in to comment.