Skip to content

Commit

Permalink
SCP-2435: Use strict environments and make many uses of them strict (I…
Browse files Browse the repository at this point in the history
…ntersectMBO#3434)

Making the parameter patterns strict is crucial otherwise this is a
regression! Making the remaining occurence of `CekValEnv` strict is also
a regression, perhaps unsurprisingly.
  • Loading branch information
michaelpj authored Jun 26, 2021
1 parent 0a2333b commit ea0ca4e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion plutus-core/plutus-core/src/PlutusCore/Name.hs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import PlutusCore.Pretty.ConfigName

import Control.Lens
import Data.Hashable
import qualified Data.IntMap as IM
import qualified Data.IntMap.Strict as IM
import qualified Data.Text as T
import Instances.TH.Lift ()
import Language.Haskell.TH.Syntax (Lift)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,8 @@ instance Show (BuiltinRuntime (CekValue uni fun)) where
data CekValue uni fun =
-- This bang gave us a 1-2% speed-up at the time of writing.
VCon !(Some (ValueOf uni))
| VDelay (Term Name uni fun ()) (CekValEnv uni fun)
| VLamAbs Name (Term Name uni fun ()) (CekValEnv uni fun)
| VDelay (Term Name uni fun ()) !(CekValEnv uni fun)
| VLamAbs Name (Term Name uni fun ()) !(CekValEnv uni fun)
| VBuiltin -- A partial builtin application, accumulating arguments for eventual full application.
!fun -- So that we know, for what builtin we're calculating the cost.
-- TODO: any chance we could sneak this into 'BuiltinRuntime'
Expand Down Expand Up @@ -480,7 +480,7 @@ emitCek str =
-- | Instantiate all the free variables of a term by looking them up in an environment.
-- Mutually recursive with dischargeCekVal.
dischargeCekValEnv :: CekValEnv uni fun -> Term Name uni fun () -> Term Name uni fun ()
dischargeCekValEnv valEnv =
dischargeCekValEnv !valEnv =
-- We recursively discharge the environments of Cek values, but we will gradually end up doing
-- this to terms which have no free variables remaining, at which point we won't call this
-- substitution function any more and so we will terminate.
Expand Down Expand Up @@ -522,8 +522,8 @@ Morally, this is a stack of frames, but we use the "intrusive list" representati
we can match on context and the top frame in a single, strict pattern match.
-}
data Context uni fun
= FrameApplyFun (CekValue uni fun) !(Context uni fun) -- ^ @[V _]@
| FrameApplyArg (CekValEnv uni fun) (Term Name uni fun ()) !(Context uni fun) -- ^ @[_ N]@
= FrameApplyFun !(CekValue uni fun) !(Context uni fun) -- ^ @[V _]@
| FrameApplyArg !(CekValEnv uni fun) (Term Name uni fun ()) !(Context uni fun) -- ^ @[_ N]@
| FrameForce !(Context uni fun) -- ^ @(force _)@
| NoFrame
deriving (Show)
Expand Down Expand Up @@ -619,36 +619,36 @@ enterComputeCek = computeCek (toWordArray 0) where
-> Term Name uni fun ()
-> CekM uni fun s (Term Name uni fun ())
-- s ; ρ ▻ {L A} ↦ s , {_ A} ; ρ ▻ L
computeCek !unbudgetedSteps !ctx env (Var _ varName) = do
computeCek !unbudgetedSteps !ctx !env (Var _ varName) = do
!unbudgetedSteps' <- stepAndMaybeSpend BVar unbudgetedSteps
val <- lookupVarName varName env
returnCek unbudgetedSteps' ctx val
computeCek !unbudgetedSteps !ctx _ (Constant _ val) = do
computeCek !unbudgetedSteps !ctx !_ (Constant _ val) = do
!unbudgetedSteps' <- stepAndMaybeSpend BConst unbudgetedSteps
returnCek unbudgetedSteps' ctx (VCon val)
computeCek !unbudgetedSteps !ctx env (LamAbs _ name body) = do
computeCek !unbudgetedSteps !ctx !env (LamAbs _ name body) = do
!unbudgetedSteps' <- stepAndMaybeSpend BLamAbs unbudgetedSteps
returnCek unbudgetedSteps' ctx (VLamAbs name body env)
computeCek !unbudgetedSteps !ctx env (Delay _ body) = do
computeCek !unbudgetedSteps !ctx !env (Delay _ body) = do
!unbudgetedSteps' <- stepAndMaybeSpend BDelay unbudgetedSteps
returnCek unbudgetedSteps' ctx (VDelay body env)
-- s ; ρ ▻ lam x L ↦ s ◅ lam x (L , ρ)
computeCek !unbudgetedSteps !ctx env (Force _ body) = do
computeCek !unbudgetedSteps !ctx !env (Force _ body) = do
!unbudgetedSteps' <- stepAndMaybeSpend BForce unbudgetedSteps
computeCek unbudgetedSteps' (FrameForce ctx) env body
-- s ; ρ ▻ [L M] ↦ s , [_ (M,ρ)] ; ρ ▻ L
computeCek !unbudgetedSteps !ctx env (Apply _ fun arg) = do
computeCek !unbudgetedSteps !ctx !env (Apply _ fun arg) = do
!unbudgetedSteps' <- stepAndMaybeSpend BApply unbudgetedSteps
computeCek unbudgetedSteps' (FrameApplyArg env arg ctx) env fun
-- s ; ρ ▻ abs α L ↦ s ◅ abs α (L , ρ)
-- s ; ρ ▻ con c ↦ s ◅ con c
-- s ; ρ ▻ builtin bn ↦ s ◅ builtin bn arity arity [] [] ρ
computeCek !unbudgetedSteps !ctx env term@(Builtin _ bn) = do
computeCek !unbudgetedSteps !ctx !env term@(Builtin _ bn) = do
!unbudgetedSteps' <- stepAndMaybeSpend BBuiltin unbudgetedSteps
meaning <- lookupBuiltin bn ?cekRuntime
returnCek unbudgetedSteps' ctx (VBuiltin bn term env meaning)
-- s ; ρ ▻ error A ↦ <> A
computeCek !_ !_ _ (Error _) =
computeCek !_ !_ !_ (Error _) =
throwing_ _EvaluationFailure

{- | The returning phase of the CEK machine.
Expand Down

0 comments on commit ea0ca4e

Please sign in to comment.