vigna / epserde-rs Goto Github PK
View Code? Open in Web Editor NEWAn ε-copy serialization/deserialization framework for Rust
An ε-copy serialization/deserialization framework for Rust
repr(u64) causes a variation in alignment that confuses ε-serde, leading to errors. We should either handle it, or refuse it.
The derive macros currently don't work with
struct Data<A> {
a: Vec<A>,
test: isize,
}
You need at least
struct Data<A: DeepCopy> {
a: Vec<A>,
test: isize,
}
to explain how to behave with Vec, but then there's a lifetime problem and if you try
struct Data<A> {
a: Vec<A>,
test: isize,
}
You get "higher-ranked lifetime error".
The docs say to be ZeroCopy you need to be a copy type, so that would make a lot of sense.
The documentation still says you need to sort it.
Currently, deserialize_full_copy
takes a slice of u8
as deserialize_eps_copy
. This however is not necessary, as a full copy can be obtained reading from a file.
We could define a ReadNoStd
parallel to WriteNoStd
and a ReadWithCnt
. deserialize_full_copy
would take a ReadWithCnt
and deserialize from there. When passing from ε to full, one would wrap the current Cursor
with a suitable ReadWithCnt
. In fact, Cursor might directly implement ReadWithCnt
, which would make passing from ε to full trivial.
At that point instead of just load
we would have load_eps
, doing what currently load
does, and load_full
, acting like a standard deserialization mechanism.
The disadvantage is that we would have to write a few deserialize_full_copy
in ReadWithCnt
style, instead of delegating or reading from a Cursor
.
Repro:
$ cargo +nightly miri test --test test_generics
Output:
running 2 tests
error: Undefined Behavior: incorrect layout on deallocation: alloc27687 has size 1024 and alignment 128, but gave size 1024 and alignment 1
--> $DIR\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\alloc\src\alloc.rs:117:14
|
117 | unsafe { __rust_dealloc(ptr, layout.size(), layout.align()) }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect layout on deallocation: alloc27687 has size 1024 and alignment 128, but gave size 1024 and alignment 1
|
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
= note: BACKTRACE:
= note: inside `std::alloc::dealloc` at $DIR\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\alloc\src\alloc.rs:117:14: 117:64
= note: inside `<std::alloc::Global as std::alloc::Allocator>::deallocate` at $DIR\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\alloc\src\alloc.rs:254:22: 254:51
= note: inside `<alloc::raw_vec::RawVec<u8> as std::ops::Drop>::drop` at $DIR\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\alloc\src\raw_vec.rs:505:22: 505:56
= note: inside `std::ptr::drop_in_place::<alloc::raw_vec::RawVec<u8>> - shim(Some(alloc::raw_vec::RawVec<u8>))` at $DIR\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ptr\mod.rs:498:1: 498:56
= note: inside `std::ptr::drop_in_place::<std::vec::Vec<u8>> - shim(Some(std::vec::Vec<u8>))` at $DIR\.rustup\toolchains\nightly-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\ptr\mod.rs:498:1: 498:56
note: inside `test_inner_param_eps`
--> epserde\tests\test_generics.rs:70:1
|
70 | }
| ^
note: inside closure
--> epserde\tests\test_generics.rs:50:26
|
49 | #[test]
| ------- in this procedural macro expansion
50 | fn test_inner_param_eps() {
| ^
= note: this error originates in the attribute macro `test` (in Nightly builds, run with -Z macro-backtrace for more info)
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace
error: aborting due to 1 previous error
It is UB to create a std::vec::Vec
using from_raw_parts
with a memory allocation that has an alignment other than align_of::<T>()
. Here, the alignment must be 1 because u8
has an alignment of 1. However, the Vec
is being created with an alignment of 16. This can cause problems with memory allocators that use the alignment during deallocation.
We should find an easy way for the user to pass parameters for a PhantomData without any requirement (presently you need TypeHash and ReprHash).
We could eliminate all requirement and use the system type name in TypeHash, but that's a bit dangerous because we lose control of the value.
Alternatively, we can provide a macro that generates a newtype (possibly trait-based) which implements ReprHash and TypeHash without recursing into the content.
E.g., the CopyType definitions should go side-by-side with serialize (or deserialize) implementations.
This is different to all other load methods and might lead to confusion (with no advantages).
This
use epserde::*;
#[derive(Serialize, Deserialize, TypeHash, Debug, PartialEq, Eq, Default, Clone)]
/// Random struct we will use to test the nested serialization and deserialization.
struct Data<A> {
a: Vec<A>,
test: isize,
}
gives a weird error:
error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied
--> epserde/examples/vec_vec.rs:11:8
|
11 | struct Data<A> {
| ^^^^ expected 1 generic argument
|
note: struct defined here, with 1 generic parameter: `A`
--> epserde/examples/vec_vec.rs:11:8
|
11 | struct Data<A> {
| ^^^^ -
help: add missing generic argument
|
9 | #[derive(Serialize, DAeserialize, TypeHash, Debug, PartialEq, Eq, Default, Clone)]
|
Note that DAeserialize
. I guess some problem in the derived code.
(Incidentally, I'm not even sure what would be the expected behavior, but let's start from the syntax error...)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.