Commit Graph

122 Commits

Author SHA1 Message Date
Robin Krom
3692a4a565
interfaces:ensure that implementations are ordered (#13071)
* interfaces:ensure that implementations are ordered

We make sure that the implementations are ordered by insertion in the
Scala AST. This is important to guarantee an evaluation order of the
interface preconditions that is determined by the order of interface
implementations of a template.

CHANGELOG_BEGIN
CHANGELOG_END

* use VectorMap instead of ListMap
2022-02-25 15:14:50 +00:00
Sofia Faro
b842b53ff4
Delete vestigial InterfaceChoice from AST (#13017)
* Delete vestigial InterfaceChoice from AST

This is a leftover from when interfaces had virtual choices.

changelog_begin
changelog_end

* delete more
2022-02-22 13:59:04 +00:00
Moisés Ackerman
7f6e1f08d4
Interface primitives continued (#12795)
* Extend daml lf parser to support new interface primitives

* Test parser on new interface primitives

* Add daml lf decoding test cases for new interface primitives

* Add TypingSpec test cases for new interface primitives

* add SBuiltinTest test cases for interface primitives

changelog_begin
changelog_end
2022-02-08 16:02:20 +01:00
Moisés Ackerman
3ce272b9f0
Replace experimental interface primitives with proper LF primitives (#12678)
* Add new primitives to proto spec

* implement E{Signatory,Observer}Interface in terms of EResolveVirtual{Signatory,Observer}

* define EToTypeRep primitive in terms of EToTypeRep Expr

* Remove experimental primitives TO_TYPE_REP and RESOLVE_VIRTUAL_{SIGNATORY,OBSERVER} 

changelog_begin
changelog_end
2022-02-03 13:36:45 +00:00
Stefano Baghino
aec3390904
Replace silencer plugin with built-in warning configuration (#12543)
Since Scala 2.13.2, Scala introduced built-in support to
manage warnings in a more granular fashion, thus making
the silencer plugin we are currently using no longer
strictly useful. Removing compiler plugins also removes
friction from migrating to Scala 3 in the future. As a
cherry on top, the built-in warning configuration also
allows to check whether a `@nowarn` actually does
anything, allowing us to proactively remove unused
warnings should the need arise.

[Here][1] is s a blog post by the Scala team about it.

Warnings have been either solved or preserved if useful,
trying to minimize the scope (keeping it at the single
expression scope if possible). In particular, all
remaining usages of the Scala Collection API compatibility
module have been removed.

Using the silencer plugin also apparently hid a few
remaining usages of compatibility libraries that were used
as part of the transition from Scala 2.12 to Scala 2.13
that are no longer needed. Removing those warnings
highlighted those.

changelog_begin
changelog_end

[1]: https://www.scala-lang.org/2021/01/12/configuring-and-suppressing-warnings.html
2022-01-24 15:01:35 +00:00
Gary Verhaegen
d2e2c21684
update copyright headers (#12240)
New year, new copyright, new expected unknown issues with various files
that won't be covered by the script and/or will be but shouldn't change.

I'll do the details on Jan 1, but would appreciate this being
preapproved so I can actually get it merged by then.

CHANGELOG_BEGIN
CHANGELOG_END
2022-01-03 16:36:51 +00:00
Remy
c53cf758da
LF: Add EToRequiredInterface and EFromRequiredInterface to Scala Ast. (#12042)
Part of #11978. Adds typechecking for those primitives.

CHANGELOG_BEGIN
CHANGELOG_END
2021-12-08 11:09:10 +00:00
Remy
9d7eb07745
LF: Add "requires" field to Scala Ast. (#12028)
Part of #11978. Adds typechecking for this field on the interface side,
and enforces that any template that implements A must implement B if A requires B.

CHANGELOG_BEGIN
CHANGELOG_END
2021-12-07 17:53:40 +00:00
Moritz Kiefer
8179c73763
Drop support for Daml-LF party literals from the Scala side (#11922)
* Drop support for Daml-LF party literals from the Scala side

This PR enforces that forbidPartyLiterals is always `true` and drops
the corresponding literals from the AST. Haskell side is in #11930

fixes #11581

changelog_begin
changelog_end

* Update daml-lf/interpreter/src/test/scala/com/digitalasset/daml/lf/speedy/ComparisonSBuiltinTest.scala

Co-authored-by: Remy <remy.haemmerle@daml.com>

* Revert "Update daml-lf/interpreter/src/test/scala/com/digitalasset/daml/lf/speedy/ComparisonSBuiltinTest.scala"

This reverts commit 55e542ce4e3a7fd15544ee703de3277ffc309b17.

Co-authored-by: Remy <remy.haemmerle@daml.com>
2021-12-01 10:37:42 +00:00
Sofia Faro
1d7bca801e
Add optional typerep argument in UExerciseInterface. (#11910)
* Add type rep argument for interface exercises.

(Still WIP.)

Part of #11703. Fixes the order in which errors are raised ("wrong type"
takes priority over "does not implement interface"). This PR also simplifies
ExerciseInterface by making the guard mandatory, otherwise there's too
many variations. We can revisit that later if we want.

changelog_begin
changelog_end

* haskell side

* dont throw exception in checkTemplateId

* scalafmt

* evidence security

* fix TypingSpec test
2021-11-30 15:10:33 +00:00
Remy
86da6e8eef
LF: Test scala interface type checking (#11833)
CHANGELOG_BEGIN
CHANGELOG_END
2021-11-24 15:58:45 +00:00
Sofia Faro
5c12d757f4
Add a guard when exercising by interface. (#11836)
* Add a guard when exercising by interface.

This fixes part of #11703, when exercising an inherited choice by
interface and you know the template id, via the command preprocessor.

It does this by inserting a "guard" in between the interface fetch and
the exercise body. The guard is a function Interface -> Bool, which
is general enough to check the template id, without complicating too
much in speedy. And can be generalized in the future to check more,
like signatories, etc.

I added the guard as an optional argument to UExerciseByInterface.
This isn't hooked up to the protobuf AST yet (or Haskell side for
that matter) -- but I'll do it in the next PR! For now you can invoke
the guarded exercise via the command preprocessor, so I can enable the
approprate engine tests. (There's still some failing fetch tests left,
but I decided to leave this for later. Fetch can be a lot simpler than
guarded choices, since you always add a fetch node. No need for fancy
continuations.)

changelog_begin
changelog_end

* scalafmt

* Feedback and fix matches

* Update comments, we are always going to abort the transaction

* Raise WronglyTypedContract in SBGuardTemplateId.

* rebase and fix parser

* restore ANF

* scalafmt
2021-11-24 14:22:40 +00:00
Remy
1610d977dc
LF: parsing interface primitives (#11825)
Continue work start in #11797

CHANGELOG_BEGIN
CHANGELOG_END
2021-11-23 12:03:03 +00:00
Remy
ae8391ee01
LF Parser: handle interface (#11797)
CHANGELOG_BEGIN
CHANGELOG_END
2021-11-22 14:49:02 +01:00
Remy
f33486154f
LF: Simplify LF Syntax (#11795)
- Do not wrapped choices in `choices { ... }`
- use sytematic `;` after choice component instead of ',`

CHANGELOG_BEGIN
CHANGELOG_END
2021-11-19 17:23:36 +01:00
Remy
cbe9c922ba
LF: Clean up Ast (#11786)
- rename non-default builders `apply` to `build`
  * avoid confusing both
  * make explicit the build can crash

- make interfaceId and templateId fields consitent

- use when possible named arguments

- check for non-repetition of inherited choices

CHANGELOG_BEGIN
CHANGELOG_END
2021-11-19 15:40:28 +01:00
Moritz Kiefer
3b5f8a73e1
Remove precondition field from TemplateImplements (#11763)
* Remove precondition field from TemplateImplements

fixes #11635

changelog_begin
changelog_end

* Update daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Compiler.scala

Co-authored-by: Remy <remy.haemmerle@daml.com>

Co-authored-by: Remy <remy.haemmerle@daml.com>
2021-11-18 17:10:40 +01:00
Sofia Faro
87f282c7f3
interfaces: Preserve/provide by_interface data for create actions. (#11639)
* interfaces: Preserve by_interface data for create.

Part of #10915

This was a lot more involved than fetch or exercise. The first issue is
that we need to preserve the interface id into speedy, so it needs a
separate primitive ("experimental" won't cut it). Second, because
speedy's create requires the template definition, and now the interface
id as well, we basically need to compile a separate version of "create"
for each interface that a template implements, hence the separate
`CreateByInterfaceDefRef(templateId, ifaceId)`.

changelog_begin
changelog_end

* scalafmt and refactoring

* fixx merge conflict

* fix silly mistakes
2021-11-11 12:57:55 +00:00
Moisés Ackerman
7d68e05f7f
Remove virtual choices (#11482)
* Remove virtual choices

* Remove choices without a body in 'interface' definition
* Remove choices in 'template ... implements' section

part of #11372

changelog_begin
changelog_end

* Remove virtual choices cont.

Switch uses of virtual choices to fixed choice with method implementation

* update snapshot after pin on windows

* Disable failing interface tests with TODO #10810
2021-11-08 17:05:23 +01:00
Robin Krom
da76e2825b
iface: check for interface implementations precond (#11494)
* iface: check for interface implementations precond

We change speedy to also check all preconditions defined in interface
implementations upon a create.

CHANGELOG_BEGIN
CHANGELOG_END

* Update daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Compiler.scala

Co-authored-by: Remy <remy.haemmerle@daml.com>

* format

* interfaces: lfconversion for iface preconditions

This adds interface preconditions to the interface implementations
during completion phase in the LF conversion.

CHANGELOG_BEGIN
CHANGELOG_END

* format

* rebase

Co-authored-by: Remy <remy.haemmerle@daml.com>
2021-11-02 17:27:49 +00:00
Sofia Faro
48afb7b5ea
interface: Add inherited choice names in scala AST (#11503)
Also checks that they're right. There's no collision checking yet.

Part of #11137.

changelog_begin
changelog_end
2021-11-02 14:35:37 +00:00
Robin Krom
b98a3ade29
interfaces: precondition, scala ast, decoder/encoder (#11452)
* interfaces: precondition, scala ast, decoder/encoder

This adds the interface precondition to the scala Daml LF AST, plus
decoder/encoder and the typechecker.

CHANGELOG_BEGIN
CHANGELOG_END

* Update daml-lf/archive/src/main/scala/com/digitalasset/daml/lf/archive/DecodeV1.scala

Co-authored-by: Remy <remy.haemmerle@daml.com>

* format

Co-authored-by: Remy <remy.haemmerle@daml.com>
2021-10-29 10:10:55 +00:00
nickchapman-da
67d4011fcd
Fix NonUnitStatements in daml-lf code (#11145)
* build daml-lf/* with lf_scalacopts_stricter; and fix NonUnitStatements

fix daml-lf/archive

CHANGELOG_BEGIN
CHANGELOG_END

fix daml-lf/data/

fix daml-lf/engine

fixes for scala 2.12

data-scalacheck, interface, kv-transaction-support: switch on; nothing to do

* daml-lf/parser -- switch on; nothing to do

* daml-lf/validation : switch on lf_scalacopts_stricter & fix wartremover:NonUnitStatements

* lf_scalacopts_stricter in daml-lf/transaction-test-lib

* lf_scalacopts_stricter in daml-lf/scenario-interpreter
2021-10-11 14:54:33 +01:00
Remy
4336184a79
LF: Add interface fixed choices in scala AST and type checker (#11146)
CHANGELOG_BEGIN
CHANGELOG_END
2021-10-08 08:59:26 +02:00
Sofia Faro
c1d1521a14
interface methods: Scala AST (#11070)
* interface methods: Scala AST

Part of #11006
This PR takes care of the Scala AST and decoder.
It leaves the encoder, type checker, and speedy for later.

changelog_begin
changelog_end

* scalafmt

* AstRewriter
2021-09-29 14:11:23 +00:00
Sofia Faro
d50df11f77
interface: Add to/from interface in scala ast (#10960)
Part of #10810

changelog_begin
changelog_end
2021-09-21 16:30:01 +00:00
Moritz Kiefer
9b0fa29aec
Separate exercise & fetch for interfaces from templates (#10908)
* Separate exercise & fetch for interfaces from templates

part of #10810

changelog_begin
changelog_end

* Update compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Base.hs

Co-authored-by: Sofia Faro <sofia.faro@digitalasset.com>

* Update compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Base.hs

Co-authored-by: Sofia Faro <sofia.faro@digitalasset.com>

Co-authored-by: Sofia Faro <sofia.faro@digitalasset.com>
2021-09-16 12:05:11 +00:00
Remy
e42cd3a1c6
LF: add interface to scala AST and decoder (#10830)
this is part of #10810

CHANGELOG_BEGIN
CHANGELOG_END
2021-09-10 08:46:19 +02:00
Remy
c4e0a755d4
LF: drop ad-hoc ImmArray builders (#10763)
Since we switch to scala 2.13, ImmArray companion object extends
`Factory`. Hence:

- the `apply` methods of `ImmArray` override the one from `Factory`

- we can use the notation `.to(ImmArray)` to convert an `Iterable` to
  `ImmArray`

This PR drops those `apply` ImmArray. Conversion from Iterable to
`ImmArray` should use the `.to(ImmArray)`.

CHANGELOG_BEGIN
CHANGELOG_END
2021-09-04 16:10:07 +02:00
Moritz Kiefer
6d0109fca8
Support $ in daml-lf identifiers in the parser (#10609)
These are valid daml-lf identifiers and we use them e.g. in
f8a1820cc8/daml-lf/validation/src/main/scala/com/digitalasset/daml/lf/validation/Typing.scala (L49).

Arguably `experimental` is also just easier to understand than `$`.

changelog_begin
changelog_end
2021-08-19 09:59:18 +02:00
Samir Talwar
4b8b67a1b5
Upgrade Scalatest to v3.2.9. (#10576)
* Upgrade Scalatest to v3.2.9.

Because of some coupling we also have to upgrade Scalaz to the latest
v7.2 point release, v7.2.33.

The Scalatest changes are quite involved because the JAR has been broken
up into several smaller JARs. Because Bazel expects us to specify all
dependencies and doesn't allow transitive dependencies to be used
directly, this means that we need to specify the explicit Scalatest
components that we use.

As you can imagine, this results in quite a big set of changes. They
are, however, constrained to dependency management; all the code remains
the same.

CHANGELOG_BEGIN
CHANGELOG_END

* http-json-oracle: Fix a Scalatest dependency.

* ledger-api-client: Fix a Scalatest dependency.
2021-08-12 23:19:35 +00:00
Remy
f033bc2bbb
LF: Clean legacy from archive proto + TEXT_TO_CODE_POINTS typo (#10286)
Thanks to @tristan-da for pointing this out.

CHANGELOG_BEGIN
CHANGELOG_END
2021-07-15 16:01:08 +02:00
Samir Talwar
e7e8a5705b
daml-lf/data: Optionally truncate party names in structured logs. [KVL-996] (#10163)
* daml-lf/data: Truncate party names in log output, on request.

The party name can grow quite long, so we offer ledger implementors the
opportunity to truncate it in structured log output.

Unfortunately, because we use Logback through the global
`LoggerFactory`, there is no place to inject logging configuration. This
means we also need to use global, mutable state to configure logging
output. I have added a `LoggingConfiguration` class+object in Daml-LF
Data, which may not be the best place, but I can't think of a better
one right now. I suggest we leave it there until it has reason to grow,
at which point we may want to move it.

CHANGELOG_BEGIN
CHANGELOG_END

* logging-entries: Make `ToLoggingValue` mixin-able.

* participant-integration-api: Truncate parties in filters when logging.

* participant-integration-api: Cast to `Party` for logging.

Invalid input should not break the request at this point. No assertions.

* daml-lf/data: Move `Party to LoggingValue` to a new package.

This avoids the transitive dependency issue most of the time.

* daml-lf-data: Move the `Identifier` logging to another package.

Again, reduces the need for transitively depending on _logging-entries_.
2021-07-01 16:50:49 +00:00
Samir Talwar
eda1245311
daml-lf/data: Add a conversion from Ref.Identifier to LoggingValue. (#10157)
I am getting quite tired of (Bazel + Scala)'s attitude to transitive
dependencies.

CHANGELOG_BEGIN
CHANGELOG_END
2021-06-30 20:05:06 +00:00
Remy
a3b10dc6f9
LF: fix parser (#9809)
CHANGELOG_BEGIN
CHANGELOG_END
2021-05-27 11:57:49 +02:00
Remy
1f021b25c6
LF: Drop Builtin Exceptions completly (#9790)
CHANGELOG_BEGIN
CHANGELOG_END
2021-05-26 19:30:44 +02:00
Remy
5855a9941f
LF: Drop CONTRACT_ERROR (#9754)
CHANGELOG_BEGIN
CHANGELOG_END
2021-05-21 09:12:29 +00:00
Remy
2e9bb21091
Engine: clean conversion builtin names (#9726)
Rename conversion builtins in the engine to follow
archive conventions.

This follows up #9716

CHANGELOG_BEGIN
CHANGELOG_END
2021-05-19 13:02:16 +00:00
Remy
fcbba1cd95
LF: rename convertion builtins to be more obvious (#9716)
The name of some builtins will be exposed as part of the Exception
message. This PR, try to make conversion builtins more consistent and
more obvious, before we could not rename those.

This is part of #8020

CHANGELOG_BEGIN
CHANGELOG_END
2021-05-19 10:11:26 +00:00
Remy
fc745f2224
LF: clean shifting BigNumeric builtin (#9704)
CHANGELOG_BEGIN
CHANGELOG_END
2021-05-17 19:26:14 +02:00
Sofia Faro
22ba5fddd2
Remove builtin exception types from protobuf and ASTs. (#9595)
* Remove builtin exception types from protobuf/AST.

changelog_begin
changelog_end

* Remove builtin exxceptions from protobuf/ast.

* remove unecessary s"

* scalafmt

* syntax error

* Add TODOs

* Apply suggestions from code review

Co-authored-by: Remy <remy.haemmerle@daml.com>

* Add AnyException builtins in typing spec.

* Update protobuf "Next id" comment.

Co-authored-by: Remy <remy.haemmerle@daml.com>
2021-05-06 21:26:12 +00:00
Moritz Kiefer
42d189dbbe
Support exceptions in Daml-LF encoder (#9590)
changelog_begin
changelog_end
2021-05-06 12:18:57 +02:00
Samir Talwar
e1af564bcc
Switch from @silent to @nowarn. (#9498)
* Switch from `@silent` to `@nowarn`.

This annotation is native to Scala 2.12.13+ and 2.13.2+. It replaces
most usages of `@silent`.

I had to get creative about a couple of use cases that didn't work.
Specifically:

  1.  Suppressing deprecation warnings works, but Scala 2.12 erroneously
      complains that the `@nowarn` is unnecessary.  I had to suppress
      this warning too with `-Ywarn-unused:-nowarn`.
  2.  I can't seem to suppress the warning, "The outer reference in this
      type test cannot be checked at run time." Instead, I have
      refactored the code to remove the warning.

We still need to use the silencer plugin to suppress some warnings about
unused imports (because of compatibility between Scala 2.12 and 2.13),
but this means we no longer need the library, and therefore it is not a
transitive dependency that downstream consumers need to worry about.

CHANGELOG_BEGIN
CHANGELOG_END

* Add some comments around `@nowarn` support.

* language-support/scala: Fix a warning suppression.

* Revert to the default warnings.

Compatibility was complaining.
2021-04-26 19:46:14 +00:00
Remy
6c1f404c7d
LF: Add TO_TEXT_BIGNUMERIC (#9276)
This is part of #8719.

CHANGELOG_BEGIN
CHANGELOG_END
2021-03-30 13:31:42 +02:00
Remy
51c5eac66e
LF: Add BigNumeric to archive proto (#9210)
CHANGELOG_BEGIN
CHANGELOG_END
2021-03-23 13:58:22 +00:00
Remy
2551b2d615
LF: Add BigNumeric and Rounding to Scala AST (#9205)
This advance the state of #8719

CHANGELOG_BEGIN
CHANGELOG_END
2021-03-23 09:16:27 +01:00
Remy
70379d4e85
LF: Experiment Hook for 1.dev (#9051)
This PR adds a hook in the compiler and the engine to allow easy prototyping of new features.

In particular by using this hook, one can add a new feature in 1.dev with modifying:

    compiler
    type checkers (both Haskell and Scala)
    archive Protobuf
    archive decoder

In addition of development speed, this also adds a bit of confidence, as the peaces enumerated above are not touched when adding the feature: The feature can be added by modifying only 1.dev Daml standard library and Speedy.

aa7991f8 shows a use case of this hook.

CHANGELOG_BEGIN
CHANGELOG_END
2021-03-11 21:36:49 +01:00
nickchapman-da
dbd017ee49
Support exceptions in speedy. (#8612) 2021-02-15 11:07:12 +00:00
Moritz Kiefer
22ce940954
Upgrade scalafmt and enable trailing commas (#8437)
This PR updates scalafmt and enables trailingCommas =
multiple. Unfortunately, scalafmt broke the version field which means
we cannot fully preserve the rest of the config. I’ve made some
attempts to stay reasonably close to the original config but couldn’t
find an exact equivalent in a lot of cases. I don’t feel strongly
about any of the settings so happy to change them to something else.

As announced, this will be merged on Saturday to avoid too many conflicts.

changelog_begin
changelog_end
2021-01-09 11:37:37 +01:00
Moritz Kiefer
02d8e8fe95
Port //daml-lf/(parser|validation) to Scala 2.13 (#8391)
* Port //daml-lf/(parser|validation) to Scala 2.13

changelog_begin
changelog_end

* Rename (Expr|Type)Traversable to (Expr|Type)Iterable

changelog_begin
changelog_end
2021-01-05 13:11:27 +01:00