mirror of
https://github.com/digital-asset/daml.git
synced 2024-09-20 09:17:43 +03:00
interfaces: Improve fixed choice lookup (#11551)
* interfaces: Improve fixed choice lookup This PR adds a lazy map to match fixed choice names to their interface, to improve the worst case for choice lookup. Part of #10810 changelog_begin changelog_end * scalafmt * apply improvements from remy
This commit is contained in:
parent
ba96bf784c
commit
4d4869f06e
@ -712,7 +712,12 @@ object Ast {
|
||||
observers: E, // Observers of the contract.
|
||||
key: Option[GenTemplateKey[E]],
|
||||
implements: Map[TypeConName, GenTemplateImplements[E]],
|
||||
)
|
||||
) {
|
||||
lazy val inheritedChoices: Map[ChoiceName, TypeConName] =
|
||||
implements.flatMap { case (iface, impl) =>
|
||||
impl.inheritedChoices.view.map(chName => (chName, iface))
|
||||
}
|
||||
}
|
||||
|
||||
final class GenTemplateCompanion[E] private[Ast] {
|
||||
|
||||
|
@ -6,7 +6,6 @@ package language
|
||||
|
||||
import com.daml.lf.data.Ref._
|
||||
import com.daml.lf.language.Ast._
|
||||
import scalaz._, std.list._, std.either._, syntax.traverse._
|
||||
|
||||
private[lf] class PackageInterface(signatures: PartialFunction[PackageId, PackageSignature]) {
|
||||
|
||||
@ -202,14 +201,15 @@ private[lf] class PackageInterface(signatures: PartialFunction[PackageId, Packag
|
||||
template.choices.get(chName) match {
|
||||
case Some(choice) => Right(choice)
|
||||
case None =>
|
||||
// TODO https://github.com/digital-asset/daml/issues/10810
|
||||
// Improve lookup for fixed choices
|
||||
for {
|
||||
ifaces <- template.implements.keys.toList.traverse(lookupInterface(_, context))
|
||||
choices = ifaces.flatMap(_.fixedChoices.get(chName).toList)
|
||||
choice <-
|
||||
choices.headOption.toRight(LookupError(Reference.Choice(tmpName, chName), context))
|
||||
} yield choice
|
||||
template.inheritedChoices.get(chName) match {
|
||||
case None => Left(LookupError(Reference.Choice(tmpName, chName), context))
|
||||
case Some(ifaceName) =>
|
||||
lookupInterface(ifaceName, context).flatMap(iface =>
|
||||
iface.fixedChoices
|
||||
.get(chName)
|
||||
.toRight(LookupError(Reference.Choice(ifaceName, chName), context))
|
||||
)
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user