Remove damlLfInstantiate in favor of TypeCon.instantiate (#7166)

fixes #2506

Judging from the issue this was originally introduced to workaround a
bug. I couldn’t actually track down what that bug was but at this
point they are identical so no point keeping this around.

changelog_begin
changelog_end
This commit is contained in:
Moritz Kiefer 2020-08-18 14:15:12 +02:00 committed by GitHub
parent f0e09c54b1
commit 820c9ff844
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 6 additions and 35 deletions

View File

@ -288,10 +288,8 @@ class ApiCodecCompressed[Cid](val encodeDecimalAsString: Boolean, val encodeInt6
jsValueToApiPrimitive(value, prim, defs)
case typeCon: Model.DamlLfTypeCon =>
val id = typeCon.name.identifier
// val dt = typeCon.instantiate(defs(id).getOrElse(deserializationError(s"Type $id not found")))
val dt = Model.damlLfInstantiate(
typeCon,
defs(id).getOrElse(deserializationError(s"Type $id not found")))
val dt =
typeCon.instantiate(defs(id).getOrElse(deserializationError(s"Type $id not found")))
jsValueToApiDataType(value, id, dt, defs)
case Model.DamlLfTypeNumeric(scale) =>
val numericOrError = value match {
@ -314,10 +312,7 @@ class ApiCodecCompressed[Cid](val encodeDecimalAsString: Boolean, val encodeInt6
id: Model.DamlLfIdentifier,
defs: Model.DamlLfTypeLookup): V[Cid] = {
val typeCon = Model.DamlLfTypeCon(Model.DamlLfTypeConName(id), ImmArraySeq())
// val dt = typeCon.instantiate(defs(id).getOrElse(deserializationError(s"Type $id not found")))
val dt = Model.damlLfInstantiate(
typeCon,
defs(id).getOrElse(deserializationError(s"Type $id not found")))
val dt = typeCon.instantiate(defs(id).getOrElse(deserializationError(s"Type $id not found")))
jsValueToApiDataType(value, id, dt, defs)
}

View File

@ -67,28 +67,6 @@ trait NavigatorModelAliases[Cid] {
type DamlLfEnum = iface.Enum
val DamlLfEnum = iface.Enum
def damlLfInstantiate(typeCon: DamlLfTypeCon, defn: DamlLfDefDataType): DamlLfDataType =
if (defn.typeVars.length != typeCon.typArgs.length) {
throw new RuntimeException(
s"Mismatching type vars and applied types, expected ${defn.typeVars} but got ${typeCon.typArgs} types")
} else {
if (defn.typeVars.isEmpty) { // optimization
defn.dataType
} else {
val paramsMap = Map(defn.typeVars.zip(typeCon.typArgs): _*)
def mapTypeVars(typ: DamlLfType, f: DamlLfTypeVar => DamlLfType): DamlLfType = typ match {
case t @ DamlLfTypeVar(_) => f(t)
case t @ DamlLfTypeCon(_, _) => DamlLfTypeCon(t.name, t.typArgs.map(mapTypeVars(_, f)))
case t @ DamlLfTypePrim(_, _) => DamlLfTypePrim(t.typ, t.typArgs.map(mapTypeVars(_, f)))
case t @ DamlLfTypeNumeric(_) => t
}
val withTyp: iface.Type => iface.Type = { typ =>
mapTypeVars(typ, v => paramsMap.getOrElse(v.name, v))
}
defn.dataType.bimap(withTyp, withTyp)
}
}
import scala.language.higherKinds
type OfCid[F[_]] = F[Cid]
type ApiValue = OfCid[V]

View File

@ -136,8 +136,7 @@ object Pretty {
} else {
// Once a type is instantiated, do not instantiate it in any child node.
// Required to prevent infinite expansion of recursive types.
// val dt = typeCon.instantiate(typeDefs(id).get)
val dt = model.damlLfInstantiate(typeCon, typeDefs(id).get)
val dt = typeCon.instantiate(typeDefs(id).get)
(
Some(typeCon.name.identifier.qualifiedName.name.toString),
damlLfDataType(dt, typeDefs, doNotExpand + id))

View File

@ -44,7 +44,7 @@ package object filter {
parameter match {
case tc: DamlLfTypeCon =>
val nextOrResult =
(ps(tc.name.identifier).map(damlLfInstantiate(tc, _)), cursor.next) match {
(ps(tc.name.identifier).map(tc.instantiate(_)), cursor.next) match {
case (Some(DamlLfRecord(fields)), Some(nextCursor)) =>
fields
.collectFirst {

View File

@ -61,8 +61,7 @@ object project {
ddt <- ps(tc.name.identifier)
.toRight(UnknownType(tc.name.identifier.toString, cursor, value))
nextCursor <- cursor.next.toRight(MustNotBeLastPart("DataType", cursor, value))
//nextField <- tc.instantiate(ddt) match {
nextField <- damlLfInstantiate(tc, ddt) match {
nextField <- tc.instantiate(ddt) match {
case DamlLfRecord(fields) =>
fields
.find(f => f._1 == nextCursor.current)