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

Drop LF < 1.14 from supported damlc output versions #11701

Merged
merged 4 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
3 changes: 2 additions & 1 deletion compiler/damlc/tests/daml-test-files/NextSet.daml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
-- 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not dropping this line as done in the previous file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed that 5a3ba1e

-- @UNTIL-LF-FEATURE DAML_GENMAP

module NextSet where

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
5 changes: 4 additions & 1 deletion daml-lf/language/daml-lf.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,12 @@ 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 = ENCODER_LF_VERSIONS
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also contains 1.14 and 1.dev, should it?

Maybe we should hardcode the list of versions supported by the legacy compiler, since it presumably isn't going to keep up with new LF versions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking off this more as legacy + newer versions, i.e., everything we can build in daml_build bazel rules. Very happy for suggestions for better names.


# 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 ["1.6", "1.7", "1.8", "1.11", "1.12", "1.13"]]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not using the comparator defined at line

Suggested change
COMPILER_LF_VERSIONS = [ver for ver in ENCODER_LF_VERSIONS if ver not in ["1.6", "1.7", "1.8", "1.11", "1.12", "1.13"]]
COMPILER_LF_VERSIONS = [ver for ver in ENCODER_LF_VERSIONS if _gte(ver,"1.14") ]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed the code already

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The list ["1.6", "1.7", "1.8", "1.11", "1.12", "1.13"] is what I expected LEGACY_COMPILER_LF_VERSIONS to be.

If so you could rewrite this as [ver for ver in ENCODER_LF_VERSIONS if ver not in LEGACY_COMPILER_LF_VERSIONS].

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed it to that and added all_compiler_lf_versions corresponding to the previous behavior

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!


# 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"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need this definition anymore ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch, killed it b356687

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
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ class DependenciesSpec extends AnyFreeSpec with Matchers {
targetLfVersion(Seq.empty) shouldBe None
}
"single DALF" in {
targetLfVersion(Seq(v1_11)) shouldBe Some(v1_11)
targetLfVersion(Seq(v1_14)) shouldBe Some(v1_14)
}
"multiple DALFs" in {
targetLfVersion(Seq(v1_8, v1_11, v1_12)) shouldBe Some(v1_12)
targetLfVersion(Seq(v1_14, v1_dev)) shouldBe Some(v1_dev)
}
"should be at least 1.7" in {
targetLfVersion(Seq(v1_6)) shouldBe Some(v1_7)
"should be at least 1.14" in {
targetLfVersion(Seq(v1_6)) shouldBe Some(v1_14)
}
}
"targetFlag" - {
"1.12" in {
targetFlag(v1_12) shouldBe "--target=1.12"
"1.14" in {
targetFlag(v1_14) shouldBe "--target=1.14"
}
"1.dev" in {
targetFlag(v1_dev) shouldBe "--target=1.dev"
Expand Down
Loading