[commit: ghc] master: Add a few comments from SPJ on fixity declarations (5ff4dad)

git at git.haskell.org git at git.haskell.org
Thu Jul 23 14:03:31 UTC 2015


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

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

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

commit 5ff4daddd9bc8f424d8f71fb01ebbbae9d608cdf
Author: Ben Gamari <ben at smart-cactus.org>
Date:   Tue Jul 21 22:27:18 2015 +0200

    Add a few comments from SPJ on fixity declarations


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

5ff4daddd9bc8f424d8f71fb01ebbbae9d608cdf
 compiler/main/HscMain.hs  | 20 +++++++++++++++++++-
 compiler/main/HscTypes.hs |  2 +-
 2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/compiler/main/HscMain.hs b/compiler/main/HscMain.hs
index 3c4b92b..328655c 100644
--- a/compiler/main/HscMain.hs
+++ b/compiler/main/HscMain.hs
@@ -1467,7 +1467,6 @@ hscDeclsWithLocation hsc_env0 str source linenumber =
     -- been done. See the notes at the definition of InteractiveContext
     -- (ic_instances) for more details.
     let defaults = tcg_default tc_gblenv
-    let fix_env  = tcg_fix_env tc_gblenv
 
     {- Desugar it -}
     -- We use a basically null location for iNTERACTIVE
@@ -1521,10 +1520,29 @@ hscDeclsWithLocation hsc_env0 str source linenumber =
 
         new_tythings = map AnId ext_ids ++ map ATyCon tcs ++ map (AConLike . PatSynCon) patsyns
         ictxt        = hsc_IC hsc_env
+        -- See Note [Fixity declarations in GHCi]
+        fix_env      = tcg_fix_env tc_gblenv
         new_ictxt    = extendInteractiveContext ictxt new_tythings cls_insts
                                                 fam_insts defaults fix_env
     return (new_tythings, new_ictxt)
 
+
+{-
+  Note [Fixity declarations in GHCi]
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+  To support fixity declarations on types defined within GHCi (as requested
+  in #10018) we record the fixity environment in InteractiveContext.
+  When we want to evaluate something TcRnDriver.runTcInteractive pulls out this
+  fixity environment and uses it to initialize the global typechecker environment.
+  After the typechecker has finished its business, an updated fixity environment
+  (reflecting whatever fixity declarations were present in the statements we
+  passed it) will be returned from hscParsedStmt. This is passed to
+  updateFixityEnv, which will stuff it back into InteractiveContext, to be
+  used in evaluating the next statement.
+
+-}
+
 hscImport :: HscEnv -> String -> IO (ImportDecl RdrName)
 hscImport hsc_env str = runInteractiveHsc hsc_env $ do
     (L _ (HsModule{hsmodImports=is})) <-
diff --git a/compiler/main/HscTypes.hs b/compiler/main/HscTypes.hs
index f05dbdd..7bceda5 100644
--- a/compiler/main/HscTypes.hs
+++ b/compiler/main/HscTypes.hs
@@ -1436,7 +1436,7 @@ extendInteractiveContext ictxt new_tythings new_cls_insts new_fam_insts defaults
           , ic_instances  = ( new_cls_insts ++ old_cls_insts
                             , new_fam_insts ++ old_fam_insts )
           , ic_default    = defaults
-          , ic_fix_env    = fix_env  -- # 10018
+          , ic_fix_env    = fix_env  -- See Note [Fixity declarations in GHCi]
           }
   where
     new_ids = [id | AnId id <- new_tythings]



More information about the ghc-commits mailing list