Skip to content

Commit

Permalink
Move files in daml-foundations/daml-ghc to compiler/damlc (digital-as…
Browse files Browse the repository at this point in the history
…set#2037)

* Move files in daml-foundations/daml-ghc to compiler/damlc

There is also a bit of refactoring going on to actually split things
apart into sensible targets. What is still missing is a cleanup of the
module hierarchy and a cleanup of the test targets but I’ll leave
those for separate PRs.

As a nice bonus, this also reduces dependencies between targets so it
will speed up compiles.

* Update .hie-bios
  • Loading branch information
cocreature authored Jul 8, 2019
1 parent 85a5222 commit edff8a4
Show file tree
Hide file tree
Showing 305 changed files with 881 additions and 817 deletions.
14 changes: 8 additions & 6 deletions .hie-bios
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ echo \
-i"${BAZEL_GENFILES}" \
-i"${BAZEL_GENFILES}"/compiler/scenario-service/protos \
-i"${BAZEL_GENFILES}"/daml-lf/archive \
-icompiler/damlc/daml-compiler/src \
-icompiler/damlc/daml-doc/src \
-icompiler/damlc/daml-ide/src \
-icompiler/damlc/daml-ide-core/src \
-icompiler/damlc/daml-lf-conversion/src \
-icompiler/damlc/daml-opts/daml-opts \
-icompiler/damlc/daml-opts/daml-opts-types \
-icompiler/damlc/daml-preprocessor/src \
-icompiler/damlc/lib \
-icompiler/daml-lf-ast/src \
-icompiler/daml-lf-proto/src \
Expand All @@ -18,11 +26,5 @@ echo \
-icompiler/scenario-service/client/src \
-idaml-assistant/ \
-idaml-assistant/daml-project-config \
-idaml-foundations/daml-ghc/daml-compiler/src \
-idaml-foundations/daml-ghc/damldoc/src \
-idaml-foundations/daml-ghc/ghc-compiler/src \
-idaml-foundations/daml-ghc/ghc-compiler/src \
-idaml-foundations/daml-ghc/ide/src \
-idaml-foundations/daml-ghc/language-server/src \
-ilibs-haskell/bazel-runfiles/src \
-ilibs-haskell/da-hs-base/src
1 change: 0 additions & 1 deletion .stylish-haskell.yaml

This file was deleted.

8 changes: 4 additions & 4 deletions BAZEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -557,11 +557,11 @@ da_haskell_library(
To build this single target from the root of the DAML repository, the
command would be:
```
bazel build //daml-foundations/daml-ghc:daml-ghc-compiler
bazel build //compiler/damlc/daml-compiler
```
since the `BUILD.bazel` that defines the target is in the
`daml-foundations/daml-ghc` sub-folder of the root of the DA
repository and the target `name` is `daml-ghc`.
`compiler/damlc` sub-folder of the root of the DA
repository and the target `name` is `damlc`.
Let's break this definition down:
- `name`:
Expand Down Expand Up @@ -624,7 +624,7 @@ da_haskell_binary (
main_function = "DA.Cli.GHC.Run.main",
hazel_deps = [ "base", "time", ...],
data = [
"//daml-foundations/daml-ghc/package-database:package-db"
"//compiler/damlc/pkg-db"
, ...
],
deps = [
Expand Down
216 changes: 209 additions & 7 deletions compiler/damlc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,16 @@ da_haskell_library(
"//compiler/daml-lf-proto",
"//compiler/daml-lf-reader",
"//compiler/daml-lf-tools",
"//compiler/damlc/daml-compiler",
"//compiler/damlc/daml-doc",
"//compiler/damlc/daml-ide",
"//compiler/damlc/daml-ide-core",
"//compiler/damlc/daml-opts",
"//compiler/damlc/daml-opts:daml-opts-types",
"//compiler/hie-core",
"//compiler/scenario-service/client",
"//compiler/scenario-service/protos:scenario_service_haskell_proto",
"//daml-assistant:daml-project-config",
"//daml-foundations/daml-ghc/daml-compiler",
"//daml-foundations/daml-ghc/damldoc",
"//daml-foundations/daml-ghc/ghc-compiler",
"//daml-foundations/daml-ghc/ide",
"//daml-foundations/daml-ghc/language-server",
"//daml-lf/archive:daml_lf_haskell_proto",
"//libs-haskell/bazel-runfiles",
"//libs-haskell/da-hs-base",
Expand Down Expand Up @@ -169,7 +170,6 @@ da_haskell_test(
data = [
":cli-tests/visual/Basic.dot",
":visual-test-daml.dar",
# "//daml-foundations/daml-ghc/package-database:package-db",
],
hazel_deps = [
"tasty",
Expand Down Expand Up @@ -212,8 +212,210 @@ da_haskell_test(
visibility = ["//visibility:private"],
deps = [
":damlc-lib",
"//compiler/damlc/daml-opts:daml-opts-types",
"//compiler/hie-core",
"//daml-foundations/daml-ghc/ghc-compiler",
"//libs-haskell/da-hs-base",
],
)

# Generating DAML stdlib docs.

filegroup(
name = "daml-base-files", # DAML files to be included in DAML base docs.
srcs = [
"//compiler/damlc/daml-prim-src",
"//compiler/damlc/daml-stdlib-src",
],
visibility = ["__pkg__"],
)

filegroup(
name = "daml-base-hoogle-prefix",
srcs = ["base-hoogle-prefix.txt"],
visibility = ["__pkg__"],
)

filegroup(
name = "daml-base-rst-prefix",
srcs = ["base-rst-prefix.rst"],
visibility = ["__pkg__"],
)

genrule(
name = "daml-base-hoogle-docs",
srcs = [
":daml-base-files",
":daml-base-hoogle-prefix",
],
outs = ["daml-base-hoogle.txt"],
cmd = "$(location //compiler/damlc) -- docs --output=$(OUTS) --format=Hoogle $(locations :daml-base-files) --prefix=$(location :daml-base-hoogle-prefix)",
tools = ["//compiler/damlc"],
visibility = ["//visibility:public"],
)

genrule(
name = "daml-base-rst-docs",
srcs = [
":daml-base-files",
":daml-base-rst-prefix",
],
outs = ["daml-base.rst"],
cmd = "$(location //compiler/damlc) -- docs --output=$(OUTS) --format=Rst $(locations :daml-base-files) --prefix=$(location :daml-base-rst-prefix)",
tools = ["//compiler/damlc"],
visibility = ["//visibility:public"],
)

load(
":util.bzl",
"daml_ghc_compile_test",
"daml_ghc_integration_test",
)
load("@os_info//:os_info.bzl", "is_windows")

# Runs the tests with all non-dev DAML-LF versions
daml_ghc_integration_test("daml-ghc-test-stable", "DA.Test.GHC.mainAll")

# Runs the tests with DAML-LF 1.dev
daml_ghc_integration_test("daml-ghc-test-dev", "DA.Test.GHC.main")

da_haskell_test(
name = "tasty-test",
srcs = ["test-src/DA/Test/TastyMain.hs"],
data = [
":test-files",
"//compiler/damlc/pkg-db",
],
hazel_deps = [
"base",
"tasty-hunit",
"text",
],
main_function = "DA.Test.TastyMain.main",
src_strip_prefix = "test-src",
visibility = ["//visibility:public"],
deps = [
"//compiler/damlc:damlc-lib",
"//compiler/damlc/daml-doc:daml-doc-testing",
"//libs-haskell/da-hs-base",
],
)

da_haskell_test(
name = "damlc-shake-tests",
size = "large",
# this test takes a while and often time out -- tell that to bazel
timeout = "long",
srcs = ["test-src/DA/Test/ShakeIdeClient.hs"],
data = [
"//compiler/damlc/pkg-db",
"//compiler/scenario-service/server:scenario_service_jar",
],
hazel_deps = [
"base",
"directory",
"tasty-hunit",
"text",
],
main_function = "DA.Test.ShakeIdeClient.main",
src_strip_prefix = "test-src",
visibility = ["//visibility:public"],
deps = [
"//compiler/damlc/daml-compiler",
"//compiler/damlc/daml-ide-core",
"//compiler/damlc/daml-ide-core:ide-testing",
"//compiler/hie-core",
"//libs-haskell/da-hs-base",
],
)

da_haskell_binary(
name = "generate-module-tree",
srcs = ["test-src/DA/Test/GenerateModuleTree.hs"],
hazel_deps = [
"base",
"filepath",
],
main_function = "DA.Test.GenerateModuleTree.main",
src_strip_prefix = "test-src",
deps = ["//libs-haskell/da-hs-base"],
)

genrule(
name = "module-tree-test",
outs = ["FatTree{i}.daml".format(i = i) for i in range(1, 19)],
cmd = "$(location :generate-module-tree) $(@D) 18",
tools = [":generate-module-tree"],
visibility = ["//visibility:public"],
)

daml_ghc_compile_test(
name = "module-tree-memory",
srcs = [":module-tree-test"],
main = "FatTree18.daml",
visibility = ["//visibility:public"],
)

daml_ghc_compile_test(
name = "compile-subdir",
srcs = [":test-files"],
main = "test-files/Subdir/Examples.daml",
)

daml_ghc_compile_test(
name = "compile-empty",
srcs = [":test-files"],
main = "test-files/Empty.daml",
)

daml_ghc_compile_test(
name = "examples-memory",
srcs = [":test-files"],
heap_limit = "200M",
main = "test-files/Examples.daml",
stack_limit = "230K",
)

daml_ghc_compile_test(
name = "bond-trading-memory",
srcs = [":bond-trading"],
heap_limit = "200M" if is_windows else "100M",
main = "bond-trading/Test.daml",
stack_limit = "35K",
)

filegroup(
name = "test-files",
srcs = glob(["test-files/**"]),
visibility = [
"__pkg__",
"//daml-foundations/integration-tests:__pkg__",
],
)

filegroup(
name = "bond-trading",
srcs = glob(["bond-trading/**"]),
visibility = [
"__pkg__",
"//daml-foundations/integration-tests:__pkg__",
],
)

# Check that DAML compilation is deterministic.
sh_test(
name = "daml-ghc-deterministic",
srcs = ["test-files/daml-ghc-deterministic.sh"],
args = [
"$(location //compiler/damlc)",
"$(location @com_google_protobuf//:protoc)",
],
data = [
":test-files",
"//compiler/damlc",
"//compiler/damlc/pkg-db",
"@com_google_protobuf//:protoc",
],
deps = [
"@bazel_tools//tools/bash/runfiles",
],
)
71 changes: 71 additions & 0 deletions compiler/damlc/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
## Developing

Before you start, build the IDE test suite. We fall back to this to
find runfiles such as the scenario service and the package database
when we’re running inside GHCi.

```
bazel build //compiler/damlc:damlc-shake-tests
```

When working on the compiler:

```
da-ghcid //compiler/damlc:daml-ghc-test-dev --reload=compiler/damlc/test-files --test=":main --pattern="
bazel run //compiler/damlc:daml-ghc-test-dev -- --pattern=
bazel run damlc -- compile $PWD/MyDaml12File.daml
```

When working on the IDE via the test suite:

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

The above commands do not execute scenarios. To do that, use a command like
```
bazel run damlc test $PWD/compiler/damlc/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
```
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion compiler/damlc/cli-tests/DamlcTest.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Test.Tasty
import Test.Tasty.HUnit

import qualified DA.Cli.Damlc.Test as Damlc
import DA.Daml.GHC.Compiler.Options
import DA.Daml.GHC.Compiler.Options.Types
import Development.IDE.Types.Location

main :: IO ()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ da_haskell_library(
"ghc-lib",
"ghc-lib-parser",
"haskell-lsp",
"lens",
"mtl",
"safe",
"safe-exceptions",
Expand All @@ -32,10 +33,11 @@ da_haskell_library(
deps = [
"//compiler/daml-lf-ast",
"//compiler/daml-lf-proto",
"//compiler/damlc/daml-ide-core",
"//compiler/damlc/daml-opts:daml-opts-types",
"//compiler/damlc/daml-preprocessor",
"//compiler/hie-core",
"//compiler/scenario-service/client",
"//daml-foundations/daml-ghc/ghc-compiler",
"//daml-foundations/daml-ghc/ide",
"//libs-haskell/da-hs-base",
],
)
Loading

0 comments on commit edff8a4

Please sign in to comment.