Skip to content

Commit

Permalink
PLT-1566 Add cost semantics for basic builtins (#5679)
Browse files Browse the repository at this point in the history
Cost semantics in the metatheory for the following builtin functions, and their corresponding costing models:
addInteger
subtractInteger
multiplyInteger
divideInteger
quotientInteger
remainderInteger
modInteger
equalsInteger
lessThanInteger
lessThanEqualsInteger
ifThenElse
  • Loading branch information
mjaskelioff authored Dec 13, 2023
1 parent f4f4734 commit f03ef31
Show file tree
Hide file tree
Showing 6 changed files with 395 additions and 101 deletions.
6 changes: 6 additions & 0 deletions plutus-metatheory/plutus-metatheory.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ library
, composition-prelude
, cryptonite
, extra
, ghc-prim
, ieee754
, megaparsec
, memory
Expand All @@ -66,6 +67,9 @@ library
, text
, transformers

if impl(ghc <9.0)
build-depends: integer-gmp

exposed-modules:
Opts
Raw
Expand Down Expand Up @@ -127,6 +131,7 @@ library
MAlonzo.Code.Category.Monad.Indexed
MAlonzo.Code.Check
MAlonzo.Code.Cost
MAlonzo.Code.Cost.Base
MAlonzo.Code.Data.Bool.Base
MAlonzo.Code.Data.Bool.Properties
MAlonzo.Code.Data.Char.Base
Expand Down Expand Up @@ -349,6 +354,7 @@ library
MAlonzo.Code.Category.Monad.Indexed
MAlonzo.Code.Check
MAlonzo.Code.Cost
MAlonzo.Code.Cost.Base
MAlonzo.Code.Data.Bool.Base
MAlonzo.Code.Data.Bool.Properties
MAlonzo.Code.Data.Char.Base
Expand Down
6 changes: 5 additions & 1 deletion plutus-metatheory/src/Builtin.lagda.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ open import Data.Bool using (Bool;true;false)
open import Data.List using (List)
open import Data.Nat using (ℕ;suc)
open import Data.Fin using (Fin) renaming (zero to Z; suc to S)
open import Data.List.NonEmpty using (List⁺;_∷⁺_;[_];reverse)
open import Data.List.NonEmpty using (List⁺;_∷⁺_;[_];reverse;length)
open import Data.Product using (Σ;proj₁;proj₂)
open import Relation.Binary using (DecidableEquality)
Expand Down Expand Up @@ -298,6 +298,10 @@ hence need to be embedded into `n⋆ / n♯ ⊢⋆` using the postfix constructo

open SugaredSignature using (signature) public

-- The arity of a builtin, according to its signature.
arity : Builtin → ℕ
arity b = length (Sig.args (signature b))

```
## GHC Mappings
Expand Down
Loading

0 comments on commit f03ef31

Please sign in to comment.