Skip to content
Draft
1 change: 1 addition & 0 deletions regression-tests/tests/1opt-par1.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5
20 changes: 20 additions & 0 deletions regression-tests/tests/1opt-par1.ssl.failing
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// once non-application expressions are allowed inside a par,
// this test should pass.

// check that optimize par pass does NOT rewrite par expressions
// that have at least one non-instantaneous argument

type Pair2 a b
Pair2 a b

add a b = a + b

main cin cout =
let q = par 3+4 // instantaneous
add 3 4 // functions are not necessarily instantaneous

// ^should NOT rewrite q as a tuple
after 1, cout <- 5 + 48 // Should print 5
wait cout
after 1, cout <- 10
wait cout
1 change: 1 addition & 0 deletions regression-tests/tests/1opt-par2.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5
17 changes: 17 additions & 0 deletions regression-tests/tests/1opt-par2.ssl
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// check that optimize par pass rewrites par expressions
// that have all instantaneous arguemnts as tuples

type Pair2 a b
Pair2 a b

add a b = a + b

main cin cout =
let q = par 2+3 // instantaneous
3+4 // instantaneous

// ^should rewrite q as a tuple
after 1, cout <- 5 + 48 // Should print 5
wait cout
after 1, cout <- 10
wait cout
1 change: 1 addition & 0 deletions regression-tests/tests/1opt-par3.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5
16 changes: 16 additions & 0 deletions regression-tests/tests/1opt-par3.ssl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// check that optimize par pass does NOT rewrite par expressions
// that have at least one non-instantaneous argument

type Pair2 a b
Pair2 a b

add a b = a + b

main cin cout =
let q = par add 2 3 // functions are not necessarily instantaneous
add 3 4 // functions are not necessarily instantaneous
// ^should NOT rewrite q as a tuple
after 1, cout <- 5 + 48 // Should print 5
wait cout
after 1, cout <- 10
wait cout
1 change: 1 addition & 0 deletions regression-tests/tests/1opt-par4.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A
23 changes: 23 additions & 0 deletions regression-tests/tests/1opt-par4.ssl.failing
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// once codegen supports return value of tuples,
// this test should pass

// check that optimize par pass does NOT rewrite par expressions
// that have at least one non-instantaneous argument

type Pair2 a b
Pair2 a b

add a b = a + b

main cin cout =
let x = 5
y = 60
let r = par add x y // functions are not necessarily instantaneous
add y x // functions are not necessarily instantaneous
// ^should NOT rewrite r as a tuple
match r
(0,0) = ()
(a1,a2) = after 1, cout <- a2
wait cout
after 1, cout <- 10
wait cout
1 change: 1 addition & 0 deletions regression-tests/tests/1opt-par5.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5
17 changes: 17 additions & 0 deletions regression-tests/tests/1opt-par5.ssl.failing
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// once non-application expressions are allowed inside a par,
// this test should pass.

// check that optimize par pass does NOT rewrite par expressions
// that have at least one non-instantaneous argument

add a b = a + b

main cin cout =
let q = par 2+3 // instantaneous
3+4 // instantaneous
wait cout // NOT instantaneous
// ^should NOT rewrite q as a tuple
after 1, cout <- 5 + 48 // Should print 5
wait cout
after 1, cout <- 10
wait cout
1 change: 1 addition & 0 deletions regression-tests/tests/1opt-par6.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
5
16 changes: 16 additions & 0 deletions regression-tests/tests/1opt-par6.ssl.failing
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// once non-application expressions are allowed inside a par,
// this test should pass.

// check that optimize par pass does NOT rewrite par expressions
// that have at least one non-instantaneous argument

add a b = a + b
main cin cout =
let q = par wait cout // NOT instantaneous
wait cout // NOT instantaneous
wait cout // NOT instantaneous
// ^should NOT rewrite q as a tuple
after 1, cout <- 5 + 48 // Should print 5
wait cout
after 1, cout <- 10
wait cout
41 changes: 41 additions & 0 deletions regression-tests/tests/1opt-par7.failing
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// once codegen supports return value of tuples,
// this test should pass

type Pair2 a b
Pair2 a b

add a b = a + b

printCharTuple putc p =
match p
(x,y) = putc x
putc 32
putc y

main cin cout =
let putc c = after 1, cout <- c
wait cout
let putnl _ = putc 10

let x = 66
let y = 67

// tuple with arguments evaluated sequentially
let w = (add x 0, add y 0)
// let's print it out
printCharTuple putc w // this is okay
putnl ()

// tuple with arguments already evaluated
let r = (x,y)
// let's print it out
printCharTuple putc r // this is okay
putnl ()

// code below causes segmentation fault
// par with arguments evaluated at the same time
let q = par add x 0
add y 0
// let's print it out
printCharTuple putc q // this is okay
putnl ()
3 changes: 3 additions & 0 deletions regression-tests/tests/1opt-par7.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
B C
B C
B C
7 changes: 7 additions & 0 deletions src/IR.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import Text.Show.Pretty
-}
data Mode
= Continue
| DumpOptPar
| DumpIR
| DumpIRAnnotated
| DumpIRConstraints
Expand Down Expand Up @@ -70,6 +71,11 @@ options =
["dump-ir"]
(NoArg $ setMode DumpIRAnnotated)
"Print the IR immediately after lowering"
, Option
""
["dumpOptPar"]
(NoArg $ setMode DumpOptPar)
"Print the IR immediately after opt par pass"
, Option
""
["dump-ir-annotated"]
Expand Down Expand Up @@ -153,6 +159,7 @@ transform opt p = do
p <- dConToFunc p
p <- externToCall p
p <- optimizePar p
when (mode opt == DumpOptPar) $ (throwError . Dump . ppShow) p
p <- liftProgramLambdas p
p <- segmentLets p
when (mode opt == DumpIRLifted) $ dump p
Expand Down
Loading