|
1 | 1 | include "mexpr/ast-builder.mc" |
2 | 2 | include "mexpr/builtin.mc" |
3 | 3 | include "mexpr/eq.mc" |
| 4 | +include "mexpr/pprint.mc" |
4 | 5 | include "mexpr/side-effect.mc" |
5 | 6 | include "mexpr/symbolize.mc" |
6 | 7 | include "name.mc" |
@@ -327,20 +328,86 @@ lang MExprDeadcodeElimination = |
327 | 328 | removeLets nmap t |
328 | 329 | end |
329 | 330 |
|
330 | | -lang TestLang = MExprDeadcodeElimination + MExprEq |
| 331 | +lang TestLang = MExprDeadcodeElimination + MExprEq + MExprPrettyPrint |
331 | 332 | end |
332 | 333 |
|
333 | 334 | mexpr |
334 | 335 |
|
335 | 336 | use TestLang in |
336 | 337 |
|
| 338 | +let pprintExprs = lam l. lam r. |
| 339 | + join ["LHS:\n", expr2str l, "\n\nRHS:\n", expr2str r] |
| 340 | +in |
| 341 | + |
| 342 | +let e = |
| 343 | + bind_ |
| 344 | + (ulet_ "x" (int_ 2)) |
| 345 | + (var_ "x") |
| 346 | +in |
| 347 | +utest deadcodeElimination e with e using eqExpr else pprintExprs in |
| 348 | + |
337 | 349 | let e = |
338 | 350 | bindall_ |
339 | 351 | [ ulet_ "x" (int_ 2) |
340 | 352 | , ulet_ "y" (int_ 3) ] |
341 | 353 | (var_ "y") |
342 | 354 | in |
343 | 355 | let expected = bind_ (ulet_ "y" (int_ 3)) (var_ "y") in |
344 | | -utest deadcodeElimination e with expected using eqExpr in |
| 356 | +utest deadcodeElimination e with expected using eqExpr else pprintExprs in |
| 357 | + |
| 358 | +let e = |
| 359 | + bind_ |
| 360 | + (ureclets_ [ |
| 361 | + ("x", (ulam_ "a" (app_ (var_ "y") (var_ "a")))), |
| 362 | + ("y", (ulam_ "b" (int_ 0))) |
| 363 | + ]) |
| 364 | + (var_ "x") |
| 365 | +in |
| 366 | +utest deadcodeElimination e with e using eqExpr else pprintExprs in |
| 367 | + |
| 368 | +let e = |
| 369 | + bind_ |
| 370 | + (ureclets_ [ |
| 371 | + ("x", (ulam_ "a" (app_ (var_ "y") (var_ "a")))), |
| 372 | + ("y", (ulam_ "b" (app_ (var_ "x") (var_ "b")))), |
| 373 | + ("z", (ulam_ "c" (int_ 0))) |
| 374 | + ]) |
| 375 | + (var_ "y") |
| 376 | +in |
| 377 | +let expected = |
| 378 | + bind_ |
| 379 | + (ureclets_ |
| 380 | + [ ("x", (ulam_ "a" (app_ (var_ "y") (var_ "a")))) |
| 381 | + , ("y", (ulam_ "b" (app_ (var_ "x") (var_ "b")))) ]) |
| 382 | + (var_ "y") |
| 383 | +in |
| 384 | +utest deadcodeElimination e with expected using eqExpr else pprintExprs in |
| 385 | + |
| 386 | +let e = |
| 387 | + bindall_ |
| 388 | + [ ulet_ "z" (int_ 0) |
| 389 | + , ureclets_ |
| 390 | + [ ("x", (ulam_ "a" (app_ (var_ "y") (var_ "a")))) |
| 391 | + , ("y", (ulam_ "b" (app_ (var_ "x") (var_ "b")))) ] ] |
| 392 | + (var_ "z") |
| 393 | +in |
| 394 | +let expected = bind_ (ulet_ "z" (int_ 0)) (var_ "z") in |
| 395 | +utest deadcodeElimination e with expected using eqExpr else pprintExprs in |
| 396 | + |
| 397 | +let e = |
| 398 | + bindall_ |
| 399 | + [ ext_ "abs_int" true (tyarrow_ tyint_ tyint_) |
| 400 | + , ulet_ "" (app_ (var_ "abs_int") (int_ -3)) ] |
| 401 | + (int_ 0) |
| 402 | +in |
| 403 | +utest deadcodeElimination e with e using eqExpr else pprintExprs in |
| 404 | + |
| 405 | +let e = |
| 406 | + bindall_ |
| 407 | + [ ext_ "abs_int" false (tyarrow_ tyint_ tyint_) |
| 408 | + , ulet_ "" (app_ (var_ "abs_int") (int_ -3)) ] |
| 409 | + (int_ 0) |
| 410 | +in |
| 411 | +utest deadcodeElimination e with int_ 0 using eqExpr else pprintExprs in |
345 | 412 |
|
346 | 413 | () |
0 commit comments