icicle-lang / icicle-ambiata

A streaming query language.
BSD 3-Clause "New" or "Revised" License
57 stars 11 forks source link

better Core pretty printing #336

Open tranma opened 8 years ago

tranma commented 8 years ago

The Core pretty printer is a bit savage:

e.g.

Streams:
conv$2               = sfold [Map (Sum Error String) ((Sum Error (Struct [(buzz
                                                                          ,String)
                                                                         ,(fizz,Int)])), (Sum Error Int))] (Map []@{Map (Sum Error String) ((Sum Error (Struct [(buzz,String),(fizz,Int)])), (Sum Error Int))}) then (
let simp$6 = fst#@{(Sum Error (Struct [(bar,Int),(foo,Struct [(buzz,String),(fizz,Int)])])), Time} conv$0
 in
let simp$7 = Sum_fold#@{(Error,Struct [(bar,Int),(foo,Struct [(buzz,String),(fizz,Int)])])}@{(Sum Error (Struct [(buzz,String),(fizz,Int)]))} (
             \_err@{Error} left#@{Error Struct [(buzz,String),(fizz,Int)]} _err) (
             \_val@{Struct [(bar,Int),(foo,Struct [(buzz,String),(fizz,Int)])]} right#@{Error Struct [(buzz,String),(fizz,Int)]} (get#@{foo Struct [(buzz,String),(fizz,Int)] Struct [(bar,Int),(foo,Struct [(buzz,String),(fizz,Int)])]} _val)) simp$6
 in
let simp$9 = Sum_fold#@{(Error,Struct [(buzz,String),(fizz,Int)])}@{(Sum Error Int)} (
             \reify$2$conv$6@{Error} left#@{Error Int} reify$2$conv$6) (
             \reify$3$conv$7@{Struct [(buzz,String),(fizz,Int)]} Right 1@{(Sum Error Int)}) simp$7
 in
let simp$11 = simp$9
 in
let simp$12 = pair#@{(Sum Error (Struct [(buzz,String),(fizz,Int)])) (Sum Error Int)} simp$7 simp$11
 in
let simp$13 = fst#@{(Sum Error (Struct [(bar,Int),(foo,Struct [(buzz,String),(fizz,Int)])])), Time} conv$0
 in
let simp$14 = Sum_fold#@{(Error,Struct [(bar,Int),(foo,Struct [(buzz,String),(fizz,Int)])])}@{(Sum Error (Struct [(buzz,String),(fizz,Int)]))} (
              \_err@{Error} left#@{Error Struct [(buzz,String),(fizz,Int)]} _err) (
              \_val@{Struct [(bar,Int),(foo,Struct [(buzz,String),(fizz,Int)])]} right#@{Error Struct [(buzz,String),(fizz,Int)]} (get#@{foo Struct [(buzz,String),(fizz,Int)] Struct [(bar,Int),(foo,Struct [(buzz,String),(fizz,Int)])]} _val)) simp$13
 in
let simp$15 = Sum_fold#@{(Error,Struct [(buzz,String),(fizz,Int)])}@{(Sum Error String)} (
              \_err@{Error} left#@{Error String} _err) (
              \_val@{Struct [(buzz,String),(fizz,Int)]} right#@{Error String} (get#@{buzz String Struct [(buzz,String),(fizz,Int)]} _val)) simp$14
 in Map_insertOrUpdate#@{((Sum Error String),((Sum Error (Struct [(buzz,String),(fizz,Int)])), (Sum Error Int)))} (
    \conv$20@{((Sum Error (Struct [(buzz,String),(fizz,Int)])), (Sum Error Int))}
    let conv$22 = snd#@{(Sum Error (Struct [(buzz,String),(fizz,Int)])), (Sum Error Int)} conv$20
     in
    let simp$8 = Sum_fold#@{(Error,Struct [(bar,Int),(foo,Struct [(buzz,String),(fizz,Int)])])}@{(Sum Error (Struct [(buzz,String),(fizz,Int)]))} (
                 \_err@{Error} left#@{Error Struct [(buzz,String),(fizz,Int)]} _err) (
                 \_val@{Struct [(bar,Int),(foo,Struct [(buzz,String),(fizz,Int)])]} right#@{Error Struct [(buzz,String),(fizz,Int)]} (get#@{foo Struct [(buzz,String),(fizz,Int)] Struct [(bar,Int),(foo,Struct [(buzz,String),(fizz,Int)])]} _val)) (fst#@{(Sum Error (Struct [(bar,Int),(foo,Struct [(buzz,String),(fizz,Int)])])), Time} conv$0)
     in pair#@{(Sum Error (Struct [(buzz,String),(fizz,Int)])) (Sum Error Int)} simp$8 (
        let simp$10 = Sum_fold#@{(Error,Struct [(buzz,String),(fizz,Int)])}@{(Sum Error Int)} (
                      \reify$2$conv$6@{Error} left#@{Error Int} reify$2$conv$6) (
                      \reify$3$conv$7@{Struct [(buzz,String),(fizz,Int)]} Sum_fold#@{(Error,Int)}@{(Sum Error Int)} (
                                      \reify$4$conv$11@{Error} left#@{Error Int} reify$4$conv$11) (
                                      \reify$5$conv$12@{Int} right#@{Error Int} reify$5$conv$12) (Sum_fold#@{(Error,Int)}@{(Sum Error Int)} (
                                                                                \reify$0$conv$8@{Error} left#@{Error Int} reify$0$conv$8) (
                                                                                \reify$1$conv$9@{Int} right#@{Error Int} (add#@{Int} reify$1$conv$9 (1@{Int}))) conv$22)) simp$8
         in simp$10)) simp$12 simp$15 conv$2)
amosr commented 8 years ago

I think this is a bit more readable, and the indentation is more predictable too without soft breaks. it's not great but it's better

> feature salary ~> group value ~> count value
- Core:
Program (conv$0 : (Sum Error Int), conv$1 : FactIdentifier, conv$2 : Time, conv$3 : SNAPSHOT_TIME)
Precomputations:

Streams:
  STREAM_FOLD (conv$4 : Map (Sum Error Int) ((Sum Error Int), (Sum Error Int)))
    INIT:
      Map []@{Map (Sum Error Int) ((Sum Error Int), (Sum Error Int))}
    KONS:

        let simp$3 = fst#@{(Sum Error Int), Time} conv$0
        let simp$5 = Sum_fold#@{(Error,Int)}@{(Sum Error Int)}
          (\reify$2$conv$8@{Error} left#@{Error Int} reify$2$conv$8)
          (\reify$3$conv$9@{Int} Right 1@{(Sum Error Int)}) simp$3
        let simp$7 = simp$5
        let simp$8 = pair#@{(Sum Error Int) (Sum Error Int)} simp$3 simp$7
        let simp$9 = fst#@{(Sum Error Int), Time} conv$0
         in Map_insertOrUpdate#@{((Sum Error Int),((Sum Error Int), (Sum Error Int)))}
          (\conv$22@{((Sum Error Int), (Sum Error Int))}
            let conv$24 = snd#@{(Sum Error Int), (Sum Error Int)} conv$22
            let simp$4 = fst#@{(Sum Error Int), Time} conv$0
             in pair#@{(Sum Error Int) (Sum Error Int)} simp$4 (
              let simp$6 = Sum_fold#@{(Error,Int)}@{(Sum Error Int)}
                (\reify$2$conv$8@{Error} left#@{Error Int} reify$2$conv$8)
                (\reify$3$conv$9@{Int} Sum_fold#@{(Error,Int)}@{(Sum Error Int)}
                  (\reify$4$conv$13@{Error} left#@{Error Int} reify$4$conv$13)
                  (\reify$5$conv$14@{Int} right#@{Error Int} reify$5$conv$14) (Sum_fold#@{(Error,Int)}@{(Sum Error Int)}
                  (\reify$0$conv$10@{Error} left#@{Error Int} reify$0$conv$10)
                  (\reify$1$conv$11@{Int} right#@{Error Int} (add#@{Int} reify$1$conv$11 (1@{Int}))) conv$24)) simp$4
               in simp$6)) simp$8 simp$9 conv$4

Postcomputations:
  conv$36              = Map_fold#@{((Sum Error Int),((Sum Error Int), (Sum Error Int)))}@{(Sum Error (Map Int Int))}
                           (\conv$33@{(Sum Error (Map Int Int))} \conv$28@{(Sum Error Int)} \conv$30@{((Sum Error Int), (Sum Error Int))} Sum_fold#@{(Error,Map Int Int)}@{(Sum Error (Map Int Int))}
                             (\conv$35@{Error} left#@{Error Map Int Int} conv$35)
                             (\conv$34@{Map Int Int} Sum_fold#@{(Error,Int)}@{(Sum Error (Map Int Int))}
                               (\conv$35@{Error} left#@{Error Map Int Int} conv$35)
                               (\conv$29@{Int} Sum_fold#@{(Error,Int)}@{(Sum Error (Map Int Int))}
                                 (\conv$35@{Error} left#@{Error Map Int Int} conv$35)
                                 (\conv$31@{Int} right#@{Error Map Int Int} (Map_insertOrUpdate#@{(Int,Int)}
                                   (\conv$32@{Int} conv$32) conv$31 conv$29 conv$34)) (
                                 let conv$27 = snd#@{(Sum Error Int), (Sum Error Int)} conv$30
                                  in conv$27)) conv$28) conv$33) (Right Map []@{(Sum Error (Map Int Int))}) conv$4

Returning:
  repl                 = conv$36
tranma commented 8 years ago

yeah this is much better at least indentation-wise.

There are still problems like unclear distinction of annotations, e.g. Map_fold#@{((Sum Error Int),((Sum Error Int), (Sum Error Int)))}@{(Sum Error (Map Int Int))}, one is the arguments the other is the return type but it's kinda hard to see. And sometimes the annotations are separated by spaces sometimes by comma (e.g. Sum_fold#@{(Error,Int)}@{(Sum Error Int)}). These things can be solved later though, this is a good start :rocket: :moon: