Commit Graph

180 Commits

Author SHA1 Message Date
Sofia Faro
1d7bca801e
Add optional typerep argument in UExerciseInterface. (#11910)
* Add type rep argument for interface exercises.

(Still WIP.)

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

changelog_begin
changelog_end

* haskell side

* dont throw exception in checkTemplateId

* scalafmt

* evidence security

* fix TypingSpec test
2021-11-30 15:10:33 +00:00
Moritz Kiefer
3b5f8a73e1
Remove precondition field from TemplateImplements (#11763)
* Remove precondition field from TemplateImplements

fixes #11635

changelog_begin
changelog_end

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

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

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

Part of #10915

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

changelog_begin
changelog_end

* scalafmt and refactoring

* fixx merge conflict

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

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

part of #11372

changelog_begin
changelog_end

* Remove virtual choices cont.

Switch uses of virtual choices to fixed choice with method implementation

* update snapshot after pin on windows

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

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

CHANGELOG_BEGIN
CHANGELOG_END

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

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

* format

* interfaces: lfconversion for iface preconditions

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

CHANGELOG_BEGIN
CHANGELOG_END

* format

* rebase

Co-authored-by: Remy <remy.haemmerle@daml.com>
2021-11-02 17:27:49 +00:00
Sofia Faro
d8898b8c80
Check fixed choices in name collision checker (#11481)
* Check fixed choices in name collision checker

This is a follow up to #11364. This PR checks that the list of inherited
choice names is correct in the type checker, and moves the "fixed choice name
collision" check into the name collision checker using this data.

Haskell side only for now. Part of #11137.

changelog_begin
changelog_end

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

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

Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
2021-11-01 14:52:44 +00:00
Sofia Faro
741a6e75a7
interfaces: Add list of fixed choices in TemplateImplements structure. (#11364)
* interfaces: Add fixed choices in TemplateImplements

To make template choice collision checks local.

changelog_begin
changelog_end

* LF completer

* lint

* scary non-shadowing

* improve comment

* change field name
2021-11-01 11:51:51 +00:00
Robin Krom
45beaf7aac
interfaces: typecheck for precond, haskell side. (#11468)
This adds the typecheck for the interface precondition on the Haskell
side.

CHANGELOG_BEGIN
CHANGELOG_END
2021-10-29 14:36:32 +00:00
Sofia Faro
ed9dbed100
interfaces: Add fixed choice collision check in typechecker (Haskell) (#11337)
* interfaces: Add fixed choice name collision check

Add a check that a template cannot have two choices with the same name,
even taking into account all of its "inherited" interface fixed choices.

Part of #11137

changelog_begin
changelog_end

* "Me want" -> "We want"
2021-10-21 12:29:05 +01:00
Sofia Faro
7e2edbdfaf
interface fixed choices: Haskell Typechecker (#11177)
Part of #11137

changelog_begin
changelog_end
2021-10-08 15:42:29 +01:00
Sofia Faro
53c76d47c3
interface fixed choices: Haskell AST (#11160)
* interface fixed choices: Haskell AST

Part of #11137

changelog_begin
changelog_end

* Make intParam strict
2021-10-07 10:46:50 +00:00
Sofia Faro
0d3ae6e14c
interface methods: Haskell Typechecker (#11028)
part of #11006

changelog_begin
changelog_end
2021-09-27 12:32:05 +01:00
Sofia Faro
4075624cfc
interface methods: Haskell AST (#11018)
* interface methods: Haskell AST for methods

Part of #11006. This leaves typechecker and LF conversion for later, on
the haskell side.

changelog_begin
changelog_end

* Forgot ECallInterface in DecodeV1

* fix a test
2021-09-27 10:10:21 +01:00
Sofia Faro
cebe6ed482
Refactor safetyStep in the simplifier. (#10948)
changelog_begin
changelog_end
2021-09-21 15:49:48 +01:00
Sofia Faro
ac192fc6db
interfaces: Add to/from interface in Haskell typechecker (#10951)
* interfaces: Add to/from interface in hs typecheck

changelog_begin
changelog_end

* questionable lint
2021-09-21 15:29:33 +01:00
Sofia Faro
724e50d739
interfaces: Add to/from interface in Haskell AST (#10945)
Part of #10810

changelog_begin
changelog_end
2021-09-21 10:24:10 +01:00
Robin Krom
2edfc062a0
ifaces: name collision, typecheck fetch/exercise (#10896)
* ifaces: name collision, typecheck fetch/exercise

This adds name collision detection and adds typechecking for
fetch/exercising of interface instances.

CHANGELOG_BEGIN
CHANGELOG_END

* turn on exercises in InterfaceDesugared test case

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

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

Co-authored-by: Sofia Faro <sofia.faro@digitalasset.com>
2021-09-20 21:40:26 +00:00
Robin Krom
50291ed61b
interfaces: scala typechecker implementation (#10867)
* interfaces: scala typechecker implementation

This is the scala side of the lf typechecker for interfaces.

CHANGELOG_BEGIN
CHANGELOG_END

* added collision check

* added exercise/fetch typechecking

* review suggestions

* added todos for collision/typing scala tests
2021-09-16 20:37:33 +00:00
Moritz Kiefer
9b0fa29aec
Separate exercise & fetch for interfaces from templates (#10908)
* Separate exercise & fetch for interfaces from templates

part of #10810

changelog_begin
changelog_end

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

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

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

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

Co-authored-by: Sofia Faro <sofia.faro@digitalasset.com>
2021-09-16 12:05:11 +00:00
Robin Krom
6dc769b7ad
interfaces: lf typechecker implementation (#10843)
* interfaces: lf typechecker implementation

CHANGELOG_BEGIN
CHANGELOG_END

* review suggestions
2021-09-13 14:58:33 +02:00
Moritz Kiefer
6d347d4e88
Add daml interfaces to the Haskell LF AST (#10811)
* Add daml interfaces to the Haskell LF AST

Just copied from Sofia’s PR with no changes and stubbed all usages of
it that aren’t trivial.

changelog_begin
changelog_end
2021-09-08 15:48:02 +00:00
Remy
1f021b25c6
LF: Drop Builtin Exceptions completly (#9790)
CHANGELOG_BEGIN
CHANGELOG_END
2021-05-26 19:30:44 +02:00
Remy
5855a9941f
LF: Drop CONTRACT_ERROR (#9754)
CHANGELOG_BEGIN
CHANGELOG_END
2021-05-21 09:12:29 +00:00
Remy
40b23810d2
Compiler: clean convertion builtin name (#9724)
This follows up #9716

CHANGELOG_BEGIN
CHANGELOG_END
2021-05-19 19:16:29 +02:00
Remy
55c36cc93e
Compiler: drop BEToTextBigNumeric in favor of BEToText (#9728)
CHANGELOG_BEGIN
CHANGELOG_END
2021-05-18 14:49:03 +00:00
Sofia Faro
2a2c745978
Implement name collision check for type synonyms. (#9723)
Part of #3616

changelog_begin
changelog_end
2021-05-18 13:56:02 +01:00
Remy
d4fca0305b
LF: Change error exception for Arithmetic builtins (#9692)
This PR is a priliminary step toward making Arithmetic Builtin
throwing proper Daml Excetpions.

This is part of #8020.

CHANGELOG_BEGIN
CHANGELOG_END
2021-05-18 10:41:44 +02:00
Sofia Faro
1edb110f99
Fix simplifier safety for AnyExceptionMessage (#9707)
* Fix simplifier safety for AnyExceptionMessage

This highlights the danger of shifting definitions. At some point this safety was correct (AnyException contained the message string directly, "throw" took a message argument), and then we decided to have AnyException call a function associated with the type (to speed up exception throwing & catching), and this safety became incorrect :-(

changelog_begin
changelog_end

* s/may crash/may throw
2021-05-17 14:04:23 +00:00
Sofia Faro
22ba5fddd2
Remove builtin exception types from protobuf and ASTs. (#9595)
* Remove builtin exception types from protobuf/AST.

changelog_begin
changelog_end

* Remove builtin exxceptions from protobuf/ast.

* remove unecessary s"

* scalafmt

* syntax error

* Add TODOs

* Apply suggestions from code review

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

* Add AnyException builtins in typing spec.

* Update protobuf "Next id" comment.

Co-authored-by: Remy <remy.haemmerle@daml.com>
2021-05-06 21:26:12 +00:00
Remy
6c1f404c7d
LF: Add TO_TEXT_BIGNUMERIC (#9276)
This is part of #8719.

CHANGELOG_BEGIN
CHANGELOG_END
2021-03-30 13:31:42 +02:00
Sofia Faro
27dbf0bef9
BigNumeric in the stdlib cleanup. (#9253)
* Cleaning up BigNumeric somewhat.

Done in this PR:
- Moved BigNumeric and RoundingMode to GHC.Types to be alongside Numeric and Decimal
- Additive, Multiplicative, Number instances for BigNumeric
- Eq, Ord instances for BigNumeric and RoundingMode

Todo:
- BigNumeric literals in Daml
- Constructors and pattern matching for rounding mode
- Better documentation

changelog_begin
changelog_end

* remove ^ for now

* define (^) because it's required

* Error in (^) for negative powers.

* better error message

* import fromString and error

* Add -Wno-unused-imports because of compiling to different versions.

* add (fromString) and (error)

* Update bignumeric test.
2021-03-29 13:33:36 +00:00
Remy
181afe4607
Daml: Add basic support for BigNumeric in 1.dev (#9243)
CHANGELOG_BEGIN
CHANGELOG_END
2021-03-26 09:00:05 +01:00
Remy
1e0c67c306
LF: Add RoundingMode and BigNumeric in Haskell Ast (#9215)
This is part of #8719.

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

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

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

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

aa7991f8 shows a use case of this hook.

CHANGELOG_BEGIN
CHANGELOG_END
2021-03-11 21:36:49 +01:00
Sofia Faro
34fe42237d
data-deps: Dont let defaults leak constraints. (#8833)
* data-deps: Dont let defaults leak constraints.

Fixes #8802

changelog_begin
changelog_end

* use expandSynApp instead of expandTypeSynonyms

* revert isConstraint change

* fix indentation
2021-02-12 15:44:29 +00: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
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
Sofia Faro
84e5881236
Add serializability check for exceptions. (#8151)
* Add serializability check for exceptions.

Part of #8020

changelog_begin
changelog_end

* typo
2020-12-07 14:44:24 +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
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
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
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
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
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
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
Sofia Faro
1390703cc9
Use $$ instead of $ for new name prefixes in damlc (#7701)
GHC uses $. To avoid a clash, let's use $$ instead as suggested by Martin.

changelog_begin
changelog_end
2020-10-16 12:13:44 +01:00
Remy
0bb378690d
LF: Add ExerciseByKey Update (#7663)
CHANGELOG_BEGIN
CHANGELOG_END
2020-10-14 12:06:36 +02: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
Sofia Faro
a2077e5558
Inline typeclass projections for unknown dictionaries. (#7057)
* Inline tc projections for unknown dictionaries.

changelog_begin
changelog_end

* remove unrelated change

* this is fine

* safety gate unneeded
2020-08-10 10:55:14 +01:00
Sofia Faro
3b08440fe7
Strip ELocation nodes in simplifier rules. (#6930)
* Strip ELocation nodes in simplifier rules.

Uses stripLoc in the patterns used by the simplifier. This change
reduces the size of the generated code by 1.5% for a very large project,
meaning we had rules (like `let x = e in x`) that weren't trigerring
because of the `ELocation` nodes that weren't being properly ignored.

changelog_begin
changelog_end

* More stripLoc
2020-07-30 14:37:35 +00:00
Sofia Faro
f812aaf8e0
Add some tests for constant lifting. (#6519)
* add simplifier tests

* add some lambda constant lifting tests

changelog_begin
changelog_end

* update copyright

* clarify that the subexpression is a lambda

* Explicit export list in tests module

* don't use lambda in test names :-(
2020-06-29 17:25:38 +01:00
Sofia Faro
4d698fc5ed
constant lifting: adjust what gets lifted (#6430)
* Adjust what gets lifted

* dont lift typerep

changelog_begin
changelog_end
2020-06-19 17:09:52 +01:00
Sofia Faro
f5613785e0
Constant lifting transformation in the LF simplifier. (#6101)
* First draft of constant lifting

changelog_begin
changelog_end

* refactoring

* doing stuff

* run simplifier on template exprs

* remove merge artifact

* Fix ExerciseWithoutActors

* add comments

* fix trace order test

* prefix generated val names with their provenance

* Verification tool bugfix

During the value collection phase, when encountering a record projection on a (yet) undefined value, stop searching this branch instead of throwing an error.

* Bump pattern-match-perf memory limit with cocreature`s blessing

* bump again

* Filter generated identifiers from daml script test runner

changelog_begin
changelog_end

* Fix party literals

* Remove inlineClosedExpr for now.

* Improve comments

* Reset script test locations

* Unhashmap

* disable daml-lf-verify quickstart tests for now

Co-authored-by: Gert-Jan Bottu <gertjan.bottu@kuleuven.be>
Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
2020-06-18 17:36:28 +00:00
Martin Huschenbett
79e1f9d105
damlc: Run simplifier on templates as well (#6286)
* damlc: Run simplifier on templates as well

Currently, the simplifier only runs on top-level value definitions.
However, there's no good reason for not running it on all expressions
within templates as well.

This does not significantly improve the `CollectAuthority` benchmark,
but there's not much code in the templates.

CHANGELOG_BEGIN
CHANGELOG_END

* Verification tool bugfix in variable projection and substitution with… (#6344)

* Verification tool bugfix in variable projection and substitution within let expressions

* Remove redundant substitution ; apply feedback Martin

Co-authored-by: Gert-Jan Bottu <gertjanbottu@hotmail.com>
2020-06-15 11:24:25 +00:00
Martin Huschenbett
d75afebb8a
damlc: Avoid immediately invoked closures (#6274)
* damlc: Avoid immediately invoked closures

We add rules to the simplifier which rewrite expressions of the form
```
(\x1 ... xn -> E) A1 ... An
```
into
```
let x1 = A1 in ... let xn = An in E
```
provided that `xi` is not free in `Aj` for any `i < j`.

In cases where `E` is _not_ a lambda, this rewriting is beneficial
since it removes a costly closure allocation and the immediate entering
of the closure. If `E` is a closure itself, this rewriting is not
detrimental since the only difference it makes is that the values for
`A1, ..., An` end up in the list of captured variables rather than in
the list of already applied variables.

Even though users might not write expressions like the one we're
simplifying here themselves, various desugarings produce them
nevertheless. A common pattern is to define multiple auxiliary
functions that a only used once in a where cluase. For instance, with
the help these new rewriting rules the function
```haskell
f: Int -> Int -> Int
f x y = g (h x) y
  where
    g x y = x+y
    h x = 2*x
```
gets translated to
```
def f : Int64 -> Int64 -> Int64 =
  \(x : Int64) (y : Int64).
    let x2 : Int64 =
          let x2 : Int64 = x
          in MUL_INT64 2 x2
        y2 : Int64 = y
    in ADD_INT64 x2 y2
```
Without the simplification, `g` and `h` would each allocate a closure:
```
def f : Int64 -> Int64 -> Int64 =
  \(x : Int64) (y : Int64).
    (\(x2 : Int64) (y2 : Int64). ADD_INT64 x2 y2)
      ((\(x2 : Int64). MUL_INT64 2 x2) x)
      y
```

The `collect-authority` benchmarck is sped up by 1.03x by this change.
This is not a huge improvement but the change is simple enough to
merge it nevertheless.

CHANGELOG_BEGIN
CHANGELOG_END

* Let code speak not comments

CHANGELOG_BEGIN
CHANGELOG_END

* Improve explanations

CHANGELOG_BEGIN
CHANGELOG_END
2020-06-09 18:07:33 +00:00
Sofia Faro
73d58f3fa3
Run simplifier in topological order. (#6013)
* Run simplifier in topological order.

changelog_begin
changelog_end

* Remove bang pattern
2020-05-19 14:16:52 +00:00
Sofia Faro
1bd117bcec
Inline typeclass projections. (#5759)
* Inline typeclasses and apply projections.

This draft PR:

* adds a Subst module for substitution within LF expressions.
  This implementation piggybacks on the existing type
  substition. But there are not enough tests yet.
* passes World data into the simplifier, in order to have
  have the ability to inline functions (selectively)
* inlines typeclass dictionaries and projection functions
* beta reduces type lambdas (which are just ignored by
  speedy afaik)
* beta reduces lambdas that are passed units or dictionaries
* runs the simplifier twice so it has a change to
  perform the inlining, reduction, AND projection
  -- this is probably avoidable by sequencing the
  simplifier steps in a specific order, but running
  the simplifier twice is simple enough for now.
* together, these fix #5748 (see result on a toy module)

TODO:

* add lots of tests for Subst
* run this on a benchmark to see how big of a difference it makes.
* reduce the jankiness of running the simplifier twice.

Results:

DAML input:

```
module Main where

hello : Int
hello = 10 + 30
```

Original DAML-LF output:

```
module Main where
    @location(7:0-7:5)
    def hello : Int64 =
      a284919a95c4a515cd1efac0d89be302d0e9d61e692a2176128c871ad8067e36:GHC.Num:+
        @Int64
        a284919a95c4a515cd1efac0d89be302d0e9d61e692a2176128c871ad8067e36:GHC.Num:$fAdditiveInt
        10
        30
```

Current DAML-LF output:

```
 module Main where
    @location(7:0-7:5)
    def hello : Int64 = ADD_INT64 10 30
```

changelog_begin
changelog_end

* Update copyright header

* Lint

* More direct typeclass simplification

* extendWorldSelf + getTypeClassDictionary

* Fix visual

* Fix visual comment

* Disable cross-module inlining for incremental builds

* Cleanup subst/freevars.

* copyright header

* Alpha equivalence for LF expressions.

* copyright header

* lots of tests

* fix comment

* Apply review suggestions
2020-05-11 16:48:27 +00:00
Remy
560525b80a
DAML-LF: LF type checkers reject repeated variables in pattern (#5894)
CHANGELOG_BEGIN
CHANGELOG_END
2020-05-07 20:17:52 +02:00
Martin Huschenbett
ccfb17c91b
Rename daml codegen ts to daml codegen js (#5409)
I've completely removed the possibility to call `daml codegen ts`. I'm
happy to add in back in a followup PR once I've seen that all our tests
pass without it existing.

CHANGELOG_BEGIN
CHANGELOG_END
2020-04-03 14:54:46 +00:00
Gary Verhaegen
1872c668a5
replace DAML Authors with DA in copyright headers (#5228)
Change requested by Manoj.

CHANGELOG_BEGIN
CHANGELOG_END
2020-03-27 01:26:10 +01:00
Moritz Kiefer
17d82bf076
Make name collision check more strict (#5219)
* Make name collision check more strict

This PR extends the name collision check to catch collisions between
A:B (type B in module A) and module A.B.C. For now this is just a
warning and not an error. Once we turn it into an error, we also need
to add this to the Scala collision checker.

There is a fair bit of plumbing required to make warnings work but on
the plus side we get multiple errors at once now instead of erroring
out on the first one.

changelog_begin

- [DAML Compiler] The name collision check has been extended to also
  count the case as a collision where you have a type B in module A and a module
  A.B.C (but no module A.B). This is a warning in this SDK release but
  will become an error in a future release. The typescript codegen is
  not usable on packages that don’t uphold this restriction.

changelog_end

* Address review comments
2020-03-26 19:24:34 +01:00
Remy
c76e0bc1e0
DAML-LF add support for generic comparison in archive (#4983)
* DAML-LF: add generic comparison to archive
2020-03-13 20:13:13 +01:00
nickchapman-da
b8124a993f
damlc validate-dar (#4654)
changelog_begin
changelog_end
2020-02-27 14:26:14 +00:00
associahedron
159d828040
daml-dependencies: Use a safer safeToReexport (#4353)
* Use a safer safeToReexport

This is much safer than the approximation from last time. The only downside is
introducing a dependency between data dependencies and our type checker,
but that seems safer than having two versions of `expandTypeSynonyms`
floating around (and perhaps this dependency is something we would end
up adding anyway).

changelog_begin
changelog_end

* Add own package to extPackages.

* Use mkTForalls

* simplify mkTForalls
2020-02-03 19:11:11 +00:00
nickchapman-da
73978cd212
check for and reject cyclic type synonym definitions (#4026)
* CHANGELOG_BEGIN
check for and reject cyclic type synonym definitions
CHANGELOG_END

* mark 2x comments as TODO
2020-01-13 17:32:55 +00:00
nickchapman-da
006aa9b608
Type checking DAML-LF type synonyms (#3959)
* CHANGELOG_BEGIN
Type-check type synonyms.
CHANGELOG_END

* placate HLint

* comments

* Add an example that requires the check in kindOf

* check types containing syn-apps are well formed even when there is no expression of that type

* show type mismatch error after synonyms are expanded

* typeOf calls expandTypeSynonyms; track vars bound by TForall during expansion

* test interaction of syn-expansion and free-vars; add one bigger testcase

* extend bigger example with pointed typeclass, having functor as a super class

Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
2020-01-10 17:51:51 +00:00
Gary Verhaegen
878429e3bf
update copyright notices to 2020 (#3939)
copyright update 2020

* update template
* run script: `dade-copyright-headers update .`
* update script
* manual adjustments
* exclude frozen proto files from further header checks (by adding NO_AUTO_COPYRIGHT files)
2020-01-02 21:21:13 +01:00
nickchapman-da
1369351f70
separate type-synonyms from type-constructors (#3829)
* separate type-synonyms from type-constructors in DAML-LF .proto and Haskell AST

* comments
2019-12-16 11:52:28 +00:00
associahedron
4fe8cbff6e Run a package-wide name collision check when building a DAR. (#3827)
* Perform full package name collision check

* Comment on the ascendants thing

* Fix comment
2019-12-12 13:27:22 +00:00
associahedron
76531c93bf Expose generic equality in compiler (#3815) 2019-12-11 12:15:52 +00:00
associahedron
398a1237ca Perform name collision check against other names in package. (#3770)
* Full package name collision check

* Handle type synonyms appropriately

* Better comment

* Make isAscendant case-insensitive

* Document isAscendant and explain case-insensitivity

* Add a package-wide name collision test.
2019-12-09 16:36:55 +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
nickchapman-da
d15b0c7538
Add support for type-synonyms in DAML-LF .proto and Haskell AST (#3703)
* Add support for type-synonyms in DAML-LF .proto and Haskell AST

* address review comments
2019-12-03 14:51:02 +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
associahedron
87de36a7fe Add GenMap support in the compiler. (#3437)
* Add GenMap support in the compiler.

* Add GenMap ticket number in Upgrade.hs
2019-11-13 13:05:53 +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
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
Andreas Herrmann
a49c6469c7 Implement templateTypeRep in DAML (#3174)
* Improve comment

https://github.com/digital-asset/daml/pull/3118#discussion_r332894977

* Implement templateTypeRep in DAML

* TemplateTypeRep tests: use === and =/=

https://github.com/digital-asset/daml/pull/3174#discussion_r334775937

* Switch to bintray ghc-lib 20191015
2019-10-15 10:08:41 +00:00
associahedron
172996e4db Restrict type-level nats to [0,37]. (#3139)
* Restrict type-level nats to [0,37]

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

Co-Authored-By: Martin Huschenbett <martin.huschenbett@posteo.me>
2019-10-10 12:20:24 +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
5266b042b2 Implement ToTextTemplateId in proto (#3118) 2019-10-07 14:56:52 +00:00
associahedron
e4956ce4da
Forbid polymorphic Numeric literals. (#3085)
* Remove polymorphic literals from library

* Add BECastNumeric and BEShiftNumeric in DAML-LF AST.

* Update rest

* Copyright header

* Remove polymorphic literals from LF conversion.

* Update tests

* Add test for forbidden polymorphic literals

* Add newline in DA.Numeric

* use MulNumeric instead of CastNumeric in DA.Internal.Prelude
2019-10-02 16:01:13 +01:00
associahedron
db04b57f3e Name collision checking within a module. (#2981)
* Implement name collision check

* Better error messages

* Update copyright header

* Make the map strict

* Update collision test
2019-09-23 17:17:38 +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
Andreas Herrmann
ed39800a9f Rename hazel_deps to hackage_deps (#2789)
* hazel_deps --> hackage_deps

Mechanical change:

```
sed -i 's/hazel_deps/hackage_deps/g' $(ag -l hazel_deps)
```

* Hazel dependencies --> Hackage dependencies
2019-09-06 09:01:09 +00:00
associahedron
ea9d9cb02e Convert Decimal type, literals, and primitives to Numeric when feature is available. (#2723)
* Add missing alpha-equivalence case.

* Type-level nat is not serializable.

* Convert decimal primitives as numeric primitives if feature is available.

* Convert decimal literals to numeric if available.

* Better approach to decimal primitves.

* Fixing BEDecimalFromText

* Add issue number

* Set Numeric feature at v1.7
2019-09-02 17:10:26 +00:00
associahedron
0eed4afb3f Add Numeric literals in daml-lf-ast and daml-lf-proto. (#2706)
* Add Numeric literals.

* Decode numeric literals

* Add tests and fix Read for s=0

* lint

* Copyright header

* Use numericMaxScale in Serializability check

* Fix comment!
2019-08-30 08:45:03 +00:00
associahedron
dce578bbea damlc: Add Numeric primitives and type-level nats. (#2670)
* Add Numeric primitives and type-level nats

* Statically enforce Numeric scale in serializability check
2019-08-28 12:30:33 +00:00
Martin Huschenbett
25d1e2ce63
Fix the safety of the empty map in the DAML-LF simplifier (#2679)
Currently, we use `Safe 1` as the safety of the `BEMapEmpty` primitive. This
is clearly wrong since `BEMapEmtpy` is not supposed to be applied to a value
(but only to a type). Thus, it must be `Safe 0`. This has not caused any
problems in the past because the type checker would have caught any
application of `BEMapEmpty` to a value.
2019-08-28 13:20:31 +02:00
Gary Verhaegen
99ea93168d
update copyright notices (#2499) 2019-08-13 17:23:03 +01:00
nickchapman-da
b30228ab95
{-# LANGUAGE OverloadedStrings #-} is now on by default (#2270) 2019-07-24 08:09:26 +01:00
Martin Huschenbett
d5d08707c2 Drop support for DAML-LF 1.5 from damlc (#2161) 2019-07-16 13:52:29 +00:00
Moritz Kiefer
cd69b6f553
Cache rewrites of PRSelf references (#2028)
Previously we rewrote references to `PRSelf` to `PRImport` references
every time we call `initWorld`. However, we call `initWorld` quite
often (e.g. every time we run a scenario) while the packages that need
to be rewritten stay constant. Since rewriting the package references
requires traversing the whole package, this can be quite expensive.

This PR moves the rewriting of package references out of `initWorld`
and caches it as part of `GeneratePackageMap`.

On a large project where I tested this, this caused a drop in the
runtime of `daml test` from 250s to 200s. In the IDE this can also
make a pretty big difference since we call this everytime we run a
scenario which we do on every file change.
2019-07-08 08:48:09 +02:00