daml/compiler/damlc
Gary Verhaegen 46a4804672
bump nix (#15628)
Partly because the current version is from February (of this year,
fortunately), and partly because I need a more recent one to bump node
to 18 and fix the GSG for that.
2022-11-24 14:29:09 +00:00
..
daml-compiler Remove GHC.Tuple.Check module (#15549) 2022-11-14 18:29:35 +00:00
daml-desugar Desugared Daml golden tests (#13591) 2022-04-14 13:14:37 +00:00
daml-doc Clean up uses of locateRunfiles (#15446) 2022-11-10 13:20:43 +01:00
daml-doctest Remove GHC.Tuple.Check module (#15549) 2022-11-14 18:29:35 +00:00
daml-ghc-util Move userWrittenTuple check into own helper in GHC.Tuple.Check (#15445) 2022-11-11 15:59:29 +00:00
daml-ide hunt down DAML (#13191) 2022-03-08 14:25:25 +01:00
daml-ide-core Remove GHC.Tuple.Check module (#15549) 2022-11-14 18:29:35 +00:00
daml-lf-conversion Move userWrittenTuple check into own helper in GHC.Tuple.Check (#15445) 2022-11-11 15:59:29 +00:00
daml-lf-util hunt down DAML (#13191) 2022-03-08 14:25:25 +01:00
daml-opts Clean up uses of locateRunfiles (#15446) 2022-11-10 13:20:43 +01:00
daml-package-config Upgrade to GHC 9.0.2 (#12300) 2022-02-01 11:27:11 +01:00
daml-preprocessor Remove GHC.Tuple.Check module (#15549) 2022-11-14 18:29:35 +00:00
daml-prim-src Remove GHC.Tuple.Check module (#15549) 2022-11-14 18:29:35 +00:00
daml-rule-types hunt down DAML (#13191) 2022-03-08 14:25:25 +01:00
daml-stdlib-src Add DA.List.chunksOf function in Daml stdlib (#15618) 2022-11-21 16:09:34 +00:00
daml-visual Clean up uses of locateRunfiles (#15446) 2022-11-10 13:20:43 +01:00
exe update copyright headers (#12240) 2022-01-03 16:36:51 +00:00
ide-debug-driver Upgrade ghcide (#12579) 2022-01-26 16:00:20 +01:00
lib/DA/Cli bump nix (#15628) 2022-11-24 14:29:09 +00:00
pkg-db Add warnings to conversion, Warn for tuples size > 5 (#15018) 2022-09-21 14:16:39 +01:00
stable-packages Remove GHC.Tuple.Check module (#15549) 2022-11-14 18:29:35 +00:00
tests bump nix (#15628) 2022-11-24 14:29:09 +00:00
base-hoogle-template.txt hunt down DAML (#13191) 2022-03-08 14:25:25 +01:00
base-md-template.md Daml case and logo (#8433) 2021-01-08 12:50:15 +00:00
base-rst-index-template.rst Upgrade to GHC 9.0.2 (#12300) 2022-02-01 11:27:11 +01:00
base-rst-template.rst update copyright headers (#12240) 2022-01-03 16:36:51 +00:00
BUILD.bazel daml test: print test summary at end of test suite. (#13648) 2022-04-22 12:30:30 +02:00
README.md Desugared Daml golden tests (#13591) 2022-04-14 13:14:37 +00:00
util.bzl Upgrade to GHC 9.0.2 (#12300) 2022-02-01 11:27:11 +01: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-desugar

daml-desugar provides a simple way to obtain the GHC representation of a parsed Daml file.

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.

Updating daml-desugar's golden tests

Likewise, run

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

to accept the current desugaring 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