Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate 'controller ... can' syntax #11363

Merged
merged 4 commits into from
Dec 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bazel-haskell-deps.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ load("@os_info//:os_info.bzl", "is_linux", "is_windows")
load("@dadew//:dadew.bzl", "dadew_tool_home")
load("@rules_haskell//haskell:cabal.bzl", "stack_snapshot")

GHC_LIB_REV = "ded0a9e82e5d4bdf47e568ee83f26959"
GHC_LIB_SHA256 = "cee47f49c8f26feba53d3d90bc6d306f9a832b199096e06c3cadc1b021792269"
GHC_LIB_REV = "87dda21236dc010afa5cf075d413335d"
GHC_LIB_SHA256 = "8d1e90cd6af1641ca13198e216fd38ff8bfcf69c4cfd5294cdd7589fcf7d2640"
GHC_LIB_VERSION = "8.8.1"
GHC_LIB_PARSER_REV = "ded0a9e82e5d4bdf47e568ee83f26959"
GHC_LIB_PARSER_SHA256 = "869452c0158186928eb20540818eec69d6d76c1f7cf8a96de98be4150bebdd66"
GHC_LIB_PARSER_REV = "87dda21236dc010afa5cf075d413335d"
GHC_LIB_PARSER_SHA256 = "a7e1e79956a5b93db5ae61150063a3e44256014bab5722381b9639cd6ee5708d"
GHC_LIB_PARSER_VERSION = "8.8.1"
GHCIDE_REV = "e04b5386b3741b839eb5c3d2a2586fd2aa97229c"
GHCIDE_SHA256 = "1d27926e0ad3c2a9536f23b454875a385ecc766ae68ce48a0ec88d0867884b46"
Expand Down
2 changes: 1 addition & 1 deletion ci/da-ghc-lib/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
variables:
ghc-lib-sha: '362d4f38a7ac10521393de9b7ad942a77a2605be'
base-sha: '9c787d4d24f2b515934c8503ee2bbd7cfac4da20'
patches: '8d26bb64b7ea02d2a54f22cc3296b7245458821f 833ca63be2ab14871874ccb6974921e8952802e9'
patches: '1a7dbeff4cec600d0d04aa2ae47df649a947ce62 833ca63be2ab14871874ccb6974921e8952802e9'
flavor: 'da-ghc-8.8.1'
steps:
- checkout: self
Expand Down
14 changes: 7 additions & 7 deletions compatibility/sandbox-migration/daml/Divulgence.daml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ template AssetDivulgence
assetOwner: Party
where
signatory divulgee
observer assetOwner

controller assetOwner can
nonconsuming Divulge: ()
with
divulgedAsset: ContractId Asset
do
fetch divulgedAsset
return ()
nonconsuming choice Divulge: () with
divulgedAsset: ContractId Asset
controller assetOwner
do
fetch divulgedAsset
return ()
2 changes: 2 additions & 0 deletions compiler/daml-extension/syntaxes/TestGrammar.daml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ template FeatureSuggestion
assert $ elem sponsor founders -- assert -> source.daml
create FeatureAssignment with employee, description, sponsor -- create -> source.daml

-- deprecated syntax: 'controller ... can' will be removed in a future version of Daml.
controller employee can
nonconsuming DoNothing : ()
do
return ()

-- deprecated syntax: 'controller ... can' will be removed in a future version of Daml.
controller employee can
Revoke : ()
do pure ()
4 changes: 4 additions & 0 deletions compiler/damlc/tests/daml-test-files/ChoiceSyntaxes.daml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

-- Check that all syntaxes for defining choices can be parsed.

{-# OPTIONS_GHC -Wno-controller-can #-}

module ChoiceSyntaxes where

template T with
Expand All @@ -21,6 +23,8 @@ template T with
do
pure ()

-- deprecated syntax: 'controller ... can' will be removed in a future version of Daml.
-- This file tests the various options for defining choices, so we keep it until it is removed.
controller p can
C3 : () with
x : ()
Expand Down
26 changes: 14 additions & 12 deletions compiler/damlc/tests/daml-test-files/ConsumedContractKey.daml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-- @ERROR range=23:1-23:32; no contract with that key was found
-- @ERROR range=33:1-33:29; consumed in same transaction
-- @ERROR range=25:1-25:32; no contract with that key was found
-- @ERROR range=35:1-35:29; consumed in same transaction
module ConsumedContractKey where

template Foo
Expand All @@ -9,16 +9,18 @@ template Foo
signatory signer
key signer : Party
maintainer key
controller signer can
FetchKey : Foo
do
snd <$> fetchByKey @Foo signer
LookupKey : ()
do
None <- lookupByKey @Foo signer
pure ()
Fetch : Foo
do fetch self
choice FetchKey : Foo
controller signer
do
snd <$> fetchByKey @Foo signer
choice LookupKey : ()
controller signer
do
None <- lookupByKey @Foo signer
pure ()
choice Fetch : Foo
controller signer
do fetch self

testFetchKeyFromConsumingChoice = do
alice <- getParty "Alice"
Expand Down
17 changes: 17 additions & 0 deletions compiler/damlc/tests/daml-test-files/NoWarnControllerCan.daml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Copyright (c) 2021, Digital Asset (Switzerland) GmbH and/or its affiliates.
-- All rights reserved.

{-# OPTIONS_GHC -Wno-controller-can #-}

module NoWarnControllerCan where

template T with
p : Party
q : Party
where
signatory p

controller q can
nonconsuming Pass : ()
do
pure ()
8 changes: 7 additions & 1 deletion compiler/damlc/tests/daml-test-files/SemanticsEvalOrder.daml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
-- rule's name in the error message itself. If there are multiple tests for
-- the same rule, we use `R_1`, `R_2`, `R_3`, and so on. This is why there is
-- `evExpRecUpdErr1`, `evExpRecUpdErr2_1`, and `evExpRecUpdErr2_2`, for example.)

{-# OPTIONS_GHC -Wno-controller-can #-}

module SemanticsEvalOrder where

-- @ERROR EvTyAbsErasableErr OK
Expand Down Expand Up @@ -294,7 +297,7 @@ evUpdCreateErr1 = scenario do
create (T_EvUpdCreateErr1 p)
error "EvUpdCreateErr1 failed (4)"

-- @ERROR range=307:1-307:16; Template precondition violated
-- @ERROR range=310:1-310:16; Template precondition violated
template T_EvUpdCreateFail
with
p : Party
Expand Down Expand Up @@ -421,6 +424,9 @@ template T_ControllerCanAddsObserver
p : Party
where
signatory p
-- deprecated syntax: 'controller ... can' will be removed in a future version of Daml.
-- This tests that `controller X can` implicitly adds `X` as an observer, so we keep
-- it until it is removed.
controller (error @Party "controllerCanAddsObserver OK") can
C_ControllerCanAddsObserver: ()
do pure ()
Expand Down
17 changes: 17 additions & 0 deletions compiler/damlc/tests/daml-test-files/WarnControllerCan.daml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
-- Copyright (c) 2021, Digital Asset (Switzerland) GmbH and/or its affiliates.
-- All rights reserved.

-- @WARN range=14:5-17:18; The syntax 'controller ... can' is deprecated

module WarnControllerCan where

template T with
p : Party
q : Party
where
signatory p

controller q can
nonconsuming Pass : ()
do
pure ()
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ template Bar

key BarKey owner name : BarKey
maintainer key.p

controller owner can
Bar_SomeChoice: Bool
with

choice Bar_SomeChoice: Bool
with
aName: Text
do return True
controller owner
do return True
-- end snippet: template example
42 changes: 32 additions & 10 deletions docs/source/app-dev/bindings-java/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -273,23 +273,26 @@ Take a look at the Daml that specifies the contract model in the quickstart appl
#. Open :doc:`Daml Studio </daml/daml-studio>`, a Daml IDE based on VS Code, by running ``daml studio`` from the root of your project.
#. Using the explorer on the left, open ``daml/Iou.daml``.

The first two lines specify language version and module name:
The first line specifies the module name:

.. literalinclude:: quickstart/template-root/daml/Iou.daml
:language: daml
:lines: 4-5
:start-after: -- BEGIN_IOU_MODULE_NAME
:end-before: -- END_IOU_MODULE_NAME

Next, a template called `Iou` is declared together with its datatype. This template has five fields:

.. literalinclude:: quickstart/template-root/daml/Iou.daml
:language: daml
:lines: 9-15
:start-after: -- BEGIN_IOU_TEMPLATE_DATATYPE
:end-before: -- END_IOU_TEMPLATE_DATATYPE

Conditions for the creation of a contract are specified using the `ensure` and `signatory` keywords:

.. literalinclude:: quickstart/template-root/daml/Iou.daml
:language: daml
:lines: 17-19
:start-after: -- BEGIN_IOU_TEMPLATE_CONDITIONS
:end-before: -- END_IOU_TEMPLATE_CONDITIONS

In this case, there are two conditions:

Expand All @@ -304,15 +307,32 @@ Observers are specified using the ``observer`` keyword:

.. literalinclude:: quickstart/template-root/daml/Iou.daml
:language: daml
:lines: 21
:start-after: -- BEGIN_IOU_TEMPLATE_OBSERVERS
:end-before: -- END_IOU_TEMPLATE_OBSERVERS

Next, *rights* or *choices* are given to ``owner``:
Next, the *rights* or *choices* are defined, in this case with ``owner`` as the ``controller``:

.. literalinclude:: quickstart/template-root/daml/Iou.daml
:language: daml
:lines: 23, 52-55
:start-after: -- BEGIN_IOU_TEMPLATE_SPLIT
:end-before: -- END_IOU_TEMPLATE_SPLIT

``controller owner can`` starts the block. In this case, ``owner`` has the right to:
.. literalinclude:: quickstart/template-root/daml/Iou.daml
:language: daml
:start-after: -- BEGIN_IOU_TEMPLATE_MERGE
:end-before: -- END_IOU_TEMPLATE_MERGE

.. literalinclude:: quickstart/template-root/daml/Iou.daml
:language: daml
:start-after: -- BEGIN_IOU_TEMPLATE_TRANSFER
:end-before: -- END_IOU_TEMPLATE_TRANSFER

.. literalinclude:: quickstart/template-root/daml/Iou.daml
:language: daml
:start-after: -- BEGIN_IOU_TEMPLATE_OBSERVER_CHOICES
:end-before: -- END_IOU_TEMPLATE_OBSERVER_CHOICES

Thus, ``owner`` has the right to:

- split the Iou
- merge it with another one differing only on ``amount``
Expand All @@ -325,7 +345,8 @@ A more interesting choice is ``IouTrade_Accept``. To look at it, open ``IouTrade

.. literalinclude:: quickstart/template-root/daml/IouTrade.daml
:language: daml
:lines: 25-46
:start-after: -- BEGIN_IOU_COMPOSITE_CHOICE
:end-before: -- END_IOU_COMPOSITE_CHOICE

This choice uses the ``===`` operator from the :doc:`Daml Standard Library </daml/stdlib/index>` to check pre-conditions. The standard library is imported using ``import DA.Assert`` at the top of the module.

Expand All @@ -352,7 +373,8 @@ The following block, for example, issues an ``Iou`` and transfers it to Alice:

.. literalinclude:: quickstart/template-root/daml/Tests/Trade.daml
:language: daml
:lines: 19-27
:start-after: -- BEGIN_SCENARIO
:end-before: -- END_SCENARIO

Compare the scenario with the ``setup`` scenario in ``daml/Main.daml``. You will see that the scenario you used to initialize the sandbox is an initial segment of the ``trade_test`` scenario. The latter adds transactions to perform the trade you performed through Navigator, and a couple of transactions in which expectations are verified.

Expand Down
Loading