Skip to content

Commit

Permalink
Update generic templates (digital-asset#2547)
Browse files Browse the repository at this point in the history
* Extract template instance doc from newtype constructor doc
* Use new ghc-libs
* Remove type application which is not needed anymore
* Update daml-doc output with template instances
* Update hlint version
  • Loading branch information
rohanjr authored Aug 14, 2019
1 parent 6defc5f commit 5bf86db
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 28 deletions.
2 changes: 1 addition & 1 deletion 3rdparty/haskell/BUILD.ghc-lib-parser
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ haskell_library(
"-I/compiler", "-I/compiler/utils"
],
package_name = "ghc-lib-parser",
version = "8.8.0.20190809",
version = "8.8.0.20190814",
)

cc_library(
Expand Down
8 changes: 4 additions & 4 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -469,12 +469,12 @@ HASKELL_LSP_COMMIT = "bfbd8630504ebc57b70948689c37b85cfbe589da"

HASKELL_LSP_HASH = "a301d9409c3a19a042bdf5763611c6a60af5cbc1ff0f281acbc19b3ee70dde5f"

GHC_LIB_VERSION = "8.8.0.20190809"
GHC_LIB_VERSION = "8.8.0.20190814"

http_archive(
name = "haskell_ghc__lib__parser",
build_file = "//3rdparty/haskell:BUILD.ghc-lib-parser",
sha256 = "8d7774dc830d8e27d20ce0a4f039fcfdf440a3332f2dfce3716743ea30e3589e",
sha256 = "ce14e19bbe2a52289c5fb436941f948678a86bd821c17710082131bbe87d997f",
strip_prefix = "ghc-lib-parser-{}".format(GHC_LIB_VERSION),
urls = ["https://digitalassetsdk.bintray.com/ghc-lib/ghc-lib-parser-{}.tar.gz".format(GHC_LIB_VERSION)],
)
Expand Down Expand Up @@ -524,15 +524,15 @@ hazel_repositories(

# Read [Working on ghc-lib] for ghc-lib update instructions at
# https://github.com/DACH-NY/daml/blob/master/ghc-lib/working-on-ghc-lib.md.
hazel_ghclibs(GHC_LIB_VERSION, "8d7774dc830d8e27d20ce0a4f039fcfdf440a3332f2dfce3716743ea30e3589e", "0a0231b5d98ea60d9987b8b46fd911d7d183b9c4b7e0513640c54515a5de7362") +
hazel_ghclibs(GHC_LIB_VERSION, "ce14e19bbe2a52289c5fb436941f948678a86bd821c17710082131bbe87d997f", "02482f4fd7691c2e442f9dd4c8d6816325d0bd164f6e03cec6a2db1ef9e65d43") +

# Support for Hlint:
# - Requires haskell-src-exts 1.21.0 so override hazel/packages.bzl.
# - To build the binary : `bazel build @haskell_hlint//:bin`
# - To build the library : `bazel build @haskell_hlint//:lib`
# We'll be using it via the library, not the binary.
hazel_hackage("haskell-src-exts", "1.21.0", "95dac187824edfa23b6a2363880b5e113df8ce4a641e8a0f76e6d45aaa699ff3") +
hazel_github_external("digital-asset", "hlint", "35c5857c5d19e1bc502b2ee2f5dd315f8850532a", "5e6155aa5d0a02b8ad34df9403606ccf7284dd9b90b23bcd0c0466c63d91ed21") +
hazel_github_external("digital-asset", "hlint", "cc93aa00116cfba8cad7cfbd0de31f6bf3b5b48a", "c9403ec7f1c21ffb0b9b7cb8a4fb71ce1c02dfcf9839122182cb3a0b57288c30") +
hazel_github_external("awakesecurity", "proto3-wire", "43d8220dbc64ef7cc7681887741833a47b61070f", "1c3a7fbf4ab3308776675c6202583f9750de496757f3ad4815e81edd122d75e1") +
hazel_github_external("awakesecurity", "proto3-suite", "dd01df7a3f6d0f1ea36125a67ac3c16936b53da0", "59ea7b876b14991347918eefefe24e7f0e064b5c2cc14574ac4ab5d6af6413ca") +
hazel_hackage("happy", "1.19.10", "22eb606c97105b396e1c7dc27e120ca02025a87f3e44d2ea52be6a653a52caed") +
Expand Down
17 changes: 7 additions & 10 deletions compiler/damlc/daml-doc/src/DA/Daml/Doc/Extract.hs
Original file line number Diff line number Diff line change
Expand Up @@ -458,31 +458,28 @@ getTemplateDocs DocCtx{..} typeMap templateInstanceMap =
[] -> [] -- catching the dummy case here, see above
_other -> error "getFields: found multiple constructors"

-- | As per issue #2239, a template instance is desugared into a
-- newtype with a docs marker. For example,
-- | A template instance is desugared into a newtype with a docs marker.
-- For example,
--
-- @template instance ProposalIou = Proposal Iou@
--
-- becomes
--
-- @newtype ProposalIou = MkProposalIou with unProposalIou : Proposal Iou -- ^ TEMPLATE_INSTANCE@
-- @newtype ProposalIou = ProposalIou (Proposal Iou) -- ^ TEMPLATE_INSTANCE@
--
-- So the goal of this function is to extract the template instance doc
-- from the newtype doc if it exists.
--
-- The TEMPLATE_INSTANCE doc marker used here does not exist yet.
-- (See issue #2239 in the daml repo for an up to date status.)
getTemplateInstanceDoc :: ADTDoc -> Maybe TemplateInstanceDoc
getTemplateInstanceDoc adt
| ADTDoc{..} <- adt
, [RecordC{..}] <- ad_constrs
, [FieldDoc{..}] <- ac_fields
, Just (DocText "TEMPLATE_INSTANCE") <- fd_descr
, [PrefixC{..}] <- ad_constrs
, Just (DocText "TEMPLATE_INSTANCE") <- ac_descr
, [argType] <- ac_args
= Just TemplateInstanceDoc
{ ti_name = ad_name
, ti_anchor = ad_anchor
, ti_descr = ad_descr
, ti_rhs = fd_type
, ti_rhs = argType
}

| otherwise
Expand Down
7 changes: 3 additions & 4 deletions compiler/damlc/tests/daml-test-files/ProposalIou.EXPECTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
>
> (no fields)
## Data Types
## Template Instances

<a name="type-proposaliou-proposaliou-81988"></a>**data** [ProposalIou](#type-proposaliou-proposaliou-81988)
<a name="type-proposaliou-proposaliou-81988"></a>**template instance** [ProposalIou](#type-proposaliou-proposaliou-81988)

> <a name="constr-proposaliou-proposaliou-48383"></a>[ProposalIou](#constr-proposaliou-proposaliou-48383) (Proposal [Iou](#type-proposaliou-iou-51326))
>
> = Proposal [Iou](#type-proposaliou-iou-51326)
12 changes: 4 additions & 8 deletions compiler/damlc/tests/daml-test-files/ProposalIou.EXPECTED.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,10 @@ Templates
+ **Choice Burn**


Data Types
^^^^^^^^^^
Template Instances
^^^^^^^^^^^^^^^^^^

.. _type-proposaliou-proposaliou-81988:

**data** `ProposalIou <type-proposaliou-proposaliou-81988_>`_

.. _constr-proposaliou-proposaliou-48383:

`ProposalIou <constr-proposaliou-proposaliou-48383_>`_ (Proposal `Iou <type-proposaliou-iou-51326_>`_)

**template instance** `ProposalIou <type-proposaliou-proposaliou-81988_>`_
= Proposal `Iou <type-proposaliou-iou-51326_>`_
2 changes: 1 addition & 1 deletion compiler/damlc/tests/daml-test-files/ProposalIou.daml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test = scenario do
lookupByKey @(Proposal Iou) ([bank], "present")
mbPropId === Some propId
iouId <- submit alice do
exercise propId (Accept @Iou)
exercise propId Accept
iou' <- submit alice do
fetch iouId
iou' === iou
Expand Down

0 comments on commit 5bf86db

Please sign in to comment.