Skip to content

Conversation

@keyboardDrummer
Copy link
Contributor

@keyboardDrummer keyboardDrummer commented Feb 9, 2026

Changes

  • Add metadata to many more places in Laurel. For example, preconditions and postconditions are now given a metadata and that is propagated to Core
  • Made it an internal error if diagnostics are reported for which no source location is known
  • Remove the default empty value for the metadata of Procedure.Check

Testing

  • Turned on tests for preconditions and postconditions, although the precondition test does not report errors correctly due to Core reporting them on the precondition instead of on the call, and with an incorrect message.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@keyboardDrummer keyboardDrummer requested review from andrewmwells-amazon, atomb and joscoh and removed request for atomb February 9, 2026 15:00
@keyboardDrummer keyboardDrummer marked this pull request as ready for review February 9, 2026 15:01
@keyboardDrummer keyboardDrummer requested a review from a team as a code owner February 9, 2026 15:01
@keyboardDrummer
Copy link
Contributor Author

keyboardDrummer commented Feb 9, 2026

@atomb the codebase contains many pieces like md : MetaData Expression := .empty. I think we should remove the defaults because anytime an AST node is created on which an error could be reported, it is a bug if there is no source location information available. The default empty metadata prevents the programmer from having to think about whether metadata is available.

Copy link
Contributor

@MikaelMayer MikaelMayer left a comment

Choose a reason for hiding this comment

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

One small change to consider.

md : Imperative.MetaData Core.Expression
deriving Repr

structure StmtExprMd where
Copy link
Contributor

Choose a reason for hiding this comment

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

I would recommend creating one structure that adds metadata to any type like the DDM does, i.e.
structure WithMetadata (t: T) where
val: T
md: Imperative.Metadata Core.Expression
deriving Repr

It will make it easier to generalize down the road. You can always make StmtExprMd an abbreviation of it.

I would even have you consider reusing DDM's Ann that is fully parametric in the metadata and has the same purpose. It has also methods to replace the metadata.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Applied the change

procedure foo(c: Container, d: Container) returns (r: int)
requires c != d && d#intValue == 1
ensures d#intValue == 3
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting, there are no modifies clauses? Nothing to indicate what the procedure can or cannot change?

Copy link
Contributor Author

@keyboardDrummer keyboardDrummer Feb 10, 2026

Choose a reason for hiding this comment

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

in a subsequent PR that adds support for modifies clauses, this generates an error, but only because there is an ensures clause so the procedure is opaque.

fabiomadge added a commit that referenced this pull request Feb 10, 2026
Add HighTypeMd.sizeOf_val_lt lemma and use it to prove translateType
terminates. The remaining partial defs recurse through List StmtExprMd
which requires the same sizeOf bridging pattern that is a known issue
across the codebase (see PR #396).
- `valueUsed`: whether the result value of this expression is used (affects optimization of heap-writing calls)
-/
def heapTransformExpr (heapVar : Identifier) (expr : StmtExpr) (valueUsed : Bool := true) : TransformM StmtExpr :=
partial def heapTransformExpr (heapVar : Identifier) (expr : StmtExprMd) (valueUsed : Bool := true) : TransformM StmtExprMd :=
Copy link
Contributor

Choose a reason for hiding this comment

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

Would prefer not to make things partial unless needed. Is this because it is trickier with the nested record structure for metadata?


Example 1:
`composite Some<T> { value: T }`
`composite SomeT> { value: T }`
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure why this was changed


def formatHighType : HighType → Format
private theorem HighTypeMd.sizeOf_val_lt (e : HighTypeMd) : sizeOf e.val < sizeOf e := by
cases e
Copy link
Contributor

Choose a reason for hiding this comment

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

Does cases e<;> simp_wf<;> omega work? (the current proof is fine, just suggesting a potentially shorter one)

-/
def translateType (ty : HighType) : LMonoTy :=
match ty with
partial def translateType (ty : HighTypeMd) : LMonoTy :=
Copy link
Contributor

Choose a reason for hiding this comment

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

termination should be provable here

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.

3 participants