Skip to content

Rewrite pretty printer#62

Merged
danbaterisna merged 15 commits into
masterfrom
pretty-print-rewrite
Nov 10, 2025
Merged

Rewrite pretty printer#62
danbaterisna merged 15 commits into
masterfrom
pretty-print-rewrite

Conversation

@danbaterisna

Copy link
Copy Markdown
Collaborator

Changes the pretty printing algorithm to use (what I believe are) more reasonable spacing and indentation defaults.

Some selected examples to demonstrate the change:

Source Current pretty printer New pretty printer
 map.ml, thrice_list 
let match100 : (int) list =
                            ens ((res = xs) /\ emp) in
                            (((ens
                               ((match100 = []()) /\ (true = true) /\ emp);
                               ens ((res = []()) /\ emp))
                             \/
                             ex xs' : (int) list.
                              ex x : int.
                               (ens
                                ((match100 = ::(x, xs')) /\ (true = true) /\
                                  emp);
                                let v98 : int =
                                 let v97 : int = ens ((res = (x + x)) /\ emp)
                                  in (ens ((res = (v97 + x)) /\ emp)) in
                                 (let v99 : (int) list = thrice_list(xs') in
                                   (ens ((res = ::(v98, v99)) /\ emp)))))
(ens (res = xs)); match100.
ens (match100 = [] /\ true = true /\ emp); ens (res = [])
\/ ex xs'. ex x.
     (ens (match100 = x :: xs' /\ true = true /\ emp);
      ((ens (res = x + x)); v97. (ens (res = v97 + x))); v98.
      ((thrice_list(xs')); v99. ens (res = v98 :: v99)))
 state.ml, main 
 let v14 : unit->int =
                            ens
                            ((res =
                              (fun _v12 : unit
                               (*@
                               (tick(());
                                (tick(());
                                 let a : 'tv1670 = get(()) in
                                  ((tick(());
                                    let v13 : int = get(()) in
                                     (ens ((res = (v13 - a)) /\ emp)))))) @*) ))
                              /\ emp) in (run_state(v14))
(
  ens (res =
    (fun _v12 ->
        (*@ tick(()); tick(());
            (get(())); a. (tick(()); (get(())); v13. (ens (res = v13 - a)))
            @*)
        _))
); v14.
run_state(v14)

Resolves #43, #55 (type display is now togglable via the SHOW_TYPES env var). Does partial work on #52 (the printer now uses the new syntax, but the parser for specifications in code comments is left unchanged.)

this should probably only be done in untyped mode, though currently
the `can_unify_with` check eliminates all ill-typed instantiations
in typed mode so it won't change anything for now
@VietAnh1010

Copy link
Copy Markdown
Collaborator

Is this ready to be merged? If so, let's do it.

Also, can you handle #60 as well? That can also be merged, but it seems like there would be some conflicts between these two PRs.

Comment thread lib/hipcore/subst.ml

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 guess this is not necessary anymore?

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, all callers of Subst use the typed version now.

visitors { variety = "mapreduce"; name = "mapreduce_spec" },
ord]

let spec_calls_func spec f_name =

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.

What does this function do?

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.

This is currently used to check if a specification of some function refers to itself (which is the case for the inferred spec of a recursive function). The old check for this used to be in Pretty for some reason.

need to check tests if the changes are only format-wise
currently unsure if a Format-based approach can still be salvaged or if
a handrolled one is needed to achieve the desired outputs

all the tests are broken but Trust Me BroTM it's just formatting changes
all code has already been ported over to typed subst
done by adding a group to wrap the annotations, to
make the split choice independent of the context
@danbaterisna danbaterisna merged commit 9066efe into master Nov 10, 2025
1 check passed
@VietAnh1010 VietAnh1010 deleted the pretty-print-rewrite branch March 5, 2026 06:25
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.

Pretty printing need to be fixed

2 participants