Commit Graph

49 Commits

Author SHA1 Message Date
Remy
5f0976343c
DAML-LF: fix subsitution bug (#3798)
* damlc lf typechecker: expose subtitution bug

* Fix substitution bug

* Rename variables

* fix subsitution bug in scala side

* reactive some test

* Update daml-lf/validation/src/main/scala/com/digitalasset/daml/lf/validation/TypeSubst.scala

Co-Authored-By: associahedron <231829+associahedron@users.noreply.github.com>

* Update daml-lf/validation/src/main/scala/com/digitalasset/daml/lf/validation/TypeSubst.scala

Co-Authored-By: associahedron <231829+associahedron@users.noreply.github.com>
2019-12-10 13:36:55 +01:00
Remy
e055b2bd9b DAML LF: expose generic equality in LF (#3752)
* daml-lf: expose generic equality

* drop unnecessary parentheses

* fix issue number

* address Fran's comments
2019-12-06 14:12:48 +00:00
associahedron
8127a415d9
Add unstable experimental text primitives in DA.Text and LF 1.dev (#3734)
* Add experimental text primitives

* Implement SBTextSlice

* Implemented SBTextSliceIndex

* Implement toUpper / toLower

* Implement SBTextContainsOnly

* Implement SBTextReplicate

* Implement SBTextReplicate

* Implement SBTextSplitOn

* Implement SBTextIntercalate

* Add unstable primitives in LFConversion

* Add unstable text primitives in DA.Text

* Remove all the ASCII infixes

* Fix typing mishap

* Change numbering for unstable primitives

* Deal with UTF8

* More careful slice

* Fix typo

* Missing decoder
2019-12-05 14:35:50 +00:00
Remy
5e63db7a40 speedy: Rename SMap to STextMap (#3664)
+ rename MAP to TEXTMAP in decoder/encoder
2019-11-28 17:05:26 +00:00
nickchapman-da
885bbefdf3 rename structural records: tuple -> struct (#3660)
* rename structural records: tuple -> struct

* add missing renames (tuple -> struct) in comments, var-names and error messages

* exposition: structural vs nominal; change history note

* remove accidentilly checked-in file
2019-11-28 10:00:24 +00:00
nickchapman-da
d3d6891021
Rename daml lf tuples (#3658)
* Rename DAML-LF tuples as structs (structural records)
2019-11-28 07:58:30 +00:00
Remy
d152c7cbfd daml-lf: rename Map to TextMap in archive proto (#3589)
* daml-lf: rename Map to TextMap in archive proto
+ in Scala/haskell AST

* a bit more renamming

* Update compiler/daml-lf-tools/src/DA/Daml/LF/TypeChecker/Serializability.hs

Co-Authored-By: associahedron <231829+associahedron@users.noreply.github.com>

* fix test

* Apply suggestions from code review

Co-Authored-By: associahedron <231829+associahedron@users.noreply.github.com>

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

Co-Authored-By: associahedron <231829+associahedron@users.noreply.github.com>
2019-11-25 12:14:57 +00:00
Remy
6f5c5fd3b1 daml-lf: add GenMap to archive proto (#3431)
* add GenMap to archive proto

* Address Martin's comments

* Address Gerolf's comments
2019-11-12 14:25:19 +00:00
Remy
7c427119e1 DAML-LF add Type Representation value (#3326)
* daml-lf: update spec with type-rep

* daml-lf: update proto with type-rep

* daml-lf: update scala side with TypeRep

* daml-lf: update compiler side with TypeRep

* Get triggers to compile

* Add featureTypeRep to allFeatures

* Apply suggestions from code review

Co-Authored-By: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>

* daml-lf: add builtin for TypeRep equality

* Address Andrea's comments

* formatting

* Fix triggers

* Fix template typerep tests
2019-11-04 17:00:55 +00:00
Remy
5812a1246d
daml-lf: to_text_template_id -> to_text_type_con_name (#3293)
* simplify to_text_template_id

* to_text_template_id -> to_text_type_con_name
2019-10-30 17:32:36 +01:00
Andreas Herrmann
2bd1db490a
Replace bazel-deps by rules_jvm_external (#3253)
* Update bazel-common to fix javadoc issues

Specifically, to fix the following error

```
ERROR: /home/aj/tweag.io/da/da-bazel-1.1/ledger-api/rs-grpc-bridge/BUILD.bazel:7:1: in javadoc_library rule //ledger-api/rs-grpc-bridge:rs-grpc-bridge_javadoc:
Traceback (most recent call last):
        File "/home/aj/tweag.io/da/da-bazel-1.1/ledger-api/rs-grpc-bridge/BUILD.bazel", line 7
                javadoc_library(name = 'rs-grpc-bridge_javadoc')
        File "/home/aj/.cache/bazel/_bazel_aj/5f825ad28f8e070f999ba37395e46ee5/external/com_github_google_bazel_common/tools/javadoc/javadoc.bzl", line 27, in _javadoc_library
                dep.java.transitive_deps
object of type 'JavaSkylarkApiProvider' has no field 'transitive_deps'
```

* Define Maven deps using rules_jvm_external

* Pin artifacts

* Remove bazel-deps generated targets

* Remove bazel-deps

* Switch to rules_jvm_external targets

* update bazel documentation

* pom_file: There are no more bazel-deps targets

* BAZEL-JVM.md `maven_install` typo
2019-10-28 13:53:14 +01:00
Moritz Kiefer
f4766ad903 Forbid quantifiers in Any in the Haskell typechecker (#3200)
This is a followup to #3196 which updated the Scala typechecker
2019-10-16 15:10:45 +00:00
Remy
b2985c394f daml-lf: prevent use of quanitifier in any type (#3196) 2019-10-16 11:41:58 +00:00
Remy
dd5804bff5 validation: add mising cases in type traversable (#3164)
* validation: add mising cases in type traversable
+ remove default case

* minor simplification
2019-10-14 10:28:31 +00:00
Moritz Kiefer
dcdcf7f0c0
Generalize AnyTemplate type to Any in DAML-LF (#3141)
* Generalize AnyTemplate type to Any in DAML-LF

See #3131 for the motivation for this. The tl;dr is that we need
something like AnyTemplate for choice types as well.

Since the protobuf was already more general in anticipation of such a
change, this change only changes the internal AST on the Haskell and
Scala side.

Since AnyTemplate change has never made it out of 1.dev, I updated the
changelog in the LF spec instead of adding a new entry.

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

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

* windows debugging

* more windows debugging

* clean expunge

* don’t cat the config file

* remove comment on type equality

* windows …

* gnah

* foobar

* foobar

* does anything ever work?

* reenable caching

* Do not build daml-lf-ast separately
2019-10-10 08:51:52 +02:00
Andreas Herrmann
0ba7f9f8f2 Implement ToTextTemplateId primitive on Scala side (#3115)
* Implement TyCon primitive on Scala side

* tyCon --> toTextTemplateId

https://github.com/digital-asset/daml/pull/3115#discussion_r331901925
https://github.com/digital-asset/daml/pull/3115#discussion_r331903274
2019-10-07 13:09:14 +00:00
associahedron
46051e8d11
Start adding Numeric to the standard library. (#2950)
* Numeric implementation

* Dealing with all sorts of numeric literals.

* Fix DA.Generics

* Reduce code duplication with IF_NUMERIC

* Simplify Prelude with IF_NUMERIC

* Fix daml-lf validation for MUL_NUMERIC and DIV_NUMERIC
2019-09-25 10:56:33 +01:00
Remy
23c3c33fe1
scenario-service: run no validation, when called from ide (#3003) 2019-09-25 11:06:47 +02:00
Remy
a46f1c041a Daml-LF: make Numeric scale type safe (#2958)
* daml-lf: make numeric scale type safe

* navigator: fix scale

* ledger: fix scale in tests

* Update daml-lf/data/src/main/scala/com/digitalasset/daml/lf/data/NumericModule.scala

Co-Authored-By: Gerolf Seitz <gerolf.seitz@digitalasset.com>

* Update ApiCodecCompressedSpec.scala

* Update ApiCodecCompressedSpec.scala
2019-09-18 19:33:52 +00:00
Remy
5b36d5f88b Daml-LF: make archive decoder more restrictive for 1.dev (#2937)
* daml-lf: make decoder more restrictive

* daml-lf: update spec

* daml-lf: update comment in archive proto
2019-09-18 17:22:48 +00:00
Remy
220a03c9e8 Daml-LF: make MUL_NUMERIC and DIV_NUMERIC multi-scale (#2921)
* daml-lf: Make MUL_NUMERIC and DIV_NUMERIC multi-scale

* update release notes

* compiler: fix with type change
2019-09-17 14:32:49 +00:00
Moritz Kiefer
36e95f6cf3
Add Any type and to_any/from_any primitives to protobuf (#2930)
* Add Any type and to_any/from_any primitives to protobuf

Following a suggestion by Rémy, the protobuf representation is more
general and is associated with an arbitrary type instead of a
typecon. This allows us to easily extend this later to a full Any
type.

I’ve still called the type in the protobuf Any instead of Haskell’s
Dynamic since I find AnyTemplate more clear than DynamicTemplate and
having AnyTemplate and Dynamic seems confusing.

Right now, the decoder enforces that the type is a TypeCon.

* Fix some mistakes in the spec

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

Co-Authored-By: Remy <remy.haemmerle@daml.com>

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

Co-Authored-By: Remy <remy.haemmerle@daml.com>

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

Co-Authored-By: Remy <remy.haemmerle@daml.com>

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

Co-Authored-By: Remy <remy.haemmerle@daml.com>

* Add evaluation rule for to_any_template

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

Co-Authored-By: Remy <remy.haemmerle@daml.com>
2019-09-17 15:02:59 +02:00
Remy
dc9429be1d Daml-LF: Add CAST_NUMERIC and SHIFT_NUMERIC (#2919)
* daml-lf: add CAST_NUMERIC and SHIFT_NUMERIC internally

* daml-lf: add CAST_NUMERIC and SHIFT_NUMERIC to archive proto

* daml-lf: update spec with CAST_NUMERIC and SHIFT_NUMERIC

* update release notes

* fix spec

* Address comments from Fran and Gerolf

* fix unrel
2019-09-17 08:52:54 +00:00
Moritz Kiefer
1703a517de Implement AnyTemplate DAML-LF type on the Scala side (#2905)
* Implement AnyTemplate DAML-LF type on the Scala side

This is the first part of
https://github.com/digital-asset/daml/issues/2876. The PR adds
AnyTemplate to Speedy and to the internal expression representation
and adapts all the relevant infrastructure (e.g., the typechecker) and
the tests.

It does not yet change the protobuf representation, the Haskell side
or the spec. I’ll update the spec together with changing the protobuf.

* Add comments to SBToAnyTemplate and SBFromAnyTemplate

* Address some comments from Remy

* Only allocate TBuiltin(BTAnyTemplate) once
2019-09-16 10:54:52 +00:00
Remy
9a4dff63b2
daml-lf: introduce Numeric in internal AST (#2608)
* daml-lf: introduce numeric in daml-lf AST
* daml-lf: add test for command preprocessor
* interface-reader: fix for Numerics
* Address Gerolf's review
2019-08-23 15:27:14 +02:00
Gary Verhaegen
99ea93168d
update copyright notices (#2499) 2019-08-13 17:23:03 +01:00
Francesco Mazzoli
6cc5510dae purge all Map#mapValues from daml-lf codebase (#1864)
fixes #1861.
2019-07-04 15:08:43 +00:00
Martin Huschenbett
3ffa2232a9 Allow shadowing of type variables in DAML and DAML-LF (#1962)
* Allow shadowing of type variables in DAML and DAML-LF

We relax the DAML-LF type checker to allow for shadowing of type variables.
This does not need big changes since the substitution we use already avoids
name capture. The test for alpha equivalence converts to de Bruijn indices
on the fly and is hence not a problem either.

We inline type synonyms during the conversion from GHC Core to DAML-LF. This
requires alpha renaming. The cheapest way to get this, is to use the unique
names of type variables instead of their surface names.

This fixes #1915.

* Fix Scala test

* Relax memory constraints for bond-trading test
2019-07-03 08:57:43 +00:00
Remy
6cd3f93d2e scala-codegen: add support for enum type (#1833)
* scala-codege: add support for enum type

* formatting

* first part of Stephen comments

* Address Stephen's comments
2019-06-26 17:50:37 +00:00
Remy
8f006e2714 minor fix for scala typecheck (#1764)
* daml-lf: fix typecheck bug with template type

* address Martin's comment
2019-06-19 16:21:59 +00:00
Remy
11b602da03 Scala Daml-lf encoder (#1715)
* encode ast in protobuf

* daml-lf parser: make defaultPackageId and languageVersion parametric

* daml-lf rewritting of AST

* test ast encoder

* copyright

* test function type encoding

* daml-lf add parameter to parser implicits

* damlfl-as stands for "damllf assembler"

* move encoder in its own private package
2019-06-18 17:32:21 +00:00
Remy
0591075187 cleanup daml-lf scala packages (#1581)
* cleanup daml-lf scala packages

* Address Stephen's Comments

* update maven coordinates of language package
2019-06-12 15:55:48 +00:00
Remy
bf5309b42e daml-lf: add enum pattern matching (#1506)
* daml-lf: add enum pattern matching

* daml-lf: add test for interpreter pattern matching
2019-06-04 22:25:22 +00:00
Remy
0d25b73d1f daml-lf add builtin to (un)pack string in code points (#1480)
, namely

* FROM_TEXT_CODE_POINTS: Text -> [Int64]
* TO_TEXT_CODE_POINTS: [Int64] -> Text
2019-06-04 14:06:25 +00:00
Remy
f84e7d79d2 Add enum type to daml-lf (#1397)
* add enum type to daml-lf dev

* Address Francesco's comments

* Address Martin's comments

* fix daml-lf proto version history
2019-05-29 12:15:01 +00:00
Martin Huschenbett
2605f00804 Freeze DAML-LF 1.dev into DAML-LF 1.5 (#1408)
* Freeze DAML-LF 1.dev into DAML-LF 1.5

In other words, we release DAML-LF 1.5.

This is required for generic templates (#1387).

* description of FROM_TEXT_INT64 & FROM_TEXT_DECIMAL

* amend version history

add ``FROM_TEXT_INT64`` and ``FROM_TEXT_DECIMAL`` in the specification changelog

* typos

* Fix markup in DAML-LF spec

* Add release notes
2019-05-27 21:11:37 +00:00
Remy
439613bee8 daml-lf: add FROM_TEXT_INT64 and FROM_TEXT_DECIMAL (#1407)
* daml-lf: add FROM_TEXT_INT64 and FROM_TEXT_DECIMAL

* Fix typos in Haskell

* cosmetic change

* Fix DAML-LF type checker

* Fix merging fallout
2019-05-27 17:19:01 +00:00
Martin Huschenbett
c30ec0fc03
Make the actors optional in DAML-LF's exercise instruction (#1377)
* Make the actors optional in DAML-LF's exercise instruction

If they are not present, the controllers will be filled in. Surface DAML
does this currenty anyway by fetching the contract and computing the
choice controllers before each `exercise`. This change will allow for
getting rid of the additional `fetch` preceding each `exercise`.

The compiler does not use the new form yet. I will do this in a separate
PR together with tests for the new behaviour.

This fixes #1347.

* Fix DAML-LF type checker test

* Check presence of actors for old DAML-LF versions in decoder
2019-05-24 15:01:56 +02:00
Martin Huschenbett
b09cbd037b
Add coerce for contract ids to DAML-LF (#1346)
* Add coerce for contract ids to DAML-LF

This is needed for our implementation plan for generic templates.

Fixes #1277.

* Reformat Scala
2019-05-24 09:08:15 +02:00
Martin Huschenbett
8ec03875c6
Lift restriction on serializable contract ids in DAML-LF 1.dev (#1315)
* Lift restriction on serializable contract ids in DAML-LF 1.dev

In DAML-LF 1.dev, make `ContractId a` serializable whenever `a` is
serializable. This is part 2 of #1277.

* Reformat Scala

* Add changelog entry to daml_lf_1.proto
2019-05-22 22:23:59 +02:00
Martin Huschenbett
a50c2edf9a
Fix package validation for DAML-LF 1.4 (#1316)
* Fix package valdiation for DAML-LF 1.4

Currently, complex contract keys are are not accepted for DAML-LF 1.4
although they should because we forgot to roll the version when freezing
DAML-LF 1.4.

@bitonic we need a way forward to avoid this in the future.

* Fix test

* Format Scala
2019-05-22 22:22:57 +02:00
Martin Huschenbett
d87ba19ea2 Add more tests for (un)serializable contract ids (#1296)
* Add more tests for (un)serializable contract ids

I want to lift this restriction in a subsequent PR for the next version
of DAML-LF. Let's first make sure we have a correct implementation for the
current version though.

* fix test

* in serializability tests, check the modules are properly typed
2019-05-22 10:19:51 +00:00
Martin Huschenbett
24e305c1af Relax syntactic restriction on contract keys in DAML-LF 1.dev (#1219)
* Relax syntactic restriction on contract keys in DAML-LF 1.dev

We lift the syntactic restriction that contact keys must be built using
only record constructions and projections entirely when compiling to
DAML-LF 1.dev. To make this more useful, we also search all sub-expressions
of `maintainer` in `key` during our rewriting of `maintainer` for using
`this` to using `key`.

As one of our next steps we should bring `key` into scope in `maintainer`
and perhaps deprecate the use of `this` at some point in the future.

* Fix versioning

* Adapt package validation to complext contract keys
2019-05-17 20:06:23 +00:00
Remy
2e3a87934b Daml lf type safty (ChoiceName, VarName, FieldName, ConstructorName) (#983)
* daml-lf: make DefinitionRef more typesafe

* daml-lf: Identifier -> DefinitionRef

* daml-lf: remove unsafe apply and copy methods from DottedName

* daml-lf: create identifier

* daml-lf: make ChoiceNames Identifiers

* daml-lf: cleanup TVar

* daml-lf: FieldNames & VariantConstructors -> Identifiers

* bazel fmt

* daml-lf: VarName -> Identifier

* daml-lf: drop return inside Ref.scala

* daml-lf Identifier -> Name

* daml-lf DefinitionRef -> Identifier

* daml-lf make iface more type safe
+ address Francesco's comments

* daml-lf: remove unsafe unapply from MatchingStringModule

* fix navigator

* Address Stephen's Comments
2019-05-13 11:17:12 +00:00
Stephen Compall
a3e9aad147
remove major LF dev version (#681)
* removing major LF dev version from Haskell proto codecs

* removing major LF dev version from scenario service client

* missed import

* remove Scala support for dev major version; remove --allow-dev option from sandbox cli

* Version.minorFromCliOption function

* don't build daml-stdlib artifacts for dev major

* remove damlc CLI --target dev

* release note about removed dev major LF version

* governance now discusses minor dev, no more major dev

* don't build from daml_lf_dev.proto anymore

* remove daml_lf_dev.proto

* raise deprecated release

* reserve 9999 in the ArchivePayload sum, as suggested by @bitonic

* use reserved proto keyword, as suggested by @bitonic

- `reserved` cannot occur within `oneof` block

* remove --allow-dev test

* dev removal release note followed the previous release; move it back to HEAD
2019-04-26 13:10:09 -04:00
Francesco Mazzoli
6af84051ee
fix various conversion functions from string to Decimal (#439)
* fix various conversion functions from string to Decimal

Fixes #399.

This fixes a critical bug -- since:

* The DAML-LF spec specifies that the scale of `Decimal` is 10 --
    that is, there are at most 10 digits past the decimal point:
    <79bbf5c794/daml-lf/spec/value.rst (field-decimal)>.
* However, the code converting from the string representation that
    we get on the wire was _not_ performing this check. This is due
    to two reasons:

    - `Decimal.check` is a function that checks whether a given
        `Decimal` is within the upper and lower bounds of what the
        DAML-LF spec specifies, but crucially it does _not_ check that
        the scale is not exceeded:
        <79bbf5c794/daml-lf/data/src/main/scala/com/digitalasset/daml/lf/data/Decimal.scala (L31)>.
        This behavior is correct in some cases (more on that later),
        but not in others. Crucially, `Decimal.fromString`, which was
        supposed to check if a decimal string literal is valid, used
        this function, which means that it accepted string literals
        containing numbers out of the required scale, rounding them to
        make them fit within the scale. This function has been renamed
        to `Decimal.checkWithinBoundsAndRound`, and a new function
        `Decimal.checkWithinBoundsAndWithinScale` has been added, which
        fails if the number provided has data not within the scale.
        `Decimal.fromString` now uses
        `Decimal.checkWithinBoundsAndWithinScale`.

    - `ApiToLfEngine.parseDecimal` assumed that `Decimal.fromString` _did_
        fail when passed numbers that were in any way invalid, and
        moreover did _not_ use the result of `Decimal.fromString`, but rather
        re-parsed the string into an unconstrained `BigDecimal`:
        <79bbf5c794/ledger/ledger-api-common/src/main/scala/com/digitalasset/platform/participant/util/ApiToLfEngine.scala (L96)>.
        The reason for the code to work this way is that in the past
        it was responsible for converting decimal strings both for the
        current engine but also for an older version of the engine which
        handled decimals of a different type. Both issues have been fixed.

* Therefore, `Decimal`s with scale exceeding the specified scale
    made it into the engine, and contracts could be created containing
    this invalid value.

* Once on the ledger, these bad numbers can be used to produce extremely
    surprising results, due to how `Decimal` operations are
    implemented. Generally speaking, all operations on `Decimal`
    first compute the result and then run the output through
    `Decimal.checkWithinBoundsAndRound`. The reason for this behavior
    is that we specify multiplication and division as rounding their
    output. Consider the case where the bad value 0.00000000005 made
    it to the engine, and is then added to 100. The full-precision
    result will be 100.00000000005, which after rounding becomes 100.
    Therefore, on a ledger where such invalid values exist, it is not
    the case that `y > 0 ==> x + y != x`, and so on.

Thanks a bunch to @briandbecker for the excellent bug report.

* fix failing test using to much precision
2019-04-14 13:49:28 +02:00
gleber
aa70c7f64e
Enforce consistent formatting of BUILD files. (#412)
* Add buildifier targets.

The tool allows to check and format BUILD files in the repo.

To check if files are well formatted, run:

    bazel run //:buildifier

To fix badly-formatted files run:

    bazel run //:buildifier-fix

* Cleanup dade-copyright-headers formatting.

* Fix dade-copyright-headers on files with just the copyright.

* Run buildifier automatically on CI via 'fmt.sh'.

* Reformat all BUILD files with buildifier.

Excludes autogenerated Bazel files.
2019-04-12 13:10:16 +02:00
moritzkiefer-da
fa4067ad1b
Move POM file generation to Bazel rules (#374)
* Move POM file generation to Bazel rules
2019-04-11 11:24:52 +02:00
Digital Asset GmbH
05e691f558 open-sourcing daml 2019-04-04 09:33:38 +01:00