-
Notifications
You must be signed in to change notification settings - Fork 479
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle integerNegate in the plugin (#5494)
- Loading branch information
Showing
10 changed files
with
341 additions
and
21 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
35 changes: 35 additions & 0 deletions
35
...s-tx-plugin/test/IntegerLiterals/9.2/integerLiterals-NoStrict-NegativeLiterals.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,35 @@ | ||
(program | ||
1.1.0 | ||
(lam | ||
x | ||
(con integer) | ||
[ | ||
[ (builtin addInteger) (con integer 24680135792468013579) ] | ||
[ | ||
[ (builtin addInteger) (con integer -99887766554433221100) ] | ||
[ | ||
[ (builtin addInteger) (con integer 98765432109876543210) ] | ||
[ | ||
[ (builtin addInteger) (con integer -654) ] | ||
[ | ||
[ (builtin addInteger) (con integer 456) ] | ||
[ | ||
[ (builtin addInteger) (con integer 13579246801357924680) ] | ||
[ | ||
[ (builtin addInteger) (con integer -11223344556677889900) ] | ||
[ | ||
[ (builtin addInteger) (con integer 12345678901234567890) ] | ||
[ | ||
[ (builtin addInteger) (con integer -321) ] | ||
[ [ (builtin multiplyInteger) (con integer 123) ] x ] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
) | ||
) |
35 changes: 35 additions & 0 deletions
35
...tx-plugin/test/IntegerLiterals/9.2/integerLiterals-NoStrict-NoNegativeLiterals.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,35 @@ | ||
(program | ||
1.1.0 | ||
(lam | ||
x | ||
(con integer) | ||
[ | ||
[ (builtin addInteger) (con integer 24680135792468013579) ] | ||
[ | ||
[ (builtin addInteger) (con integer -99887766554433221100) ] | ||
[ | ||
[ (builtin addInteger) (con integer 98765432109876543210) ] | ||
[ | ||
[ (builtin addInteger) (con integer -654) ] | ||
[ | ||
[ (builtin addInteger) (con integer 456) ] | ||
[ | ||
[ (builtin addInteger) (con integer 13579246801357924680) ] | ||
[ | ||
[ (builtin addInteger) (con integer -11223344556677889900) ] | ||
[ | ||
[ (builtin addInteger) (con integer 12345678901234567890) ] | ||
[ | ||
[ (builtin addInteger) (con integer -321) ] | ||
[ [ (builtin multiplyInteger) (con integer 123) ] x ] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
) | ||
) |
35 changes: 35 additions & 0 deletions
35
...s-tx-plugin/test/IntegerLiterals/9.6/integerLiterals-NoStrict-NegativeLiterals.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,35 @@ | ||
(program | ||
1.1.0 | ||
(lam | ||
x | ||
(con integer) | ||
[ | ||
[ (builtin addInteger) (con integer 24680135792468013579) ] | ||
[ | ||
[ (builtin addInteger) (con integer -99887766554433221100) ] | ||
[ | ||
[ (builtin addInteger) (con integer 98765432109876543210) ] | ||
[ | ||
[ (builtin addInteger) (con integer -654) ] | ||
[ | ||
[ (builtin addInteger) (con integer 456) ] | ||
[ | ||
[ (builtin addInteger) (con integer 13579246801357924680) ] | ||
[ | ||
[ (builtin addInteger) (con integer -11223344556677889900) ] | ||
[ | ||
[ (builtin addInteger) (con integer 12345678901234567890) ] | ||
[ | ||
[ (builtin addInteger) (con integer -321) ] | ||
[ [ (builtin multiplyInteger) (con integer 123) ] x ] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
) | ||
) |
35 changes: 35 additions & 0 deletions
35
...tx-plugin/test/IntegerLiterals/9.6/integerLiterals-NoStrict-NoNegativeLiterals.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,35 @@ | ||
(program | ||
1.1.0 | ||
(lam | ||
x | ||
(con integer) | ||
[ | ||
[ (builtin addInteger) (con integer 24680135792468013579) ] | ||
[ | ||
[ (builtin addInteger) (con integer -99887766554433221100) ] | ||
[ | ||
[ (builtin addInteger) (con integer 98765432109876543210) ] | ||
[ | ||
[ (builtin addInteger) (con integer -654) ] | ||
[ | ||
[ (builtin addInteger) (con integer 456) ] | ||
[ | ||
[ (builtin addInteger) (con integer 13579246801357924680) ] | ||
[ | ||
[ (builtin addInteger) (con integer -11223344556677889900) ] | ||
[ | ||
[ (builtin addInteger) (con integer 12345678901234567890) ] | ||
[ | ||
[ (builtin addInteger) (con integer -321) ] | ||
[ [ (builtin multiplyInteger) (con integer 123) ] x ] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
] | ||
) | ||
) |
63 changes: 63 additions & 0 deletions
63
plutus-tx-plugin/test/IntegerLiterals/NoStrict/NegativeLiterals/Spec.hs
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,63 @@ | ||
{-# LANGUAGE BangPatterns #-} | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE MultiParamTypeClasses #-} | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE ScopedTypeVariables #-} | ||
{-# LANGUAGE TemplateHaskell #-} | ||
{-# LANGUAGE TypeApplications #-} | ||
|
||
{-# LANGUAGE NegativeLiterals #-} | ||
{-# LANGUAGE NoStrict #-} | ||
|
||
{-# OPTIONS_GHC -fplugin PlutusTx.Plugin #-} | ||
|
||
-- | This module tests that integer literals are handled correctly, when @Strict@ is off | ||
-- and @NegativeLiterals@ is on. These two extensions affect the Core we get. When | ||
-- @NegativeLiterals@ is on, we can get @IN@ for negative integers. | ||
-- | ||
-- This module runs the PIR and UPLC simplifiers, because (1) we want to verify that | ||
-- `integerNegate` is compiled away; (2) it is easier to tell from the optimized PIR | ||
-- whether or not the signs of the numbers are correct, which is ultimately what we | ||
-- care about. | ||
module IntegerLiterals.NoStrict.NegativeLiterals.Spec where | ||
|
||
import PlutusTx.Code | ||
import PlutusTx.Prelude qualified as PlutusTx | ||
import PlutusTx.Test | ||
import PlutusTx.TH (compile) | ||
|
||
import Test.Tasty.Extras | ||
|
||
tests :: TestNested | ||
tests = testNestedGhc "IntegerLiterals" | ||
[ goldenPir "integerLiterals-NoStrict-NegativeLiterals" integerLiterals | ||
] | ||
|
||
integerLiterals :: CompiledCode (Integer -> Integer) | ||
integerLiterals = | ||
$$( compile | ||
[|| | ||
\x -> | ||
let !smallStrict = 123 | ||
!smallNegStrict = -321 | ||
!bigStrict = 12345678901234567890 | ||
!bigNegStrict = -11223344556677889900 | ||
!bigDoubleNegStrict = -(-13579246801357924680) | ||
~smallLazy = 456 | ||
~smallNegLazy = -654 | ||
~bigLazy = 98765432109876543210 | ||
~bigNegLazy = -99887766554433221100 | ||
~bigDoubleNegLazy = -(-24680135792468013579) | ||
in x PlutusTx.* smallStrict | ||
PlutusTx.+ smallNegStrict | ||
PlutusTx.+ bigStrict | ||
PlutusTx.+ bigNegStrict | ||
PlutusTx.+ bigDoubleNegStrict | ||
PlutusTx.+ smallLazy | ||
PlutusTx.+ smallNegLazy | ||
PlutusTx.+ bigLazy | ||
PlutusTx.+ bigNegLazy | ||
PlutusTx.+ bigDoubleNegLazy | ||
||] | ||
) |
Oops, something went wrong.