Commit Graph

129 Commits

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