Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize par #159

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft

Optimize par #159

wants to merge 12 commits into from

Conversation

MatthewDavidGoodman
Copy link

par optimization for par expression with instantaneous arguments

@EmilySillars
Copy link
Contributor

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 []])) 
  1. What is the type of each node in this tree?
    Hint: Think partial application of data constructors.

  2. 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?

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