From 068467ad7afb130c8f6fca45d5e03d7424035b2a Mon Sep 17 00:00:00 2001 From: Andreas Herrmann Date: Fri, 23 Jul 2021 16:51:56 +0200 Subject: [PATCH] Allow imports of internal modules changelog_begin - [Daml Compiler] Imports of internal modules are no longer illegal. Previously, the compiler raised an error when it encountered imports of internal modules such as `DA.Internal.*`. Such imports are now accepted by the compile. Note, however, that internal modules are still not part of the stable API. Fixes https://github.com/digital-asset/daml/issues/10379 changelog_end Previously, imports of internal modules such as --- .../damlc/daml-preprocessor/src/DA/Daml/Preprocessor.hs | 9 +-------- compiler/damlc/tests/daml-test-files/InternalImport.daml | 5 ++--- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/compiler/damlc/daml-preprocessor/src/DA/Daml/Preprocessor.hs b/compiler/damlc/daml-preprocessor/src/DA/Daml/Preprocessor.hs index 30f343230bdd..9e030f0a98b6 100644 --- a/compiler/damlc/daml-preprocessor/src/DA/Daml/Preprocessor.hs +++ b/compiler/damlc/daml-preprocessor/src/DA/Daml/Preprocessor.hs @@ -100,8 +100,7 @@ damlPreprocessor dataDependableExtensions mbUnitId dflags x , checkKinds x ] , preprocErrors = concat - [ checkImports x - , checkDataTypes x + [ checkDataTypes x , checkModuleDefinition x , checkRecordConstructor x , checkModuleName x @@ -160,12 +159,6 @@ checkModuleName (GHC.L _ m) | otherwise = [] --- | 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] - -- | Emit a warning if the "daml 1.2" version header is present. checkDamlHeader :: GHC.ParsedSource -> [(GHC.SrcSpan, String)] checkDamlHeader (GHC.L _ m) diff --git a/compiler/damlc/tests/daml-test-files/InternalImport.daml b/compiler/damlc/tests/daml-test-files/InternalImport.daml index 630b3ed96877..5ad082fff866 100644 --- a/compiler/damlc/tests/daml-test-files/InternalImport.daml +++ b/compiler/damlc/tests/daml-test-files/InternalImport.daml @@ -1,9 +1,8 @@ -- 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. - +-- Internal imports used to be forbidden but are allowed since 1.16.0. module InternalImport where -import DA.Internal.Template +import DA.Internal.Template()