diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/EvaluatorV1.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/EvaluatorV1.scala index 41eba9da3a..386388a194 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/EvaluatorV1.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/EvaluatorV1.scala @@ -8,7 +8,6 @@ import com.wavesplatform.lang.v1.compiler.Terms.* import com.wavesplatform.lang.v1.compiler.Types.{CASETYPEREF, NOTHING} import com.wavesplatform.lang.v1.evaluator.ContextfulNativeFunction.{Extended, Simple} import com.wavesplatform.lang.v1.evaluator.ctx.* -import com.wavesplatform.lang.v1.evaluator.ctx.EnabledLogEvaluationContext.Lenses import com.wavesplatform.lang.v1.task.imports.* import com.wavesplatform.lang.v1.traits.Environment import com.wavesplatform.lang.* @@ -30,8 +29,6 @@ object EvaluatorV1 { } class EvaluatorV1[F[_]: Monad, C[_[_]]](implicit ev: Monad[EvalF[F, *]], ev2: Monad[CoevalF[F, *]]) { - private val lenses = new Lenses[F, C] - import lenses.* private def evalLetBlock(let: LET, inner: EXPR): EvalM[F, C, (EvaluationContext[C, F], EVALUATED)] = for { @@ -39,7 +36,9 @@ class EvaluatorV1[F[_]: Monad, C[_[_]]](implicit ev: Monad[EvalF[F, *]], ev2: Mo blockEvaluation = evalExpr(let.value) lazyBlock = LazyVal(blockEvaluation.ter(ctx), ctx.l(let.name)) result <- local { - modify[F, EnabledLogEvaluationContext[C, F], ExecutionError](lets.modify(_)(_.updated(let.name, lazyBlock))) + modify[F, EnabledLogEvaluationContext[C, F], ExecutionError](ctx1 => + ctx1.copy(ec = ctx1.ec.copy(letDefs = ctx1.ec.letDefs.updated(let.name, lazyBlock))) + ) .flatMap(_ => evalExprWithCtx(inner)) } } yield result @@ -49,7 +48,9 @@ class EvaluatorV1[F[_]: Monad, C[_[_]]](implicit ev: Monad[EvalF[F, *]], ev2: Mo val function = UserFunction(func.name, 0, NOTHING, func.args.map(n => (n, NOTHING))*)(func.body) .asInstanceOf[UserFunction[C]] local { - modify[F, EnabledLogEvaluationContext[C, F], ExecutionError](funcs.modify(_)(_.updated(funcHeader, function))) + modify[F, EnabledLogEvaluationContext[C, F], ExecutionError](ctx => + ctx.copy(ec = ctx.ec.copy(functions = ctx.ec.functions.updated(funcHeader, function))) + ) .flatMap(_ => evalExprWithCtx(inner)) } } @@ -57,7 +58,7 @@ class EvaluatorV1[F[_]: Monad, C[_[_]]](implicit ev: Monad[EvalF[F, *]], ev2: Mo private def evalRef(key: String): EvalM[F, C, (EvaluationContext[C, F], EVALUATED)] = for { ctx <- get[F, EnabledLogEvaluationContext[C, F], ExecutionError] - r <- lets.get(ctx).get(key) match { + r <- ctx.ec.letDefs.get(key) match { case Some(lzy) => liftTER[F, C, EVALUATED](lzy.value) case None => raiseError[F, EnabledLogEvaluationContext[C, F], ExecutionError, EVALUATED](s"A definition of '$key' not found") } @@ -83,8 +84,7 @@ class EvaluatorV1[F[_]: Monad, C[_[_]]](implicit ev: Monad[EvalF[F, *]], ev2: Mo private def evalFunctionCall(header: FunctionHeader, args: List[EXPR]): EvalM[F, C, (EvaluationContext[C, F], EVALUATED)] = for { ctx <- get[F, EnabledLogEvaluationContext[C, F], ExecutionError] - result <- funcs - .get(ctx) + result <- ctx.ec.functions .get(header) .map { case func: UserFunction[C] => @@ -94,7 +94,7 @@ class EvaluatorV1[F[_]: Monad, C[_[_]]](implicit ev: Monad[EvalF[F, *]], ev2: Mo } local { val newState: EvalM[F, C, Unit] = - set[F, EnabledLogEvaluationContext[C, F], ExecutionError](lets.set(ctx)(letDefsWithArgs)).map(_.pure[F]) + set[F, EnabledLogEvaluationContext[C, F], ExecutionError](ctx.copy(ec = ctx.ec.copy(letDefs = letDefsWithArgs))).map(_.pure[F]) Monad[EvalM[F, C, *]].flatMap(newState)(_ => evalExpr(func.ev(ctx.ec.environment, args))) } }: EvalM[F, C, EVALUATED] @@ -118,7 +118,7 @@ class EvaluatorV1[F[_]: Monad, C[_[_]]](implicit ev: Monad[EvalF[F, *]], ev2: Mo // no such function, try data constructor header match { case FunctionHeader.User(typeName, _) => - types.get(ctx).get(typeName).collect { case t @ CASETYPEREF(_, fields, _) => + ctx.ec.typeDefs.get(typeName).collect { case t @ CASETYPEREF(_, fields, _) => args .traverse[EvalM[F, C, *], EVALUATED](evalExpr) .map(values => CaseObj(t, fields.map(_._1).zip(values).toMap): EVALUATED) diff --git a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/EvaluationContext.scala b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/EvaluationContext.scala index 1013b3bae4..863cbaa99c 100644 --- a/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/EvaluationContext.scala +++ b/lang/shared/src/main/scala/com/wavesplatform/lang/v1/evaluator/ctx/EvaluationContext.scala @@ -8,7 +8,6 @@ import com.wavesplatform.lang.v1.compiler.Terms.LET import com.wavesplatform.lang.v1.compiler.Types.FINAL import com.wavesplatform.lang.v1.evaluator.Contextful.NoContext import com.wavesplatform.lang.v1.evaluator.{Contextful, LetExecResult, LetLogCallback} -import shapeless.{Lens, lens} import java.util @@ -51,17 +50,6 @@ case class EnabledLogEvaluationContext[C[_[_]], F[_]: Monad](l: LetLogCallback[F loggedLets.computeIfAbsent(let, _ => l(let.name)(result)) } -object EnabledLogEvaluationContext { - class Lenses[F[_]: Monad, C[_[_]]] { - val types: Lens[EnabledLogEvaluationContext[C, F], Map[String, FINAL]] = - lens[EnabledLogEvaluationContext[C, F]] >> Symbol("ec") >> Symbol("typeDefs") - val lets: Lens[EnabledLogEvaluationContext[C, F], Map[String, LazyVal[F]]] = - lens[EnabledLogEvaluationContext[C, F]] >> Symbol("ec") >> Symbol("letDefs") - val funcs: Lens[EnabledLogEvaluationContext[C, F], Map[FunctionHeader, BaseFunction[C]]] = - lens[EnabledLogEvaluationContext[C, F]] >> Symbol("ec") >> Symbol("functions") - } -} - case class DisabledLogEvaluationContext[C[_[_]], F[_]](ec: EvaluationContext[C, F]) extends LoggedEvaluationContext[C, F] { override def log(let: LET, result: LetExecResult[F]): Unit = () }