Skip to content

Proof modes (RFC)#1997

Draft
Lysxia wants to merge 1 commit into
masterfrom
modes
Draft

Proof modes (RFC)#1997
Lysxia wants to merge 1 commit into
masterfrom
modes

Conversation

@Lysxia

@Lysxia Lysxia commented Mar 20, 2026

Copy link
Copy Markdown
Collaborator

Starting with a proposal for what they should look like, before implementing it.

Fixes #1532 (safety mode)
Fixes #1957 (termination mode)
Fixes #1940 (ghost mode)

@Lysxia
Lysxia force-pushed the modes branch 4 times, most recently from 830f925 to 0a42fd7 Compare March 20, 2026 22:54
@xldenis

xldenis commented Mar 20, 2026

Copy link
Copy Markdown
Collaborator

what's an example use case for having the mode as a conclusion?

@Lysxia

Lysxia commented Mar 20, 2026

Copy link
Copy Markdown
Collaborator Author

what's an example use case for having the mode as a conclusion?

Ghost-only functions would require ghost mode.

@xldenis

xldenis commented Mar 20, 2026

Copy link
Copy Markdown
Collaborator

Ghost-only functions would require ghost mode.

so true => mode!(ghost)? is there an example of a non-trivial precondition?

@Lysxia

Lysxia commented Mar 20, 2026

Copy link
Copy Markdown
Collaborator Author

It seems that closures need something a bit more sophisticated than what I've written so far: the mode of a closure may be independent of the function it's passed to.

Comment thread guide/src/proof_modes.md Outdated
Comment on lines +75 to +78
On built-in integer types, arithmetic operations are also safe: they may either panic
(in debug profiles) or perform wrapping operations (in release profiles).
Thus, in safety mode the precondition of these operations is `true` and
their postconditions are those of the wrapping operations.

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.

A simpler solution is to keep the "won't overflow" precondition, because overflow of built-ins is undesirable basically always.

@jhjourdan

Copy link
Copy Markdown
Collaborator

If we do that, we need to adapt the specifications of closures to take the mode as parameter.

@jhjourdan

Copy link
Copy Markdown
Collaborator

We need to discuss that directly. I think there is a direct way to encode all that (including safety) using first-class Booleans and without disabling preconditions in the safety mode.

@jhjourdan

jhjourdan commented Mar 22, 2026

Copy link
Copy Markdown
Collaborator

It seems that closures need something a bit more sophisticated than what I've written so far: the mode of a closure may be independent of the function it's passed to.

Yes, and that is why the logical functions precondition and postconditionxxx should take an additional mode parameter.

Comment thread guide/src/proof_modes.md Outdated
Hence, we follow different rules to determine verification conditions for proving
safety than for proving adherence to a contract. In safety mode:

1. We ignore the contract of the function to verify: we don't assume preconditions, and we don't assert postconditions.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Why not assert postconditions?

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.

We already prove them in normal (non-safety) mode.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

So the same function would be proven in both modes?

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.

Yes

@Lysxia
Lysxia force-pushed the modes branch 4 times, most recently from cbea10a to 785419d Compare April 3, 2026 08:55
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.

Termination of next for Range Relax the ghost check for 'ghost in ghost' situations Mode for only verifying the absence of UB

4 participants