Skip to content

Commit

Permalink
damldoc: Move towards extracting information from TypecheckedModule i…
Browse files Browse the repository at this point in the history
…n HaddockParse. (#2013)

* Run typechecker in damldocs (but don't use result yet)

* Add Modulename to TypeApp constructor.

* Add md_name where appropriate.

* Thread a DocCtx through each doc extractor.

* Move template set and choices map into docctx

* Use Typename for template set and choice map

* Make Anchor a newtype and move it to Types

* Make Modulename in TypeApp an Anchor instead.

* Remove import of hidden module.

* Qualify that which doth need be qualified

* Update tests

* Build stdlib in such a way that it passes typechecking.

* Update release notes.

* Remove MOVE Prelude directives in daml-prim.

* Use optional in damldoc options

* Update function hashes

* Compile base packages to json first
  • Loading branch information
Fran authored and mergify[bot] committed Jul 9, 2019
1 parent 2d52406 commit a8f9817
Show file tree
Hide file tree
Showing 16 changed files with 253 additions and 155 deletions.
54 changes: 50 additions & 4 deletions compiler/damlc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -168,26 +168,72 @@ filegroup(
visibility = ["__pkg__"],
)

genrule(
name = "daml-prim-json-docs",
srcs = ["//compiler/damlc/daml-prim-src"],
outs = ["daml-prim.json"],
cmd = """
$(location //compiler/damlc) -- docs \
--output=$(OUTS) \
--package-name=daml-prim \
--format=Json \
$(locations //compiler/damlc/daml-prim-src)
""",
tools = ["//compiler/damlc"],
visibility = ["//visibility:public"],
)

genrule(
name = "daml-stdlib-json-docs",
srcs = ["//compiler/damlc/daml-stdlib-src"],
outs = ["daml-stdlib.json"],
cmd = """
$(location //compiler/damlc) -- docs \
--output=$(OUTS) \
--package-name=daml-stdlib \
--format=Json \
$(locations //compiler/damlc/daml-stdlib-src)
""",
tools = ["//compiler/damlc"],
visibility = ["//visibility:public"],
)

genrule(
name = "daml-base-hoogle-docs",
srcs = [
":daml-base-files",
":daml-prim.json",
":daml-stdlib.json",
":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)",
cmd = """
$(location //compiler/damlc) -- docs \
--output=$(OUTS) \
--input-format=json \
--format=Hoogle \
--prefix=$(location :daml-base-hoogle-prefix) \
$(location :daml-stdlib.json) $(location :daml-prim.json)
""",
tools = ["//compiler/damlc"],
visibility = ["//visibility:public"],
)

genrule(
name = "daml-base-rst-docs",
srcs = [
":daml-base-files",
":daml-prim.json",
":daml-stdlib.json",
":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)",
cmd = """
$(location //compiler/damlc) -- docs \
--output=$(OUTS) \
--input-format=json \
--format=Rst \
--prefix=$(location :daml-base-rst-prefix) \
$(location :daml-stdlib.json) $(location :daml-prim.json)
""",
tools = ["//compiler/damlc"],
visibility = ["//visibility:public"],
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
-- satisfy the regex /[a-z0-9]+(-[a-z0-9]+)*/). It's also nice for them to be readable.
-- So we generate a human readable tag, and append a hash to guarantee uniqueness.

module DA.Daml.Doc.Render.Anchor
module DA.Daml.Doc.Anchor
( Anchor
, moduleAnchor
, classAnchor
Expand All @@ -24,11 +24,9 @@ import Data.Hashable
import qualified Data.Text as T
import qualified Data.Char as C

type Anchor = T.Text

moduleAnchor :: Modulename -> Anchor
-- calculating a hash on String instead of Data.Text as hash output of the later is different on Windows than other OSes
moduleAnchor m = T.intercalate "-" ["module", convertModulename m, hashText . T.unpack . unModulename $ m]
moduleAnchor m = Anchor $ T.intercalate "-" ["module", convertModulename m, hashText . T.unpack . unModulename $ m]

convertModulename :: Modulename -> T.Text
convertModulename = T.toLower . T.replace "." "-" . T.replace "_" "" . unModulename
Expand All @@ -47,10 +45,9 @@ dataAnchor m n = anchor "data" m (unTypename n) ()
constrAnchor m n = anchor "constr" m (unTypename n) ()
functionAnchor m n = anchor "function" m (unFieldname n)


anchor :: Hashable v => T.Text -> Modulename -> T.Text -> v -> Anchor
-- calculating a hash on String instead of Data.Text as hash output of the later is different on Windows than other OSes
anchor k m n v = T.intercalate "-" [k, convertModulename m, expandOps n, hashText (T.unpack k, T.unpack (unModulename m), T.unpack n, v)]
anchor k m n v = Anchor $ T.intercalate "-" [k, convertModulename m, expandOps n, hashText (T.unpack k, T.unpack (unModulename m), T.unpack n, v)]
where
expandOps :: T.Text -> T.Text
expandOps = T.pack . replaceEmpty . concatMap expandOp . T.unpack
Expand Down
Loading

0 comments on commit a8f9817

Please sign in to comment.