From fc6b00498e653d6260e062bdfccbeede0a20fadd Mon Sep 17 00:00:00 2001 From: simonpj Date: Thu, 30 Oct 2003 10:14:59 +0000 Subject: [PATCH] [project @ 2003-10-30 10:14:59 by simonpj] 1. When desugaring a [d| ... |], do not gensym the method names of an instance declaration, else we get very confused! 2. We don't need to make fresh Names in DsMeta.mkGenSym, because the existing Name will do, I believe. We'll do the genSym when we *run* the splice. (This stuff makes my head hurt.) Assuming this is so, we can simplify the mkGenSym stuff still more. --- ghc/compiler/deSugar/DsMeta.hs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/ghc/compiler/deSugar/DsMeta.hs b/ghc/compiler/deSugar/DsMeta.hs index 061c367..9ab3bf7 100644 --- a/ghc/compiler/deSugar/DsMeta.hs +++ b/ghc/compiler/deSugar/DsMeta.hs @@ -37,7 +37,8 @@ import HsSyn ( Pat(..), HsExpr(..), Stmt(..), HsLit(..), HsOverLit(..), InstDecl(..), ConDecl(..), BangType(..), PendingSplice, splitHsInstDeclTy, placeHolderType, tyClDeclNames, - collectHsBinders, collectPatBinders, collectPatsBinders, + collectHsBinders, collectPatBinders, + collectMonoBinders, collectPatsBinders, hsTyVarName, hsConArgs ) @@ -51,7 +52,7 @@ import OccName ( isDataOcc, isTvOcc, occNameUserString ) import qualified OccName( varName, tcName ) import Module ( Module, mkModule, moduleUserString ) -import Id ( Id, idType ) +import Id ( Id, idType, mkLocalId ) import Name ( mkExternalName ) import OccName ( mkOccFS ) import NameEnv @@ -267,10 +268,10 @@ repInstD' (InstDecl ty binds _ loc) ; let ss = mkGenSyms (collectMonoBinders binds) ; binds1 <- addBinds ss (rep_monobind binds) ; decls1 <- coreList decQTyConName binds1 - ; i <- repInst cxt1 inst_ty1 - (wrapNonGenSyms ss decls1) + ; decls2 <- wrapNongenSyms ss decls1 -- wrapNonGenSyms: do not clone the class op names! -- They must be called 'op' etc, not 'op34' + ; i <- repInst cxt1 inst_ty1 decls2 ; return (loc, i)} where (tvs, cxt, cls, tys) = splitHsInstDeclTy ty @@ -802,6 +803,14 @@ type GenSymBind = (Name, Id) -- Gensym the string and bind it to the Id -- Generate a fresh name for a locally bound entity mkGenSym :: Name -> GenSymBind +-- Does not need to be monadic, becuase we can use the +-- existing name. For example: +-- [| \x_77 -> x_77 + x_77 |] +-- desugars to +-- do { x_77 <- genSym "x"; .... } +-- We use the same x_77 in the desugared program, but with the type Bndr +-- instead of Int + mkGenSym nm = (nm, mkLocalId nm stringTy) -- Ditto for a list of names -- 1.7.10.4