Skip to content

Commit

Permalink
Drop LF < 1.14 from supported damlc output versions (#11701)
Browse files Browse the repository at this point in the history
* Drop LF < 1.14 from supported damlc output versions

fixes #11319

We keep test coverage by depending on the most recent snapshot which
still has 1.14 support.

changelog_begin

- [Daml Compiler] Damlc can only produce Daml-LF 1.14 or
  newer. Passing aynthing older to `--target` is an error. If you
  need to produce older versions, use an older SDK.

changelog_end

* Switch around legacy_compiler_lf_versions

changelog_begin
changelog_end

* drop since-lf

changelog_begin
changelog_end
  • Loading branch information
cocreature authored Nov 22, 2021
1 parent ae8391e commit 5785bbf
Show file tree
Hide file tree
Showing 29 changed files with 642 additions and 74 deletions.
12 changes: 12 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,18 @@ dev_env_nix_repos = {
"nixpkgs": "@nixpkgs",
}

load("//bazel_tools:damlc_legacy.bzl", "damlc_legacy")

damlc_legacy(
name = "damlc_legacy",
sha256 = {
"linux": "dd1c7f2d34f3eac631c7edc1637c9b3e93c341561d41828b4f0d8e897effa90f",
"windows": "f458b8d2612887915372aad61766120e34c0fdc6a65eb37cdb1a8efc58e14de3",
"macos": "63141d7168e883c0b8c212dca6198f5463f82aa82bbbc51d8805ce7e474300e4",
},
version = "1.18.0-snapshot.20211117.8399.0.a05a40ae",
)

# Bazel cannot automatically determine which files a Nix target depends on.
# rules_nixpkgs offers the nix_file_deps attribute for that purpose. It should
# list all files that a target depends on. This allows Bazel to rebuild the
Expand Down
64 changes: 64 additions & 0 deletions bazel_tools/damlc_legacy.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0

load("@os_info//:os_info.bzl", "is_windows", "os_name")
load("@io_bazel_rules_scala//scala:scala_cross_version.bzl", "default_maven_server_urls")

runfiles_library = """
# Copy-pasted from the Bazel Bash runfiles library v2.
set -uo pipefail; f=bazel_tools/tools/bash/runfiles/runfiles.bash
source "${RUNFILES_DIR:-/dev/null}/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "${RUNFILES_MANIFEST_FILE:-/dev/null}" | cut -f2- -d' ')" 2>/dev/null || \
source "$0.runfiles/$f" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
source "$(grep -sm1 "^$f " "$0.exe.runfiles_manifest" | cut -f2- -d' ')" 2>/dev/null || \
{ echo>&2 "ERROR: cannot find $f"; exit 1; }; f=; set -e
# --- end runfiles.bash initialization v2 ---
"""

def _damlc_legacy_impl(ctx):
out_dir = ctx.path("damlc")

ctx.download_and_extract(
output = out_dir,
url = "https://github.com/digital-asset/daml/releases/download/v{}/daml-sdk-{}-{}.tar.gz".format(ctx.attr.version, ctx.attr.version, ctx.attr.os_name),
sha256 = ctx.attr.sha256[ctx.attr.os_name],
stripPrefix = "sdk-{}/damlc".format(ctx.attr.version),
)

ctx.file(
"damlc.sh",
content =
"""#!/usr/bin/env bash
{runfiles_library}
$(rlocation damlc_legacy/damlc/damlc.exe) $@
""".format(runfiles_library = runfiles_library),
) if is_windows else None

ctx.file(
"BUILD",
content =
"""
load("@os_info//:os_info.bzl", "is_windows")
package(default_visibility = ["//visibility:public"])
sh_binary(
name = "damlc_legacy",
srcs = [":damlc/damlc"],
) if not is_windows else sh_binary(
name = "damlc_legacy",
srcs = [":damlc.sh"],
deps = ["@bazel_tools//tools/bash/runfiles"],
data = ["damlc/damlc.exe"],
)
""".format(version = ctx.attr.version),
)
return None

damlc_legacy = repository_rule(
implementation = _damlc_legacy_impl,
attrs = {
"version": attr.string(mandatory = True),
"os_name": attr.string(mandatory = False, default = os_name),
"sha256": attr.string_dict(mandatory = True),
},
)
4 changes: 2 additions & 2 deletions compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ versionDev :: Version
versionDev = V1 PointDev

supportedOutputVersions :: [Version]
supportedOutputVersions = [version1_6, version1_7, version1_8, version1_11, version1_12, version1_13, version1_14, versionDev]
supportedOutputVersions = [version1_14, versionDev]

supportedInputVersions :: [Version]
supportedInputVersions = supportedOutputVersions
supportedInputVersions = [version1_6, version1_7, version1_8, version1_11, version1_12, version1_13] ++ supportedOutputVersions


data Feature = Feature
Expand Down
1 change: 1 addition & 0 deletions compiler/damlc/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ da_haskell_test(
srcs = ["src/DA/Test/DataDependencies.hs"],
data = [
"//compiler/damlc",
"@damlc_legacy",
"//compiler/damlc/tests:generate-simple-dalf",
"//daml-lf/repl",
"@davl-v3//:released/davl-v3.dar",
Expand Down
5 changes: 2 additions & 3 deletions compiler/damlc/tests/daml-test-files/NextMap.daml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
-- We test for deprecations in NextMapDeprecated
{-# OPTIONS -Wno-deprecations #-}
-- Copyright (c) 2020, Digital Asset (Switzerland) GmbH and/or its affiliates.
-- All rights reserved.
-- @ERROR could not parse ""notaparty"" as 'Party'
-- @ERROR could not parse "not-an-int" as 'Int'
-- @ERROR could not parse "not-a-decimal" as 'Decimal'
-- @SINCE-LF 1.3
-- @UNTIL-LF-FEATURE DAML_GENMAP

module NextMap where

import DA.Next.Map as M
Expand Down
5 changes: 2 additions & 3 deletions compiler/damlc/tests/daml-test-files/NextSet.daml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
-- We test for deprecations in NextMapDeprecated
{-# OPTIONS -Wno-deprecations #-}
-- Copyright (c) 2020, Digital Asset (Switzerland) GmbH and/or its affiliates.
-- All rights reserved.

-- @SINCE-LF 1.3
-- @UNTIL-LF-FEATURE DAML_GENMAP

module NextSet where

import DA.Next.Set as S
Expand Down
33 changes: 22 additions & 11 deletions compiler/damlc/tests/src/DA/Test/DataDependencies.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import DA.Daml.StablePackages (numStablePackagesForVersion)
import DA.Test.Process
import DA.Test.Util
import qualified Data.ByteString.Lazy as BSL
import Data.List (sort)
import Data.List (sort, (\\))
import qualified Data.NameMap as NM
import Module (unitIdString)
import System.Directory.Extra
Expand All @@ -30,6 +30,7 @@ main :: IO ()
main = do
setEnv "TASTY_NUM_THREADS" "3" True
damlc <- locateRunfiles (mainWorkspace </> "compiler" </> "damlc" </> exe "damlc")
damlcLegacy <- locateRunfiles ("damlc_legacy" </> exe "damlc_legacy")
repl <- locateRunfiles (mainWorkspace </> "daml-lf" </> "repl" </> exe "repl")
davlDar <- locateRunfiles ("davl-v3" </> "released" </> "davl-v3.dar")
oldProjDar <- locateRunfiles (mainWorkspace </> "compiler" </> "damlc" </> "tests" </> "dars" </> "old-proj-0.13.55-snapshot.20200309.3401.0.6f8c3ad8-1.8.dar")
Expand All @@ -38,27 +39,37 @@ main = do

data Tools = Tools -- and places
{ damlc :: FilePath
, damlcLegacy :: FilePath
, repl :: FilePath
, validate :: FilePath -> IO ()
, davlDar :: FilePath
, oldProjDar :: FilePath
}

damlcForTarget :: Tools -> LF.Version -> FilePath
damlcForTarget Tools{damlc, damlcLegacy} target
| target `elem` LF.supportedOutputVersions = damlc
| otherwise = damlcLegacy

darPackageIds :: FilePath -> IO [LF.PackageId]
darPackageIds fp = do
archive <- Zip.toArchive <$> BSL.readFile fp
Dalfs mainDalf dalfDeps <- either fail pure $ readDalfs archive
Right dalfPkgIds <- pure $ mapM (LFArchive.decodeArchivePackageId . BSL.toStrict) $ mainDalf : dalfDeps
pure dalfPkgIds

-- | Sequential LF version pairs, with an additional (1.dev, 1.dev) pair at the end.
sequentialVersionPairs :: [(LF.Version, LF.Version)]
sequentialVersionPairs =
let versions = sort LF.supportedOutputVersions ++ [LF.versionDev]
in zip versions (tail versions)
-- | We test two sets of versions:
-- 1. Versions no longer supported as output versions by damlc are tested against
-- 1.14.
-- 2. For all other versions we test them against the next version + an extra (1.dev, 1.dev) pair.
lfVersionTestPairs :: [(LF.Version, LF.Version)]
lfVersionTestPairs =
let legacyPairs = map (, LF.version1_14) (LF.supportedInputVersions \\ LF.supportedOutputVersions)
versions = sort LF.supportedOutputVersions ++ [LF.versionDev]
in legacyPairs ++ zip versions (tail versions)

tests :: Tools -> TestTree
tests Tools{damlc,repl,validate,davlDar,oldProjDar} = testGroup "Data Dependencies" $
tests tools@Tools{damlc,repl,validate,davlDar,oldProjDar} = testGroup "Data Dependencies" $
[ testCaseSteps ("Cross DAML-LF version: " <> LF.renderVersion depLfVer <> " -> " <> LF.renderVersion targetLfVer) $ \step -> withTempDir $ \tmpDir -> do
let proja = tmpDir </> "proja"
let projb = tmpDir </> "projb"
Expand Down Expand Up @@ -91,7 +102,7 @@ tests Tools{damlc,repl,validate,davlDar,oldProjDar} = testGroup "Data Dependenci
, "source: src"
, "dependencies: [daml-prim, daml-stdlib]"
]
callProcessSilent damlc
callProcessSilent (damlcForTarget tools depLfVer)
["build"
, "--project-root", proja
, "--target", LF.renderVersion depLfVer
Expand Down Expand Up @@ -143,7 +154,7 @@ tests Tools{damlc,repl,validate,davlDar,oldProjDar} = testGroup "Data Dependenci
- numStablePackagesForVersion depLfVer ) + -- new stable packages
1 + -- projb
(if targetLfVer /= depLfVer then 2 else 0) -- different daml-stdlib/daml-prim
| (depLfVer, targetLfVer) <- sequentialVersionPairs
| (depLfVer, targetLfVer) <- lfVersionTestPairs
] <>
[ testCaseSteps "Cross-SDK dependency on DAVL" $ \step -> withTempDir $ \tmpDir -> do
step "Building DAR"
Expand Down Expand Up @@ -642,7 +653,7 @@ tests Tools{damlc,repl,validate,davlDar,oldProjDar} = testGroup "Data Dependenci
, "source: src"
, "dependencies: [daml-prim, daml-stdlib]"
]
callProcessSilent damlc
callProcessSilent (damlcForTarget tools depLfVer)
[ "build"
, "--project-root", proja
, "--target", LF.renderVersion depLfVer
Expand Down Expand Up @@ -736,7 +747,7 @@ tests Tools{damlc,repl,validate,davlDar,oldProjDar} = testGroup "Data Dependenci
]
validate $ projb </> "projb.dar"

| (depLfVer, targetLfVer) <- sequentialVersionPairs
| (depLfVer, targetLfVer) <- lfVersionTestPairs
, LF.supports depLfVer LF.featureTypeSynonyms -- only test for new-style typeclasses
] <>
[ testCase "Cross-SDK typeclasses" $ withTempDir $ \tmpDir -> do
Expand Down
18 changes: 9 additions & 9 deletions compiler/damlc/tests/src/DA/Test/Packaging.hs
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ tests Tools{damlc} = testGroup "Packaging" $
, "name: a"
, "source: ."
, "dependencies: [daml-prim, daml-stdlib]"
, "build-options: [--target=1.8]"
, "build-options: [--target=1.dev]"
]
writeFileUTF8 (tmpDir </> "a" </> "A.daml") $ unlines
[ "module A where"
Expand All @@ -633,13 +633,13 @@ tests Tools{damlc} = testGroup "Packaging" $
, " - daml-stdlib"
, "data-dependencies:"
, " - " <> show (tmpDir </> "a" </> "a.dar")
, "build-options: [--target=1.7]"
, "build-options: [--target=1.14]"
]
writeFileUTF8 (tmpDir </> "b" </> "B.daml") $ unlines
[ "module B where"
, "import A ()"
]
buildProjectError (tmpDir </> "b") "" "Targeted LF version 1.7 but dependencies have newer LF versions"
buildProjectError (tmpDir </> "b") "" "Targeted LF version 1.14 but dependencies have newer LF versions"

, testCaseSteps "Error on newer LF dependency" $ \step -> withTempDir $ \tmpDir -> do
step "Building 'a"
Expand All @@ -650,7 +650,7 @@ tests Tools{damlc} = testGroup "Packaging" $
, "name: a"
, "source: ."
, "dependencies: [daml-prim, daml-stdlib]"
, "build-options: [--target=1.8]"
, "build-options: [--target=1.dev]"
]
writeFileUTF8 (tmpDir </> "a" </> "A.daml") $ unlines
[ "module A where"
Expand All @@ -668,13 +668,13 @@ tests Tools{damlc} = testGroup "Packaging" $
, " - daml-prim"
, " - daml-stdlib"
, " - " <> show (tmpDir </> "a" </> "a.dar")
, "build-options: [--target=1.7]"
, "build-options: [--target=1.14]"
]
writeFileUTF8 (tmpDir </> "b" </> "B.daml") $ unlines
[ "module B where"
, "import A ()"
]
buildProjectError (tmpDir </> "b") "" "Targeted LF version 1.7 but dependencies have different LF versions"
buildProjectError (tmpDir </> "b") "" "Targeted LF version 1.14 but dependencies have different LF versions"

, testCaseSteps "Error on inconsistent LF dependency" $ \step -> withTempDir $ \tmpDir -> do
step "Building 'a"
Expand All @@ -685,7 +685,7 @@ tests Tools{damlc} = testGroup "Packaging" $
, "name: a"
, "source: ."
, "dependencies: [daml-prim, daml-stdlib]"
, "build-options: [--target=1.6]"
, "build-options: [--target=1.14]"
]
writeFileUTF8 (tmpDir </> "a" </> "A.daml") $ unlines
[ "module A where"
Expand All @@ -703,13 +703,13 @@ tests Tools{damlc} = testGroup "Packaging" $
, " - daml-prim"
, " - daml-stdlib"
, " - " <> show (tmpDir </> "a" </> "a.dar")
, "build-options: [--target=1.7]"
, "build-options: [--target=1.dev]"
]
writeFileUTF8 (tmpDir </> "b" </> "B.daml") $ unlines
[ "module B where"
, "import A ()"
]
buildProjectError (tmpDir </> "b") "" "Targeted LF version 1.7 but dependencies have different LF versions"
buildProjectError (tmpDir </> "b") "" "Targeted LF version 1.dev but dependencies have different LF versions"

, testCase "build-options + project-root" $ withTempDir $ \projDir -> do
createDirectoryIfMissing True (projDir </> "src")
Expand Down
8 changes: 5 additions & 3 deletions daml-lf/language/daml-lf.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ PROTO_LF_VERSIONS = LF_VERSIONS
# The subset of LF versions accepted by //daml-lf/encoder
ENCODER_LF_VERSIONS = ["1.dev" if ver == "dev" else ver for ver in LF_VERSIONS]

# We support older LF versions using an older compiler binary
LEGACY_COMPILER_LF_VERSIONS = ["1.6", "1.7", "1.8", "1.11", "1.12", "1.13"]

# The subset of LF versions accepted by the compiler in the syntax
# expected by the --target option.
COMPILER_LF_VERSIONS = ENCODER_LF_VERSIONS
COMPILER_LF_VERSIONS = [ver for ver in ENCODER_LF_VERSIONS if ver not in LEGACY_COMPILER_LF_VERSIONS]

# We need Any in DAML Script so we require DAML-LF >= 1.7
SCRIPT_LF_VERSIONS = [ver for ver in COMPILER_LF_VERSIONS if ver != "1.6"]
ALL_COMPILER_LF_VERSIONS = LEGACY_COMPILER_LF_VERSIONS + COMPILER_LF_VERSIONS

LF_VERSION_PACKAGE_DIGITALASSET = {
"1.6": "digitalasset",
Expand Down
6 changes: 3 additions & 3 deletions daml-script/daml/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# TODO Once daml_compile uses build instead of package we should use
# daml_compile instead of a genrule.
load("@build_environment//:configuration.bzl", "ghc_version", "sdk_version")
load("//daml-lf/language:daml-lf.bzl", "SCRIPT_LF_VERSIONS")
load("//daml-lf/language:daml-lf.bzl", "COMPILER_LF_VERSIONS")

# Build one DAR per LF version to bundle with the SDK.
# Also build one DAR with the default LF version for test-cases.
Expand Down Expand Up @@ -46,15 +46,15 @@ EOF
tools = ["//compiler/damlc"],
visibility = ["//visibility:public"],
)
for lf_version in SCRIPT_LF_VERSIONS + [""]
for lf_version in COMPILER_LF_VERSIONS + [""]
for suffix in [("-" + lf_version) if lf_version else ""]
]

filegroup(
name = "daml-script-dars",
srcs = [
"daml-script-{}.dar".format(lf_version)
for lf_version in SCRIPT_LF_VERSIONS
for lf_version in COMPILER_LF_VERSIONS
],
visibility = ["//visibility:public"],
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ tmpdir=$$(mktemp -d)
trap "rm -rf $$tmpdir" EXIT
DAMLC=$$(canonicalize_rlocation $(rootpath //compiler/damlc))
unzip $$(canonicalize_rlocation $(rootpath :lf16-export.zip)) -d $$tmpdir
cp -L $$(canonicalize_rlocation $(rootpath //daml-script/daml:daml-script-1.7.dar)) $$tmpdir/
sed -i.bak 's/daml-script/daml-script-1.7.dar/' $$tmpdir/daml.yaml
cp -L $$(canonicalize_rlocation $(rootpath //daml-script/daml:daml-script-1.14.dar)) $$tmpdir/
sed -i.bak 's/daml-script/daml-script-1.14.dar/' $$tmpdir/daml.yaml
cat $$tmpdir/daml.yaml
DAML_PROJECT=$$tmpdir $$DAMLC build
""",
data = [
":lf16-export.zip",
"//compiler/damlc",
"//daml-script/daml:daml-script-1.7.dar",
"//daml-script/daml:daml-script-1.14.dar",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ object Dependencies {

/** The Daml-LF version to target based on the DALF dependencies.
*
* Chooses the latest LF version among the DALFs but at least 1.7 as that is the minimum required for Daml Script.
* Chooses the latest LF version among the DALFs but at least 1.14 as that is the minimum supported by damlc.
* Returns None if no DALFs are given.
*/
def targetLfVersion(dalfs: Iterable[LanguageVersion]): Option[LanguageVersion] = {
if (dalfs.isEmpty) { None }
else { Some((List(LanguageVersion.v1_7) ++ dalfs).max) }
else { Some((List(LanguageVersion.v1_14) ++ dalfs).max) }
}

def targetFlag(v: LanguageVersion): String =
Expand Down
Loading

0 comments on commit 5785bbf

Please sign in to comment.