Skip to content

feat: add specs for some tricky functions#7

Open
abentkamp wants to merge 2 commits into
mainfrom
specs
Open

feat: add specs for some tricky functions#7
abentkamp wants to merge 2 commits into
mainfrom
specs

Conversation

@abentkamp

@abentkamp abentkamp commented May 18, 2026

Copy link
Copy Markdown
Collaborator

This PR adds specs for some tricky functions in Aeneas and in core.

Open question: Should I put the non-core specs into the Aeneas repo? Where though?

All specs are annotated with a global @[spec]. I think that is the right thing to do because otherwise users will need to figure out how to turn on specs before being able to use them. Although specs can't be deactivated globally, it's fairly easy to override them with a higher-prio spec or deactivate them locally using mvcgen [-my_spec].

Another problem is that slicing is defined wrong in Aeneas when start and end are equal. I left a TODO comment in the two places where that pops up here.

@abentkamp abentkamp force-pushed the specs branch 2 times, most recently from 2ee2b9c to 86790d0 Compare June 11, 2026 13:01
@abentkamp abentkamp changed the title Add specs: loop, Array.eq @abentkamp feat: add specs for some tricky functions Jun 22, 2026
@abentkamp abentkamp changed the title @abentkamp feat: add specs for some tricky functions feat: add specs for some tricky functions Jun 22, 2026
@abentkamp abentkamp marked this pull request as ready for review June 22, 2026 10:06

@clementblaudeau clementblaudeau left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks good overall. A couple of comments below. To me, the main question is : where should the specs go, and where should the spec attributes go ? Inheriting from step is not enough I assume ? By putting them directly with the definitions we run the risk of upstreaming, and by putting them separately we run the risk of desync/missing annotations.

Comment thread lean/CoreModels/Spec/Aeneas.lean Outdated
Comment thread lean/CoreModels/Spec/Aeneas.lean Outdated
Comment on lines +17 to +19
theorem triple_of_result_eq {α : Type} {x : Result α} {v : α} :
⦃ ⌜ True ⌝ ⦄ x ⦃ ⇓ r => ⌜ r = v ⌝ ⦄ ↔ x = .ok v := by
cases x <;> simp_all [Triple, WP.wp, PredTrans.apply]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Out of curiosity, what is the use of that theorem ?

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.

I've renamed it to triple_post_eq_iff_eq now. It's used a few lemmas further down.

(inv : α → Prop)
(rel : γ → γ → Prop)
(termination : α → γ)
(hwf : WellFounded rel)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Should this be a typeclass argument ? or implicit ?

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.

I don't think so. There is a type class WellFoundedRelation that attaches one canonical well-founded relation to a type. But here, we don't necessarily want the canonical one. So I think we need to keep it explicit.

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.

Oh, wait, did you mean making inv implicit? Yeah, we could do that.

Comment thread lean/CoreModels/Spec/Aeneas.lean Outdated
Comment thread lean/CoreModels/Spec/RustPrimitives/Slice.lean Outdated
@abentkamp

Copy link
Copy Markdown
Collaborator Author

In Aeneas, I have already extended the step attribute to also produce spec lemmas. What I've missed is extending step_pure_def and step_simps in the same way. That would get rid of the spec annotation for uncurry for example. Still, there would be some that remain. I think we should try to upstream them directly next to the def.

@abentkamp

abentkamp commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

To be clear: I think the spec annotations that we would have to be upstreamed are few. Typically, they would be produced by the step annotation automatically. I don't know what's the matter with the shiftRight specs. The step attribute does produce a spec lemma for them, but for some reason mvcgen doesn't pick it up.

@abentkamp

Copy link
Copy Markdown
Collaborator Author

The shiftRight specs work fine for unsigned ints on the left-hand side, but for signed ints they are simply missing in Aeneas. So that's something that should be easy to upstream.

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