daml/compiler/damlc
Sofia Faro e52c2a0252
Bundle ghcversion.h and hpp with damlc. (#8278)
* Bundle hpp with damlc.

This PR eliminates the red squiggly lines you get when opening up the
standard library in daml studio (e.g. after a Go To Definitien).

(When CPP is used, Go To Definition is still pointing to the wrong place,
because the line numbers are messed up. But it's better than having a
million error messages.)

We could also remove --cpp flag in a separate PR, though that may be
considered a breaking change.

changelog_begin
changelog_end

* cleanup locateRunfiles jank

* Revert "cleanup locateRunfiles jank"

This reverts commit 82552003ae.
2020-12-14 17:23:41 +00:00
..
daml-compiler Fix prettyprinting in DAML REPL (#8214) 2020-12-09 15:24:43 +01:00
daml-doc Patch ghc to add a daml version header marker. (#7489) 2020-09-28 17:01:20 +00:00
daml-doctest Deprecate the "daml 1.2" version header. (#7513) 2020-09-29 13:14:59 +00:00
daml-ide IDE distinguish scripts and scenarios (#7197) 2020-08-20 16:36:23 +00:00
daml-ide-core Add overlap mode annotations during LF conversion. (#7765) 2020-10-21 12:53:03 +01:00
daml-lf-conversion fix link to AST (#8238) 2020-12-10 15:48:58 +01:00
daml-opts Bundle ghcversion.h and hpp with damlc. (#8278) 2020-12-14 17:23:41 +00:00
daml-package-config damlc: warn on bad package names/versions. (#8254) 2020-12-14 16:44:43 +01:00
daml-preprocessor Use a NonEmpty list in makeLocalValBinds. (#8013) 2020-11-19 11:29:19 +00:00
daml-prim-src Make GHC recognise our ($) operator. (#7969) 2020-11-16 15:10:14 +00:00
daml-rule-types Extend the scenario service with DAML Script support (#6929) 2020-08-05 12:56:09 +02:00
daml-stdlib-src Doc: fix minor issues in intro 2 (#8175) 2020-12-05 16:23:12 +01:00
daml-visual Add exceptions in DAML-LF AST (Haskell side) (#8112) 2020-11-30 16:18:29 +00:00
exe replace DAML Authors with DA in copyright headers (#5228) 2020-03-27 01:26:10 +01:00
ide-debug-driver replace DAML Authors with DA in copyright headers (#5228) 2020-03-27 01:26:10 +01:00
lib/DA/Cli damlc: warn on bad package names/versions. (#8254) 2020-12-14 16:44:43 +01:00
pkg-db Bazel: Upgrade Buildifier. (#6625) 2020-07-06 16:07:47 +00:00
stable-packages Update protobuf for exceptions. (#8087) 2020-11-30 10:42:17 +00:00
tests Add multi-party submissions to DAML Script (#8240) 2020-12-11 12:45:32 +01:00
base-hoogle-template.txt Generate hoogle docs for daml script/triggers (#7371) 2020-09-10 15:58:15 +02:00
base-md-template.md damldocs: Switch to mustache templates. (#2373) 2019-08-02 13:52:38 +00:00
base-rst-index-template.rst Connectify user-facing output (#7624) 2020-10-09 15:45:02 +02:00
base-rst-template.rst Split standard library docs up one page per module. (#5636) 2020-04-22 13:23:46 +01:00
BUILD.bazel Bundle ghcversion.h and hpp with damlc. (#8278) 2020-12-14 17:23:41 +00:00
README.md Add sed script to help with updating the damlc ITs (#7727) 2020-10-19 14:26:59 +02:00
util.bzl Fix scenario service vs struct projections bug (#7778) 2020-10-23 13:30:56 +02:00

Code layout

The following list is ordered topologicaly based on the dependency graph.

daml-preprocessor

daml-preprocessor contains the DAML preprocessor which runs our version of the record-dot-preprocessor and the preprocessor for generating Generic instances. The preprocessor also performs a few additional checks, e.g., that you do not import internal modules.

daml-opts

daml-opts contains two libraries: daml-opt-types and daml-opts.

daml-opt-types contains the Options type which controls the various flags affecting most damlc commands. Most of the options can be controlled via command line flags.

daml-opts contains the conversion from damlcs Options type to ghcides IdeOptions type. This is in a separate package to avoid making everything depend on daml-preprocessor.

daml-lf-conversion

daml-lf-conversion handles the conversion from GHCs Core to DAML-LF.

daml-ide-core

daml-ide-core is a wrapper around ghcide that adds DAML-specific rules such as rules for producing DAML-LF.

daml-doc

daml-doc contains our variant of haddock.

daml-ide

daml-ide contains the LSP layer of the IDE and wraps the corresponding LSP layer in ghcide and adds custom handlers such as those for scenario results.

daml-compiler

daml-compiler contains the implementation of a few top-level damlc commands, e.g., upgrade.

lib

lib is all of damlc but packaged as a library since that can be more convenient for tests.

exe

This is a tiny wrapper around lib to produce the damlc executable.

Developing

When working on the compiler:

da-ghcid //compiler/damlc/tests:integration-v1dev --reload=compiler/damlc/tests/daml-test-files --test=":main --pattern="
bazel run //compiler/damlc/tests:integration-v1dev -- --pattern=
bazel run damlc -- compile $PWD/MyDaml12File.daml

When working on the IDE via the test suite:

bazel run //compiler/damlc/tests:shake -- --pattern=
da-ghcid //compiler/damlc/tests:shake --test=":main --pattern="

The above commands do not execute scenarios. To do that, use a command like

bazel run damlc test $PWD/compiler/damlc/tests/bond-trading/Test.daml

At the moment, commands relying on ghc-pkg, e.g., damlc build do not work via bazel run. For testing, install the SDK with daml-sdk-head and then use daml-head damlc.

Updating expected diagnostics in the damlc integration tests

Most of the .daml files in tests/daml-test-files contain comments of the form

-- @WARN range=1:1-1:10; Something to warn about

These comments specify the diagnostics we expect when compiling the file. Sometimes these expectations change for various reasons and updating the comments can be quite tedious, particularly when there are many of them. You can extract the comments reflecting the updated expectations from the compiler output by copying the output into the clipboard and running

# On MacOS
pbpaste | sed -n -r -f compiler/damlc/tests/extract-diagnostics.sed

# On Linux
xclip -out -selection clipboard | sed -n -r -f compiler/damlc/tests/extract-diagnostics.sed

If a test case in the damlc intgration tests fails, it will print the compiler output. Alternative, you can run damlc as described above to get the output.

Updating daml-doc's golden tests

Run

bazel run //compiler/damlc/tests:daml-doc -- --accept

to accept the current documentation as new golden files.

Documentation

Standard library docs are exposed under the bazel rules which you can build with:

bazel build //compiler/damlc:daml-base-docs

This creates a tarball containing RST (ReStructured Text) docs, and a hoogle database.

DAML Packages and Database

A DAML project is compiled to a DAML package and can be distributed as a DAML archive (DAR). This is essentially a zip archive containing the DAML source code of the library together with the compiled .dalf file. The damlc package loading mechanism is based on GHC's package database and uses the same .conf file format. GHC's package database is documented at https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/packages.html.

Loading packages

damlc loads packages from a package database given by the option --package-db. It creates a map from package name to DAML-LF file from all the contained .dalf files in this directory and links the created DAML-LF against these packages. It uses the .hi interface files created upon installation of the packages for type checking.

Base packages

Currently a package database is provided together with the damlc Bazel rule and bazel run damlc loads this database by default. This package database is also bundled in the damlc-dist.tar.gz tarball included in the SDK.

Building the package database

The package database that comes with damlc and the above archives can be build with

bazel build //compiler/damlc/pkg-db:pkg-db