daml/compiler/damlc
Moritz Kiefer ba30e86911
Split wired-in modules into separate LF packages (#3696)
This is a first step towards making sure that the package ids for
types defined in daml-prim and daml-stdlib don’t change. This PR
mostly adds all the necessary infrastructure for that and moves
GHC.Types and GHC.Prim to make sure it works.

Until data-dependencies are really solid and we have verified that we
no longer have performance issues with an increasing number of Haskell
packages, we still include the source files in daml-prim and then just
rewrite the references.

We will also need to add tests that these packages really have stable
ids but I’ll leave that for separate PRs since this doesn’t make that
much sense anyway until all of the types have moved to stable
packages.

CHANGELOG_BEGIN

- [DAML Compiler] The modules GHC.Prim and GHC.Types from daml-prim
have been moved to separate packages.

CHANGELOG_END
2019-12-04 16:42:48 +01:00
..
daml-compiler Add support for type-synonyms in DAML-LF .proto and Haskell AST (#3703) 2019-12-03 14:51:02 +00:00
daml-doc Remove generic template support from damldocs (#3693) 2019-12-02 15:08:06 +00:00
daml-doctest Replace Hazel by stack_snapshot (#2743) 2019-11-22 14:24:08 +00:00
daml-ide Upgrade ghcide and haskell-lsp (#3499) 2019-11-18 10:56:19 +00:00
daml-ide-core Split wired-in modules into separate LF packages (#3696) 2019-12-04 16:42:48 +01:00
daml-lf-conversion Split wired-in modules into separate LF packages (#3696) 2019-12-04 16:42:48 +01:00
daml-opts Split wired-in modules into separate LF packages (#3696) 2019-12-04 16:42:48 +01:00
daml-preprocessor Remove check for generic templates (#3680) 2019-11-29 15:58:27 +00:00
daml-prim-src Implement DAML constraint tuples as LF structs. (#3667) 2019-11-28 17:18:55 +00:00
daml-stdlib-src Expose keys and values function from DA.Map (#3684) 2019-12-01 11:49:23 +01:00
daml-visual Add support for type-synonyms in DAML-LF .proto and Haskell AST (#3703) 2019-12-03 14:51:02 +00:00
exe update copyright notices (#2499) 2019-08-13 17:23:03 +01:00
ide-debug-driver Update to current state of progress reporting in LSP (#3211) 2019-10-17 16:14:49 +02:00
jar Fix Bazel warnings (#3414) 2019-11-11 15:41:34 +00:00
lib/DA/Cli Split wired-in modules into separate LF packages (#3696) 2019-12-04 16:42:48 +01:00
pkg-db Update rules_haskell (#3473) 2019-11-15 10:50:12 +00:00
stable-packages Split wired-in modules into separate LF packages (#3696) 2019-12-04 16:42:48 +01:00
tests Split wired-in modules into separate LF packages (#3696) 2019-12-04 16:42:48 +01:00
base-hoogle-template.txt damldocs: Hook up multiple file rendering to cli options. (#2295) 2019-07-26 13:45:06 +01:00
base-md-template.md damldocs: Switch to mustache templates. (#2373) 2019-08-02 13:52:38 +00:00
base-rst-template.rst update copyright notices (#2499) 2019-08-13 17:23:03 +01:00
BUILD.bazel Split wired-in modules into separate LF packages (#3696) 2019-12-04 16:42:48 +01:00
README.md Rename hie-core to ghcide (#2820) 2019-09-09 13:55:16 +00: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-dev --reload=compiler/damlc/tests/daml-test-files --test=":main --pattern="
bazel run //compiler/damlc/tests:integration-dev -- --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 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-rst-docs
bazel build //compiler/damlc:daml-base-hoogle-docs

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