daml/compiler/damlc
Martin Huschenbett a35af9697f
Hide the --target flag of damlc (#2253)
We want to discourage users to pin down a target DAML-LF version but rather
want them to always use the default version, which is typically the newest
version. Thus, we turn this into an expert flag that is mostly used for
testing by us.
2019-07-22 20:43:22 +02:00
..
daml-compiler language: added a merge command to damlc (#2232) 2019-07-22 14:04:28 +00:00
daml-doc damldocs: Document template instances. (#2240) 2019-07-22 14:48:12 +01:00
daml-doctest Add a damlc doctest command and test the standard library (#2157) 2019-07-16 15:51:01 +02:00
daml-ide Ignore optional notification and request methods (#2244) 2019-07-22 13:12:36 +00:00
daml-ide-core VSCode scenario codelenses improvements (#2141) 2019-07-22 10:50:30 +02:00
daml-lf-conversion Generic templates: erase default implementations of magic methods (#2249) 2019-07-22 16:57:01 +00:00
daml-opts Enable GHC Core linter in damlc integration tests (#2206) 2019-07-18 10:26:03 +02:00
daml-preprocessor language: additional (hidden) compiler options needed for migrate (#2123) 2019-07-12 16:41:10 +02:00
daml-prim-src Fix MOVE in GHC.Enum (#2215) 2019-07-18 13:40:09 +00:00
daml-stdlib-src More stdlib tweaks (#2203) 2019-07-17 17:05:10 +00:00
exe Move code in daml-tools outside of daml-foundations (#2033) 2019-07-08 11:40:48 +02:00
jar Move code in daml-tools outside of daml-foundations (#2033) 2019-07-08 11:40:48 +02:00
lib/DA/Cli Hide the --target flag of damlc (#2253) 2019-07-22 20:43:22 +02:00
pkg-db Drop support for DAML-LF 1.5 from damlc (#2161) 2019-07-16 13:52:29 +00:00
tests Prefix method names in generic template classes with underscore (#2248) 2019-07-22 15:07:53 +00:00
base-hoogle-prefix.txt Move files in daml-foundations/daml-ghc to compiler/damlc (#2037) 2019-07-08 17:55:51 +02:00
base-md-prefix.md damldocs: Anchors and type signature links for markdown output. (#2156) 2019-07-16 13:53:15 +01:00
base-rst-prefix.rst Move files in daml-foundations/daml-ghc to compiler/damlc (#2037) 2019-07-08 17:55:51 +02:00
BUILD.bazel Add a damlc doctest command and test the standard library (#2157) 2019-07-16 15:51:01 +02:00
README.md Document damlc code layout (#2071) 2019-07-09 16:22:13 +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 hie-cores 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 hie-core 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 hie-core 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.

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