Skip to content

Commit

Permalink
Add recordFieldsManual test (#5636)
Browse files Browse the repository at this point in the history
* Add recordFieldsManual test

* Use field accessors repeatedly

* 9.6
  • Loading branch information
zliu41 authored Nov 16, 2023
1 parent 2de3958 commit 0e3c20b
Show file tree
Hide file tree
Showing 28 changed files with 1,144 additions and 132 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
program
1.1.0
(\d ->
(\tup ->
force
(force ifThenElse
(equalsInteger 0 (force (force fstPair) tup))
(delay
((\l ->
(\l ->
(\l ->
(\ds ->
(\ds ->
(\ds -> unIData (force headList l))
(unIData (force headList (force tailList l))))
(unIData (force headList l)))
(unIData (force headList l)))
(force tailList l))
(force tailList l))
(force (force sndPair) tup)))
(delay error)))
(unConstrData d))
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 4752053
| mem: 14356})
({cpu: 55946147
| mem: 167776})
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(con integer 100)
(con integer 220)
86 changes: 53 additions & 33 deletions plutus-tx-plugin/test/AsData/Budget/9.2/patternMatching.pir.golden
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
let
data (Tuple4 :: * -> * -> * -> * -> *) a b c d | Tuple4_match where
Tuple4 : a -> b -> c -> d -> Tuple4 a b c d
!addInteger : integer -> integer -> integer
= \(x : integer) (y : integer) -> addInteger x y
data Bool | Bool_match where
True : Bool
False : Bool
!addInteger : integer -> integer -> integer
= \(x : integer) (y : integer) -> addInteger x y
!lessThanInteger : integer -> integer -> Bool
= \(x : integer) (y : integer) ->
ifThenElse {Bool} (lessThanInteger x y) True False
in
\(d : data) ->
let
!ds : Tuple4 integer integer integer integer
~ds : Tuple4 integer integer integer integer
= (let
r = Tuple4 integer integer integer integer
in
Expand Down Expand Up @@ -39,39 +42,56 @@ in
(\(x : integer) (y : integer) (z : integer) (w : integer) ->
Tuple4 {integer} {integer} {integer} {integer} x y z w)
(\(void : unit) -> error {Tuple4 integer integer integer integer})
in
addInteger
(addInteger
(addInteger
(Tuple4_match
{integer}
{integer}
{integer}
{integer}
ds
{integer}
(\(x : integer) (y : integer) (z : integer) (w : integer) -> x))
(Tuple4_match
{integer}
{integer}
{integer}
{integer}
ds
{integer}
(\(x : integer) (y : integer) (z : integer) (w : integer) -> y)))
(Tuple4_match
~w : integer
= Tuple4_match
{integer}
{integer}
{integer}
{integer}
ds
{integer}
(\(x : integer) (y : integer) (z : integer) (w : integer) -> w)
~z : integer
= Tuple4_match
{integer}
{integer}
{integer}
{integer}
ds
{integer}
(\(x : integer) (y : integer) (z : integer) (w : integer) -> z)
~y : integer
= Tuple4_match
{integer}
{integer}
{integer}
{integer}
ds
{integer}
(\(x : integer) (y : integer) (z : integer) (w : integer) -> y)
~x : integer
= Tuple4_match
{integer}
{integer}
{integer}
{integer}
ds
{integer}
(\(x : integer) (y : integer) (z : integer) (w : integer) -> z)))
(Tuple4_match
{integer}
{integer}
{integer}
{integer}
ds
{integer}
(\(x : integer) (y : integer) (z : integer) (w : integer) -> w))
(\(x : integer) (y : integer) (z : integer) (w : integer) -> x)
!ds : Tuple4 integer integer integer integer = ds
in
addInteger
(addInteger
(addInteger (addInteger (addInteger x y) z) w)
(Bool_match
(lessThanInteger (addInteger y z) (addInteger x w))
{all dead. integer}
(/\dead -> addInteger x z)
(/\dead -> addInteger y w)
{all dead. dead}))
(Bool_match
(lessThanInteger (addInteger z y) (addInteger w x))
{all dead. integer}
(/\dead -> addInteger z x)
(/\dead -> addInteger w y)
{all dead. dead})
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
program
1.1.0
(\d ->
(\ds ->
(\ds ->
(\x ->
(\y ->
(\z ->
(\w ->
(\lessThanInteger ->
(\addInteger ->
addInteger
(addInteger
(addInteger
(addInteger
(addInteger (force x) (force y))
(force z))
(force w))
(force
(case
(lessThanInteger
(addInteger (force y) (force z))
(addInteger (force x) (force w)))
[ (delay
(addInteger (force x) (force z)))
, (delay
(addInteger
(force y)
(force w))) ])))
(force
(case
(lessThanInteger
(addInteger (force z) (force y))
(addInteger (force w) (force x)))
[ (delay (addInteger (force z) (force x)))
, (delay
(addInteger (force w) (force y))) ])))
(\x y -> addInteger x y))
(\x y ->
force ifThenElse
(lessThanInteger x y)
(constr 0 [])
(constr 1 [])))
(delay (case (force ds) [(\x y z w -> w)])))
(delay (case (force ds) [(\x y z w -> z)])))
(delay (case (force ds) [(\x y z w -> y)])))
(delay (case (force ds) [(\x y z w -> x)])))
(force ds))
(delay
((\tup ->
force
(force ifThenElse
(equalsInteger 0 (force (force fstPair) tup))
(delay
((\l ->
(\l ->
(\l ->
(\z w ->
constr 0
[ (unIData (force headList l))
, (unIData (force headList l))
, z
, w ])
(unIData (force headList l))
(unIData (force headList (force tailList l))))
(force tailList l))
(force tailList l))
(force (force sndPair) tup)))
(delay error)))
(unConstrData d))))
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
({cpu: 23015765
| mem: 62058})
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
({cpu: 12986619
| mem: 39006})
({cpu: 36195493
| mem: 107926})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(con integer 220)
101 changes: 101 additions & 0 deletions plutus-tx-plugin/test/AsData/Budget/9.2/recordFields-manual.pir.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
let
!addInteger : integer -> integer -> integer
= \(x : integer) (y : integer) -> addInteger x y
!int1Manual : data -> integer
= \(ds : data) ->
let
!tup : pair integer (list data) = unConstrData ds
!i : integer = fstPair {integer} {list data} tup
!d : data = headList {data} (sndPair {integer} {list data} tup)
in
ifThenElse
{all dead. integer}
(equalsInteger 0 i)
(/\dead -> unIData d)
(/\dead -> error {integer})
{all dead. dead}
!int2Manual : data -> integer
= \(ds : data) ->
let
!tup : pair integer (list data) = unConstrData ds
!i : integer = fstPair {integer} {list data} tup
!d : data
= headList
{data}
(tailList {data} (sndPair {integer} {list data} tup))
in
ifThenElse
{all dead. integer}
(equalsInteger 0 i)
(/\dead -> unIData d)
(/\dead -> error {integer})
{all dead. dead}
!int3Manual : data -> integer
= \(ds : data) ->
let
!tup : pair integer (list data) = unConstrData ds
!i : integer = fstPair {integer} {list data} tup
!d : data
= headList
{data}
(tailList
{data}
(tailList {data} (sndPair {integer} {list data} tup)))
in
ifThenElse
{all dead. integer}
(equalsInteger 0 i)
(/\dead -> unIData d)
(/\dead -> error {integer})
{all dead. dead}
!int4Manual : data -> integer
= \(ds : data) ->
let
!tup : pair integer (list data) = unConstrData ds
!i : integer = fstPair {integer} {list data} tup
!d : data
= headList
{data}
(tailList
{data}
(tailList
{data}
(tailList {data} (sndPair {integer} {list data} tup))))
in
ifThenElse
{all dead. integer}
(equalsInteger 0 i)
(/\dead -> unIData d)
(/\dead -> error {integer})
{all dead. dead}
data Bool | Bool_match where
True : Bool
False : Bool
!lessThanInteger : integer -> integer -> Bool
= \(x : integer) (y : integer) ->
ifThenElse {Bool} (lessThanInteger x y) True False
in
\(d : data) ->
let
!x : integer = int1Manual d
!y : integer = int2Manual d
!z : integer = int3Manual d
!w : integer = int4Manual d
in
addInteger
(addInteger
(addInteger (addInteger (addInteger x y) z) w)
(Bool_match
(lessThanInteger (addInteger y z) (addInteger x w))
{all dead. integer}
(/\dead -> addInteger x z)
(/\dead -> addInteger y w)
{all dead. dead}))
(Bool_match
(lessThanInteger
(addInteger (int3Manual d) (int2Manual d))
(addInteger (int4Manual d) (int1Manual d)))
{all dead. integer}
(/\dead -> addInteger (int3Manual d) (int1Manual d))
(/\dead -> addInteger (int4Manual d) (int2Manual d))
{all dead. dead})
Loading

0 comments on commit 0e3c20b

Please sign in to comment.