Skip to content

Commit

Permalink
Merge branch 'master' into rsoeldner/nix-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
enobayram committed Jul 20, 2023
2 parents 04ddfce + 570d148 commit ec78121
Show file tree
Hide file tree
Showing 103 changed files with 6,660 additions and 2,966 deletions.
18 changes: 6 additions & 12 deletions .github/workflows/applications.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,17 @@ jobs:
strategy:
fail-fast: false
matrix:
ghc: ['8.10.7']
cabal: ['3.8']
ghc: ['9.6']
cabal: ['3.10']
os: ['ubuntu-20.04', 'ubuntu-22.04', 'macOS-latest']
cabalcache: ['true']
flags: ['+build-tool']
include:
- os: 'ubuntu-22.04'
ghc: '8.10.7'
cabal: '3.8'
ghc: '9.6'
cabal: '3.10'
cabalcache: 'true'
flags: '-build-tool'
- os: 'ubuntu-22.04'
ghc: '9.0.2'
cabal: '3.8'
cabalcache: 'true'
flags: '+build-tool'

env:
AWS_ACCESS_KEY_ID: ${{ secrets.kadena_cabal_cache_aws_access_key_id }}
Expand Down Expand Up @@ -98,14 +93,13 @@ jobs:
benchmarks: True
documentation: False
optimization: 1
flags: ${{ matrix.flags }}
flags: ${{ matrix.flags }} +cryptonite-ed25519
EOF
- name: Extend cabal.project.local for GHC-9.0.2
if: "startsWith(matrix.ghc, '9')"
shell: bash
run: |
cat >> cabal.project.local <<EOF
allow-newer: hashable:*
package pact
ghc-options: -Wwarn -Wunused-packages
EOF
Expand Down Expand Up @@ -207,7 +201,7 @@ jobs:
fail-fast: false
matrix:
include:
- ghc: "8.10.7"
- ghc: "9.6"
os: "ubuntu-20.04"
env:
OS: ${{ matrix.os }}
Expand Down
128 changes: 128 additions & 0 deletions bench/PactJson.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
{-# LANGUAGE CPP #-}
{-# LANGUAGE DeriveFoldable #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}

{-# OPTIONS_GHC -Wno-orphans #-}

-- |
-- Module: PactJson
-- Copyright: Copyright © 2023 Kadena LLC.
-- License: MIT
-- Maintainer: Lars Kuhtz <[email protected]>
-- Stability: experimental
--
-- benchmarks for pact-json
--
module Main
( main
) where

import Bound

import Criterion
import Criterion.Main

import qualified Data.Aeson as A
import qualified Data.ByteString.Lazy as BL

import qualified Pact.JSON.Encode as J

import System.IO.Unsafe

import Test.QuickCheck

-- internal modules
import Pact.Types.Command
import Pact.Types.Names
import Pact.Types.RowData
import Pact.Types.SPV
import Pact.Types.Term
import Pact.Types.Term.Arbitrary ()


-- -------------------------------------------------------------------------- --
-- Main

main :: IO ()
main = defaultMain [benchmarks]

-- -------------------------------------------------------------------------- --
-- Benchmarks

benchmarks :: Benchmark
benchmarks = bgroup "JsonEncoding"
[ bgroup "pact"
[ group "module" pactModule
, group "RowData" rowData
, group "CommandResult" commandResult
, group "ContProof" contProof
]
]

group
:: J.Encode a
=> String
-> a
-> Benchmark
group l a = bgroup l
[ bench_encode a
]

-- -------------------------------------------------------------------------- --
-- Benchmark Functions

bench_encode :: J.Encode a => a -> Benchmark
bench_encode a = bench "bench_encode" $ nf run_encode a

run_encode :: J.Encode a => a -> BL.ByteString
run_encode = J.encode
{-# NOINLINE run_encode #-}

-- -------------------------------------------------------------------------- --
-- Orphans

deriving newtype instance A.ToJSON a => A.ToJSON (J.Aeson a)
deriving newtype instance A.FromJSON a => A.FromJSON (J.Aeson a)
deriving newtype instance Show a => Show (J.Aeson a)
deriving newtype instance Eq a => Eq (J.Aeson a)
deriving newtype instance Arbitrary a => Arbitrary (J.Aeson a)
deriving instance Functor J.Aeson
deriving instance Foldable J.Aeson
deriving instance Traversable J.Aeson

instance J.Encode [J.Aeson ()] where
build a = J.build $ J.Array a

instance J.Encode [Var Int [J.Aeson ()]] where
build a = J.build $ J.Array a

-- -------------------------------------------------------------------------- --
-- Benchmark Data
--

type A = J.Aeson

pactModule :: Module Name
pactModule = unsafeDupablePerformIO $ generate $ arbitrary
{-# NOINLINE pactModule #-}

rowData :: RowData
rowData = unsafeDupablePerformIO $ generate $ arbitrary
{-# NOINLINE rowData #-}

commandResult :: CommandResult (A ())
commandResult = unsafeDupablePerformIO $ generate $ arbitrary
{-# NOINLINE commandResult #-}

contProof :: ContProof
contProof = unsafeDupablePerformIO $ generate $ arbitrary
{-# NOINLINE contProof #-}

49 changes: 43 additions & 6 deletions cabal.project
Original file line number Diff line number Diff line change
@@ -1,18 +1,55 @@
packages: .

allow-older: libBF:hashable

-- temporary upper bounds
constraints: sbv <10

-- these upper bounds are required in order to not break payload validation in chainweb
constraints: aeson <2
constraints: base16-bytestring <1
constraints: base64-bytestring <1.1
constraints: hashable <1.3.1
constraints: prettyprinter <1.6.1
constraints: unordered-containers <0.2.16
constraints: base64-bytestring <1.1

allow-newer: base64-bytestring:*
allow-newer: base16-bytestring:*
allow-newer: prettyprinter:*

-- test upper bounds
constraints: hspec-golden <0.2,

-- The following fork provides trifecta-2.`1.1.1 which is compatible with
-- hashable >=1.4 and prettyprinter <1.7
--
-- trifeta >=2.1.2 requires a prettyprinter >=1.7, which isn't supported by
-- pact (because it would break mainnet replays). trifecta ==2.1.1 does not
-- support hashable >=1.4.
--
source-repository-package
type: git
tag: f991ffb74a1a1ab86f14e751d7c4f4ba549785b3
location: https://github.com/hackage-package-forks/trifecta
--sha256: sha256-m+IplwZ9DxJt6Mzkq961BzgiboHJul6w1uwDUqXnljo=

source-repository-package
type: git
tag: e43073d0b8d89d9b300980913b842f4be339846d
location: https://github.com/kadena-io/pact-json
--sha256: sha256-ZWbAId0JBaxDsYhwcYUyw04sjYstXyosSCenzOvUxsQ=

-- Required for GHC-9.6

allow-newer: *:template-haskell
allow-newer: *:base

-- Patch merged into master (upcoming verison 10.0). We are currently using 9.2
source-repository-package
type: git
tag: b66e3a04c20f753213fe7e5115a95b3fe34109f9
location: https://github.com/larskuhtz/sbv
--sha256: sha256-NQ00KGhu4IWeAry0r6m6FR/iCu/XboWtjOhbU+gtijU=

-- Servant is notoriously forcing outdated upper bounds onto its users.
-- It is usually safe to just ignore those.
--
allow-newer: servant-server:*
allow-newer: servant-client-core:*
allow-newer: servant-client:*
allow-newer: servant:*
22 changes: 21 additions & 1 deletion executables/ReplGhcjs.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,19 @@

module Main where

import Control.Monad.State.Strict

import Data.Aeson hiding ((.=),Object)

import GHCJS.Marshal
import GHCJS.Foreign.Callback
import GHCJS.Types

import Prelude hiding (log)

import Pact.Repl (evalString)
import qualified Pact.JSON.Encode as J
import Pact.Repl
import Pact.Repl.Types

foreign import javascript unsafe "evalCmd = $1"
evalCmd :: Callback (JSVal -> JSVal -> IO JSVal) -> IO ()
Expand All @@ -23,3 +30,16 @@ main = do
r <- evalString log' cmd'
toJSVal_aeson r
evalCmd callback

-- -------------------------------------------------------------------------- --
-- Utils

evalString :: Bool -> String -> IO Value
evalString showLog cmd = do
(er,s) <- initReplState StringEval Nothing >>= runStateT (evalRepl' cmd)
return $ J.object $ case (showLog,er) of
(False,Right v) -> [ "success" J..= v]
(True,Right _) -> ["success" J..= trim (_rOut s) ]
(False,Left e) -> ["failure" J..= e ]
(True,Left e) -> ["failure" J..= (_rOut s ++ e) ]

Loading

0 comments on commit ec78121

Please sign in to comment.