Skip to content

Commit

Permalink
Explicit export lists in the DAML-LF Haskell module (digital-asset#813)
Browse files Browse the repository at this point in the history
* Delete an entirely unused module

* Delete an entirely unused module

* Switch the compiler to use EUnit over mkEUnit

* Delete an unused module

* Whitespace only

* Clean up the API for World, don't expose the internals, better creation functions

* Clean up the type checker environment, don't expose the internals of Gamma, add a few helper functions

* Delete unused functions

* Explicit module export lists

* Fix the nub replacement hints

* Turn on the warning that we require module export lists

* Add an explicit export list
  • Loading branch information
neil-da authored and hurryabit committed May 2, 2019
1 parent 935155c commit 536b1ea
Show file tree
Hide file tree
Showing 22 changed files with 112 additions and 248 deletions.
11 changes: 7 additions & 4 deletions .hlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,14 @@
# Under Linux/MacOS, Foreign function interface language pragma is unused.
- ignore: {name: Unused LANGUAGE pragma, within: DA.Sdk.Cli.System}

# Off by default hints we like
- warn: {name: Use module export list}

# Condemn nub and friends
- warn: {lhs: nub (sort x), rhs: Data.List.Extended.nubSort x}
- warn: {lhs: nub, rhs: Data.List.Extended.nubOrd}
- warn: {lhs: nubBy, rhs: Data.List.Extended.nubOrdBy}
- warn: {lhs: Data.List.Extra.nubOn, rhs: Data.List.Extended.nubOrdOn}
- warn: {lhs: nub (sort x), rhs: Data.List.Extra.nubSort x}
- warn: {lhs: nub, rhs: Data.List.Extra.nubOrd}
- warn: {lhs: nubBy, rhs: Data.List.Extra.nubOrdBy}
- warn: {lhs: Data.List.Extra.nubOn, rhs: Data.List.Extra.nubOrdOn}

# DA specific hints
- warn: {lhs: Data.Text.pack (DA.Pretty.renderPlain x), rhs: DA.Pretty.renderPlain x}
Expand Down
2 changes: 1 addition & 1 deletion bazel_tools/client_server_test/runner/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- SPDX-License-Identifier: Apache-2.0

{-# LANGUAGE OverloadedStrings #-}
module Main where
module Main(main) where

import qualified Data.Text as T
import qualified Data.Text.IO as T
Expand Down
7 changes: 3 additions & 4 deletions compiler/daml-lf-ast/src/DA/Daml/LF/Ast.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ module DA.Daml.LF.Ast
( module LF
) where

import DA.Daml.LF.Ast.Base as LF
import DA.Daml.LF.Ast.Make as LF
import DA.Daml.LF.Ast.Util as LF
import DA.Daml.LF.Ast.Base as LF
import DA.Daml.LF.Ast.Util as LF
import DA.Daml.LF.Ast.Version as LF
import DA.Daml.LF.Ast.World as LF
import DA.Daml.LF.Ast.World as LF
import DA.Daml.LF.Ast.Pretty ()
4 changes: 3 additions & 1 deletion compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Base.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
-- | Types and pretty-printer for the AST of the DAML Ledger Fragment.
module DA.Daml.LF.Ast.Base where
module DA.Daml.LF.Ast.Base(
module DA.Daml.LF.Ast.Base
) where

import DA.Prelude

Expand Down
141 changes: 0 additions & 141 deletions compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Conversion.hs

This file was deleted.

23 changes: 0 additions & 23 deletions compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Make.hs

This file was deleted.

15 changes: 10 additions & 5 deletions compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Optics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE RankNTypes #-}
module DA.Daml.LF.Ast.Optics where
module DA.Daml.LF.Ast.Optics(
moduleModuleRef,
unlocate,
moduleExpr,
dataConsType,
_PRSelfModule,
exprPartyLiteral,
exprValueRef,
templateExpr
) where

import DA.Prelude

Expand Down Expand Up @@ -75,10 +84,6 @@ moduleExpr f (Module name path flags dataTypes values templates) =
<$> (NM.traverse . _dvalBody) f values
<*> (NM.traverse . templateExpr) f templates

packageExpr :: Traversal' Package Expr
packageExpr f (Package version modules) =
Package version <$> (NM.traverse . moduleExpr) f modules

dataConsType :: Traversal' DataCons Type
dataConsType f = \case
DataRecord fs -> DataRecord <$> (traverse . _2) f fs
Expand Down
10 changes: 6 additions & 4 deletions compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Pretty.hs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE PatternSynonyms #-}
module DA.Daml.LF.Ast.Pretty where
module DA.Daml.LF.Ast.Pretty(
prettyName,
prettyDottedName,
prettyQualified,
(<:>)
) where

import DA.Prelude

Expand Down Expand Up @@ -265,9 +270,6 @@ prettyTyArg t = type_ ("@" <> pPrintPrec prettyNormal precHighest t)
prettyBTyArg :: BuiltinType -> Doc ann
prettyBTyArg = prettyTyArg . TBuiltin

prettyTyArgTpl :: Qualified TypeConName -> Doc ann
prettyTyArgTpl tpl = prettyTyArg (TCon tpl)

prettyTmArg :: Expr -> Doc ann
prettyTmArg = pPrintPrec prettyNormal (succ precEApp)

Expand Down
9 changes: 8 additions & 1 deletion compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Recursive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@

-- | This module provides all the boilerplate necessary to make the DAML-LF AST
-- work with the recursion-schemes package.
module DA.Daml.LF.Ast.Recursive where
module DA.Daml.LF.Ast.Recursive(
ExprF(..),
UpdateF(..),
ScenarioF(..),
BindingF(..),
TypeF(..),
retrieveByKeyFKey
) where

import Data.Functor.Foldable

Expand Down
28 changes: 0 additions & 28 deletions compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Subst.hs

This file was deleted.

2 changes: 1 addition & 1 deletion compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Util.hs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE OverloadedStrings #-}
module DA.Daml.LF.Ast.Util where
module DA.Daml.LF.Ast.Util(module DA.Daml.LF.Ast.Util) where

import DA.Prelude

Expand Down
2 changes: 1 addition & 1 deletion compiler/daml-lf-ast/src/DA/Daml/LF/Ast/Version.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE OverloadedStrings #-}
module DA.Daml.LF.Ast.Version where
module DA.Daml.LF.Ast.Version(module DA.Daml.LF.Ast.Version) where

import DA.Prelude
import DA.Pretty
Expand Down
33 changes: 21 additions & 12 deletions compiler/daml-lf-ast/src/DA/Daml/LF/Ast/World.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,20 @@

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell #-}
module DA.Daml.LF.Ast.World where

import DA.Prelude
module DA.Daml.LF.Ast.World(
World,
initWorld,
initWorldSelf,
extendWorldSelf,
LookupError,
lookupTemplate,
lookupDataType,
lookupChoice,
lookupValue,
lookupModule
) where

import DA.Pretty

import Control.Lens
Expand All @@ -21,14 +32,11 @@ import DA.Daml.LF.Ast.Version
-- the modules of the current package. The latter shall always be closed under
-- module dependencies but we don't enforce this here.
data World = World
{ worldImported :: HMS.HashMap PackageId Package
, worldSelf :: Package
{ _worldImported :: HMS.HashMap PackageId Package
, _worldSelf :: Package
}

makeUnderscoreLenses ''World

emptyWorld :: Version -> World
emptyWorld = initWorld []
makeLensesFor [("_worldSelf","worldSelf")] ''World

-- | Construct the 'World' from only the imported packages.
initWorld :: [(PackageId, Package)] -> Version -> World
Expand All @@ -46,12 +54,13 @@ initWorld importedPkgs version =
PRSelf -> PRImport pkgId
ref@PRImport{} -> ref

singlePackageWorld :: Package -> World
singlePackageWorld = World HMS.empty
-- | Create a World with an initial self package
initWorldSelf :: [(PackageId, Package)] -> Version -> Package -> World
initWorldSelf a b c = (initWorld a b){_worldSelf = c}

-- | Extend the 'World' by a module in the current package.
extendWorld :: Module -> World -> World
extendWorld = over (_worldSelf . _packageModules) . NM.insert
extendWorldSelf :: Module -> World -> World
extendWorldSelf = over (worldSelf . _packageModules) . NM.insert

data LookupError
= LEPackage !PackageId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ inferPackage :: [(PackageId, Package)] -> Package -> Either String Package
inferPackage pkgDeps (Package version mods0) = do
let infer1 (mods1, world0) mod0 = do
mod1 <- inferModule world0 mod0
pure (NM.insert mod1 mods1, extendWorld mod1 world0)
pure (NM.insert mod1 mods1, extendWorldSelf mod1 world0)
Package version . fst <$> foldlM infer1 (NM.empty, initWorld pkgDeps version) mods0
Loading

0 comments on commit 536b1ea

Please sign in to comment.