Commit Graph

629 Commits

Author SHA1 Message Date
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