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

Remove major version parameter from the interpreter #18824

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sdk/compiler/damlc/stable-packages/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
load("//bazel_tools:haskell.bzl", "da_haskell_binary", "da_haskell_library", "generate_and_track_cabal")
load(
"//daml-lf/language:daml-lf.bzl",
"LF_MAJOR_VERSIONS",
"SUPPORTED_LF_MAJOR_VERSIONS",
)
load(
":defs.bzl",
Expand Down Expand Up @@ -65,7 +65,7 @@ da_haskell_binary(
tools = [":generate-stable-package"],
visibility = ["//visibility:public"],
)
for majorLfVersion in LF_MAJOR_VERSIONS
for majorLfVersion in SUPPORTED_LF_MAJOR_VERSIONS
]

# Generates a list of dalf paths to be used by StablePackages.scala to load the dalfs as classpath
Expand All @@ -86,7 +86,7 @@ EOF""".format(paths = "\n".join([
])),
visibility = ["//visibility:public"],
)
for majorLfVersion in LF_MAJOR_VERSIONS
for majorLfVersion in SUPPORTED_LF_MAJOR_VERSIONS
]

# If you change this you also need to update generateStablePackages in Development.IDE.Core.Rules.Daml
Expand All @@ -96,7 +96,7 @@ filegroup(
dalf
for dalfs in [
stable_packages(majorLfVersion).values()
for majorLfVersion in LF_MAJOR_VERSIONS
for majorLfVersion in SUPPORTED_LF_MAJOR_VERSIONS
]
for dalf in dalfs
],
Expand Down
4 changes: 2 additions & 2 deletions sdk/compiler/damlc/tests/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ load("@os_info//:os_info.bzl", "is_darwin", "is_windows")
load(":util.bzl", "damlc_compile_test")
load("//rules_daml:daml.bzl", "daml_compile", "daml_compile_with_dalf", "generate_and_track_dar_hash_file")
load("@build_environment//:configuration.bzl", "ghc_version", "sdk_version")
load("//daml-lf/language:daml-lf.bzl", "COMPILER_LF2_VERSIONS", "LF_MAJOR_VERSIONS", "lf_version_default_or_latest", "mangle_for_damlc")
load("//daml-lf/language:daml-lf.bzl", "COMPILER_LF_VERSIONS", "lf_version_default_or_latest", "mangle_for_damlc")
load("//compiler/damlc:util.bzl", "ghc_pkg")

# Tests for the lax CLI parser + damlc CLI parser
Expand Down Expand Up @@ -208,7 +208,7 @@ da_haskell_library(
":integration-lib",
],
)
for version in COMPILER_LF2_VERSIONS
for version in COMPILER_LF_VERSIONS
]

da_haskell_test(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,8 @@ object SignatureReader {
s"interface view type ${astIf.view.pretty} must be either a no-argument type reference or unit",
)
}
} yield name -> typesig.DefInterface(choices, viewType)
retroImplements = astIf.coImplements.keySet
} yield name -> typesig.DefInterface(choices, viewType, retroImplements)

private[lf] def toIfaceType(
ctx: QualifiedName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class SignatureReaderSpec extends AnyWordSpec with Matchers with Inside {
val Archive = cn("Archive")
val TIf = qn("InterfaceTestPackage:TIf")
val LibTIf = qn("InterfaceTestLib:TIf")
val RetroIf = qn("RetroInterface:RetroIf")
val LibTIfView = qn("InterfaceTestLib:TIfView")
val Useless = cn("Useless")
val UselessTy = qn("InterfaceTestPackage:Useless")
Expand Down Expand Up @@ -330,12 +331,52 @@ class SignatureReaderSpec extends AnyWordSpec with Matchers with Inside {
)
}

"resolve retro implements harmlessly when there are none" in {
// TODO: https://github.com/digital-asset/daml/issues/18821
// Make SignatureReaderSpec handle LF 1.x and active the 3 fallowing test for LF 1.x
"have interfaces with retroImplements" ignore {
itp.main.interfaces.keySet should ===(Set(LibTIf, TIf, RetroIf))
itp.main.interfaces(RetroIf).retroImplements should ===(
Set(Ref.TypeConName(itp.main.packageId, Foo))
)
}

"resolve retro implements harmlessly when there are none" ignore {
PackageSignature.resolveRetroImplements((), itpWithoutRetroImplements.all)((_, _) =>
None
) should ===((), itpWithoutRetroImplements.all)
itpESWithoutRetroImplements.resolveRetroImplements should ===(itpESWithoutRetroImplements)
}

"resolve retro implements" ignore {
val (_, itpResolvedRetro) =
PackageSignature.resolveRetroImplements((), itp.all)((_, _) => None)
itpResolvedRetro should !==(itp.all)
inside(
itpResolvedRetro.find(_.packageId == itp.main.packageId)
) { case Some(packageSignature) =>
inside(packageSignature.interfaces.get(RetroIf)) {
case Some(DefInterface(_, retroImplements, _)) =>
retroImplements shouldBe empty
}
inside(packageSignature.typeDecls.get(Foo)) {
case Some(TypeDecl.Template(_, DefTemplate(_, _, implementedInterfaces))) =>
implementedInterfaces should contain(Ref.TypeConName(itp.main.packageId, RetroIf))
}
}

val itsESResolvedRetro = itpES.resolveRetroImplements
itsESResolvedRetro should !==(itpES)
inside(
itsESResolvedRetro.interfaces.get(Ref.TypeConName(itp.main.packageId, RetroIf))
) { case Some(DefInterface(_, retroImplements, _)) =>
retroImplements shouldBe empty
}

inside(itsESResolvedRetro.typeDecls.get(Ref.TypeConName(itp.main.packageId, Foo))) {
case Some(TypeDecl.Template(_, DefTemplate(_, _, implementedInterfaces))) =>
implementedInterfaces should contain(Ref.TypeConName(itp.main.packageId, RetroIf))
}
}
}

private def wrappInModule(dataName: DottedName, dfn: Ast.DDataType) =
Expand Down
8 changes: 4 additions & 4 deletions sdk/daml-lf/archive/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ load(
)
load(
"//daml-lf/language:daml-lf.bzl",
"LF_DEV_VERSIONS",
"LF_MAJOR_VERSIONS",
"SUPPORTED_LF_DEV_VERSIONS",
"SUPPORTED_LF_MAJOR_VERSIONS",
"SUPPORTED_PROTO_STABLE_LF_VERSIONS",
"mangle_for_damlc",
"mangle_for_java",
Expand Down Expand Up @@ -135,7 +135,7 @@ da_scala_test_suite(
":DarReaderTest.dar",
] + [
":DarReaderTest-{}.dar".format(mangle_for_damlc(version))
for version in LF_DEV_VERSIONS
for version in SUPPORTED_LF_DEV_VERSIONS
],
scala_deps = [
"@maven//:org_scalacheck_scalacheck",
Expand Down Expand Up @@ -171,7 +171,7 @@ daml_compile_with_dalf(
srcs = ["src/test/daml/DarReaderTest.daml"],
target = version,
)
for version in LF_DEV_VERSIONS
for version in SUPPORTED_LF_DEV_VERSIONS
]

# An ad-hoc tool for testing, benchmarking and profiling package decoding performance in isolation.
Expand Down
18 changes: 9 additions & 9 deletions sdk/daml-lf/engine/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ load(
)
load(
"//daml-lf/language:daml-lf.bzl",
"LF_DEV_VERSIONS",
"LF_MAJOR_VERSIONS",
"SUPPORTED_LF_DEV_VERSIONS",
"SUPPORTED_LF_MAJOR_VERSIONS",
"lf_version_default_or_latest",
"mangle_for_damlc",
)
Expand Down Expand Up @@ -62,7 +62,7 @@ ENGINE_TEST_FILES = \
target = lf_version_default_or_latest(major),
)
for name in ENGINE_TEST_FILES
for major in LF_MAJOR_VERSIONS
for major in SUPPORTED_LF_MAJOR_VERSIONS
]

[
Expand All @@ -75,7 +75,7 @@ ENGINE_TEST_FILES = \
target = version,
)
for name in ENGINE_TEST_FILES
for version in LF_DEV_VERSIONS
for version in SUPPORTED_LF_DEV_VERSIONS
]

da_scala_test_suite(
Expand All @@ -102,14 +102,14 @@ da_scala_test_suite(
"//daml-lf/tests:MultiKeys",
"//daml-lf/tests:ReinterpretTests",
]
for major in LF_MAJOR_VERSIONS
for major in SUPPORTED_LF_MAJOR_VERSIONS
] + [
":{name}-v{major}.dar".format(
name = name,
major = major,
)
for name in ENGINE_TEST_FILES
for major in LF_MAJOR_VERSIONS
for major in SUPPORTED_LF_MAJOR_VERSIONS
] + [
"{name}-{version}.dar".format(
name = prefix,
Expand All @@ -121,7 +121,7 @@ da_scala_test_suite(
"//daml-lf/tests:MultiKeys",
"//daml-lf/tests:Exceptions",
]
for version in LF_DEV_VERSIONS
for version in SUPPORTED_LF_DEV_VERSIONS
],
scala_deps = [
"@maven//:org_scalatest_scalatest_core",
Expand Down Expand Up @@ -157,7 +157,7 @@ da_scala_test_suite(
srcs = ["src/test/daml/LargeTransaction.daml"],
target = lf_version_default_or_latest(major),
)
for major in LF_MAJOR_VERSIONS
for major in SUPPORTED_LF_MAJOR_VERSIONS
]

da_scala_test(
Expand All @@ -169,7 +169,7 @@ da_scala_test(
]),
data = [
":LargeTransaction-v{}.dar".format(major)
for major in LF_MAJOR_VERSIONS
for major in SUPPORTED_LF_MAJOR_VERSIONS
],
# We setup a large heap size to reduce as much as possible GC overheads.
initial_heap_size = "2g",
Expand Down
4 changes: 2 additions & 2 deletions sdk/daml-lf/interpreter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ load(
load("@io_bazel_rules_scala//scala:scala.bzl", "scala_repl")
load(
"//daml-lf/language:daml-lf.bzl",
"LF_MAJOR_VERSIONS",
"SUPPORTED_LF_MAJOR_VERSIONS",
"lf_version_default_or_latest",
)

Expand Down Expand Up @@ -163,7 +163,7 @@ scala_repl(
"@maven//:com_google_protobuf_protobuf_java",
],
)
for major in LF_MAJOR_VERSIONS
for major in SUPPORTED_LF_MAJOR_VERSIONS
]

da_scala_benchmark_jmh(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,15 @@ private[lf] final class Compiler(
addDef(compileChoiceController(ifaceId, iface.param, choice))
addDef(compileChoiceObserver(ifaceId, iface.param, choice))
}
iface.coImplements.values.foreach { coimpl =>
compileInterfaceInstance(
parent = ifaceId,
tmplParam = iface.param,
interfaceId = ifaceId,
templateId = coimpl.templateId,
interfaceInstanceBody = coimpl.body,
).foreach(addDef)
}
}

builder.result()
Expand Down
45 changes: 17 additions & 28 deletions sdk/daml-lf/language/daml-lf.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -105,48 +105,37 @@ def lf_versions_aggregate(versions):
# in a stable LF version.
lf_docs_version = lf_version_configuration.get("preview", lf_version_configuration.get("latest"))

# All LF dev versions
LF_DEV_VERSIONS = [
"2.dev",
]

# All LF versions
LF_VERSIONS = [
"2.1",
] + LF_DEV_VERSIONS

# All LF versions suported by the engine
ENGINE_LF_VERSIONS = [
"2.1",
"2.dev",
]
# fully supported LF dev versions
SUPPORTED_LF_DEV_VERSIONS = ["2.dev"]

def lf_version_is_dev(versionStr):
return _minor_str(versionStr) == "dev"
# fully supported LF versions
SUPPORTED_LF_VERSIONS = ["2.1"] + SUPPORTED_LF_DEV_VERSIONS

# The stable versions for which we have an LF proto definition under daml-lf/archive/src/stable
SUPPORTED_PROTO_STABLE_LF_VERSIONS = ["2.1"]
# All LF versions supported by the engine
ENGINE_LF_VERSIONS = ["2.1"] + SUPPORTED_LF_DEV_VERSIONS

# The subset of LF versions accepted by the compiler's --target option.
# Must be kept in sync with supportedOutputVersions in Version.hs.
COMPILER_LF_VERSIONS = ["2.1"] + LF_DEV_VERSIONS
COMPILER_LF_VERSIONS = ["2.1"] + SUPPORTED_LF_DEV_VERSIONS

# The subset of COMPILER_LF_VERSIONS with major version 2.
COMPILER_LF2_VERSIONS = [
v
for v in COMPILER_LF_VERSIONS
if version_in(v, v2_minor_version_range = ("0", "dev"))
]
# LF Versions supported by the dar reader
LF_VERSIONS = [] + ENGINE_LF_VERSIONS

def lf_version_is_dev(versionStr):
return _minor_str(versionStr) == "dev"

# The stable versions for which we have an LF proto definition under daml-lf/archive/src/stable
SUPPORTED_PROTO_STABLE_LF_VERSIONS = ["2.1"]

# All LF major versions
LF_MAJOR_VERSIONS = depset([_major_str(v) for v in LF_VERSIONS]).to_list()
SUPPORTED_LF_MAJOR_VERSIONS = depset([_major_str(v) for v in SUPPORTED_LF_VERSIONS]).to_list()

# The major version of the default LF version
LF_DEFAULT_MAJOR_VERSION = _major_str(lf_version_configuration.get("default"))

# The dev LF version with the same major version number as the default LF version.
LF_DEFAULT_DEV_VERSION = [
v
for v in LF_DEV_VERSIONS
for v in SUPPORTED_LF_DEV_VERSIONS
if _major_str(v) == LF_DEFAULT_MAJOR_VERSION
][0]
Loading
Loading