Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix normalization and value translation of LF1.15 values in 1.17 contexts #20473

Merged
merged 13 commits into from
Dec 16, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,22 @@ final class ValueEnricher(
)

def enrichChoiceResult(
choicePackageId: PackageId,
templatePackageId: PackageId,
qualifiedTemplateName: QualifiedName,
interfaceId: Option[Identifier],
choiceName: Name,
value: Value,
): Result[Value] = for {
choice <- handleLookup(
pkgInterface.lookupChoice(
Identifier(choicePackageId, qualifiedTemplateName),
Identifier(templatePackageId, qualifiedTemplateName),
interfaceId,
choiceName,
)
)
pkg <- handleLookup(pkgInterface.lookupPackage(choicePackageId))
pkg <- handleLookup(
pkgInterface.lookupPackage(interfaceId.fold(templatePackageId)(_.packageId))
)
enrichedValue <- enrichValue(choice.returnType, pkg.upgradable, value)
} yield enrichedValue

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ private[lf] final class CommandPreprocessor(
key.contractKey,
)
val ckTtype = handleLookup(pkgInterface.lookupTemplateKey(templateId)).typ
val preprocessedKey = translateArg(ckTtype, key.contractKey)
val preprocessedKey = translateArg(ckTtype, upgradable(templateId), key.contractKey)

speedy.Speedy.Machine
.globalKey(pkgInterface, templateId, preprocessedKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.daml.lf.value.Value._
import scala.annotation.tailrec

private[lf] final class ValueTranslator(
pkgInterface: language.PackageInterface,
val pkgInterface: language.PackageInterface,
checkV1ContractIdSuffixes: Boolean,
) {

Expand Down Expand Up @@ -197,8 +197,11 @@ private[lf] final class ValueTranslator(
case ValueRecord(mbId, sourceElements) =>
checkUserTypeId(upgradable, tyCon, mbId)
val lookupResult = handleLookup(pkgInterface.lookupDataRecord(tyCon))
val targetFieldsAndTypes = lookupResult.dataRecord.fields
val subst = lookupResult.subst(tyArgs)
val targetFieldsAndTypes =
lookupResult.dataRecord.fields.map { case (lbl, typ) =>
lbl -> AstUtil.substitute(typ, subst)
}

def addMissingField(lbl: Ref.Name, ty: Type): (Option[Ref.Name], Value) =
ty match {
Expand Down Expand Up @@ -279,8 +282,7 @@ private[lf] final class ValueTranslator(

// Recursive substitution
val translatedCorrectFields = correctFields.map { case (lbl, v, typ) =>
val replacedTyp = AstUtil.substitute(typ, subst)
lbl -> go(replacedTyp, v, newNesting)
lbl -> go(typ, v, newNesting)
}

extraFields.foreach {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ class EngineTest(langVersion: LanguageVersion)
"translate empty list" in {
val list = ValueNil
val res = preprocessor
.translateValue(TList(TBuiltin(BTInt64)), list)
.translateValue(TList(TBuiltin(BTInt64)), false, list)
.consume(lookupContract, lookupPackage, lookupKey)

res shouldEqual Right(SList(FrontStack.empty))
Expand All @@ -892,7 +892,7 @@ class EngineTest(langVersion: LanguageVersion)
"translate singleton" in {
val list = ValueList(FrontStack(ValueInt64(1)))
val res = preprocessor
.translateValue(TList(TBuiltin(BTInt64)), list)
.translateValue(TList(TBuiltin(BTInt64)), false, list)
.consume(lookupContract, lookupPackage, lookupKey)

res shouldEqual Right(SList(FrontStack(SInt64(1))))
Expand All @@ -903,7 +903,7 @@ class EngineTest(langVersion: LanguageVersion)
FrontStack(ValueInt64(1), ValueInt64(2), ValueInt64(3), ValueInt64(4), ValueInt64(5))
)
val res = preprocessor
.translateValue(TList(TBuiltin(BTInt64)), list)
.translateValue(TList(TBuiltin(BTInt64)), false, list)
.consume(lookupContract, lookupPackage, lookupKey)

res shouldEqual Right(
Expand All @@ -918,6 +918,7 @@ class EngineTest(langVersion: LanguageVersion)
preprocessor
.translateValue(
TTyConApp(TypeConName(basicTestsPkgId, "BasicTests:Nesting0"), ImmArray.Empty),
false,
nested,
)
.consume(lookupContract, lookupPackage, lookupKey)
Expand Down Expand Up @@ -951,6 +952,7 @@ class EngineTest(langVersion: LanguageVersion)
val res = preprocessor
.translateValue(
TTyConApp(Identifier(basicTestsPkgId, "BasicTests:MyNestedRec"), ImmArray.Empty),
false,
rec,
)
.consume(lookupContract, lookupPackage, lookupKey)
Expand All @@ -973,6 +975,7 @@ class EngineTest(langVersion: LanguageVersion)
val res = preprocessor
.translateValue(
TTyConApp(Identifier(basicTestsPkgId, "BasicTests:TypeWithParameters"), ImmArray.Empty),
false,
rec,
)
.consume(lookupContract, lookupPackage, lookupKey)
Expand All @@ -996,6 +999,7 @@ class EngineTest(langVersion: LanguageVersion)
val res = preprocessor
.translateValue(
TTyConApp(Identifier(basicTestsPkgId, "BasicTests:TypeWithParameters"), ImmArray.Empty),
false,
rec,
)
.consume(lookupContract, lookupPackage, lookupKey)
Expand All @@ -1016,6 +1020,7 @@ class EngineTest(langVersion: LanguageVersion)
val res = preprocessor
.translateValue(
TTyConApp(Identifier(basicTestsPkgId, "BasicTests:TypeWithParameters"), ImmArray.Empty),
false,
rec,
)
.consume(lookupContract, lookupPackage, lookupKey)
Expand All @@ -1038,6 +1043,7 @@ class EngineTest(langVersion: LanguageVersion)
val res = preprocessor
.translateValue(
TTyConApp(Identifier(basicTestsPkgId, "BasicTests:TypeWithParameters"), ImmArray.Empty),
false,
rec,
)
.consume(lookupContract, lookupPackage, lookupKey)
Expand All @@ -1058,6 +1064,7 @@ class EngineTest(langVersion: LanguageVersion)
val res = preprocessor
.translateValue(
TTyConApp(Identifier(basicTestsPkgId, "BasicTests:TypeWithParameters"), ImmArray.Empty),
false,
rec,
)
.consume(lookupContract, lookupPackage, lookupKey)
Expand Down
Loading
Loading