Skip to content

Commit

Permalink
Speedy Compiler: clean up. (digital-asset#5649)
Browse files Browse the repository at this point in the history
CHANGELOG_BEGIN
CHANGELOG_END
  • Loading branch information
remyhaemmerle-da authored Apr 22, 2020
1 parent 5f9db11 commit 7bdde70
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 111 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.daml.lf.language.{Ast, LanguageVersion}
import com.daml.lf.speedy.SExpr._
import com.daml.lf.speedy.{Compiler, SValue, SExpr, SError}
import com.daml.grpc.adapter.{AkkaExecutionSequencerPool, ExecutionSequencerFactory}
import com.daml.ledger.api.refinements.ApiTypes.{ApplicationId}
import com.daml.ledger.api.refinements.ApiTypes.ApplicationId
import com.daml.ledger.api.tls.TlsConfiguration
import com.daml.ledger.client.configuration.{
CommandClientConfiguration,
Expand Down Expand Up @@ -172,7 +172,7 @@ class ReplService(
respObs: StreamObserver[LoadPackageResponse]): Unit = {
val (pkgId, pkg) = Decode.decodeArchiveFromInputStream(req.getPackage.newInput)
packages = packages + (pkgId -> pkg)
compiledDefinitions = compiledDefinitions ++ Compiler(packages).compilePackage(pkgId)
compiledDefinitions = compiledDefinitions ++ Compiler(packages).unsafeCompilePackage(pkgId)
respObs.onNext(LoadPackageResponse.newBuilder.build)
respObs.onCompleted()
}
Expand Down Expand Up @@ -208,8 +208,8 @@ class ReplService(
}

val allPkgs = packages + (homePackageId -> pkg)
val defs = Compiler(allPkgs).compilePackage(homePackageId)
val compiledPackages = PureCompiledPackages(allPkgs, compiledDefinitions ++ defs).right.get
val defs = Compiler(allPkgs).unsafeCompilePackage(homePackageId)
val compiledPackages = PureCompiledPackages(allPkgs, compiledDefinitions ++ defs)
val runner = new Runner(
compiledPackages,
Script.Action(scriptExpr, ScriptIds(scriptPackageId)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Context(val contextId: Context.ContextId) {
Decode.decodeArchiveFromInputStream(archive.newInput)
}.toMap
extPackages ++= newPackages
defns ++= Compiler(extPackages).compilePackages(extPackages.keys, !omitValidation)
defns ++= Compiler.compilePackages(extPackages, !omitValidation).right.get

// And now the new modules can be loaded.
val lfModules = loadModules.map(module =>
Expand All @@ -131,7 +131,7 @@ class Context(val contextId: Context.ContextId) {
++ m.definitions.flatMap {
case (defName, defn) =>
compiler
.compileDefn(Identifier(homePackageId, QualifiedName(m.name, defName)), defn)
.unsafeCompileDefn(Identifier(homePackageId, QualifiedName(m.name, defName)), defn)
})
}

Expand All @@ -154,7 +154,7 @@ class Context(val contextId: Context.ContextId) {
.build(
checkSubmitterInMaintainers = false,
sexpr = defn,
compiledPackages = PureCompiledPackages(allPackages, defns).right.get,
compiledPackages = PureCompiledPackages(allPackages, defns),
submissionTime,
initialSeeding,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ final class ConcurrentCompiledPackages extends MutableCompiledPackages {
_packages.computeIfAbsent(
pkgId, { _ =>
// Compile the speedy definitions for this package.
val defns = speedy.Compiler(packages orElse state.packages).compilePackage(pkgId)
for ((defnId, defn) <- defns) {
_defns.put(defnId, defn)
val defns =
speedy.Compiler(packages orElse state.packages).unsafeCompilePackage(pkgId)
defns.foreach {
case (defnId, defn) => _defns.put(defnId, defn)
}
// Compute the transitive dependencies of the new package. Since we are adding
// packages in dependency order we can just union the dependencies of the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ final class Engine {
val machine = Machine
.build(
checkSubmitterInMaintainers = checkSubmitterInMaintainers,
sexpr = Compiler(compiledPackages.packages).compile(commands),
sexpr = Compiler(compiledPackages.packages).unsafeCompile(commands),
compiledPackages = compiledPackages,
submissionTime = submissionTime,
seeds = seeding,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,12 @@ object PureCompiledPackages {
def apply(
packages: Map[PackageId, Package],
defns: Map[SDefinitionRef, SExpr],
): Either[String, PureCompiledPackages] = {
Right(new PureCompiledPackages(packages, defns))
}
): PureCompiledPackages =
new PureCompiledPackages(packages, defns)

def apply(packages: Map[PackageId, Package]): Either[String, PureCompiledPackages] =
Compiler
.compilePackages(packages)
.map(new PureCompiledPackages(packages, _))

def apply(packages: Map[PackageId, Package]): Either[String, PureCompiledPackages] = {
apply(packages, Compiler(packages).compilePackages(packages.keys))
}
}
Loading

0 comments on commit 7bdde70

Please sign in to comment.