Commit Graph

187 Commits

Author SHA1 Message Date
Moisés Ackerman
0d1ef10472
Retroactive Implements - Scala side (#14130)
* Add CoImplements to daml-lf AST

* Add AstSpec case for duplicate co-implements in interface

* Add placeholders for CoImplements in daml-lf validation

* Handle CoImplements in daml-lf iterators

* Handle CoImplements in daml-lf scala decoder

* Test DefInterface components in DecodeV1Spec

* Handle CoImplements in daml-lf (testing) parser

* Handle CoImplements in daml-lf (testing) encoder

changelog_begin
changelog_end
2022-06-23 17:13:38 +00:00
Remy
ae8f50dbb8
LF: drop inheretedChoices from Implements (#14068)
part of #13653

CHANGELOG_BEGIN
CHANGELOG_END
2022-06-02 18:48:54 +00:00
Remy
62877ab78b
LF: Cleanup Fetches (#13804)
- Rename fetch to fetch_template
- Rename misnamed fetch_by_interface to fetch_interface
- Drop dead fetch_by_interface

CHANGELOG_BEGIN
CHANGELOG_END
2022-05-30 18:55:41 +02:00
Remy
d3264236ba
Interface: drop collision check between inherited choice name (#13939)
CHANGELOG_BEGIN
CHANGELOG_END
2022-05-24 17:53:18 +02:00
Remy
ea0d101913
Interface: Rename fixedChoice to choice (#13883)
CHANGELOG_BEGIN
CHANGELOG_END
2022-05-17 12:03:53 +02:00
nickchapman-da
0c368aafdc
always typecheck the rhs of let expressions (#13779)
* always typecheck the rhs of let expressions

changelog_begin
changelog_end

* update security evidence

* test for new parer syntax: let _ = ...
2022-05-03 15:16:11 +00:00
nickchapman-da
804a399115
Tests for stack-safety of type-checking (#13729)
* Tests for stack-safety of type-checking

changelog_begin
changelog_end

* remove testcases app[123]of3

* typecheck returns Option[ValidationError]

* remove LARGE testset, which only has non-overflow because of ill-typed examples causing early exit

* ensure all test examples are well-typed

* fix TODO issue links
2022-05-03 08:59:12 +01:00
Nicu Reut
a792de39a5
Update scalafmt to 3.5.1. (#13584)
CHANGELOG_BEGIN
CHANGELOG_END
2022-04-28 09:57:04 +00:00
nickchapman-da
30f83bae46
Small cleanup to the bazel testing setup for daml-lf/interpreter and daml-lf/validation (#13716)
changelog_begin
changelog_end
2022-04-27 13:27:17 +01:00
nickchapman-da
aeda7159cf
clarify entry points to type checking code (#13697)
changelog_begin
changelog_end
2022-04-26 15:34:38 +01:00
Remy
99a2f4384d
LF: Factorize language.Reference with validation.Context (#13608)
CHANGELOG_BEGIN
CHANGELOG_END
2022-04-20 11:57:16 +02:00
Remy
c048966d91
LF: Slightly reduce stack consumption of the type cheker. (#13513)
Workaroung to solve flakyness of
//daml-lf/tests:test-scenario-stable-many-field until #13410 is fixed.

CHANGELOG_BEGIN
CHANGELOG_END
2022-04-06 13:10:18 +01:00
Moisés Ackerman
f59d1cd0b4
Convert experimental primitive TYPEREP_TYCON_NAME into proper LF builtin (#13465)
* Convert experimental primitive TYPEREP_TYCON_NAME into proper LF builtin

* Add entry for TYPEREP_TYCON_NAME in daml-lf spec

* disable quickcheck test in DA.Test.Packaging

changelog_begin
changelog_end
2022-03-31 14:35:46 +02:00
Moisés Ackerman
b47fa3ba92
interface conversion primitives test cases (#13416)
* Add LF ParsersSpec cases for conversion primitives

* Add LF TypingSpec cases for conversion primitives

* Add LF DecodeV1Spec cases for conversion primitives

* Add LF EncodeV1Spec cases for conversion primitives

* update security-evidence.md

* Add missing cases in daml-lf encoder

* Add missing cases in EncodeV1Spec

* Add InterfaceMod in DamlLfEncoderTest

changelog_begin
changelog_end
2022-03-25 16:08:31 +00:00
Moisés Ackerman
f9f1611d46
Unsafe interface conversion primitives (#13391)
* Add unsafeFromInterface method to HasFromInterface class

* Use unsafeFromInterface instead of fromInterface + experimental primitive

* Drop THROW_WRONGLY_TYPED_CONTRACT experimental primitive

* Add UnsafeFrom{,Required}Interface LF primitives

* Add convertPrim cases for UnsafeFrom{,Required}Interface

* Add InterfaceGuarded tests for WronglyTypedContract cases

changelog_begin
changelog_end

Co-authored-by: Sofia Faro <sofia.faro@digitalasset.com>
2022-03-25 10:07:14 +00:00
Robin Krom
f7a73c5a87
ifaces: more tests for requires (#13309)
This adds tests for circular and non-closed requires in interfaces on
the daml-lf side.

CHANGELOG_BEGIN
CHANGELOG_END
2022-03-16 18:15:26 +01:00
Robin Krom
93c53da3df
requires checks (#13300)
* interfaces: tests for requires typing

We add tests for the correct typing of the interface requires field.

CHANGELOG_BEGIN
CHANGELOG_END

* security evidence
2022-03-16 12:05:30 +00:00
Sofia Faro
1feb4d25eb
Drop typerep argument from ExerciseInterface. (#13284)
* ifaces: Remove typerep arg from UExerciseInterface

changelog_begin
changelog_end

* Drop typerep argument in protobuf and haskell ast

changelog_begin
changelog_end

* scalafmt

* fix ExprParser

* fix PhaseOneTest

* fix validation test

* update evidencing security
2022-03-15 13:53:06 +00:00
Sofia Faro
b2d6f8014c
LF: Use template parameter (this) in method bodies. (#13142)
* Use `this` param in method bodies in LF.

Instead of having method bodies be functions from the template, have them reuse the existing template parameter (usually `this`).

Fixes #13123

changelog_begin
changelog_end

* fix validation-test
2022-03-03 13:50:59 +00:00
Sofia Faro
db100c131a
Prevent iface choice & method name collisions. (#13075)
* Prevent iface choice & method name collisions.

This PR adds interface choices and methods to the name collision checker.

changelog_begin
changelog_end

* check the names from interfaces

* add error

* implement name collision check in scala side

* scalafmt
2022-02-28 13:21:41 +00:00
Sofia Faro
b842b53ff4
Delete vestigial InterfaceChoice from AST (#13017)
* Delete vestigial InterfaceChoice from AST

This is a leftover from when interfaces had virtual choices.

changelog_begin
changelog_end

* delete more
2022-02-22 13:59:04 +00:00
Moisés Ackerman
7f6e1f08d4
Interface primitives continued (#12795)
* Extend daml lf parser to support new interface primitives

* Test parser on new interface primitives

* Add daml lf decoding test cases for new interface primitives

* Add TypingSpec test cases for new interface primitives

* add SBuiltinTest test cases for interface primitives

changelog_begin
changelog_end
2022-02-08 16:02:20 +01:00
Moisés Ackerman
3ce272b9f0
Replace experimental interface primitives with proper LF primitives (#12678)
* Add new primitives to proto spec

* implement E{Signatory,Observer}Interface in terms of EResolveVirtual{Signatory,Observer}

* define EToTypeRep primitive in terms of EToTypeRep Expr

* Remove experimental primitives TO_TYPE_REP and RESOLVE_VIRTUAL_{SIGNATORY,OBSERVER} 

changelog_begin
changelog_end
2022-02-03 13:36:45 +00:00
Moisés Ackerman
366cd897fc
Add new interface serializability tests (#12666)
changelog_begin
changelog_end
2022-01-31 14:31:29 +01:00
Moisés Ackerman
7567cf50aa
Add scala serializability checks for interfaces (#12631)
* interfaces should not be implicitly serializable

* Add scala serializability check for interface choices

* Add scala serializability check for interface payloads

changelog_begin
changelog_end
2022-01-28 09:44:02 +01:00
Stefano Baghino
f1cd4b1c7c
Remove dependencies on compatibility libraries (#12548)
Continues the work started in https://github.com/digital-asset/daml/pull/12543

These libraries were only needed to transition from Scala 2.12 to 2.13
and are no longer useful as all the necessary items are now available
in Scala 2.13.

changelog_begin
changelog_end
2022-01-24 18:04:07 +00:00
Stefano Baghino
aec3390904
Replace silencer plugin with built-in warning configuration (#12543)
Since Scala 2.13.2, Scala introduced built-in support to
manage warnings in a more granular fashion, thus making
the silencer plugin we are currently using no longer
strictly useful. Removing compiler plugins also removes
friction from migrating to Scala 3 in the future. As a
cherry on top, the built-in warning configuration also
allows to check whether a `@nowarn` actually does
anything, allowing us to proactively remove unused
warnings should the need arise.

[Here][1] is s a blog post by the Scala team about it.

Warnings have been either solved or preserved if useful,
trying to minimize the scope (keeping it at the single
expression scope if possible). In particular, all
remaining usages of the Scala Collection API compatibility
module have been removed.

Using the silencer plugin also apparently hid a few
remaining usages of compatibility libraries that were used
as part of the transition from Scala 2.12 to Scala 2.13
that are no longer needed. Removing those warnings
highlighted those.

changelog_begin
changelog_end

[1]: https://www.scala-lang.org/2021/01/12/configuring-and-suppressing-warnings.html
2022-01-24 15:01:35 +00:00
Remy
30300fdac6
LF: Revert #7742 (#12354)
Following #12338 which merges the two implementations of the
structural record projection introduced by #7740, this PR merges the two
implementations of the structural record introduced by #7742.

However, this PR does not try to cache the field index as it is done

1- unlike what it is suggested by commit message of #7742, the update
   has a linear complexity anyway, as it has to copy the whole struct.

2- the compiler does not produce any structural record updates

As result the PR is basically a revert of #7742.

CHANGELOG_BEGIN
CHANGELOG_END
2022-01-11 15:53:10 +00:00
Remy
7ec55d7f33
LF: Cache field index inside structural record projection builtin (#12338)
Currently we have two implementations for the projection of structural
record.

1- The first implementation takes as parameter the index of the
projected field and is therefore constant. This implementations is
used when the type checking is enable, as the index cannot be directly
inferred from the AST and must hence be filled in by the DAML-LF type
checker.

2- The second implementation takes as parameter the name of the
projected field and is therefore logarithmic as the field must be
lookup by binary search at each call. This version is used when the
type checking is disable as the index cannot be inferred without type
inference.

In this PR, we modify the second implementation so it cache the index
at the first call, hence avoiding the recomputation during further
calls.  In this way we reach an amortized constant complexity.  The
first implementation is decommissioned in benefit of the second one.

The advantages of this approach are:

- We have a unique implementation of the projection, so the behavior
  of a program is the same whenever the type checking is on or off.

- The AST for structural projection is immutable.

Benchmarks show no performance differences when the type checking is on.

Based on an idea by @sofiafaro-da.

CHANGELOG_BEGIN
CHANGELOG_END
2022-01-11 13:03:21 +01:00
Gary Verhaegen
d2e2c21684
update copyright headers (#12240)
New year, new copyright, new expected unknown issues with various files
that won't be covered by the script and/or will be but shouldn't change.

I'll do the details on Jan 1, but would appreciate this being
preapproved so I can actually get it merged by then.

CHANGELOG_BEGIN
CHANGELOG_END
2022-01-03 16:36:51 +00:00
Remy
1989a2def9
LF: Check non circularity of requires Interface field
CHANGELOG_BEGIN
CHANGELOG_END
2021-12-10 12:35:54 +00:00
Remy
a4fa1311ca
LF: Prevent circular and non-closed interface requirements (#12070)
CHANGELOG_BEGIN
CHANGELOG_END
2021-12-09 18:13:55 +01:00
Remy
c53cf758da
LF: Add EToRequiredInterface and EFromRequiredInterface to Scala Ast. (#12042)
Part of #11978. Adds typechecking for those primitives.

CHANGELOG_BEGIN
CHANGELOG_END
2021-12-08 11:09:10 +00:00
Remy
9d7eb07745
LF: Add "requires" field to Scala Ast. (#12028)
Part of #11978. Adds typechecking for this field on the interface side,
and enforces that any template that implements A must implement B if A requires B.

CHANGELOG_BEGIN
CHANGELOG_END
2021-12-07 17:53:40 +00:00
Moritz Kiefer
8179c73763
Drop support for Daml-LF party literals from the Scala side (#11922)
* Drop support for Daml-LF party literals from the Scala side

This PR enforces that forbidPartyLiterals is always `true` and drops
the corresponding literals from the AST. Haskell side is in #11930

fixes #11581

changelog_begin
changelog_end

* Update daml-lf/interpreter/src/test/scala/com/digitalasset/daml/lf/speedy/ComparisonSBuiltinTest.scala

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

* Revert "Update daml-lf/interpreter/src/test/scala/com/digitalasset/daml/lf/speedy/ComparisonSBuiltinTest.scala"

This reverts commit 55e542ce4e3a7fd15544ee703de3277ffc309b17.

Co-authored-by: Remy <remy.haemmerle@daml.com>
2021-12-01 10:37:42 +00:00
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
Remy
58e69ade1a
LF: replace "dev" LF version by "1.dev" in bazel files (#11894)
the more consistent, as asked by Moritz in review of #11820

CHANGELOG_BEGIN
CHANGELOG_END
2021-11-26 12:23:17 +00:00
Remy
86da6e8eef
LF: Test scala interface type checking (#11833)
CHANGELOG_BEGIN
CHANGELOG_END
2021-11-24 15:58:45 +00:00
Sofia Faro
5c12d757f4
Add a guard when exercising by interface. (#11836)
* Add a guard when exercising by interface.

This fixes part of #11703, when exercising an inherited choice by
interface and you know the template id, via the command preprocessor.

It does this by inserting a "guard" in between the interface fetch and
the exercise body. The guard is a function Interface -> Bool, which
is general enough to check the template id, without complicating too
much in speedy. And can be generalized in the future to check more,
like signatories, etc.

I added the guard as an optional argument to UExerciseByInterface.
This isn't hooked up to the protobuf AST yet (or Haskell side for
that matter) -- but I'll do it in the next PR! For now you can invoke
the guarded exercise via the command preprocessor, so I can enable the
approprate engine tests. (There's still some failing fetch tests left,
but I decided to leave this for later. Fetch can be a lot simpler than
guarded choices, since you always add a fetch node. No need for fancy
continuations.)

changelog_begin
changelog_end

* scalafmt

* Feedback and fix matches

* Update comments, we are always going to abort the transaction

* Raise WronglyTypedContract in SBGuardTemplateId.

* rebase and fix parser

* restore ANF

* scalafmt
2021-11-24 14:22:40 +00:00
Remy
f33486154f
LF: Simplify LF Syntax (#11795)
- Do not wrapped choices in `choices { ... }`
- use sytematic `;` after choice component instead of ',`

CHANGELOG_BEGIN
CHANGELOG_END
2021-11-19 17:23:36 +01:00
Remy
cbe9c922ba
LF: Clean up Ast (#11786)
- rename non-default builders `apply` to `build`
  * avoid confusing both
  * make explicit the build can crash

- make interfaceId and templateId fields consitent

- use when possible named arguments

- check for non-repetition of inherited choices

CHANGELOG_BEGIN
CHANGELOG_END
2021-11-19 15:40:28 +01: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
Moritz Kiefer
fa7663148a
Drop 2.12 versioned_scala_deps (#11748)
I’ve kept the infrastructure for versioned_scala_deps around because
I’m optimistic and hope that eventually we’ll do another Scala upgrade.

changelog_begin
changelog_end
2021-11-17 22:13:08 +00: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
Remy
3b61a1b748
LF: allow exercise command by template for inherited choice. (#11584)
CHANGELOG_BEGIN
CHANGELOG_END
2021-11-09 13:10:06 +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
Sofia Faro
776790e386
Add choice collisions in scala name collision checker (#11528)
* Add choice collisions in scala name collision chk

This brings it in line with the LF spec.
This PR also adds collisions for inherited (interface) choices.
Closes #11137.

changelog_begin
changelog_end

* scalafmt

* Apply suggestions from code review

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

Co-authored-by: Remy <remy.haemmerle@daml.com>
2021-11-03 17:01:34 +00: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
48afb7b5ea
interface: Add inherited choice names in scala AST (#11503)
Also checks that they're right. There's no collision checking yet.

Part of #11137.

changelog_begin
changelog_end
2021-11-02 14:35:37 +00:00
Robin Krom
b98a3ade29
interfaces: precondition, scala ast, decoder/encoder (#11452)
* interfaces: precondition, scala ast, decoder/encoder

This adds the interface precondition to the scala Daml LF AST, plus
decoder/encoder and the typechecker.

CHANGELOG_BEGIN
CHANGELOG_END

* Update daml-lf/archive/src/main/scala/com/digitalasset/daml/lf/archive/DecodeV1.scala

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

* format

Co-authored-by: Remy <remy.haemmerle@daml.com>
2021-10-29 10:10:55 +00:00