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

LF: rename language Interface to PackageInterface #10938

Merged
merged 1 commit into from
Sep 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class ReplService(
val (pkgId, pkg) = archive.ArchiveDecoder.assertFromByteString(req.getPackage)
val newSignatures = signatures.updated(pkgId, AstUtil.toSignature(pkg))
val newCompiledDefinitions = compiledDefinitions ++
new Compiler(new language.Interface(newSignatures), compilerConfig)
new Compiler(new language.PackageInterface(newSignatures), compilerConfig)
.unsafeCompilePackage(pkgId, pkg)
signatures = newSignatures
compiledDefinitions = newCompiledDefinitions
Expand Down Expand Up @@ -257,7 +257,7 @@ class ReplService(
}

val signatures = this.signatures.updated(homePackageId, AstUtil.toSignature(pkg))
val interface = new language.Interface(signatures)
val interface = new language.PackageInterface(signatures)
val defs =
new Compiler(interface, compilerConfig).unsafeCompilePackage(homePackageId, pkg)
val compiledPackages =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class Context(val contextId: Context.ContextId, languageVersion: LanguageVersion
if (unloadPackages.nonEmpty || newPackages.nonEmpty) {
val invalidPackages = unloadModules ++ newPackages.keys
val newExtSignature = extSignatures -- unloadPackages ++ AstUtil.toSignatures(newPackages)
val interface = new language.Interface(newExtSignature)
val interface = new language.PackageInterface(newExtSignature)
val newExtDefns = extDefns.view.filterKeys(sdef => !invalidPackages(sdef.packageId)) ++
assertRight(Compiler.compilePackages(interface, newPackages, compilerConfig))
// we update only if we manage to compile the new packages
Expand All @@ -112,7 +112,7 @@ class Context(val contextId: Context.ContextId, languageVersion: LanguageVersion
newModules
}

val interface = new language.Interface(this.allSignatures)
val interface = new language.PackageInterface(this.allSignatures)
val compiler = new Compiler(interface, compilerConfig)

modulesToCompile.foreach { mod =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.nio.file.Paths
import com.daml.lf.archive.{Dar, DarWriter}
import com.daml.lf.data.Ref
import com.daml.lf.data.Ref.PackageId
import com.daml.lf.language.{Ast, Interface, LanguageVersion}
import com.daml.lf.language.{Ast, PackageInterface, LanguageVersion}
import com.daml.lf.testing.parser.{ParserParameters, parseModules}
import com.daml.lf.validation.Validation
import com.daml.SdkVersion
Expand Down Expand Up @@ -71,7 +71,7 @@ private[daml] object DamlLfEncoder extends App {

val pkg =
Ast.Package(modules, Set.empty[PackageId], parserParameters.languageVersion, metadata)
val pkgs = Interface(Map(pkgId -> pkg))
val pkgs = PackageInterface(Map(pkgId -> pkg))

Validation.checkPackage(pkgs, pkgId, pkg).left.foreach(e => error(e.pretty))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ object EncodeV1Spec {

private def validate(pkgId: PackageId, pkg: Package): Unit =
Validation
.checkPackage(language.Interface(Map(pkgId -> pkg)), pkgId, pkg)
.checkPackage(language.PackageInterface(Map(pkgId -> pkg)), pkgId, pkg)
.left
.foreach(e => sys.error(e.toString))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import java.util.concurrent.ConcurrentHashMap
import com.daml.lf.data.Ref.PackageId
import com.daml.lf.engine.ConcurrentCompiledPackages.AddPackageState
import com.daml.lf.language.Ast.{Package, PackageSignature}
import com.daml.lf.language.{Interface, Util => AstUtil}
import com.daml.lf.language.{PackageInterface, Util => AstUtil}
import com.daml.lf.speedy.Compiler
import com.daml.nameof.NameOf

Expand All @@ -30,7 +30,7 @@ private[lf] final class ConcurrentCompiledPackages(compilerConfig: Compiler.Conf
new ConcurrentHashMap()

override def packageIds: scala.collection.Set[PackageId] = signatures.keySet
override def interface: Interface = new Interface(signatures)
override def interface: PackageInterface = new PackageInterface(signatures)
override def getDefinition(dref: speedy.SExpr.SDefinitionRef): Option[speedy.SDefinition] =
Option(definitionsByReference.get(dref))

Expand Down Expand Up @@ -99,7 +99,7 @@ private[lf] final class ConcurrentCompiledPackages(compilerConfig: Compiler.Conf
if (!signatures.contains(pkgId)) {
val pkgSignature = AstUtil.toSignature(pkg)
val extendedSignatures =
new language.Interface(Map(pkgId -> pkgSignature) orElse signatures)
new language.PackageInterface(Map(pkgId -> pkgSignature) orElse signatures)

// Compile the speedy definitions for this package.
val defns =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import com.daml.lf.transaction.{SubmittedTransaction, Transaction => Tx}
import com.daml.lf.transaction.Node._
import java.nio.file.Files

import com.daml.lf.language.{Interface, LanguageVersion, LookupError, StablePackages}
import com.daml.lf.language.{PackageInterface, LanguageVersion, LookupError, StablePackages}
import com.daml.lf.validation.Validation
import com.daml.nameof.NameOf

Expand Down Expand Up @@ -456,7 +456,7 @@ class Engine(val config: EngineConfig = Engine.StableConfig) {
pkgIds = pkgs.keySet
missingDeps = pkgs.valuesIterator.flatMap(_.directDeps).toSet.filterNot(pkgIds)
_ <- Either.cond(missingDeps.isEmpty, (), Error.Package.SelfConsistency(pkgIds, missingDeps))
interface = Interface(pkgs)
interface = PackageInterface(pkgs)
_ <- {
pkgs.iterator
// we trust already loaded packages
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.daml.lf.value.Value
import scala.annotation.tailrec

private[lf] final class CommandPreprocessor(
interface: language.Interface,
interface: language.PackageInterface,
// See Preprocessor scala doc for more details about the following flags.
forbidV0ContractId: Boolean,
requireV1ContractIdSuffix: Boolean,
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[engine] final class ValueTranslator(
interface: language.Interface,
interface: language.PackageInterface,
// See Preprocessor scala doc for more details about the following flags.
forbidV0ContractId: Boolean,
requireV1ContractIdSuffix: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class EngineTest
"daml-lf/tests/BasicTests.dar"
)

val basicTestsSignatures = language.Interface(Map(basicTestsPkgId -> basicTestsPkg))
val basicTestsSignatures = language.PackageInterface(Map(basicTestsPkgId -> basicTestsPkg))

val withKeyTemplate = "BasicTests:WithKey"
val BasicTests_WithKey = Identifier(basicTestsPkgId, withKeyTemplate)
Expand Down Expand Up @@ -561,7 +561,7 @@ class EngineTest
}

val let = Time.Timestamp.now()
val submissionSeed = hash("multi-party create command")
val submissionSeed = hash("multi-party create command2")

def interpretResult(
templateId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package com.daml.lf
package speedy
package explore

import com.daml.lf.language.Interface
import com.daml.lf.language.PackageInterface
import com.daml.lf.speedy.SExpr._
import com.daml.lf.speedy.SValue._
import com.daml.lf.speedy.SResult._
Expand All @@ -25,7 +25,7 @@ object PlaySpeedy {

def main(args0: List[String]) = {
val config: Config = parseArgs(args0)
val compiler: Compiler = new Compiler(Interface.Empty, compilerConfig)
val compiler: Compiler = new Compiler(PackageInterface.Empty, compilerConfig)

val names: List[String] = config.names match {
case Nil => examples.toList.map(_._1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package com.daml.lf

import com.daml.lf.data.Ref.PackageId
import com.daml.lf.language.Ast.{Package, PackageSignature}
import com.daml.lf.language.{Interface, Util}
import com.daml.lf.language.{PackageInterface, Util}
import com.daml.lf.speedy.SExpr.SDefinitionRef
import com.daml.lf.speedy.{Compiler, SDefinition}

Expand All @@ -17,7 +17,7 @@ private[lf] abstract class CompiledPackages(
) {
def getDefinition(dref: SDefinitionRef): Option[SDefinition]
def packageIds: scala.collection.Set[PackageId]
def interface: Interface
def interface: PackageInterface
def definitions: PartialFunction[SDefinitionRef, SDefinition] =
Function.unlift(this.getDefinition)

Expand All @@ -29,7 +29,7 @@ private[lf] abstract class CompiledPackages(
*/
private[lf] final class PureCompiledPackages(
val packageIds: Set[PackageId],
val interface: Interface,
val interface: PackageInterface,
val defns: Map[SDefinitionRef, SDefinition],
compilerConfig: Compiler.Config,
) extends CompiledPackages(compilerConfig) {
Expand All @@ -46,14 +46,14 @@ private[lf] object PureCompiledPackages {
defns: Map[SDefinitionRef, SDefinition],
compilerConfig: Compiler.Config,
): PureCompiledPackages =
new PureCompiledPackages(packages.keySet, new Interface(packages), defns, compilerConfig)
new PureCompiledPackages(packages.keySet, new PackageInterface(packages), defns, compilerConfig)

def build(
packages: Map[PackageId, Package],
compilerConfig: Compiler.Config = Compiler.Config.Default,
): Either[String, PureCompiledPackages] = {
Compiler
.compilePackages(Interface(packages), packages, compilerConfig)
.compilePackages(PackageInterface(packages), packages, compilerConfig)
.map(apply(Util.toSignatures(packages), _, compilerConfig))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import java.util
import com.daml.lf.data.Ref._
import com.daml.lf.data.{ImmArray, Numeric, Ref, Struct, Time}
import com.daml.lf.language.Ast._
import com.daml.lf.language.{LanguageVersion, LookupError, Interface, StablePackages}
import com.daml.lf.language.{LanguageVersion, LookupError, PackageInterface, StablePackages}
import com.daml.lf.speedy.Anf.flattenToAnf
import com.daml.lf.speedy.Profile.LabelModule
import com.daml.lf.speedy.SBuiltin._
Expand Down Expand Up @@ -105,7 +105,7 @@ private[lf] object Compiler {
* they transitively reference are in the [[packages]] in the compiler.
*/
def compilePackages(
interface: Interface,
interface: PackageInterface,
packages: Map[PackageId, Package],
compilerConfig: Compiler.Config,
): Either[String, Map[SDefinitionRef, SDefinition]] = {
Expand Down Expand Up @@ -136,7 +136,7 @@ private[lf] object Compiler {
}

private[lf] final class Compiler(
interface: Interface,
interface: PackageInterface,
config: Compiler.Config,
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.daml.lf.data.Ref
import com.daml.lf.data.Ref.{PackageId, Party}
import com.daml.lf.interpretation.{Error => IE}
import com.daml.lf.language.Ast._
import com.daml.lf.language.{LanguageVersion, Interface}
import com.daml.lf.language.{LanguageVersion, PackageInterface}
import com.daml.lf.speedy.Compiler.FullStackTrace
import com.daml.lf.speedy.SResult.{SResultError, SResultFinalValue}
import com.daml.lf.speedy.SError.SErrorDamlException
Expand Down Expand Up @@ -539,7 +539,7 @@ class ExceptionTest extends AnyWordSpec with Matchers with TableDrivenPropertyCh
private def typeAndCompile(pkg: Package): PureCompiledPackages = {
import defaultParserParameters.defaultPackageId
val rawPkgs = Map(defaultPackageId -> pkg)
Validation.checkPackage(Interface(rawPkgs), defaultPackageId, pkg)
Validation.checkPackage(PackageInterface(rawPkgs), defaultPackageId, pkg)
val compilerConfig = Compiler.Config.Dev.copy(stacktracing = FullStackTrace)
PureCompiledPackages.assertBuild(rawPkgs, compilerConfig)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.daml.lf.data.ImmArray
import com.daml.lf.data.Ref
import com.daml.lf.data.Ref.Party
import com.daml.lf.language.Ast.{Package, Expr, PrimLit, PLParty, EPrimLit, EApp}
import com.daml.lf.language.{LanguageVersion, Interface}
import com.daml.lf.language.{LanguageVersion, PackageInterface}
import com.daml.lf.speedy.Compiler.FullStackTrace
import com.daml.lf.speedy.PartialTransaction.{CompleteTransaction, IncompleteTransaction, LeafNode}
import com.daml.lf.speedy.SResult.SResultFinalValue
Expand Down Expand Up @@ -38,7 +38,7 @@ class ExceptionTest extends AnyWordSpec with Matchers with TableDrivenPropertyCh
private def typeAndCompile(pkg: Package): PureCompiledPackages = {
import defaultParserParameters.defaultPackageId
val rawPkgs = Map(defaultPackageId -> pkg)
Validation.checkPackage(Interface(rawPkgs), defaultPackageId, pkg)
Validation.checkPackage(PackageInterface(rawPkgs), defaultPackageId, pkg)
val compilerConfig = Compiler.Config.Dev.copy(stacktracing = FullStackTrace)
PureCompiledPackages.assertBuild(rawPkgs, compilerConfig)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ object SpeedyTest {
private def typeAndCompile(pkg: Package): PureCompiledPackages = {
import defaultParserParameters.defaultPackageId
val rawPkgs = Map(defaultPackageId -> pkg)
Validation.checkPackage(language.Interface(rawPkgs), defaultPackageId, pkg)
Validation.checkPackage(language.PackageInterface(rawPkgs), defaultPackageId, pkg)
val compilerConfig = Compiler.Config.Default.copy(stacktracing = FullStackTrace)
PureCompiledPackages.assertBuild(rawPkgs, compilerConfig)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class TailCallTest extends AnyWordSpec with Matchers with TableDrivenPropertyChe
import defaultParserParameters.defaultPackageId
val rawPkgs = Map(defaultPackageId -> pkg)
Validation.checkPackage(
language.Interface(rawPkgs),
language.PackageInterface(rawPkgs),
defaultParserParameters.defaultPackageId,
pkg,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ package language
import com.daml.lf.data.Ref._
import com.daml.lf.language.Ast._

private[lf] class Interface(signatures: PartialFunction[PackageId, PackageSignature]) {
private[lf] class PackageInterface(signatures: PartialFunction[PackageId, PackageSignature]) {

import Interface._
import PackageInterface._

private[this] def lookupPackage(
pkgId: PackageId,
Expand Down Expand Up @@ -263,12 +263,12 @@ private[lf] class Interface(signatures: PartialFunction[PackageId, PackageSignat

}

object Interface {
object PackageInterface {

val Empty = new Interface(PartialFunction.empty)
val Empty = new PackageInterface(PartialFunction.empty)

def apply(packages: Map[PackageId, Package]): Interface =
new Interface(Util.toSignatures(packages))
def apply(packages: Map[PackageId, Package]): PackageInterface =
new PackageInterface(Util.toSignatures(packages))

case class DataRecordInfo(
dataType: DDataType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.daml.lf.speedy.SResult._
import com.daml.lf.speedy.SExpr.LfDefRef
import com.daml.lf.validation.Validation
import com.daml.lf.testing.parser
import com.daml.lf.language.{Interface, LanguageVersion => LV}
import com.daml.lf.language.{PackageInterface, LanguageVersion => LV}
import java.io.{File, PrintWriter, StringWriter}
import java.nio.file.{Path, Paths}
import java.io.PrintStream
Expand Down Expand Up @@ -156,7 +156,7 @@ object Repl {

def cmdValidate(state: State): (Boolean, State) = {
val (validationResults, validationTime) = time(state.packages.map { case (pkgId, pkg) =>
Validation.checkPackage(Interface(state.packages), pkgId, pkg)
Validation.checkPackage(PackageInterface(state.packages), pkgId, pkg)
})
System.err.println(s"${state.packages.size} package(s) validated in $validationTime ms.")
validationResults collectFirst { case Left(e) =>
Expand Down Expand Up @@ -428,7 +428,7 @@ object Repl {
def speedyCompile(state: State, args: Seq[String]): Unit = {
val defs = assertRight(
Compiler.compilePackages(
Interface(state.packages),
PackageInterface(state.packages),
state.packages,
state.scenarioRunner.compilerConfig,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import scala.Ordering.Implicits.infixOrderingOps
private[validation] object DependencyVersion {

@throws[ValidationError]
def checkPackage(interface: language.Interface, pkgId: PackageId, pkg: Package): Unit =
def checkPackage(interface: language.PackageInterface, pkgId: PackageId, pkg: Package): Unit =
for {
depPkgId <- pkg.directDeps
depPkg = Util.handleLookup(NoContext, interface.lookupPackage(depPkgId))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ package com.daml.lf.validation

import com.daml.lf.data.Ref.PackageId
import com.daml.lf.language.Ast._
import com.daml.lf.language.Interface
import com.daml.lf.language.PackageInterface
import com.daml.lf.validation.iterable.ExprIterable

private[validation] object PartyLiterals {

import Util.handleLookup

@throws[EForbiddenPartyLiterals]
def checkModule(interface: Interface, pkgId: PackageId, module: Module): Unit = {
def checkModule(interface: PackageInterface, pkgId: PackageId, module: Module): Unit = {
module.definitions.foreach {
case (defName, DValue(typ @ _, noPartyLiterals, body, isTest @ _)) =>
def context = ContextDefValue(pkgId, module.name, defName)
Expand All @@ -29,7 +29,7 @@ private[validation] object PartyLiterals {
}
}

private def checkExpr(interface: Interface, context: => Context, expr: Expr): Unit =
private def checkExpr(interface: PackageInterface, context: => Context, expr: Expr): Unit =
expr match {
case EPrimLit(party: PLParty) =>
throw EForbiddenPartyLiterals(context, PartyLiteral(party.value))
Expand Down
Loading