[commit: ghc] master: Error eagerly after renaming failures in reifyInstances (d618649)

git at git.haskell.org git at git.haskell.org
Fri Jul 28 15:52:27 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/d6186496d414638aa66a677bb4e555dba376ec97/ghc

>---------------------------------------------------------------

commit d6186496d414638aa66a677bb4e555dba376ec97
Author: Ryan Scott <ryan.gl.scott at gmail.com>
Date:   Fri Jul 28 11:35:22 2017 -0400

    Error eagerly after renaming failures in reifyInstances
    
    Summary:
    Previously, if `reifyInstances` failed to discover a `Name` during
    renaming, it would blindy charge into typechecking, at which point GHC would
    become very confused at the absence of that `Name` and throw an internal error.
    A simple workaround is to fail eagerly after renaming errors.
    
    Test Plan: make test TEST=T13837
    
    Reviewers: goldfire, austin, bgamari, simonpj
    
    Reviewed By: simonpj
    
    Subscribers: simonpj, rwbarton, thomie
    
    GHC Trac Issues: #13837
    
    Differential Revision: https://phabricator.haskell.org/D3793


>---------------------------------------------------------------

d6186496d414638aa66a677bb4e555dba376ec97
 compiler/typecheck/TcSplice.hs   |  6 +++++-
 testsuite/tests/th/T13837.hs     | 10 ++++++++++
 testsuite/tests/th/T13837.stderr | 10 ++++++++++
 testsuite/tests/th/all.T         |  1 +
 4 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/compiler/typecheck/TcSplice.hs b/compiler/typecheck/TcSplice.hs
index 824227a..266a4df 100644
--- a/compiler/typecheck/TcSplice.hs
+++ b/compiler/typecheck/TcSplice.hs
@@ -1138,7 +1138,11 @@ reifyInstances th_nm th_tys
         ; let tv_rdrs = freeKiTyVarsAllVars free_vars
           -- Rename  to HsType Name
         ; ((tv_names, rn_ty), _fvs)
-            <- bindLRdrNames tv_rdrs $ \ tv_names ->
+            <- checkNoErrs $ -- If there are out-of-scope Names here, then we
+                             -- must error before proceeding to typecheck the
+                             -- renamed type, as that will result in GHC
+                             -- internal errors (#13837).
+               bindLRdrNames tv_rdrs $ \ tv_names ->
                do { (rn_ty, fvs) <- rnLHsType doc rdr_ty
                   ; return ((tv_names, rn_ty), fvs) }
         ; (_tvs, ty)
diff --git a/testsuite/tests/th/T13837.hs b/testsuite/tests/th/T13837.hs
new file mode 100644
index 0000000..3d33341
--- /dev/null
+++ b/testsuite/tests/th/T13837.hs
@@ -0,0 +1,10 @@
+{-# LANGUAGE TemplateHaskell #-}
+module T13837 where
+
+import Language.Haskell.TH.Lib
+import Language.Haskell.TH.Syntax
+
+test_local_tyfam_expansion :: String
+test_local_tyfam_expansion =
+  $(do fam_name <- newName "Fam"
+       stringE . show =<< qReifyInstances fam_name [])
diff --git a/testsuite/tests/th/T13837.stderr b/testsuite/tests/th/T13837.stderr
new file mode 100644
index 0000000..53700b5
--- /dev/null
+++ b/testsuite/tests/th/T13837.stderr
@@ -0,0 +1,10 @@
+
+T13837.hs:9:5: error:
+    • The exact Name ‘Fam’ is not in scope
+        Probable cause: you used a unique Template Haskell name (NameU), 
+        perhaps via newName, but did not bind it
+        If that's it, then -ddump-splices might be useful
+    • In the argument of reifyInstances: Fam_0
+      In the untyped splice:
+        $(do fam_name <- newName "Fam"
+             stringE . show =<< qReifyInstances fam_name [])
diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T
index df31162..b52042b 100644
--- a/testsuite/tests/th/all.T
+++ b/testsuite/tests/th/all.T
@@ -389,5 +389,6 @@ test('T13618', normal, compile_and_run, ['-v0'])
 test('T13642', normal, compile_fail, ['-v0'])
 test('T13781', normal, compile, ['-v0'])
 test('T13782', normal, compile, [''])
+test('T13837', normal, compile_fail, ['-v0 -dsuppress-uniques'])
 test('T13856', normal, compile, ['-v0 -ddump-splices -dsuppress-uniques'])
 test('T13968', normal, compile_fail, ['-v0'])



More information about the ghc-commits mailing list