Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rebase verifies Compilation #6379

Merged
merged 190 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
190 commits
Select commit Hold shift + click to select a range
7db7e37
Trace removal re-implemented as a IR rewrite rule (#5907)
Unisay Apr 17, 2024
d32bc7e
CIP-0057 Howto: exporting a Plutus contract blueprint (#5817)
Unisay Apr 18, 2024
3e00141
[Release] 1.26.0.0 (#5914)
ana-pantilie Apr 19, 2024
7707aab
A quick isabelle experiment. (#5913)
ramsay-t Apr 19, 2024
9d0a9cf
PLT-8171: Combine PIR, PLC, and UPLC into a single executable (#5699)
bezirg Apr 21, 2024
83fe75f
chore(deps): bump slackapi/slack-github-action from 1.25.0 to 1.26.0 …
dependabot[bot] Apr 22, 2024
2e2a7fb
Kwxm/plc spec/bitwise conversions (#5911)
Apr 22, 2024
bcce392
Use Int64 in CostModelParams (#5920)
zliu41 Apr 23, 2024
b97e8be
Change CMTooFewParamsError to a warning (#5912)
zliu41 Apr 23, 2024
3944e09
[Costing] Provide support for multiple 'CostModel's (#5851)
effectfully Apr 25, 2024
0567ef7
CaseOfCase kind mismatch error fix (#5923)
Unisay Apr 26, 2024
2748f90
Fix some Notes so they pass the check (#5930)
Apr 29, 2024
4a29380
Restore old cost model param names (#5932)
Apr 29, 2024
d64be66
Tidy up SimpleJSON.hs (#5936)
Apr 30, 2024
6912db2
chore: formatting (#5937)
Unisay Apr 30, 2024
d10d5df
1.27.0.0 (#5938)
zliu41 Apr 30, 2024
d319fe5
Do not build the plutus executable if GHC <9.6 (#5940)
zliu41 Apr 30, 2024
f1eae1c
Update CONTRIBUTING.adoc (#5950)
zliu41 May 3, 2024
619ddbc
Add 'Note [Table of all possible ledger's states w.r.t. cost model pa…
effectfully May 3, 2024
067e74f
Remove annoying error message (#5956)
May 4, 2024
ca60dad
Add plutus-tx-template Release Instructions and GH Workflow (#5952)
zeme-wana May 6, 2024
ef40c38
[StdLib] Strictify 'fix' (#5939)
effectfully May 6, 2024
16be7da
[PIR] Don't generate 'fixBy' if you don't need to (#5954)
effectfully May 6, 2024
34fa7c5
Chore: formatting, imports, pragmas. (#5965)
Unisay May 8, 2024
b6e82b6
CaseOfCase UPLC transformation tests. (#5960)
Unisay May 8, 2024
253004f
Avoid evaluating `nilCase` strictly in `matchList`, and rename the or…
zliu41 May 9, 2024
1df52aa
Improvements to plutus-metatheory site (#5959)
zeme-wana May 11, 2024
774616b
chore(deps): bump nixbuild/nix-quick-install-action from 27 to 28 (#5…
dependabot[bot] May 13, 2024
59d4b04
[Build] Remove the doctests runner of 'prettyprinter-configurable' (#…
effectfully May 14, 2024
6e3da00
Kwxm/mainnet script budgets (#5973)
May 14, 2024
5f207e5
Release 1.28.0.0 (#5975)
Unisay May 15, 2024
92d94ca
[PlutusTx] [Builtins] Split 'FromBuiltin' and 'ToBuiltin' (#5971)
effectfully May 15, 2024
d99ba33
Update README.md (#5997)
May 15, 2024
802cf4f
chore(deps): bump cachix/install-nix-action from 26 to 27 (#5999)
dependabot[bot] May 16, 2024
5ee2936
Script to prepare binary executables for uploading to the github rele…
Unisay May 17, 2024
0d8149c
Kwxm/mainnet script budgets 2 (#6057)
May 20, 2024
1529ef8
Add integerToByteString and byteStringToInteger to PlutusV2 at PV10 (…
zliu41 May 20, 2024
9326493
[Refactoring] Remove 'UnknownBuiltin' and 'UnknownBuiltinType' (#6064)
effectfully May 20, 2024
ef97537
Conditionally add 'triage' label to new issues (#6061)
zeme-wana May 21, 2024
0b670f7
Fix bug in add-triage-label.yml (#6067)
zeme-wana May 21, 2024
5eb57a5
chore(deps): bump benchmark-action/github-action-benchmark (#6058)
dependabot[bot] May 21, 2024
0ce328c
Add integerToByteString and byteStringToInteger to V2.ParamName (#6065)
zliu41 May 21, 2024
acdaeb2
Add PlutusTx Map backed by Data (#5927)
ana-pantilie May 21, 2024
794bf9d
Let nightly.yml accept hedgehog-tests input (#6062)
zeme-wana May 22, 2024
5771700
Remove obsolete defer-plugin-errors flag (#6080)
zeme-wana May 22, 2024
252b634
Add a Plutus Tx test utility package (#6086)
ana-pantilie May 23, 2024
6c6918c
[Errors] polish evaluation errors (#6043)
effectfully May 23, 2024
1afe001
[Test] Add do-notation support for 'TestNested' (#5948)
effectfully May 23, 2024
85cf1ed
Run nightly tests on plutus-benchmark (#6091)
zeme-wana May 24, 2024
d7a5c76
[Exe] Generalize 'withL' to 'withLangGeneral' (#5918)
effectfully May 29, 2024
00beff4
Kwxm/provisional conway cost model (#6087)
May 29, 2024
f63f3ca
Update issue templates (#6037)
zliu41 May 30, 2024
e675e65
Remove reference to benching.csv in plutus-core.cabal (#6149)
May 30, 2024
7b3fd3e
PlutusV3: Datum/Redeemer in ScriptContext, Datum Optional, Unified Sc…
zliu41 May 30, 2024
20e418e
Kwxm/costing/reduce CEK CPU step costs B (#6153)
May 30, 2024
cd20770
[Test] Dump UPLC for 'strictLetRec' (#5963)
effectfully May 30, 2024
7411e14
Use the most recent evaluation context for most of the benchmarks (#6…
May 30, 2024
0d26761
[Builtins] Polish handling of integral types (#6036)
effectfully May 31, 2024
f34e999
Tests for the `preserve-logging` flag. (#6162)
Unisay Jun 3, 2024
d34e4d3
Require PlutusV3 scripts to evaluate to BuiltinUnit (#6159)
zliu41 Jun 3, 2024
50c6cb0
Quadratic costing for integer division functions (#6161)
Jun 3, 2024
bbeb1a4
Fix V2's costModelParamsForTesting (#6166)
zliu41 Jun 3, 2024
c013014
Release 1.29.0.0 (#6170)
Jun 4, 2024
f601fb9
Update update-version.sh to match package names less greedily (#6174)
Jun 5, 2024
a2c6bc0
More error checking (#6179)
Jun 5, 2024
f1f2e9f
Reorganized Plutus user guide on the Docusaurus platform initial depl…
joseph-fajen Jun 5, 2024
88ad493
Initial version of new combined-haddock.yml workflow (#6182)
zeme-wana Jun 6, 2024
a43d8f9
[Builtins] Make 'BuiltinSuccess' the first constructor (#5885)
effectfully Jun 6, 2024
1848101
[PlutusLedgerApi] [Refactoring] Polish imports and exports (#6178)
effectfully Jun 6, 2024
3656505
Adding link to Haddock documentation to index.md (#6187)
joseph-fajen Jun 6, 2024
4d68254
removing outdated and incorrect content from the Plutus platform page…
joseph-fajen Jun 7, 2024
3f2e83b
Add `Data.Value` to `PlutusLedgerAPI` (#6143)
ana-pantilie Jun 7, 2024
c9b77f5
added the term Haddock where the public Plutus code libraries are men…
joseph-fajen Jun 7, 2024
be0aa25
Refactored Serialise/Flat-Via. Fixes #6083 (#6144)
bezirg Jun 8, 2024
37e681c
Add Redeemer to V3 ScriptContext Pretty instance (#6191)
ana-pantilie Jun 8, 2024
f6b9bdc
Logical operations (#5970)
kozross Jun 9, 2024
811f9fc
Combined Haddock Generation (#6146)
zeme-wana Jun 10, 2024
5894525
Run nightly tests on plutus-shared instead of plutus-benchmark (#6195)
zeme-wana Jun 10, 2024
a9a8315
Run combined-haddock.yml workflow on plutus-shared instead of plutus-…
zeme-wana Jun 10, 2024
7b70ab0
Fix combined_haddock.sh script (#6199)
zeme-wana Jun 10, 2024
8a0dacd
[Test] [Builtins] Add golden tests with unlifting errors (#6189)
effectfully Jun 10, 2024
c8450b5
Changed the term "Documentation" to "User guide" in the upper left ar…
joseph-fajen Jun 10, 2024
eed1426
Update Alert Message in longitudinal-benchmark.yml (#6201)
zeme-wana Jun 11, 2024
69eff87
[Test] Add missing bitwise builtins golden files (#6204)
effectfully Jun 11, 2024
6910d70
[Errors] Preserve operational unlifting errors (#6181)
effectfully Jun 12, 2024
56c90bf
Docs raise visibility code libraries (#6203)
joseph-fajen Jun 12, 2024
7d6dbc1
[Test] [Builtin] Polish 'MakeRead' tests (#6202)
effectfully Jun 12, 2024
294eaca
Remove AssocMap comparison instances (#6173)
ana-pantilie Jun 13, 2024
4ea8b3d
Update README.adoc (#6206)
joseph-fajen Jun 13, 2024
3b20c63
Remove PyF as it depends on GHC and causes depenecy conflicts downstr…
Unisay Jun 13, 2024
2ec9bf3
Bitwise operations (#6090)
kozross Jun 13, 2024
62ba600
Reduce coverage limits for signature verification tests (#6209)
Jun 13, 2024
72fa971
moved the Getting Started page to immediately follow the Introduction…
joseph-fajen Jun 14, 2024
9e3147c
Haskell Eq for AssocMap (#6213)
ana-pantilie Jun 14, 2024
5dffbd7
Shorten some filenames in the conformance tests (#6214)
Jun 14, 2024
3a36126
MK-5422 move getting started page fixing link (#6215)
joseph-fajen Jun 14, 2024
cc05625
[Evaluation] Move stuff under `enterComputeCek` (#6156)
effectfully Jun 14, 2024
bc8c3a7
Release 1.30.0.0 (#6216)
Unisay Jun 17, 2024
623c715
plutus-ir: fix redundant imports (#6218)
disassembler Jun 18, 2024
23edce1
Fix incorrect Note reference (#6217)
Jun 18, 2024
cc12361
Add documentation to `Data.Value` (#6220)
ana-pantilie Jun 18, 2024
a94bffd
[Builtins] Replace 'EvaluationResult' with 'BuiltinResult' (#5926)
effectfully Jun 18, 2024
7dbbd7f
New `./scripts/combined-haddock.sh` (#6205)
zeme-wana Jun 19, 2024
8c17ae4
Add workflow for publishing Agda Metatheory site (#6223)
zeme-wana Jun 20, 2024
1091562
Fixes to `metatheory-site.yml` workflow (#6228)
zeme-wana Jun 20, 2024
f9dfec2
Final changes to `metatheory-site.yml` workflow (#6229)
zeme-wana Jun 21, 2024
c33af07
Update RELEASE.adoc with instructions to delete unused branches and t…
zeme-wana Jun 21, 2024
151887d
Complete Migration from RDT to Docusaurus (#6227)
zeme-wana Jun 21, 2024
af578b5
Fix broken links in docusaurus docs (#6232)
zeme-wana Jun 21, 2024
8845e12
Add flake.nix for doc/docusaurus (#6233)
zeme-wana Jun 21, 2024
b9ad1dd
making a spelling correction on the doc/docusaurus README file (#6235)
joseph-fajen Jun 21, 2024
3ab37c5
[Builtins] Remove 'Emitter' and 'MonadEmitter' (#6224)
effectfully Jun 22, 2024
45ab436
Refactor GitHub Workflows (#6124)
zeme-wana Jun 24, 2024
84ad029
Fix & simplify SOP encoding example comment (#6231)
klntsky Jun 24, 2024
8f3c74f
Update github-action-benchmark version (#6238)
zeme-wana Jun 25, 2024
6357d23
Make it build with ghc 9.10 (#6079)
erikd Jun 25, 2024
6900c42
Update version of github-action-benchmark to v1.20.3 (#6240)
zeme-wana Jun 25, 2024
5579d34
Add workflows to check broken links and deploy papers to GH Pages (#6…
zeme-wana Jun 26, 2024
d3a42f2
Publish papers and specs on push to master only (#6246)
zeme-wana Jun 26, 2024
89a8aa1
Cabal project to compile docusaurus examples. (#6239)
Unisay Jun 26, 2024
dcd6f5d
Added cardano-constitution package (#6234)
bezirg Jun 26, 2024
b63c544
[Test] Turn off CSE for problematic tests (#6249)
effectfully Jun 26, 2024
91b4ed6
[Test] Turn off CSE for the 'patternMatching' test (#6251)
effectfully Jun 27, 2024
a156996
[Optimization] Remove case-of-case (#6248)
effectfully Jun 27, 2024
30402a4
Spec that verifies various script sizes (#6247)
Unisay Jun 27, 2024
e8f9389
Add cardano-constitution-tests and slack-message-broker workflows (#6…
zeme-wana Jun 27, 2024
3cdfbca
Updates to slack-message-broker.yml (#6258)
zeme-wana Jun 27, 2024
ed71a3d
Update slackapi/slack-github-action version -> v1.26.0 (#6259)
zeme-wana Jun 27, 2024
3df47ef
Improve messages in slack-message-broker.yml (#6260)
zeme-wana Jun 27, 2024
29eabaf
Fix error message in slack-message-broker.yml (#6261)
zeme-wana Jun 27, 2024
e3c3fd2
Fix another error in slack-message-broker.yml (#6262)
zeme-wana Jun 27, 2024
d0d77dc
Fix "un-rolling" a list type. (#6165)
Unisay Jun 28, 2024
115c3df
constitution: Add executable that creates json envelope (#6267)
bezirg Jun 28, 2024
c74136f
Fix bug in ./script/combined-haddock.sh (#6263)
zeme-wana Jul 1, 2024
b34d6ca
Update baseUrl in docusaurus.config.ts (#6275)
zeme-wana Jul 2, 2024
cabfc01
Improvements to haddock-site.yml (support auto-publish on push to mas…
zeme-wana Jul 2, 2024
cb791cd
Better messages in slack-message-broker.yml (#6280)
zeme-wana Jul 2, 2024
f616b87
Remove --ignore-url's from linkchecker step in combined-haddock.sh (#…
zeme-wana Jul 2, 2024
32a7336
Add cabal update step in combined-haddock.sh (#6283)
zeme-wana Jul 4, 2024
e5c0e76
Fix CsvTable.tsx and LiteralInclde.tsx in docusaurus (#6282)
zeme-wana Jul 4, 2024
7a24d97
Fix haddock documentation for cardano-constitution (#6284)
zeme-wana Jul 5, 2024
3f60557
Stronger docusaurus builds and general QOL improvements (#6287)
zeme-wana Jul 5, 2024
db89d22
Move package-lock.json from top-level to scripts/blueprints (#6289)
zeme-wana Jul 5, 2024
ee7de68
Fix editUrl in docusaurus.config.ts (#6291)
zeme-wana Jul 6, 2024
79fc117
chore(deps): bump JamesIves/github-pages-deploy-action (#6292)
dependabot[bot] Jul 8, 2024
317b63d
Fix typos (#6288)
omahs Jul 8, 2024
92f390c
Detect broken links for haddock,metatheory,docusaurus + local repo fi…
zeme-wana Jul 8, 2024
c1b9208
Fix broken linkchecker workflows (#6295)
zeme-wana Jul 8, 2024
db5cabb
Add .github/linkchecker/action.yml
zeme-wana Jul 9, 2024
55861af
Add support for ghc910 to hydraJobs (#6293)
zeme-wana Jul 9, 2024
ceb91aa
Disable linkchecker on live sites (#6298)
zeme-wana Jul 9, 2024
42d08e0
[Bug] Fix 'isNormalType' and add 'prop_normalizedTypeIsNormal' (#6272)
effectfully Jul 10, 2024
8ec1b64
Analyse script events supports PlutusLedgerLanguage V3 (#6300)
Unisay Jul 11, 2024
51ae3da
fix: parameter 33 should be a Rational (#6302)
RSoulatIOHK Jul 11, 2024
19f192d
Address guardrail script audit comments (#6305)
zliu41 Jul 12, 2024
0c02489
All names are printed with their unique values by default. (#5972)
Unisay Jul 12, 2024
5c06051
fix: types in defaultConstitution (#6307)
RSoulatIOHK Jul 17, 2024
b49bd63
Fix overflow bug in shiftByteString, rotateByteString, add tests to e…
kozross Jul 18, 2024
de7339b
Release 1.31.0.0 (#6312)
Unisay Jul 18, 2024
903e383
Re-export bitwise builtins from PlutusTx.Prelude (#6313)
kozross Jul 18, 2024
d89a339
[Costing] Increase the cost of constructors of '[]' (#6285)
effectfully Jul 18, 2024
0da4c4b
Change writeBits to take changelists as two separate lists (#6317)
kozross Jul 19, 2024
514d521
[Costing] Remove the 'ExMemoryUsage' instance for 'SomeTypeIn' (#6318)
effectfully Jul 19, 2024
db11987
feat: New version of VT-CC-01 (#6320)
RSoulatIOHK Jul 22, 2024
8c7a5f6
[Test] Make tests take reasonable time (#6286)
effectfully Jul 23, 2024
65f6714
fix: haddock error (#6323)
Unisay Jul 23, 2024
3461df2
Reverse hunk test_multiSplitSound (#6324)
bezirg Jul 23, 2024
39ae101
Kwxm/costing/bitwise 4 (#6301)
Jul 24, 2024
7f02fab
8-queens using bitwise primops benchmark (#6311)
kozross Jul 25, 2024
d510d24
[Plinth] [Builtins] Fix 'writeBits' (#6329)
effectfully Jul 25, 2024
bfac69f
[Plinth] Ban using 'toBuiltin' and 'fromBuiltin' (#6342)
effectfully Jul 26, 2024
5571f53
Kwxm/bitwise/enable nqueens benchmark (#6343)
Jul 26, 2024
c7eb24c
[plc] Support for `Natural` numbers in the default universe, backed b…
bezirg Jul 26, 2024
f74023e
nothunks ^>= 0.2 (#6349)
Unisay Jul 27, 2024
613ab5f
Make NumBytesCostedAsNumWords use Integer instead of Int (#6350)
Jul 29, 2024
ffe41b8
[Benchmark] Reduce the number of benchmarks (#6328)
effectfully Jul 30, 2024
ed76af5
[Test] Improve distribution of generated integers (#6315)
effectfully Jul 31, 2024
a4b0f43
[Plinth] [Builtins] Add a general 'mkNil' (#6347)
effectfully Jul 31, 2024
88c7e23
[Refactoring] Use 'KnownBuiltinTypeIn' instead of 'HasConstant' consi…
effectfully Aug 1, 2024
d3cf117
Restore auto generation of compiler option table (#6373)
zliu41 Aug 2, 2024
36311fe
Add the bitwise builtins to the metatheory (#6368)
Aug 5, 2024
5947b18
Restore CI checks for doc site code (#6376)
zliu41 Aug 5, 2024
e90e9f0
andByteString conformance cases (#6356)
kozross Aug 6, 2024
cd73651
Conformance cases for complementByteString (#6359)
kozross Aug 6, 2024
966b420
Conformance for orByteString (#6357)
kozross Aug 6, 2024
922c9c1
Conformance cases for readBit (#6360)
kozross Aug 6, 2024
0b6a695
Conformance for shiftByteString (#6363)
kozross Aug 6, 2024
8dcfa54
Conformance for findFirstSetBit (#6366)
kozross Aug 6, 2024
3d489da
Conformance for xorByteString (#6358)
kozross Aug 6, 2024
51a9f16
Conformance for countSetBits (#6365)
kozross Aug 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
PLT-8171: Combine PIR, PLC, and UPLC into a single executable (#5699)
Acked-by: Nikolaos Bezirgiannis <bezirg@users.noreply.github.com>

Co-authored-by: Nikolaos Bezirgiannis <bezirg@users.noreply.github.com>
  • Loading branch information
bezirg and bezirg authored Apr 21, 2024
commit 9d0a9cf5bffc78875c4b719d3a60aee4031a2e78
2 changes: 1 addition & 1 deletion nix/outputs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ in
hydraJobs.musl64.ghc96.pir = ghc96-musl64.cabalProject.hsPkgs.plutus-core.components.exes.pir;
hydraJobs.musl64.ghc96.plc = ghc96-musl64.cabalProject.hsPkgs.plutus-core.components.exes.plc;
hydraJobs.musl64.ghc96.uplc = ghc96-musl64.cabalProject.hsPkgs.plutus-core.components.exes.uplc; # editorconfig-checker-disable-line
hydraJobs.musl64.ghc96.debugger = ghc96-musl64.cabalProject.hsPkgs.plutus-core.components.exes.debugger; # editorconfig-checker-disable-line
hydraJobs.musl64.ghc96.plutus = ghc96-musl64.cabalProject.hsPkgs.plutus-core.components.exes.plutus; # editorconfig-checker-disable-line
})

(lib.optionalAttrs (system == "aarch64-darwin")
Expand Down
2 changes: 1 addition & 1 deletion plutus-benchmark/nofib/exe/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ options = hsubparser
<> command "run-hs"
(info (RunHaskell <$> progAndArgs)
(progDesc "run the program directly as Hs"))
<> command "dump-plc"
<> command "dump-uplc"
(info (DumpPLC <$> progAndArgs)
(progDesc "print the program (applied to arguments) as Plutus Core source on standard output"))
<> command "dump-flat-named"
Expand Down
12 changes: 12 additions & 0 deletions plutus-core/changelog.d/20240421_114005_bezirg_exe_combined.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
### Removed

- Debugger executable is removed and integrated inside plutus executable.

### Added

- An experimental "plutus" tool that unifies `pir`, `plc`, `uplc`, and `debugger` executables into one.
- `Codec.CBOR.Extras` module is migrated here from `plutus-ledger-api.

### Fixed

- Restrict `eraseTerm`/`eraseProgram` to only work with `TPLC Name` input.
23 changes: 23 additions & 0 deletions plutus-core/executables/plutus/AnyProgram/Apply.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module AnyProgram.Apply
( applyProgram
) where

import AnyProgram.With
import PlutusCore qualified as PLC
import PlutusCore.Error as PLC
import PlutusIR qualified as PIR
import Types
import UntypedPlutusCore qualified as UPLC

import Control.Monad.Except

-- | Given a singleton witness and two programs of that type witness, apply them together.
applyProgram :: MonadError PLC.ApplyProgramError m
=> SLang s -> FromLang s -> FromLang s -> m (FromLang s)
applyProgram sng p1 p2 = withA @Semigroup (_sann sng) $
case sng of
SPir{} -> PIR.applyProgram p1 p2
SPlc{} -> PLC.applyProgram p1 p2
SUplc{} -> UPLC.UnrestrictedProgram <$>
UPLC.unUnrestrictedProgram p1 `UPLC.applyProgram` UPLC.unUnrestrictedProgram p2
SData{} -> error "Cannot apply to Data. This should have failed earlier during compilation."
8 changes: 8 additions & 0 deletions plutus-core/executables/plutus/AnyProgram/Bench.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module AnyProgram.Bench
( runBench
) where

import Types

runBench :: SLang s -> FromLang s -> IO ()
runBench = error "Not implemented yet"
300 changes: 300 additions & 0 deletions plutus-core/executables/plutus/AnyProgram/Compile.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,300 @@
{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE ViewPatterns #-}
module AnyProgram.Compile
( compileProgram
, toOutAnn
, plcToOutName
, uplcToOutName
, uplcToOutName'
) where

import AnyProgram.With
import GetOpt
import Types

import PlutusCore qualified as PLC
import PlutusCore.Compiler qualified as PLC
import PlutusCore.DeBruijn qualified as PLC
import PlutusCore.Default
import PlutusCore.Error as PLC
import PlutusCore.MkPlc hiding (error)
import PlutusIR qualified as PIR
import PlutusIR.Compiler qualified as PIR
import PlutusIR.TypeCheck qualified as PIR
import UntypedPlutusCore qualified as UPLC
import UntypedPlutusCore.Check.Uniques qualified as UPLC

import Control.Lens hiding ((%~))
import Control.Monad.Error.Lens
import Control.Monad.Except
import Control.Monad.Reader
import Data.Singletons.Decide
import Data.Text
import PlutusPrelude hiding ((%~))

-- Note that we use for erroring the original term's annotation
compileProgram :: (?opts :: Opts, e ~ PIR.Provenance (FromAnn (US_ann s1)),
MonadError (PIR.Error DefaultUni DefaultFun e) m)
=> SLang s1
-> SLang s2
-> FromLang s1
-> m (FromLang s2)
compileProgram = curry $ \case
-- exclude all pir-debruijn input&output combinations
----------------------------------------
(SPir SNamedDeBruijn _, _) -> throwingPIR "pir input cannot be debruijn"
(SPir SDeBruijn _, _ ) -> throwingPIR "pir input cannot be nameddebruijn"
(_, SPir SDeBruijn _) -> throwingPIR "pir out cannot be debruijn"
(_, SPir SNamedDeBruijn _) -> throwingPIR "pir out cannot be nameddebruijn"

-- self-lang to self-lang patterns
----------------------------------------
(SPir n1@SName a1, SPir n2@SName a2) ->
through (modifyError (fmap PIR.Original) . pirTypecheck a1)
-- TODO: optimise
>=> pirToOutName n1 n2
>=> toOutAnn a1 a2
(SPlc n1 a1, SPlc n2 a2) ->
through (modifyError (fmap PIR.Original . PIR.PLCError) . plcTypecheck n1 a1)
>=> plcToOutName n1 n2
>=> toOutAnn a1 a2
(SUplc n1 a1, SUplc n2 a2) ->
through (modifyError (fmap PIR.Original) . uplcTypecheck n1 a1)
>=> uplcOptimise n1
>=> uplcToOutName n1 n2
>=> toOutAnn a1 a2
-- nothing to be done; seems silly, but can be used for later changing format of Data
(SData, SData) -> pure

-- exclude other cases of Data as target
(_, SData) -> throwingPIR "Cannot compile a pir/tplc/uplc program to Data"

-- pir to plc
----------------------------------------
(SPir n1@SName a1, SPlc n2 SUnit) -> withA @Ord a1 $ withA @Pretty a1 $
-- Note: PIR.compileProgram subsumes pir typechecking
(PLC.runQuoteT . flip runReaderT compCtx . PIR.compileProgram)
>=> plcToOutName n1 n2
-- completely drop annotations for now
>=> pure . void
where
compCtx = PIR.toDefaultCompilationCtx $
unsafeFromRight @(PIR.Error DefaultUni DefaultFun ()) $
PLC.getDefTypeCheckConfig ()

-- note to self: this restriction is because of PIR.Provenance appearing in the output
(SPir _n1@SName _, SPlc _ _) -> throwingPIR "only support unit-ann output for now"

-- plc to pir (a special case of embedding, since plc is subset of pir)
----------------------------------------
(sng1@(SPlc _n1 a1), SPir n2@SName a2) ->
-- first self-"compile" to plc (just for reusing code)
compileProgram sng1 (SPlc n2 a1)
>=> pure . embedProgram
-- here we also run the pir typechecker, and pir optimiser
>=> compileProgram (SPir n2 a1) (SPir n2 a2)

-- pir to uplc
----------------------------------------
(sng1@(SPir _n1@SName a1), sng2@(SUplc n2 _a2)) ->
-- intermediate through plc==sng12
let sng12 = SPlc n2 a1
in compileProgram sng1 sng12
>=> compileProgram sng12 sng2

-- plc to uplc
----------------------------------------
(sng1@(SPlc _n1 _a1), SUplc n2 a2) ->
-- first self-"compile" to plc (just for reusing code)
compileProgram sng1 (SPlc n2 a2)
-- PLC.compileProgram subsumes uplcOptimise
>=> (PLC.runQuoteT . flip runReaderT PLC.defaultCompilationOpts .
plcToUplcViaName n2 PLC.compileProgram)
>=> pure . UPLC.UnrestrictedProgram

-- data to pir/plc/uplc

-- TODO: deduplicate if we had `withTermLikeL`
(SData, SPir _ a2) -> withA @Monoid a2 $
pure . PIR.Program mempty PLC.latestVersion . PIR.Constant mempty . someValue
(SData, SPlc _ a2) -> withA @Monoid a2 $
pure . PLC.Program mempty PLC.latestVersion . PLC.Constant mempty . someValue
(SData, SUplc _ a2) -> withA @Monoid a2 $
pure . UPLC.UnrestrictedProgram . UPLC.Program mempty PLC.latestVersion .
UPLC.Constant mempty . someValue

-- uplc to ?
(SUplc _ _, SPlc _ _) -> throwingPIR "Cannot compile uplc to tplc"
(SUplc _ _, SPir SName _) -> throwingPIR "Cannot compile uplc to pir"

embedProgram :: PLC.Program tyname name uni fun ann -> PIR.Program tyname name uni fun ann
embedProgram (PLC.Program a v t) = PIR.Program a v $ embed t

toOutAnn :: (Functor f, PIR.AsError e uni fun a, MonadError e m)
=> SAnn s1
-> SAnn s2
-> f (FromAnn s1)
-> m (f (FromAnn s2))
toOutAnn sng1 ((sng1 %~) -> Proved Refl) = pure
toOutAnn _ SUnit = pure . void
toOutAnn _ _ = throwingPIR "cannot convert annotation"

-- MAYBE: All of the following could be unified under a ProgramLike typeclass.
-- or by some singletons type-level programming

pirTypecheck
:: ( PIR.AsTypeErrorExt e DefaultUni (FromAnn a)
, PIR.AsTypeError e (PIR.Term UPLC.TyName UPLC.Name DefaultUni DefaultFun ())
DefaultUni DefaultFun (FromAnn a), MonadError e m
)
=> SAnn a
-> PIR.Program PLC.TyName PLC.Name DefaultUni DefaultFun (FromAnn a)
-> m ()
pirTypecheck sngA p = PLC.runQuoteT $ do
tcConfig <- withA @Monoid sngA $ PIR.getDefTypeCheckConfig mempty
void $ PIR.inferTypeOfProgram tcConfig p

plcToUplcViaName :: (PLC.MonadQuote m, PLC.AsFreeVariableError e, MonadError e m)
=> SNaming n
-> (PLC.Program PLC.TyName PLC.Name uni fun a -> m (UPLC.Program PLC.Name uni fun a))
-> PLC.Program (FromNameTy n) (FromName n) uni fun a
-> m (UPLC.Program (FromName n) uni fun a)
plcToUplcViaName sngN act = case sngN of
SName -> act
SNamedDeBruijn -> plcToName sngN act
>=> UPLC.progTerm UPLC.deBruijnTerm
SDeBruijn -> plcToName sngN act
>=> UPLC.progTerm UPLC.deBruijnTerm
>=> pure . UPLC.programMapNames PLC.unNameDeBruijn

plcToName :: (PLC.MonadQuote m, PLC.AsFreeVariableError e, MonadError e m)
=> SNaming n
-> (PLC.Program PLC.TyName PLC.Name uni fun a -> m x)
-> (PLC.Program (FromNameTy n) (FromName n) uni fun a -> m x)
plcToName sngN act = case sngN of
SName -> act
SNamedDeBruijn -> PLC.progTerm PLC.unDeBruijnTerm
>=> act
SDeBruijn -> pure . PLC.programMapNames PLC.fakeTyNameDeBruijn PLC.fakeNameDeBruijn
>=> plcToName SNamedDeBruijn act

uplcViaName :: (PLC.MonadQuote m, PLC.AsFreeVariableError e, MonadError e m)
=> (UPLC.Program PLC.Name uni fun a -> m (UPLC.Program PLC.Name uni fun a))
-> SNaming n
-> UPLC.Program (FromName n) uni fun a
-> m (UPLC.Program (FromName n) uni fun a)
uplcViaName act sngN = case sngN of
SName -> act
SNamedDeBruijn -> UPLC.progTerm UPLC.unDeBruijnTerm
>=> act
>=> UPLC.progTerm UPLC.deBruijnTerm
SDeBruijn -> pure . UPLC.programMapNames UPLC.fakeNameDeBruijn
>=> uplcViaName act SNamedDeBruijn
>=> pure . UPLC.programMapNames UPLC.unNameDeBruijn

plcTypecheck :: (PLC.AsTypeError
e
-- errors remain with names
(PLC.Term PLC.TyName PLC.Name DefaultUni DefaultFun ())
DefaultUni
DefaultFun
(FromAnn a)
, PLC.AsFreeVariableError e
, MonadError e m
)
=> SNaming n
-> SAnn a
-> PLC.Program (FromNameTy n) (FromName n) DefaultUni DefaultFun (FromAnn a)
-> m ()
plcTypecheck sngN sngA p = PLC.runQuoteT $ do
tcConfig <- withA @Monoid sngA $ PLC.getDefTypeCheckConfig mempty
void $ plcToName sngN (PLC.inferTypeOfProgram tcConfig) p

uplcOptimise :: (?opts :: Opts, PLC.AsFreeVariableError e, MonadError e m)
=> SNaming n1
-> UPLC.UnrestrictedProgram (FromName n1) DefaultUni DefaultFun a
-> m (UPLC.UnrestrictedProgram (FromName n1) DefaultUni DefaultFun a)
uplcOptimise =
case _optimiseLvl ?opts of
NoOptimise -> const pure -- short-circuit to avoid renaming
safeOrUnsafe ->
let sOpts = UPLC.defaultSimplifyOpts &
case safeOrUnsafe of
SafeOptimise -> set UPLC.soConservativeOpts True
UnsafeOptimise -> id
in fmap PLC.runQuoteT
. _Wrapped
. uplcViaName (UPLC.simplifyProgram sOpts def)


-- | We do not have a typechecker for uplc, but we could pretend that scopecheck is a "typechecker"
uplcTypecheck :: forall sN sA uni fun e m
. (PLC.AsFreeVariableError e, PLC.AsUniqueError e (FromAnn sA), MonadError e m)
=> SNaming sN
-> SAnn sA
-> UPLC.UnrestrictedProgram (FromName sN) uni fun (FromAnn sA)
-> m ()
uplcTypecheck sngN sngA ast = case sngN of
SName -> withA @Ord sngA $ UPLC.checkProgram (const True) (ast ^. _Wrapped)
-- TODO: deduplicate
SDeBruijn -> UPLC.checkScope (ast ^. _Wrapped. UPLC.progTerm)
SNamedDeBruijn -> UPLC.checkScope (ast ^. _Wrapped. UPLC.progTerm)


-- | Placed here just for uniformity, not really needed
pirToOutName :: (PIR.AsError e uni fun a, MonadError e m)
=> SNaming s1
-> SNaming s2
-> PIR.Program (FromNameTy s1) (FromName s1) uni fun ann
-> m (PIR.Program (FromNameTy s2) (FromName s2) uni fun ann)
pirToOutName sng1 ((sng1 %~) -> Proved Refl) = pure
pirToOutName _ _ = throwingPIR "we do not support name conversion for PIR atm"

plcToOutName :: (PLC.AsFreeVariableError e, MonadError e m)
=> SNaming s1
-> SNaming s2
-> PLC.Program (FromNameTy s1) (FromName s1) uni fun ann
-> m (PLC.Program (FromNameTy s2) (FromName s2) uni fun ann)
plcToOutName sng1 ((sng1 %~) -> Proved Refl) = pure
plcToOutName SName SNamedDeBruijn = PLC.progTerm PLC.deBruijnTerm
plcToOutName SNamedDeBruijn SName = PLC.runQuoteT . PLC.progTerm PLC.unDeBruijnTerm
plcToOutName SDeBruijn SNamedDeBruijn =
pure . PLC.programMapNames PLC.fakeTyNameDeBruijn PLC.fakeNameDeBruijn
plcToOutName SNamedDeBruijn SDeBruijn =
pure . PLC.programMapNames PLC.unNameTyDeBruijn PLC.unNameDeBruijn
plcToOutName SName SDeBruijn = plcToOutName SName SNamedDeBruijn
>=> plcToOutName SNamedDeBruijn SDeBruijn
plcToOutName SDeBruijn SName = plcToOutName SDeBruijn SNamedDeBruijn
>=> plcToOutName SNamedDeBruijn SName
plcToOutName _ _ = error "this is complete, but i don't want to use -fno-warn-incomplete-patterns"

uplcToOutName :: (PLC.AsFreeVariableError e, MonadError e m)
=> SNaming s1
-> SNaming s2
-> UPLC.UnrestrictedProgram (FromName s1) uni fun ann
-> m (UPLC.UnrestrictedProgram (FromName s2) uni fun ann)
uplcToOutName = fmap _Wrapped . uplcToOutName'

uplcToOutName' :: (PLC.AsFreeVariableError e, MonadError e m)
=> SNaming s1
-> SNaming s2
-> UPLC.Program (FromName s1) uni fun ann
-> m (UPLC.Program (FromName s2) uni fun ann)
uplcToOutName' sng1 ((sng1 %~) -> Proved Refl) = pure
uplcToOutName' SName SNamedDeBruijn = UPLC.progTerm UPLC.deBruijnTerm
uplcToOutName' SNamedDeBruijn SName = PLC.runQuoteT . UPLC.progTerm UPLC.unDeBruijnTerm
uplcToOutName' SDeBruijn SNamedDeBruijn = pure . UPLC.programMapNames UPLC.fakeNameDeBruijn
uplcToOutName' SNamedDeBruijn SDeBruijn = pure . UPLC.programMapNames UPLC.unNameDeBruijn
uplcToOutName' SName SDeBruijn = uplcToOutName' SName SNamedDeBruijn
>=> uplcToOutName' SNamedDeBruijn SDeBruijn
uplcToOutName' SDeBruijn SName = uplcToOutName' SDeBruijn SNamedDeBruijn
>=> uplcToOutName' SNamedDeBruijn SName
uplcToOutName' _ _ = error "this is complete, but i don't want to use -fno-warn-incomplete-patterns"

-- TODO: use better, more detailed erroring
throwingPIR :: (PIR.AsError e uni fun a, MonadError e m)
=> Text -> b -> m c
throwingPIR = const . throwing PIR._Error . PIR.OptionsError
17 changes: 17 additions & 0 deletions plutus-core/executables/plutus/AnyProgram/Debug.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{-# LANGUAGE ImplicitParams #-}
{-# LANGUAGE LambdaCase #-}
module AnyProgram.Debug
( runDebug
) where

import Common
import Debugger.TUI.Main qualified
import GetOpt
import Types
import UntypedPlutusCore as UPLC

runDebug :: (?opts :: Opts)
=> SLang s -> FromLang s -> IO ()
runDebug = \case
SUplc sn sa -> Debugger.TUI.Main.main sn sa . UPLC.unUnrestrictedProgram
_ -> const $ failE "Debugging pir/tplc program is not available."
Loading
Loading