ssm-lang / sslang

A language built atop the Sparse Synchronous Model
BSD 3-Clause "New" or "Revised" License
18 stars 0 forks source link

Optimize par #159

Open MatthewDavidGoodman opened 1 year ago

MatthewDavidGoodman commented 1 year ago

par optimization for par expression with instantaneous arguments

EmilySillars commented 1 year ago

Final Steps in Par to Tuple Transformation

Hey Matthew, I think if you can answer the questions after this example program, you will be ready to fix the last part of your optimize-par transformation pass.

type Pair2 a b
    Pair2 a b

type Pair3 a b c
    Pair3 a b c

type Bool
    False
    True

giveBool x = False

giveNum y = 2

p q = par giveNum 5
          giveNum 7
          giveBool 5

t r = Pair3 (giveNum 5) (giveNum 7) (giveBool 5)

t2 r2 = Pair3 2 2 False

main cin cout = ()

1) What is the type of the return value of function p? Hint: stack exec sslc -- --dump-ir-typed tests/test-file-name.ssl

2) What is the type of the return value of function t? Of function t2? Hint: stack exec sslc -- --dump-ir-typed tests/test-file-name.ssl

3) What is the return value of function t? Of function t2? Hint: stack exec sslc -- --dump-ir-typed tests/test-file-name.ssl

4) What does the return value of function t2 look like in the IR? (Draw the IR tree) Hint1: stack exec sslc -- --dump-ir-typed-ugly tests/test-file-name.ssl Hint2: It's a bunch of nested application nodes Hint3: Drawings of the IR tree from this guide might help. Hint4: Here's how I would add spaces to the dumped IR to make it more readable for function t2:

(VarId t2,Lambda (Just (VarId r2)) 
  (App (App (App 
                (Var (VarId __Pair3) (TCon -> [TCon Int32 [],
                                      TCon -> [TCon Int32 [],
                                      TCon -> [TCon Bool [],TCon Pair3 [TCon Int32 [],TCon Int32 [],TCon Bool []]]]])) 
                (Lit (LitIntegral 2) (TCon Int32 [])) 
            (TCon -> [TCon Int32 [],
             TCon -> [TCon Bool [],TCon Pair3 [TCon Int32 [],TCon Int32 [],TCon Bool []]]])) 

            (Lit (LitIntegral 2) (TCon Int32 [])) 
        (TCon -> [TCon Bool [],TCon Pair3 [TCon Int32 [],TCon Int32 [],TCon Bool []]])) 

        (Data (DConId False) (TCon Bool [])) 
  (TCon Pair3 [TCon Int32 [],TCon Int32 [],TCon Bool []])) 

5) What is the type of each node in this tree? Hint: Think partial application of data constructors.

6) When you transform a par expression into a tuple, the type of the tuple IR node and all of its subnodes must have the correct type. When you pass foldApp a data constructor and a list of arguments, it will wrap them up in the correct nested application form, but foldApp also needs you tell it the type of each node (and subnode) in the nested application in order to perform this wrapping. Suppose you want to construct a tuple that looks like (Pair3 2 2 False); what are the extra types you must provide to foldApp?