Skip to content

Commit

Permalink
Speedy: Implement EToRequiredInterface and EFromRequiredInterface (#1…
Browse files Browse the repository at this point in the history
…2046)

Part of #11978.

CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
remyhaemmerle-da authored Dec 8, 2021
1 parent 6c7112c commit 4f1892b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -578,11 +578,9 @@ private[lf] final class Compiler(
case ECallInterface(iface, methodName, e) =>
SBCallInterface(iface, methodName)(compile(env, e))
case EToRequiredInterface(requiredIfaceId @ _, requiringIfaceId @ _, body @ _) =>
// TODO https://github.com/digital-asset/daml/issues/11978
throw CompilationError("EToRequiredInterface is not implemented")
case EFromRequiredInterface(requiredIfaceId @ _, requiringIfaceId @ _, body @ _) =>
// TODO https://github.com/digital-asset/daml/issues/11978
throw CompilationError("EFromRequiredInterface is not implemented")
compile(env, body)
case EFromRequiredInterface(requiredIfaceId @ _, requiringIfaceId, body @ _) =>
SBFromRequiredInterface(requiringIfaceId)(compile(env, body))
case EExperimental(name, _) =>
SBExperimental(name)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,28 @@ private[lf] object SBuiltin {
}
}

// Convert an interface `requiredIface` to another interface `requiringIface`, if
// the `requiringIface` implements `requiredIface`.
final case class SBFromRequiredInterface(
requiringIface: TypeConName
) extends SBuiltin(1) {

override private[speedy] def execute(
args: util.ArrayList[SValue],
machine: Machine,
) = {
val record = getSRecord(args, 0)
// TODO https://github.com/digital-asset/daml/issues/11345
// The lookup is probably slow. We may want to investigate way to make the feature faster.
machine.returnValue = machine.compiledPackages.interface.lookupTemplate(record.id) match {
case Right(ifaceSignature) if ifaceSignature.implements.contains(requiringIface) =>
SOptional(Some(record))
case _ =>
SOptional(None)
}
}
}

final case class SBCallInterface(
ifaceId: TypeConName,
methodName: MethodName,
Expand Down

0 comments on commit 4f1892b

Please sign in to comment.