[commit: ghc] wip/pattern-synonyms: Add note about renaming of pattern synonym wrappers (a9c7f64)

git at git.haskell.org git at git.haskell.org
Tue Jul 29 09:28:45 UTC 2014


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

On branch  : wip/pattern-synonyms
Link       : http://ghc.haskell.org/trac/ghc/changeset/a9c7f64de332584105fa427f53e15faf6f8a4015/ghc

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

commit a9c7f64de332584105fa427f53e15faf6f8a4015
Author: Dr. ERDI Gergo <gergo at erdi.hu>
Date:   Tue Jul 29 11:28:33 2014 +0200

    Add note about renaming of pattern synonym wrappers


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

a9c7f64de332584105fa427f53e15faf6f8a4015
 compiler/rename/RnBinds.lhs    | 27 +++++++++++++++++++++++++++
 compiler/typecheck/TcBinds.lhs |  1 +
 2 files changed, 28 insertions(+)

diff --git a/compiler/rename/RnBinds.lhs b/compiler/rename/RnBinds.lhs
index 4efd847..0f9f44a 100644
--- a/compiler/rename/RnBinds.lhs
+++ b/compiler/rename/RnBinds.lhs
@@ -582,6 +582,7 @@ rnPatSynBind _sig_fn bind@(PSB { psb_id = L _ name
 
         ; fvs' `seq` -- See Note [Free-variable space leak]
           return (bind', [name], fvs1)
+          -- See Note [Pattern synonym wrappers don't yield dependencies]
       }
   where
     lookupVar = wrapLocM lookupOccRn
@@ -592,6 +593,32 @@ rnPatSynBind _sig_fn bind@(PSB { psb_id = L _ name
            2 (ptext (sLit "Use -XPatternSynonyms to enable this extension"))
 
 {-
+Note [Pattern synonym wrappers don't yield dependencies]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+When renaming a pattern synonym that has an explicit wrapper,
+references in the wrapper definition should not be used when
+calculating dependencies. For example, consider the following pattern
+synonym definition:
+
+pattern P x <- C1 x where
+  P x = f (C1 x)
+
+f (P x) = C2 x
+
+In this case, 'P' needs to be typechecked in two passes:
+
+1. Typecheck the pattern definition of 'P', which fully determines the
+type of 'P'. This step doesn't require knowing anything about 'f',
+since the wrapper definition is not looked at.
+
+2. Typecheck the wrapper definition, which needs the typechecked
+definition of 'f' to be in scope.
+
+This behaviour is implemented in 'tcValBinds', but it crucially
+depends on 'P' not being put in a recursive group with 'f' (which
+would make it look like a recursive pattern synonym a la 'pattern P =
+P' which is unsound and rejected).
 
 -}
 
diff --git a/compiler/typecheck/TcBinds.lhs b/compiler/typecheck/TcBinds.lhs
index 8fb97b6..936502e 100644
--- a/compiler/typecheck/TcBinds.lhs
+++ b/compiler/typecheck/TcBinds.lhs
@@ -318,6 +318,7 @@ tcValBinds top_lvl binds sigs thing_inside
         ; tcExtendIdEnv2 [(idName id, id) | id <- poly_ids] $ do
             { (binds', (extra_binds', thing)) <- tcBindGroups top_lvl sig_fn prag_fn binds $ do
                    { thing <- thing_inside
+                     -- See Note [Pattern synonym wrappers don't yield dependencies]
                    ; patsyn_wrappers <- mapM tc_patsyn_wrapper patsyns
                    ; let extra_binds = [ (NonRecursive, wrapper) | wrapper <- patsyn_wrappers ]
                    ; return (extra_binds, thing) }



More information about the ghc-commits mailing list