Skip to content

Commit

Permalink
Merge pull request #48 from rodrimati1992/fix_fn_promotion
Browse files Browse the repository at this point in the history
0.9.2 release
  • Loading branch information
rodrimati1992 authored Jan 9, 2021
2 parents ff985dd + 2dd75dd commit ed2c95d
Show file tree
Hide file tree
Showing 44 changed files with 940 additions and 494 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ jobs:
cargo test
cd "${{github.workspace}}/abi_stable"
cargo test --features "testing sabi_trait_examples"
cargo test --features "testing sabi_trait_examples test_const_params"
cd "${{github.workspace}}/examples/0_modules_and_interface_types/impl/"
cargo test
Expand Down
13 changes: 12 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@ This is the changelog,summarising changes in each version(some minor changes may

# 0.9

# 0.9.2

Added impls of StableAbi for arrays of all sizes, conditional on the "const_params" feature.

Made abi_stable more resilient to changes in how static promotion works.

Documented that staticref only supports declaring inherent associated constants,
but doesn't stop compiling anywhere else yet.

Moved continuous integration testing to github.

# 0.9.1

Fixed a memory safety bug in RString::retain and RVec::retain.
Fixed a memory safety bug in `RString::retain` and `RVec::retain`.

# 0.9.0

Expand Down
13 changes: 9 additions & 4 deletions abi_stable/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "abi_stable"
version = "0.9.1"
version = "0.9.2"
authors = ["rodrimati1992 <[email protected]>"]
edition="2018"
license = "MIT/Apache-2.0"
Expand Down Expand Up @@ -34,20 +34,25 @@ all_nightly=[
"nightly_const_params",
]

# Enables stuff that requires const generics(in nightly Rust).
nightly_const_params=[]
# Enables the `#![feature(min_const_generics)]` attribute in
nightly_const_params=["const_params"]

# Test features,only used internally.
testing=[]
test_const_params = []
only_new_tests=["testing"]
sabi_trait_examples=[]
nonexhaustive_examples=[]

# For disabling tests that break with the reduced promotion in
# https://github.com/rust-lang/rust/pull/80243#event-4161720040
no_fn_promotion = []

channels=["crossbeam-channel"]


[dependencies]
abi_stable_derive= {version="0.9.0",path="../abi_stable_derive"}
abi_stable_derive= {version="0.9.2",path="../abi_stable_derive"}
abi_stable_shared= {version="0.9.0",path="../abi_stable_shared"}
serde = { version = "1.0.117", features = ["derive"] }
repr_offset = { version = "0.1.1", default_features = false }
Expand Down
16 changes: 8 additions & 8 deletions abi_stable/build.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use rustc_version::{Version, Channel};
use rustc_version::Channel;

fn main() {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=../readme.md");

let rver = rustc_version::version().unwrap();
let channel=rustc_version::version_meta().unwrap().channel;
if channel == Channel::Nightly && std::env::var("CARGO_FEATURE_test_const_params").is_ok() {
println!("cargo:warning=ENABLED CONST GENERICS");

if Version::new(1, 42, 0) <= rver {
println!("cargo:rustc-cfg=rust_1_42");
println!("cargo:rustc-cfg=feature=\"nightly_const_params\"");
println!("cargo:rustc-cfg=feature=\"const_params\"");
}

let channel=rustc_version::version_meta().unwrap().channel;
if let Channel::Nightly=channel {
println!("cargo:rustc-cfg=feature=\"nightly_rust\"");
}


}
50 changes: 47 additions & 3 deletions abi_stable/src/abi_stability/const_generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ impl ConstGeneric{
}
}

/// Constructs a ConstGeneric from an erased reference and a vtable.
///
/// # Safety
///
/// `this` must point to an object that lives for the `'static` lifetime,
/// and `vtable` must be a `ConstGenericVTableFor::<T>::NEW`
/// (where `T` is the unerased type of `this`)
pub const unsafe fn from_erased(this: *const (), vtable: ConstGenericVTable_Ref)->Self{
Self{
ptr: this as *const ErasedObject,
vtable,
}
}

/// Compares this to another `ConstGeneric` for equality,
/// returning an error if the type layout of `self` and `other` is not compatible.
pub fn is_equal(
Expand Down Expand Up @@ -99,12 +113,13 @@ impl Eq for ConstGeneric{}

///////////////////////////////////////////////////////////////////////////////


/// The vtable of `ConstGeneric`,
/// only constructible with `ConstGenericVTableFor::<T>::new.erased()`
#[repr(C)]
#[derive(StableAbi)]
#[sabi(kind(Prefix))]
#[sabi(missing_field(panic))]
struct ConstGenericVTable{
pub struct ConstGenericVTable {
layout:&'static TypeLayout,
partial_eq:unsafe extern "C" fn(&ErasedObject,&ErasedObject)->bool,
#[sabi(last_prefix_field)]
Expand All @@ -119,9 +134,19 @@ pub struct ConstGenericVTableFor<T>{
}


impl<T> ConstGenericVTableFor<T> {
/// Allows inferring `T` by passing a reference to it.
pub const fn infer_type(&self, _: &T) {}

/// Extracts the vtable for the erased type.
pub const fn erased(&self) -> ConstGenericVTable_Ref {
self.vtable
}
}

impl<T> ConstGenericVTableFor<T>
where
T: StableAbi + Eq + PartialEq + Debug + Send + Sync
T: StableAbi + Eq + PartialEq + Debug + Send + Sync + 'static
{
const _VTABLE_STATIC: WithMetadata<ConstGenericVTable> = {
WithMetadata::new(
Expand All @@ -140,3 +165,22 @@ where
_marker: PhantomData,
};
}


#[doc(hidden)]
pub struct ConstGenericErasureHack<T: ?Sized>{
pub vtable: ConstGenericVTable_Ref,
pub value: T,
}


#[doc(hidden)]
impl<T> ConstGenericErasureHack<T> {
pub const fn new(vtable: ConstGenericVTableFor<T>, value: T) -> Self {
Self {
vtable: vtable.erased(),
value,
}
}
}

Loading

0 comments on commit ed2c95d

Please sign in to comment.