Skip to content

Further improve formatting of Core#412

Open
keyboardDrummer wants to merge 20 commits intostrata-org:mainfrom
keyboardDrummer:furtherCoreFormattingChange
Open

Further improve formatting of Core#412
keyboardDrummer wants to merge 20 commits intostrata-org:mainfrom
keyboardDrummer:furtherCoreFormattingChange

Conversation

@keyboardDrummer
Copy link
Contributor

@keyboardDrummer keyboardDrummer commented Feb 12, 2026

Changes

  • Add a Python script in Tools that enables automatically updating the results of #guard_msg
  • Update formatting of applications in Core. A good way to see how the formatting has changed is to look at the updated tests in this PR.

Before:

while (((~Int.Lt i) n)) (some ((~Int.Sub n) i)) (some ((~Bool.And ((~Int.Le i) n)) (((~Int.Div ((~Int.Mul i) ((~Int.Sub i) #1))) #2) == sum))) {sum := ((~Int.Add sum) i)
 i := ((~Int.Add i) #1)}

After:

  while
    (~Int.Lt i n)
    (some (~Int.Sub n i))
    (some (~Bool.And (~Int.Le i n) ((~Int.Div (~Int.Mul i (~Int.Sub i #1)) #2) == sum)))
  {
    sum := (~Int.Add sum i)
    i := (~Int.Add i #1)
  }

Applications in expressions require fewer parenthesis are are shown in a tree like fashion when they do not fit on a line:

Before

/-- info: Annotated expression:
((((~List$Elim : (arrow (List (Tup int string)) (arrow int (arrow (arrow (Tup int string) (arrow (List (Tup int string)) (arrow int int))) int)))) (((~Cons : (arrow (Tup int string) (arrow (List (Tup int string)) (List (Tup int string))))) (((~Prod : (arrow int (arrow string (Tup int string)))) #3) #a)) (((~Cons : (arrow (Tup int string) (arrow (List (Tup int string)) (List (Tup int string))))) (((~Prod : (arrow int (arrow string (Tup int string)))) #4) #b)) (~Nil : (List (Tup int string)))))) #0) (λ (λ (λ (((~Int.Add : (arrow int (arrow int int))) (((~Tup$Elim : (arrow (Tup int string) (arrow (arrow int (arrow string int)) int))) %2) (λ (λ %1)))) ((((~List$Elim : (arrow (List (Tup int string)) (arrow int (arrow (arrow (Tup int string) (arrow (List (Tup int string)) (arrow int int))) int)))) %1) #1) (λ (λ (λ (((~Tup$Elim : (arrow (Tup int string) (arrow (arrow int (arrow string int)) int))) %2) (λ (λ %1))))))))))))

After

/--
info: Annotated expression:
((~List$Elim : (arrow (List (Tup int string)) (arrow int (arrow (arrow (Tup int string) (arrow (List (Tup int string)) (arrow int int))) int))))
 ((~Cons : (arrow (Tup int string) (arrow (List (Tup int string)) (List (Tup int string)))))
  ((~Prod : (arrow int (arrow string (Tup int string)))) #3 #a)
  ((~Cons : (arrow (Tup int string) (arrow (List (Tup int string)) (List (Tup int string)))))
   ((~Prod : (arrow int (arrow string (Tup int string)))) #4 #b)
   (~Nil : (List (Tup int string)))))
 #0
 (λ (λ (λ ((~Int.Add : (arrow int (arrow int int)))
     ((~Tup$Elim : (arrow (Tup int string) (arrow (arrow int (arrow string int)) int))) %2 (λ (λ %1)))
     ((~List$Elim : (arrow (List (Tup int string)) (arrow int (arrow (arrow (Tup int string) (arrow (List (Tup int string)) (arrow int int))) int))))
      %1
      #1
      (λ (λ (λ ((~Tup$Elim : (arrow (Tup int string) (arrow (arrow int (arrow string int)) int)))
          %2
          (λ (λ %1))))))))))))

Testing

Updated tests

@keyboardDrummer keyboardDrummer marked this pull request as ready for review February 12, 2026 12:16
@keyboardDrummer keyboardDrummer requested a review from a team as a code owner February 12, 2026 12:16
Copy link
Contributor

@atomb atomb left a comment

Choose a reason for hiding this comment

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

I noted one small suggestion for formatting, but it's not at all blocking.


-- 13. loop: with measure and invariant
/--
info: while
Copy link
Contributor

Choose a reason for hiding this comment

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

It'd be nice to have this closer to source syntax. Maybe:

while ((x : int) == #0)
  decreases (x : int)
  invariant #true
...

And the decreases and invariant could simply be omitted when they don't exist.

# SPDX-License-Identifier: Apache-2.0 OR MIT
#!/usr/bin/env python3
"""
Parse `lake test` output to extract #guard_msgs diffs and apply fixes.
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for writing this! It'll be a huge help to all of us.

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