Skip to content

Commit e64d6e1

Browse files
Merge pull request #49 from triblespace/codex/plan-next-steps-for-project-advancement
Add Kani proofs for ownership recovery and weak refs
2 parents b02fb7e + a4a5172 commit e64d6e1

File tree

3 files changed

+48
-1
lines changed

3 files changed

+48
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
and return the original value on failure
5353
in a dedicated AGENTS section
5454
- add tests for weak reference upgrade/downgrade and Kani proofs for view helpers
55+
- add Kani proofs covering `Bytes::try_unwrap_owner` and `WeakBytes` upgrade semantics
5556
- add examples for quick start and PyBytes usage
5657
- add example showing how to wrap Python `bytes` into `Bytes`
5758
- summarize built-in `ByteSource`s and show how to extend them

INVENTORY.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
## Desired Functionality
77
- Example demonstrating Python + winnow parsing.
8-
- Additional Kani proofs covering `try_unwrap_owner` and weak references.
98
- `ByteSource` implementation for `VecDeque<u8>` to support ring buffers.
109

1110
## Discovered Issues

src/bytes.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,4 +609,51 @@ mod verification {
609609
let other: [u8; 4] = kani::any();
610610
assert!(bytes.slice_to_bytes(&other).is_none());
611611
}
612+
613+
#[kani::proof]
614+
#[kani::unwind(16)]
615+
pub fn check_try_unwrap_owner_unique() {
616+
let data: Vec<u8> = Vec::bounded_any::<16>();
617+
let bytes = Bytes::from_source(data.clone());
618+
let recovered = bytes.try_unwrap_owner::<Vec<u8>>().expect("unwrap owner");
619+
assert_eq!(recovered, data);
620+
}
621+
622+
#[kani::proof]
623+
#[kani::unwind(16)]
624+
pub fn check_try_unwrap_owner_shared() {
625+
let data: Vec<u8> = Vec::bounded_any::<16>();
626+
let bytes = Bytes::from_source(data.clone());
627+
let _clone = bytes.clone();
628+
let result = bytes.try_unwrap_owner::<Vec<u8>>();
629+
assert!(result.is_err());
630+
}
631+
632+
#[kani::proof]
633+
#[kani::unwind(16)]
634+
pub fn check_try_unwrap_owner_wrong_type() {
635+
let data: Vec<u8> = Vec::bounded_any::<16>();
636+
let bytes = Bytes::from_source(data);
637+
assert!(bytes.try_unwrap_owner::<String>().is_err());
638+
}
639+
640+
#[kani::proof]
641+
#[kani::unwind(16)]
642+
pub fn check_weakbytes_upgrade_some() {
643+
let data: Vec<u8> = Vec::bounded_any::<16>();
644+
let bytes = Bytes::from_source(data.clone());
645+
let weak = bytes.downgrade();
646+
let upgraded = weak.upgrade().expect("upgrade");
647+
assert_eq!(upgraded.as_ref(), data.as_slice());
648+
}
649+
650+
#[kani::proof]
651+
#[kani::unwind(16)]
652+
pub fn check_weakbytes_upgrade_none() {
653+
let data: Vec<u8> = Vec::bounded_any::<16>();
654+
let bytes = Bytes::from_source(data);
655+
let weak = bytes.downgrade();
656+
drop(bytes);
657+
assert!(weak.upgrade().is_none());
658+
}
612659
}

0 commit comments

Comments
 (0)