Add daml-util-ghc lib (#11260)

* Extract UtilGHC module from daml-lf-conversion to its own library

* Drop daml-preprocessor dependency on daml-lf-conversion

changelog_begin
changelog_end
This commit is contained in:
Moisés Ackerman 2021-10-15 17:52:29 +02:00 committed by GitHub
parent 68a93cf70f
commit 82fa229385
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 40 additions and 12 deletions

View File

@ -115,7 +115,7 @@
# - {name: Control.Arrow, within: []} # Certain modules are banned entirely
#
- functions:
- {name: unsafePerformIO, within: [DA.Daml.LFConversion.UtilGHC]}
- {name: unsafePerformIO, within: [DA.Daml.UtilGHC]}
- {name: unsafeInterleaveIO, within: []}
- {name: unsafeDupablePerformIO, within: []}
- {name: setCurrentDirectory, within: [DA.Daml.Assistant.Tests, Main]}

View File

@ -51,6 +51,7 @@ da_haskell_library(
"//compiler/daml-lf-reader",
"//compiler/daml-lf-tools",
"//compiler/damlc/daml-doctest",
"//compiler/damlc/daml-ghc-util",
"//compiler/damlc/daml-ide-core",
"//compiler/damlc/daml-lf-conversion",
"//compiler/damlc/daml-opts",

View File

@ -34,9 +34,9 @@ import DA.Daml.LF.Ast.Optics (packageRefs)
import qualified DA.Daml.LF.ReplClient as ReplClient
import DA.Daml.LFConversion (convertModule)
import DA.Daml.LFConversion.UtilLF (buildPackage)
import DA.Daml.LFConversion.UtilGHC
import DA.Daml.Options.Types
import qualified DA.Daml.Preprocessor.Records as Preprocessor
import DA.Daml.UtilGHC
import Data.Bifunctor (first)
import Data.Functor.Alt
import Data.Functor.Bind

View File

@ -0,0 +1,27 @@
# Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.
# SPDX-License-Identifier: Apache-2.0
load(
"//bazel_tools:haskell.bzl",
"da_haskell_library",
)
da_haskell_library(
name = "daml-ghc-util",
srcs = glob(["src/**/*.hs"]),
hackage_deps = [
"base",
"bytestring",
"containers",
"ghc-lib-parser",
"ghc-lib",
"text",
"uniplate",
],
repl_ghci_args = ["-hide-package=ghc"],
src_strip_prefix = "src",
visibility = ["//visibility:public"],
deps = [
"//compiler/daml-lf-ast",
],
)

View File

@ -12,8 +12,8 @@
-- * Call runGhc, use runGhcFast instead. It's faster and doesn't require config we don't have.
--
-- * Call setSessionDynFlags, use modifyDynFlags instead. It's faster and avoids loading packages.
module DA.Daml.LFConversion.UtilGHC(
module DA.Daml.LFConversion.UtilGHC
module DA.Daml.UtilGHC (
module DA.Daml.UtilGHC
) where
import "ghc-lib" GHC hiding (convertLit)
@ -327,3 +327,7 @@ collectNonRecLets = \case
makeNonRecLets :: [(GHC.Var, GHC.Expr Var)] -> GHC.Expr Var -> GHC.Expr Var
makeNonRecLets lets body =
foldr (\(x,y) b -> Let (NonRec x y) b) body lets
convertModuleName :: GHC.ModuleName -> LF.ModuleName
convertModuleName =
LF.ModuleName . T.split (== '.') . fsToText . moduleNameFS

View File

@ -38,6 +38,7 @@ da_haskell_library(
"//compiler/daml-lf-ast",
"//compiler/daml-lf-proto",
"//compiler/daml-lf-tools",
"//compiler/damlc/daml-ghc-util",
"//libs-haskell/da-hs-base",
],
)

View File

@ -74,7 +74,6 @@
module DA.Daml.LFConversion
( convertModule
, convertModuleName
, sourceLocToRange
, convertRationalBigNumeric -- exposed for festing
, runConvertM -- exposed for testing
@ -82,9 +81,9 @@ module DA.Daml.LFConversion
) where
import DA.Daml.LFConversion.Primitives
import DA.Daml.LFConversion.UtilGHC
import DA.Daml.LFConversion.UtilLF
import DA.Daml.LFConversion.MetadataEncoding
import DA.Daml.UtilGHC
import Development.IDE.Types.Diagnostics
import Development.IDE.Types.Location
@ -1894,10 +1893,6 @@ convertCoercion env co = evalStateT (go env co) 0
flv = tyConFlavour t
isSatNewTyCon _ _ = Nothing
convertModuleName :: GHC.ModuleName -> LF.ModuleName
convertModuleName =
ModuleName . T.split (== '.') . fsToText . moduleNameFS
qualify :: Env -> GHC.Module -> a -> ConvertM (Qualified a)
qualify env m x = do
unitId <- convertUnitId (envModuleUnitId env) (envPkgMap env) $ GHC.moduleUnitId m

View File

@ -35,7 +35,7 @@ da_haskell_library(
"//compiler/daml-lf-ast",
"//compiler/daml-lf-proto",
"//compiler/daml-lf-tools",
"//compiler/damlc/daml-lf-conversion",
"//compiler/damlc/daml-ghc-util",
"//compiler/damlc/stable-packages:stable-packages-lib",
"//libs-haskell/bazel-runfiles",
"//libs-haskell/da-hs-base",

View File

@ -8,11 +8,11 @@ module DA.Daml.Preprocessor
, noPreprocessor
) where
import DA.Daml.LFConversion (convertModuleName)
import DA.Daml.Preprocessor.Records
import DA.Daml.Preprocessor.Generics
import DA.Daml.Preprocessor.EnumType
import DA.Daml.StablePackages (stablePackageByModuleName)
import DA.Daml.UtilGHC (convertModuleName)
import Development.IDE.Types.Options
import qualified "ghc-lib" GHC