summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2020-07-28 12:58:53 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-07-30 22:54:48 -0400
commit7c274cd530cc42a26028050b75d56b3437e06ec1 (patch)
tree235ec0129a613d35ec8b73da6e4f787083b90b1c
parent9f71f69714255165d0fdc2790a588487ff9439dc (diff)
downloadhaskell-7c274cd530cc42a26028050b75d56b3437e06ec1.tar.gz
Fix minimal imports dump for boot files (fix #18497)
-rw-r--r--compiler/GHC/Rename/Names.hs22
-rw-r--r--compiler/GHC/Tc/Module.hs2
-rw-r--r--testsuite/tests/rename/should_compile/Makefile4
-rw-r--r--testsuite/tests/rename/should_compile/T18497.stdout5
-rw-r--r--testsuite/tests/rename/should_compile/T18497_Bar.hs14
-rw-r--r--testsuite/tests/rename/should_compile/T18497_Bar.hs-boot9
-rw-r--r--testsuite/tests/rename/should_compile/T18497_Foo.hs8
-rw-r--r--testsuite/tests/rename/should_compile/T18497_Foo.hs-boot5
-rw-r--r--testsuite/tests/rename/should_compile/all.T1
9 files changed, 60 insertions, 10 deletions
diff --git a/compiler/GHC/Rename/Names.hs b/compiler/GHC/Rename/Names.hs
index d339a841cc..fb91f940ba 100644
--- a/compiler/GHC/Rename/Names.hs
+++ b/compiler/GHC/Rename/Names.hs
@@ -1234,11 +1234,11 @@ lookupChildren all_kids rdr_items
*********************************************************
-}
-reportUnusedNames :: TcGblEnv -> RnM ()
-reportUnusedNames gbl_env
+reportUnusedNames :: TcGblEnv -> HscSource -> RnM ()
+reportUnusedNames gbl_env hsc_src
= do { keep <- readTcRef (tcg_keep gbl_env)
; traceRn "RUN" (ppr (tcg_dus gbl_env))
- ; warnUnusedImportDecls gbl_env
+ ; warnUnusedImportDecls gbl_env hsc_src
; warnUnusedTopBinds $ unused_locals keep
; warnMissingSignatures gbl_env }
where
@@ -1360,8 +1360,8 @@ type ImportDeclUsage
, [GlobalRdrElt] -- What *is* used (normalised)
, [Name] ) -- What is imported but *not* used
-warnUnusedImportDecls :: TcGblEnv -> RnM ()
-warnUnusedImportDecls gbl_env
+warnUnusedImportDecls :: TcGblEnv -> HscSource -> RnM ()
+warnUnusedImportDecls gbl_env hsc_src
= do { uses <- readMutVar (tcg_used_gres gbl_env)
; let user_imports = filterOut
(ideclImplicit . unLoc)
@@ -1383,7 +1383,7 @@ warnUnusedImportDecls gbl_env
mapM_ (warnUnusedImport Opt_WarnUnusedImports fld_env) usage
; whenGOptM Opt_D_dump_minimal_imports $
- printMinimalImports usage }
+ printMinimalImports hsc_src usage }
findImportUsage :: [LImportDecl GhcRn]
-> [GlobalRdrElt]
@@ -1619,9 +1619,9 @@ getMinimalImports = mapM mk_minimal
all_non_overloaded = all (not . flIsOverloaded)
-printMinimalImports :: [ImportDeclUsage] -> RnM ()
+printMinimalImports :: HscSource -> [ImportDeclUsage] -> RnM ()
-- See Note [Printing minimal imports]
-printMinimalImports imports_w_usage
+printMinimalImports hsc_src imports_w_usage
= do { imports' <- getMinimalImports imports_w_usage
; this_mod <- getModule
; dflags <- getDynFlags
@@ -1638,7 +1638,11 @@ printMinimalImports imports_w_usage
| Just d <- dumpDir dflags = d </> basefn
| otherwise = basefn
where
- basefn = moduleNameString (moduleName this_mod) ++ ".imports"
+ suffix = case hsc_src of
+ HsBootFile -> ".imports-boot"
+ HsSrcFile -> ".imports"
+ HsigFile -> ".imports"
+ basefn = moduleNameString (moduleName this_mod) ++ suffix
to_ie_post_rn_var :: (HasOccName name) => Located name -> LIEWrappedName name
diff --git a/compiler/GHC/Tc/Module.hs b/compiler/GHC/Tc/Module.hs
index 277a6fec7d..512bf21f54 100644
--- a/compiler/GHC/Tc/Module.hs
+++ b/compiler/GHC/Tc/Module.hs
@@ -301,7 +301,7 @@ tcRnModuleTcRnM hsc_env mod_sum
-- Do this /after/ typeinference, so that when reporting
-- a function with no type signature we can give the
-- inferred type
- reportUnusedNames tcg_env
+ reportUnusedNames tcg_env hsc_src
; -- add extra source files to tcg_dependent_files
addDependentFiles src_files
; tcg_env <- runTypecheckerPlugin mod_sum hsc_env tcg_env
diff --git a/testsuite/tests/rename/should_compile/Makefile b/testsuite/tests/rename/should_compile/Makefile
index 6e41534ca8..495efed5cc 100644
--- a/testsuite/tests/rename/should_compile/Makefile
+++ b/testsuite/tests/rename/should_compile/Makefile
@@ -56,3 +56,7 @@ T7969:
'$(TEST_HC)' $(TEST_HC_OPTS) -c T7969a.hs
'$(TEST_HC)' $(TEST_HC_OPTS) -c T7969.hs -ddump-minimal-imports
cat T7969.imports
+
+T18497:
+ '$(TEST_HC)' $(TEST_HC_OPTS) -fno-code T18497_Foo.hs T18497_Bar.hs -ddump-minimal-imports
+ cat T18497_Bar.imports-boot
diff --git a/testsuite/tests/rename/should_compile/T18497.stdout b/testsuite/tests/rename/should_compile/T18497.stdout
new file mode 100644
index 0000000000..d3118818ac
--- /dev/null
+++ b/testsuite/tests/rename/should_compile/T18497.stdout
@@ -0,0 +1,5 @@
+[1 of 4] Compiling T18497_Foo[boot] ( T18497_Foo.hs-boot, nothing )
+[2 of 4] Compiling T18497_Bar[boot] ( T18497_Bar.hs-boot, nothing )
+[3 of 4] Compiling T18497_Foo ( T18497_Foo.hs, nothing )
+[4 of 4] Compiling T18497_Bar ( T18497_Bar.hs, nothing )
+import {-# SOURCE #-} T18497_Foo ( X )
diff --git a/testsuite/tests/rename/should_compile/T18497_Bar.hs b/testsuite/tests/rename/should_compile/T18497_Bar.hs
new file mode 100644
index 0000000000..30675fd1b1
--- /dev/null
+++ b/testsuite/tests/rename/should_compile/T18497_Bar.hs
@@ -0,0 +1,14 @@
+module T18497_Bar where
+
+import T18497_Foo
+
+data Y = SomeY X | NoY
+
+blah :: Y
+blah = NoY
+
+blip :: Y
+blip = SomeY foo
+
+woop NoX = NoY
+woop (SomeX y _) = y
diff --git a/testsuite/tests/rename/should_compile/T18497_Bar.hs-boot b/testsuite/tests/rename/should_compile/T18497_Bar.hs-boot
new file mode 100644
index 0000000000..0eeb59f436
--- /dev/null
+++ b/testsuite/tests/rename/should_compile/T18497_Bar.hs-boot
@@ -0,0 +1,9 @@
+module T18497_Bar where
+
+import {-# SOURCE #-} T18497_Foo
+
+data Y
+
+blah :: Y
+
+woop :: X -> Y
diff --git a/testsuite/tests/rename/should_compile/T18497_Foo.hs b/testsuite/tests/rename/should_compile/T18497_Foo.hs
new file mode 100644
index 0000000000..09f048fe51
--- /dev/null
+++ b/testsuite/tests/rename/should_compile/T18497_Foo.hs
@@ -0,0 +1,8 @@
+module T18497_Foo where
+
+import {-# SOURCE #-} T18497_Bar
+
+data X = SomeX Y Y | NoX
+
+foo :: X
+foo = SomeX blah (woop NoX)
diff --git a/testsuite/tests/rename/should_compile/T18497_Foo.hs-boot b/testsuite/tests/rename/should_compile/T18497_Foo.hs-boot
new file mode 100644
index 0000000000..acf3e8245c
--- /dev/null
+++ b/testsuite/tests/rename/should_compile/T18497_Foo.hs-boot
@@ -0,0 +1,5 @@
+module T18497_Foo where
+
+data X
+
+foo :: X
diff --git a/testsuite/tests/rename/should_compile/all.T b/testsuite/tests/rename/should_compile/all.T
index 6bcb9377bd..9a519483d5 100644
--- a/testsuite/tests/rename/should_compile/all.T
+++ b/testsuite/tests/rename/should_compile/all.T
@@ -174,3 +174,4 @@ test('T17244B', normal, compile, [''])
test('T17244C', normal, compile, [''])
test('T17832', [], multimod_compile, ['T17832M1', 'T17832M2'])
test('T17837', normal, compile, [''])
+test('T18497', [], makefile_test, ['T18497'])