diff --git a/compiler/damlc/daml-lf-conversion/src/DA/Daml/LFConversion.hs b/compiler/damlc/daml-lf-conversion/src/DA/Daml/LFConversion.hs index 93d33b8622d7..5dce65bbbdf7 100644 --- a/compiler/damlc/daml-lf-conversion/src/DA/Daml/LFConversion.hs +++ b/compiler/damlc/daml-lf-conversion/src/DA/Daml/LFConversion.hs @@ -75,6 +75,7 @@ module DA.Daml.LFConversion ( convertModule + , convertModuleName , sourceLocToRange , convertRationalBigNumeric -- exposed for festing , runConvertM -- exposed for testing diff --git a/compiler/damlc/daml-preprocessor/BUILD.bazel b/compiler/damlc/daml-preprocessor/BUILD.bazel index 96ec5cb5bda8..3d897af34814 100644 --- a/compiler/damlc/daml-preprocessor/BUILD.bazel +++ b/compiler/damlc/daml-preprocessor/BUILD.bazel @@ -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", ], diff --git a/compiler/damlc/daml-preprocessor/src/DA/Daml/Preprocessor.hs b/compiler/damlc/daml-preprocessor/src/DA/Daml/Preprocessor.hs index 30f343230bdd..9c97621fba73 100644 --- a/compiler/damlc/daml-preprocessor/src/DA/Daml/Preprocessor.hs +++ b/compiler/damlc/daml-preprocessor/src/DA/Daml/Preprocessor.hs @@ -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 @@ -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. @@ -164,7 +171,7 @@ checkModuleName (GHC.L _ m) 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] + | 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)] diff --git a/compiler/damlc/tests/daml-test-files/InternalImport.daml b/compiler/damlc/tests/daml-test-files/InternalImport.daml index 630b3ed96877..acb603747f0a 100644 --- a/compiler/damlc/tests/daml-test-files/InternalImport.daml +++ b/compiler/damlc/tests/daml-test-files/InternalImport.daml @@ -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 internal module DA.Internal.RebindableSyntax is not allowed. module InternalImport where -import DA.Internal.Template +import DA.Internal.Template () +import DA.Internal.RebindableSyntax ()