Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow imports of internal modules #10397

Merged
merged 2 commits into from
Jul 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@

module DA.Daml.LFConversion
( convertModule
, convertModuleName
, sourceLocToRange
, convertRationalBigNumeric -- exposed for festing
, runConvertM -- exposed for testing
Expand Down
2 changes: 2 additions & 0 deletions compiler/damlc/daml-preprocessor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ da_haskell_library(
"//compiler/daml-lf-ast",
"//compiler/daml-lf-proto",
"//compiler/daml-lf-tools",
"//compiler/damlc/daml-lf-conversion",
"//compiler/damlc/stable-packages:stable-packages-lib",
"//libs-haskell/bazel-runfiles",
"//libs-haskell/da-hs-base",
],
Expand Down
11 changes: 9 additions & 2 deletions compiler/damlc/daml-preprocessor/src/DA/Daml/Preprocessor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +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 Development.IDE.Types.Options
import qualified "ghc-lib" GHC
Expand Down Expand Up @@ -47,6 +49,11 @@ isInternal (GHC.moduleNameString -> x)
, "DA.Time.Types"
]

isUnstableInternal :: GHC.ModuleName -> Bool
isUnstableInternal moduleName =
isInternal moduleName &&
convertModuleName moduleName `Map.notMember` stablePackageByModuleName

preprocessorExceptions :: Set.Set GHC.ModuleName
preprocessorExceptions = Set.fromList $ map GHC.mkModuleName
-- These modules need to import internal modules.
Expand Down Expand Up @@ -163,8 +170,8 @@ checkModuleName (GHC.L _ m)
-- | We ban people from importing modules such
checkImports :: GHC.ParsedSource -> [(GHC.SrcSpan, String)]
checkImports x =
[ (ss, "Import of internal module " ++ GHC.moduleNameString m ++ " is not allowed.")
| GHC.L ss GHC.ImportDecl{ideclName=GHC.L _ m} <- GHC.hsmodImports $ GHC.unLoc x, isInternal m]
[ (ss, "Import of unstable internal module " ++ GHC.moduleNameString m ++ " is not allowed.")
aherrmann-da marked this conversation as resolved.
Show resolved Hide resolved
| GHC.L ss GHC.ImportDecl{ideclName=GHC.L _ m} <- GHC.hsmodImports $ GHC.unLoc x, isUnstableInternal m]

-- | Emit a warning if the "daml 1.2" version header is present.
checkDamlHeader :: GHC.ParsedSource -> [(GHC.SrcSpan, String)]
Expand Down
5 changes: 3 additions & 2 deletions compiler/damlc/tests/daml-test-files/InternalImport.daml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
-- Copyright (c) 2020, Digital Asset (Switzerland) GmbH and/or its affiliates.
-- All rights reserved.

-- @ERROR range=9:1-9:28; Import of internal module DA.Internal.Template is not allowed.
-- @ERROR range=10:1-10:39; Import of unstable internal module DA.Internal.RebindableSyntax is not allowed.


module InternalImport where

import DA.Internal.Template
import DA.Internal.Template ()
import DA.Internal.RebindableSyntax ()