Skip to content

Commit

Permalink
LF: clean up useless version tests.
Browse files Browse the repository at this point in the history
Since SDK 1.0.0 the min LF version is 1.6.
We drop some checks that are now redundant.

CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
remyhaemmerle-da committed Sep 9, 2021
1 parent 61a07b1 commit f35f380
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,23 @@ private[archive] class DecodeV1(minor: LV.Minor) {
lfPackage: PLF.Package,
onlySerializableDataDefs: Boolean,
): Either[Error, Package] = attempt(NameOf.qualifiedNameOfCurrentFunc) {
val internedStrings = lfPackage.getInternedStringsList.asScala.to(ImmArraySeq)
if (internedStrings.nonEmpty)
assertSince(LV.Features.internedPackageId, "interned strings table")

val internedDottedNames =
decodeInternedDottedNames(
lfPackage.getInternedDottedNamesList.asScala,
internedStrings,
lfPackage.getInternedStringsList.asScala.to(ImmArraySeq),
)

val dependencyTracker = new PackageDependencyTracker(packageId)

val metadata: Option[PackageMetadata] =
if (lfPackage.hasMetadata) {
assertSince(LV.Features.packageMetadata, "Package.metadata")
Some(decodePackageMetadata(lfPackage.getMetadata, internedStrings))
Some(
decodePackageMetadata(
lfPackage.getMetadata,
lfPackage.getInternedStringsList.asScala.to(ImmArraySeq),
)
)
} else {
if (!versionIsOlderThan(LV.Features.packageMetadata)) {
throw Error.Parsing(s"Package.metadata is required in Daml-LF 1.$minor")
Expand All @@ -55,7 +56,7 @@ private[archive] class DecodeV1(minor: LV.Minor) {

val env0 = Env(
packageId,
internedStrings,
lfPackage.getInternedStringsList.asScala.to(ImmArraySeq),
internedDottedNames,
IndexedSeq.empty,
Some(dependencyTracker),
Expand Down Expand Up @@ -289,10 +290,8 @@ private[archive] class DecodeV1(minor: LV.Minor) {
throw Error.Parsing(s"invalid internedString table index $id")
}

private[this] def getInternedPackageId(id: Int): PackageId = {
assertSince(LV.Features.internedPackageId, "interned PackageId")
private[this] def getInternedPackageId(id: Int): PackageId =
eitherToParseError(PackageId.fromString(getInternedStr(id)))
}

private[this] def getInternedName(id: Int, description: => String): Name = {
assertSince(LV.Features.internedStrings, description)
Expand Down Expand Up @@ -361,7 +360,6 @@ private[archive] class DecodeV1(minor: LV.Minor) {
case PLF.DefDataType.DataConsCase.VARIANT =>
DataVariant(decodeFields(lfDataType.getVariant.getFieldsList.asScala))
case PLF.DefDataType.DataConsCase.ENUM =>
assertSince(LV.Features.enum, "DefDataType.DataCons.Enum")
assertEmpty(params, "params")
DataEnum(decodeEnumCon(lfDataType.getEnum))
case PLF.DefDataType.DataConsCase.DATACONS_NOT_SET =>
Expand Down Expand Up @@ -883,7 +881,6 @@ private[archive] class DecodeV1(minor: LV.Minor) {
)

case PLF.Expr.SumCase.ENUM_CON =>
assertSince(LV.Features.enum, "Expr.Enum")
val enumCon = lfExpr.getEnumCon
EEnumCon(
decodeTypeConName(enumCon.getTycon),
Expand Down Expand Up @@ -1096,7 +1093,6 @@ private[archive] class DecodeV1(minor: LV.Minor) {
),
)
case PLF.CaseAlt.SumCase.ENUM =>
assertSince(LV.Features.enum, "CaseAlt.Enum")
val enum = lfCaseAlt.getEnum
CPEnum(
tycon = decodeTypeConName(enum.getCon),
Expand Down Expand Up @@ -1731,7 +1727,7 @@ private[lf] object DecodeV1 {
minVersion = contractIdTextConversions,
),
BuiltinFunctionInfo(PARTY_TO_QUOTED_TEXT, BPartyToQuotedText, maxVersion = Some(exceptions)),
BuiltinFunctionInfo(CODE_POINTS_TO_TEXT, BCodePointsToText, minVersion = textPacking),
BuiltinFunctionInfo(CODE_POINTS_TO_TEXT, BCodePointsToText),
BuiltinFunctionInfo(TEXT_TO_PARTY, BTextToParty),
BuiltinFunctionInfo(TEXT_TO_INT64, BTextToInt64),
BuiltinFunctionInfo(
Expand All @@ -1741,7 +1737,7 @@ private[lf] object DecodeV1 {
maxVersion = Some(numeric),
),
BuiltinFunctionInfo(TEXT_TO_NUMERIC, BTextToNumeric, minVersion = numeric),
BuiltinFunctionInfo(TEXT_TO_CODE_POINTS, BTextToCodePoints, minVersion = textPacking),
BuiltinFunctionInfo(TEXT_TO_CODE_POINTS, BTextToCodePoints),
BuiltinFunctionInfo(SHA256_TEXT, BSHA256Text),
BuiltinFunctionInfo(DATE_TO_UNIX_DAYS, BDateToUnixDays),
BuiltinFunctionInfo(EXPLODE_TEXT, BExplodeText),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,6 @@ private[daml] class EncodeV1(minor: LV.Minor) {
setString(binder, b.setBinderStr, b.setBinderInternedStr)
builder.setVariant(b)
case CPEnum(tyCon, con) =>
assertSince(LV.Features.enum, "CaseAlt.Enum")
val b = PLF.CaseAlt.Enum.newBuilder()
b.setCon(tyCon)
setString(con, b.setConstructorStr, b.setConstructorInternedStr)
Expand Down Expand Up @@ -547,7 +546,6 @@ private[daml] class EncodeV1(minor: LV.Minor) {
b.setVariantArg(arg)
builder.setVariantCon(b)
case EEnumCon(tyCon, con) =>
assertSince(LV.Features.enum, "Expr.Enum")
val b = PLF.Expr.EnumCon.newBuilder().setTycon(tyCon)
setString(con, b.setEnumConStr, b.setEnumConInternedStr)
builder.setEnumCon(b.build())
Expand Down Expand Up @@ -669,7 +667,6 @@ private[daml] class EncodeV1(minor: LV.Minor) {
PLF.DefDataType.Fields.newBuilder().accumulateLeft(variants)(_ addFields _)
)
case DataEnum(constructors) =>
assertSince(LV.Features.enum, "DefDataType.Enum")
val b = PLF.DefDataType.EnumConstructors.newBuilder()
constructors.foreach(
setString(_, b.addConstructorsStr, b.addConstructorsInternedStr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ object LanguageVersion {

object Features {
val default = v1_6
val textPacking = v1_6
val enum = v1_6
val internedPackageId = v1_6
val internedStrings = v1_7
val internedDottedNames = v1_7
Expand Down

0 comments on commit f35f380

Please sign in to comment.