Commit Graph

1224 Commits

Author SHA1 Message Date
nickchapman-da
0867605e1a
Don't loose signatures in template let binding (#8136)
* update ghc-lib patch

* update stack-snapshot.yaml

changelog_begin
changelog_end

* bazel run @stackage-unpinned//:pin (on linux) and update stackage_snapshot.json

* testcase to check type signatures in template-lets are not ignored

* update to ghc-lib commit hash following merge

* update snapshot

* update snapshot after pin on windows

* update stack pin on linux

Co-authored-by: Nick Chapman <nchapman@digitalasset.com>
2020-12-03 15:08:02 +00:00
Sofia Faro
6b7f714c4d
Add exception type coherence check on Haskell side (#8137)
* Add exception type coherence check on Haskell side

changelog_begin
changelog_end

* update pretty instance

* follow martin suggestions
2020-12-02 14:36:22 +00:00
Sofia Faro
0df1a79ee3
Add DAML_EXCEPTIONS feature. (#8114)
* Add DAML_EXCEPTIONS feature.

Part of #8020. This extracts the DAML_EXCEPTIONS feature from #8023
since we need it for typechecking & LF conversion soon.

changelog_begin
changelog_end

* add full url

* add another url
2020-12-01 12:38:41 +00:00
Sofia Faro
6499ee9716
Add exceptions in DAML-LF AST (Haskell side) (#8112)
* Add exceptions in DAML-LF AST (Haskell side)

Updates the Haskell DAML-LF AST for exceptions, including
encode/decode, and updates all the functions that deal with the
AST directly.

changelog_begin
changelog_end

* Missed some TODOs in DecodeV1
2020-11-30 16:18:29 +00: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
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
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
Sofia Faro
4ac8d7cdf1
Make featureCppFlag field optional. (#8014)
Some features, in particular daml-lf encoding features, don't make any sense to have an associated CPP flag. I made the CPP flag optional and removed these unnecessary feature flags (based mostly on whether the flags were used in the standard library).

changelog_begin
changelog_end
2020-11-19 12:40:41 +00:00
Sofia Faro
ddf1378273
Use a NonEmpty list in makeLocalValBinds. (#8013)
Rewrite makeLocalValBinds to make the non-emptiness of the `binds`
argument explicit.

changelog_begin
changelog_end
2020-11-19 11:29:19 +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
Sofia Faro
6c7e37a330
Rewrite multiple binding lets sequentially. (#8006)
* Rewrite multiple binding lets sequentially.

This PR enforces a sequential evaluation and dependency on
multiple-binding lets, by rewriting,

  let x1 = e1
      x2 = e2
      ...
      xn = en
  in b

Into a chain of single-binding let expressions,

  let x1 = e1 in
    let x2 = e2 in
      ...
        let xn = en in
          b

And likewise, rewriting multi-binding let statements in a "do" block,

  do
      ...
      let x1 = e1
          x2 = e2
          ...
          xn = en
      ...

Into single-binding let statements,

  do
      ...
      let x1 = e1
      let x2 = e2
      ...
      let xn = en
      ...

This PR fixes #6788 and adds a bunch of tests.

This is a bugfix, but it may break existing code that relies on
out-of-order let bindings. The suggested fix is to simply reorder
the let bindings, placing them in order of their dependency.

CHANGELOG_BEGIN

- [DAML Compiler] The DAML compiler now enforces sequential
  ordering for ``let`` expressions with multiple bindings.
  This fixes a bug where ``let`` expressions would be evaluated
  in the wrong order.

CHANGELOG_END

* Update compiler/damlc/daml-preprocessor/src/DA/Daml/Preprocessor.hs

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

* adjust last binding behavior

Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
2020-11-18 19:32:08 +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
Moritz Kiefer
221dd5189f
Fix missing trace statements on failed submits (#7987)
changelog_begin

- [DAML Script] Fix a bug where trace statements from a failing
  transaction where not displayed in DAML Studio.

changelog_end
2020-11-17 17:09:24 +01:00
Robin Krom
5bfff4e9ba
sandbox: fail on already existing port-file. (#7929)
Fixes #7806. This aligns the port file behaviour of the sandbox with the
HTTP JSON API.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-17 11:08:37 +01:00
Sofia Faro
f7e096afc3
Make GHC recognise our ($) operator. (#7969)
* Make GHC recognise our ($) operator.

Fixes #4555 by moving ($) to GHC.Base and giving it a levity polymorphic
signature, as GHC expects. Added a regression test.

changelog_begin
changelog_end

* Update line numbers for debug...

* Fix `daml test-script` tests

changelog_begin
changelog_end

* fmt for the format gods

Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
2020-11-16 15:10:14 +00:00
Sofia Faro
f7ba14a4c4
Allow for lets before letrec transformation. (#7956)
* Allow for lets before letrec transformation.

Fixes #7953 by adjusting the letrec transformation to handle
(optional) nonrecursive lets before the letrec binding, and adds
a regression test.

changelog_begin
changelog_end

* typo

* apply martin suggestions
2020-11-12 23:25:39 +00:00
Martin Huschenbett
b926c6f061
damlc: Tiny improvement to DAML-LF type checker (#7948)
I suppose there's not much to say.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-11 15:41:15 +00:00
Sofia Faro
5d86abce55
Avoid generating ill-formed kinds in DAML compiler (#7944)
* Perform kind-checking in DAML compiler.

This PR avoids generating invalid kinds (i.e. kinds of the form k ->
Nat) during LF conversion, and adds a small "kind checking" step
whenever a type variable is introduced in the LF typechecker (since the
only way to get invalid kinds is to introduce them in a `forall`).

Right now there's no way to test that both the typechecker & the
conversion raise an error here, and in general, we try to always push
our LF type errors into GHC type errors or LF conversion errors. This
is something we can work on (adding actual LF typechecker tests). But
also, I verified manually that the type checker raises the error, in
the absence of the changes to LF conversion.

Ok, last point: The test case here has a weird location, but I tried and
couldn't figure out how to get a better location. I think this is a
general problem with the GHC Core representation?

changelog_begin
changelog_end

* Add more kind checks and restrict test version.

* fix test again
2020-11-11 14:43:20 +00:00
Sofia Faro
62cd53d402
Add a warning for GHC.Types.Symbol (#7921)
* Add a warning for GHC.Types.Symbol

CHANGELOG_BEGIN

- [DAML Compiler] Added a warning for references to
  the GHC.Types.Symbol kind since these cannot be
  preserved across data-dependencies.

CHANGELOG_END

* lint

* Address review comments

* fix LFNameCollisions test

* improve LFNameCollisions fix
2020-11-10 18:16:14 +00:00
Robin Krom
f78d375fe4
damlc: fix: relative output path relative to cwd (#7927)
* damlc: fix: relative output path relative to cwd

This fixes #7913. Build output path were considered relative to the
project root instead of the current working directory.

CHANGELOG_BEGIN
CHANGELOG_END

* adding a test
2020-11-10 15:05:06 +01:00
Robin Krom
a491002483
daml ledger: implementation of ledger commands via json api (#7885)
* daml ledger: implementation of ledger commands

Implementation of the remaining daml ledger commands via HTTP JSON
service endpoints instead of gRPC.

Fixes #4824 .

CHANGELOG_BEGIN
[daml assistant] `daml ledger` commands can now also be run against the JSON API instead of the gRPC API.
CHANGELOG_END
2020-11-09 16:24:45 +01:00
Martin Huschenbett
a83871b948
damlc: Check DAML-LF pattern matches for exhaustiveness (#7892)
* damlc: Check DAML-LF pattern matches for exhaustiveness

`damlc` has always produced exhaustive pattern matches in DAML-LF since
GHC adds a default branch with a call to `error` message as soon as a
pattern match is not exhaustive. It was a complete oversight on our
side that we did not enforce this properly in DAML-LF. Since `damlc`
has never produced non-exhaustive pattern matches, enforcing this now
and for all DAML-LF versions is only theoretically a breaking change,
namely if people hand-crafted DAML-LF, but not practically.

This check is as under-tested as the rest of our Haskell implementation
of the DAML-LF type checker. Well, all our other tests implicitly check
that the type checker does not give false errors. However, we have no
tests ensuring that the type checker is not too permissive. Fixing this
situation would require a big time investment since we currently don't
have a simple way to produce DAML-LF without going through GHC, which
will always produe well-typed DAML-LF.

I will update the DAML-LF specification wrt pattern matching
exhaustiveness in a separete PR.

This PR does not have a changelog entry since there's no impact for our
users.

CHANGELOG_BEGIN
CHANGELOG_END

* Make check linear in match size not constructor number

CHANGELOG_BEGIN
CHANGELOG_END

* Move lookupWithIndex in Data.List.Extended

CHANGELOG_BEGIN
CHANGELOG_END

* Implement the suggestions

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-06 17:15:04 +01:00
Martin Huschenbett
b01d327211
Haskell: Add hlint rule to suggest foldl' over foldl (#7897)
* Haskell: Add hlint rule to suggest foldl' over foldl

`foldl` is lazy in a way that almost never is what you want since it
can cause space leaks without any benefit. `foldl'` does not have this
problem. See https://www.well-typed.com/blog/2014/04/fixing-foldl/ for
more details.

CHANGELOG_BEGIN
CHANGELOG_END

* Fix all existing occurrences of foldl

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-05 18:32:44 +00:00
Martin Huschenbett
814e62caf5
damlc: Don't warn on TypeOperators and UndecidableInstances (#7909)
Currently, we're warning that both extensions might not work with
`data-dependencies`. However, we have tests that demonstrate that both
extensions actually do work with `data-dependencies`. Since there's
been customer demand to remove these warnings, we'll do so.

CHANGELOG_BEGIN
[damlc] Don't warn anymore that the language extensions TypeOperators
and UndecidableInstances might not work with `data-dependencies`.
CHANGELOG_END
2020-11-05 16:43:31 +00:00
Martin Huschenbett
123811cef9
damlc: Split data-deps test out of packaging tests (#7894)
The packaging test suite has become just so big that it regularly
exceeds its 15 min timeout. There are some deeper issues here, for
instance that we set up tons of tiny DAML projects and call
`daml build` on each of them. Each of those builds initializes a
package database, which is one of the things that seem to take
noticable time. Unfortunately, fixing these issues is a bigger effort.

This PR is more of a band aid rather than a proper solution: split the
packaging tests into two parts: the packaging tests and the tests for
data-depenendencies. Effectively, this amounts to giving the old
packaging test suite a 30 min time budges, but at least the two parts
can now be run in parallel.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-05 11:04:46 +01:00
Martin Huschenbett
075cab697b
damlc: Rotate type checking of case expressions by 90 degrees (#7873)
Currently, the Haskell implementation of the DAML-LF type checker
first branches on the pattern and then on the type of the scrutinee.
This PR changes it to first branch on the type of the scrutinee and
then on the pattern. This allows for destructing the type of the
scrutinee only once intead of repeating it for each pattern. This
should be good for performance, which is a nice side effect of this
change.

The main reason why I'm changing this is because we want to implement
an exhaustiveness check. This seems rather complicated to achieve with
the current implementation and will be significantly easier after this
change.

This PR is purely a refactoring and does not change the semantics of
amnything. In particular, it does not touch the decision that default
patterns match on anything, even no other pattern would match on the
value.

CHANGELOG_BEGIN
CHANGELOG_END
2020-11-04 13:06:00 +01:00
Sofia Faro
e75d42ddc3
Represent overlap modes at the type level. (#7864)
On request by @hurryabit, this PR changes the representation of
overlap modes by moving it to the type-level. Since the value-level
encoding never made it into a stable release, this isn't a breaking
change. Also, the data-dependency and roundtrip tests are unchanged,
only the daml-test-files overlap mode test had to be updated.

changelog_begin
changelog_end
2020-11-03 12:40:36 +00:00
Martin Huschenbett
5853d24a80
damlc: Make record projection sections faster (#7853)
Currently, `damlc` compiles a record projection section `(.foo.bar)`
into
```
getField @"bar" . getField @"foo"
```
Since we don't inline the `.`
operator, this is slower than it could be.

This PR changes the compilation scheme to produce
```
\record -> getField @"bar" (getField @"foo" record)
```
This is significantly faster since it avoids a couple of function
applications.

My micro benchmarks show a speedup of 1.8x for a single application of
`(.foo.bar)`. For a chain of length 3, as in `(.foo.bar.baz)`, the
speedup is even 2.3x.

This PR does add any new tests since the existing tests, particularly
the ones in `Records.daml`, already cover that area.

CHANGELOG_BEGIN
[daml] Performance improvements for record selector sections such as
`(.foo.bar)`.
CHANGELOG_END
2020-11-03 09:13:48 +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
Martin Huschenbett
6572457973
damlc: Use fresh names when compiling builtins (#7809)
* damlc: Use fresh names when compiling builtins

Currently, we're always using the variables names `v1`, `v2`, ... for
the lambdas we introduce during the conversion of partially applied
builtins to DAML-LF. This can lead to problems when the variable name
is already in use. The test cases used to fail because of the usage of
`v2`.

This PR fixes the issue by properly generating fresh names. There's no
test case for type variables since I don't know how to trigger an
issue. Fixing it seems a good idea nevertheless.

CHANGELOG_BEGIN
CHANGELOG_END

* Add Sofia's suggestions

CHANGELOG_BEGIN
CHANGELOG_END

* Fix a nasty typo

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

* Fix more issues pointed out by Sofia

CHANGELOG_BEGIN
CHANGELOG_END

Co-authored-by: Sofia Faro <sofia.faro@digitalasset.com>
2020-10-29 14:17:52 +01: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
Sofia Faro
5aa5ea6f41
Add roundtrip tests for MetadataEncoding. (#7833)
* Add roundtrip tests for MetadataEncoding.

changelog_begin
changelog_end

* buildifier fixx
2020-10-28 13:09:40 +00:00
Sofia Faro
3f64a6ae8d
Add MINIMAL pragma support in data-deps. (#7815)
* Add MINIMAL pragma support in data-deps.

CHANGELOG_BEGIN

- [DAML Compiler] MINIMAL pragmas are now imported correctly
  in data-dependencies.

CHANGELOG_END

* fix test

* Review comments

* Update compiler/damlc/daml-lf-conversion/src/DA/Daml/LFConversion.hs

Co-authored-by: Martin Huschenbett <martin.huschenbett@posteo.me>

Co-authored-by: Martin Huschenbett <martin.huschenbett@posteo.me>
2020-10-28 10:37:23 +00:00
Sofia Faro
201a6e8c1b
Refactor fun dep and overlap mode implementations. (#7810)
* Refactor fun dep and overlap mode implementations.

This PR moves the functional dependency and overlap
mode encoding/decoding functions to a single module,
separate from the rest of LF conversion or
data-dependencies, in preparation of adding more
annotations of this sort (e.g. MINIMAL).

This involves a small amount of refactoring to get
the types to line up... It should be a little easer
to write some roundtrip tests for these now.

I'm not super satisfied with how much fun dep / overlap
mode logic is still left in LFConversion.hs and
DataDependencies.hs, but this is a step in the right
direction at least.

changelog_begin
changelog_end

* Rename Encoding to MetadatEncoding
2020-10-26 15:59:39 +00:00
Martin Huschenbett
e49b07092a
damlc: Minor cleanup in setFieldPrim conversion (#7802)
That `setFieldPrim` is so far away from `getFieldPrim` has bugged me
for a while now. I _strongly_ feel that they should be next to each
other.

There are also a few outdated comments that are brought up to date.

CHANGELOG_BEGIN
CHANGELOG_END
2020-10-26 08:57:25 +00:00
Martin Huschenbett
9dec66899b
Compiler: Add more tests for record projection conversion (#7786)
This PR adds a couple of tests that ensure that various syntactic
variants of record projection all get translated into the according
DAML-LF primitive as soon as we know the record type and field name.

This PR also fixes some inconsistencies in the translations of
`getField` and `getFieldPrim`. The change for `getField` does not have
any impact if the simplifier is run since the simplifier would perform
the inlining for a partially applied `getField` we perform here.

Nevertheless, performing this inlining in the conversion to DAML-LF has
some advantages. First of all, we also run it in cases where the
simplifier is turned off, like incremental computation. Second, this is
such a crucial optimization that I want to be as sure as possible that
it is run. Third, doing the inlining in the conversion is cheap and
removes a bit of load from the simplifier. Fourth, the consistency with
the other record primitives is quite nice too.

CHANGELOG_BEGIN
CHANGELOG_END
2020-10-23 13:32:33 +02: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
Robin Krom
cf85751c3c
daml assistant: cleanup of daml ledger commands (#7777)
* daml assistant: cleanup of daml ledger commands

This is a cleanup of the Helper/Ledger.hs module in preparation for
further implementations of `daml ledger` commands against the JSON API.
In particular the module Compiler/Fetch.hs is removed from daml-compiler
and its contents moved over the Helper/Ledger.hs. Some renaming and
reorganization is done for clarity.

CHANGELOG_BEGIN
CHANGELOG_END
2020-10-22 17:07:43 +02:00
Martin Huschenbett
51a97d44e4
Hide Symbol kind from stdlib docs (#7752)
`Symbol` is the kind of type-level strings. We use type-level strings
as part of our record system. That's why we need the `Symbol` in the
first place. However, one can abstract over record fields using the
`HasField` typeclass without directly using the `Symbol` kind. Thus,
there's is no need for our users to ever use it. In fact, they
most likely don't want to use it since it does work work with
data-dependencies and we have no plans to support it in that way.

Given that `Symbol` is not necessary and doesn't work in all cases,
let's hide it from the docs so that nobody gets the idea to use it.

CHANGELOG_BEGIN
CHANGELOG_END
2020-10-22 14:23:46 +02:00
Bernhard Elsner
e6a276e591
Add Enum and Bounded instances to DA.Date (#7774)
* Add Enum and Bounded instances to DA.Date

CHANGELOG_BEGIN
[DAML StdLib] Add Enum and Bounded instances to DA.Date
CHANGELOG_END

* Hide internal date functions in docs

* Fix line numbers

* Export Date<>Int conversion functions rather than hiding

* Update compiler/damlc/daml-stdlib-src/DA/Date.daml

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

* Offset the Date enum to make it zero-based

* Apply suggestions from code review

Co-authored-by: Martin Huschenbett <martin.huschenbett@posteo.me>

* Improve tests

* Incorporate Martin's feedback

Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
Co-authored-by: Martin Huschenbett <martin.huschenbett@posteo.me>
2020-10-22 11:46:13 +00:00
Sofia Faro
b925c483d2
Add overlapping instances support in data-deps. (#7770)
Also adds a small test.

changelog_begin

- [DAML Compiler] Similar to functional dependencies, the
  compiler now adds overlapping instance pragmas into the
  DALF/DAR files. This way, overlapping instances pragmas
  will be preserved when importing typeclass instances
  via data-dependencies.

changelog_end
2020-10-21 15:07:10 +01:00
Sofia Faro
1d64fca39a
Add overlap mode annotations during LF conversion. (#7765)
* Add overlap mode annotations during LF conversion.

This PR adds an overlap mode binding `$$om$fFoo...` during LF conversion
per typeclass instance `$fFoo...` that uses an overlap mode pragma. The
idea is that we can then pick these up during data-dependencies
(left to a separate PR).

This PR also adds a test to make sure we're capturing this information
correctly.

changelog_begin
changelog_end

* git shrapnel
2020-10-21 12:53:03 +01: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
Martin Huschenbett
03a03957d9
Reverts digital-asset/daml#7725 (#7744)
I tried a compiler with these new warnings on a giant codebase and I
turned out they are _extremely_ noisy. There are basically two things we
want to warn about:

1.  Usage of the promoted kinds and types coming from the `DA.Generics`
    module.

    We already have a warning that importing `DA.Generics` will break
    data-dependencies. Adding a warning to every single use site of its
    exports seems rather excessive and doesn't add any new information.

2.  Usage of the `Symbol` kind and type-level strings.

    The `Symbol` kind seems to work better with data-dependencies than I
    expected although it is erased into kind `*` during conversion to
    DAML-LF. This is for two reasons: (1) The only _legal_ way to
    introduce a type variable of kind `Symbol` is by means of the
    `HasField` typeclass (you can technically get your hands on the
    `Symbol` kind directly, but you need work around not being able to
    import the internal module `GHC.Types`). (2) In data-dependencies,
    we reconstruct type variables of kind `*` not as kind `*` but rather
    ask GHC to infer their kinds (via
    [`UserTyVar`](https://hackage.haskell.org/package/ghc-8.10.1/docs/src/GHC.Hs.Types.html#UserTyVar)).
    This means that every type variable that was originally of kind
    `Symbol` will be reconstructed at that kind again since the
    necessary `HasField` constraint will force GHC to infer it.

    I'm totally aware that it looks a lot like this works by accident
    but I'm not completely opposed to making it a feature after the
    fact. Before we make any decisions in this regard though, we should
    decide on what uses of kind `Symbol` we want to make compatible with
    data-dependencies. For instance, functions of types like

        overField: forall x r a. HasField x r a => (a -> a) -> r -> r

    might be something we want to support. We also need to support
    constraints of the form `HasField "abc" ...` with a concrete
    type-level string everywhere. The current implementation would have
    warned about them. Thus, I see two open questions around the
    `Symbol` kind: (1) Do we want to allow `HasField x r a`, where `r`
    is a type variable and _not_ a type-level string, to be a superclass
    constraint? (2) Do we want to allow the same constraint in the
    context of a typeclass instance?

    One thing we should definitely not allow is using the `Symbol` kind
    directly under its name `GHC.Types.Symbol`, which is always in scope
    for our record preprocessor. I will add an error when users try to
    access that kind in a separate PR.

CHANGELOG_BEGIN
[DAML Compiler] The warning about advanced types combined with type
classes in a way that is supported by data-dependencies has been removed
again.
CHANGELOG_END
2020-10-20 22:15:14 +02:00
Sofia Faro
8e4e0f98c5
Functional dependency support in data-dependencies (#7719)
* Functional dependency support in data-dependencies

(WIP)

* Add test.

changelog_begin

- [DAML Compiler] Functional dependencies are now saved
  by the DAML compiler in the DALF file / DAR package. When
  importing a file with the functional dependency data via
  data-dependencies, these will be picked up automatically.

changelog_end
2020-10-19 16:50:45 +01:00
Sofia Faro
5e0559ce51
Move CallStack, HasCallStack docs to DA.Stack (#7735)
* Move CallStack, HasCallStack docs to DA.Stack

This PR only modifies the docs. In particular, it:

- moves the `CallStack` and `HasCallStack` docs to `DA.Stack`
- gives an example of adding the `HasCallStack` constraint
- hides the rest of `GHC.Stack.Types` from the docs

Rationale: `GHC.Stack.Types` has a lot of `TextLit` stuff that
we don't want people to use directly, and we want people to
import `DA.Stack` instead anyway.

changelog_begin
changelog_end

* commit unsaved changes, doh

* grammar
2020-10-19 13:13:43 +00:00
Martin Huschenbett
5f0acbc21f
Add sed script to help with updating the damlc ITs (#7727)
Updating the expected dignostics for `damlc`'s integration tests can
be quite tedious. This PR adds a `sed` script to simplify it a bit.
See the included readme for details.

CHANGELOG_BEGIN
CHANGELOG_END
2020-10-19 14:26:59 +02:00
Martin Huschenbett
7074d92324
Warn about un-upgradability of fancy kinds (#7725)
Haskell allows for promoting types to the kind level with the
`DataKinds` extension. Since DAML-LF has no similar concept (and
frankly speaking should't have one), this does not work well with
data-dependencies. Unfortunately, we need to enable the `DataKinds`
extension by default in `damlc` since our record system and the
`Numeric` type depend on it. Thus, issuing a warning that the
`DataKinds` is not supported with data-dependencies is not an option
and we need more refined warnings.

Most uses of promoted kinds won't even compile to DAML-LF and there's
no need to warn about those since they cause hard failures. However,
we need some limited support for type-level strings and the `Symbol`
kind, for type-level numbers and the `Nat` kind, as well as for some
stuff from `DA.Generics`. Type-level numbers and the `Nat` kind work
reasonable well since we have them in DAML-LF too. The `Symbol` kind,
and the types and kinds from `DA.Generics` are "erased" during
conversion to DAML-LF by replacing them with either a special `Erased`
type or the star kind. Thus, these entities are not restored properly
with data-dependencies. In combination with type classes this leads
easily to instances that for different types in the original code but
are at conflict during interface reconstruction. Long story short,
erased types/kinds and type classes don't work with data-dependencies.

We have a hack to somehow preserve type-level string since we need that
for our record system and the `HasField` type class. I have no desire
to support this hack for arbitrary type classes coming from the user.
Thus, I consider type-level strings to be erased as well here.

This PR adds a warning whenever a user is attempting to define a type
class that involves a kind that will be erased or an instance that
involves a type that will be erased. The warning tells the user that
this does not work with data-dependencies and is hence not upgradable.

There is one caveat: the `HasField` instances produced by the
propressor fall in the category we should warn about as well. Since not
supporting them would make our record system unusable, we need to give
them special treatment in data-dependencies. Thus, warning about them
would be unjustified noise and we explicitly exclude them in the code
producing the warnings.

CHANGELOG_BEGIN
[DAML Compiler] Issue warning when advanced types are with type classes
in a way that is supported by data-dependencies.
CHANGELOG_END
2020-10-19 10:13:51 +02:00