summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2020-07-28 12:58:53 +0200
committerBen Gamari <ben@smart-cactus.org>2021-04-07 13:07:05 -0400
commit78eacdb8d359ef2d9cdceeac94b9bc183190e0c7 (patch)
treec582c1d927b501fbeb5477c53a4dc5eeeb6cb6ce
parent426b78b8d0cce951372e27027c530ea1832fa7c6 (diff)
downloadhaskell-78eacdb8d359ef2d9cdceeac94b9bc183190e0c7.tar.gz
Fix minimal imports dump for boot files (fix #18497)
(cherry picked from commit 7c274cd530cc42a26028050b75d56b3437e06ec1)
-rw-r--r--compiler/rename/RnNames.hs22
-rw-r--r--compiler/typecheck/TcRnDriver.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/rename/RnNames.hs b/compiler/rename/RnNames.hs
index 04d16370b4..f17b41ce88 100644
--- a/compiler/rename/RnNames.hs
+++ b/compiler/rename/RnNames.hs
@@ -1231,11 +1231,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
@@ -1357,8 +1357,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)
@@ -1380,7 +1380,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]
@@ -1608,9 +1608,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
@@ -1627,7 +1627,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/typecheck/TcRnDriver.hs b/compiler/typecheck/TcRnDriver.hs
index 36f9c208e1..e70037dede 100644
--- a/compiler/typecheck/TcRnDriver.hs
+++ b/compiler/typecheck/TcRnDriver.hs
@@ -296,7 +296,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 d9fb52d430..4637129219 100644
--- a/testsuite/tests/rename/should_compile/all.T
+++ b/testsuite/tests/rename/should_compile/all.T
@@ -173,3 +173,4 @@ test('T17244A', normal, compile, ['-Wno-error=compat-unqualified-imports'])
test('T17244B', normal, compile, [''])
test('T17244C', normal, compile, [''])
test('T17832', [], multimod_compile, ['T17832M1', 'T17832M2'])
+test('T18497', [], makefile_test, ['T18497'])