Skip to content

Commit

Permalink
Remove compiler support for controller..can choice syntax (#17362)
Browse files Browse the repository at this point in the history
* Update GHC_REV

* Remove 'controller..can' syntax in java codegen StakeholdersTest

* Remove 'controller..can' syntax in ChoiceSyntaxes daml-test-file

* Remove daml-test-files {,No}WarnControllerCan

* Remove 'controller..can' syntax in SemanticsEvalOrder{,RightToLeft} daml-test-files

* Update {Structure,Reference}.daml code snippets for docs.daml.com

* Remove 'controller..can' syntax in TestGrammar.daml

* changelog entry for 'controller..can' removal

* Update UNRELEASED.md

Co-authored-by: carrielaben-da <91496516+carrielaben-da@users.noreply.github.com>
  • Loading branch information
akrmn and carrielaben-da authored Sep 8, 2023
1 parent 74d7459 commit 1bee52e
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 186 deletions.
13 changes: 13 additions & 0 deletions UNRELEASED.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,19 @@ following warning will be shown during compilation or in the IDE:

For more information, see [Reference: Templates: Template-local Definitions (Deprecated)](https://docs.daml.com/2.8.0/daml/reference/templates.html#template-local-definitions-deprecated)

## Removal of deprecated 'controller..can' syntax

The 'controller..can' syntax for defining template choices, deprecated since
Daml 2.0, has now been completely removed. Projects that use this syntax are no
longer accepted. Those choices should instead be defined using 'choice-first'
syntax.

Note that, as a consequence, the warning flags `-Wcontroller-can` and
`-Wnocontroller-can` are not accepted anymore.

See [Deprecation of `controller`-first syntax: Migrating](https://docs.daml.com/2.7.0/daml/reference/choices.html#migrating)
for more information on how to adapt existing projects.

## What’s New
### Daml-script json support for --all
The daml-script binary runner has been refactored to be more consistent across using `--script-name` and `--all`.
Expand Down
2 changes: 1 addition & 1 deletion bazel_tools/ghc-lib/version.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ GHC_LIB_PATCHES = [
]

GHC_REPO_URL = "https://github.com/digital-asset/ghc"
GHC_REV = "760149aceaf1c870b122308e8af792c1c4546091"
GHC_REV = "6cea01bd8eec50722bffa9b3b1b9067653ee6123"
GHC_PATCHES = [
]

Expand Down
11 changes: 0 additions & 11 deletions compiler/daml-extension/syntaxes/TestGrammar.daml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,3 @@ template FeatureSuggestion
do
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 ()
14 changes: 0 additions & 14 deletions compiler/damlc/tests/daml-test-files/ChoiceSyntaxes.daml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

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

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

module ChoiceSyntaxes where

template T with
Expand All @@ -22,15 +20,3 @@ template T with
controller p
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 : ()
do
pure ()

C4 : ()
do
pure ()
17 changes: 0 additions & 17 deletions compiler/damlc/tests/daml-test-files/NoWarnControllerCan.daml

This file was deleted.

26 changes: 1 addition & 25 deletions compiler/damlc/tests/daml-test-files/SemanticsEvalOrder.daml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
-- 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 #-}
{-# LANGUAGE ApplicativeDo #-}

module SemanticsEvalOrder where
Expand Down Expand Up @@ -246,7 +245,7 @@ evUpdCreateErr1 = script do
createCmd (T_EvUpdCreateErr1 p)
abort "EvUpdCreateErr1 failed (4)"

-- @ERROR range=260:1-260:16; Template precondition violated
-- @ERROR range=259:1-259:16; Template precondition violated
template T_EvUpdCreateFail
with
p : Party
Expand Down Expand Up @@ -371,29 +370,6 @@ evUpdCreateWithKeyErr2 = script do
createCmd (T_EvUpdCreateWithKeyErr2 p)
abort "EvUpdCreateWithKeyErr2 failed"

-- | `controller P can ...` syntax adds `P` to the observers,
-- so if `P` causes an error, this is triggered on create,
-- instead of on exercise.
-- @ERROR controllerCanAddsObserver OK
template T_ControllerCanAddsObserver
with
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 ()

controllerCanAddsObserver : Script ()
controllerCanAddsObserver = script do
p <- allocateParty "Alice"
submit p do
createCmd (T_ControllerCanAddsObserver p)
abort "controllerCanAddsObserver failed"

-- | `choice ... controller P ...` doesn't add `P` as observer.
-- This test is here to contrast with the previous.
-- @ERROR choiceControllerDoesntAddObserver OK
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
-- 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 #-}
{-# LANGUAGE ApplicativeDo #-}

module SemanticsEvalOrderRightToLeft where
Expand Down Expand Up @@ -246,7 +245,7 @@ evUpdCreateErr1 = script do
createCmd (T_EvUpdCreateErr1 p)
abort "EvUpdCreateErr1 failed (4)"

-- @ERROR range=260:1-260:16; Template precondition violated
-- @ERROR range=259:1-259:16; Template precondition violated
template T_EvUpdCreateFail
with
p : Party
Expand Down Expand Up @@ -371,29 +370,6 @@ evUpdCreateWithKeyErr2 = script do
createCmd (T_EvUpdCreateWithKeyErr2 p)
abort "EvUpdCreateWithKeyErr2 failed"

-- | `controller P can ...` syntax adds `P` to the observers,
-- so if `P` causes an error, this is triggered on create,
-- instead of on exercise.
-- @ERROR controllerCanAddsObserver OK
template T_ControllerCanAddsObserver
with
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 ()

controllerCanAddsObserver : Script ()
controllerCanAddsObserver = script do
p <- allocateParty "Alice"
submit p do
createCmd (T_ControllerCanAddsObserver p)
abort "controllerCanAddsObserver failed"

-- | `choice ... controller P ...` doesn't add `P` as observer.
-- This test is here to contrast with the previous.
-- @ERROR choiceControllerDoesntAddObserver OK
Expand Down
17 changes: 0 additions & 17 deletions compiler/damlc/tests/daml-test-files/WarnControllerCan.daml

This file was deleted.

60 changes: 58 additions & 2 deletions docs/source/daml/code-snippets/Reference.daml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
-- Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0

{-# OPTIONS -Wno-controller-can #-}

-- template-let warning disabled because 'start template let snippet' is
-- used by docs.daml.com for older compiler versions and to explain
-- new deprecation warning in 2.8.0
Expand Down Expand Up @@ -50,6 +48,63 @@ template NameOfTemplate
key (exampleParty, exampleParam) : (Party, Text)
maintainer (exampleFunction key)
-- end contract key snippet

-- start new template choice snippet
choice NameOfChoice
: () -- replace () with the actual return type
with
exampleParameter : Text -- parameters here
controller exampleParty
do
return () -- replace this line with the choice body
-- end new template choice snippet

-- start new choice name snippet
choice ExampleChoice
: () -- replace () with the actual return type
-- end new choice name snippet
-- start new choice params snippet
with
exampleParameter : Text
-- end new choice params snippet
-- start new controller snippet
controller exampleParty
-- end new controller snippet
do
return () -- replace () with the actual return type
-- start new preconsuming snippet
preconsuming choice ExamplePreconsumingChoice
: () -- replace () with the actual return type
-- end new preconsuming snippet
with -- params
controller exampleParty
do
return ()
-- start new postconsuming snippet
postconsuming choice ExamplePostconsumingChoice
: () -- replace () with the actual return type
-- end new postconsuming snippet
with -- params
controller exampleParty
do
return ()
-- start new nonconsuming snippet
nonconsuming choice ExampleNonconsumingChoice
: () -- replace () with the actual return type
-- end new nonconsuming snippet
with -- params
controller exampleParty
do
return ()

{- LEGACY CHOICE SNIPPETS
Before Daml 2.8.0, two syntaxes were supported for declaring choices,
choice name first and controller-first. The latter was removed, so the
code below doesn't compile anymore, but docs.daml.com uses the version
of this file in the `main` branch, including when building the docs
for Daml <2.8.0, so it's easier to leave the old snippets alone for
those versions.
-- start template choice snippet
-- option 1 for specifying choices: choice name first
choice NameOfChoice1
Expand Down Expand Up @@ -147,3 +202,4 @@ template NameOfTemplate
-- end controller-first nonconsuming snippet
do
return () -- replace () with the actual return type
-}
34 changes: 32 additions & 2 deletions docs/source/daml/code-snippets/Structure.daml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
-- Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0

{-# OPTIONS -Wno-controller-can #-}
module Structure where

exampleFunction : (Party, Text) -> Party
Expand All @@ -28,6 +27,36 @@ template NameOfTemplate
maintainer (exampleFunction key)
-- a choice goes here; see next section
-- end of template outline snippet

-- start of new choice snippet
choice NameOfChoice
: () -- replace () with the actual return type
with
party : Party -- parameters here
controller party
do
return () -- replace this line with the choice body
-- end of new choice snippet

-- start of new choice observer snippet
choice NameOfChoiceWithObserver
: () -- replace () with the actual return type
with
party : Party -- parameters here
observer party -- optional specification of choice observers
controller exampleParty
do
return () -- replace this line with the choice body
-- end of new choice observer snippet

{- LEGACY CHOICE SNIPPETS
Before Daml 2.8.0, two syntaxes were supported for declaring choices,
choice name first and controller-first. The latter was removed, so the
code below doesn't compile anymore, but docs.daml.com uses the version
of this file in the `main` branch, including when building the docs
for Daml <2.8.0, so it's easier to leave the old snippets alone for
those versions.
-- start of choice snippet
-- option 1 for specifying choices: choice name first
choice NameOfChoice
Expand All @@ -46,7 +75,7 @@ template NameOfTemplate
party : Party -- parameters here
do
return () -- replace the line with the choice body
-- end of choice snippet
-- end of choice snippet
-- start of choice observer snippet
-- choice observers may be specified if option 1 is used
Expand All @@ -59,3 +88,4 @@ template NameOfTemplate
do
return () -- replace this line with the choice body
-- end of choice observer snippet
-}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
-- Copyright (c) 2023 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
-- SPDX-License-Identifier: Apache-2.0
{-# OPTIONS -Wno-controller-can #-}

module Stakeholders where

Expand All @@ -10,50 +9,10 @@ template OnlySignatories
where
signatory owner

-- 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 owner can
OnlySignatories_Choice : ()
do return ()

template ImplicitObservers
with
owner: Party
thirdParty: Party
where
signatory owner

-- 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 thirdParty can
ImplicitObservers_Choice : ()
do return ()

template ExplicitObservers
with
owner: Party
thirdParty: Party
where
signatory owner
observer thirdParty

-- 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 owner can
ExplicitObservers_Choice : ()
do return ()

template MixedObservers
with
owner: Party
thirdParty1: Party
thirdParty2: Party
where
signatory owner
observer thirdParty1

-- 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 thirdParty2 can
MixedObservers_Choice : ()
do return ()
Loading

0 comments on commit 1bee52e

Please sign in to comment.