Skip to content

Specify alloc::Layout#1972

Open
dianegolfouse wants to merge 1 commit intocreusot-rs:masterfrom
dianegolfouse:layout
Open

Specify alloc::Layout#1972
dianegolfouse wants to merge 1 commit intocreusot-rs:masterfrom
dianegolfouse:layout

Conversation

@dianegolfouse
Copy link
Copy Markdown
Collaborator

No description provided.

Comment thread creusot-std/src/std/alloc.rs Outdated
pearlite! {
align != 0 &&
(exists<a: Int> a.pow2() == align) &&
size <= isize::MAX@ &&
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
size <= isize::MAX@ &&
0 <= size && size <= isize::MAX@ &&

Comment thread creusot-std/src/std/alloc.rs Outdated

/// Requirements for creating a [`Layout`].
#[logic(open)]
pub fn layout_requirements(size: Int, align: Int) -> bool {
Copy link
Copy Markdown
Collaborator

@jhjourdan jhjourdan Mar 10, 2026

Choose a reason for hiding this comment

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

One possibility would be to require size and align to be positive usize values that fit an isize. I think that would simplify quite a few specs.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Also, there is one missing requirement:

size, when rounded up to the nearest multiple of align,
must not overflow isize (i.e., the rounded value must be
less than or equal to isize::MAX).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, but the actual program values this specifies are usize, so you would still need to require that they are in bounds for isize

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I don't think your requirements implies this requirement, which is part of Rust's documentation.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

One possibility would be to require size and align to be positive usize values that fit an isize. I think that would simplify quite a few specs.

That's what I originally did, but this is annoying since size_of_logic/align_of_logic return Ints, so you need some shenanigans to pass them to layout_requirements.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I see. We need a way to caset from Int to machine integers.

Comment thread creusot-std/src/std/alloc.rs
Comment thread creusot-std/src/std/alloc.rs Outdated
Comment thread creusot-std/src/std/alloc.rs Outdated
Comment thread creusot-std/src/std/alloc.rs Outdated
res.size_log() == s &&
res.align_log() == align_of_logic::<T>()
} else {
exists<err> result == Err(err)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Isn't this dead code?

Comment thread creusot-std/src/std/alloc.rs
@jhjourdan
Copy link
Copy Markdown
Collaborator

Generally, this is typically the kind of modules where I would expect a formal proof to make sure none of the spec is unsound.

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