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

Let stable packages bypass LF version restrictions. #10377

Merged
merged 16 commits into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -12,7 +12,7 @@ import com.daml.lf.archive
import com.daml.lf.data.{assertRight, ImmArray}
import com.daml.lf.data.Ref.{DottedName, Identifier, ModuleName, PackageId, QualifiedName}
import com.daml.lf.engine.script.ledgerinteraction.{IdeLedgerClient, ScriptTimeMode}
import com.daml.lf.language.{Ast, LanguageVersion, Util => AstUtil}
import com.daml.lf.language.{Ast, LanguageVersion, Util => AstUtil, StablePackages}
import com.daml.lf.scenario.api.v1.{ScenarioModule => ProtoScenarioModule}
import com.daml.lf.speedy.{Compiler, SDefinition, SExpr, Speedy}
import com.daml.lf.speedy.SExpr.{LfDefRef, SDefinitionRef}
Expand Down Expand Up @@ -41,6 +41,7 @@ object Context {
private val compilerConfig =
Compiler.Config(
allowedLanguageVersions = LanguageVersion.DevVersions,
allowedStablePackages = StablePackages.ids,
packageValidation = Compiler.FullPackageValidation,
profiling = Compiler.NoProfile,
stacktracing = Compiler.FullStackTrace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import com.daml.lf.transaction.Node._
import com.daml.lf.value.Value
import java.nio.file.Files

import com.daml.lf.language.{Interface, LanguageVersion}
import com.daml.lf.language.{Interface, LanguageVersion, StablePackages}
import com.daml.lf.validation.Validation
import com.daml.lf.value.Value.ContractId
import com.daml.nameof.NameOf
Expand Down Expand Up @@ -50,7 +50,9 @@ import com.daml.nameof.NameOf
*
* This class is thread safe as long `nextRandomInt` is.
*/
class Engine(val config: EngineConfig = new EngineConfig(LanguageVersion.StableVersions)) {
class Engine(
val config: EngineConfig = new EngineConfig(LanguageVersion.StableVersions, StablePackages.ids)
) {

config.profileDir.foreach(Files.createDirectories(_))

Expand Down Expand Up @@ -452,7 +454,9 @@ class Engine(val config: EngineConfig = new EngineConfig(LanguageVersion.StableV
for {
_ <- pkgs
.collectFirst {
case (pkgId, pkg) if !config.allowedLanguageVersions.contains(pkg.languageVersion) =>
case (pkgId, pkg)
if !config.allowedStablePackages.contains(pkgId) && !config.allowedLanguageVersions
.contains(pkg.languageVersion) =>
Error.Package.AllowedLanguageVersion(
pkgId,
pkg.languageVersion,
Expand Down Expand Up @@ -512,7 +516,9 @@ object Engine {
}
}

def DevEngine(): Engine = new Engine(new EngineConfig(LanguageVersion.DevVersions))
def DevEngine(): Engine = new Engine(
new EngineConfig(LanguageVersion.DevVersions, StablePackages.ids)
)

def StableEngine(): Engine = new Engine()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package engine
import java.nio.file.Path

import com.daml.lf.transaction.ContractKeyUniquenessMode
import com.daml.lf.data.Ref.PackageId
import com.daml.lf.language.{LanguageVersion, StablePackages}

/** The Engine configurations describes the versions of language and
* transaction the engine is allowed to read and write together with
Expand All @@ -17,14 +19,18 @@ import com.daml.lf.transaction.ContractKeyUniquenessMode
* @param allowedLanguageVersions The range of language versions the
* engine is allowed to load. The engine will crash if it asked
* to load a language version that is not included in this range.
* @param allowedStablePackages The set of stable packages that are
* allowed regardless of the allowed language version. This set
* of packages bypass the language version checks.
* @param stackTraceMode The flag enables the runtime support for
* stack trace.
* @param profileDir The optional specifies the directory where to
* save the output of the Daml scenario profiler. The profiler is
* disabled if the option is empty.
*/
final case class EngineConfig(
allowedLanguageVersions: VersionRange[language.LanguageVersion],
allowedLanguageVersions: VersionRange[LanguageVersion],
allowedStablePackages: Set[PackageId] = StablePackages.ids,
packageValidation: Boolean = true,
stackTraceMode: Boolean = false,
profileDir: Option[Path] = None,
Expand All @@ -34,6 +40,7 @@ final case class EngineConfig(
private[lf] def getCompilerConfig: speedy.Compiler.Config =
speedy.Compiler.Config(
allowedLanguageVersions,
allowedStablePackages,
packageValidation =
if (packageValidation)
speedy.Compiler.FullPackageValidation
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}
import com.daml.lf.language.{LanguageVersion, LookupError, Interface, 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 @@ -59,6 +59,7 @@ private[lf] object Compiler {

case class Config(
allowedLanguageVersions: VersionRange[LanguageVersion],
allowedStablePackages: Set[PackageId],
packageValidation: PackageValidationMode,
profiling: ProfilingMode,
stacktracing: StackTraceMode,
Expand All @@ -67,12 +68,14 @@ private[lf] object Compiler {
object Config {
val Default = Config(
allowedLanguageVersions = LanguageVersion.StableVersions,
allowedStablePackages = StablePackages.ids,
packageValidation = FullPackageValidation,
profiling = NoProfile,
stacktracing = NoStackTrace,
)
val Dev = Config(
allowedLanguageVersions = LanguageVersion.DevVersions,
allowedStablePackages = StablePackages.ids,
packageValidation = FullPackageValidation,
profiling = NoProfile,
stacktracing = NoStackTrace,
Expand Down Expand Up @@ -346,7 +349,9 @@ private[lf] final class Compiler(
val t0 = Time.Timestamp.now()

interface.lookupPackage(pkgId) match {
case Right(pkg) if !config.allowedLanguageVersions.contains(pkg.languageVersion) =>
case Right(pkg)
if !config.allowedStablePackages.contains(pkgId) && !config.allowedLanguageVersions
.contains(pkg.languageVersion) =>
throw LanguageVersionError(pkgId, pkg.languageVersion, config.allowedLanguageVersions)
case _ =>
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package com.daml.lf.language

import com.daml.lf.data.Ref.{PackageId, PackageName}

object StablePackages {
// Based on compiler/damlc/tests/src/stable-packages.sh
// TODO: Use this map to generate the mapping used in the test,
miklos-da marked this conversation as resolved.
Show resolved Hide resolved
// or generate both from a single source.
val map = Map[PackageName, PackageId](
sofiafaro-da marked this conversation as resolved.
Show resolved Hide resolved
PackageName.assertFromString(
"daml-prim-DA-Exception-ArithmeticError-cb0552debf219cc909f51cbb5c3b41e9981d39f8f645b1f35e2ef5be2e0b858a"
) -> PackageId.assertFromString(
"cb0552debf219cc909f51cbb5c3b41e9981d39f8f645b1f35e2ef5be2e0b858a"
),
PackageName.assertFromString(
"daml-prim-DA-Exception-AssertionFailed-3f4deaf145a15cdcfa762c058005e2edb9baa75bb7f95a4f8f6f937378e86415"
) -> PackageId.assertFromString(
"3f4deaf145a15cdcfa762c058005e2edb9baa75bb7f95a4f8f6f937378e86415"
),
PackageName.assertFromString(
"daml-prim-DA-Exception-GeneralError-86828b9843465f419db1ef8a8ee741d1eef645df02375ebf509cdc8c3ddd16cb"
) -> PackageId.assertFromString(
"86828b9843465f419db1ef8a8ee741d1eef645df02375ebf509cdc8c3ddd16cb"
),
PackageName.assertFromString(
"daml-prim-DA-Exception-PreconditionFailed-f20de1e4e37b92280264c08bf15eca0be0bc5babd7a7b5e574997f154c00cb78"
) -> PackageId.assertFromString(
"f20de1e4e37b92280264c08bf15eca0be0bc5babd7a7b5e574997f154c00cb78"
),
PackageName.assertFromString(
"daml-prim-DA-Internal-Erased-76bf0fd12bd945762a01f8fc5bbcdfa4d0ff20f8762af490f8f41d6237c6524f"
) -> PackageId.assertFromString(
"76bf0fd12bd945762a01f8fc5bbcdfa4d0ff20f8762af490f8f41d6237c6524f"
),
PackageName.assertFromString(
"daml-prim-DA-Internal-PromotedText-d58cf9939847921b2aab78eaa7b427dc4c649d25e6bee3c749ace4c3f52f5c97"
) -> PackageId.assertFromString(
"d58cf9939847921b2aab78eaa7b427dc4c649d25e6bee3c749ace4c3f52f5c97"
),
PackageName.assertFromString(
"daml-prim-DA-Types-40f452260bef3f29dede136108fc08a88d5a5250310281067087da6f0baddff7"
) -> PackageId.assertFromString(
"40f452260bef3f29dede136108fc08a88d5a5250310281067087da6f0baddff7"
),
PackageName.assertFromString(
"daml-prim-GHC-Prim-e491352788e56ca4603acc411ffe1a49fefd76ed8b163af86cf5ee5f4c38645b"
) -> PackageId.assertFromString(
"e491352788e56ca4603acc411ffe1a49fefd76ed8b163af86cf5ee5f4c38645b"
),
PackageName.assertFromString(
"daml-prim-GHC-Tuple-6839a6d3d430c569b2425e9391717b44ca324b88ba621d597778811b2d05031d"
) -> PackageId.assertFromString(
"6839a6d3d430c569b2425e9391717b44ca324b88ba621d597778811b2d05031d"
),
PackageName.assertFromString(
"daml-prim-GHC-Types-518032f41fd0175461b35ae0c9691e08b4aea55e62915f8360af2cc7a1f2ba6c"
) -> PackageId.assertFromString(
"518032f41fd0175461b35ae0c9691e08b4aea55e62915f8360af2cc7a1f2ba6c"
),
PackageName.assertFromString(
"daml-stdlib-DA-Date-Types-bfcd37bd6b84768e86e432f5f6c33e25d9e7724a9d42e33875ff74f6348e733f"
) -> PackageId.assertFromString(
"bfcd37bd6b84768e86e432f5f6c33e25d9e7724a9d42e33875ff74f6348e733f"
),
PackageName.assertFromString(
"daml-stdlib-DA-Internal-Any-cc348d369011362a5190fe96dd1f0dfbc697fdfd10e382b9e9666f0da05961b7"
) -> PackageId.assertFromString(
"cc348d369011362a5190fe96dd1f0dfbc697fdfd10e382b9e9666f0da05961b7"
),
PackageName.assertFromString(
"daml-stdlib-DA-Internal-Down-057eed1fd48c238491b8ea06b9b5bf85a5d4c9275dd3f6183e0e6b01730cc2ba"
) -> PackageId.assertFromString(
"057eed1fd48c238491b8ea06b9b5bf85a5d4c9275dd3f6183e0e6b01730cc2ba"
),
PackageName.assertFromString(
"daml-stdlib-DA-Internal-Template-d14e08374fc7197d6a0de468c968ae8ba3aadbf9315476fd39071831f5923662"
) -> PackageId.assertFromString(
"d14e08374fc7197d6a0de468c968ae8ba3aadbf9315476fd39071831f5923662"
),
PackageName.assertFromString(
"daml-stdlib-DA-Logic-Types-c1f1f00558799eec139fb4f4c76f95fb52fa1837a5dd29600baa1c8ed1bdccfd"
) -> PackageId.assertFromString(
"c1f1f00558799eec139fb4f4c76f95fb52fa1837a5dd29600baa1c8ed1bdccfd"
),
PackageName.assertFromString(
"daml-stdlib-DA-Monoid-Types-6c2c0667393c5f92f1885163068cd31800d2264eb088eb6fc740e11241b2bf06"
) -> PackageId.assertFromString(
"6c2c0667393c5f92f1885163068cd31800d2264eb088eb6fc740e11241b2bf06"
),
PackageName.assertFromString(
"daml-stdlib-DA-NonEmpty-Types-e22bce619ae24ca3b8e6519281cb5a33b64b3190cc763248b4c3f9ad5087a92c"
) -> PackageId.assertFromString(
"e22bce619ae24ca3b8e6519281cb5a33b64b3190cc763248b4c3f9ad5087a92c"
),
PackageName.assertFromString(
"daml-stdlib-DA-Semigroup-Types-8a7806365bbd98d88b4c13832ebfa305f6abaeaf32cfa2b7dd25c4fa489b79fb"
) -> PackageId.assertFromString(
"8a7806365bbd98d88b4c13832ebfa305f6abaeaf32cfa2b7dd25c4fa489b79fb"
),
PackageName.assertFromString(
"daml-stdlib-DA-Set-Types-97b883cd8a2b7f49f90d5d39c981cf6e110cf1f1c64427a28a6d58ec88c43657"
) -> PackageId.assertFromString(
"97b883cd8a2b7f49f90d5d39c981cf6e110cf1f1c64427a28a6d58ec88c43657"
),
PackageName.assertFromString(
"daml-stdlib-DA-Time-Types-733e38d36a2759688a4b2c4cec69d48e7b55ecc8dedc8067b815926c917a182a"
) -> PackageId.assertFromString(
"733e38d36a2759688a4b2c4cec69d48e7b55ecc8dedc8067b815926c917a182a"
),
PackageName.assertFromString(
"daml-stdlib-DA-Validation-Types-99a2705ed38c1c26cbb8fe7acf36bbf626668e167a33335de932599219e0a235"
) -> PackageId.assertFromString(
"99a2705ed38c1c26cbb8fe7acf36bbf626668e167a33335de932599219e0a235"
),
)
val ids = map.values.toSet
sofiafaro-da marked this conversation as resolved.
Show resolved Hide resolved
}
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.{Interface, LanguageVersion => LV, StablePackages}
import java.io.{File, PrintWriter, StringWriter}
import java.nio.file.{Path, Paths}
import java.io.PrintStream
Expand Down Expand Up @@ -83,6 +83,7 @@ object Repl {
val defaultCompilerConfig: Compiler.Config =
Compiler.Config(
allowedLanguageVersions = LV.StableVersions,
allowedStablePackages = StablePackages.ids,
packageValidation = Compiler.FullPackageValidation,
profiling = Compiler.NoProfile,
stacktracing = Compiler.FullStackTrace,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import com.daml.lf.engine.script.ledgerinteraction.{
import com.daml.lf.iface.EnvironmentInterface
import com.daml.lf.iface.reader.InterfaceReader
import com.daml.lf.language.Ast._
import com.daml.lf.language.{Interface, LanguageVersion}
import com.daml.lf.language.{Interface, LanguageVersion, StablePackages}
import com.daml.lf.interpretation.{Error => IE}
import com.daml.lf.speedy.SBuiltin.SBToAny
import com.daml.lf.speedy.SExpr._
Expand Down Expand Up @@ -214,6 +214,7 @@ object Runner {
Config(
// FIXME: Should probably not include 1.dev by default.
allowedLanguageVersions = LanguageVersion.DevVersions,
allowedStablePackages = StablePackages.ids,
packageValidation = FullPackageValidation,
profiling = NoProfile,
stacktracing = FullStackTrace,
Expand Down