Skip to content

Commit a032835

Browse files
committed
wip
1 parent a02cb68 commit a032835

File tree

154 files changed

+2382
-52
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+2382
-52
lines changed

out.html

Lines changed: 563 additions & 0 deletions
Large diffs are not rendered by default.

plutus-tx-plugin/src/PlutusTx/Compiler/Expr.hs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -984,24 +984,31 @@ compileExpr e = traceCompilation 2 ("Compiling expr:" GHC.<+> GHC.ppr e) $ do
984984
-- <error func> <overall type> <message>
985985
GHC.Var (isErrorId -> True) `GHC.App` GHC.Type t `GHC.App` _ ->
986986
PIR.TyInst annMayInline <$> errorFunc <*> compileTypeNorm t
987-
(strip -> GHC.Var n) `GHC.App` GHC.Type ty
988-
| GHC.getName n == mkNilOpaqueName -> case ty of
987+
988+
(strip -> GHC.Var n) `GHC.App` GHC.Type ty | GHC.getName n == mkNilOpaqueName ->
989+
case ty of
989990
GHC.TyConApp tyCon []
990991
| tyCon == GHC.integerTyCon || tyCon == builtinIntegerTyCon ->
991992
pure $ PLC.mkConstant annMayInline ([] @Integer)
992-
| tyCon == builtinBoolTyCon -> pure $ PLC.mkConstant annMayInline ([] @Bool)
993-
| tyCon == builtinDataTyCon -> pure $ PLC.mkConstant annMayInline ([] @PLC.Data)
993+
| tyCon == builtinBoolTyCon ->
994+
pure $ PLC.mkConstant annMayInline ([] @Bool)
995+
| tyCon == builtinDataTyCon ->
996+
pure $ PLC.mkConstant annMayInline ([] @PLC.Data)
997+
994998
GHC.TyConApp tyCon [GHC.TyConApp tyArg1 [], GHC.TyConApp tyArg2 []]
995999
| (tyCon, tyArg1, tyArg2) == (builtinPairTyCon, builtinDataTyCon, builtinDataTyCon) ->
9961000
pure $ PLC.mkConstant annMayInline ([] @(PLC.Data, PLC.Data))
1001+
9971002
GHC.TyConApp tyCon [GHC.TyConApp tyArg1 []]
9981003
| (tyCon, tyArg1) == (builtinListTyCon, builtinIntegerTyCon) ->
9991004
pure $ PLC.mkConstant annMayInline ([] @[Integer])
10001005
| (tyCon, tyArg1) == (builtinListTyCon, builtinBoolTyCon) ->
10011006
pure $ PLC.mkConstant annMayInline ([] @[Bool])
10021007
| (tyCon, tyArg1) == (builtinListTyCon, builtinDataTyCon) ->
10031008
pure $ PLC.mkConstant annMayInline ([] @[PLC.Data])
1004-
_ -> throwPlain $ CompilationError "'mkNil' applied to an unknown type"
1009+
_ ->
1010+
throwPlain $ CompilationError "'mkNil' applied to an unknown type"
1011+
10051012
GHC.Var n
10061013
| GHC.getName n == useToOpaqueName ->
10071014
throwPlain $ UnsupportedError "It is no longer possible to use 'toBuiltin' with a script, use 'toOpaque' instead"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cpu: 9002784
2+
mem: 33712
3+
size: 42
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(con (list integer) [1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10])
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
\(xs : list integer) ->
2+
(let
3+
b = list integer
4+
in
5+
\(f : integer -> b -> b) (acc : b) ->
6+
letrec
7+
!go : list integer -> b
8+
= \(xs : list integer) ->
9+
chooseList
10+
{integer}
11+
{all dead. b}
12+
xs
13+
(/\dead -> acc)
14+
(/\dead ->
15+
let
16+
!x : integer = headList {integer} xs
17+
!xs : list integer = tailList {integer} xs
18+
in
19+
f x (go xs))
20+
{b}
21+
in
22+
go)
23+
(mkCons {integer})
24+
xs
25+
xs
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(program
2+
1.1.0
3+
(\xs ->
4+
(\s -> s s)
5+
(\s xs ->
6+
force
7+
(force (force chooseList)
8+
xs
9+
(delay xs)
10+
(delay
11+
(force mkCons
12+
(force headList xs)
13+
((\x -> s s x) (force tailList xs))))))
14+
xs))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cpu: 216462
2+
mem: 1032
3+
size: 9
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(con (list integer) [42,1,2,3,4,5,6,7,8,9,10])
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
\(xs : list integer) -> mkCons {integer} 42 xs
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(program 1.1.0 (\xs -> force mkCons 42 xs))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cpu: 2091812
2+
mem: 8694
3+
size: 53
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(constr 1)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
let
2+
data Bool | Bool_match where
3+
True : Bool
4+
False : Bool
5+
in
6+
letrec
7+
!go : list bool -> Bool
8+
= \(xs : list bool) ->
9+
chooseList
10+
{bool}
11+
{all dead. Bool}
12+
xs
13+
(/\dead -> True)
14+
(/\dead ->
15+
let
16+
!x : bool = headList {bool} xs
17+
!xs : list bool = tailList {bool} xs
18+
in
19+
Bool_match
20+
(ifThenElse {Bool} x True False)
21+
{all dead. Bool}
22+
(/\dead -> go xs)
23+
(/\dead -> False)
24+
{all dead. dead})
25+
{Bool}
26+
in
27+
\(xs : list bool) -> go xs
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
(program
2+
1.1.0
3+
((\go xs -> go xs)
4+
((\s -> s s)
5+
(\s xs ->
6+
force
7+
(force (force chooseList)
8+
xs
9+
(delay (constr 0 []))
10+
(delay
11+
((\x ->
12+
(\xs ->
13+
force
14+
(force ifThenElse
15+
x
16+
(delay (s s xs))
17+
(delay (constr 1 []))))
18+
(force tailList xs))
19+
(force headList xs))))))))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cpu: 9002784
2+
mem: 33712
3+
size: 42
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(con (list integer) [1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10])
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
\(xs : list integer) ->
2+
(let
3+
b = list integer
4+
in
5+
\(f : integer -> b -> b) (acc : b) ->
6+
letrec
7+
!go : list integer -> b
8+
= \(xs : list integer) ->
9+
chooseList
10+
{integer}
11+
{all dead. b}
12+
xs
13+
(/\dead -> acc)
14+
(/\dead ->
15+
let
16+
!x : integer = headList {integer} xs
17+
!xs : list integer = tailList {integer} xs
18+
in
19+
f x (go xs))
20+
{b}
21+
in
22+
go)
23+
(mkCons {integer})
24+
xs
25+
xs
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
(program
2+
1.1.0
3+
(\xs ->
4+
(\s -> s s)
5+
(\s xs ->
6+
force
7+
(force (force chooseList)
8+
xs
9+
(delay xs)
10+
(delay
11+
(force mkCons
12+
(force headList xs)
13+
((\x -> s s x) (force tailList xs))))))
14+
xs))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cpu: 23678800
2+
mem: 97612
3+
size: 85
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(con (list integer) [1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10])
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
let
2+
!caseList' : all a r. r -> (a -> list a -> r) -> list a -> r
3+
= /\a r ->
4+
\(z : r) (f : a -> list a -> r) (xs : list a) ->
5+
chooseList
6+
{a}
7+
{all dead. r}
8+
xs
9+
(/\dead -> z)
10+
(/\dead -> f (headList {a} xs) (tailList {a} xs))
11+
{r}
12+
in
13+
\(xs : list integer) ->
14+
(letrec
15+
!go : list (list integer) -> list integer
16+
= caseList'
17+
{list integer}
18+
{list integer}
19+
[]
20+
(\(x : list integer) (xs : list (list integer)) ->
21+
let
22+
!r : list integer = go xs
23+
in
24+
(let
25+
b = list integer
26+
in
27+
\(f : integer -> b -> b) (acc : b) ->
28+
letrec
29+
!go : list integer -> b
30+
= caseList'
31+
{integer}
32+
{b}
33+
acc
34+
(\(x : integer) (xs : list integer) -> f x (go xs))
35+
in
36+
go)
37+
(mkCons {integer})
38+
r
39+
x)
40+
in
41+
go)
42+
(mkCons
43+
{list integer}
44+
xs
45+
((let
46+
a = list integer
47+
in
48+
\(`$dMkNil` : (\arep -> list arep) a) (x : a) ->
49+
mkCons {a} x `$dMkNil`)
50+
[]
51+
xs))
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(program
2+
1.1.0
3+
(\xs ->
4+
(\caseList' ->
5+
(\s -> s s)
6+
(\s ->
7+
caseList'
8+
[]
9+
(\x xs ->
10+
(\acc ->
11+
(\s -> s s)
12+
(\s ->
13+
caseList' acc (\x xs -> force mkCons x (s s xs))))
14+
(s s xs)
15+
x)))
16+
(\z f xs ->
17+
force
18+
(force (force chooseList)
19+
xs
20+
(delay z)
21+
(delay (f (force headList xs) (force tailList xs)))))
22+
(force mkCons xs (force mkCons xs []))))
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
({cpu: 216462
2-
| mem: 1032})
1+
cpu: 216462
2+
mem: 1032
3+
size: 9
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cpu: 7834491
2+
mem: 32602
3+
size: 83
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(con (list integer) [])
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
let
2+
data Bool | Bool_match where
3+
True : Bool
4+
False : Bool
5+
in
6+
letrec
7+
!drop : all a. (\arep -> list arep) a -> integer -> list a -> list a
8+
= /\a ->
9+
\(`$dMkNil` : (\arep -> list arep) a) (n : integer) (l : list a) ->
10+
Bool_match
11+
(ifThenElse {Bool} (lessThanEqualsInteger n 0) True False)
12+
{all dead. list a}
13+
(/\dead -> `$dMkNil`)
14+
(/\dead ->
15+
(let
16+
r = list a
17+
in
18+
\(z : r) (f : a -> list a -> r) (xs : list a) ->
19+
chooseList
20+
{a}
21+
{all dead. r}
22+
xs
23+
(/\dead -> z)
24+
(/\dead -> f (headList {a} xs) (tailList {a} xs))
25+
{r})
26+
`$dMkNil`
27+
(\(ds : a) (xs : list a) ->
28+
drop {a} `$dMkNil` (subtractInteger n 1) xs)
29+
l)
30+
{all dead. dead}
31+
in
32+
\(xs : list integer) -> drop {integer} [] 5 xs
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
(program
2+
1.1.0
3+
((\drop xs -> force drop [] 5 xs)
4+
((\s -> s s)
5+
(\s arg ->
6+
delay
7+
(\`$dMkNil` n l ->
8+
force
9+
(force ifThenElse
10+
(lessThanEqualsInteger n 0)
11+
(delay `$dMkNil`)
12+
(delay
13+
(force
14+
(force (force chooseList)
15+
l
16+
(delay `$dMkNil`)
17+
(delay
18+
((\ds xs ->
19+
force (s s (delay (\x -> x)))
20+
`$dMkNil`
21+
(subtractInteger n 1)
22+
xs)
23+
(force headList l)
24+
(force tailList l)))))))))
25+
(delay (\x -> x)))))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
cpu: 5295830
2+
mem: 20590
3+
size: 54
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(con (list integer) [5,6,7,8,9,10])

0 commit comments

Comments
 (0)