From d85eba356f9af23567eb8230d6b3a9ef8ef86a75 Mon Sep 17 00:00:00 2001 From: SeungHwan Kim Date: Tue, 8 Oct 2024 03:12:52 +0000 Subject: [PATCH] add: small version of view --- .completion | 2 +- src/main/scala/esmeta/es/util/Coverage.scala | 1 + .../scala/esmeta/es/util/CoverageSmall.scala | 1 + .../scala/esmeta/es/util/JsonProtocol.scala | 32 +++++++++++++++++++ src/main/scala/esmeta/phase/MinifyFuzz.scala | 2 +- 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/.completion b/.completion index 682492359f..a27f6dc2c6 100644 --- a/.completion +++ b/.completion @@ -24,7 +24,7 @@ _esmeta_completions() { test262testOpt="-test262-test:target -test262-test:features -test262-test:progress -test262-test:coverage -test262-test:timeout -test262-test:with-yet -test262-test:log -test262-test:concurrent -test262-test:verbose" injectOpt="-inject:body -inject:defs -inject:out -inject:log" mutateOpt="-mutate:out -mutate:mutator -mutate:untilValid" - fuzzOpt="-fuzz:log -fuzz:log-interval -fuzz:out -fuzz:debug -fuzz:timeout -fuzz:trial -fuzz:duration -fuzz:seed -fuzz:cp -fuzz:k-fs -fuzz:init -fuzz:dumpDetail" + fuzzOpt="-fuzz:log -fuzz:log-interval -fuzz:out -fuzz:debug -fuzz:timeout -fuzz:trial -fuzz:duration -fuzz:seed -fuzz:cp -fuzz:k-fs -fuzz:init -fuzz:dump-detail" coverageinvestigateOpt="-coverage-investigate:out" analyzeOpt="-analyze:repl" # completion for commands diff --git a/src/main/scala/esmeta/es/util/Coverage.scala b/src/main/scala/esmeta/es/util/Coverage.scala index 3bb11736b0..ccf170d32b 100644 --- a/src/main/scala/esmeta/es/util/Coverage.scala +++ b/src/main/scala/esmeta/es/util/Coverage.scala @@ -537,6 +537,7 @@ object Coverage { kFs: Int, cp: Boolean, timeLimit: Option[Int], + dumpDetail: Int = 2, ) def fromLogSimpl(baseDir: String, cfg: CFG): Coverage = diff --git a/src/main/scala/esmeta/es/util/CoverageSmall.scala b/src/main/scala/esmeta/es/util/CoverageSmall.scala index 2061edb879..b81d4b9724 100644 --- a/src/main/scala/esmeta/es/util/CoverageSmall.scala +++ b/src/main/scala/esmeta/es/util/CoverageSmall.scala @@ -538,6 +538,7 @@ object CoverageSmall { kFs: Int, cp: Boolean, timeLimit: Option[Int], + dumpDetail: Int = 1, ) def fromLogSimpl(baseDir: String, cfg: CFG): Coverage = diff --git a/src/main/scala/esmeta/es/util/JsonProtocol.scala b/src/main/scala/esmeta/es/util/JsonProtocol.scala index 7df8c48c75..bc7f8b08a1 100644 --- a/src/main/scala/esmeta/es/util/JsonProtocol.scala +++ b/src/main/scala/esmeta/es/util/JsonProtocol.scala @@ -9,6 +9,7 @@ import io.circe.*, io.circe.syntax.*, io.circe.generic.semiauto.* class JsonProtocol(cfg: CFG) extends StateJsonProtocol(cfg) { import Coverage.* + import CoverageSmall.{ViewSmall, NodeViewSmall, CondViewSmall} // branch or reference to EReturnIfAbrupt with boolean values given condDecoder: Decoder[Cond] = deriveDecoder @@ -68,4 +69,35 @@ class JsonProtocol(cfg: CFG) extends StateJsonProtocol(cfg) { // coverage constructor given coverageConstructorDecoder: Decoder[CoverageConstructor] = deriveDecoder given coverageConstructorEncoder: Encoder[CoverageConstructor] = deriveEncoder + + // syntax-sensitive views with small information + // given viewSmallDecoder: Decoder[ViewSmall] = optionDecoder + given viewSmallEncoder: Encoder[ViewSmall] = + Encoder.instance { + case None => Json.Null + case Some((enclosing, feature, path)) => + Json.obj( + "enclosing" -> Json.fromValues( + enclosing.map(f => f.func.id.asJson), + ), + "feature" -> feature.func.id.asJson, + "path" -> path.map(_.toString).asJson, // to be changed + ) + } + given viewSmallDecoder: Decoder[ViewSmall] = deriveDecoder + + // given nodeViewSmallDecoder: Decoder[NodeViewSmall] = deriveDecoder + given nodeViewSmallEncoder: Encoder[NodeViewSmall] = + Encoder.instance(nv => + Json.obj( + "node" -> Json.obj( + "inst" -> nv.node.id.asJson, + "func" -> cfg.funcOf(nv.node).id.asJson, + ), + "view" -> viewSmallEncoder(nv.view), + ), + ) + + given condViewSmallDecoder: Decoder[CondViewSmall] = deriveDecoder + given condViewSmallEncoder: Encoder[CondViewSmall] = deriveEncoder } diff --git a/src/main/scala/esmeta/phase/MinifyFuzz.scala b/src/main/scala/esmeta/phase/MinifyFuzz.scala index d60866c2ff..d880f5a7a7 100644 --- a/src/main/scala/esmeta/phase/MinifyFuzz.scala +++ b/src/main/scala/esmeta/phase/MinifyFuzz.scala @@ -111,7 +111,7 @@ case object MinifyFuzz extends Phase[CFG, Coverage] { "explicitly use the given init pool", ), ( - "dumpDetail", + "dump-detail", NumOption((c, k) => if (k < 0 || k > 2) error("invalid dump detail level: please set 0 to 2")