-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into ramsay-t/translation-efficiency-2
- Loading branch information
Showing
17 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
plutus-tx-plugin/test/Recursion/9.6/length-direct.budget.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
({cpu: 1855724 | ||
| mem: 9806}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(con integer 3) |
17 changes: 17 additions & 0 deletions
17
plutus-tx-plugin/test/Recursion/9.6/length-direct.pir.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
letrec | ||
data (List :: * -> *) a | List_match where | ||
Nil : List a | ||
Cons : a -> List a -> List a | ||
in | ||
letrec | ||
!lengthDirect : List integer -> integer | ||
= \(xs : List integer) -> | ||
List_match | ||
{integer} | ||
xs | ||
{integer} | ||
0 | ||
(\(ds : integer) (ys : List integer) -> | ||
addInteger 1 (lengthDirect ys)) | ||
in | ||
lengthDirect |
3 changes: 3 additions & 0 deletions
3
plutus-tx-plugin/test/Recursion/9.6/length-direct.uplc.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(program | ||
1.1.0 | ||
((\s -> s s) (\s xs -> case xs [0, (\ds ys -> addInteger 1 (s s ys))]))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
({cpu: 1855724 | ||
| mem: 9806}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
(con integer 3) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
letrec | ||
data (List :: * -> *) a | List_match where | ||
Nil : List a | ||
Cons : a -> List a -> List a | ||
in | ||
(let | ||
a = List integer | ||
in | ||
/\b -> | ||
\(f : (a -> b) -> a -> b) -> | ||
let | ||
!s : (\a -> ifix (\(self :: * -> *) a -> self a -> a) a) (a -> b) | ||
= iwrap | ||
(\(self :: * -> *) a -> self a -> a) | ||
(a -> b) | ||
(\(s : | ||
(\a -> ifix (\(self :: * -> *) a -> self a -> a) a) | ||
(a -> b)) -> | ||
f (\(x : a) -> unwrap s s x)) | ||
in | ||
unwrap s s) | ||
{integer} | ||
(\(f : List integer -> integer) (xs : List integer) -> | ||
List_match | ||
{integer} | ||
xs | ||
{integer} | ||
0 | ||
(\(ds : integer) (ys : List integer) -> addInteger 1 (f ys))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
(program | ||
1.1.0 | ||
((\s -> s s) (\s xs -> case xs [0, (\ds ys -> addInteger 1 (s s ys))]))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
{-# LANGUAGE BangPatterns #-} | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE LambdaCase #-} | ||
{-# LANGUAGE MultiParamTypeClasses #-} | ||
{-# LANGUAGE NegativeLiterals #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE PatternSynonyms #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
{-# LANGUAGE ViewPatterns #-} | ||
|
||
{-# OPTIONS_GHC -fplugin-opt PlutusTx.Plugin:defer-errors #-} | ||
|
||
module Recursion.Spec where | ||
|
||
import Test.Tasty.Extras | ||
|
||
import PlutusTx.Code | ||
import PlutusTx.Function (fix) | ||
import PlutusTx.Lift (liftCodeDef) | ||
import PlutusTx.Prelude qualified as PlutusTx | ||
import PlutusTx.Test | ||
import PlutusTx.TH (compile) | ||
|
||
tests :: TestNested | ||
tests = | ||
testNested "Recursion" . pure $ | ||
testNestedGhc | ||
[ goldenUPlcReadable "length-direct" compiledLengthDirect | ||
, goldenPirReadable "length-direct" compiledLengthDirect | ||
, goldenEvalCekCatch | ||
"length-direct" | ||
[compiledLengthDirect `unsafeApplyCode` liftCodeDef [1, 2, 3]] | ||
, goldenBudget | ||
"length-direct" | ||
(compiledLengthDirect `unsafeApplyCode` liftCodeDef [1, 2, 3]) | ||
, goldenUPlcReadable "length-fix" compiledLengthFix | ||
, goldenPirReadable "length-fix" compiledLengthFix | ||
, goldenEvalCekCatch | ||
"length-fix" | ||
[compiledLengthFix `unsafeApplyCode` liftCodeDef [1, 2, 3]] | ||
, goldenBudget | ||
"length-fix" | ||
(compiledLengthFix `unsafeApplyCode` liftCodeDef [1, 2, 3]) | ||
] | ||
|
||
lengthDirect :: [Integer] -> Integer | ||
lengthDirect xs = case xs of | ||
[] -> 0 | ||
(_ : ys) -> 1 PlutusTx.+ lengthDirect ys | ||
|
||
lengthFix :: [Integer] -> Integer | ||
lengthFix = | ||
fix | ||
( \f xs -> case xs of | ||
[] -> 0 | ||
(_ : ys) -> 1 PlutusTx.+ f ys | ||
) | ||
|
||
compiledLengthDirect :: CompiledCode ([Integer] -> Integer) | ||
compiledLengthDirect = $$(compile [||lengthDirect||]) | ||
|
||
compiledLengthFix :: CompiledCode ([Integer] -> Integer) | ||
compiledLengthFix = $$(compile [||lengthFix||]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
### Added | ||
|
||
- `PlutusTx.Function.fix`, Plinth's equivalent of `Data.Function.fix`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module PlutusTx.Function (fix) where | ||
|
||
fix :: forall a b. ((a -> b) -> a -> b) -> a -> b | ||
fix f = let ~x = f x in x | ||
{-# OPAQUE fix #-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters