mirror of
https://github.com/digital-asset/daml.git
synced 2024-11-13 00:16:19 +03:00
remove v1 encoder and decoder in the engine (#18295)
run-all-tests: true
This commit is contained in:
parent
90d90ea759
commit
3d3e05981a
@ -127,7 +127,6 @@ da_scala_library(
|
||||
"//daml-lf/language",
|
||||
"//libs-scala/crypto",
|
||||
"//libs-scala/nameof",
|
||||
"//libs-scala/safe-proto",
|
||||
"//libs-scala/scala-utils",
|
||||
"@maven//:com_google_protobuf_protobuf_java",
|
||||
],
|
||||
|
@ -16,15 +16,6 @@ object Decode {
|
||||
onlySerializableDataDefs: Boolean = false,
|
||||
): Either[Error, (PackageId, Ast.Package)] =
|
||||
payload.version match {
|
||||
case LanguageVersion(LanguageMajorVersion.V1, minor)
|
||||
if LanguageMajorVersion.V1.supportedMinorVersions.contains(minor) =>
|
||||
new DecodeV1(minor)
|
||||
.decodePackage(
|
||||
payload.pkgId,
|
||||
payload.proto.getDamlLf1,
|
||||
onlySerializableDataDefs,
|
||||
)
|
||||
.map(payload.pkgId -> _)
|
||||
case LanguageVersion(LanguageMajorVersion.V2, minor)
|
||||
if LanguageMajorVersion.V2.supportedMinorVersions.contains(minor) =>
|
||||
new DecodeV2(minor)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,31 +0,0 @@
|
||||
// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package com.daml.lf
|
||||
package archive
|
||||
|
||||
import com.daml.daml_lf_dev.{DamlLf1 => PLF}
|
||||
import com.daml.lf.data.Ref._
|
||||
import com.daml.lf.language.Ast._
|
||||
import com.daml.lf.language.{LanguageVersion => LV}
|
||||
|
||||
private[archive] class DecodeV1(minor: LV.Minor) {
|
||||
|
||||
private val decodeCommon = new DecodeCommon(LV(LV.Major.V1, minor))
|
||||
|
||||
def decodePackage( // entry point
|
||||
packageId: PackageId,
|
||||
lfPackage: PLF.Package,
|
||||
onlySerializableDataDefs: Boolean,
|
||||
): Either[Error, Package] =
|
||||
decodeCommon.decodePackage(packageId, lfPackage, onlySerializableDataDefs)
|
||||
|
||||
// each LF scenario module is wrapped in a distinct proto package
|
||||
type ProtoScenarioModule = PLF.Package
|
||||
|
||||
def decodeScenarioModule( // entry point
|
||||
packageId: PackageId,
|
||||
lfScenarioModule: ProtoScenarioModule,
|
||||
): Either[Error, Module] =
|
||||
decodeCommon.decodeScenarioModule(packageId, lfScenarioModule)
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -3,7 +3,7 @@
|
||||
|
||||
package com.daml.lf
|
||||
|
||||
import com.daml.daml_lf_dev.{DamlLf, DamlLf1, DamlLf2}
|
||||
import com.daml.daml_lf_dev.{DamlLf, DamlLf2}
|
||||
import com.daml.lf.data.Ref.PackageId
|
||||
import com.daml.lf.language.{Ast, LanguageMajorVersion, LanguageVersion}
|
||||
import com.daml.nameof.NameOf
|
||||
@ -52,20 +52,6 @@ package object archive {
|
||||
Right(cos)
|
||||
})
|
||||
|
||||
// TODO(#17366): This is only used to coerce LF2 to LF1 packages in the decoder.
|
||||
// Remove once Lf2 and LF1 have diverged.
|
||||
val Lf1PackageParser: GenReader[DamlLf1.Package] =
|
||||
Base.andThen(cos =>
|
||||
attempt(getClass.getCanonicalName + ".Lf1PackageParser")(DamlLf1.Package.parseFrom(cos))
|
||||
)
|
||||
|
||||
// TODO(#17366): This is only used to coerce LF1 to LF2 packages in the encoder.
|
||||
// Remove once LF2 and LF1 have diverged.
|
||||
val Lf2PackageParser: GenReader[DamlLf2.Package] =
|
||||
Base.andThen(cos =>
|
||||
attempt(getClass.getCanonicalName + ".Lf2PackageParser")(DamlLf2.Package.parseFrom(cos))
|
||||
)
|
||||
|
||||
val ArchiveParser: GenReader[DamlLf.Archive] =
|
||||
Base.andThen(cos =>
|
||||
attempt(getClass.getCanonicalName + ".ArchiveParser")(DamlLf.Archive.parseFrom(cos))
|
||||
@ -91,18 +77,14 @@ package object archive {
|
||||
|
||||
private[lf] def moduleDecoder(ver: LanguageVersion, pkgId: PackageId): GenReader[Ast.Module] = {
|
||||
ver.major match {
|
||||
case LanguageMajorVersion.V1 =>
|
||||
Base
|
||||
.andThen(cos =>
|
||||
attempt(NameOf.qualifiedNameOfCurrentFunc)(DamlLf1.Package.parseFrom(cos))
|
||||
)
|
||||
.andThen(new DecodeV1(ver.minor).decodeScenarioModule(pkgId, _))
|
||||
case LanguageMajorVersion.V2 =>
|
||||
Base
|
||||
.andThen(cos =>
|
||||
attempt(NameOf.qualifiedNameOfCurrentFunc)(DamlLf2.Package.parseFrom(cos))
|
||||
)
|
||||
.andThen(new DecodeV2(ver.minor).decodeScenarioModule(pkgId, _))
|
||||
case _ =>
|
||||
new GenReader[Ast.Module](_ => Left(Error.Parsing(s"LF version $ver unsupported")))
|
||||
}
|
||||
}
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -3,7 +3,7 @@
|
||||
|
||||
package com.daml.lf.archive
|
||||
|
||||
import com.daml.daml_lf_dev.DamlLf1
|
||||
import com.daml.daml_lf_dev.DamlLf2
|
||||
import com.daml.lf.language.{Ast, TypeOrdering}
|
||||
import org.scalatest.matchers.should.Matchers
|
||||
import org.scalatest.wordspec.AnyWordSpec
|
||||
@ -17,11 +17,11 @@ class TypeOrderingSpec extends AnyWordSpec with Matchers {
|
||||
"follow archive protobuf order" in {
|
||||
|
||||
val protoMapping =
|
||||
DecodeCommon.builtinTypeInfos.iterator.map(info => info.proto -> info.bTyp).toMap
|
||||
DecodeV2.builtinTypeInfos.iterator.map(info => info.proto -> info.bTyp).toMap
|
||||
|
||||
val primTypesInProtoOrder =
|
||||
DamlLf1.PrimType.getDescriptor.getValues.asScala
|
||||
.map(desc => DamlLf1.PrimType.internalGetValueMap().findValueByNumber(desc.getNumber))
|
||||
DamlLf2.PrimType.getDescriptor.getValues.asScala
|
||||
.map(desc => DamlLf2.PrimType.internalGetValueMap().findValueByNumber(desc.getNumber))
|
||||
.sortBy(_.getNumber)
|
||||
.collect(protoMapping)
|
||||
|
||||
|
@ -29,12 +29,6 @@ object Encode {
|
||||
val LanguageVersion(major, minor) = version
|
||||
|
||||
major match {
|
||||
case LanguageMajorVersion.V1 =>
|
||||
PLF.ArchivePayload
|
||||
.newBuilder()
|
||||
.setMinor(minor.toProtoIdentifier)
|
||||
.setDamlLf1(new EncodeV1(minor).encodePackage(pkgId, pkg))
|
||||
.build()
|
||||
case LanguageMajorVersion.V2 =>
|
||||
PLF.ArchivePayload
|
||||
.newBuilder()
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,21 +0,0 @@
|
||||
// Copyright (c) 2024 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package com.daml.lf.archive
|
||||
package testing
|
||||
|
||||
import com.daml.lf.data.Ref._
|
||||
import com.daml.lf.language.Ast._
|
||||
import com.daml.lf.language.{LanguageVersion => LV}
|
||||
import com.daml.daml_lf_dev.{DamlLf1 => PLF}
|
||||
|
||||
// Important: do not use this in production code. It is designed for testing only.
|
||||
@SuppressWarnings(Array("org.wartremover.warts.NonUnitStatements"))
|
||||
private[daml] class EncodeV1(minor: LV.Minor) {
|
||||
|
||||
private val encodeCommon = new EncodeCommon(LV(LV.Major.V1, minor))
|
||||
|
||||
def encodePackage(pkgId: PackageId, pkg: Package): PLF.Package = {
|
||||
encodeCommon.encodePackage(pkgId, pkg)
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
@ -9,7 +9,7 @@ import com.daml.daml_lf_dev.{DamlLf1, DamlLf2}
|
||||
import com.daml.lf.archive.{
|
||||
ArchivePayload,
|
||||
Dar,
|
||||
DecodeCommon,
|
||||
DecodeV2,
|
||||
UniversalArchiveDecoder,
|
||||
UniversalArchiveReader,
|
||||
}
|
||||
@ -36,7 +36,7 @@ class DamlLfEncoderTest
|
||||
|
||||
"be readable" in {
|
||||
|
||||
val modules_1_8 = Set[DottedName](
|
||||
val modules_2_1 = Set[DottedName](
|
||||
"UnitMod",
|
||||
"BoolMod",
|
||||
"Int64Mod",
|
||||
@ -56,23 +56,17 @@ class DamlLfEncoderTest
|
||||
"NumericMod",
|
||||
"AnyMod",
|
||||
"SynonymMod",
|
||||
"GenMapMod",
|
||||
"BigNumericMod",
|
||||
"ExceptionMod",
|
||||
"InterfaceMod",
|
||||
"InterfaceMod0",
|
||||
"InterfaceExtMod",
|
||||
)
|
||||
val modules_1_11 = modules_1_8 + "GenMapMod"
|
||||
val modules_1_13 = modules_1_11 + "BigNumericMod"
|
||||
val modules_1_14 = modules_1_13 + "ExceptionMod"
|
||||
val modules_1_15 = modules_1_14 + "InterfaceMod" + "InterfaceMod0"
|
||||
val modules_1_dev = modules_1_15 + "InterfaceExtMod"
|
||||
val modules_2_1 = modules_1_dev
|
||||
val modules_2_dev = modules_2_1
|
||||
|
||||
val versions = Table(
|
||||
"versions" -> "modules",
|
||||
"1.8" -> modules_1_8,
|
||||
"1.11" -> modules_1_11,
|
||||
"1.13" -> modules_1_13,
|
||||
"1.14" -> modules_1_14,
|
||||
"1.15" -> modules_1_15,
|
||||
"1.dev" -> modules_1_dev,
|
||||
"2.1" -> modules_2_1,
|
||||
"2.dev" -> modules_2_dev,
|
||||
)
|
||||
@ -150,7 +144,7 @@ class DamlLfEncoderTest
|
||||
val builtinMod = ModuleName.assertFromString("BuiltinMod")
|
||||
|
||||
"contains all builtins " in {
|
||||
forEvery(Table("version", LanguageVersion.All.filter(LanguageVersion.v1_13 <= _): _*)) {
|
||||
forEvery(Table("version", LanguageVersion.All.filter(LanguageVersion.v2_1 <= _): _*)) {
|
||||
// We do not check package older that 1.11 as they are used for stable packages only
|
||||
version =>
|
||||
val Right(dar) =
|
||||
@ -163,8 +157,8 @@ class DamlLfEncoderTest
|
||||
.values
|
||||
.collect { case Ast.DValue(_, Ast.EBuiltin(builtin), _) => builtin }
|
||||
.toSet
|
||||
val builtinsInVersion = DecodeCommon.builtinFunctionInfos.collect {
|
||||
case DecodeCommon.BuiltinFunctionInfo(_, builtin, minVersion, maxVersion, _)
|
||||
val builtinsInVersion = DecodeV2.builtinFunctionInfos.collect {
|
||||
case DecodeV2.BuiltinFunctionInfo(_, builtin, minVersion, maxVersion, _)
|
||||
if minVersion <= version && maxVersion.forall(version < _) =>
|
||||
builtin
|
||||
}.toSet
|
||||
|
@ -18,9 +18,6 @@ import org.scalatest.wordspec.AnyWordSpec
|
||||
|
||||
import scala.language.implicitConversions
|
||||
|
||||
// TODO (#17366): Once the LF2 syntax diverges from LF1, code sharing between these two tests is no
|
||||
// longer possible.
|
||||
class EncodeV1Spec extends EncodeSpec(LanguageVersion.v1_dev)
|
||||
class EncodeV2Spec extends EncodeSpec(LanguageVersion.v2_dev)
|
||||
|
||||
class EncodeSpec(languageVersion: LanguageVersion)
|
||||
|
@ -117,12 +117,6 @@ LF_VERSIONS = [
|
||||
|
||||
# All LF versions suported by the engine
|
||||
ENGINE_LF_VERSIONS = [
|
||||
"1.8",
|
||||
"1.11",
|
||||
"1.13",
|
||||
"1.14",
|
||||
"1.15",
|
||||
"1.dev",
|
||||
"2.1",
|
||||
"2.dev",
|
||||
]
|
||||
|
@ -132,7 +132,7 @@ daml_compile(
|
||||
daml_compile(
|
||||
name = "test-daml-with-same-dependencies-but-different-target-version",
|
||||
srcs = ["src/test/daml/Foo2.daml"],
|
||||
target = "1.13",
|
||||
target = "2.dev",
|
||||
)
|
||||
|
||||
daml_compile(
|
||||
|
@ -47,9 +47,6 @@ final class CodeGenRunnerTests extends AnyFlatSpec with Matchers {
|
||||
}
|
||||
|
||||
// Test case reproducing #15341
|
||||
// TODO(#17366): once we've got two 2.x compilers with different std libs, compile
|
||||
// testDarWithSameDependenciesButDifferentTargetVersion with one of these compilers and revert
|
||||
// the expectation to 6.
|
||||
it should "read interfaces from 2 DAR files with same dependencies but one with different daml compiler version" in {
|
||||
|
||||
val scope =
|
||||
@ -64,7 +61,7 @@ final class CodeGenRunnerTests extends AnyFlatSpec with Matchers {
|
||||
// + `daml-prim` from different LF version
|
||||
// + `daml-stdlib` from different LF version
|
||||
// + testDarWithSameDependenciesButDifferentTargetVersion
|
||||
scope.signatures.map(_.packageId).diff(stablePackageIds).length should ===(23)
|
||||
scope.signatures.map(_.packageId).diff(stablePackageIds).length should ===(6)
|
||||
scope.packagePrefixes should ===(Map.empty)
|
||||
scope.toBeGenerated should ===(Set.empty)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user