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

git at git.haskell.org git at git.haskell.org
Tue Jul 29 14:24:36 UTC 2014


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

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

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

commit 3219ed9629a75b3b8b6757ee3ab5a8acc70f6900
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


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

3219ed9629a75b3b8b6757ee3ab5a8acc70f6900
 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 bbbed51..83a9591 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 tcPatSynWrapper patsyns
                    ; let extra_binds = [ (NonRecursive, wrapper) | wrapper <- patsyn_wrappers ]
                    ; return (extra_binds, thing) }



More information about the ghc-commits mailing list