From 11f1f51763f187d41b6f3573bb6c405aeb4c558b Mon Sep 17 00:00:00 2001 From: Moritz Kiefer Date: Mon, 15 Nov 2021 12:58:58 +0100 Subject: [PATCH 1/4] 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 --- WORKSPACE | 12 + bazel_tools/damlc_legacy.bzl | 64 +++++ .../daml-lf-ast/src/DA/Daml/LF/Ast/Version.hs | 4 +- compiler/damlc/tests/BUILD.bazel | 1 + .../damlc/tests/daml-test-files/NextMap.daml | 5 +- .../damlc/tests/daml-test-files/NextSet.daml | 3 +- .../tests/src/DA/Test/DataDependencies.hs | 33 ++- compiler/damlc/tests/src/DA/Test/Packaging.hs | 18 +- daml-lf/language/daml-lf.bzl | 5 +- .../export-lf-1.6/BUILD.bazel | 6 +- .../com/daml/script/export/Dependencies.scala | 4 +- .../daml/script/export/DependenciesSpec.scala | 12 +- language-support/java/codegen/BUILD.bazel | 20 +- .../src/it/java-1.14/com/daml/AllTests.java | 15 ++ .../src/it/java-1.14/com/daml/GenMapTest.java | 237 ++++++++++++++++++ .../it/java-1.14/com/daml/NumericTest.java | 196 +++++++++++++++ .../digitalasset/testing/AllTestsFor1_11.java | 4 +- .../digitalasset/testing/AllTestsFor1_12.java | 4 +- .../digitalasset/testing/AllTestsFor1_14.java | 16 ++ .../digitalasset/testing/AllTestsFor1_7.java | 2 +- .../digitalasset/testing/AllTestsFor1_8.java | 2 +- .../testing/AllTestsFor1_dev.java | 4 +- ...or1_12ndFor1_13AndFor1_14AndFor1_dev.java} | 2 +- ...or1_12ndFor1_13AndFor1_14AndFor1_dev.java} | 2 +- language-support/ts/codegen/tests/BUILD.bazel | 1 + .../ts/codegen/tests/src/DA/Test/Daml2js.hs | 14 +- rules_daml/daml.bzl | 13 +- 27 files changed, 635 insertions(+), 64 deletions(-) create mode 100644 bazel_tools/damlc_legacy.bzl create mode 100644 language-support/java/codegen/src/it/java-1.14/com/daml/AllTests.java create mode 100644 language-support/java/codegen/src/it/java-1.14/com/daml/GenMapTest.java create mode 100644 language-support/java/codegen/src/it/java-1.14/com/daml/NumericTest.java create mode 100644 language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_14.java rename language-support/java/codegen/src/test/java/com/digitalasset/testing/{GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_dev.java => GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_dev.java} (97%) rename language-support/java/codegen/src/test/java/com/digitalasset/testing/{NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_dev.java => NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_dev.java} (98%) diff --git a/WORKSPACE b/WORKSPACE index 96d7f3e073be..143fd5f298b6 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -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 diff --git a/bazel_tools/damlc_legacy.bzl b/bazel_tools/damlc_legacy.bzl new file mode 100644 index 000000000000..13de1ad3063d --- /dev/null +++ b/bazel_tools/damlc_legacy.bzl @@ -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), + }, +) diff --git a/compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Version.hs b/compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Version.hs index 5521f1eb1e53..974fee56dc0b 100644 --- a/compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Version.hs +++ b/compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Version.hs @@ -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 diff --git a/compiler/damlc/tests/BUILD.bazel b/compiler/damlc/tests/BUILD.bazel index 8159bdbe1d50..ef07d6bcd510 100644 --- a/compiler/damlc/tests/BUILD.bazel +++ b/compiler/damlc/tests/BUILD.bazel @@ -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", diff --git a/compiler/damlc/tests/daml-test-files/NextMap.daml b/compiler/damlc/tests/daml-test-files/NextMap.daml index dbe87d79d39b..1f07d40c29ae 100644 --- a/compiler/damlc/tests/daml-test-files/NextMap.daml +++ b/compiler/damlc/tests/daml-test-files/NextMap.daml @@ -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 diff --git a/compiler/damlc/tests/daml-test-files/NextSet.daml b/compiler/damlc/tests/daml-test-files/NextSet.daml index da6d23f69cf6..a3702bf572e5 100644 --- a/compiler/damlc/tests/daml-test-files/NextSet.daml +++ b/compiler/damlc/tests/daml-test-files/NextSet.daml @@ -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 --- @UNTIL-LF-FEATURE DAML_GENMAP module NextSet where diff --git a/compiler/damlc/tests/src/DA/Test/DataDependencies.hs b/compiler/damlc/tests/src/DA/Test/DataDependencies.hs index 7d80fcf3d5cb..03064f3dbb4d 100644 --- a/compiler/damlc/tests/src/DA/Test/DataDependencies.hs +++ b/compiler/damlc/tests/src/DA/Test/DataDependencies.hs @@ -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 @@ -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") @@ -38,12 +39,18 @@ 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 @@ -51,14 +58,18 @@ darPackageIds fp = do 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" @@ -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 @@ -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" @@ -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 @@ -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 diff --git a/compiler/damlc/tests/src/DA/Test/Packaging.hs b/compiler/damlc/tests/src/DA/Test/Packaging.hs index 00d490c1cd8e..99fad44771dc 100644 --- a/compiler/damlc/tests/src/DA/Test/Packaging.hs +++ b/compiler/damlc/tests/src/DA/Test/Packaging.hs @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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") diff --git a/daml-lf/language/daml-lf.bzl b/daml-lf/language/daml-lf.bzl index 09295a310311..1adb42220e0a 100644 --- a/daml-lf/language/daml-lf.bzl +++ b/daml-lf/language/daml-lf.bzl @@ -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 + # 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"]] # 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"] diff --git a/daml-script/export/integration-tests/export-lf-1.6/BUILD.bazel b/daml-script/export/integration-tests/export-lf-1.6/BUILD.bazel index 7f63eb121af3..844871262e9d 100644 --- a/daml-script/export/integration-tests/export-lf-1.6/BUILD.bazel +++ b/daml-script/export/integration-tests/export-lf-1.6/BUILD.bazel @@ -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", ], ) diff --git a/daml-script/export/src/main/scala/com/daml/script/export/Dependencies.scala b/daml-script/export/src/main/scala/com/daml/script/export/Dependencies.scala index 65ceca6c8722..650c3590eac2 100644 --- a/daml-script/export/src/main/scala/com/daml/script/export/Dependencies.scala +++ b/daml-script/export/src/main/scala/com/daml/script/export/Dependencies.scala @@ -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 = diff --git a/daml-script/export/src/test/scala/com/daml/script/export/DependenciesSpec.scala b/daml-script/export/src/test/scala/com/daml/script/export/DependenciesSpec.scala index c8e94d2b791b..37a97f4d9c21 100644 --- a/daml-script/export/src/test/scala/com/daml/script/export/DependenciesSpec.scala +++ b/daml-script/export/src/test/scala/com/daml/script/export/DependenciesSpec.scala @@ -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" diff --git a/language-support/java/codegen/BUILD.bazel b/language-support/java/codegen/BUILD.bazel index dcd2e287e168..f1d5d4f06d67 100644 --- a/language-support/java/codegen/BUILD.bazel +++ b/language-support/java/codegen/BUILD.bazel @@ -23,7 +23,7 @@ load( ) load( "//daml-lf/language:daml-lf.bzl", - "COMPILER_LF_VERSIONS", + "LEGACY_COMPILER_LF_VERSIONS", "LF_VERSIONS", "lf_version_configuration", ) @@ -162,9 +162,11 @@ scala_source_jar( ], ), ] - for target in COMPILER_LF_VERSIONS - # we skip 1.13 and 1.14 as their serializable types are the same as 1.12 - if target != "1.13" and target != "1.14" + for target in LEGACY_COMPILER_LF_VERSIONS + # we skip 1.13 as their serializable types are the same as 1.12. + # We include 1.14 since while it has no new serializable types + # it is the earliest version supported by HEAD damlc. + if target != "1.13" ] ######################################################## @@ -183,7 +185,7 @@ scala_source_jar( ), target = ver, ) - for ver in COMPILER_LF_VERSIONS + for ver in LEGACY_COMPILER_LF_VERSIONS ] daml_compile( @@ -302,9 +304,11 @@ java_test( ], ), ] - for target in COMPILER_LF_VERSIONS - # we skip 1.13 and 1.14 as their serializable types are the same as 1.12 - if target != "1.13" and target != "1.14" + for target in LEGACY_COMPILER_LF_VERSIONS + # we skip 1.13 as their serializable types are the same as 1.12. + # We include 1.14 since while it has no new serializable types + # it is the earliest version supported by HEAD damlc. + if target != "1.13" ] ######################################################## diff --git a/language-support/java/codegen/src/it/java-1.14/com/daml/AllTests.java b/language-support/java/codegen/src/it/java-1.14/com/daml/AllTests.java new file mode 100644 index 000000000000..04f552990ca9 --- /dev/null +++ b/language-support/java/codegen/src/it/java-1.14/com/daml/AllTests.java @@ -0,0 +1,15 @@ +// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +package com.daml; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + AllGenericTests.class, + GenMapTest.class, + NumericTest.class, +}) +public class AllTests {} diff --git a/language-support/java/codegen/src/it/java-1.14/com/daml/GenMapTest.java b/language-support/java/codegen/src/it/java-1.14/com/daml/GenMapTest.java new file mode 100644 index 000000000000..81ab831792ea --- /dev/null +++ b/language-support/java/codegen/src/it/java-1.14/com/daml/GenMapTest.java @@ -0,0 +1,237 @@ +// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +package com.daml; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import com.daml.ledger.api.v1.ValueOuterClass; +import com.daml.ledger.javaapi.data.DamlRecord; +import com.daml.ledger.javaapi.data.Int64; +import com.daml.ledger.javaapi.data.Text; +import com.daml.ledger.javaapi.data.Variant; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import org.junit.jupiter.api.Test; +import org.junit.platform.runner.JUnitPlatform; +import org.junit.runner.RunWith; +import tests.genmaptest.MapMapRecord; +import tests.genmaptest.MapRecord; +import tests.genmaptest.TemplateWithMap; +import tests.genmaptest.mapvariant.ParameterizedVariant; +import tests.genmaptest.mapvariant.RecordVariant; +import tests.genmaptest.mapvariant.TextVariant; + +@RunWith(JUnitPlatform.class) +public class GenMapTest { + + @Test + public void mapRecordRoundTrip() { + + ValueOuterClass.Record protoRecord = + buildRecord( + buildRecordField( + "field", + buildMap( + buildEntryMap(buildNone, buildText("None")), + buildEntryMap(buildSome(buildInt(1)), buildText("Some(1)")), + buildEntryMap(buildSome(buildInt(42)), buildText("Some(42)"))))) + .getRecord(); + + Map, String> javaMap = new HashMap<>(); + javaMap.put(Optional.empty(), "None"); + javaMap.put(Optional.of(1L), "Some(1)"); + javaMap.put(Optional.of(42L), "Some(42)"); + + DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); + MapRecord fromValue = MapRecord.fromValue(dataRecord); + MapRecord fromConstructor = new MapRecord(javaMap); + MapRecord fromRoundTrip = MapRecord.fromValue(fromConstructor.toValue()); + + assertEquals(fromValue, fromConstructor); + assertEquals(fromConstructor.toValue(), dataRecord); + assertEquals(fromConstructor, fromRoundTrip); + } + + private Map reverseMap(Map m) { + Map reversedMap = new HashMap<>(); + for (Map.Entry entry : m.entrySet()) reversedMap.put(entry.getValue(), entry.getKey()); + return reversedMap; + } + + @Test + public void mapMapRecordRoundTrip() { + + ValueOuterClass.Record protoRecord = + buildRecord( + buildRecordField( + "field", + buildMap( + buildEntryMap(buildMap(), buildMap()), + buildEntryMap( + buildMap(buildEntryMap(buildInt(1), buildText("1L"))), + buildMap(buildEntryMap(buildText("1L"), buildInt(1)))), + buildEntryMap( + buildMap( + buildEntryMap(buildInt(1), buildText("1L")), + buildEntryMap(buildInt(42), buildText("42L"))), + buildMap( + buildEntryMap(buildText("1L"), buildInt(1)), + buildEntryMap(buildText("42L"), buildInt(42))))))) + .getRecord(); + + Map inner1Map = new HashMap<>(); + Map inner2Map = new HashMap<>(); + inner2Map.put(1L, "1L"); + Map inner3Map = new HashMap<>(); + inner3Map.put(1L, "1L"); + inner3Map.put(42L, "42L"); + + Map, Map> javaMap = new HashMap<>(); + javaMap.put(inner1Map, reverseMap(inner1Map)); + javaMap.put(inner2Map, reverseMap(inner2Map)); + javaMap.put(inner3Map, reverseMap(inner3Map)); + + DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); + MapMapRecord fromValue = MapMapRecord.fromValue(dataRecord); + MapMapRecord fromConstructor = new MapMapRecord(javaMap); + MapMapRecord fromRoundTrip = MapMapRecord.fromValue(fromConstructor.toValue()); + + assertEquals(fromValue, fromConstructor); + assertEquals(fromConstructor.toValue(), dataRecord); + assertEquals(fromConstructor, fromRoundTrip); + } + + @Test + public void textMapVariantRoundTripTest() { + + ValueOuterClass.Variant protoVariant = + buildVariant("TextVariant", buildMap(buildEntryMap(buildText("key"), buildText("value")))) + .getVariant(); + + Variant dataVariant = Variant.fromProto(protoVariant); + TextVariant fromValue = TextVariant.fromValue(dataVariant); + TextVariant fromConstructor = new TextVariant<>(Collections.singletonMap("key", "value")); + TextVariant fromRoundTrip = TextVariant.fromValue(fromConstructor.toValue()); + + assertEquals(fromValue, fromConstructor); + assertEquals(fromConstructor.toValue(), dataVariant); + assertEquals(fromConstructor, fromRoundTrip); + } + + @Test + public void mapRecordVariantRoundTripTest() { + + ValueOuterClass.Variant protoVariant = + buildVariant( + "RecordVariant", + buildRecord( + buildRecordField("x", buildMap(buildEntryMap(buildText("key"), buildInt(42)))))) + .getVariant(); + + Variant dataVariant = Variant.fromProto(protoVariant); + RecordVariant fromValue = RecordVariant.fromValue(dataVariant); + RecordVariant fromConstructor = new RecordVariant<>(Collections.singletonMap("key", 42L)); + RecordVariant fromRoundTrip = RecordVariant.fromValue(fromConstructor.toValue()); + + assertEquals(fromValue, fromConstructor); + assertEquals(fromConstructor.toValue(), dataVariant); + assertEquals(fromConstructor, fromRoundTrip); + } + + @Test + public void mapParameterizedVariantRoundTripTest() { + + ValueOuterClass.Variant protoVariant = + buildVariant( + "ParameterizedVariant", buildMap(buildEntryMap(buildText("key"), buildInt(42)))) + .getVariant(); + + Variant dataVariant = Variant.fromProto(protoVariant); + ParameterizedVariant fromValue = + ParameterizedVariant.fromValue( + dataVariant, x -> x.asText().get().getValue(), x -> x.asInt64().get().getValue()); + ParameterizedVariant fromConstructor = + new ParameterizedVariant<>(Collections.singletonMap("key", 42L)); + + assertEquals(fromValue, fromConstructor); + assertEquals(fromConstructor.toValue(x -> new Text(x), x -> new Int64(x)), dataVariant); + assertEquals(fromValue.toValue(x -> new Text(x), x -> new Int64(x)), dataVariant); + } + + @Test + public void mapTemplateRoundTripTest() { + + ValueOuterClass.Record protoRecord = + buildRecord( + buildRecordField("owner", buildParty("party1")), + buildRecordField( + "valueMap", buildMap(buildEntryMap(buildInt(42), buildText("42"))))) + .getRecord(); + + DamlRecord dataRecord = DamlRecord.fromProto(protoRecord); + TemplateWithMap fromValue = TemplateWithMap.fromValue(dataRecord); + TemplateWithMap fromConstructor = + new TemplateWithMap("party1", Collections.singletonMap(42L, "42")); + + TemplateWithMap fromRoundTrip = TemplateWithMap.fromValue(fromConstructor.toValue()); + + assertEquals(fromValue, fromConstructor); + assertEquals(fromConstructor.toValue(), dataRecord); + assertEquals(fromValue.toValue(), dataRecord); + assertEquals(fromConstructor, fromRoundTrip); + } + + private static ValueOuterClass.Value buildInt(int i) { + return ValueOuterClass.Value.newBuilder().setInt64(i).build(); + } + + private static ValueOuterClass.Value buildText(String text) { + return ValueOuterClass.Value.newBuilder().setText(text).build(); + } + + private static ValueOuterClass.Value buildParty(String party) { + return ValueOuterClass.Value.newBuilder().setParty(party).build(); + } + + private static final ValueOuterClass.Value buildNone = + ValueOuterClass.Value.newBuilder().setOptional(ValueOuterClass.Optional.newBuilder()).build(); + + private static ValueOuterClass.Value buildSome(ValueOuterClass.Value value) { + return ValueOuterClass.Value.newBuilder() + .setOptional(ValueOuterClass.Optional.newBuilder().setValue(value)) + .build(); + } + + private static ValueOuterClass.Value buildMap(ValueOuterClass.GenMap.Entry... entries) { + ValueOuterClass.GenMap.Builder builder = ValueOuterClass.GenMap.newBuilder(); + for (ValueOuterClass.GenMap.Entry entry : entries) builder.addEntries(entry); + return ValueOuterClass.Value.newBuilder().setGenMap(builder).build(); + } + + private static ValueOuterClass.GenMap.Entry buildEntryMap( + ValueOuterClass.Value key, ValueOuterClass.Value value) { + return ValueOuterClass.GenMap.Entry.newBuilder().setKey(key).setValue(value).build(); + } + + private static ValueOuterClass.RecordField buildRecordField( + String field, ValueOuterClass.Value value) { + return ValueOuterClass.RecordField.newBuilder().setLabel(field).setValue(value).build(); + } + + private static ValueOuterClass.Value buildRecord(ValueOuterClass.RecordField... fields) { + ValueOuterClass.Record.Builder builder = ValueOuterClass.Record.newBuilder(); + for (ValueOuterClass.RecordField field : fields) builder.addFields(field); + return ValueOuterClass.Value.newBuilder().setRecord(builder).build(); + } + + private static ValueOuterClass.Value buildVariant( + String constructor, ValueOuterClass.Value value) { + return ValueOuterClass.Value.newBuilder() + .setVariant( + ValueOuterClass.Variant.newBuilder().setConstructor(constructor).setValue(value)) + .build(); + } +} diff --git a/language-support/java/codegen/src/it/java-1.14/com/daml/NumericTest.java b/language-support/java/codegen/src/it/java-1.14/com/daml/NumericTest.java new file mode 100644 index 000000000000..fbdc0649161a --- /dev/null +++ b/language-support/java/codegen/src/it/java-1.14/com/daml/NumericTest.java @@ -0,0 +1,196 @@ +// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +package com.daml; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import com.daml.ledger.api.v1.ValueOuterClass; +import com.daml.ledger.javaapi.data.*; +import java.math.BigDecimal; +import java.math.BigInteger; +import java.util.ArrayList; +import org.junit.jupiter.api.Test; +import org.junit.platform.runner.JUnitPlatform; +import org.junit.runner.RunWith; +import tests.numerictest.NumericBox; +import tests.numerictest.nestednumericbox.Nested; +import tests.numerictest.nestednumericbox.NoMore; + +@RunWith(JUnitPlatform.class) +public class NumericTest { + + void checkRecord(NumericBox myRecord) { + assertEquals(myRecord.decimal, decimalValue()); + assertEquals(myRecord.numeric0, numeric0Value()); + assertEquals(myRecord.numeric37, numeric37Value()); + NumericBox myNestedRecord = ((Nested) myRecord.nestedBox).numericBoxValue; + assertEquals(myNestedRecord.decimal, decimalValue().negate()); + assertEquals(myNestedRecord.numeric0, numeric0Value().negate()); + assertEquals(myNestedRecord.numeric37, numeric37Value().negate()); + assertTrue(myNestedRecord.nestedBox instanceof NoMore); + } + + @Test + void deserializableFromRecord() { + ArrayList fieldsList_ = new ArrayList<>(10); + fieldsList_.add(new DamlRecord.Field("decimal", new Numeric(decimalValue().negate()))); + fieldsList_.add(new DamlRecord.Field("numeric0", new Numeric(numeric0Value().negate()))); + fieldsList_.add(new DamlRecord.Field("numeric37", new Numeric(numeric37Value().negate()))); + fieldsList_.add(new DamlRecord.Field("nested", new Variant("NoMore", Unit.getInstance()))); + DamlRecord nestedRecord = new DamlRecord(fieldsList_); + ArrayList fieldsList = new ArrayList<>(10); + fieldsList.add(new DamlRecord.Field("decimal", new Numeric(decimalValue()))); + fieldsList.add(new DamlRecord.Field("numeric0", new Numeric(numeric0Value()))); + fieldsList.add(new DamlRecord.Field("numeric37", new Numeric(numeric37Value()))); + fieldsList.add(new DamlRecord.Field("nestedBox", new Variant("Nested", nestedRecord))); + Value value = new DamlRecord(fieldsList); + NumericBox record = NumericBox.fromValue(value); + checkRecord(record); + assertTrue( + "to value uses original Daml-LF names for fields", + record.toValue().getFieldsMap().get("numeric37").asNumeric().isPresent()); + } + + @Test + void objectMethodsWork() { + + NumericBox record1 = numericBox(); + NumericBox record2 = numericBox(); + + assertEquals(record1, record2); + assertEquals(record1.hashCode(), record2.hashCode()); + } + + ValueOuterClass.Record.Builder recordBuilder() { + return ValueOuterClass.Record.newBuilder(); + } + + ValueOuterClass.RecordField.Builder recordFieldBuilder() { + return ValueOuterClass.RecordField.newBuilder(); + } + + ValueOuterClass.Value.Builder valueBuilder() { + return ValueOuterClass.Value.newBuilder(); + } + + ValueOuterClass.Variant.Builder variantBuilder() { + return ValueOuterClass.Variant.newBuilder(); + } + + com.google.protobuf.Empty.Builder emptyBuilder() { + return com.google.protobuf.Empty.newBuilder(); + } + + @Test + void outerRecordRoundtrip() { + ValueOuterClass.Value protoValue = + valueBuilder() + .setRecord( + recordBuilder() + .addFields( + recordFieldBuilder() + .setLabel("decimal") + .setValue(valueBuilder().setNumeric("10.0000000000"))) + .addFields( + recordFieldBuilder() + .setLabel("numeric0") + .setValue( + valueBuilder() + .setNumeric("99999999999999999999999999999999999999"))) + .addFields( + recordFieldBuilder() + .setLabel("numeric37") + .setValue( + valueBuilder() + .setNumeric("9.9999999999999999999999999999999999999"))) + .addFields( + recordFieldBuilder() + .setLabel("nestedBox") + .setValue( + valueBuilder() + .setVariant( + variantBuilder() + .setConstructor("Nested") + .setValue( + valueBuilder() + .setRecord( + recordBuilder() + .addFields( + recordFieldBuilder() + .setLabel("decimal") + .setValue( + valueBuilder() + .setNumeric( + "-10.0000000000"))) + .addFields( + recordFieldBuilder() + .setLabel("numeric0") + .setValue( + valueBuilder() + .setNumeric( + "-99999999999999999999999999999999999999"))) + .addFields( + recordFieldBuilder() + .setLabel("numeric37") + .setValue( + valueBuilder() + .setNumeric( + "-9.9999999999999999999999999999999999999"))) + .addFields( + recordFieldBuilder() + .setLabel("nestedBox") + .setValue( + valueBuilder() + .setVariant( + variantBuilder() + .setConstructor( + "NoMore") + .setValue( + valueBuilder() + .setUnit( + emptyBuilder()))))))))))) + .build(); + + Value value = Value.fromProto(protoValue); + NumericBox fromValue = NumericBox.fromValue(value); + NumericBox fromConstructor = numericBox(); + NumericBox fromRoundTrip = + NumericBox.fromValue(Value.fromProto(fromConstructor.toValue().toProto())); + + assertEquals(fromValue, fromConstructor); + assertEquals(fromConstructor.toValue(), value); + assertEquals(fromConstructor.toValue().toProto(), protoValue); + assertEquals(fromRoundTrip, fromConstructor); + } + + BigDecimal maxValue(int s) { + return new BigDecimal(BigInteger.TEN.pow(38).subtract(BigInteger.ONE), s); + } + + java.math.BigDecimal decimalValue() { + return BigDecimal.TEN.setScale(10); + } + + java.math.BigDecimal numeric0Value() { + return maxValue(0); + } + + java.math.BigDecimal numeric37Value() { + return maxValue(37); + } + + NumericBox numericBox() { + return new NumericBox( + decimalValue(), + numeric0Value(), + numeric37Value(), + new Nested( + new NumericBox( + decimalValue().negate(), + numeric0Value().negate(), + numeric37Value().negate(), + new NoMore(Unit.getInstance())))); + } +} diff --git a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_11.java b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_11.java index 8cb324209119..e03fe2e34e9c 100644 --- a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_11.java +++ b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_11.java @@ -10,7 +10,7 @@ @Suite.SuiteClasses({ DecimalTestForAll.class, EnumTestForForAll.class, - NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_dev.class, - GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_dev.class, + NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_dev.class, + GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_dev.class, }) public class AllTestsFor1_11 {} diff --git a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_12.java b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_12.java index 7c40f2d2350d..85a9b16abaf6 100644 --- a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_12.java +++ b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_12.java @@ -10,7 +10,7 @@ @Suite.SuiteClasses({ DecimalTestForAll.class, EnumTestForForAll.class, - NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_dev.class, - GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_dev.class, + NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_dev.class, + GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_dev.class, }) public class AllTestsFor1_12 {} diff --git a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_14.java b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_14.java new file mode 100644 index 000000000000..9d8a2c154248 --- /dev/null +++ b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_14.java @@ -0,0 +1,16 @@ +// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. +// SPDX-License-Identifier: Apache-2.0 + +package com.daml.testing; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + DecimalTestForAll.class, + EnumTestForForAll.class, + NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_dev.class, + GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_dev.class, +}) +public class AllTestsFor1_14 {} diff --git a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_7.java b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_7.java index 8d26ef40c93c..f4bec62fac5b 100644 --- a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_7.java +++ b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_7.java @@ -10,6 +10,6 @@ @Suite.SuiteClasses({ DecimalTestForAll.class, EnumTestForForAll.class, - NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_dev.class, + NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_dev.class, }) public class AllTestsFor1_7 {} diff --git a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_8.java b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_8.java index e74befa2483a..02a3acd9f1e8 100644 --- a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_8.java +++ b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_8.java @@ -10,6 +10,6 @@ @Suite.SuiteClasses({ DecimalTestForAll.class, EnumTestForForAll.class, - NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_dev.class, + NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_dev.class, }) public class AllTestsFor1_8 {} diff --git a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_dev.java b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_dev.java index d1fe402d5123..bc2934b1b0b5 100644 --- a/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_dev.java +++ b/language-support/java/codegen/src/test/java/com/digitalasset/testing/AllTestsFor1_dev.java @@ -10,7 +10,7 @@ @Suite.SuiteClasses({ DecimalTestForAll.class, EnumTestForForAll.class, - NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_dev.class, - GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_dev.class, + NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_dev.class, + GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_dev.class, }) public class AllTestsFor1_dev {} diff --git a/language-support/java/codegen/src/test/java/com/digitalasset/testing/GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_dev.java b/language-support/java/codegen/src/test/java/com/digitalasset/testing/GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_dev.java similarity index 97% rename from language-support/java/codegen/src/test/java/com/digitalasset/testing/GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_dev.java rename to language-support/java/codegen/src/test/java/com/digitalasset/testing/GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_dev.java index 6872c67a3419..46558fce0f46 100644 --- a/language-support/java/codegen/src/test/java/com/digitalasset/testing/GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_dev.java +++ b/language-support/java/codegen/src/test/java/com/digitalasset/testing/GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_dev.java @@ -19,7 +19,7 @@ import test.variantmod.either.*; @RunWith(JUnitPlatform.class) -public class GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_dev { +public class GenMapTestFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_dev { private BigDecimal bg1() { return new BigDecimal("1.0000000000"); diff --git a/language-support/java/codegen/src/test/java/com/digitalasset/testing/NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_dev.java b/language-support/java/codegen/src/test/java/com/digitalasset/testing/NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_dev.java similarity index 98% rename from language-support/java/codegen/src/test/java/com/digitalasset/testing/NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_dev.java rename to language-support/java/codegen/src/test/java/com/digitalasset/testing/NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_dev.java index 22ef97f908cb..6afb5cc66fb0 100644 --- a/language-support/java/codegen/src/test/java/com/digitalasset/testing/NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_dev.java +++ b/language-support/java/codegen/src/test/java/com/digitalasset/testing/NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_dev.java @@ -15,7 +15,7 @@ import test.numericmod.Box; @RunWith(JUnitPlatform.class) -public class NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_dev { +public class NumericTestFor1_7AndFor1_8AndFor1_11AndFor1_12ndFor1_13AndFor1_14AndFor1_dev { @Test void numeric2Value2Numeric() { diff --git a/language-support/ts/codegen/tests/BUILD.bazel b/language-support/ts/codegen/tests/BUILD.bazel index e563cffe0b54..0f6b4ca9d948 100644 --- a/language-support/ts/codegen/tests/BUILD.bazel +++ b/language-support/ts/codegen/tests/BUILD.bazel @@ -186,6 +186,7 @@ da_haskell_test( "//language-support/ts/codegen:daml2js", "//language-support/ts/daml-ledger:npm_package", "//language-support/ts/daml-types:npm_package", + "@damlc_legacy", "@davl//:released/davl-upgrade-v4-v5.dar", "@davl//:released/davl-v4.dar", "@davl//:released/davl-v5.dar", diff --git a/language-support/ts/codegen/tests/src/DA/Test/Daml2js.hs b/language-support/ts/codegen/tests/src/DA/Test/Daml2js.hs index 24d79a999e16..4fdbe8ca2b07 100644 --- a/language-support/ts/codegen/tests/src/DA/Test/Daml2js.hs +++ b/language-support/ts/codegen/tests/src/DA/Test/Daml2js.hs @@ -30,6 +30,7 @@ main = withTempDir $ \yarnCache -> do setEnv "YARN_CACHE_FOLDER" yarnCache True yarnPath : args <- getArgs damlc <- locateRunfiles (mainWorkspace "compiler" "damlc" exe "damlc") + damlcLegacy <- locateRunfiles ("damlc_legacy" "damlc_legacy") daml2js <- locateRunfiles (mainWorkspace "language-support" "ts" "codegen" exe "daml2js") yarn <- locateRunfiles (mainWorkspace yarnPath) davl <- locateRunfiles ("davl" "released") @@ -37,7 +38,7 @@ main = withTempDir $ \yarnCache -> do withArgs args $ withEnv [ ("PATH", Just $ intercalate [searchPathSeparator] $ takeDirectory yarn : oldPath) , ("TASTY_NUM_THREADS", Just "1") - ] $ defaultMain (tests yarn damlc daml2js davl) + ] $ defaultMain (tests yarn damlc damlcLegacy daml2js davl) -- It may help to keep in mind for the following tests, this quick -- refresher on the layout of a simple project: @@ -64,8 +65,8 @@ main = withTempDir $ \yarnCache -> do -- ... -- daml-types <-- referred to by the "resolutions" field in package.json -tests :: FilePath -> FilePath -> FilePath -> FilePath -> TestTree -tests yarn damlc daml2js davl = testGroup "daml2js tests" +tests :: FilePath -> FilePath -> FilePath -> FilePath -> FilePath -> TestTree +tests yarn damlc damlcLegacy daml2js davl = testGroup "daml2js tests" [ testCaseSteps "Different package, same name test" $ \step -> withTempDir $ \here -> do let grover = here "grover" @@ -107,7 +108,7 @@ tests yarn damlc daml2js davl = testGroup "daml2js tests" "module Grover where data Grover = Grover" writeDamlYaml "grover" ["Grover"] ["daml-prim", "daml-stdlib"] (Just LF.version1_7) step "daml build..." - buildProject [] + buildProjectLegacy [] let superGrover = here "super-grover" superGroverDaml = superGrover "daml" superGroverDar = superGrover ".daml" "dist" "super-grover-1.0.dar" @@ -117,7 +118,7 @@ tests yarn damlc daml2js davl = testGroup "daml2js tests" "module Grover where data Grover = Grover" writeDamlYaml "super-grover" ["Grover"] ["daml-prim", "daml-stdlib"] (Just LF.version1_7) step "daml build..." - buildProject [] + buildProjectLegacy [] withCurrentDirectory here $ do step "daml2js..." setupYarnEnvironment @@ -250,6 +251,9 @@ tests yarn damlc daml2js davl = testGroup "daml2js tests" buildProject :: [String] -> IO () buildProject args = callProcessSilent damlc (["build"] ++ args) + buildProjectLegacy :: [String] -> IO () + buildProjectLegacy args = callProcessSilent damlcLegacy (["build"] ++ args) + daml2jsProject :: [FilePath] -> FilePath -> IO () daml2jsProject dars outDir = callProcessSilent daml2js $ dars ++ ["-o", outDir] diff --git a/rules_daml/daml.bzl b/rules_daml/daml.bzl index f0cbb7e5676d..74ba933c4793 100644 --- a/rules_daml/daml.bzl +++ b/rules_daml/daml.bzl @@ -3,9 +3,9 @@ load("@build_environment//:configuration.bzl", "ghc_version", "sdk_version") load("//bazel_tools/sh:sh.bzl", "sh_inline_test") +load("//daml-lf/language:daml-lf.bzl", "COMPILER_LF_VERSIONS") _damlc = attr.label( - allow_single_file = True, default = Label("//compiler/damlc:damlc-compile-only"), executable = True, cfg = "host", @@ -78,7 +78,7 @@ def _daml_build_impl(ctx): daml_yaml = ctx.file.daml_yaml srcs = ctx.files.srcs dar_dict = ctx.attr.dar_dict - damlc = ctx.file._damlc + damlc = ctx.executable.damlc input_dars = [file_of_target(k) for k in dar_dict.keys()] output_dar = ctx.outputs.dar posix = ctx.toolchains["@rules_sh//sh/posix:toolchain_type"] @@ -149,7 +149,7 @@ _daml_build = rule( doc = "Options passed to GHC.", default = ["--ghc-option=-Werror", "--ghc-option=-Wwarn", "--log-level=WARNING"], ), - "_damlc": _damlc, + "damlc": _damlc, }, toolchains = ["@rules_sh//sh/posix:toolchain_type"], ) @@ -249,6 +249,12 @@ _default_project_version = "1.0.0" default_damlc_opts = ["--ghc-option=-Werror", "--ghc-option=-Wwarn", "--log-level=WARNING"] +def damlc_for_target(target): + if not target or target in COMPILER_LF_VERSIONS: + return "//compiler/damlc:damlc-compile-only" + else: + return "@damlc_legacy//:damlc_legacy" + def daml_compile( name, srcs, @@ -276,6 +282,7 @@ def daml_compile( dar_dict = {}, dar = name + ".dar", ghc_options = ghc_options, + damlc = damlc_for_target(target), **kwargs ) _inspect_dar( From bddf0f36467009d93e8b7163b0a23adeffc6ebb8 Mon Sep 17 00:00:00 2001 From: Moritz Kiefer Date: Mon, 22 Nov 2021 16:10:53 +0100 Subject: [PATCH 2/4] Switch around legacy_compiler_lf_versions changelog_begin changelog_end --- daml-lf/language/daml-lf.bzl | 6 ++++-- language-support/java/codegen/BUILD.bazel | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/daml-lf/language/daml-lf.bzl b/daml-lf/language/daml-lf.bzl index 1adb42220e0a..0927bdf1b777 100644 --- a/daml-lf/language/daml-lf.bzl +++ b/daml-lf/language/daml-lf.bzl @@ -60,11 +60,13 @@ PROTO_LF_VERSIONS = LF_VERSIONS 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 +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 = [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 ver not in LEGACY_COMPILER_LF_VERSIONS] + +ALL_COMPILER_LF_VERSIONS = LEGACY_COMPILER_LF_VERSIONS + 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"] diff --git a/language-support/java/codegen/BUILD.bazel b/language-support/java/codegen/BUILD.bazel index f1d5d4f06d67..eb9fedcbd55f 100644 --- a/language-support/java/codegen/BUILD.bazel +++ b/language-support/java/codegen/BUILD.bazel @@ -23,7 +23,7 @@ load( ) load( "//daml-lf/language:daml-lf.bzl", - "LEGACY_COMPILER_LF_VERSIONS", + "ALL_COMPILER_LF_VERSIONS", "LF_VERSIONS", "lf_version_configuration", ) @@ -162,7 +162,7 @@ scala_source_jar( ], ), ] - for target in LEGACY_COMPILER_LF_VERSIONS + for target in ALL_COMPILER_LF_VERSIONS # we skip 1.13 as their serializable types are the same as 1.12. # We include 1.14 since while it has no new serializable types # it is the earliest version supported by HEAD damlc. @@ -185,7 +185,7 @@ scala_source_jar( ), target = ver, ) - for ver in LEGACY_COMPILER_LF_VERSIONS + for ver in ALL_COMPILER_LF_VERSIONS ] daml_compile( @@ -304,7 +304,7 @@ java_test( ], ), ] - for target in LEGACY_COMPILER_LF_VERSIONS + for target in ALL_COMPILER_LF_VERSIONS # we skip 1.13 as their serializable types are the same as 1.12. # We include 1.14 since while it has no new serializable types # it is the earliest version supported by HEAD damlc. From 5a3ba1e290d1136534b24993dd1857353b1cdd0a Mon Sep 17 00:00:00 2001 From: Moritz Kiefer Date: Mon, 22 Nov 2021 16:11:55 +0100 Subject: [PATCH 3/4] drop since-lf changelog_begin changelog_end --- compiler/damlc/tests/daml-test-files/NextSet.daml | 2 -- 1 file changed, 2 deletions(-) diff --git a/compiler/damlc/tests/daml-test-files/NextSet.daml b/compiler/damlc/tests/daml-test-files/NextSet.daml index a3702bf572e5..05c239ded68e 100644 --- a/compiler/damlc/tests/daml-test-files/NextSet.daml +++ b/compiler/damlc/tests/daml-test-files/NextSet.daml @@ -3,8 +3,6 @@ -- Copyright (c) 2020, Digital Asset (Switzerland) GmbH and/or its affiliates. -- All rights reserved. --- @SINCE-LF 1.3 - module NextSet where import DA.Next.Set as S From b356687535526b2a3548d76033d3fd8fddb1bcf7 Mon Sep 17 00:00:00 2001 From: Moritz Kiefer Date: Mon, 22 Nov 2021 16:30:34 +0100 Subject: [PATCH 4/4] drop script_lf_versions changelog_begin changelog_end --- daml-lf/language/daml-lf.bzl | 3 --- daml-script/daml/BUILD.bazel | 6 +++--- triggers/daml/BUILD.bazel | 6 +++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/daml-lf/language/daml-lf.bzl b/daml-lf/language/daml-lf.bzl index 0927bdf1b777..d21edeccba87 100644 --- a/daml-lf/language/daml-lf.bzl +++ b/daml-lf/language/daml-lf.bzl @@ -68,9 +68,6 @@ COMPILER_LF_VERSIONS = [ver for ver in ENCODER_LF_VERSIONS if ver not in LEGACY_ ALL_COMPILER_LF_VERSIONS = LEGACY_COMPILER_LF_VERSIONS + 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"] - LF_VERSION_PACKAGE_DIGITALASSET = { "1.6": "digitalasset", "1.7": "digitalasset", diff --git a/daml-script/daml/BUILD.bazel b/daml-script/daml/BUILD.bazel index 327de750f16c..b6ca267ce608 100644 --- a/daml-script/daml/BUILD.bazel +++ b/daml-script/daml/BUILD.bazel @@ -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. @@ -46,7 +46,7 @@ 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 ""] ] @@ -54,7 +54,7 @@ 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"], ) diff --git a/triggers/daml/BUILD.bazel b/triggers/daml/BUILD.bazel index b5e5c63ff603..a3d14a413dd7 100644 --- a/triggers/daml/BUILD.bazel +++ b/triggers/daml/BUILD.bazel @@ -5,7 +5,7 @@ # 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. @@ -51,7 +51,7 @@ EOF ], 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 ""] ] @@ -59,7 +59,7 @@ filegroup( name = "daml-trigger-dars", srcs = [ "daml-trigger-{}.dar".format(lf_version) - for lf_version in SCRIPT_LF_VERSIONS + for lf_version in COMPILER_LF_VERSIONS ], visibility = ["//visibility:public"], )