Commit Graph

986 Commits

Author SHA1 Message Date
Moritz Kiefer
0549d07bdc
Port //daml-lf/interpreter to Scala 2.13 (#8421)
* Port //daml-lf/interpreter to Scala 2.13

For now the perf tests are left out since they depend on a DAR built
by damlc which depends on daml script which depends on the world
:exploding-head:

changelog_begin
changelog_end

* Scala 2.13-style to for ImmArray and FrontStack

changelog_begin
changelog_end

* Avoid extra conversion

changelog_begin
changelog_end
2021-01-07 10:13:08 +00:00
Remy
c49f319a6f
LF Spec: fix ordering of contract IDs. (#8389)
CHANGELOG_BEGIN
CHANGELOG_END
2021-01-06 14:33:20 +01:00
Remy
acf1134bae
LF: clone dev protobuf for LF 1.11 (#8373)
Create protobuf packages for DAML-LF 1.11

This is part of #7139

CHANGELOG_BEGIN
CHANGELOG_END
2021-01-06 14:32:26 +01:00
Remy
cdd9e36395
LF: document preview of LF 1.11 (#8401)
CHANGELOG_BEGIN
* Release preview of LF 1.11. Preview versions can be changed only to
  include bug fixes. Changes of LF 1.11 include:
  - add support for generic map;
  - add support for choice observers;
  - reduce archive size thanks to type interning.
CHANGELOG_END
2021-01-06 13:47:59 +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
Moritz Kiefer
746b5f4774
Remove a few redundant toString calls (#8379)
Spotbugs yelled at me and while they don’t do any harm they might be slightly confusing.

changelog_begin
changelog_end
2021-01-05 08:31:15 +01:00
Moritz Kiefer
54f597ae57
Add missing + in prettyKind (#8378)
changelog_begin
changelog_end
2021-01-04 17:29:19 +00:00
Remy
7c9331478b
LF: minro fixed suggested by Martin. (#8376)
from comments made in #8366.

CHANGELOG_BEGIN
CHANGELOG_END
2021-01-04 17:41:22 +01:00
Remy
57aa4993e9
LF: test LF 1.11 in DamlLfEncoderTest (#8365)
This is part of #7139.

CHANGELOG_BEGIN
CHANGELOG_END
2021-01-04 15:15:06 +00:00
Remy
425fca6541
LF: Scala serializability checker handle exceptions (#8363)
This is part of #8020.

CHANGELOG_BEGIN
CHANGELOG_END
2021-01-04 15:25:25 +01:00
Remy
8b5940842f
LF: fix specification of exceptions (#8366)
This is part of #8020.

CHANGELOG_BEGIN
CHANGELOG_END
2021-01-04 14:30:36 +01:00
Remy
693e5fac70
LF: prevent collision betweem templates and excetpions (#8367)
@sofiafaro-da noticed this was missing when reviewing #8364.

This is part of #8020.

CHANGELOG_BEGIN
CHANGELOG_END
2021-01-04 13:05:36 +00:00
Remy
ae915b8dee
LF: Scala type checker handle exceptions (#8364)
* LF: Scala type checker handle exceptions

This includes some fixes of the DAML-LF specifications.

This is part of #8020.

CHANGELOG_BEGIN
CHANGELOG_END
2021-01-04 13:47:15 +01:00
Moritz Kiefer
b324fc4551
Port //daml-lf/(transaction|language) to Scala 2.13 (#8343)
changelog_begin
changelog_end
2021-01-04 10:54:38 +01:00
Gary Verhaegen
a925f0174c
update copyright notices for 2021 (#8257)
* update copyright notices for 2021

To be merged on 2021-01-01.

CHANGELOG_BEGIN
CHANGELOG_END

* patch-bazel-windows & da-ghc-lib
2021-01-01 19:49:51 +01:00
Gary Verhaegen
93f449d245
rename master to main (#8245)
As we strive for more inclusiveness, we are becoming less comfortable
with historically-charged terms being used in our everyday work.

This is targeted for merge on Dec 26, _after_ the necessary
corresponding changes at both the GitHub and Azure Pipelines levels.

CHANGELOG_BEGIN

- DAML Connect development is now conducted from the `main` branch,
  rather than the `master` one. If you had any dependency on the
  digital-asset/daml repository, you will need to update this parameter.

CHANGELOG_END
2020-12-27 14:19:07 +01:00
Remy
9ba146a3e4
LF: Preview of LF 1.11 (#8280)
First step of LF 1.11 release #7139

Preview version is not stable and cannot be used in the ledger only in dev mode.

CHANGELOG_BEGIN
CHANGELOG_END
2020-12-18 17:08:22 +01:00
Moritz Kiefer
cb57ad374c
Port //daml-lf/data to Scala 2.13 (#8321)
* Port //daml-lf/data to Scala 2.13

changelog_begin
changelog_end

* factor common ImmArraySeq code to version-agnostic file

- ImmArraySeq itself is agnostic; the 2.12 and 2.13 versions contain
  implementation mixins/superclasses for parts that must be specific.  The 2.13
  version will collapse into the agnostic version when 2.12 support is no longer
  desired

* factor common InsertOrdMap code to version-agnostic file

- InsertOrdMap itself is agnostic; the 2.12 and 2.13 versions contain
  implementation mixins/superclasses for parts that must be specific.  The 2.13
  version will collapse into the agnostic version when 2.12 support is no longer
  desired

* factor common InsertOrdSet code to version-agnostic file

- InsertOrdSet itself is agnostic; the 2.12 and 2.13 versions contain
  implementation mixins/superclasses for parts that must be specific.  The 2.13
  version will collapse into the agnostic version when 2.12 support is no longer
  desired

* factor Map removal

* Move ImmArraySeq back into ImmArray

changelog_begin
changelog_end

* Type assertion instead of symbol

changelog_begin
changelog_end

Co-authored-by: Stephen Compall <stephen.compall@daml.com>
2020-12-18 13:20:15 +01:00
Remy
063ce6dc0f
LF: update LF parser with exceptions (#8332)
CHANGELOG_BEGIN
CHANGELOG_END
2020-12-18 13:06:24 +01:00
Remy
a8c4f1661b
LF: Add exceptions to Scala DAML-LF AST (#8312)
This advances states of #8020.

CHANGELOG_BEGIN
CHANGELOG_END
2020-12-17 17:45:32 +01:00
Remy
649f740efd
LF: retire ValueVersion (#8303)
use TransactionVersion instead.

This is part of #7788

CHANGELOG_BEGIN
CHANGELOG_END
2020-12-17 17:35:43 +01:00
Sofia Faro
33df124d84
Throw exceptions directly. (#8320)
* Update protobuf to throw exceptions directly.

Part of #8020. This PR changes the exception protobuf and AST (Haskell
side) to make exceptions be thrown directly via a primitive expression
(EThrow), instead of wrapping them up via AnyException.

changelog_begin
changelog_end

* Rename MakeAnyException to ToAnyException

* update EToAnyException field names

* Missing stuff

* missing scala case

* Make AnyException unserializable

* reindex protobuf builtins

* meaningless change

* refrobulate

* change pretty
2020-12-17 14:14:46 +00:00
nickchapman-da
2d511b449d
Make choice observers mandatory when available. (#8316)
* Make choice observers mandatory when available.

This is an invariant of the DAML-LF proto.

The haskell AST allows missing choice observers for any version, because the AST represents what was written in the syntax. However, if we are targeting a new DAML-LF version (>= `featureChoiceObservers`) then `Nothing` is converted to `Just (ENil TParty)` by the haskell encoder (`EncodeV1.hs`) to satisfy the proto invariant.

On the scala side, the decoder (`DecodeV1.scala`) now insists that choice observers are present when_ the version is new. (>= `LV.Features.choiceObservers`).

changelog_begin
changelog_end

* LF: LF encoder generate always choice observer if lf >= 1.dev (#8318)

This is a follow up of #8316.
This advances the state of #7709

CHANGELOG_BEGIN
CHANGELOG_END

Co-authored-by: Remy <remy.haemmerle@daml.com>
2020-12-16 14:38:25 +00:00
Remy
fe44764e61
LF: Refactor TransactionVersion (#8299)
Simplify transaction version. In particular we drop the dependency to LfVersions abstract class.

CHANGELOG_BEGIN
CHANGELOG_END
2020-12-16 11:27:54 +01:00
Stefano Baghino
6580dbd15c
Benchmarks for Speedy/DAML-LF/Protobuf translations [DPP-104] (#8272)
* Fix typos and inconsistencies

* Implement toString for SRequiresOnLedger

* Add benchmarks

changelog_begin
changelog_end

* Add copyright headers

* Make SubmissionBuilder final

* Address missing reference ledger export on Windows

* Fix README.md

* Add clarification on README.md

* Limit visibility of reference ledger export output

* Ensure benchmark recognizes the optionality of exercise return values

* Address https://github.com/digital-asset/daml/pull/8272#discussion_r542194308

* Follow up to changes from https://github.com/digital-asset/daml/pull/8273
2020-12-15 11:49:52 +00:00
Remy
91b53dd3f1
LF: Archive decoder reject choice observers for LF < 1.dev (#8283)
CHANGELOG_BEGIN
CHANGELOG_END
2020-12-15 09:42:54 +01:00
Remy
9bc2e4bd2c
LF: fix some of the choice-observer FIXMEs (#8281)
CHANGELOG_BEGIN
CHANGELOG_END
2020-12-14 18:26:49 +01:00
Remy
7d31135645
LF: retire VersionTimeline (#8273)
CHANGELOG_BEGIN
CHANGELOG_END
2020-12-14 16:56:47 +01:00
Moritz Kiefer
76b6fd86fb
Upgrade Scala dependencies for 2.13 compatibility (#8268)
* Upgrade Scala dependencies for 2.13 compatibility

This upgrades a bunch of Scala libraries to versions that have 2.13
support. There are two libraries that are still missing:

- diffson, this has a new version but with significant breaking
  changes and it is only used in Naigator console which I hope to kill
  before I have to worry about this.

- ai.x:diff, this is used in the ledger API test tool. The library is
  abondened but there are a few alternatives.

changelog_begin
changelog_end

* Fix pureconfig

changelog_begin
changelog_end

* Fix Navigator

changelog_begin
changelog_end
2020-12-14 09:59:00 +01:00
Remy
9dbc6dbfcc
LF: use constants for language/transaction versions. (#8261)
We use the constants defined in LanguageVersion/TransactionVersions instead 
repeating the somewhat magic constants "6", "7", "8", "10" and "dev" in multiple places?

CHANGELOG_BEGIN
CHANGELOG_END
2020-12-11 19:31:46 +01:00
Remy
44c5b8a777
LF: remove version from value nested in GenNode. (#8217)
CHANGELOG_BEGIN
CHANGELOG_END
2020-12-11 17:12:14 +01:00
Remy
009b030463
LF: Simplify Language Version representation (#8258)
We drop the distinction (at the type level) of Dev and Stable language
version.  The two main reason that motivate this choice:
* we never really used this distinction.
* we want to add the concept of "preview" version (which is neither Dev nor Stable)

CHANGELOG_BEGIN
CHANGELOG_END
2020-12-11 16:21:45 +01:00
Moritz Kiefer
5c077a4550
Add multi-party submissions to DAML Script (#8240)
* Add multi-party submissions to DAML Script

changelog_begin

- [DAMl Script] Add early-access submitMulti and submitMultiMustFail
  for multi-party submissions. This is only supported in DAML Studio at
  the moment.

changelog_end

* Fix daml-lf prettyprinter

changelog_begin
changelog_end

* Cleanup visibleIn

changelog_begin
changelog_end

* Fix JsonApiIt

changelog_begin
changelog_end

* s/Set()/Set.empty

changelog_begin
changelog_end

* Cleanup token check

changelog_begin
changelog_end

* Update daml-script/runner/src/main/scala/com/digitalasset/daml/lf/engine/script/LedgerInteraction.scala

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

* Document ParticipantView

changelog_begin
changelog_end

Co-authored-by: Remy <remy.haemmerle@daml.com>
2020-12-11 12:45:32 +01:00
Kamil Bożek
5db4ca687b
Multi-party command submission [KVL-699] (#8152)
Changes:
- replaced submitter: Party with actAs: Set[Party] and readAs: Set[Party] in com.daml.ledger.api.domain.Commands
- adapted contract and key lookups for multi-party submissions

* Changed single Commands to accept multiple submitters

* Removed submitter field from Commands

* Replaced submitters with actAs and readAs in Commands

* Moved actAs and readAs to com.daml.ledger.api.Commands

* Contract lookup tests

* Key lookup tests

CHANGELOG_BEGIN
CHANGELOG_END

* Formatted code changes

* Remove unused method

* Formatting fixes

* Simplified logical condition for active contracts visibility

* Removed unused temporary method in Commands

* Unified contract key lookup query for different type of db types

* Simplified ContractReader class structure

* Improved dao unit tests

* Unit tests for lookups as a divulgee

* Reduced code duplication in unit tests

* Minor improvement

* Formatted code

* Fixed a ContractsReader's query

* Improved unit tests

* Explanation for engine's command authorizers and contract readers

* Minor fixes

* Adapted SpannedIndexService for the multi-party submission
2020-12-11 10:04:15 +01:00
Remy
76c4380fef
LF: drop support from deprecated LF value versions. (#8083) (#8237)
* LF: drop support from deprecated LF value versions. (#8083)

CHANGELOG_BEGIN
CHANGELOG_END
2020-12-10 17:14:36 +01:00
Moritz Kiefer
4478d63c68
Improve error messages on use of contract ids in contract keys (#8236)
* Improve error messages on use of contract ids in contract keys

We got some feedback that "Unexpected contract id" sounds like an
internal error whereas this is really a user error.

changelog_begin
changelog_end

* Include templateId in error message

changelog_begin
changelog_end
2020-12-10 16:26:55 +01:00
Remy
e2e0523b78
LF: fix versioning output in LF Repl. (#8219)
With this PR, the Repl now:
* outputs the transaction version (not sure why it was not
there before)
* outputs the node version, because each node is now versioned
independently (See #7788)
* drops the value version, because it is dictated by the node version
(See #7788)

CHANGELOG_BEGIN
CHANGELOG_END
2020-12-09 17:40:12 +01:00
Remy
8f3c6a4494
LF: Add version directly in GenNode (#8154)
CHANGELOG_BEGIN
CHANGELOG_END
2020-12-08 16:12:12 +01:00
Moritz Kiefer
7e05dc7932
Upgrade rules-scala and scalatest (#8187)
This is necessary to at least attempt an upgrade to 2.13 and
generally, I want to keep our rulesets up2date. rules-scala forces the
version of scalatest so we have to bump that at the same time.

This requires changes to basically all Scala test suites since the
import structure has changed and a bunch of things (primarily
scalacheck support) got split out.

Apologies for the giant PR, I don’t see a way to keep it smaller.

changelog_begin
changelog_end
2020-12-08 06:59:23 +01:00
Remy
ab43da3f7a
Speedy: Add a built to optimize cons with 1 elems (#8177)
We have a builtin SBConsMany use to concatenate a list with a prefix
of variable size. Its appear that most of the concatenation happens
with only one element. For this reason we add a new builtin to handle
the most efficiently possible the case with 1 element.

CHANGELOG_BEGIN
CHANGELOG_END
2020-12-07 15:13:33 +01:00
Samir Talwar
88cb4c0981
daml-lf: Include position information in the testing parsers. (#8182)
So it's easier to figure out where I've gone wrong.

CHANGELOG_BEGIN
CHANGELOG_END
2020-12-07 12:33:00 +00:00
Samir Talwar
5943e1ae8d
daml-lf: Simplify types in the TransactionBuilder test helper. (#8178)
CHANGELOG_BEGIN
CHANGELOG_END
2020-12-07 09:46:24 +00:00
Samir Talwar
38de5b1eb3
daml-lf: Remove aliases that have been deprecated since v1.4. (#8155)
CHANGELOG_BEGIN
- [DAML-LF] Some types that were deprecated in DAML 1.4 have been
  removed. Please fix any deprecation warnings by using the new types
  before upgrading.
CHANGELOG_END
2020-12-03 17:07:42 +00:00
Stefano Baghino
56292dc191
Address leftover comments from 8019 (#8139)
changelog_begin
changelog_end

Address https://github.com/digital-asset/daml/pull/8019#discussion_r528755357

Address https://github.com/digital-asset/daml/pull/8019#discussion_r528763902

Address https://github.com/digital-asset/daml/pull/8019#discussion_r528767077

Address https://github.com/digital-asset/daml/pull/8019#discussion_r528773062
2020-12-03 09:23:16 +01:00
Remy
45b04724ec
LF: Change ordering of builtin type to follow proto declaration (#8133)
CHANGELOG_BEGIN
CHANGELOG_END
2020-12-02 18:38:03 +01:00
Samir Talwar
93acf1e6cd
Bazel: Reduce visibility of Protobuf JARs and accoutrements. (#8121)
* Bazel: Reduce the visibility of some Protobuf targets.

* Bazel: Make Protobuf JAR visibility parameterizable.

Default to private, and explicitly make it public where it's needed.

CHANGELOG_BEGIN
CHANGELOG_END
2020-12-01 14:00:44 +00:00
nickchapman-da
7d25cbba8b
test tail calls execute in constant env-stack (#8102)
* Tail-recursive function definitions execute with bounded environment and continuation stacks.

changelog_begin
changelog_end

* be more precise about the throw exception; use thrownBy

* add test for the KFoldr1Map/Reduce case
2020-12-01 10:35:58 +00:00
Martin Huschenbett
fbabb5e0f4
DAML-LF spec: Incorporate Remy's feedback on exceptions (#8111)
CHANGELOG_BEGIN
CHANGELOG_END
2020-11-30 18:08:31 +01:00
Remy
17bed0fd3b
LF: clean spec from deprecated version (#8108)
* LF: clean the spec from deprecated versions

This advances the state of #7155.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-30 15:32:57 +01:00
Kamil Bożek
012ae55d65
Engine API - multi-party submissions [KVL-703] (#8081)
* Multiple submitters field for Command

* Multiple submitters field for Engine API

* Tests for multi-party submissions in Engine

* Make use of multi-party Engine capabilities in the engine benchmark

* Enable multi-party submission in Engine's API
CHANGELOG_BEGIN
CHANGELOG_END

* Separate unit tests for multi-party engine

* Unit tests for multi-party submission transaction replay
2020-11-30 15:04:30 +01:00
Sofia Faro
72e2f7d967
Update protobuf for exceptions. (#8087)
* Update proto file for exceptions

* s/CONS/MAKE

* typo

* DefException

* var is interned

* fix DefException numbers

* adjust decoding slightly

* lint

* Update scala decoder.

changelog_begin
changelog_end

* update simplifier tests

* move the MAKE up front

* suggestions

* fix pretty

* add placeholder builtin infos on scala side

* add exceptions feature on scala side

* fix typos

* forgot THROW
2020-11-30 10:42:17 +00:00
Remy
e4869083fe
LF: drop support from deprecated LF versions. (#8083)
CHANGELOG_BEGIN
CHANGELOG_END
2020-11-27 21:33:45 +01:00
Samir Talwar
052f69cde9
ledger-api: Use proto_jars, and publish Protobuf sources separately from the Scala classes. [KVL-714] (#8091)
* ledger-api: Use `proto_jars`.

CHANGELOG_BEGIN
- [Ledger API] The Scala JARs containing the gRPC definitions no longer
  contain the *.proto files used to generate the ScalaPB-based classes.
CHANGELOG_END

* Create a source JAR for *.proto files in `proto_jars`.

* ledger-api: Publish the protobuf sources as "ledger-api-proto".

CHANGELOG_BEGIN
- [Ledger API] The *.proto files containing the gRPC definitions are now
  provided by a new Maven Central artifact, with the group "com.daml"
  and the artifact name "ledger-api-proto".
CHANGELOG_END

* release: We don't need the "main-jar" option.

* Bazel: Proto JARs will always have a Maven artifact suffix.

* Bazel: Simplify Protobuf source file TAR and JAR targets.

* Bazel: Extract out Protobuf functions.
2020-11-27 17:14:48 +00:00
Remy
10e360942b
LF: Optimize string validators (#8086)
String validators from com.daml.lf.data.IdString are use extensively.
This PR optimize the implementation of some of those.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-27 17:43:25 +01:00
Martin Huschenbett
da823c2c35
First batch of formal exception semantics (#8068)
* WIP Draft of formal exception semantics

CHANGELOG_BEGIN
CHANGELOG_END

* Make throw take an AnyException

* Don't allow templates as exceptions

* Make throw a builtin

* Pass the textual error message to to_any_exception

* Rename builtin exceptions to errors

* Rename to_any_exception in make_any_exception

* Fix typing rules for make/from_any_exception

* Add availability notes

* Fix typo
2020-11-27 16:12:32 +00:00
Remy
0c793790c9
LF: require type interning for 1.dev (#8069)
CHANGELOG_BEGIN
CHANGELOG_END
2020-11-27 13:20:54 +01:00
nickchapman-da
6afe9fff25
Refactor continuations for speedy machine (#8063)
* simplify interface to construct speedy continuations

move code from caller to definition

* relocate comment to the relocated code it refers to!

changelog_begin
changelog_end

* rename var: m -> machine

* relocate instrumentation print() from where KFinished is thrown, to where it is handled in run()

* revert KFinished back to an object (instead of a class taking machne); and revert back to use initialKontStack()
2020-11-27 11:56:46 +00:00
Samir Talwar
68459e60e9
Fix the paths of the files in protobufs.zip. (#8088)
Turns out the `package_dir` is not what we're looking for. Omitting it
fixes the path.

_Before:_

```
     1766  2010-01-01 00:00   protos-0.0.0/com/digitalasset/daml_lf_1_8/com/digitalasset/daml_lf_1_8/daml_lf.proto
```

_After:_

```
     1766  2010-01-01 00:00   protos-0.0.0/com/digitalasset/daml_lf_1_8/daml_lf.proto
```

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-27 11:51:22 +00:00
Samir Talwar
9976b4cd50
Bazel: Factor out logic around Protobuf JARs. [KVL-714] (#8084)
* kvutils: Use ScalaPB to generate a Scala JAR for daml_kvutils.proto.

* Bazel: Delete the unused `da_java_binary` rule, and inline `_wrap_rule`.

* Bazel: Factor out Java/Scala protobuf class generation into a helper.

CHANGELOG_BEGIN
CHANGELOG_END

* daml-lf/archive: Use `proto_jars`.

* Bazel: Remove the visibility modifier from `proto_jars`.

It's too confusing. Just make everything public.

* daml-lf/archive: Push protobuf source tarballs into `proto_jars`.

* Bazel: Add comments to the various parts of `proto_jars`.

* daml-assistant: Do unpleasant things with `location` in Bazel.
2020-11-27 08:34:53 +00:00
Remy
2b67c74d9a
LF: clean scala Decoder test. (#8077)
As requested by Martin in #8069, we extract most of the changes from
DecodeV1Spec in a separate PR.
This advances the state of #7155

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-26 16:16:27 +01:00
Remy
174ba1de30
Compiler: Clean compiler from from Exercise's actors (#8076)
This is the Haskell counterpart of #8071.
This advances the state of #7155.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-26 15:38:30 +01:00
Remy
41543ad161
LF: drop support for Exercise's actors (#8071)
This is a first set toward dropping support of deprecated LF version
(#7155).

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-26 14:38:16 +01:00
nickchapman-da
654f5e33b6
Fix tail-calls to execute in constant space by doing early pop of temporaries stack. (#8036)
changelog_begin
changelog_end
2020-11-25 15:12:21 +00:00
Andreas Lochbihler
2156f946d1
kvutils reports lookupByKey inconsistencies as Inconsistent (#7914)
CHANGELOG_BEGIN
kvutils reports LookupByKey node mismatches during validation as Inconsistent
instead of Disputed if they can be due to contention on the contract key
CHANGELOG_END
2020-11-25 13:36:26 +01:00
Martin Huschenbett
38a9c70a79
DAML-LF spec: Some minor fixes (#8050)
We correct some spelling mistakes and make the formatting of some rules a bit more consistent.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-24 15:07:54 +00:00
Remy
0e4adfc47b
LF: clean LF encoder from deprecated LF versions (#8049)
This advances the state of #7788.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-24 15:56:13 +01:00
Remy
68c92b479c
LF: version transaction node independently in proto (#7925)
This advances the state of #7788.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-24 14:07:33 +01:00
Stefano Baghino
d5ff0dd8ea
Refactor indexing to minimize transaction traversals (#8019)
* Refactor indexing to minimize transaction traversals

changelog_begin
[Integration Kit] Bugfix: daml.index.db.store_transaction metrics were keeping track of empty insertions, skewing down the numbers
[Integration Kit] Performance: minimizing the number of traversals of a transaction to index it, more efficient indexing
changelog_end

* Add empty stakeholders for non-consuming exercises

* Fix test to check usage of pre-computed blinding info

* Remove unnecessary string interpolators

* Shorten creation of net visibility

* Delete obsolete comment

* Add visibility of divulged contracts

* Address review https://github.com/digital-asset/daml/pull/8019#discussion_r527666572

* Address review https://github.com/digital-asset/daml/pull/8019#pullrequestreview-535399441

* Address review https://github.com/digital-asset/daml/pull/8019#discussion_r527681774

* Fix ordering of batches, use explicitly named types to avoid confusion

* Default to an empty set if a divulged contract is not visible in the current transaction

* Shorten references to store transaction metrics when writing

* Address review https://github.com/digital-asset/daml/pull/8019#discussion_r527745640

* Add divulgences from past transactions

* More fine-grained types and signatures
2020-11-24 13:08:35 +01:00
Martin Huschenbett
da551ea142
DAML-LF spec: Explain how to use LaTeX input (#8018)
Add a description of how to enable LaTeX input mode when editing the
DAML-LF spec in VS Code. Also add some additional symbols.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-20 13:41:10 +01:00
fabiotudone-da
2ff4d923a9
[KV] proto: add optional DamlTransactionBlindingInfo to DamlTransactionEntry [KVL-736] (#8005)
* KV proto: add optional DamlTransactionBlindingInfo to DamlTransactionEntry

CHANGELOG_BEGIN
CHANGELOG_END

* Wording

* Wording

* Rename party -> <action>_to for consistency

* Treat contract IDs as opaque strings (and for consistency)

* Address review comments
2020-11-19 15:09:23 +01:00
Martin Huschenbett
cfb8681b1c
DAML-LF spec: Fix some bad markup for links (#8010)
CHANGELOG_BEGIN
CHANGELOG_END
2020-11-19 09:06:34 +00:00
nickchapman-da
6a745ed1fa
Support choice observers in 1.dev (#7922)
* Adapt to new desugaring for choice observers.

update hash of ghc patch.

changelog_begin
changelog_end

update ghc patch to final version

update stack-snapshot hashes for ghc-lib(-parser)

update stackage_snapshot.json, following `bazel run @stackage-unpinned//:pin`

expose Optional constructors for desugared code to use

adapt LFConversion to expect a 4-tuple for a desugared choice def/sig

update LFConversion for choice-observers

first example using new choice observer syntax.

fix scala type checker to have correct scoping rules for choice-observers

remove comment from example which says it is broken

improve variable names

improve tests for choice-observer clause

only test choice-observers SINCE 1.dev

add jq queries for choice observeres

make positive statement in jq test which checks choice obserers are present

test behaviour of choice observers

squash me

typo

* test more choice-observer divulgence

* Update documention for choice observers.

changelog_begin
Support choice observers in 1.dev
changelog_end

* fix docs build

* fix daml docs choice-observers example

* address comments: rewording text

* annotate choices observers as early-access in documention

* split out documentation code-snippets which require --target=1.dev

* final tweaks to documentation text
2020-11-18 19:51:15 +00:00
Martin Huschenbett
f0e5bed36f
DAML-LF: Add interning for type to DAML-LF 1.dev (#7893)
* DAML-LF: Add interning for type to DAML-LF 1.dev

We add two new features to DAML-LF 1.dev:

* a per package list (or table) of `Type` messages, and
* a new case in the `Type` message which is an index into this table.

In combination, these two features can be used to allow DAML-LF
encoders to perform hash-consing of `Type` messages. We also change the
Haskell implementation of our DAML-LF encoder to do exactly that when
targetting DAML-LF 1.dev.

Doing this has a few benefits:

1. The DALFs produced by `damlc` get smaller: I've seen a case where
   the size dropped from 69MB to 45MB.
2. DAML-LF decoders need to decode less data.
3. Decoded packages use less memory because identical structures are
   now shared. This is particularly helpful in situations where we need
   to keep the interface (or signature) of a package in memory for a
   long time.

This PR mostly takes care of the Haskell implementation. However, we
need to make the Scala implementation of the decoder aware of the new
features as well since we have tests that load DAML-LF 1.dev into the
engine. A decoder and _targeted_ tests on the Scala side will follow
in a separate PR.

CHANGELOG_BEGIN
CHANGELOG_END

* Make jq tests aware of type interning

CHANGELOG_BEGIN
CHANGELOG_END

* Improve jq test

CHANGELOG_BEGIN
CHANGELOG_END

* Apply Remy's suggestions

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

* Improve the imperative bits

CHANGELOG_BEGIN
CHANGELOG_END

Co-authored-by: Remy <remy.haemmerle@daml.com>
2020-11-18 11:14:30 +00:00
nickchapman-da
cdcfd379f0
When computing blinding info, divulge to choice-observers. (#7970)
changelog_begin
changelog_end
2020-11-16 16:35:31 +00:00
Remy
6700400760
LF: Update DAML-LF Governance process (#7926)
CHANGELOG_BEGIN
CHANGELOG_END
2020-11-13 15:03:54 +01:00
Remy
5ca5cc7e98
LF: few more tests for pattern matching exhaustiveness (#7959)
This follows late requests made by Martin in #7936.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-13 13:03:36 +00:00
Remy
c093e094cb
LF: Check DAML-LF pattern matches for exhaustiveness (#7936)
This reproduces changes made to the Haskell type checker (in #7892) in
the Scala type checker.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-13 10:47:11 +01:00
Remy
732c1ac792
LF: Make node validation taking into account version (#7947)
We introduce in #7835 VersionedNode which associate to each node a
version. In this PR, we update Transaction validation to take into
account this version when comparing nodes.

This advances the state of #7788

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-13 10:46:29 +01:00
Remy
57bc2c95c1
LF: check for ill-formed kinds in scala type checker. (#7949)
Following what have been done in #7944, we add a check in the Scala
version of the LF type checker that rejects invalid kinds (i.e. kinds
of the form k -> Nat).

This PR does the "Scala side" of #7917.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-12 13:52:56 +01:00
Sofia Faro
0057016519
Require pattern matching exhaustiveness in the LF spec. (#7946)
* Require pattern match exhaustiveness in spec.

Changes the rules for case expressions to require exhaustiveness.
This involves moving out the "well-formed case alternative" rules
to a separate judgement, and introducing a "pattern match
exhaustiveness" judgement.

The symbol ⊲ used for pattern match exhaustiveness comes from
sheaf theory and formal topology, where "A ⊲ B₁, …, Bₙ" means
"A is covered by { B₁, …, Bₙ }", indicating an exhaustive
coverage of A by possibly overlapping conditions B₁, …, Bₙ.
For example, see [this nlab page](https://ncatlab.org/nlab/show/posite).

It seemed appropriate.

changelog_begin
changelog_end

* rst syntax

* fix ExhaustVariant and some weird other syntax

* review comments
2020-11-12 11:47:55 +00:00
Remy
51d134f925
LF: fix complexity of TransactionBuilder#addNode (#7930)
Fix issue with slowSnoc underlines by Martin in #7835

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-11 12:57:59 +01:00
Remy
a14035cea5
Drop plan to implement contract key. (#7924)
Remove file describing how contract key will be implement.  The file
is not usefull as contract key have been fully implemented. Futhermore
the file contains plenty of out of date information.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-10 12:41:41 +01:00
Remy
a8902a75db
LF: version transaction node independently (#7835)
This PR prepares the change of inference algorithm described #7788
where each node is version independently. This PR associates to each
node of `VersionedTransaction` a version. In the current state, all
nodes are associated to the version of the transaction itself. The
inference algorithm (that will make those versions potentially
distinct) will be implemented in an upcoming PR.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-10 12:12:16 +01:00
Remy
db8fbcb502
LF: fix test scala type checker (#7905)
This PR fixes two bugs in the type checker:

- Fetch are now rejected if the type constructor does not match a
  template
- to_any, from_any, and type_rep are now rejected if the type
  parameter contains synonyms.


Additionally, this PR adds the type of the validation error that each
test case should throw in the test that ill formed expression are
properly rejected.  In the way we fix some wrong test cases.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-09 16:26:34 +01:00
Remy
6fd12862c2
LF: redesign transaction validation to return mismatching nodes. (#7826)
- Exercises' results are checked after the children have been checked.
- output the mismatching nodes in case of comparison failure.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-05 18:25:10 +01:00
Martin Huschenbett
feb3510a7c
DALF Reader: Refactor decoder environment (#7891)
* DALF Reader: Refactor decoder environment

Currently, the module to be decoded is part of the decoder environment.
This turned out to be unpleasant during my attempts to implement
interning for types since decoding the type interning table does not
happen in the context of a module.

This PR moves the module out of the decoder environment and passes it
to the decoder function for modules directly. Unfornatunately, we still
need to keep the module name in the environment since that is used as a
default when decoding location information. We solve this problem by
making the module name in the environment optional and always filling
it in when decoding in actual module.

CHANGELOG_BEGIN
CHANGELOG_END

* Adapt tests

CHANGELOG_BEGIN
CHANGELOG_END

* Follow Remy's suggestion

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-04 21:18:34 +00:00
Remy
37eb1d4c4c
LF: Kill deprecated Transaction version. (#7785)
This PR drops support for Transaction version 1 to 9. This is a
breaking change that may affect only ledger created with a pre SDK
1.0.0. No Sandbox-based ledger is affected by this change.

This advances the state of #7788

This breaking change was approved by the architecture committed.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-04 15:45:42 +01:00
Remy
5c36f07832
LF: Rotate type checking of case expressions by 90 degrees (#7883)
* LF: Rotate type checking of case expressions by 90 degrees

This reproduces changes made to the Haskell type checker (in #7873) 
into the Scala type checker.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-04 14:50:52 +01:00
Remy
8677bd92f3
LF: remove allowed transaction versions from EngineConfig. (#7861)
This is a followup of #7858.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-03 10:43:06 +01:00
Remy
21c1c951f1
LF: remove control of input/output value/transaction versions. (#7858)
This is made obsolete by #7788.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-02 20:02:53 +01:00
Remy
23ba79ca6b
LF: drop legacy logic to infer transaction versions. (#7856)
This advances the state of #7788

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-02 19:15:55 +01:00
Remy
7325499ff9
LF: fix CidContainer2 (#7857)
Drop useless type variables in the definition of CidContainer2.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-02 19:15:36 +01:00
Martin Huschenbett
8519e52f03
Speedy: Add more tests for multi record updates (#7848)
Add two more tests for the following cases:
1. The Expressions the values should be updated with are non-atomoic.
   This tests that our internal ANF transformation doesn't destroy the
   omptimization. (In fact, it can't really do that because it is run
   after the phase which does the optimization. But better safe than
   sorry.)
2. A single record field is updated multiple times. This tests that
   the last update wins. Unfortunately, we cannot drop the earlier
   updates, or at least computing their values, since these values
   might be bottom. (We could add an optimization _after_ we've
   transformed into ANF but I don't expect any benefits from this in
   practice and would hence not do it.)

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-02 08:43:57 +00:00
Jussi Mäki
fa9bc4a984
Cache computation of top-level values at definition level (#7818)
* Cache computation of top-level values at definition level

Earlier the computation of a top-level value was only cached at the
use-site in SEVal. This introduces SDefinition which contains the same
mechanism as SEVal to cache the computation.

As expected this does not impact performance much:

before: CollectAuthority.bench  //daml-lf/scenario-interpreter/CollectAuthority.dar  CollectAuthority:test  avgt   40  44.267 ± 0.728  ms/op
after: CollectAuthority.bench  //daml-lf/scenario-interpreter/CollectAuthority.dar  CollectAuthority:test  avgt   40  43.693 ± 0.702  ms/op

What this does have a significant impact is on reducing the number of distinct
SValues for things like type class dictionaries etc, so that now we have one
SValue per dictionary rather than one per SEVal.

CHANGELOG_BEGIN
CHANGELOG_END

* Address code review

* Fix speedy tests
2020-10-28 13:39:20 +00:00
Remy
a845f66a62
LF: Make the compiler using less stack when compiling commands (#7807)
CHANGELOG_BEGIN
CHANGELOG_END
2020-10-26 14:11:23 +01:00
Remy
67370104da
LF: add ad-hoc toString to GlobalKey (#7797)
CHANGELOG_BEGIN
CHANGELOG_END
2020-10-26 13:42:22 +01:00
Remy
93a098612e
LF: add TransactionCoder test for choiceObservers (#7795)
advances the state of #7709.

CHANGELOG_BEGIN
CHANGELOG_END
2020-10-26 09:42:46 +01:00
Martin Huschenbett
35a401f575
Fix scenario service vs struct projections bug (#7778)
* Fix scenario service vs struct projections bug

In a recent change, we have sped up the projection from structural
records by means of an inference in the DAML-LF type checker. This
change was made under the assumption that users of the DAML interpreter
run through package validation before compiling to the internal Speedy
AST. Unfortunately, that assumption was wrong and not covered by our
existing tests.  Manually testing of a new release candidate reminded us
of the fact that the scenario service skips package validation for the
sake of faster response times in the IDE.

This PR drops the assumption that package validation is always run.
Instead, we add the old implementation of struct projection, which works
without DAML-LF type checking, back and use it whenever the AST has not
been annotated with the information inferred by the type checker. We do
the same for struct updates.

We improve test coverage by _additionally_ running the `damlc`
integration tests without package validation for the latest stable
version of DAML-LF and DAML-LF 1.dev. These tests would have caught the
issue we only discovered during manual testing.

CHANGELOG_BEGIN
CHANGELOG_END

* Add some explanations

CHANGELOG_BEGIN
CHANGELOG_END
2020-10-23 13:30:56 +02:00
Remy
c961e795e3
LF: rename value version 7 and transaction version 10, dev (#7779)
This make clear wich which value and transaction version correspond to
1.dev.

CHANGELOG_BEGIN
CHANGELOG_END
2020-10-22 16:02:43 +02:00
nickchapman-da
fd5db0cfd7
choice observers, prep (#7548)
* choice observers, WIP

changelog_begin
changelog_end

fix generator driven test

Node.isReplayedBy, consider observers

add observers to NodeExercise in transaction.proto

add observers to TemplateChoice in Ast.scala

add observers to LF .proto, and Haskell Ast for TemplateChoice

reinstate trailing // for better format

fix validate tests

fix haskell LF decoder when choice-observers field is missing in .proto

fix build

make choice-observers optional in scala AST

make choice-observers optional in Haskell Ast

address comments from Remy and Martin

more review comments

check TransactionVersions.minChoiceObservers in Transaction encode/decode

featureChoiceObservers, and check in haskell type-checker

improve speedy Compiler for empty choice-observers

extend scala LF decoder for optional choice observers

extend scala parser for choices to allow optional choice-observers clause, and test

rename new field in scala Ast -> "choiceObservers"

var rename

extend TypingSpec tests for choice-observers. also add missing negative test for controllers

switch from keyword "ob" to identifier "observers" in scala parser choice syntax

add TODO for featureChoiceObservers to be part of DAML 1.9 (issue 7139)

* replace "NICK" comment markers with "FIXME #7709" comment markers
2020-10-21 11:15:18 +01:00
nickchapman-da
b7f8e3a812
Regularize scala mod-parser syntax for controllers (#7748)
* Regularize scala mod-parser syntax for controllers in preparation for adding choice-observers.

From keyword "by" to identifier "controllers" + leading ","

changelog_begin
changelog_end

* fix another use of the old "by" syntax -> ", controllers"
2020-10-20 16:16:45 +01:00
Martin Huschenbett
7b7839c2d9
Speed up updates of structural records (#7742)
This is pretty much a verbatim copy of
https://github.com/digital-asset/daml/pull/7740, but for updates of
structural records instead of projections.

This has no immediate performance impacts since the DAML compiler does
_currently_ not produce any structural record updates. Having both,
projections and updates, have the same runtime characteristics seems to
be a desirable property nevertheless, simply to avoid nasty surprises
should we ever start to use these updates.

Since the compiler does not produce any structural record updates, I
have no way to benchmark this. However, since the code is changed here
in the same way it was changed in the PR mentioned above, I expect the
same saving, which were roughly 80 ns per operation, where the previous
cost of an operation was _at most_ 210 ns.

CHANGELOG_BEGIN
CHANGELOG_END
2020-10-20 11:28:09 +02:00
Martin Huschenbett
3665025acb
Speed up projections of structural records (#7740)
* Speed up projections of structural records

Currently, for every projection of a structural record, we first do a
linear search through the field names to find the index of the field
value in the record value. Then we use this index to get the actual
value. However, since we started sorting the fields in alphabetic order
both in types and in values, this lookup will always yield the same
result for a fixed record type and a fixed field name, regardless of the
value of the record.

This PR changes the AST node for structural record projection to
contain the index of the field within the record as well. This
information is not contained in the DAML-LF archive itself and must
hence be filled in by the DAML-LF type checker.

The only context in which we use structural record prejections are
typeclass method invocations, which do a little bit more than just the
projection. Unfortunately, typeclass method invocations are the small
unit of work I can benchmark using the setup I have. In the end, they
are also the feature our users really care about.

My benchmarks show that the time a single typeclass method invocation
takes has dropped from ca. 210ns to ca. 130ns. That's a speedup of
ca. 1.6x.

CHANGELOG_BEGIN
[DAML Interpreter] Typeclass method invocation is now 1.6x faster.
CHANGELOG_END

* Apply Remy's suggestions

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

* Make it compile again

CHANGELOG_BEGIN
CHANGELOG_END

Co-authored-by: Remy <remy.haemmerle@daml.com>
2020-10-19 22:05:13 +02:00
Remy
27a4acafa4
LF: update DAML-LF specification with exercise_by_key. (#7702)
* LF: update DAML-LF specification with exercise_by_key.

CHANGELOG_BEGIN
CHANGELOG_END
2020-10-19 13:11:44 +02:00
Remy
9b2a7d59e8
LF: enforce non-empty maintainers in contract key in fetchByKey (#7649)
This fixes a bug in the Speedy interpreter. With this change, the
interpreter crashes if it attempts to fetch using a contract key that
has an empty set of maintainers. This propagates to exerciseByKey as
this command is compiled using fetchByKey speedy built-in.

This is a breaking change approved by @bame-da .

CHANGELOG_BEGIN
    [LF] (Bug fix) enforce non-empty maintainers in contract key during fetchByKey and exericiseByKey.
CHANGELOG_END
2020-10-15 12:22:56 +02:00
Moritz Kiefer
cd4f085e92
Support multiple parties in scenario’s ParticipantView (#7666)
As part of multi-party read/write on command submissions we also need
to be able to support multi-party queries in DAML Script. Since the
queries in DAML Studio go via ParticipantView, this PR extends this as
a prerequisite to making use of this in DAML Script.

This does not yet relax any restrictions on command submissions. Those
still require a single committer.

For consistency with the surrounding code, I went for a simple Set
rather than a non-empty Set.

changelog_begin
changelog_end
2020-10-14 12:51:02 +02:00
Remy
0bb378690d
LF: Add ExerciseByKey Update (#7663)
CHANGELOG_BEGIN
CHANGELOG_END
2020-10-14 12:06:36 +02:00
Stephen Compall
bafde51752
add silent_annotations option to da_scala bazel functions (#7668)
* add silent_annotations option to da scala bazel functions

* use silent_annotations for several scala targets

* use silencer_plugin instead when the lib isn't used

* use silent_annotations for several more scala targets

* use silencer_lib for strange indirect requirement for running tests

* no changelog

CHANGELOG_BEGIN
CHANGELOG_END

* silent_annotations support for scaladoc
2020-10-13 15:44:16 +00:00
Stephen Compall
1a2afd5266
upgrade to Scala 2.12.12 from 2.12.11 (#7661)
* upgrade bazel settings to scala 2.12.12

* upgrade nix scala tool to scala 2.12.12

* upgrade silencer references to scala 2.12.12

* repin for scala 2.12, silencer, wartremover upgrades

* remove numerous occurrences of unused silencer now spotted

* update Scala version in our bazel notes

CHANGELOG_BEGIN
CHANGELOG_END

* update compatibility maven_install.json to match compatibility WORKSPACE
2020-10-13 08:42:14 -04:00
Remy
8a9e59d99e
LF: mark nodes if they correspond to a "by key" operation. (#7617)
Currently the list of node that correspond to a "by key" operations 
is tracked in the Transaction metadata. this PR move this information 
into the nodes themself.

This is a preparatory work to include this information in the serialization 
format for  transactions

This advances the state of  #7622

CHANGELOG_BEGIN
CHANGELOG_END
2020-10-13 12:44:03 +02:00
Remy
dc34d4f637
LF: add PackageInterface a lightweigh Package (#7577)
CHANGELOG_BEGIN
CHANGELOG_END
2020-10-13 12:41:22 +02:00
Remy
bebbbc14cd
LF: enforce non-empty maintainers in contract key lookup (#7610)
* LF: enforce non-empty maintainer in contracts key lookup

This fixes a bug in the Speedy interpreter.  With this change, the
interpreter crashes if it attempts to lookup using a contract key that
has an empty set of maintainers.

This is a breaking change approved by Bernhard Elsner.

CHANGELOG_BEGIN
- [LF] (Bug fix) enforce non-empty maintainers in contract key during
  lookupByKey.
CHANGELOG_END

* Apply suggestions from code review

Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>

* Address Moritz's  review.

* Address Martin's review

Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
2020-10-12 14:32:46 +02:00
Remy
ea2a637a11
LF: decouple template from record in the Scala Ast. (#7631)
CHANGELOG_BEGIN
CHANGELOG_END
2020-10-12 11:28:30 +02:00
Moritz Kiefer
e09c31899d
Connectify user-facing output (#7624)
Together with #7615, this overs all items in #7612.

changelog_begin
changelog_end
2020-10-09 15:45:02 +02:00
Remy
be35f3a31f
kutils: Make the validation and the preloading of PackageCommitter parametric (#7460)
This PR creates 3 validation modes:
* `Strict`: Specifies that the committer should validate the package
  before committing them to the ledger. When using this mode, the
  packages committed to the ledger can be fully trusted and do not
  have to be validated when loaded into the engine.
* `Lenient`: Specifies that the committer should perform a fast
  validation of the packages before committing them to the ledger.
  This mode is useful for ledger integrations that cannot handle
  long-running submissions (> 10s). When using this mode, the
  packages committed to the ledger cannot be trusted and must be
  validated every time they are loaded into the engine.
* `No`: Specifies that the committer should not perform any
  validation the packages before committing them to the ledger. This
  should be used only by non distributed ledgers, like DAML-on-SQL,
  where the validation done in the API server can be trusted.

This PR creates 3 preloading modes:
* `Synchronous` : Specifies that the packages should be preloading
  into the engine before committed.
* `Asynchronous`: Specifies that the packages should be preloaded into
  the engine asynchronously with the rest of the commit process. This
  mode is useful for ledger integrations that cannot handle
  long-running submissions (> 10s). Failure of the preloading process
  will not affect the commit.
* `No`: Specifies that the packages should not be preloaded into
  the engine.

CHANGELOG_BEGIN
-   [Integration Kit] In kvutils, add metric
    daml.kvutils.committer.package_upload.validate_timer to track
    package validation time.
CHANGELOG_END
2020-10-08 15:03:14 +02:00
Remy
cf89f6a74d
LF: enforce non-empty maintainer in contracts key. (#7597)
This fixes a bug in the Speedy interpreter.  With this change, the
interpreter crashes if it attempts to create a contract containing a 
contract key that has an empty set of maintainers.

This is a breaking change approved by Bernhard Elsner. 

CHANGELOG_BEGIN
- [LF] (Bug fix) enforce non-empty maintainers in contract key during
  contract creation.
CHANGELOG_END
2020-10-08 14:59:41 +02:00
Remy
31f274ebca
LF: force actor field in Exercise Update to be undefined. (#7578)
* LF: force `actor` field in Exercise Update to be undefined.

This PR forces the field 'actor' from 'Upate.Exercise' to be undefined
starting from LF 1.5.

This breaking change is approved by Bernhard Elsner and Shaul Kfir.

It will affect only handcrafted LF archives, as no compiler from SDK
1.0.0 or latter made use of this field.

CHANGELOG_BEGIN
CHANGELOG_END
2020-10-07 14:42:10 +02:00
nickchapman-da
be79a93f99
fix comment (#7594)
changelog_begin
changelog_end
2020-10-07 11:18:49 +00:00
Remy
a146147df0
LF: drop unused functions in com.daml.lf.engine.Result (#7573)
CHANGELOG_BEGIN
CHANGELOG_END
2020-10-06 10:02:09 +02:00
nickchapman-da
2ef478cdb7
remove redundant (always None) param to compileExerciseByKey (#7564)
changelog_begin
changelog_end
2020-10-05 14:05:30 +00:00
Remy
2f325349ef
Speedy Compiler: factorize and clean code (fixe of #7493) (#7540)
* Revert "Revert "Speedy Compiler: factorize and clean code (#7493)""

This reverts commit d99f35b3cd.

* Speedy: Reintroduce usage of muti-binding let.

This PR fixes recursion issue with `closureConvert` and `freeVars`.
The explosion of muti-binding in single binding makes the function
`closureConvert` crash with stackoverflow in some cases.

We reintroduce the usage of multi-binding let in the first pass of the
compiler. The ANF transformation pass will replace them with nested
single binding let. ANF pass do not have issue with deep expression,
as it handle them with trampoline.

CHANGELOG_BEGIN
CHANGELOG_END
2020-10-01 16:58:57 +02:00
Martin Huschenbett
6a0b13ad73
DAML Engine: Remove token argument to SBU* builtins (#7542)
We currently pass the token to all builtins named `SBU*` aka the
update builtins. Since we pass the token immediately on all call sites
of these builtins, there's no point in passing the token at all.

This PR removes the token passing for the `SBU*` builtins.
Unfortunately, this does not improve execution performance. However,
since it simplifies the code, I still consider it worthwhile.

CHANGELOG_BEGIN
CHANGELOG_END
2020-10-01 13:02:00 +00:00
Remy
29117a1903
Revert "Speedy Compiler: factorize and clean code (#7493)" (#7538)
* Revert "Speedy Compiler: factorize and clean code (#7493)"

This reverts commit 41b96f6203.

* changelog

CHANGELOG_BEGIN
CHANGELOG_END
2020-10-01 08:21:50 +00:00
Remy
41b96f6203
Speedy Compiler: factorize and clean code (#7493)
We factorize scala code in the compiler:

Here are some example of changes:

*  factorize the common part of `compileChoice` and `compileChoiceByKey`
*  factorize the common part of `compileFetch` and `compileFetchByKey`

*  application patterns like
   ```
     SEApp(expr1, Array(expr2))
   ```
    are replaced by:
   ```
    app(expr1, expr2)`
   ```

*  let binding patterns like
   ```
        val x1 = expr1
        val x1Pos = nextPosition()
        SLet(x1, ...)
   ```
    are replaced by pattern
   ```
     let(expr){ x1Pos => ... }
   ```

*  function binding pattern like
   ```
        Abs(1){
          val x1Pos = nextPosition()
          x1
        }
   ```
    are replaced by
   ```
    function{ x1Pos => ... }
   ```

CHANGELOG_BEGIN
CHANGELOG_END
2020-10-01 08:52:25 +02:00
Remy
177a49f978
Speedy Profiler: add labels for new SDefinitionRef (#7492)
With this PR, the profiler nicely handles the new SDefinitionRef's added in #7472.

We add labels for:

    'create'
    'exerciseByKey'
    'fetch'
    'fetchByKey'
    'lookupByKey'

CHANGELOG_BEGIN
CHANGELOG_END
2020-09-30 10:24:27 +02:00
Remy
e6b24d1a5d
Speedy Compiler: compute variable indices more generally. (#7502)
CHANGELOG_BEGIN
CHANGELOG_END
2020-09-29 18:54:21 +02:00
Sofia Faro
e9cd92f061
Deprecate the "daml 1.2" version header. (#7513)
* changelog_begin

- [DAML] The "daml 1.2" version header is now deprecated.

changelog_end

* fix some line numbers

* fix some more locations
2020-09-29 13:14:59 +00:00
Moritz Kiefer
00b80b8ea3
Separate off-ledger ond on-ledger speedy (#7501)
* Separate off-ledger ond on-ledger speedy

changelog_begin
changelog_end

* Add OnLedgerBuiltin abstract class

changelog_begin
changelog_end

* fix typo

changelog_begin
changelog_end

* Fix borked rebase

changelog_begin
changelog_end

* Remove unscoped withOnLedger

changelog_begin
changelog_end
2020-09-29 10:05:45 +00:00
Remy
2e9979f2db
Speedy: Compile commands as speedy functions. (#7472)
This includes:

*   Create
*   ExceciseByKey
*   Fetch
*   FetchByKey
*   LookupByKey

This change allows us to reference the code used in a template definition from another package instead of having to inline it at the use-site

CHANGELOG_BEGIN
CHANGELOG_END
2020-09-28 21:08:04 +02:00
nickchapman-da
a1ac658aa2
Allow speedy execution without performing authorization checks. (#7491)
* Allow speedy execution without performing authorization checks. This is a temporary measure for canton.

This is controlled by a new Speedy machine member:

      /* Controls if authorization checks are performed during evaluation */
      val checkAuthorization: Boolean,

The default value for `Machine.checkAuthorization` is `true`, but can be set `false` when execution is called from `Engine.reinterpret`, by passing `checkAuthorization = false` to `reinterpret`.

changelog_begin
changelog_end

* CheckAuthorizationMode

* share duplicate code for computing machine contextActors and auth
2020-09-25 17:10:38 +00:00
Remy
ad587e2dfb
LF: implement hashing for GenMap (#7461)
This is used (in particular) for contract keys containning GenMaps.

CHANGELOG_BEGIN
CHANGELOG_END
2020-09-23 14:14:19 +02:00
Remy
c00b149ed8
LF Repl: cosmetic Cleanup (#7459)
+ Use directly compiler config instead of `devMode` and `profiling` flags
+ rename `fMap` into `chain`
+ minor changes

CHANGELOG_BEGIN
CHANGELOG_END
2020-09-22 16:42:20 +02:00
Remy
f5694ee2ea
LF: Kill ValueStruct (#7457)
Struct is not serializable and therefore should not appear as Value.

CHANGELOG_BEGIN
CHANGELOG_END
2020-09-22 13:37:59 +02:00
Remy
a899e5e4e6
Speedy: Check language version as part of Speedy compilation. (#7440)
Additionnally
+ move allowedLanguageVersion inside compiler config
+ add missing catch error insde
  ConcurrentCompiledPackages#addPackageInternal
+ implement EngineConfig method to easily produce a Compiler.Config

CHANGELOG_BEGIN
CHANGELOG_END
2020-09-22 12:43:48 +02:00
Remy
63be90c0fd
Engine: documents for Engine configuration (#7420)
CHANGELOG_BEGIN
CHANGELOG_END
2020-09-22 09:08:02 +02:00
Remy
7df0feeb58
Speedy: remove wrong comments introduced as part of #7438. (#7450)
CHANGELOG_BEGIN
CHANGELOG_END
2020-09-21 16:09:43 +02:00
Remy
42dcac38f0
[LF] Drop some tests for deprecated LF versions (#7449)
Since #5321, LF versions < 1.6 are deprecated. 
This PR drops some tests for those deprecated versions.

CHANGELOG_BEGIN
CHANGELOG_END
2020-09-21 15:36:47 +02:00
Remy
e1f8d9c781
DAML-LF: utility to compute duplicated keys in a transaction. (#7409)
The Engine does not verify key duplication when construction a
transaction, this task is currently let to the ledger implementation.
This PR provides an utility function to compute the duplicated keys
in a transaction.

CHANGELOG_BEGIN
CHANGELOG_END
2020-09-21 09:18:47 +02:00
nickchapman-da
4e32fde001
Cleanup following interleave execution and authorization (#7437)
* remove failedTransactions field from ScenarioLedger.RichTransaction

changelog_begin
changelog_end

* remove Blinding.checkAuthorizationAndBlind; fixup callers to use Blinding.blind when blindningInfo is required

* rename/relocate: ScenarioLedger.CommitError.FailedAuthorizations --> SError.DamlEFailedAuthorization

* fix types to demonstate that at most one FailedAuthorization is detected/reported

* address small review comments
2020-09-18 19:05:19 +01:00
Remy
76ef4c861a
Speedy: group compiler parameters into a Config case class. (#7438)
* Speedy: group compiler parameters into a Config case class.

Speedy compiler is parametrized by several option flags.  Those flags
are passed through different calls (in particular in the instance of
`CompiledPackages`.

This PR group all this configuration parameters into a case class to
pass the option in a cleaner way.

CHANGELOG_BEGIN
CHANGELOG_END
2020-09-18 19:32:26 +02:00
Remy
71c19901fd
Ledger-API: Validate Dar before sending it to the ledger. (#7430)
This PR implements a part of the proposal from #7093.

Here packages are validated in the participant node before to be sent to the ledger.

CHANGELOG_BEGIN

- [Ledger-API] participant node validate Dar before uploading to the ledger.
   This may increase upload time significantly.

CHANGELOG_END
2020-09-18 17:26:22 +02:00
Remy
6aa6f9245b
Engine: make package validation option. (#7436)
This is part of #7399.

This enable skipping packages validation in the engine when they are
comming from a trusted source.

CHANGELOG_BEGIN
CHANGELOG_END
2020-09-18 12:58:59 +02:00
nickchapman-da
96d704b25b
Perform authorization checks during execution and not as a separate post-execution phase. (#7400)
changelog_begin
changelog_end

Adapt test for small error message change. An improvement! Previously an internal message was shown. Make test flexible enough to pass for old & new message.

Adapt expected output file. Only change is the contract-ids for active-contracts when the test ends.

fix small test bugs in testcase where authorization is wrong

temp disabled 3 tests; needs investigation; see TODO markers

temp adapt 1 test for change in error message

temp disable 1 test. needs invesigation

undo accidentally commited change to .bazelrc

add copyright header to new file

remove testcase (badActorCheck2) which is no longer expected behaviour, when authorization occurs during execution

address comments: be mre private & other tiny changes

appease scala formatter

improve expected error message in KeyNotVisibleStakeholders testcase

fix authorization issues and re-enable the 3 failing tests in EngineTest which now pass

fix auth issue and re-enable ledger-test-tool test: WronglyTypedContractIdIT

fix compatibility

re-enable test in KVUtilsTransactionSpec.scala
2020-09-17 17:50:04 +01:00
Remy
23d8451b98
LF: Drop legacy engine configuration for Sandbox Classic. (#7415)
The migration script from #7344 ensures that there are no more values
in Sandbox Classic DB encoded with Value version < 6.  Hence, we do
not need anymore a special EngineConfig to maintain backward
compatibility of Sandbox classic DB.

CHANGELOG_BEGIN
CHANGELOG_END
2020-09-16 17:14:53 +02:00
Remy
ddbb334ecb
Engine: add submitter arg to Engine#validate (#7405)
CHANGELOG_BEGIN
CHANGELOG_END
2020-09-16 13:47:21 +02:00
Remy
23d5552807
DAML-script: drop ScriptLedgerClient.Command (#7378)
in favor of standard lf.command.Command.

This PR tries to decuple a bit more DAML-script to speedy.

CHANGELOG_BEGIN
CHANGELOG_END
2020-09-14 14:46:49 +02:00
Remy
f67af49044
LF: typos in contract ID spec. (#7364)
CHANGELOG_BEGIN
CHANGELOG_END
2020-09-10 10:58:27 +02:00
Martin Huschenbett
cf3d5ad819
Contract ID spec: Fix typos (#7363)
CHANGELOG_BEGIN
CHANGELOG_END
2020-09-09 15:38:36 +00:00
Remy
56fd866180
LF: minor cleanup in SortedLookupList (#7345)
CHANGELOG_BEGIN
CHANGELOG_END
2020-09-09 14:57:07 +02:00
Remy
0c1d11d5ac
Speedy: dop useless Hasher for value (#7346)
This is a left over of #4893, where we changeed underlying of
SGenMap from InsertOrdMap to TreeMap.

CHANGELOG_BEGIN
CHANGELOG_END
2020-09-09 12:30:48 +02:00
Remy
73121fef0b
LF: minor typo in spec (#7352)
CHANGELOG_BEGIN
CHANGELOG_END
2020-09-09 11:39:32 +02:00
Remy
95f17d5239
Speedy: share implementation of GenMap and TextMap. (#7334)
CHANGELOG_BEGIN
CHANGELOG_END
2020-09-09 09:12:02 +02:00
Remy
b385f9b7d4
Speedy: cleanup test for builtins (#7326)
CHANGELOG_BEGIN
CHANGELOG_END
2020-09-08 16:14:37 +02:00
Remy
598f8d585d
LF: shortcup failure in TypeOrdering (#7204)
CHANGELOG_BEGIN
CHANGELOG_END
2020-09-08 16:14:12 +02:00
Remy
f0372979be
Speedy: shortcup failure in SValue ordering. (#7329)
* LF: shortcup failure in SValue ordering.

Before this PR comparison of lists, maps, ans structural record had a
always linear complexity.

CHANGELOG_BEGIN
CHANGELOG_END
2020-09-08 16:13:40 +02:00
Remy
8aa34c701c
Speedy: use standard scala equality to check SBuiltinTests result. (#7333)
This reverts changed made in #3416, where the standard scala was
replace by ad-hoc Speedy equality for SValue. As Speedy equality
become more permisive (e.g. it does not check for type constructor of
records, variants, and enumrations or constructor of variants or
enumerations) this is safer to use standard scala eqality for case
class.

CHANGELOG_BEGIN
CHANGELOG_END
2020-09-07 16:33:01 +02:00
Martin Huschenbett
d7f0bc1c7b
DAML-LF spec: Fix two minor issues around structs (#7323)
* DAML-LF spec: Fix two minor issues around structs

We make it explicit that all field names in a structural record need to
be distince. We also fix a small typo in the indices for the
`ExpStructCon` typing rule.

CHANGELOG_BEGIN
CHANGELOG_END

* Address comments regarding distinctness

CHANGELOG_BEGIN
CHANGELOG_END
2020-09-07 15:13:13 +02:00
Remy
8968889a31
LF: drop buggy/useless check in SBCheckPrecond (#7331)
CHANGELOG_BEGIN
CHANGELOG_END
2020-09-07 12:31:27 +02:00
Remy
fbeae8ae5e
LF: Use the new Struct data structure for SStruct (#7319)
This PR uses the new data structure introduced in #7220.

Additionally this fixes `svalue.Equality` and
`svalue.Ordering` which were considering <a: x, b: y>
different from <b:y, a:x>.

CHANGELOG_BEGIN
CHANGELOG_END
2020-09-04 22:04:07 +02:00
Remy
78e770bf72
LF: Use the new Struct data structure for ValueStruct (#7241)
This PR uses the new data structure introduced in #7220.
Additionnally this fix `Value Equal instance` which was considering
<a: x, b: y> different from <b:y, a:x>.

CHANGELOG_BEGIN
CHANGELOG_END
2020-09-04 18:32:39 +02:00
Remy
ee309d1e35
LF: extend tests for comparison builtins (#7314)
CHANGELOG_BEGIN
CHANGELOG_END
2020-09-04 17:13:29 +02:00
Remy
724466f77c
Speedy compile: cleanup (#7321)
This PR perform the following changes:
 - reduce function size by spliting them out,
 - rename "translate" function prefix to "compile",
 - replace 'private' by 'private[this]',
 - add 'inline' annotation to function used only once.

CHANGELOG_BEGIN
CHANGELOG_END
2020-09-04 11:38:39 +02:00
Remy
d08de60d9c
LF: prevent duplicate fields in Struct (#7299)
CHANGELOG_BEGIN
CHANGELOG_END
2020-09-03 16:07:38 +02:00
Moritz Kiefer
4460cb5e08
Fix trace statement handling in DAML Script service (#7292)
* Fix trace statement handling in DAML Script service

This PR makes sure that we get both trace statements coming from the
ledger client as well as from the ledger server. In the script service
those are two different Speedy machines so we need to interleave
them. This is a bit messy so let me explain the steps (apologies for
not splitting it up but I think it’s easier to understand the
motivation when it is a single PR):

1. Abstract over the tracelog interface. The ringbuffer doesn’t makes
   sense for our purposes and is annoying to clear.

2. Pass in the respective fields of `Machine` to `Conversions` instead
   of the whole machine. This is both a simpler design (passing around
   mutable objects scares me) and it allows us to assemble the fields
   from different machines.

3. Initialize the ledger machine with a simple ArrayBuffer tracelog.

4. After `submit` and `submitMustFail` copy the tracelog from the
   ledger to the client.

fixes #7280

changelog_begin
changelog_end

* Address review feedback

changelog_begin
changelog_end
2020-09-01 17:15:48 +00:00
Moritz Kiefer
09a1b445df
Only include stakeholder contracts in result of query (#7291)
* Only include stakeholder contracts in result of query

This fixes a bug in the script service. We need to filter out divulged
contracts since this should behave exactly like the ACS endpoint on
the ledger API.

changelog_begin
changelog_end

* Update daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/scenario/ScenarioLedger.scala

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

* Update daml-script/runner/src/main/scala/com/digitalasset/daml/lf/engine/script/LedgerInteraction.scala

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

* fmt

changelog_begin
changelog_end

Co-authored-by: Remy <remy.haemmerle@daml.com>
2020-09-01 10:34:11 +00:00
nickchapman-da
4e80ee62e6
Refactor EnrichedTransaction (#7262)
* Refactor EnrichedTransaction

This PR prepares for work to interleave _authorization_ with _execution_, which has been an open issue for a long time: #132.

- Split computation of `BlindingInfo` and `FailedAuthorizations` into separate modules.

- Fixup callers: `Blinding.scala` and `ScenarioLedger.scala`, to do:

```
    val failedAuthorizations =
      AuthorizingTransaction.checkAuthFailures(authorization, tx)

    val blindingInfo =
      BlindingTransaction.calculateBlindingInfo(tx)
```

- Simplify code to remove `DontAuthorize` and `Authorization` types, which were only needed to restrict the combined _enrichment_ code from doing the authorization check when `blind`ing only is required. Now  `Blinding.blind` calls just `calculateBlindingInfo`.

* address comments from Stefano
2020-08-28 15:16:37 +00:00
Remy
ada8ba033b
LF: ad-hoc data struct to store LF Struct like data (#7220)
A `Struct[+X]` is a list of pair `(FieldName, X)` ordered by first
component.

We use this data-structure to represent TStruct LF type.

It will be used in upcomming PRs to sorted fields in Struct values.

CHANGELOG_BEGIN
CHANGELOG_END
2020-08-26 12:18:18 +02:00
Remy
4e265f0c1c
Speedy: Make the fields 'fields' from SStruct immutable. (#7227)
Change the type of SStruct.fields from Array to ImmArray.

CHANGELOG_BEGIN
CHANGELOG_END
2020-08-25 18:03:33 +02:00
Remy
89770cf1c1
Speedy: make the field names from SRecord immutable. (#7225)
CHANGELOG_BEGIN
CHANGELOG_END
2020-08-25 17:02:27 +02:00
Sofia Faro
3429ec24cc
Normalize struct field order in the LF spec. (#7228)
* Normalize struct field order in the LF spec.

This commit changes the LF spec to ensure that struct field order is ignored whenever reasonable.

* Rename "type synonym resolution" to "type normalization", and change the rule for structs to also normalize the order of fields.

* Make the struct type "well-formed" only if the struct fields are sorted by field name. (This matches the way "well-formed" is only used for normalized types. E.g. type synonyms are not considered "well-formed" by the spec. This nomenclature should possibly be fixed in a separate PR.)

* Change the struct con expression type rule accordingly.

* Change the definition of a struct value. A struct value is now a struct expression where all the field expressions are values, and all the field names are sorted.

* Change the evaluation rule for struct expressions to also sort the fields by field name in the process.

As far as I know, this spec matches the behavior of the LF engine. I also tried to make the treatment of struct field order in the types match the treatment of struct field order in expressions (i.e. normalized structs always have sorted fields, but non-normalized structs do not).

changelog_begin
changelog_end

* Apply suggestions from code review

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

* Update daml-lf/spec/daml-lf-1.rst

Co-authored-by: Remy <remy.haemmerle@daml.com>
2020-08-25 14:32:03 +00:00
Moritz Kiefer
3058af8286
Support HasCallStack constraints (#7217)
This is primarily intended to improve error reporting in DAML Script,
in particular, https://github.com/digital-asset/daml/issues/7192 which
is a blocker for replacing scenarios by DAML Script.

However, I think it is also a very reasonable feature in general.

changelog_begin
changelog_end
2020-08-25 08:54:21 +00:00
Remy
0e9616f784
LF: move the type ordering form interpreter to language package (#7203)
CHANGELOG_BEGIN
CHANGELOG_END
2020-08-24 07:18:41 +00:00
Remy
7f60560593
LF: make QualifiedName and Identifier Ordered (#7199)
CHANGELOG_BEGIN
CHANGELOG_END
2020-08-21 17:39:51 +02:00
Remy
6371f51930
PartialTransaction: replace nested Eithers by a custom ADT (#7191)
CHANGELOG_BEGIN
CHANGELOG_END
2020-08-21 10:16:36 +02:00
Remy
ba74146c10
Speedy: shortcup failure in recursive data structure equality (#7083)
CHANGELOG_BEGIN
CHANGELOG_END
2020-08-20 16:15:11 +02:00
Remy
17abe2f4cd
DAML for PostgreSQL: prevent dev version of DAML-LF (#7176)
Add a hidden flag to enable dev mode for testing purpose only.

CHANGELOG_BEGIN
CHANGELOG_END
2020-08-20 12:15:38 +02:00
Moritz Kiefer
255832cefc
Fix failed contract lookups in scenario runner (#7190)
lookupContract catches the exception which results in us continuing
and eventually running into a null-pointer exception.

This is another reason why we should enable the NonUnitStatements wart
but I’ll leave that for a separate PR (last I tried the scenario
service resulted in a ton of false positives).

fixes #7185

changelog_begin
changelog_end
2020-08-20 09:49:03 +02:00
Remy
cc6e8fa901
Engine: submit fail nicely when transaction output cannot be serialized (#7189)
CHANGELOG_BEGIN
CHANGELOG_END
2020-08-20 09:20:50 +02:00
Remy
e54c182032
Engine: move check of valide packages inside MutableCompiledPackages (#7186)
CHANGELOG_BEGIN
CHANGELOG_END
2020-08-19 19:37:53 +02:00
Remy
1b33d3742a
Revert "Sandbox: add a development mode (#7127)" (#7168)
This reverts commit 87a0ee9383.

CHANGELOG_BEGIN

WARNING remove the changelog entry from 87a0ee93 and starting by :
 "[Sandbox] By default Sandbox rejects the development versions of ..."

CHANGELOG_END
2020-08-18 19:17:56 +02:00
Martin Huschenbett
37d74287f1
DAML Engine: Use while loop instead of for loops (#7126)
This PR replaces a few `for (... to/until ...)` loops with `while`
loops which explicitly maintain their counter. In my benchmarks, this
has lead to a 3% performance improvement. Since the affected functions
are the ones used for applying arguments to functions, similar
improvements should be observable regardless of the specific benchmark.

CHANGELOG_BEGIN
CHANGELOG_END
2020-08-17 12:29:33 +00:00
Moritz Kiefer
ab8b418b72
Add TO_TEXT_CONTRACT_ID primitive (#7137)
* Add TO_TEXT_CONTRACT_ID primitive

This is the first part of #7114.

This PR

* Adds the primitive to the protobuf.
* Handles decoding and encoding in Haskell and Scala.
* Handles typechecking in Haskell and Scala.
* Handles speedy compilation and interpretation in Scala.
* Updates the specification.

This PR does not yet change the standard library to make use of this
primitive.

changelog_begin
changelog_end

* Apply suggestions from code review

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

* Avoid extra allocation

changelog_begin
changelog_end

Co-authored-by: Remy <remy.haemmerle@daml.com>
2020-08-17 08:39:16 +00:00
Andreas Herrmann
2df09194d5
allocateParty and listKnownParties in script service (#7141)
* script service party management test-case

* script service: allocateParty and listKnownParties

Behave like sandbox on party hint. If a hint is given then allocate
exactly that party name and fail if it already exists. Otherwise
generate a fresh party name. For easier debugging the fresh name is
based on the display name.

changelog_begin
changelog_end

* Track parties that were not allocated explicitly

E.g. parties generated by `partyFromText`.

* Handle and test party already exists error

* fmt

Co-authored-by: Andreas Herrmann <andreas.herrmann@tweag.io>
2020-08-17 10:36:06 +02:00
Remy
629ba564ab
LF Engine: move profileDir and stackTraceMode to Engine Config. (#7122)
Originally those two options were set up by calling state mutating
method on a build engine.

In this PR, we move this two options to the recently introduced EngineConfig.

CHANGELOG_BEGIN
CHANGELOG_END
2020-08-14 16:23:09 +02:00
Remy
87a0ee9383
Sandbox: add a development mode (#7127)
CHANGELOG_BEGIN
 * [Sandbox] By default Sandbox rejects the development versions of
   DAML-LF and transaction format. One has to explicitly use the
   command line option `--dev-mode` to allows those versions.
CHANGELOG_END
2020-08-14 13:23:18 +02:00
Remy
66ae38da6c
LF: control of input value version in the engine (#6828)
CHANGELOG_BEGIN
CHANGELOG_END
2020-08-13 21:15:52 +02:00
Remy
a890618782
LF: Drop completely the support for LF 0 (#7128)
CHANGELOG_BEGIN
CHANGELOG_END
2020-08-13 19:59:07 +02:00
Remy
ec7c53ce6f
LF: control of language version in the engine (#6847)
This PR allows to control the language version accepted by the engine
following #5164.

CHANGELOG_BEGIN
CHANGELOG_END
2020-08-13 19:52:04 +02:00
Martin Huschenbett
c014de0a11
DAML Engine: Move a few methods from the Machine object into the class (#7123)
The methods moved take a single instance of the `Machine` class as an
argument, hence it makes no sense to have them in the companion object.

CHANGELOG_BEGIN
CHANGELOG_END
2020-08-13 15:16:01 +00:00
Remy
6d02e20764
Scenarios: simplify getScenarioLedger method. (#7125)
This PR simplifies the deprecated `getScenarioLedger` to take the
whole engine instead of `compiledPackages` (from the engine) and the
rest of the `outputTransactionVersions` (form the engine conffig).

This prepares for some changes for #5164, where more options for the
engine config will have to be used by the method. Also we will need to
be sure the `compiledPackages` following the option of the engine
config.

CHANGELOG_BEGIN
CHANGELOG_END
2020-08-13 16:41:46 +02:00
Martin Huschenbett
501b3fd1ed
DAML Engine: Use ANF to make foldl/foldr faster (#7102)
This PR addresses a TODO in the implementations of `foldl` and `foldr`.
The continuations for both primitives have to apply the step function to
the accumulcation and the current list item. So far, we've used the
`SEAppAtomicFun` AST node for this purpose.  However, since the step
function and both arguments have already been evaluated to values, we
can also use the `enterApplication` function that has recently been
introduced together with our use of ANF.

Benchmarks: Applying `foldr (+) 0` (or `foldl (+) 0`) to the
pre-computed (and pre-allocated) list `[1..1_000_000]` has taken ca.
117s before this change and now takes only ca. 83ms. This is a speedup
of ca. 1.4x.

CHANGELOG_BEGIN
CHANGELOG_END
2020-08-13 14:51:27 +02:00
nickchapman-da
0a881f74b1
Partial ANF transformation. (#6918)
changelog_begin
changelog_end
2020-08-12 10:39:22 +02:00
Remy
17926c5a8a
LF: move language version from modules to packages (#7064)
CHANGELOG_BEGIN
CHANGELOG_END
2020-08-10 11:26:58 +02:00
Stephen Compall
96624a7677
use -Ywarn-unused for all Scala code (#6907)
* add -Ywarn-unused to all scalac options

* remove some unused arguments

* remove some unused definitions

* remove some unused variable names

* suppress some unused variable names

* changeExtension doesn't use baseName

* no changelog

CHANGELOG_BEGIN
CHANGELOG_END

* work around no plugins in scenario interpreter perf tests

* remove many more unused things

* remove more unused things, restore some used things

* remove more unused things, restore a couple signature mistakes

* missed import

* unused argument

* remove more unused loggingContexts

* some unused code in triggers

* some unused code in sandbox and kvutils

* some unused code in repl-service and daml-script

* some unused code in bindings-rxjava tests

* some unused code in triggers runner

* more comments on silent usages

- suggested by @cocreature; thanks

* fix missing reference in TestCommands

* more unused in triggers

* more unused in sandbox

* more unused in daml-script

* more unused in ledger-client tests

* more unused in triggers

* more unused in kvutils

* more unused in daml-script

* more unused in sandbox

* remove unused in ledger-api-test-tool

* suppress final special case for codegen unused warnings

.../com/daml/sample/mymain/ContractIdNT.scala:24: warning: parameter value ev 0 in method ContractIdNT Value is never used
      implicit def `ContractIdNT Value`[a_a1dk](implicit `ev 0`: ` lfdomainapi`.Value[a_a1dk]): ` lfdomainapi`.Value[_root_.com.daml.sample.MyMain.ContractIdNT[a_a1dk]] = {
                                                         ^
.../com/daml/sample/mymain/ContractIdNT.scala:41: warning: parameter value eva_a1dk in method ContractIdNT LfEncodable is never used
      implicit def `ContractIdNT LfEncodable`[a_a1dk](implicit eva_a1dk: ` lfdomainapi`.encoding.LfEncodable[a_a1dk]): ` lfdomainapi`.encoding.LfEncodable[_root_.com.daml.sample.MyMain.ContractIdNT[a_a1dk]] = {
                                                               ^

* one more unused in daml-script

* special scaladoc rules may need silencer, too

* unused in compatibility/sandbox-migration

* more commas, a different way to `find`

- suggested by @remyhaemmerle-da; thanks
2020-08-07 13:16:09 -04:00
Remy
a39b7cc003
LF: check dependencies are not compiled to newer version. (#7050)
This PR prevents a module to depend on an older version of LF than the one is compile to.

CHANGELOG_BEGIN
CHANGELOG_END
2020-08-07 18:32:20 +02:00
nickchapman-da
52cb1d1b3a
Factor out executeMatchAlts from KMatch.execute. (#7046)
This is a pre-step for ANF, which will allow ANF expression forms to call `executeMatchAlts` directly, rather than always from the `KMatch` continuation.

changelog_begin
changelog_end
2020-08-07 10:18:59 +01:00
nickchapman-da
15bbd9a858
Run json-parser example using explore-dar. (#7045)
This is another small PR split out from the ANF work.

Improve explore-dar to allow dar file to be selected on the command line, and so allows the json-parser example to be run like this:

    bazel run daml-lf/interpreter/perf:explore-dar -- --base JsonParser pipeline --arg 10

As well as a speed test:

    bazel run daml-lf/interpreter/perf:speed-json-parser

This example is a nice quick smoke test to check speedy execution is not broken.

changelog_begin
changelog_end
2020-08-07 07:47:48 +02:00
Martin Huschenbett
e2ce916b17
DAML Engine: Speed up foldr (#6997)
* DAML Engine: Speed up foldr

This PR replaces Speedy's current implementation of `foldr`, which
basically does nothing more than replace the builtin `foldr` with an
expression for its standard implementation in a functional language,
with a more loop-like implementation that takes advantage of the
structure of Speedy. There's additional complexity for the case when
the step function expects only one more argument before it performs
some computation. The exact issue and the solution are explained in a
comment in the code.

I've benchmarked the application of `foldr (+) 0` to the pre-computed
list `[1..100_000]`. With the old implementation of `foldl` this took
ca. 35ms, with the new implementation ca. 11ms. Further experiments
indicate that out of these times ca. 5ms are spent applying the
arguments to `(+)` and performing the addition. Thus, the time actually
spent in `foldr` amounts to 30ms and 6ms, respectively. This means
the new implementation of `foldr` is ca. 5x faster than the old
implementation when the step function takes at least two arguments.

For the case of a step function which expects only one argument before
performing computation, I've benchmarked the application of
`foldr (\_ -> identity) 0` to the pre-computed list `[1..100_00]`. The
measured times have dropped from ca. 42ms to ca. 19ms. Further
experiments that the time spent in `foldr` itself has dropped from
ca. 32ms to 9ms.

CHANGELOG_BEGIN
- [DAML Engine] The performance of `foldr` has been improved by more
  than 4x.
CHANGELOG_END

CHANGELOG_BEGIN
CHANGELOG_END

* Add explanation on how extra coomplexity could have been avoided

CHANGELOG_BEGIN
CHANGELOG_END
2020-08-07 07:31:42 +02:00
nickchapman-da
eba8f1b0bd
Regard SEBuiltinRecursiveDefinition as an atomic speedy expression. (#7009)
And rename `evaluate` -> `lookupValue` for clarify. (Old suggestion from Martin)

changelog_begin
changelog_end
2020-08-06 09:52:40 +01:00
Moritz Kiefer
ad9d8c24ed
Extend the scenario service with DAML Script support (#6929)
* Extend the scenario service with DAML Script support

This adds most of the infrastructure for running DAML Script via the
scenario service which means it runs as part of DAML Studio and `daml
test`. This is hidden behind a feature flag so we can land this and
parallelize the remaining tasks. The main things that are missing are:

1. `createAndExerciseCmd` and `exerciseByKeyCmd`.
2. Party management needs some work and listing parties is
unsupported.
3. Time management
4. Potentially some better error handling (we need to go through
   SResult and SError and see what is relevant for us).

Overall, it is already in a very usable state and there is a decent
range of tests.

closes #3688

changelog_begin
changelog_end

* Update compiler/damlc/daml-ide-core/src/Development/IDE/Core/Rules/Daml.hs

Co-authored-by: Andreas Herrmann <42969706+aherrmann-da@users.noreply.github.com>

* Fix name for actor system and pool

changelog_begin
changelog_end

Co-authored-by: Andreas Herrmann <42969706+aherrmann-da@users.noreply.github.com>
2020-08-05 12:56:09 +02:00
nickchapman-da
2ee3ae35d5
Stratify Speedy Builtins as Pure/Effectful. (#6996)
* Stratify Speedy builtins into pure/effectful.

This is a preparatory change for the ANF translation, which can treat pure
builtins more efficiently.

- Parent: `SBuiltin`, (which are effectful).
- Child: `SBuiltinPure` (which are pure).

Effectful builtin functions may raise `SpeedyHungry` exceptions or change
machine state.  Pure builtins can be treated specially because their evaluation
is immediate.

The interface to effectful builtins remains:

  def execute(args: util.ArrayList[SValue], machine: Machine): Unit

For pure builtins the interface is:

  def executePure(args: util.ArrayList[SValue]): SValue

changelog_begin
changelog_end

* insert trailing comma and newline in 17x execute method args-list

* fix spello
2020-08-05 09:03:49 +00:00
Martin Huschenbett
c3d62b80e8
DAML Engine: Speed up foldl (#6973)
This PR replaces Speedy's current implementation of `foldl`, which
basically does nothing more than replace the builtine`foldl` with an
expression for its standard implementation in a functional language,
with a more loop-like implementation that takes advantage of the
structure of Speedy.

I've benchmarked the application of `foldl (+) 0` to the pre-computed
list `[1..100_000]`. With the old implementation of `foldl` this took
ca. 31ms, with the new implementation ca. 11ms. Further experiments
indicate that out of these times ca. 5ms are spent applying the
arguments to `(+)` and performing the addition. Thus, the time actually
spent in `foldl` amounts to 6ms and 26ms, respectively. This means
the new implementation of `foldl` is ca. 4.3x faster than the old
implementation.

CHANGELOG_BEGIN
- [DAML Engine] The performance of `foldl` has been improved by more
  than 4x.
CHANGELOG_END
2020-08-04 09:57:46 +02:00
Martin Huschenbett
2bfb1b12fc
DAML Engine: Use reflection for state classification (#6974)
I've already grown very tired of almost always having to touch the
`Classify` class whenever I change anything about Speedy. Let's put an
end to this by using reflection instead of explicitly listing all
different AST nodes and continuation types.

The `PrettyLightweight` class has similar problems that can be fixed
using the same idea.

This change might slightly change this output but since this is an
experimentation tool, I deem this acceptable.

CHANGELOG_BEGIN
CHANGELOG_END
2020-08-04 08:33:47 +02:00
Remy
ae7e92a6c4
LF: adapt TransactionBuilder to the new version inference (#6854)
This PR changes TransactionBuilder according the new version inference
algorithm implemented in #6756

CHANGELOG_BEGIN
CHANGELOG_END
2020-08-03 19:05:30 +02:00
Remy
5cae5b43ce
DAML-LF: fix minor typos in LF spec (#6963)
CHANGELOG_BEGIN
CHANGELOG_END
2020-08-03 15:07:57 +02:00
Sofia Faro
262220a501
Add 'unknown contract' cases in LF spec. (#6955)
* Add 'unknown contract' cases in LF spec.

changelog_begin
changelog_end

* Fix duplicate Err t

* remove indices
2020-08-03 12:54:57 +01:00
Martin Huschenbett
de3f593399
FrontStack: Ensure that claimed invariant is maintained (#6960)
* FrontStack: Ensure that claimed invariant is maintained

The documentation of `FrontStack` claims that the head of the
`FQPrepend` is never empty but there's a way to violate this claimed
invariant.

This PR makes sure the invariant is maintained and then uses the
invariant to remove a redundant `else`-branch.

CHANGELOG_BEGIN
CHANGELOG_END

* Remove initials from NOTE

CHANGELOG_BEGIN
CHANGELOG_END
2020-08-03 11:39:04 +00:00
Martin Huschenbett
d95b867a0f
DAML Engine: Speed up updates of multiple fields in a record (#6937)
* DAML Engine: Speed up updates of multiple fields in a record

Currently, updating multiple fields of a single record is not very
efficient. If you update, say, `n` fields, as in
```haskell
  r with f_1 = ...; ...; f_n = ...
```
`n-1` intermediate records are created and almost immediately
discarded. Each creation of an intermediate record involves shallowly
cloning an array of size `m`, where `m` is the number of fields of the
record type. This does not only cost computation time but also a lot of
avoidable memory allocations. Overall, the cost of such an update is
`O(m*n)` in terms of time and memory.

This PR changes the DAML-LF interpreter such that multiple updates of
the same record are batched together. This avoids the creating of any
intermediate records but only creates the final record resulting from
the updates. This reduces the time complexity to `O(m+n)` and the
memory complexity to `O(m)`.

The code path for updating a single record field remains unchanged
(for now) and hence won't suffer from the additional complexity that
is required for the batching described above.

I've benchmarked this change by creating a single record with `m`
fields and updating all `m` fields in one single update expression,
for `m = 10` and `m = 20`. In both cases, the benchmarks showed a
speedup of ca. 2.5x.

This is part of #5766.

CHANGELOG_BEGIN
- [DAML Engine] Record update expressions of the form
  `R with f_1 = E_1; ...; f_n = E_n` are now run as batch updates
  in order to improve runtime performance and avoid unneccesary
  memory allocations.
CHANGELOG_END

* Apply suggestions from code review

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

Co-authored-by: Remy <remy.haemmerle@daml.com>
2020-08-03 09:00:24 +00:00
Moritz Kiefer
83031f3edf
Mark contract lookups as private[lf] (#6938)
DAML Script is in lf so that is good enough and nothing else should
access this.

changelog_begin
changelog_end
2020-07-30 17:28:23 +00:00
Moritz Kiefer
13add95a5e
Expose lookupContract and lookupKey methods from ScenarioRunner (#6931)
This is a spinoff from IDE support for DAML Script #6929. There I need
cannot quite use `run` from ScenarioRunner since I need to handle
results differently but I don’t want to replicate all the visibility
and authorization logic from `lookupContract` and `lookupKey`.

changelog_begin
changelog_end
2020-07-30 18:15:48 +02:00
Andreas Herrmann
8e706a9bde
Remove vendored pkg_tar (#6934)
* Use Bazel builtin pkg_tar rule

* Use @rules_pkg//:pkg.bzl%pkg_tar

The pkg_tar rule builtin to Bazel has been deprecated.
See https://docs.bazel.build/versions/master/be/pkg.html

Co-authored-by: Andreas Herrmann <andreas.herrmann@tweag.io>
2020-07-30 15:53:16 +00:00
Martin Huschenbett
3c1e8c7748
daml-lf/parser: Add the ability to parse location annotations (#6932)
* daml-lf/parser: Add the ability to parse location annotations

Currently, the DAML-LF parser we use for testing in Scala land does not
understand location information and has in particular no way to produce
`ELocation` AST nodes. Having these nodes will be important in a test
for a feature I'm currently working on in order to demonstrate that my
Speedy AST transformation can actually look through location
information properly.

This PR adds a rule to the parser to allow for parsing location
information and producing `ELocation` nodes.

CHANGELOG_BEGIN
CHANGELOG_END

* Address Nick's feedback

CHANGELOG_BEGIN
CHANGELOG_END
2020-07-30 15:29:00 +00:00
Sofia Faro
0f06d63570
Evaluation order specification and tests for exercise and other updates. (#6867)
* Evaluation order for exercise & other updates.

This adds more DAML tests and error cases for, finishing off the update
interpretation for now. I believe this is roughly the limit of what we
can test directly in DAML, and the rest is up to DAML-LF testing.

For example, there's no way to test that the contract inactivity check
in EvUpdExercInactive happens before the evaluation of the controller
expression, since there is no way to generate an 'exercise' with actors
from DAML, as far as I could tell, and 'exercise_without_actor' always
evaluates the controller before passing it off to 'exercise'.

For the same reason, the EvUpdExercBadActor check seems impossible to
trigger from DAML itself. The closest is an authorization test that
happens during submit (which I added a test for, because it is kinda
relevant to evaluation order of scenarios, even though scenario
interpretation isn't really important to the spec).

So at the very least we should add LF tests for those two cases.

changelog_begin
changelog_end

* Apply Moritz\'s suggestions

* Add test with fetch of consumed contract
2020-07-29 09:59:46 +01:00
Stephen Compall
fd07a26510
check for scaladoc comments that are not actually used (#6802)
* add -Xlint:doc-detached

- reverts 1feae964e3 from #6798

* attach several scaladocs where they'll actually be included

* no changelog

* attach several more scaladocs where they'll actually be included

* no changelog

CHANGELOG_BEGIN
CHANGELOG_END
2020-07-28 20:32:30 +00:00
Remy
ce3c3c89a4
LF: redesign engine configuration (#6763)
This PR redesigns the engine Configuration as described in #5164. 

CHANGELOG_BEGIN
CHANGELOG_END
2020-07-22 12:17:07 +02:00
Sofia Faro
8d5d9090c3
Draft of new operational semantics. (#6598)
* Draft of new operational semantics.

* make errors deterministic, and be explicit about them

* Flesh out the op semantics for expressions and add tests.

* Nail down the semantics of create

* Apply suggestions from code review

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

* Add a reminder that u has to be a value

... in the update interpretation section.

changelog_begin
changelog_end

* add a test to track the ghc behavior on multi-lets

* add test for erasable type abstraction

* Add non-erasable type abstraction value test.

* move the ValExpTyAbsNat to 1.7-only value test

Co-authored-by: Remy <remy.haemmerle@daml.com>
2020-07-21 15:56:44 +00:00
Remy
5468e4d160
DAML-LF: Simplify inference of output transaction/value version. (#6756)
* LF: Simplify inference of output transaction/value version.

As part of #5164, we simplify the way transaction and value versions
are inferred for the engine output.

The versioning of a transaction tr is done as follow:

* Let tvMin be the minimal transaction version allowed by the DAML
  engine configuration
* Let tvMax be the maximal transaction version allowed by the DAML
  engine configuration
* Let n₁, ..., nₘ be the nodes of tr.
* Let pkgᵢ be the package of the template associated to the node nᵢ
* Let lvᵢ be the maximal language version that pkgᵢ uses (directly or
  through its dependencies)
* let tvᵢ be the maximal transaction version supported by all engines
  that support both lvᵢ and tvMin
* Let vvᵢ be the maximal value version supported by all engines that
  support tvᵢ.
* Let tv be the maximal transaction version between tv₁, ..., tvₘ.
* If tv is not greater than tvMax
  + then
    - Version the values of each node nᵢ according vvᵢ
    - Version tr according tv
  + fail otherwise

CHANGELOG_BEGIN
CHANGELOG_END
2020-07-21 17:07:11 +02:00
Stephen Compall
4355406259
add more scalac 2.12 warnings (#6798)
* set many extra scalac -Xlint options for all Scala projects

CHANGELOG_BEGIN
CHANGELOG_END

* move NoCopy to its own file

package.scala:18: warning: it is not recommended to define classes/objects inside of package objects.
If possible, define trait NoCopy in package data instead.
  trait NoCopy {
        ^

* move more traits, classes, and objects to proper packages

- note that `package` is itself a scoping construct, so if your reason
  is the apparent aesthetic of placing a bunch of things in one `package
  object`, that is easily remedied by deleting the `object` keyword

* fix some type-parameter-shadow warnings

- I'm generally in favor of sensible name-shadowing, following the
  "deliberately hide variables that should not be accessed here" school
  of thought.  But I think type name shadowing isn't quite as valuable
  and more likely to confuse than general variable shadowing, so have
  experimentally linted it out.

  Example warning:

EventsTableFlatEventsRangeQueries.scala:11: warning: type parameter
 Offset defined in trait EventsTableFlatEventsRangeQueries shadows class
 Offset defined in package v1. You may want to rename your type
 parameter, or possibly remove it.
private[events] sealed trait EventsTableFlatEventsRangeQueries[Offset] {
                                                               ^

* fix more package-object-classes warnings

* fix an inaccessible warning

ContractsService.scala:197: warning: method searchDb in class ContractsService references private class ContractsFetch.
Classes which cannot access ContractsFetch may be unable to override searchDb.
  def searchDb(dao: dbbackend.ContractDao, fetch: ContractsFetch)(
      ^

* enable -Xlint:infer-any

- continuing the saga of #6116, #6132

* enable -explaintypes for more detailed type errors

* missed header for NoCopy; probably should have left it in the package file

* misspelling in comment

* revert -Xlint:doc-detached

- there are a lot of these fixes, and they are noisy, so shifting to a
  separate PR
- thanks to @leo-da for pointing out
2020-07-21 08:18:01 -04:00
Remy
a629959c09
LF: Move GlobalKey and GlobalKeyWithMaintainers outside Node (#6795)
CHANGELOG_BEGIN
CHANGELOG_END
2020-07-21 09:08:36 +02:00
Remy
a70da3478c
LF: clean TransactionCoder (#6785)
CHANGELOG_BEGIN
CHANGELOG_END
2020-07-20 20:22:35 +02:00
Remy
fca9f3d90b
DAML-LF: unset the field NodeFecth#value_version in transaction.proto (#6784)
According transaction specification the field `value_version` "is
optional; if defined, it must be a version ofthe value
specification, and `template_id` shall be consumed according to
that version.  Otherwise, it is assumed to be version 1."

We take advantage that the encoding of identifier in value does not
change since version "1" to unset the field `value_version`, hence
using the default interpretation.

CHANGELOG_BEGIN
CHANGELOG_END
2020-07-20 17:50:59 +02:00
Remy
5f4dd39b5d
Engine: add maintainers to contract key call back (#6781)
CHANGELOG_BEGIN
[Engine] - Change the callback for contract key from `GlobalKey => Option[ContractId]` to  `GlobalKeyWithMaintainers => Option[ContractId]`
CHANGELOG_END
2020-07-20 17:42:06 +02:00
Stephen Compall
134dbf0f01
check NodeFetch value_version on decode (#6786)
- decoding the template ID is not valid if the value_version is unknown

CHANGELOG_BEGIN
CHANGELOG_END
2020-07-20 11:23:05 +02:00
Remy
c32355b9fd
DAML-LF: compute the newest version of LF used by a package (#6747)
We add a method to CompiledPackages that returns the latest language version that package uses directly or indirectly through is dependencies.

This will be used in the context of #5164

CHANGELOG_BEGIN
CHANGELOG_END
2020-07-17 09:40:21 +02:00
Remy
bdcfb6c114
DAML-LF: add templateId method to GenNode (#6752)
* DAML-LF: add templateId abstract method to GenNode

* changelog

CHANGELOG_BEGIN
CHANGELOG_END
2020-07-16 10:17:04 +02:00
Remy
15da222939
DAML-LF: move some type definitions out of Transaction object (#6739)
SubmittedTransaction and CommittedTransaction are moved from com.daml.lf.transaction.Transaction to
com.daml.lf.transaction

This helps intelliJ type inference.

CHANGELOG_BEGIN
CHANGELOG_END
2020-07-16 09:13:30 +02:00
Gary Verhaegen
8176fb0c8d
fix the the typo (#6723)
```
s/the the /the /
```

CHANGELOG_BEGIN
CHANGELOG_END
2020-07-14 16:55:33 +00:00
Brian Healey
520089778d
default Engine to StableConfig as that is what you want if you are not in dev mode (#6679)
CHANGELOG_BEGIN
Default new Engine constructor to Engine.StableConfig so it does not
need to be overridden unless you specifically want to run in
Engine.DevConfig mode
CHANGELOG_END

Signed-off-by: Brian Healey <brian.healey@digitalasset.com>
2020-07-14 09:46:55 -04:00
Remy
121a6a7d77
DAMLLF: clean up Transaction definitions (#6714)
* LF: move NodeId from value to transaction

* LF: remove some `private` keywords in Transaction

CHANGELOG_BEGIN
CHANGELOG_END
2020-07-14 14:42:58 +02:00
Stephen Compall
dba6ac77b3
include contract keys in the Scala codegen output plan when using --root (#6696)
* include DefTemplate's key types under the Ty type variable

* note that contract key types are included by folding over DefTemplates' Tys

- the topo sort from --root now correctly includes contract keys

* test that contract key dependencies get included in the Scala codegen plan

* no changelog

CHANGELOG_BEGIN
CHANGELOG_END
2020-07-10 15:26:51 -04:00
Remy
a3c35e9678
Engine: bug fix for transaction validation (#6664)
CHANGELOG_BEGIN
* [Engine] fix transaction validation bug
CHANGELOG_END
2020-07-09 13:43:22 +02:00
Moritz Kiefer
02c59d4f2a
Revert ANF changes and add a testcase for evaluation order (#6645)
* Revert ANF changes and add a testcase for evaluation order

After careful consideration, we decided that the change in evaluation
order that was accidentally introduced by the ANF changes should be
considered a breaking change or arguably even a bug and should not
land in 1.3.0.

Therefore, this PR reverts the following commits:

1. 353d0da6f7
2. a45b51042f
3. 04c7b2af7f
4. a624dd7242
5. b3aab72cee

Other PRs mostly had trivial merge conflicts that I resolved. The two
most interesting ones here are probably

1. https://github.com/digital-asset/daml/pull/6576 which was easy to
   resolve and the change to return SEValue instead of SExpr is still
   nice and useful even if we do not need the guarantees.
2. it https://github.com/digital-asset/daml/pull/6542 which required
   some changes since the constructors changed. If you want to review
   those changes in detail (they are pretty straightforward so not too
   important), it’s probably easiest to check out this PR and run
   ```
   git diff 2cd2a8f2a8
   daml-lf/interpreter/src/main/scala/com/digitalasset/daml/lf/speedy/Compiler.scala
   ```
   to see the diff to the parent commit of the first commit that
   introduced ANF.

changelog_begin
changelog_end
2020-07-08 12:40:12 +02:00
Remy
e09755ca08
Replay transaction (#6464)
CHANGELOG_BEGIN
CHANGELOG_END
2020-07-08 10:21:48 +02:00
fabiotudone-da
474e92c13c
Track min and max record time in CommitContext when pre-executing (#6591) 2020-07-08 09:53:44 +02:00
Stephen Compall
4cd419623a
replace traverseU and sequenceU with traverse and sequence (#6594)
* replace traverseU and sequenceU with traverse and sequence

- with -Ypartial-unification on, the extra Unapply typeclass lookup is
  unnecessary

* no changelog

CHANGELOG_BEGIN
CHANGELOG_END

* limit imports; we only need *> and void
2020-07-07 15:01:58 +00:00
nickchapman-da
a45b51042f
Improve the interface to execute (pure) builtins. (#6613)
So that the resulting value is returned from the `execute` function, instead of being assigned to the `returnValue` machine state.

Rename the parent class from `SBuiltinMaybeHungry` to `SBuiltinEffect`, and have this be the parent of a few more subclasses which cannot meat the _pure_ interface.

Declare method `executeEffect` of the parent class `SBuiltinEffect` which has the same type as the original `execute`.

changelog_begin
changelog_end
2020-07-07 08:39:43 +01:00
Gary Verhaegen
b3aab72cee
better let ANF transform (#6606)
Ask @nickchapman-da for details on what this transform does and why it's
better. I have no clue.

What I do understand is that current master has a stack-consuming
behaviour that just so happens to not reach the 1mb default stack size
on the tests we run, and that this presumably better version of a let
transform had been left out from the original ANF PR because it was
pushing the stack consumption over that 1mb limit.

Besides reintroducing the "better" let version, this PR applies an
almost full CPS transform to the set of mutually recursive functions
that grow the stack. Combined with the trampoline, this should mean the
ANF transform itself is done in (almost) constant stack space.

The one exception to that is the `flattenAlts` function, which has been
left as a plain imperative loop. This does mean that we consume stack
linearly with the nesting level of alts, so conceivably this could still
blow the stack. There is no fundamental reason that makes this hard, it
just seemed unnecessary for the stack consumption and potentially
damaging to performance (changing a native Java loop on an array to a
recursive list consumption).

To verify the stack-consuming behaviour on master, one can apply this
patch:

```patch
diff --git a/ledger/sandbox/BUILD.bazel b/ledger/sandbox/BUILD.bazel
index a717e66fb..4c953b3ea 100644
--- a/ledger/sandbox/BUILD.bazel
+++ b/ledger/sandbox/BUILD.bazel
@@ -124,6 +124,7 @@ da_scala_library(

 da_scala_binary(
     name = "sandbox-binary",
+    jvm_flags = ["-Xss256k"],
     main_class = "com.daml.platform.sandbox.SandboxMain",
     resources = ["src/main/resources/logback.xml"],
     visibility = ["//visibility:public"],
```

then run

```
bazel test -t- //ledger/sandbox:conformance-test-contract-id-seeding-memory
```

The same process can be repeated on this branch to verify that, at
least, this now runs under 256kb of stack for all our tests. I don't
know of a good way to get a stronger guarantee on stack allocations.

While my primary motivation here is correctness (and termination, I
guess), this does seem to yield a modest performance improvement. On a
test machine, I got the following results as confidence intervals:

* `master` (b4915a4bd7): 54.00, 54.56
* this branch: 52.54, 53.11

I've only ran the benchmark once on each and don't have enough
experience with it to know how reliable those numbers are. I'll try to
run some more.

CHANGELOG_BEGIN
CHANGELOG_END
2020-07-06 15:11:05 +02:00
Remy
dbd0215dd0
DAML-LF: cleanup TransactionBuilder (#6610)
small clean up in the testing library TransactionBuilder, bsaically add a Submitted and a Committed version for empty transaction constant and build method.

plus a bit of cleaning in tests using TransactionBuilder


CHANGELOG_BEGIN
CHANGELOG_END
2020-07-06 11:25:36 +02:00
Martin Huschenbett
873e0163cd
Drop the global from globalImplicitDisclosure and globalDivulgence (#6588)
Since we have only absolute contract ids, there is no more distinction
between local and global disclosure/divulgence. Let's please remove the
`global` prefix since it causes confusion (at least for me it did).

CHANGELOG_BEGIN
CHANGELOG_END
2020-07-03 08:43:31 +02:00
nickchapman-da
a624dd7242
Improve handling of over-application to allow much dead code to be eliminated. (#6586)
The dead code was hanging on by a slender thread. This change cuts that thread.

For over-apps, we now push a new continuation type KOverApp, instead of KArg.
KOverApp contains args of type SExprAtomic, instead of SExpr, and so its
execute() method may use enterApplication, instead of executeApplication.

This allowing lots of code to be removed:
- the continuation types: KArg, KFun, KBuiltin and KPap.
- defs: evaluateArguments and executeApplication.

changelog_begin
changelog_end
2020-07-02 19:38:54 +00:00
Remy
1480168604
Speedy: make thing a bit more private (#6579)
CHANGELOG_BEGIN
CHANGELOG_END
2020-07-02 18:19:03 +02:00
Martin Huschenbett
6dc2c9c9b8
Only ship disclosure information once in scenario service (#6578)
Currently, the scenario service ships the disclosure information of a
transaction twice. One of the two copies is completely unused. This PR
simply deletes it. I hope this reduces confusion in the future.

CHANGELOG_BEGIN
CHANGELOG_END
2020-07-02 13:16:21 +00:00
Martin Huschenbett
3296f56519
Distinguish witnesses and divulgences in scenario table view (#6571)
* Distinguish witnesses and divulgences in scenario table view

Currently, we display a "D" (for "Disclosure/Divulgence") in the table
view of the scenario view when a party can see a contract because they
have learnt about it via disclosure.

This change further refines this visibily indicators for disclosure:
We display a "W" for "Witness" (i.e. the party has witnessed the
creation of the contract) and "D" for "Divulgence".

Help for the reviewer: In the scenario service server, witnessing is
called explicit disclosure whereas divulgence is called implicit
disclosure.

CHANGELOG_BEGIN
* [DAML Studio]
  When displaying scenario results in table view in DAML Studio, we now
  indicate _why_ a party knows about the existence of a contract:
  - `S` means the party is a signatory.
  - `O` means the party is an observer.
  - `W` means the party has witnessed the creation of the contract.
  - `D` means the party has learned about the contract via divulgence.
CHANGELOG_END

* Address @cocreature's feedback
2020-07-02 07:58:21 +00:00
nickchapman-da
04c7b2af7f
Unit tests for ANF transform (#6562)
* Unit tests for ANF transform

changelog_begin
changelog_end

* add testcase for issue 6535
2020-07-02 07:45:05 +00:00
Stephen Compall
86148c398b
make @silent annotations narrower (#6570)
* check that all @silent annotations are used

CHANGELOG_BEGIN
CHANGELOG_END

* make all @silent annotations very specific about what they're silencing
2020-07-01 20:53:22 +00:00
Remy
817465defa
LF-Repl: log loading/compilation/validation time (#6549)
CHANGELOG_BEGIN
CHANGELOG_END
2020-07-01 18:28:43 +02:00
Gary Verhaegen
72851d83e9
refactor speedy.Compiler.freeVars to be functional (#6542)
I was trying to track down what looks like a new source of flakiness in
the ANF work (#6440), which manifested in a stack overflow on the
recursion of the `go` function in speedy.Compiler. I spent a bit of time
refactoring this to be functional in order to then trampoline it, only
to realize afterwards that I had worked on `freeVars/go` whereas the one
blowing up the stack was `validate/go`.

Obviously, it did nothing to reduce the rate of flakiness on the stack
overflow issue I was trying to address, as it's a separate function.

So there isn't really a good reason for this change, except I had done
it and I do believe the code looks marginally nicer, so might as well
submit it.

CHANGELOG_BEGIN
CHANGELOG_END
2020-07-01 07:26:10 +00:00
nickchapman-da
353d0da6f7
Speedy ANF (#6440)
* ANF transformation in Speedy.

The idea behind this PR is to transform speedy expressions into a simpler form where all non-atomic sub-expressions are made explicit by the introduction of let-forms. In particular, for the function-application form. These simpler forms allow the execution engine to take advantage of the atomic assumption, and often removes many additional execution steps. In particular the pushing of continuations to allow execution to continue after a compound expression has been reduced to a value.

changelog_begin
changelog_end

* improve comment

* inline functions relocateA/L

* remove comment about scalafmt

* remove commented out alterative def for transformLet1

* improve code by adding incr methods to DepthA/E

* remove (n == 0) special case in trackBindings

* clarify comment further

* improve validate/go to not consume stack for deeply right-nested let-expressions

* address comments from Remy: be private; use final case case; etc

* rename to unsafeCompilationPipeline

* add back some trailing commas

* remove commented-out debug line

* improve comment

* remove dev/debug code in compilationPipeline

* remove commented out code in SEAppGeneral.execute

* undo unrelated code improvement in SValue.scala

* fix compile. object Anf cannot be private
2020-06-30 20:52:44 +00:00
Miklos
ccfb0ac94e
Make interpretation cost available for LedgerWriter/WriteService (#6515)
* Measure time of interpretation and store it in CommandExecutionResult.

* Added parameters for passing in interpretation time for WriteService and LedgerWriter.

* Code tidying.

* Added CommitMetadata parameter to LedgerWriter.

* Thread through interpretation time. Aggregate interpretation times for a batch.

* Take max of interpretation times.

* Calculate interpretation time in nanos.

* Moved CommitMetadata into separate file.
CHANGELOG_BEGIN
CHANGELOG_END

* Apply suggestions from code review

Co-authored-by: Samir Talwar <samir.talwar@digitalasset.com>

* Delegate deprecated methods to method with new signature.

* Code tidying.

* Suppress deprecation warnings.

* Made interpretation cost optional in CommitMetadata.

* Test that we populate interpretation time.

* Code tidying.

* Apply suggestions from code review

Co-authored-by: Samir Talwar <samir.talwar@digitalasset.com>

* Code tidying.

* Some more tests. Do not return interpretation cost for a batch if it only contains non-transaction submissions.

* Reformatted.

* Reformatted.

* Named arbitrary interpretation cost.

* Reverted changes for BatchingLedgerWriter.

* Always drop commit metadata for batches and don't report interpretation cost.

* More specific expectations.

* Include authorization check and blinding in interpretation time.

Co-authored-by: Samir Talwar <samir.talwar@digitalasset.com>
2020-06-30 16:45:12 +00:00
Martin Huschenbett
659e77172f
Support --profile-dir and --stack-traces in sandbox next (#6531)
So far, these two flags only worked in sandbox classic because I wasn't
aware the code path consuming the options is not shared between both
implementation. Now, sandbox next is on par with sandbox classic.

CHANGELOG_BEGIN
CHANGELOG_END
2020-06-30 09:10:39 +02:00