Skip to content

feat(rt): transmute pointer to int#812

Draft
Stevengre wants to merge 1 commit intomasterfrom
jh/pointer2int
Draft

feat(rt): transmute pointer to int#812
Stevengre wants to merge 1 commit intomasterfrom
jh/pointer2int

Conversation

@Stevengre
Copy link
Copy Markdown
Contributor

No description provided.

@Stevengre Stevengre marked this pull request as ready for review November 7, 2025 05:26
@Stevengre Stevengre self-assigned this Nov 7, 2025
Base automatically changed from jh/zero-sized to master November 10, 2025 08:29
@Stevengre Stevengre force-pushed the jh/pointer2int branch 2 times, most recently from 70da3cb to fcab480 Compare November 11, 2025 06:48

```k
// `prove-rs/interior-mut3.rs` needs this
// TODO: check its correctness, I assume the pointer offset is the address here and we can use it to recover the PtrLocal
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this is not correct. The PTR_OFFSET here is an index into an array of elements of a certain type T. To get what would be an address in a byte-addressed memory you have to multiply it with the size of one element in bytes. sizeof<T>.
This becomes interesting for the alignment check when pointers are cast from one element type to another.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PTR_OFFSET is a local OFFSET for the structure?

@Stevengre Stevengre marked this pull request as draft November 12, 2025 10:13
@Stevengre Stevengre force-pushed the jh/pointer2int branch 3 times, most recently from 1642b91 to 9a0cbd1 Compare November 17, 2025 09:31
@Stevengre Stevengre marked this pull request as ready for review November 17, 2025 09:31
@Stevengre Stevengre requested a review from jberthold November 17, 2025 09:32
@Stevengre Stevengre marked this pull request as draft November 17, 2025 10:42
Add a `#cast` rule for `castKindTransmute` that handles `PtrLocal` to
integer type conversion. The rule extracts the pointer offset from
metadata and converts it to the target integer type via `#intAsType`.

A helper function `#ptrOffsetBytes` computes byte offsets from pointer
offsets, accounting for array element sizes when the pointee is an
unsized array type.

This fixes the `interior-mut3` test which uses `UnsafeCell::get()`
(internally transmutes a pointer to `usize` for alignment checks).
The proof now passes cleanly in 333 steps instead of getting stuck
on unresolved alignment assertions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Stevengre added a commit that referenced this pull request Mar 26, 2026
Implements Miri-style lazy address allocation (Issue #1002):

Configuration:
- `<addressMap>`: maps allocation keys to (base_address, size) pairs
- `<nextAddress>`: next available address (starts at 4096 to avoid NULL)
- `<exposedSet>`: tracks allocations with exposed provenance

Semantics:
- `#allocAddressFor`: lazily assigns aligned base addresses on demand
- `#alignUp`: aligns addresses to type alignment requirements
- `castKindTransmute` PtrLocal→int: computes base + byte_offset
- `castKindPointerExposeAddress`: same as transmute but also exposes provenance

Verified via LLVM backend execution:
- interior-mut3-fail.rs reaches #EndProgram (alignment check passes with addr=4096)
- Address uniqueness: different locals get different base addresses

Note: Haskell backend (prove) performance regresses due to 3 new configuration
cells increasing the matching state space. This needs further optimization
(e.g. cell multiplicity annotations or rule priorities).

Closes #1002
Supersedes #812, #877
Fixes #638

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants