partial revert of [LF] drop retroactive interface instance #18282 (#18876)

* refactor bazel LF versions

* partial revert of [LF] drop retroactive interface instance #18282

recover retroacive instance in
- AST
- api-type-signature

* fmt

* Apply suggestions from code review

Co-authored-by: Paul Brauner <141240651+paulbrauner-da@users.noreply.github.com>

* address Paul's review

---------

Co-authored-by: Paul Brauner <141240651+paulbrauner-da@users.noreply.github.com>
This commit is contained in:
Remy 2024-04-02 12:11:36 +02:00 committed by GitHub
parent 11100b5f7f
commit e378a0f221
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
26 changed files with 327 additions and 107 deletions

View File

@ -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",
@ -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
@ -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
@ -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
],

View File

@ -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
@ -208,7 +208,7 @@ da_haskell_library(
":integration-lib",
],
)
for version in COMPILER_LF2_VERSIONS
for version in COMPILER_LF_VERSIONS
]
da_haskell_test(

View File

@ -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,

View File

@ -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")
@ -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) =

View File

@ -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",
@ -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",
@ -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.

View File

@ -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",
)
@ -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
]
[
@ -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(
@ -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,
@ -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",
@ -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(
@ -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",

View File

@ -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",
)
@ -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(

View File

@ -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()

View File

@ -105,21 +105,21 @@ 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",
]
# LF dev versions supported by archive reader
SUPPORTED_LF_DEV_VERSIONS = ["2.dev"]
# All LF versions
LF_VERSIONS = [
"2.1",
] + LF_DEV_VERSIONS
# LF dev versions supported by archive reader
SUPPORTED_LF_VERSIONS = ["2.1"] + SUPPORTED_LF_DEV_VERSIONS
# All LF versions suported by the engine
ENGINE_LF_VERSIONS = [
"2.1",
"2.dev",
]
# 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"] + SUPPORTED_LF_DEV_VERSIONS
# LF Versions supported by the dar reader
LF_VERSIONS = [] + ENGINE_LF_VERSIONS
def lf_version_is_dev(versionStr):
return _minor_str(versionStr) == "dev"
@ -127,19 +127,8 @@ def lf_version_is_dev(versionStr):
# The stable versions for which we have an LF proto definition under daml-lf/archive/src/stable
SUPPORTED_PROTO_STABLE_LF_VERSIONS = ["2.1"]
# 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
# 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"))
]
# 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"))
@ -147,6 +136,6 @@ 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]

View File

@ -734,6 +734,8 @@ object Ast {
param: ExprVarName, // Binder for template argument.
choices: Map[ChoiceName, GenTemplateChoice[E]],
methods: Map[MethodName, InterfaceMethod],
coImplements: Map[TypeConName, GenInterfaceCoImplements[E]] =
Map.empty, // Only used by LF 1.x
view: Type,
)
@ -745,6 +747,7 @@ object Ast {
choices: Iterable[GenTemplateChoice[E]],
methods: Iterable[InterfaceMethod],
view: Type,
coImplements: Iterable[GenInterfaceCoImplements[E]] = List.empty, // Only used by LF 1.x
): GenDefInterface[E] = {
val requiresSet = toSetWithoutDuplicate(
requires,
@ -758,8 +761,12 @@ object Ast {
methods.view.map(c => c.name -> c),
(name: MethodName) => PackageError(s"collision on interface method name $name"),
)
GenDefInterface(requiresSet, param, choiceMap, methodMap, view)
val coImplementsMap = toMapWithoutDuplicate(
coImplements.view.map(c => c.templateId -> c),
(templateId: TypeConName) =>
PackageError(s"repeated interface co-implementation ${templateId.toString}"),
)
GenDefInterface(requiresSet, param, choiceMap, methodMap, coImplementsMap, view)
}
def apply(
@ -768,8 +775,10 @@ object Ast {
choices: Map[ChoiceName, GenTemplateChoice[E]],
methods: Map[MethodName, InterfaceMethod],
view: Type,
coImplements: Map[TypeConName, GenInterfaceCoImplements[E]] =
Map.empty, // Only used by LF 1.x
): GenDefInterface[E] =
GenDefInterface(requires, param, choices, methods, view)
GenDefInterface(requires, param, choices, methods, coImplements, view)
def unapply(arg: GenDefInterface[E]): Some[
(
@ -778,9 +787,10 @@ object Ast {
Map[ChoiceName, GenTemplateChoice[E]],
Map[MethodName, InterfaceMethod],
Type,
Map[TypeConName, GenInterfaceCoImplements[E]],
)
] =
Some((arg.requires, arg.param, arg.choices, arg.methods, arg.view))
Some((arg.requires, arg.param, arg.choices, arg.methods, arg.view, arg.coImplements))
}
type DefInterface = GenDefInterface[Expr]
@ -794,6 +804,39 @@ object Ast {
returnType: Type,
)
final case class GenInterfaceCoImplements[E](
templateId: TypeConName,
body: GenInterfaceInstanceBody[E],
)
final class GenInterfaceCoImplementsCompanion[E] private[Ast] {
def build(
templateId: TypeConName,
body: GenInterfaceInstanceBody[E],
): GenInterfaceCoImplements[E] =
new GenInterfaceCoImplements[E](
templateId = templateId,
body = body,
)
def apply(
templateId: TypeConName,
body: GenInterfaceInstanceBody[E],
): GenInterfaceCoImplements[E] =
GenInterfaceCoImplements[E](templateId, body)
def unapply(
arg: GenInterfaceCoImplements[E]
): Some[(TypeConName, GenInterfaceInstanceBody[E])] =
Some((arg.templateId, arg.body))
}
type InterfaceCoImplements = GenInterfaceCoImplements[Expr]
val InterfaceCoImplements = new GenInterfaceCoImplementsCompanion[Expr]
type InterfaceCoImplementsSignature = GenInterfaceCoImplements[Unit]
val InterfaceCoImplementsSignature = new GenInterfaceCoImplementsCompanion[Unit]
final case class GenTemplate[E](
param: ExprVarName, // Binder for template argument.
precond: E, // Template creation precondition.

View File

@ -120,8 +120,7 @@ object Reference {
override def pretty: String = s"template without contract key $tyCon."
}
/** References an interface implementation of interfaceName for templateName,
* if a unique one exists.
/** References an non-retroactive interface implementation of interfaceName for templateName.
*/
final case class InterfaceInstance(interfaceName: TypeConName, templateName: TypeConName)
extends Reference {

View File

@ -22,11 +22,29 @@ private[daml] class PackageInfo(pkgSignature: Map[Ref.PackageId, Ast.GenPackage[
* Note that while interfaces may not be defined in `pkgSignature`, all template
* are.
*/
def interfaceInstances: Relation[Ref.Identifier, Ref.Identifier] =
def interfacesDirectImplementations: Relation[Ref.Identifier, Ref.Identifier] =
Relation.from(
templates.flatMap { case (tmplId, tmpl) => tmpl.implements.keysIterator.map(_ -> tmplId) }
)
/** return the relation between interfaces and all their retroactive implementations
* as defined in `pkgSignature`.
* The domain of the relation is the set of interface names, while the codomain
* is the set of template names.
* Note that while all interfaces are defined in `pkgSignature`, templates may not
* be.
*/
def interfacesRetroactiveInstances: Relation[Ref.Identifier, Ref.Identifier] =
Relation.from(
interfaces.flatMap { case (ifaceId, iface) =>
iface.coImplements.keysIterator.map(tmplId => ifaceId -> tmplId)
}
)
/* Union of interfacesDirectImplementations and interfacesRetroactiveInstances */
def interfaceInstances: Relation[Ref.Identifier, Ref.Identifier] =
Relation.union(interfacesDirectImplementations, interfacesRetroactiveInstances)
private[this] def withFullId[X](
pkgId: Ref.PackageId,
mod: Ast.GenModule[_],

View File

@ -254,15 +254,27 @@ object Util {
)
}
private[this] def toSignature(
coImplements: InterfaceCoImplements
): InterfaceCoImplementsSignature =
coImplements match {
case InterfaceCoImplements(name, body) =>
InterfaceCoImplementsSignature(
name,
toSignature(body),
)
}
private def toSignature(interface: DefInterface): DefInterfaceSignature =
interface match {
case DefInterface(requires, param, choices, methods, view) =>
case DefInterface(requires, param, choices, methods, view, coImplements) =>
DefInterfaceSignature(
requires,
param,
choices.transform((_, choice) => toSignature(choice)),
methods,
view,
coImplements.transform((_, v) => toSignature(v)),
)
}

View File

@ -73,6 +73,7 @@ class AstSpec extends AnyWordSpec with TableDrivenPropertyChecks with Matchers {
choices = Map.empty,
methods = Map.empty,
requires = Set.empty,
coImplements = Map.empty,
view = TUnit,
)
@ -422,8 +423,19 @@ class AstSpec extends AnyWordSpec with TableDrivenPropertyChecks with Matchers {
choices = List.empty,
methods = List(ifaceMethod1, ifaceMethod2),
view = TUnit,
coImplements = List(ifaceCoImpl1, ifaceCoImpl2),
)
a[PackageError] shouldBe thrownBy(
DefInterface.build(
requires = List.empty,
param = Name.assertFromString("x"),
choices = List.empty,
methods = List(ifaceMethod1, ifaceMethod2),
view = TUnit,
coImplements = List(ifaceCoImpl1, ifaceCoImpl1),
)
)
}
}
@ -454,6 +466,28 @@ class AstSpec extends AnyWordSpec with TableDrivenPropertyChecks with Matchers {
),
),
)
private val ifaceCoImpl1 = InterfaceCoImplements(
templateId = TypeConName.assertFromString("pkgId:Mod:T1"),
InterfaceInstanceBody(
methods = Map.empty,
view = EAbs(
(Name.assertFromString("this"), TUnit),
EBuiltinCon(BCUnit),
None,
),
),
)
private val ifaceCoImpl2 = InterfaceCoImplements(
templateId = TypeConName.assertFromString("pkgId:Mod:T2"),
InterfaceInstanceBody(
methods = Map.empty,
view = EAbs(
(Name.assertFromString("this"), TUnit),
EBuiltinCon(BCUnit),
None,
),
),
)
private val ifaceMethod1 = InterfaceMethod(name = Name.assertFromString("x"), returnType = TUnit)
private val ifaceMethod2 = InterfaceMethod(name = Name.assertFromString("y"), returnType = TUnit)
private def choiceBuilder(name: ChoiceName, typ: Type, expr: Expr) = TemplateChoice(

View File

@ -373,15 +373,28 @@ private[daml] class AstRewriter(
InterfaceMethod(name, apply(returnType))
}
def apply(x: InterfaceCoImplements): InterfaceCoImplements =
x match {
case InterfaceCoImplements(
templateId,
body,
) =>
InterfaceCoImplements(
apply(templateId),
apply(body),
)
}
def apply(x: DefInterface): DefInterface =
x match {
case DefInterface(requires, param, choices, methods, view) =>
case DefInterface(requires, param, choices, methods, view, coImplements) =>
DefInterface(
requires.map(apply(_)),
param,
choices.transform((_, v) => apply(v)),
methods.transform((_, v) => apply(v)),
apply(view),
requires = requires.map(apply(_)),
param = param,
choices = choices.transform((_, v) => apply(v)),
methods = methods.transform((_, v) => apply(v)),
view = apply(view),
coImplements = coImplements.map { case (t, x) => (apply(t), apply(x)) },
)
}
}

View File

@ -215,16 +215,25 @@ private[parser] class ModParser[P](parameters: ParserParameters[P]) {
(interfaceView <~ `;`) ~
rep(interfaceRequires <~ `;`) ~
rep(interfaceMethod <~ `;`) ~
rep(templateChoice <~ `;`) <~
rep(templateChoice <~ `;`) ~
rep(coImplements <~ `;`) <~
`}` ^^ {
case x ~ _ ~ tycon ~ _ ~ _ ~ _ ~
view ~
requires ~
methods ~
choices =>
choices ~
coImplements =>
IfaceDef(
tycon,
DefInterface.build(Set.from(requires), x, choices, methods, view),
DefInterface.build(
requires = Set.from(requires),
param = x,
choices = choices,
methods = methods,
view = view,
coImplements = coImplements,
),
)
}
private val interfaceView: Parser[Type] =
@ -238,6 +247,14 @@ private[parser] class ModParser[P](parameters: ParserParameters[P]) {
InterfaceMethod(name, typ)
}
private lazy val coImplements: Parser[InterfaceCoImplements] =
Id("coimplements") ~>! fullIdentifier ~ interfaceInstanceBody ^^ { case tplId ~ body =>
InterfaceCoImplements.build(
tplId,
body,
)
}
private val serializableTag = Ref.Name.assertFromString("serializable")
private val isTestTag = Ref.Name.assertFromString("isTest")
private val nonConsumingTag = Ref.Name.assertFromString("nonConsuming")

View File

@ -862,10 +862,17 @@ class ParsersSpec(majorLanguageVersion: LanguageMajorVersion)
, controllers Cons @Party [call_method @Mod:Person asParty this] (Nil @Party)
, observers Nil @Party
to upure @Int64 i;
coimplements Mod1:Company {
view = Mod1:PersonView { name = callMethod @Mod:Person getName this };
method asParty = Mod1:Company {party} this;
method getName = Mod1:Company {legalName} this;
};
} ;
}
"""
val TTyCon(company) = t"Mod1:Company"
val interface =
DefInterface(
requires = Set.empty,
@ -898,6 +905,25 @@ class ParsersSpec(majorLanguageVersion: LanguageMajorVersion)
update = e"upure @Int64 i",
),
),
coImplements = Map(
company ->
InterfaceCoImplements(
company,
InterfaceInstanceBody(
Map(
n"asParty" -> InterfaceInstanceMethod(
n"asParty",
e"Mod1:Company {party} this",
),
n"getName" -> InterfaceInstanceMethod(
n"getName",
e"Mod1:Company {legalName} this",
),
),
e"Mod1:PersonView { name = callMethod @Mod:Person getName this }",
),
)
),
view = t"Mod1:PersonView",
)

View File

@ -9,7 +9,7 @@ load(
)
load(
"//daml-lf/language:daml-lf.bzl",
"LF_DEV_VERSIONS",
"SUPPORTED_LF_DEV_VERSIONS",
"mangle_for_damlc",
)
load(
@ -42,7 +42,7 @@ da_scala_library(
srcs = ["src/test/daml/Simple.daml"],
target = version,
)
for version in LF_DEV_VERSIONS
for version in SUPPORTED_LF_DEV_VERSIONS
]
da_scala_test_suite(
@ -51,7 +51,7 @@ da_scala_test_suite(
srcs = glob(["src/test/scala/**/*.scala"]),
data = [
":Simple-{}.dar".format(mangle_for_damlc(version))
for version in LF_DEV_VERSIONS
for version in SUPPORTED_LF_DEV_VERSIONS
],
scala_deps = [
"@maven//:org_scalatest_scalatest_wordspec",

View File

@ -8,8 +8,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",
)
@ -22,7 +22,7 @@ load("@os_info//:os_info.bzl", "is_intel")
target = lf_version_default_or_latest(major),
visibility = ["//daml-lf:__subpackages__"],
)
for major in LF_MAJOR_VERSIONS
for major in SUPPORTED_LF_MAJOR_VERSIONS
]
[
@ -32,7 +32,7 @@ load("@os_info//:os_info.bzl", "is_intel")
target = version,
visibility = ["//daml-lf:__subpackages__"],
)
for version in LF_DEV_VERSIONS
for version in SUPPORTED_LF_DEV_VERSIONS
]
[
@ -43,7 +43,7 @@ load("@os_info//:os_info.bzl", "is_intel")
target = lf_version_default_or_latest(major),
visibility = ["//daml-lf:__subpackages__"],
)
for major in LF_MAJOR_VERSIONS
for major in SUPPORTED_LF_MAJOR_VERSIONS
]
[
@ -54,7 +54,7 @@ load("@os_info//:os_info.bzl", "is_intel")
target = lf_version_default_or_latest(major),
visibility = ["//daml-lf:__subpackages__"],
)
for major in LF_MAJOR_VERSIONS
for major in SUPPORTED_LF_MAJOR_VERSIONS
]
daml_build_test(
@ -84,7 +84,7 @@ daml_compile(
target = lf_version_default_or_latest(major),
visibility = ["//daml-lf:__subpackages__"],
)
for major in LF_MAJOR_VERSIONS
for major in SUPPORTED_LF_MAJOR_VERSIONS
]
[
@ -94,5 +94,5 @@ daml_compile(
target = version,
visibility = ["//daml-lf:__subpackages__"],
)
for version in LF_DEV_VERSIONS
for version in SUPPORTED_LF_DEV_VERSIONS
]

View File

@ -545,7 +545,7 @@ private[validation] object Typing {
private[Typing] def checkDefIface(ifaceName: TypeConName, iface: DefInterface): Unit =
iface match {
case DefInterface(requires, param, choices, methods, view) =>
case DefInterface(requires, param, choices, methods, view, _) =>
val env = introExprVar(param, TTyCon(ifaceName))
if (requires(ifaceName))
throw ECircularInterfaceRequires(ctx, ifaceName)
@ -598,7 +598,7 @@ private[validation] object Typing {
iiBody: InterfaceInstanceBody,
): Unit = {
val ctx = Context.Reference(Reference.InterfaceInstance(interfaceId, templateId))
val DefInterfaceSignature(requires, _, _, methods, view) =
val DefInterfaceSignature(requires, _, _, methods, view, _) =
handleLookup(ctx, pkgInterface.lookupInterface(interfaceId))
// Note (MA): we use an empty environment and add `tmplParam : TTyCon(templateId)`

View File

@ -243,8 +243,19 @@ private[validation] object ExprIterable {
choices,
methods @ _,
view @ _,
coImplements,
) =>
choices.values.iterator.flatMap(iterator(_))
choices.values.iterator.flatMap(iterator(_)) ++
coImplements.values.iterator.flatMap(iterator(_))
}
private[iterable] def iterator(x: InterfaceCoImplements): Iterator[Expr] =
x match {
case InterfaceCoImplements(
template @ _,
body,
) =>
iterator(body)
}
def apply(expr: Expr): Iterable[Expr] =

View File

@ -282,13 +282,20 @@ private[validation] object TypeIterable {
iterator(value)
}
private[validation] def iterator(coImpl: InterfaceCoImplements): Iterator[Type] =
coImpl match {
case InterfaceCoImplements(template, body) =>
Iterator(TTyCon(template)) ++ iterator(body)
}
private[validation] def iterator(interface: DefInterface): Iterator[Type] =
interface match {
case DefInterface(requires, _, choices, methods, view) =>
case DefInterface(requires, _, choices, methods, view, coImplements) =>
requires.iterator.map(TTyCon) ++
choices.values.iterator.flatMap(iterator) ++
methods.values.iterator.flatMap(iterator) ++
iterator(view)
iterator(view) ++
coImplements.values.flatMap(iterator)
}
private[validation] def iterator(imethod: InterfaceMethod): Iterator[Type] =

View File

@ -5,7 +5,7 @@
# daml_compile instead of a genrule.
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@build_environment//:configuration.bzl", "ghc_version", "sdk_version")
load("//daml-lf/language:daml-lf.bzl", "COMPILER_LF2_VERSIONS", "lf_version_default_or_latest")
load("//daml-lf/language:daml-lf.bzl", "COMPILER_LF_VERSIONS", "lf_version_default_or_latest")
[
genrule(
@ -43,7 +43,7 @@ EOF
tools = ["//compiler/damlc"],
visibility = ["//visibility:public"],
)
for lf_version in COMPILER_LF2_VERSIONS
for lf_version in COMPILER_LF_VERSIONS
]
# For convenience, we define daml3-script.dar which is always compiled to the
@ -60,7 +60,7 @@ filegroup(
name = "daml3-script-dars",
srcs = [
"daml3-script-{}.dar".format(lf_version)
for lf_version in COMPILER_LF2_VERSIONS
for lf_version in COMPILER_LF_VERSIONS
],
visibility = ["//visibility:public"],
)

View File

@ -14,8 +14,8 @@ load("@os_info//:os_info.bzl", "is_windows")
load("//rules_daml:daml.bzl", "daml_compile")
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",
)
@ -87,9 +87,9 @@ EOF
for (target, name) in [(
lf_version_default_or_latest(major),
major,
) for major in LF_MAJOR_VERSIONS] + [
) for major in SUPPORTED_LF_MAJOR_VERSIONS] + [
(target, target)
for target in LF_DEV_VERSIONS
for target in SUPPORTED_LF_DEV_VERSIONS
]
for scriptVersion in [
"",
@ -132,7 +132,7 @@ EOF
tools = ["//compiler/damlc"],
visibility = ["//visibility:public"],
)
for lf_version in LF_DEV_VERSIONS
for lf_version in SUPPORTED_LF_DEV_VERSIONS
]
# A variant of script-test that has not been uploaded to the ledger
@ -233,7 +233,7 @@ da_scala_library(
target = lf_version,
version = "1.0.0",
)
for lf_version in LF_DEV_VERSIONS
for lf_version in SUPPORTED_LF_DEV_VERSIONS
]
[
@ -245,7 +245,7 @@ da_scala_library(
# upgrades = "//daml-script/test:coin-v1-{}.dar".format(lf_version),
version = "2.0.0",
)
for lf_version in LF_DEV_VERSIONS
for lf_version in SUPPORTED_LF_DEV_VERSIONS
]
[
@ -257,7 +257,7 @@ da_scala_library(
# upgrades = "//daml-script/test:coin-v1-{}.dar".format(lf_version),
version = "2.0.0",
)
for lf_version in LF_DEV_VERSIONS
for lf_version in SUPPORTED_LF_DEV_VERSIONS
]
[
@ -269,7 +269,7 @@ da_scala_library(
# upgrades = "//daml-script/test:coin-v2-{}.dar".format(lf_version),
version = "3.0.0",
)
for lf_version in LF_DEV_VERSIONS
for lf_version in SUPPORTED_LF_DEV_VERSIONS
]
[
@ -291,7 +291,7 @@ da_scala_library(
target = lf_version,
version = "2.0.0",
)
for lf_version in LF_DEV_VERSIONS
for lf_version in SUPPORTED_LF_DEV_VERSIONS
]
[
@ -313,7 +313,7 @@ da_scala_library(
target = lf_version,
version = "2.0.0",
)
for lf_version in LF_DEV_VERSIONS
for lf_version in SUPPORTED_LF_DEV_VERSIONS
]
[
@ -335,7 +335,7 @@ da_scala_library(
target = lf_version,
version = "3.0.0",
)
for lf_version in LF_DEV_VERSIONS
for lf_version in SUPPORTED_LF_DEV_VERSIONS
]
daml_compile(
@ -374,7 +374,7 @@ da_scala_test_suite(
major = major,
scriptVersion = scriptVersion,
)
for major in LF_MAJOR_VERSIONS
for major in SUPPORTED_LF_MAJOR_VERSIONS
for scriptVersion in [
"",
"3",
@ -471,7 +471,7 @@ da_scala_test_suite(
":coin-v2-new-field-{}.dar".format(lf),
":coin-v3-{}.dar".format(lf),
":script-test-{}.dar".format(lf),
] for lf in LF_DEV_VERSIONS] for dep in deps] + [
] for lf in SUPPORTED_LF_DEV_VERSIONS] for dep in deps] + [
":script-test-no-ledger.dar",
"//compiler/damlc/tests:query-test.dar",
"//compiler/damlc/tests:try-submit-concurrently-test.dar",

View File

@ -10,8 +10,8 @@ load("@scala_version//:index.bzl", "scala_major_version")
load("//bazel_tools:scala.bzl", "da_scala_test")
load(
"//daml-lf/language:daml-lf.bzl",
"LF_DEV_VERSIONS",
"LF_VERSIONS",
"SUPPORTED_LF_DEV_VERSIONS",
"SUPPORTED_LF_VERSIONS",
"lf_version_configuration",
)
@ -452,7 +452,7 @@ daml_test(
enable_interfaces = True,
target = version,
)
for version in LF_DEV_VERSIONS
for version in SUPPORTED_LF_DEV_VERSIONS
]
daml_test(
@ -562,7 +562,7 @@ daml_test(
target = version,
deps = ["//daml-script/daml:daml-script-{}.dar".format(version)],
)
for version in LF_DEV_VERSIONS
for version in SUPPORTED_LF_DEV_VERSIONS
]
daml_build_test(

View File

@ -23,7 +23,7 @@ load(
)
load(
"//daml-lf/language:daml-lf.bzl",
"LF_VERSIONS",
"SUPPORTED_LF_VERSIONS",
"lf_version_configuration",
"lf_version_default_or_latest",
"lf_version_is_dev",
@ -220,7 +220,7 @@ scala_source_jar(
],
),
]
for target in LF_VERSIONS
for target in SUPPORTED_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.
@ -244,7 +244,7 @@ scala_source_jar(
project_name = "integration-tests-model",
target = ver,
)
for ver in LF_VERSIONS
for ver in SUPPORTED_LF_VERSIONS
]
daml_compile(
@ -366,7 +366,7 @@ java_test(
],
),
]
for target in LF_VERSIONS
for target in SUPPORTED_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.