merge upstream
authorAdam Megacz <megacz@cs.berkeley.edu>
Tue, 14 Jun 2011 18:50:10 +0000 (11:50 -0700)
committerAdam Megacz <megacz@cs.berkeley.edu>
Tue, 14 Jun 2011 18:50:10 +0000 (11:50 -0700)
34 files changed:
.gitmodules [new file with mode: 0644]
compiler/basicTypes/Name.lhs
compiler/basicTypes/OccName.lhs
compiler/basicTypes/Unique.lhs
compiler/cmm/CLabel.hs
compiler/deSugar/Desugar.lhs
compiler/deSugar/DsExpr.lhs
compiler/deSugar/DsForeign.lhs
compiler/ghc.cabal.in
compiler/hetmet [new submodule]
compiler/hsSyn/HsExpr.lhs
compiler/hsSyn/HsTypes.lhs
compiler/iface/BinIface.hs
compiler/iface/TcIface.lhs
compiler/main/DynFlags.hs
compiler/parser/Lexer.x
compiler/parser/Parser.y.pp
compiler/parser/RdrHsSyn.lhs
compiler/prelude/PrelNames.lhs
compiler/prelude/TysPrim.lhs
compiler/prelude/TysWiredIn.lhs
compiler/rename/RnEnv.lhs
compiler/rename/RnExpr.lhs
compiler/rename/RnHsSyn.lhs
compiler/rename/RnTypes.lhs
compiler/typecheck/TcEnv.lhs
compiler/typecheck/TcExpr.lhs
compiler/typecheck/TcHsSyn.lhs
compiler/typecheck/TcHsType.lhs
compiler/typecheck/TcRnMonad.lhs
compiler/typecheck/TcRnTypes.lhs
compiler/types/Kind.lhs
ghc.mk
libraries/base [new submodule]

diff --git a/.gitmodules b/.gitmodules
new file mode 100644 (file)
index 0000000..ee9771b
--- /dev/null
@@ -0,0 +1,3 @@
+[submodule "compiler/hetmet"]
+       path = compiler/hetmet
+       url = http://git.megacz.com/coq-hetmet.git
index a2b42a2..6153637 100644 (file)
@@ -64,6 +64,7 @@ module Name (
        getSrcLoc, getSrcSpan, getOccString,
 
        pprInfixName, pprPrefixName, pprModulePrefix,
+        getNameDepth, setNameDepth,
 
        -- Re-export the OccName stuff
        module OccName
@@ -112,6 +113,12 @@ data Name = Name {
 -- (and real!) space leaks, due to the fact that we don't look at
 -- the SrcLoc in a Name all that often.
 
+setNameDepth :: Int -> Name -> Name
+setNameDepth depth name = name { n_occ = setOccNameDepth depth (n_occ name) }
+
+getNameDepth :: Name -> Int
+getNameDepth name = getOccNameDepth $ n_occ name
+
 data NameSort
   = External Module
  
index 446d11a..5b5f620 100644 (file)
@@ -25,8 +25,8 @@ module OccName (
        
        -- ** Construction
        -- $real_vs_source_data_constructors
-       tcName, clsName, tcClsName, dataName, varName, 
-       tvName, srcDataName,
+       tcName, clsName, tcClsName, dataName, varName, varNameDepth,
+       tvName, srcDataName, setOccNameDepth, getOccNameDepth,
 
        -- ** Pretty Printing
        pprNameSpace, pprNonVarNameSpace, pprNameSpaceBrief,
@@ -115,7 +115,7 @@ import Data.Data
 %************************************************************************
 
 \begin{code}
-data NameSpace = VarName       -- Variables, including "real" data constructors
+data NameSpace = VarName   Int  -- Variables, including "real" data constructors; Int is the syntactic HetMet bracket depth
               | DataName       -- "Source" data constructors 
               | TvName         -- Type variables
               | TcClsName      -- Type constructors and classes; Haskell has them
@@ -145,6 +145,7 @@ data NameSpace = VarName    -- Variables, including "real" data constructors
 tcName, clsName, tcClsName :: NameSpace
 dataName, srcDataName      :: NameSpace
 tvName, varName            :: NameSpace
+varNameDepth               :: Int -> NameSpace
 
 -- Though type constructors and classes are in the same name space now,
 -- the NameSpace type is abstract, so we can easily separate them later
@@ -156,8 +157,23 @@ dataName    = DataName
 srcDataName = DataName -- Haskell-source data constructors should be
                        -- in the Data name space
 
-tvName      = TvName
-varName     = VarName
+tvName       = TvName
+
+varName      = VarName 0
+varNameDepth = VarName
+
+getOccNameDepth :: OccName -> Int
+getOccNameDepth name =
+    case occNameSpace name of
+      (VarName d) -> d
+      _           -> 0
+setOccNameDepth :: Int -> OccName -> OccName
+setOccNameDepth depth name =
+    case occNameSpace name of
+      (VarName _) -> name{ occNameSpace = VarName depth }
+      ns           -> if depth==0
+                     then name
+                     else error ("tried to change the depth of a name in namespace " ++ (showSDoc $ ppr name))
 
 isDataConNameSpace :: NameSpace -> Bool
 isDataConNameSpace DataName = True
@@ -173,27 +189,27 @@ isTvNameSpace _      = False
 
 isVarNameSpace :: NameSpace -> Bool    -- Variables or type variables, but not constructors
 isVarNameSpace TvName  = True
-isVarNameSpace VarName = True
+isVarNameSpace (VarName _) = True
 isVarNameSpace _       = False
 
 isValNameSpace :: NameSpace -> Bool
 isValNameSpace DataName = True
-isValNameSpace VarName  = True
+isValNameSpace (VarName _)  = True
 isValNameSpace _        = False
 
 pprNameSpace :: NameSpace -> SDoc
 pprNameSpace DataName  = ptext (sLit "data constructor")
-pprNameSpace VarName   = ptext (sLit "variable")
+pprNameSpace (VarName _)  = ptext (sLit "variable")
 pprNameSpace TvName    = ptext (sLit "type variable")
 pprNameSpace TcClsName = ptext (sLit "type constructor or class")
 
 pprNonVarNameSpace :: NameSpace -> SDoc
-pprNonVarNameSpace VarName = empty
+pprNonVarNameSpace (VarName _) = empty
 pprNonVarNameSpace ns = pprNameSpace ns
 
 pprNameSpaceBrief :: NameSpace -> SDoc
 pprNameSpaceBrief DataName  = char 'd'
-pprNameSpaceBrief VarName   = char 'v'
+pprNameSpaceBrief (VarName _)  = char 'v'
 pprNameSpaceBrief TvName    = ptext (sLit "tv")
 pprNameSpaceBrief TcClsName = ptext (sLit "tc")
 \end{code}
@@ -333,7 +349,7 @@ easy to build an OccEnv.
 \begin{code}
 instance Uniquable OccName where
       -- See Note [The Unique of an OccName]
-  getUnique (OccName VarName   fs) = mkVarOccUnique  fs
+  getUnique (OccName (VarName depth) fs) = mkVarOccUnique fs depth
   getUnique (OccName DataName  fs) = mkDataOccUnique fs
   getUnique (OccName TvName    fs) = mkTvOccUnique   fs
   getUnique (OccName TcClsName fs) = mkTcOccUnique   fs
@@ -430,7 +446,7 @@ setOccNameSpace sp (OccName _ occ) = OccName sp occ
 
 isVarOcc, isTvOcc, isTcOcc, isDataOcc :: OccName -> Bool
 
-isVarOcc (OccName VarName _) = True
+isVarOcc (OccName (VarName _) _) = True
 isVarOcc _                   = False
 
 isTvOcc (OccName TvName _) = True
@@ -442,12 +458,12 @@ isTcOcc _                     = False
 -- | /Value/ 'OccNames's are those that are either in 
 -- the variable or data constructor namespaces
 isValOcc :: OccName -> Bool
-isValOcc (OccName VarName  _) = True
+isValOcc (OccName (VarName _) _) = True
 isValOcc (OccName DataName _) = True
 isValOcc _                    = False
 
 isDataOcc (OccName DataName _) = True
-isDataOcc (OccName VarName s)  
+isDataOcc (OccName (VarName _) s)  
   | isLexCon s = pprPanic "isDataOcc: check me" (ppr s)
                -- Jan06: I don't think this should happen
 isDataOcc _                    = False
@@ -456,7 +472,7 @@ isDataOcc _                    = False
 -- a symbol (e.g. @:@, or @[]@)
 isDataSymOcc :: OccName -> Bool
 isDataSymOcc (OccName DataName s) = isLexConSym s
-isDataSymOcc (OccName VarName s)  
+isDataSymOcc (OccName (VarName _) s)  
   | isLexConSym s = pprPanic "isDataSymOcc: check me" (ppr s)
                -- Jan06: I don't think this should happen
 isDataSymOcc _                    = False
@@ -467,7 +483,7 @@ isDataSymOcc _                    = False
 isSymOcc :: OccName -> Bool
 isSymOcc (OccName DataName s)  = isLexConSym s
 isSymOcc (OccName TcClsName s) = isLexConSym s
-isSymOcc (OccName VarName s)   = isLexSym s
+isSymOcc (OccName (VarName _) s)   = isLexSym s
 isSymOcc (OccName TvName s)    = isLexSym s
 -- Pretty inefficient!
 
@@ -654,7 +670,7 @@ mkDFunOcc :: String         -- ^ Typically the class and type glommed together e.g. @Or
 -- what the  mother module will call it.
 
 mkDFunOcc info_str is_boot set
-  = chooseUniqueOcc VarName (prefix ++ info_str) set
+  = chooseUniqueOcc (VarName 0) (prefix ++ info_str) set
   where
     prefix | is_boot   = "$fx"
           | otherwise = "$f"
@@ -693,7 +709,7 @@ guys never show up in error messages.  What a hack.
 
 \begin{code}
 mkMethodOcc :: OccName -> OccName
-mkMethodOcc occ@(OccName VarName _) = occ
+mkMethodOcc occ@(OccName (VarName _) _) = occ
 mkMethodOcc occ                     = mk_simple_deriv varName "$m" occ
 \end{code}
 
@@ -829,21 +845,22 @@ isSymbolASCII c = c `elem` "!#$%&*+./<=>?@\\^|~-"
 
 \begin{code}
 instance Binary NameSpace where
-    put_ bh VarName = do
-           putByte bh 0
+    put_ bh (VarName depth) = do if depth > 255-4
+                                   then error "FIXME: no support for serializing VarNames at this syntactic depth"
+                                   else putByte bh ((fromIntegral ((depth+3) :: Int)))
     put_ bh DataName = do
-           putByte bh 1
+           putByte bh 0
     put_ bh TvName = do
-           putByte bh 2
+           putByte bh 1
     put_ bh TcClsName = do
-           putByte bh 3
+           putByte bh 2
     get bh = do
            h <- getByte bh
            case h of
-             0 -> do return VarName
-             1 -> do return DataName
-             2 -> do return TvName
-             _ -> do return TcClsName
+             0 -> do return DataName
+             1 -> do return TvName
+             2 -> do return TcClsName
+             n -> do return (VarName (fromIntegral (n-3)))
 
 instance Binary OccName where
     put_ bh (OccName aa ab) = do
index 4180604..396feea 100644 (file)
@@ -369,9 +369,14 @@ mkRegSubUnique    = mkUnique 'S'
 mkRegPairUnique   = mkUnique 'P'
 mkRegClassUnique  = mkUnique 'L'
 
-mkVarOccUnique, mkDataOccUnique, mkTvOccUnique, mkTcOccUnique :: FastString -> Unique
+mkVarOccUnique :: FastString -> Int -> Unique
+mkVarOccUnique  fs depth = 
+    if depth > 255
+    then error "FIXME: no support for syntactic depth > 255"
+    else mkUnique 'i' ((iBox (uniqueOfFS fs)) * 8 + depth )
+
+mkDataOccUnique, mkTvOccUnique, mkTcOccUnique :: FastString -> Unique
 -- See Note [The Unique of an OccName] in OccName
-mkVarOccUnique  fs = mkUnique 'i' (iBox (uniqueOfFS fs))
 mkDataOccUnique fs = mkUnique 'd' (iBox (uniqueOfFS fs))
 mkTvOccUnique  fs = mkUnique 'v' (iBox (uniqueOfFS fs))
 mkTcOccUnique  fs = mkUnique 'c' (iBox (uniqueOfFS fs))
index 3451c7d..1ba1126 100644 (file)
@@ -254,6 +254,10 @@ data ForeignLabelSource
       
    deriving (Eq, Ord)   
 
+closureSuffix' :: Name -> SDoc
+closureSuffix' hs_fn =
+    if depth==0 then ptext (sLit "") else ptext (sLit $ (show depth))
+          where depth = getNameDepth hs_fn
 
 -- | For debugging problems with the CLabel representation.
 --     We can't make a Show instance for CLabel because lots of its components don't have instances.
@@ -964,7 +968,7 @@ pprCLbl (RtsLabel (RtsSlowTickyCtr pat))
 pprCLbl (ForeignLabel str _ _ _)
   = ftext str
 
-pprCLbl (IdLabel name cafs flavor) = ppr name <> ppIdFlavor flavor
+pprCLbl (IdLabel name cafs flavor) = ppr name <> ppIdFlavor name flavor
 
 pprCLbl (CC_Label cc)          = ppr cc
 pprCLbl (CCS_Label ccs)        = ppr ccs
@@ -975,8 +979,8 @@ pprCLbl (PlainModuleInitLabel mod)
 pprCLbl (HpcTicksLabel mod)
   = ptext (sLit "_hpc_tickboxes_")  <> ppr mod <> ptext (sLit "_hpc")
 
-ppIdFlavor :: IdLabelInfo -> SDoc
-ppIdFlavor x = pp_cSEP <>
+ppIdFlavor :: Name -> IdLabelInfo -> SDoc
+ppIdFlavor n x = pp_cSEP <> closureSuffix' n <>
               (case x of
                       Closure          -> ptext (sLit "closure")
                       SRT              -> ptext (sLit "srt")
index af2db36..9b48cce 100644 (file)
@@ -15,9 +15,11 @@ import HsSyn
 import TcRnTypes
 import MkIface
 import Id
+import Pair
 import Name
 import CoreSyn
 import CoreSubst
+import CoqPass ( coqPassCoreToString, coqPassCoreToCore )
 import PprCore
 import DsMonad
 import DsExpr
@@ -40,6 +42,12 @@ import MonadUtils
 import OrdList
 import Data.List
 import Data.IORef
+import PrelNames
+import UniqSupply
+import UniqFM
+import CoreFVs
+import Type
+import Coercion
 \end{code}
 
 %************************************************************************
@@ -49,6 +57,7 @@ import Data.IORef
 %************************************************************************
 
 \begin{code}
+
 -- | Main entry point to the desugarer.
 deSugar :: HscEnv -> ModLocation -> TcGblEnv -> IO (Messages, Maybe ModGuts)
 -- Can modify PCS by faulting in more declarations
@@ -89,7 +98,34 @@ deSugar hsc_env
               <- case target of
                   HscNothing ->
                        return (emptyMessages,
-                               Just ([], nilOL, [], [], NoStubs, hpcInfo, emptyModBreaks))
+                               Just ([], nilOL, [], [], NoStubs, hpcInfo, emptyModBreaks, undefined, undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                                    , undefined
+                               ))
                    _        -> do
                      (binds_cvr,ds_hpc_info, modBreaks)
                         <- if (opt_Hpc
@@ -105,6 +141,34 @@ deSugar hsc_env
                           ; (ds_fords, foreign_prs) <- dsForeigns fords
                           ; ds_rules <- mapMaybeM dsRule rules
                           ; ds_vects <- mapM dsVect vects
+                          ; hetmet_brak <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_brak_name else return undefined
+                          ; hetmet_esc  <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_esc_name  else return undefined
+                          ; hetmet_flatten <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_flatten_name else return undefined
+                          ; hetmet_unflatten <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_unflatten_name else return undefined
+                          ; hetmet_flattened_id <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_flattened_id_name else return undefined
+                          ; hetmet_PGArrow <- if dopt Opt_F_coqpass dflags then dsLookupTyCon hetmet_PGArrow_name else return undefined
+                          ; hetmet_PGArrow_unit <- if dopt Opt_F_coqpass dflags then dsLookupTyCon hetmet_PGArrow_unit_name else return undefined
+                          ; hetmet_PGArrow_tensor <- if dopt Opt_F_coqpass dflags then dsLookupTyCon hetmet_PGArrow_tensor_name else return undefined
+                          ; hetmet_PGArrow_exponent <- if dopt Opt_F_coqpass dflags then dsLookupTyCon hetmet_PGArrow_exponent_name else return undefined
+                          ; hetmet_pga_id <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_pga_id_name else return undefined
+                          ; hetmet_pga_comp <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_pga_comp_name else return undefined
+                          ; hetmet_pga_first <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_pga_first_name else return undefined
+                          ; hetmet_pga_second <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_pga_second_name else return undefined
+                          ; hetmet_pga_cancell <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_pga_cancell_name else return undefined
+                          ; hetmet_pga_cancelr <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_pga_cancelr_name else return undefined
+                          ; hetmet_pga_uncancell <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_pga_uncancell_name else return undefined
+                          ; hetmet_pga_uncancelr <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_pga_uncancelr_name else return undefined
+                          ; hetmet_pga_assoc <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_pga_assoc_name else return undefined
+                          ; hetmet_pga_unassoc <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_pga_unassoc_name else return undefined
+                          ; hetmet_pga_copy <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_pga_copy_name else return undefined
+                          ; hetmet_pga_drop <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_pga_drop_name else return undefined
+                          ; hetmet_pga_swap <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_pga_swap_name else return undefined
+                          ; hetmet_pga_applyl <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_pga_applyl_name else return undefined
+                          ; hetmet_pga_applyr <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_pga_applyr_name else return undefined
+                          ; hetmet_pga_curryl <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_pga_curryl_name else return undefined
+                          ; hetmet_pga_curryr <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_pga_curryr_name else return undefined
+                          ; hetmet_pga_loopl <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_pga_loopl_name else return undefined
+                          ; hetmet_pga_loopr <- if dopt Opt_F_coqpass dflags then dsLookupGlobalId hetmet_pga_loopr_name else return undefined
                           ; let hpc_init
                                   | opt_Hpc   = hpcInitCode mod ds_hpc_info
                                   | otherwise = empty
@@ -112,11 +176,66 @@ deSugar hsc_env
                                    , foreign_prs `appOL` core_prs `appOL` spec_prs
                                    , spec_rules ++ ds_rules, ds_vects
                                    , ds_fords `appendStubC` hpc_init
-                                   , ds_hpc_info, modBreaks) }
+                                   , ds_hpc_info, modBreaks, hetmet_brak, hetmet_esc
+                                   , hetmet_flatten
+                                   , hetmet_unflatten
+                                   , hetmet_flattened_id
+                                   , hetmet_PGArrow
+                                   , hetmet_PGArrow_unit
+                                   , hetmet_PGArrow_tensor
+                                   , hetmet_PGArrow_exponent
+                                   , hetmet_pga_id
+                                   , hetmet_pga_comp
+                                   , hetmet_pga_first
+                                   , hetmet_pga_second
+                                   , hetmet_pga_cancell
+                                   , hetmet_pga_cancelr
+                                   , hetmet_pga_uncancell
+                                   , hetmet_pga_uncancelr
+                                   , hetmet_pga_assoc
+                                   , hetmet_pga_unassoc
+                                   , hetmet_pga_copy
+                                   , hetmet_pga_drop
+                                   , hetmet_pga_swap
+                                   , hetmet_pga_applyl
+                                   , hetmet_pga_applyr
+                                   , hetmet_pga_curryl
+                                   , hetmet_pga_curryr
+                                   , hetmet_pga_loopl
+                                   , hetmet_pga_loopr
+                                   ) }
 
         ; case mb_res of {
            Nothing -> return (msgs, Nothing) ;
-           Just (ds_ev_binds, all_prs, all_rules, vects0, ds_fords, ds_hpc_info, modBreaks) -> do
+           Just (ds_ev_binds, all_prs, all_rules, vects0, ds_fords, ds_hpc_info, modBreaks
+                                   , hetmet_brak, hetmet_esc
+                                   , hetmet_flatten
+                                   , hetmet_unflatten
+                                   , hetmet_flattened_id
+                                   , hetmet_PGArrow
+                                   , hetmet_PGArrow_unit
+                                   , hetmet_PGArrow_tensor
+                                   , hetmet_PGArrow_exponent
+                                   , hetmet_pga_id
+                                   , hetmet_pga_comp
+                                   , hetmet_pga_first
+                                   , hetmet_pga_second
+                                   , hetmet_pga_cancell
+                                   , hetmet_pga_cancelr
+                                   , hetmet_pga_uncancell
+                                   , hetmet_pga_uncancelr
+                                   , hetmet_pga_assoc
+                                   , hetmet_pga_unassoc
+                                   , hetmet_pga_copy
+                                   , hetmet_pga_drop
+                                   , hetmet_pga_swap
+                                   , hetmet_pga_applyl
+                                   , hetmet_pga_applyr
+                                   , hetmet_pga_curryl
+                                   , hetmet_pga_curryr
+                                   , hetmet_pga_loopl
+                                   , hetmet_pga_loopr
+                                   ) -> do
 
         {       -- Add export flags to bindings
           keep_alive <- readIORef keep_var
@@ -125,17 +244,70 @@ deSugar hsc_env
               final_prs = addExportFlagsAndRules target
                               export_set keep_alive rules_for_locals (fromOL all_prs)
 
-              final_pgm = combineEvBinds ds_ev_binds final_prs
+              final_pgm = let comb = combineEvBinds ds_ev_binds final_prs
+                          in if dopt Opt_F_simpleopt_before_flatten dflags
+                             then comb
+                             else simplifyBinds comb
         -- Notice that we put the whole lot in a big Rec, even the foreign binds
         -- When compiling PrelFloat, which defines data Float = F# Float#
         -- we want F# to be in scope in the foreign marshalling code!
         -- You might think it doesn't matter, but the simplifier brings all top-level
         -- things into the in-scope set before simplifying; so we get no unfolding for F#!
 
-        -- Lint result if necessary, and print
-        ; dumpIfSet_dyn dflags Opt_D_dump_ds "Desugared, before opt" $
-               (vcat [ pprCoreBindings final_pgm
-                     , pprRules rules_for_imps ])
+       ; (final_pgm', rules_for_imps') <- if dopt Opt_F_simpleopt_before_flatten dflags
+                                            then simpleOptPgm dflags final_pgm rules_for_imps
+                                            else return (final_pgm, rules_for_imps)
+
+        ; ds_binds <- if dopt Opt_F_coqpass dflags
+                       then do { us <- mkSplitUniqSupply '~'
+                               ; let do_flatten   = dopt Opt_F_flatten dflags
+                               ; let do_skolemize = dopt Opt_F_skolemize dflags
+                               ; return (coqPassCoreToCore
+                                             do_flatten
+                                             do_skolemize
+                                             hetmet_brak
+                                             hetmet_esc
+                                             hetmet_flatten
+                                             hetmet_unflatten
+                                             hetmet_flattened_id
+                                             us
+                                             final_pgm'
+                                             hetmet_PGArrow
+                                             hetmet_PGArrow_unit
+                                             hetmet_PGArrow_tensor
+                                             hetmet_PGArrow_exponent
+                                             hetmet_pga_id
+                                             hetmet_pga_comp
+                                             hetmet_pga_first
+                                             hetmet_pga_second
+                                             hetmet_pga_cancell
+                                             hetmet_pga_cancelr
+                                             hetmet_pga_uncancell
+                                             hetmet_pga_uncancelr
+                                             hetmet_pga_assoc
+                                             hetmet_pga_unassoc
+                                             hetmet_pga_copy
+                                             hetmet_pga_drop
+                                             hetmet_pga_swap
+                                             hetmet_pga_applyl
+                                             hetmet_pga_applyr
+                                             hetmet_pga_curryl
+                                             hetmet_pga_curryr
+                                             hetmet_pga_loopl
+                                             hetmet_pga_loopr
+                                        )
+                               }
+                       else return final_pgm
+
+       ; (ds_binds', ds_rules_for_imps) <- if dopt Opt_F_simpleopt_before_flatten dflags
+                                            then return (ds_binds, rules_for_imps')
+                                            else simpleOptPgm dflags ds_binds rules_for_imps'
+                        -- The simpleOptPgm gets rid of type 
+                        -- bindings plus any stupid dead code
+
+        ; dumpIfSet_dyn dflags Opt_D_dump_proofs "Coq Pass Output" $ text $ coqPassCoreToString ds_binds'
+
+        ; dumpIfSet_dyn dflags Opt_D_coqpass "After Coq Pass" (text $ showSDoc $ pprCoreBindings ds_binds')
 
         ; (ds_binds, ds_rules_for_imps, ds_vects) 
             <- simpleOptPgm dflags final_pgm rules_for_imps vects0
@@ -164,7 +336,7 @@ deSugar hsc_env
                mg_inst_env     = inst_env,
                mg_fam_inst_env = fam_inst_env,
                mg_rules        = ds_rules_for_imps,
-               mg_binds        = ds_binds,
+               mg_binds        = ds_binds',
                mg_foreign      = ds_fords,
                mg_hpc_info     = ds_hpc_info,
                 mg_modBreaks    = modBreaks,
@@ -402,3 +574,36 @@ dsVect (L loc (HsVect (L _ v) rhs))
 dsVect (L _loc (HsNoVect (L _ v)))
   = return $ NoVect v
 \end{code}
+
+
+
+\begin{code}
+--
+-- Simplification routines run before the flattener.  We can't use
+-- simpleOptPgm -- it doesn't preserve the order of subexpressions or
+-- let-binding groups.
+--
+simplify :: Expr CoreBndr -> Expr CoreBndr
+simplify (Var v)                 = Var v
+simplify (App e1 e2)             = App (simplify e1) (simplify e2)
+simplify (Lit lit)               = Lit lit
+simplify (Note note e)           = Note note (simplify e)
+simplify (Cast e co)             = if eqType (fst $ unPair $ coercionKind co) (snd $ unPair $ coercionKind co)
+                                       then simplify e
+                                       else Cast (simplify e) co
+simplify (Lam v e)               = Lam v (simplify e)
+simplify (Case e b ty as)        = Case (simplify e) b ty (map (\(a,b,e) -> (a,b,simplify e)) as)
+simplify (Let bind body)         = foldr Let (simplify body) (simplifyBind bind)
+simplify (Type t)                = Type t
+simplify (Coercion co)           = Coercion co
+
+simplifyBind :: Bind CoreBndr -> [Bind CoreBndr]
+simplifyBind (NonRec b e)             = [NonRec b (simplify e)]
+simplifyBind (Rec [])                 = []
+simplifyBind (Rec (rbs@((b,e):rbs'))) =
+    if or $ map (\x -> elemUFM x (exprFreeIds e)) (map fst rbs)
+    then [Rec (map (\(v,e) -> (v,simplify e)) rbs)]
+    else (NonRec b (simplify e)):(simplifyBind $ Rec rbs')
+
+simplifyBinds = concatMap simplifyBind
+\end{code}
index e33b113..2ac19ce 100644 (file)
@@ -216,6 +216,16 @@ dsLExpr (L loc e) = putSrcSpanDs loc $ dsExpr e
 
 dsExpr :: HsExpr Id -> DsM CoreExpr
 dsExpr (HsPar e)             = dsLExpr e
+
+dsExpr (HsHetMetBrak c   e)   = do { e' <- dsExpr (unLoc e)
+                                 ; brak <- dsLookupGlobalId hetmet_brak_name
+                                 ; return $ mkApps (Var brak) [ (Type c), (Type $ exprType e'), e'] }
+dsExpr (HsHetMetEsc  c t e)   = do { e' <- dsExpr (unLoc e)
+                                 ; esc <- dsLookupGlobalId hetmet_esc_name
+                                 ; return $ mkApps (Var esc)  [ (Type c), (Type t), e'] }
+dsExpr (HsHetMetCSP  c   e)   = do { e' <- dsExpr (unLoc e)
+                                 ; csp <- dsLookupGlobalId hetmet_csp_name
+                                 ; return $ mkApps (Var csp)  [ (Type c), (Type $ exprType e'), e'] }
 dsExpr (ExprWithTySigOut e _) = dsLExpr e
 dsExpr (HsVar var)                   = return (Var var)
 dsExpr (HsIPVar ip)                  = return (Var (ipNameName ip))
index b391b8f..2c2d5f9 100644 (file)
@@ -30,6 +30,7 @@ import Coercion
 import TcType
 
 import CmmExpr
+import qualified Var
 import CmmUtils
 import HscTypes
 import ForeignCall
@@ -524,7 +525,7 @@ mkFExportCBits c_nm maybe_target arg_htys res_hty is_IO_res_ty cc
   the_cfun
      = case maybe_target of
           Nothing    -> text "(StgClosure*)deRefStablePtr(the_stableptr)"
-          Just hs_fn -> char '&' <> ppr hs_fn <> text "_closure"
+          Just hs_fn -> char '&' <> ppr hs_fn <> text (closureSuffix hs_fn)
 
   cap = text "cap" <> comma
 
@@ -549,9 +550,8 @@ mkFExportCBits c_nm maybe_target arg_htys res_hty is_IO_res_ty cc
   extern_decl
      = case maybe_target of
           Nothing -> empty
-          Just hs_fn -> text "extern StgClosure " <> ppr hs_fn <> text "_closure" <> semi
+          Just hs_fn -> text "extern StgClosure " <> ppr hs_fn <> text (closureSuffix hs_fn) <> semi
 
-   
   -- finally, the whole darn thing
   c_bits =
     space $$
@@ -589,6 +589,10 @@ mkFExportCBits c_nm maybe_target arg_htys res_hty is_IO_res_ty cc
      , rbrace
      ]
 
+closureSuffix :: Id -> String
+closureSuffix hs_fn =
+    if depth==0 then "_closure" else "_"++(show depth)++"closure"
+        where depth = getNameDepth (Var.varName hs_fn)
 
 foreignExportInitialiser :: Id -> SDoc
 foreignExportInitialiser hs_fn =
@@ -605,11 +609,10 @@ foreignExportInitialiser hs_fn =
          <> text "() __attribute__((constructor));"
     , text "static void stginit_export_" <> ppr hs_fn <> text "()"
     , braces (text "getStablePtr"
-       <> parens (text "(StgPtr) &" <> ppr hs_fn <> text "_closure")
+       <> parens (text "(StgPtr) &" <> ppr hs_fn <> text (closureSuffix hs_fn))
        <> semi)
     ]
 
-
 mkHObj :: Type -> SDoc
 mkHObj t = text "rts_mk" <> text (showFFIType t)
 
index 4ffb915..c4be998 100644 (file)
@@ -262,6 +262,7 @@ Library
         CoreTidy
         CoreUnfold
         CoreUtils
+        CoqPass
         ExternalCore
         MkCore
         MkExternalCore
diff --git a/compiler/hetmet b/compiler/hetmet
new file mode 160000 (submodule)
index 0000000..67e0043
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit 67e004348a218f0addeff433e723496a328403ef
index dd33cae..c3c372d 100644 (file)
@@ -223,6 +223,13 @@ data HsExpr id
                 (LHsCmdTop id)          -- body of the abstraction
                                         -- always has an empty stack
 
+  -----------------------------------------------------------
+  -- Heterogeneous Metaprogramming extension
+
+  | HsHetMetBrak  PostTcType            (LHsExpr id)            -- code type brackets
+  | HsHetMetEsc   PostTcType PostTcType (LHsExpr id)            -- code type escape
+  | HsHetMetCSP   PostTcType            (LHsExpr id)            -- code type cross-stage persistence
+
   ---------------------------------------
   -- The following are commands, not expressions proper
 
@@ -353,6 +360,9 @@ ppr_expr (HsIPVar v)     = ppr v
 ppr_expr (HsLit lit)     = ppr lit
 ppr_expr (HsOverLit lit) = ppr lit
 ppr_expr (HsPar e)       = parens (ppr_lexpr e)
+ppr_expr (HsHetMetBrak _   e) = ptext (sLit "<[") <> (ppr_lexpr e) <> ptext (sLit "]>")
+ppr_expr (HsHetMetEsc  _ _ e) = ptext (sLit "~~") <> (ppr_lexpr e)
+ppr_expr (HsHetMetCSP  _   e) = ptext (sLit "%%") <> (ppr_lexpr e)
 
 ppr_expr (HsCoreAnn s e)
   = vcat [ptext (sLit "HsCoreAnn") <+> ftext s, ppr_lexpr e]
index d565c96..75e6c23 100644 (file)
@@ -156,6 +156,8 @@ data HsType name
 
   | HsPArrTy           (LHsType name)  -- Elem. type of parallel array: [:t:]
 
+  | HsModalBoxType     name (LHsType name)     -- modal types; first argument is the environment classifier
+
   | HsTupleTy          Boxity
                        [LHsType name]  -- Element types (length gives arity)
 
@@ -451,6 +453,7 @@ ppr_mono_ty _    (HsTupleTy con tys) = tupleParens con (interpp'SP tys)
 ppr_mono_ty _    (HsKindSig ty kind) = parens (ppr_mono_lty pREC_TOP ty <+> dcolon <+> pprKind kind)
 ppr_mono_ty _    (HsListTy ty)      = brackets (ppr_mono_lty pREC_TOP ty)
 ppr_mono_ty _    (HsPArrTy ty)      = pabrackets (ppr_mono_lty pREC_TOP ty)
+ppr_mono_ty _    (HsModalBoxType ecn ty) = ppr_modalBoxType (ppr ecn) (ppr_mono_lty pREC_TOP ty)
 ppr_mono_ty _    (HsPredTy pred)     = ppr pred
 ppr_mono_ty _    (HsSpliceTy s _ _)  = pprSplice s
 ppr_mono_ty _    (HsCoreTy ty)       = ppr ty
@@ -487,6 +490,10 @@ ppr_fun_ty ctxt_prec ty1 ty2
 --------------------------
 pabrackets :: SDoc -> SDoc
 pabrackets p = ptext (sLit "[:") <> p <> ptext (sLit ":]")
+
+ppr_modalBoxType :: SDoc -> SDoc -> SDoc
+ppr_modalBoxType ecn p = ptext (sLit "<[") <> p <> ptext (sLit "]>@") <> ecn 
+
 \end{code}
 
 
index 502eefa..b9ad5c8 100644 (file)
@@ -1301,10 +1301,14 @@ instance Binary IfaceNote where
 -- to avoid re-building it in various places.  So we build the OccName
 -- when de-serialising.
 
+-- NOTE regarding HetMet extensions: this screws up Adam's heinous
+-- hide-the-syntactical-level-in-the-namespace trick.
+
 instance Binary IfaceDecl where
     put_ bh (IfaceId name ty details idinfo) = do
            putByte bh 0
            put_ bh (occNameFS name)
+           put_ bh (getOccNameDepth name)
            put_ bh ty
            put_ bh details
            put_ bh idinfo
@@ -1339,10 +1343,11 @@ instance Binary IfaceDecl where
            h <- getByte bh
            case h of
              0 -> do name    <- get bh
+                     depth   <- get bh
                      ty      <- get bh
                      details <- get bh
                      idinfo  <- get bh
-                      occ <- return $! mkOccNameFS varName name
+                      occ <- return $! mkOccNameFS (varNameDepth depth) name
                      return (IfaceId occ ty details idinfo)
              1 -> error "Binary.get(TyClDecl): ForeignType"
              2 -> do
@@ -1453,13 +1458,15 @@ instance Binary IfaceConDecl where
 instance Binary IfaceClassOp where
    put_ bh (IfaceClassOp n def ty) = do        
        put_ bh (occNameFS n)
+       put_ bh (getOccNameDepth n)
        put_ bh def     
        put_ bh ty
    get bh = do
        n <- get bh
+       depth <- get bh
        def <- get bh
        ty <- get bh
-        occ <- return $! mkOccNameFS varName n
+        occ <- return $! mkOccNameFS (varNameDepth depth) n
        return (IfaceClassOp occ def ty)
 
 instance Binary IfaceRule where
index 5bfb406..c2cb33f 100644 (file)
@@ -146,7 +146,7 @@ importDecl name
   where
     nd_doc = ptext (sLit "Need decl for") <+> ppr name
     not_found_msg = hang (ptext (sLit "Can't find interface-file declaration for") <+>
-                               pprNameSpace (occNameSpace (nameOccName name)) <+> ppr name)
+                               pprNameSpace (occNameSpace (nameOccName name)) <+> (ppr (nameOccName name)))
                       2 (vcat [ptext (sLit "Probable cause: bug in .hi-boot file, or inconsistent .hi file"),
                                ptext (sLit "Use -ddump-if-trace to get an idea of which file caused the error")])
 \end{code}
index b49b860..e5bd677 100644 (file)
@@ -204,6 +204,13 @@ data DynFlag
    | Opt_DoCmmLinting
    | Opt_DoAsmLinting
 
+   | Opt_F_coqpass                      -- run the core-to-core coqPass, but don't change anything (just "parse/unparse")
+   | Opt_F_skolemize                    -- run the core-to-core coqPass, skolemizing the proof
+   | Opt_F_flatten                      -- run the core-to-core coqPass, flattening the proof
+   | Opt_F_simpleopt_before_flatten     -- run the "simplPgmOpt" before the coqPass
+   | Opt_D_dump_proofs                  -- dump natural deduction typing proof of the coqpass input
+   | Opt_D_coqpass                      -- run the core-to-string coqPass and dumps the result
+
    | Opt_WarnIsError                    -- -Werror; makes warnings fatal
    | Opt_WarnDuplicateExports
    | Opt_WarnHiShadows
@@ -333,6 +340,7 @@ data ExtensionFlag
    | Opt_GHCForeignImportPrim
    | Opt_ParallelArrays                 -- Syntactic support for parallel arrays
    | Opt_Arrows                         -- Arrow-notation syntax
+   | Opt_ModalTypes                     -- Heterogeneous Metaprogramming (modal types, brackets, escape, CSP)
    | Opt_TemplateHaskell
    | Opt_QuasiQuotes
    | Opt_ImplicitParams
@@ -1362,6 +1370,14 @@ dynamic_flags = [
                                               setVerbosity (Just 2)))
   , Flag "dfaststring-stats"       (NoArg (setDynFlag Opt_D_faststring_stats))
 
+        ------ Coq-in-GHC ---------------------------
+  , Flag "ddump-proofs"            (NoArg (setDynFlag Opt_D_dump_proofs))
+  , Flag "ddump-coqpass"           (NoArg (setDynFlag Opt_D_coqpass))
+  , Flag "fcoqpass"                (NoArg (setDynFlag Opt_F_coqpass))
+  , Flag "fsimpleopt-before-flatten"                (NoArg (setDynFlag Opt_F_simpleopt_before_flatten))
+  , Flag "fflatten"                (NoArg (do { setDynFlag Opt_F_coqpass ; setDynFlag Opt_F_flatten }))
+  , Flag "funsafe-skolemize"       (NoArg (do { setDynFlag Opt_F_coqpass ; setDynFlag Opt_F_flatten ; setDynFlag Opt_F_skolemize }))
+
         ------ Machine dependant (-m<blah>) stuff ---------------------------
 
   , Flag "monly-2-regs" (NoArg (addWarn "The -monly-2-regs flag does nothing; it will be removed in a future GHC release"))
@@ -1663,6 +1679,7 @@ xFlags = [
     deprecatedForExtension "DoRec"),
   ( "DoRec",                            Opt_DoRec, nop ),    -- Enables 'rec' keyword 
   ( "Arrows",                           Opt_Arrows, nop ),
+  ( "ModalTypes",                      Opt_ModalTypes, nop ),
   ( "ParallelArrays",                   Opt_ParallelArrays, nop ),
   ( "TemplateHaskell",                  Opt_TemplateHaskell, checkTemplateHaskellOk ),
   ( "QuasiQuotes",                      Opt_QuasiQuotes, nop ),
@@ -1758,6 +1775,11 @@ impliedFlags
     , (Opt_FlexibleInstances,         turnOn, Opt_TypeSynonymInstances)
     , (Opt_FunctionalDependencies,    turnOn, Opt_MultiParamTypeClasses)
 
+    , (Opt_ModalTypes,                 turnOn,  Opt_RankNTypes)
+    , (Opt_ModalTypes,                 turnOn,  Opt_ExplicitForAll)
+    --, (Opt_ModalTypes,                 turnOn,  Opt_RebindableSyntax)
+    , (Opt_ModalTypes,                 turnOff, Opt_MonomorphismRestriction)
+
     , (Opt_RebindableSyntax, turnOff, Opt_ImplicitPrelude)      -- NB: turn off!
 
     , (Opt_GADTs,            turnOn, Opt_GADTSyntax)
index 43a4004..c9b2e1c 100644 (file)
@@ -56,6 +56,7 @@ module Lexer (
    getLexState, popLexState, pushLexState,
    extension, bangPatEnabled, datatypeContextsEnabled,
    addWarning,
+   incrBracketDepth, decrBracketDepth, getParserBrakDepth,
    lexTokenStream
   ) where
 
@@ -326,6 +327,15 @@ $tab+         { warn Opt_WarnTabs (text "Warning: Tab character") }
 }
 
 <0> {
+  "<[" / { ifExtension hetMetEnabled `alexAndPred` notFollowedBySymbol }
+                                       { special ITopenBrak }
+  "]>" / { ifExtension hetMetEnabled }  { special ITcloseBrak }
+  "~~" / { ifExtension hetMetEnabled }  { special ITescape }
+  "%%" / { ifExtension hetMetEnabled }  { special ITdoublePercent }
+  "~~$" / { ifExtension hetMetEnabled }  { special ITescapeDollar }
+}
+
+<0> {
   \? @varid / { ifExtension ipEnabled }        { skip_one_varid ITdupipvarid }
 }
 
@@ -569,6 +579,13 @@ data Token
   | ITLarrowtail               --  -<<
   | ITRarrowtail               --  >>-
 
+  -- Heterogeneous Metaprogramming extension
+  | ITopenBrak                 --  <[
+  | ITcloseBrak                        --  ]>
+  | ITescape                   --  ~~
+  | ITescapeDollar             --  ~~$
+  | ITdoublePercent             --  %%
+
   | ITunknown String           -- Used when the lexer can't make sense of it
   | ITeof                      -- end of file token
 
@@ -1530,7 +1547,8 @@ data PState = PState {
         alr_expecting_ocurly :: Maybe ALRLayout,
         -- Have we just had the '}' for a let block? If so, than an 'in'
         -- token doesn't need to close anything:
-        alr_justClosedExplicitLetBlock :: Bool
+        alr_justClosedExplicitLetBlock :: Bool,
+        code_type_bracket_depth :: Int
      }
        -- last_loc and last_len are used when generating error messages,
        -- and in pushCurrentContext only.  Sigh, if only Happy passed the
@@ -1597,6 +1615,13 @@ setExts f = P $ \s -> POk s{ extsBitmap = f (extsBitmap s) } ()
 setSrcLoc :: RealSrcLoc -> P ()
 setSrcLoc new_loc = P $ \s -> POk s{loc=new_loc} ()
 
+incrBracketDepth :: P ()
+incrBracketDepth = P $ \s -> POk (s{code_type_bracket_depth = (code_type_bracket_depth s)+1}) ()
+decrBracketDepth :: P ()
+decrBracketDepth = P $ \s -> POk (s{code_type_bracket_depth = (code_type_bracket_depth s)-1}) ()
+getParserBrakDepth :: P Int
+getParserBrakDepth = P $ \s -> POk s (code_type_bracket_depth s)
+
 getSrcLoc :: P RealSrcLoc
 getSrcLoc = P $ \s@(PState{ loc=loc }) -> POk s loc
 
@@ -1807,6 +1832,8 @@ relaxedLayoutBit :: Int
 relaxedLayoutBit = 24
 nondecreasingIndentationBit :: Int
 nondecreasingIndentationBit = 25
+hetMetBit :: Int
+hetMetBit = 31
 
 always :: Int -> Bool
 always           _     = True
@@ -1814,6 +1841,8 @@ parrEnabled :: Int -> Bool
 parrEnabled      flags = testBit flags parrBit
 arrowsEnabled :: Int -> Bool
 arrowsEnabled    flags = testBit flags arrowsBit
+hetMetEnabled :: Int -> Bool
+hetMetEnabled    flags = testBit flags hetMetBit
 thEnabled :: Int -> Bool
 thEnabled        flags = testBit flags thBit
 ipEnabled :: Int -> Bool
@@ -1875,12 +1904,14 @@ mkPState flags buf loc =
       alr_last_loc = alrInitialLoc (fsLit "<no file>"),
       alr_context = [],
       alr_expecting_ocurly = Nothing,
-      alr_justClosedExplicitLetBlock = False
+      alr_justClosedExplicitLetBlock = False,
+      code_type_bracket_depth = 0
     }
     where
       bitmap =     ffiBit            `setBitIf` xopt Opt_ForeignFunctionInterface flags
                .|. parrBit           `setBitIf` xopt Opt_ParallelArrays  flags
                .|. arrowsBit         `setBitIf` xopt Opt_Arrows          flags
+              .|. hetMetBit         `setBitIf` xopt Opt_ModalTypes      flags
                .|. thBit             `setBitIf` xopt Opt_TemplateHaskell flags
                .|. qqBit             `setBitIf` xopt Opt_QuasiQuotes     flags
                .|. ipBit             `setBitIf` xopt Opt_ImplicitParams  flags
index b663ac2..1a847ec 100644 (file)
@@ -39,7 +39,7 @@ import Type           ( funTyCon )
 import ForeignCall     ( Safety(..), CExportSpec(..), CLabelString,
                          CCallConv(..), CCallTarget(..), defaultCCallConv
                        )
-import OccName         ( varName, dataName, tcClsName, tvName )
+import OccName         ( varName, varNameDepth, dataName, tcClsName, tvName )
 import DataCon         ( DataCon, dataConName )
 import SrcLoc
 import Module
@@ -305,6 +305,11 @@ incorrect.
  '#)'          { L _ ITcubxparen }
  '(|'          { L _ IToparenbar }
  '|)'          { L _ ITcparenbar }
+ '<['          { L _ ITopenBrak }
+ ']>'          { L _ ITcloseBrak }
+ '~~'          { L _ ITescape }
+ '~~$'         { L _ ITescapeDollar }
+ '%%'          { L _ ITdoublePercent }
  ';'           { L _ ITsemi }
  ','           { L _ ITcomma }
  '`'           { L _ ITbackquote }
@@ -470,7 +475,7 @@ export      :: { LIE RdrName }
        |  oqtycon '(' ')'              { LL (IEThingWith (unLoc $1) []) }
        |  oqtycon '(' qcnames ')'      { LL (IEThingWith (unLoc $1) (reverse $3)) }
        |  'module' modid               { LL (IEModuleContents (unLoc $2)) }
-
+        | '<[' incdepth export decdepth ']>' { $3 }
 qcnames :: { [RdrName] }
        :  qcnames ',' qcname_ext       { unLoc $3 : $1 }
        |  qcname_ext                   { [unLoc $1]  }
@@ -1020,6 +1025,7 @@ atype :: { LHsType RdrName }
        | '(' ctype ',' comma_types1 ')'  { LL $ HsTupleTy Boxed  ($2:$4) }
        | '(#' comma_types1 '#)'        { LL $ HsTupleTy Unboxed $2     }
        | '[' ctype ']'                 { LL $ HsListTy  $2 }
+       | '<[' ctype ']>' '@' tyvar     { LL $ HsModalBoxType (unLoc $5) $2 }
        | '[:' ctype ':]'               { LL $ HsPArrTy  $2 }
        | '(' ctype ')'                 { LL $ HsParTy   $2 }
        | '(' ctype '::' kind ')'       { LL $ HsKindSig $2 (unLoc $4) }
@@ -1221,6 +1227,7 @@ decl      :: { Located (OrdList (LHsDecl RdrName)) }
         | infixexp opt_sig rhs  {% do { r <- checkValDef $1 $2 $3;
                                         let { l = comb2 $1 $> };
                                         return $! (sL l (unitOL $! (sL l $ ValD r))) } }
+
         | docdecl               { LL $ unitOL $1 }
 
 rhs    :: { Located (GRHSs RdrName) }
@@ -1264,6 +1271,10 @@ quasiquote :: { Located (HsQuasiQuote RdrName) }
                                 ; quoterId = mkUnqual varName quoter }
                             in L1 (mkHsQuasiQuote quoterId (RealSrcSpan quoteSpan) quote) }
 
+incdepth :: { Located () } :  {% do { incrBracketDepth ; return $ noLoc () } }
+decdepth :: { Located () } :  {% do { decrBracketDepth ; return $ noLoc () } }
+
+
 exp   :: { LHsExpr RdrName }
        : infixexp '::' sigtype         { LL $ ExprWithTySig $1 $3 }
        | infixexp '-<' exp             { LL $ HsArrApp $1 $3 placeHolderType HsFirstOrderApp True }
@@ -1271,6 +1282,7 @@ exp   :: { LHsExpr RdrName }
        | infixexp '-<<' exp            { LL $ HsArrApp $1 $3 placeHolderType HsHigherOrderApp True }
        | infixexp '>>-' exp            { LL $ HsArrApp $3 $1 placeHolderType HsHigherOrderApp False}
        | infixexp                      { $1 }
+       | '~~$' decdepth exp incdepth   { sL (comb2 $3 $>) (HsHetMetEsc placeHolderType placeHolderType $3) }
 
 infixexp :: { LHsExpr RdrName }
        : exp10                         { $1 }
@@ -1396,6 +1408,11 @@ aexp2    :: { LHsExpr RdrName }
        -- arrow notation extension
        | '(|' aexp2 cmdargs '|)'       { LL $ HsArrForm $2 Nothing (reverse $3) }
 
+       -- code type notation extension
+       | '<[' incdepth exp  decdepth ']>'      { sL (comb2 $3 $>) (HsHetMetBrak placeHolderType                 $3) }
+       | '~~' decdepth aexp incdepth           { sL (comb2 $3 $>) (HsHetMetEsc  placeHolderType placeHolderType $3) }
+       | '%%' decdepth aexp incdepth           { sL (comb2 $3 $>) (HsHetMetCSP  placeHolderType                 $3) }
+
 cmdargs        :: { [LHsCmdTop RdrName] }
        : cmdargs acmd                  { $2 : $1 }
        | {- empty -}                   { [] }
@@ -1829,7 +1846,7 @@ qvarid :: { Located RdrName }
         | PREFIXQVARSYM         { L1 $! mkQual varName (getPREFIXQVARSYM $1) }
 
 varid :: { Located RdrName }
-       : VARID                 { L1 $! mkUnqual varName (getVARID $1) }
+       : VARID                 {% do { depth <- getParserBrakDepth ; return (L1 $! mkUnqual (varNameDepth depth) (getVARID $1)) } }
        | special_id            { L1 $! mkUnqual varName (unLoc $1) }
        | 'unsafe'              { L1 $! mkUnqual varName (fsLit "unsafe") }
        | 'safe'                { L1 $! mkUnqual varName (fsLit "safe") }
@@ -1854,9 +1871,10 @@ varsym :: { Located RdrName }
        | '-'                   { L1 $ mkUnqual varName (fsLit "-") }
 
 varsym_no_minus :: { Located RdrName } -- varsym not including '-'
-       : VARSYM                { L1 $ mkUnqual varName (getVARSYM $1) }
-       | special_sym           { L1 $ mkUnqual varName (unLoc $1) }
-
+       : VARSYM                {% do { depth <- getParserBrakDepth
+                                      ; return (L1 $! mkUnqual (varNameDepth depth) (getVARSYM $1)) } }
+       | special_sym           {% do { depth <- getParserBrakDepth
+                                      ; return (L1 $! mkUnqual (varNameDepth depth) (unLoc $1)) } }
 
 -- These special_ids are treated as keywords in various places, 
 -- but as ordinary ids elsewhere.   'special_id' collects all these
index a943344..0e265e9 100644 (file)
@@ -122,6 +122,7 @@ extract_lty (L loc ty) acc
       HsAppTy ty1 ty2                  -> extract_lty ty1 (extract_lty ty2 acc)
       HsListTy ty                      -> extract_lty ty acc
       HsPArrTy ty                      -> extract_lty ty acc
+      HsModalBoxType ecn ty    -> extract_lty ty (extract_tv loc ecn acc)
       HsTupleTy _ tys                  -> extract_ltys tys acc
       HsFunTy ty1 ty2                  -> extract_lty ty1 (extract_lty ty2 acc)
       HsPredTy p               -> extract_pred p acc
@@ -646,6 +647,7 @@ checkAPat :: DynFlags -> SrcSpan -> HsExpr RdrName -> P (Pat RdrName)
 checkAPat dynflags loc e0 = case e0 of
    EWildPat -> return (WildPat placeHolderType)
    HsVar x  -> return (VarPat x)
+   HsHetMetBrak _ p -> checkAPat dynflags loc (unLoc p)
    HsLit l  -> return (LitPat l)
 
    -- Overloaded numeric patterns (e.g. f 0 x = x)
@@ -772,6 +774,8 @@ checkValSig
        :: LHsExpr RdrName
        -> LHsType RdrName
        -> P (Sig RdrName)
+checkValSig (L l (HsHetMetBrak _ e)) ty 
+  = checkValSig e ty
 checkValSig (L l (HsVar v)) ty 
   | isUnqual v && not (isDataOcc (rdrNameOcc v))
   = return (TypeSig (L l v) ty)
index d226cbe..a2c81de 100644 (file)
@@ -213,6 +213,34 @@ basicKnownKeyNames
        -- Other classes
        randomClassName, randomGenClassName, monadPlusClassName,
 
+        -- Code types
+        hetmet_brak_name, hetmet_esc_name, hetmet_csp_name, hetmet_flatten_name, hetmet_unflatten_name, hetmet_flattened_id_name,
+        hetmet_guest_integer_literal_name, hetmet_guest_string_literal_name,
+                                         hetmet_guest_char_literal_name,
+        hetmet_PGArrow_name,
+        hetmet_PGArrow_unit_name,
+        hetmet_PGArrow_tensor_name,
+        hetmet_PGArrow_exponent_name,
+        hetmet_pga_id_name,
+        hetmet_pga_comp_name,
+        hetmet_pga_first_name,
+        hetmet_pga_second_name,
+        hetmet_pga_cancell_name,
+        hetmet_pga_cancelr_name,
+        hetmet_pga_uncancell_name,
+        hetmet_pga_uncancelr_name,
+        hetmet_pga_assoc_name,
+        hetmet_pga_unassoc_name,
+        hetmet_pga_copy_name,
+        hetmet_pga_drop_name,
+        hetmet_pga_swap_name,
+        hetmet_pga_applyl_name,
+        hetmet_pga_applyr_name,
+        hetmet_pga_curryl_name,
+        hetmet_pga_curryr_name,
+        hetmet_pga_loopl_name,
+        hetmet_pga_loopr_name,
+
         -- Annotation type checking
         toAnnotationWrapperName
 
@@ -276,6 +304,9 @@ gHC_PRIM, gHC_TYPES, gHC_UNIT, gHC_ORDERING, gHC_GENERICS,
     gHC_MAGIC,
     gHC_CLASSES, gHC_BASE, gHC_ENUM, gHC_CSTRING,
     gHC_SHOW, gHC_READ, gHC_NUM, gHC_INTEGER, gHC_INTEGER_TYPE, gHC_LIST,
+    gHC_HETMET_CODETYPES,
+    gHC_HETMET_PRIVATE,
+    gHC_HETMET_GARROW,
     gHC_TUPLE, dATA_TUPLE, dATA_EITHER, dATA_STRING, dATA_FOLDABLE, dATA_TRAVERSABLE,
     gHC_CONC, gHC_IO, gHC_IO_Exception,
     gHC_ST, gHC_ARR, gHC_STABLE, gHC_PTR, gHC_ERR, gHC_REAL,
@@ -300,6 +331,9 @@ gHC_READ    = mkBaseModule (fsLit "GHC.Read")
 gHC_NUM                = mkBaseModule (fsLit "GHC.Num")
 gHC_INTEGER    = mkIntegerModule (fsLit "GHC.Integer")
 gHC_INTEGER_TYPE= mkIntegerModule (fsLit "GHC.Integer.Type")
+gHC_HETMET_CODETYPES = mkBaseModule (fsLit "GHC.HetMet.CodeTypes")
+gHC_HETMET_PRIVATE   = mkBaseModule (fsLit "GHC.HetMet.Private")
+gHC_HETMET_GARROW    = mkBaseModule (fsLit "GHC.HetMet.GArrow")
 gHC_LIST        = mkBaseModule (fsLit "GHC.List")
 gHC_TUPLE       = mkPrimModule (fsLit "GHC.Tuple")
 dATA_TUPLE      = mkBaseModule (fsLit "Data.Tuple")
@@ -882,6 +916,66 @@ toPName             pkg = varQual (gHC_PARR pkg) (fsLit "toP")             toPId
 emptyPName          pkg = varQual (gHC_PARR pkg) (fsLit "emptyP")          emptyPIdKey
 appPName            pkg = varQual (gHC_PARR pkg) (fsLit "+:+")             appPIdKey
 
+-- code type things
+hetmet_brak_name, hetmet_esc_name, hetmet_csp_name, hetmet_flatten_name, hetmet_unflatten_name, hetmet_flattened_id_name :: Name
+hetmet_guest_integer_literal_name, hetmet_guest_string_literal_name, hetmet_guest_char_literal_name :: Name
+hetmet_brak_name = varQual gHC_HETMET_CODETYPES (fsLit "hetmet_brak") hetmet_brak_key
+hetmet_esc_name  = varQual gHC_HETMET_CODETYPES (fsLit "hetmet_esc")  hetmet_esc_key
+hetmet_csp_name  = varQual gHC_HETMET_CODETYPES (fsLit "hetmet_csp") hetmet_csp_key
+hetmet_flatten_name  = varQual gHC_HETMET_CODETYPES (fsLit "pga_flatten") hetmet_flatten_key
+hetmet_unflatten_name  = varQual gHC_HETMET_CODETYPES (fsLit "pga_unflatten") hetmet_unflatten_key
+hetmet_flattened_id_name  = varQual gHC_HETMET_CODETYPES (fsLit "pga_flattened_id") hetmet_flattened_id_key
+hetmet_guest_integer_literal_name = varQual gHC_HETMET_CODETYPES (fsLit "guestIntegerLiteral") hetmet_guest_integer_literal_key
+hetmet_guest_string_literal_name  = varQual gHC_HETMET_CODETYPES (fsLit "guestStringLiteral")  hetmet_guest_string_literal_key
+hetmet_guest_char_literal_name    = varQual gHC_HETMET_CODETYPES (fsLit "guestCharLiteral")    hetmet_guest_char_literal_key
+
+hetmet_PGArrow_name :: Name
+hetmet_PGArrow_name = tcQual gHC_HETMET_PRIVATE (fsLit "PGArrow") hetmet_PGArrow_key
+hetmet_PGArrow_unit_name :: Name
+hetmet_PGArrow_unit_name = tcQual gHC_HETMET_GARROW (fsLit "GArrowUnit") hetmet_PGArrow_unit_key
+hetmet_PGArrow_tensor_name :: Name
+hetmet_PGArrow_tensor_name = tcQual gHC_HETMET_GARROW (fsLit "GArrowTensor") hetmet_PGArrow_tensor_key
+hetmet_PGArrow_exponent_name :: Name
+hetmet_PGArrow_exponent_name = tcQual gHC_HETMET_GARROW (fsLit "GArrowExponent") hetmet_PGArrow_exponent_key
+hetmet_pga_id_name :: Name
+hetmet_pga_id_name = varQual gHC_HETMET_PRIVATE (fsLit "pga_id") hetmet_pga_id_key
+hetmet_pga_comp_name :: Name
+hetmet_pga_comp_name = varQual gHC_HETMET_PRIVATE (fsLit "pga_comp") hetmet_pga_comp_key
+hetmet_pga_first_name :: Name
+hetmet_pga_first_name = varQual gHC_HETMET_PRIVATE (fsLit "pga_first") hetmet_pga_first_key
+hetmet_pga_second_name :: Name
+hetmet_pga_second_name = varQual gHC_HETMET_PRIVATE (fsLit "pga_second") hetmet_pga_second_key
+hetmet_pga_cancell_name :: Name
+hetmet_pga_cancell_name = varQual gHC_HETMET_PRIVATE (fsLit "pga_cancell") hetmet_pga_cancell_key
+hetmet_pga_cancelr_name :: Name
+hetmet_pga_cancelr_name = varQual gHC_HETMET_PRIVATE (fsLit "pga_cancelr") hetmet_pga_cancelr_key
+hetmet_pga_uncancell_name :: Name
+hetmet_pga_uncancell_name = varQual gHC_HETMET_PRIVATE (fsLit "pga_uncancell") hetmet_pga_uncancell_key
+hetmet_pga_uncancelr_name :: Name
+hetmet_pga_uncancelr_name = varQual gHC_HETMET_PRIVATE (fsLit "pga_uncancelr") hetmet_pga_uncancelr_key
+hetmet_pga_assoc_name :: Name
+hetmet_pga_assoc_name = varQual gHC_HETMET_PRIVATE (fsLit "pga_assoc") hetmet_pga_assoc_key
+hetmet_pga_unassoc_name :: Name
+hetmet_pga_unassoc_name = varQual gHC_HETMET_PRIVATE (fsLit "pga_unassoc") hetmet_pga_unassoc_key
+hetmet_pga_copy_name :: Name
+hetmet_pga_copy_name = varQual gHC_HETMET_PRIVATE (fsLit "pga_copy") hetmet_pga_copy_key
+hetmet_pga_drop_name :: Name
+hetmet_pga_drop_name = varQual gHC_HETMET_PRIVATE (fsLit "pga_drop") hetmet_pga_drop_key
+hetmet_pga_swap_name :: Name
+hetmet_pga_swap_name = varQual gHC_HETMET_PRIVATE (fsLit "pga_swap") hetmet_pga_swap_key
+hetmet_pga_applyl_name :: Name
+hetmet_pga_applyl_name = varQual gHC_HETMET_PRIVATE (fsLit "pga_applyl") hetmet_pga_applyl_key
+hetmet_pga_applyr_name :: Name
+hetmet_pga_applyr_name = varQual gHC_HETMET_PRIVATE (fsLit "pga_applyr") hetmet_pga_applyr_key
+hetmet_pga_curryl_name :: Name
+hetmet_pga_curryl_name = varQual gHC_HETMET_PRIVATE (fsLit "pga_curryl") hetmet_pga_curryl_key
+hetmet_pga_curryr_name :: Name
+hetmet_pga_curryr_name = varQual gHC_HETMET_PRIVATE (fsLit "pga_curryr") hetmet_pga_curryr_key
+hetmet_pga_loopl_name :: Name
+hetmet_pga_loopl_name = varQual gHC_HETMET_PRIVATE (fsLit "pga_loopl") hetmet_pga_loopl_key
+hetmet_pga_loopr_name :: Name
+hetmet_pga_loopr_name = varQual gHC_HETMET_PRIVATE (fsLit "pga_loopr") hetmet_pga_loopr_key
+
 -- IO things
 ioTyConName, ioDataConName, thenIOName, bindIOName, returnIOName,
     failIOName :: Name
@@ -1286,6 +1380,10 @@ parrDataConKey                           = mkPreludeDataConUnique 24
 leftDataConKey, rightDataConKey :: Unique
 leftDataConKey                         = mkPreludeDataConUnique 25
 rightDataConKey                                = mkPreludeDataConUnique 26
+
+-- Data constructor for Heterogeneous Metaprogramming code types
+hetMetCodeTypeDataConKey :: Unique
+hetMetCodeTypeDataConKey                       = mkPreludeDataConUnique 27
 \end{code}
 
 %************************************************************************
@@ -1490,6 +1588,70 @@ liftMIdKey      = mkPreludeMiscIdUnique 132
 groupMIdKey     = mkPreludeMiscIdUnique 133
 mzipIdKey       = mkPreludeMiscIdUnique 134
 
+-- code types
+hetMetCodeTypeTyConKey :: Unique
+hetMetCodeTypeTyConKey                 = mkPreludeTyConUnique 135
+
+hetmet_guest_integer_literal_key, hetmet_guest_string_literal_key, hetmet_guest_char_literal_key :: Unique
+hetmet_guest_integer_literal_key = mkPreludeMiscIdUnique 134
+hetmet_guest_string_literal_key  = mkPreludeMiscIdUnique 135
+hetmet_guest_char_literal_key    = mkPreludeMiscIdUnique 136
+hetmet_PGArrow_key :: Unique
+hetmet_PGArrow_key = mkPreludeMiscIdUnique 137
+hetmet_pga_id_key :: Unique
+hetmet_pga_id_key = mkPreludeMiscIdUnique 138
+hetmet_pga_comp_key :: Unique
+hetmet_pga_comp_key = mkPreludeMiscIdUnique 139
+hetmet_pga_first_key :: Unique
+hetmet_pga_first_key = mkPreludeMiscIdUnique 140
+hetmet_pga_second_key :: Unique
+hetmet_pga_second_key = mkPreludeMiscIdUnique 141
+hetmet_pga_cancell_key :: Unique
+hetmet_pga_cancell_key = mkPreludeMiscIdUnique 142
+hetmet_pga_cancelr_key :: Unique
+hetmet_pga_cancelr_key = mkPreludeMiscIdUnique 143
+hetmet_pga_uncancell_key :: Unique
+hetmet_pga_uncancell_key = mkPreludeMiscIdUnique 144
+hetmet_pga_uncancelr_key :: Unique
+hetmet_pga_uncancelr_key = mkPreludeMiscIdUnique 145
+hetmet_pga_assoc_key :: Unique
+hetmet_pga_assoc_key = mkPreludeMiscIdUnique 146
+hetmet_pga_unassoc_key :: Unique
+hetmet_pga_unassoc_key = mkPreludeMiscIdUnique 147
+hetmet_pga_copy_key :: Unique
+hetmet_pga_copy_key = mkPreludeMiscIdUnique 148
+hetmet_pga_drop_key :: Unique
+hetmet_pga_drop_key = mkPreludeMiscIdUnique 149
+hetmet_pga_swap_key :: Unique
+hetmet_pga_swap_key = mkPreludeMiscIdUnique 150
+hetmet_pga_applyl_key :: Unique
+hetmet_pga_applyl_key = mkPreludeMiscIdUnique 151
+hetmet_pga_applyr_key :: Unique
+hetmet_pga_applyr_key = mkPreludeMiscIdUnique 152
+hetmet_pga_curryl_key :: Unique
+hetmet_pga_curryl_key = mkPreludeMiscIdUnique 153
+hetmet_pga_curryr_key :: Unique
+hetmet_pga_curryr_key = mkPreludeMiscIdUnique 154
+hetmet_flatten_key = mkPreludeMiscIdUnique 155
+hetmet_unflatten_key = mkPreludeMiscIdUnique 156
+hetmet_flattened_id_key = mkPreludeMiscIdUnique 157
+hetmet_PGArrow_unit_key :: Unique
+hetmet_PGArrow_unit_key = mkPreludeMiscIdUnique 158
+hetmet_PGArrow_tensor_key :: Unique
+hetmet_PGArrow_tensor_key = mkPreludeMiscIdUnique 159
+hetmet_PGArrow_exponent_key :: Unique
+hetmet_PGArrow_exponent_key = mkPreludeMiscIdUnique 160
+
+hetmet_brak_key, hetmet_esc_key, hetmet_csp_key, hetmet_flatten_key, hetmet_unflatten_key, hetmet_flattened_id_key :: Unique
+hetmet_brak_key    = mkPreludeMiscIdUnique 161
+hetmet_esc_key     = mkPreludeMiscIdUnique 162
+hetmet_csp_key     = mkPreludeMiscIdUnique 163
+
+hetmet_pga_loopl_key :: Unique
+hetmet_pga_loopl_key = mkPreludeMiscIdUnique 164
+hetmet_pga_loopr_key :: Unique
+hetmet_pga_loopr_key = mkPreludeMiscIdUnique 165
+
 
 ---------------- Template Haskell -------------------
 --     USES IdUniques 200-499
@@ -1505,7 +1667,7 @@ mzipIdKey       = mkPreludeMiscIdUnique 134
 
 \begin{code}
 numericTyKeys :: [Unique]
-numericTyKeys = 
+numericTyKeys =
        [ wordTyConKey
        , intTyConKey
        , integerTyConKey
index d0495d7..5cacacd 100644 (file)
@@ -10,7 +10,7 @@
 --   They are all, therefore, wired-in TyCons.  C.f module TysWiredIn
 module TysPrim(
        alphaTyVars, betaTyVars, alphaTyVar, betaTyVar, gammaTyVar, deltaTyVar,
-       alphaTy, betaTy, gammaTy, deltaTy,
+       alphaTy, betaTy, gammaTy, deltaTy, ecTyVars,
        openAlphaTy, openBetaTy, openAlphaTyVar, openBetaTyVar, openAlphaTyVars,
         argAlphaTy, argAlphaTyVar, argBetaTy, argBetaTyVar,
 
@@ -27,6 +27,7 @@ module TysPrim(
        liftedTypeKind, unliftedTypeKind, openTypeKind,
         argTypeKind, ubxTupleKind,
         mkArrowKind, mkArrowKinds, isCoercionKind,
+        ecKind,
 
         funTyCon, funTyConName,
         primTyCons,
@@ -175,6 +176,11 @@ tyVarList kind = [ mkTyVar (mkInternalName (mkAlphaTyVarUnique u)
                            where c = chr (u-2 + ord 'a')
                 ]
 
+ecKind           = liftedTypeKind `mkArrowKind` (liftedTypeKind `mkArrowKind` liftedTypeKind)
+
+ecTyVars :: [TyVar]
+ecTyVars = tyVarList ecKind
+
 alphaTyVars :: [TyVar]
 alphaTyVars = tyVarList liftedTypeKind
 
index 5a80067..bc45028 100644 (file)
@@ -47,6 +47,12 @@ module TysWiredIn (
         -- * Unit
        unitTy,
 
+        -- * Heterogeneous Metaprogramming
+       mkHetMetCodeTypeTy,
+        hetMetCodeTypeTyConName,
+       hetMetCodeTypeTyCon,     isHetMetCodeTypeTyCon,
+       hetMetCodeTypeTyCon_RDR,
+
         -- * Parallel arrays
        mkPArrTy,
        parrTyCon, parrFakeCon, isPArrTyCon, isPArrFakeCon,
@@ -115,6 +121,7 @@ wiredInTyCons = [ unitTyCon -- Not treated like other tuples, because
              , intTyCon
              , listTyCon
              , parrTyCon
+             , hetMetCodeTypeTyCon
              ]
 \end{code}
 
@@ -159,8 +166,14 @@ parrTyConName   = mkWiredInTyConName   BuiltInSyntax
 parrDataConName = mkWiredInDataConName UserSyntax    
                     gHC_PARR' (fsLit "PArr") parrDataConKey parrDataCon
 
+hetMetCodeTypeTyConName :: Name
+hetMetCodeTypeTyConName        = mkWiredInTyConName   BuiltInSyntax gHC_HETMET_CODETYPES (fsLit "<[]>@")      hetMetCodeTypeTyConKey   hetMetCodeTypeTyCon 
+hetMetCodeTypeDataConName :: Name
+hetMetCodeTypeDataConName      =
+    mkWiredInDataConName  BuiltInSyntax gHC_HETMET_CODETYPES (fsLit "<[]>")      hetMetCodeTypeDataConKey hetMetCodeTypeDataCon
+
 boolTyCon_RDR, false_RDR, true_RDR, intTyCon_RDR, charTyCon_RDR,
-    intDataCon_RDR, listTyCon_RDR, consDataCon_RDR, parrTyCon_RDR:: RdrName
+    intDataCon_RDR, listTyCon_RDR, consDataCon_RDR, parrTyCon_RDR, hetMetCodeTypeTyCon_RDR :: RdrName
 boolTyCon_RDR   = nameRdrName boolTyConName
 false_RDR      = nameRdrName falseDataConName
 true_RDR       = nameRdrName trueDataConName
@@ -170,6 +183,7 @@ intDataCon_RDR      = nameRdrName intDataConName
 listTyCon_RDR  = nameRdrName listTyConName
 consDataCon_RDR = nameRdrName consDataConName
 parrTyCon_RDR  = nameRdrName parrTyConName
+hetMetCodeTypeTyCon_RDR        = nameRdrName hetMetCodeTypeTyConName
 \end{code}
 
 
@@ -592,3 +606,29 @@ mkPArrFakeCon arity  = data_con
 isPArrFakeCon      :: DataCon -> Bool
 isPArrFakeCon dcon  = dcon == parrFakeCon (dataConSourceArity dcon)
 \end{code}
+
+Heterogeneous Metaprogramming
+
+\begin{code}
+-- | Construct a type representing the application of the box type
+mkHetMetCodeTypeTy    :: TyVar -> Type -> Type
+mkHetMetCodeTypeTy ecn ty = mkTyConApp hetMetCodeTypeTyCon [(mkTyVarTy ecn), ty]
+
+ecTyVar = head ecTyVars
+
+-- | Represents the type constructor of box types
+hetMetCodeTypeTyCon :: TyCon
+hetMetCodeTypeTyCon  = pcNonRecDataTyCon hetMetCodeTypeTyConName [ecTyVar, betaTyVar] [hetMetCodeTypeDataCon]
+
+-- | Check whether a type constructor is the constructor for box types
+isHetMetCodeTypeTyCon    :: TyCon -> Bool
+isHetMetCodeTypeTyCon tc  = tyConName tc == hetMetCodeTypeTyConName
+
+hetMetCodeTypeDataCon :: DataCon
+hetMetCodeTypeDataCon  = pcDataCon 
+                hetMetCodeTypeDataConName 
+                [betaTyVar]            -- forall'ed type variables
+                [betaTy] 
+                hetMetCodeTypeTyCon
+
+\end{code}
index 4492b52..1301e61 100644 (file)
@@ -36,6 +36,7 @@ module RnEnv (
 
 import LoadIface       ( loadInterfaceForName, loadSrcInterface )
 import IfaceEnv                ( lookupOrig, newGlobalBinder, newIPName )
+import TcEnv           ( getHetMetLevel )
 import HsSyn
 import RdrHsSyn                ( extractHsTyRdrTyVars )
 import RdrName
@@ -785,14 +786,14 @@ lookupIfThenElse
 lookupSyntaxName :: Name                               -- The standard name
                 -> RnM (SyntaxExpr Name, FreeVars)     -- Possibly a non-standard name
 lookupSyntaxName std_name
-  = xoptM Opt_RebindableSyntax         `thenM` \ rebindable_on -> 
-    if not rebindable_on then normal_case 
-    else
-       -- Get the similarly named thing from the local environment
-    lookupOccRn (mkRdrUnqual (nameOccName std_name)) `thenM` \ usr_name ->
-    return (HsVar usr_name, unitFV usr_name)
-  where
-    normal_case = return (HsVar std_name, emptyFVs)
+  = do ec <- getHetMetLevel
+       std_name' <- return $ setNameDepth (length ec) std_name
+       rebindable_on <- xoptM Opt_RebindableSyntax
+       if not rebindable_on
+         then return (HsVar std_name', emptyFVs)
+         else do usr_name <- lookupOccRn (mkRdrUnqual (nameOccName std_name'))
+                 return (HsVar usr_name, unitFV usr_name)
+               -- Get the similarly named thing from the local environment
 
 lookupSyntaxTable :: [Name]                            -- Standard names
                  -> RnM (SyntaxTable Name, FreeVars)   -- See comments with HsExpr.ReboundNames
index 88e0462..9b1f08e 100644 (file)
@@ -25,7 +25,7 @@ import RnBinds   ( rnLocalBindsAndThen, rnLocalValBindsLHS, rnLocalValBindsRHS,
                    rnMatchGroup, makeMiniFixityEnv) 
 import HsSyn
 import TcRnMonad
-import TcEnv           ( thRnBrack )
+import TcEnv           ( thRnBrack, getHetMetLevel )
 import RnEnv
 import RnTypes         ( rnHsTypeFVs, rnSplice, checkTH,
                          mkOpFormRn, mkOpAppRn, mkNegAppRn, checkSectionPrec)
@@ -34,6 +34,7 @@ import DynFlags
 import BasicTypes      ( FixityDirection(..) )
 import PrelNames
 
+import Var              ( TyVar, varName )
 import Name
 import NameSet
 import RdrName
@@ -84,6 +85,13 @@ rnExprs ls = rnExprs' ls emptyUniqSet
 Variables. We look up the variable and return the resulting name. 
 
 \begin{code}
+
+-- during the renamer phase we only care about the length of the
+-- current HetMet level; the actual tyvars don't
+-- matter, so we use bottoms for them
+dummyTyVar :: TyVar
+dummyTyVar = error "tried to force RnExpr.dummyTyVar"
+
 rnLExpr :: LHsExpr RdrName -> RnM (LHsExpr Name, FreeVars)
 rnLExpr = wrapLocFstM rnExpr
 
@@ -157,6 +165,21 @@ rnExpr (NegApp e _)
     mkNegAppRn e' neg_name     `thenM` \ final_e ->
     return (final_e, fv_e `plusFV` fv_neg)
 
+rnExpr (HsHetMetBrak c e)
+  = do { (e', fv_e) <- updLclEnv (\x -> x { tcl_hetMetLevel = dummyTyVar:(tcl_hetMetLevel x) }) $ rnLExpr e
+       ; return (HsHetMetBrak c e', fv_e)
+       }
+rnExpr (HsHetMetEsc c t e)
+  = do { (e', fv_e) <- updLclEnv (\x -> x { tcl_hetMetLevel = tail (tcl_hetMetLevel x) }) $ rnLExpr e
+       ; return (HsHetMetEsc c t e', fv_e)
+       }
+rnExpr (HsHetMetCSP c e)
+  = do { (e', fv_e) <- updLclEnv (\x -> x { tcl_hetMetLevel = tail (tcl_hetMetLevel x) }) $ rnLExpr e
+       ; return (HsHetMetCSP c e', fv_e)
+       }
+
+    
+
 ------------------------------------------
 -- Template Haskell extensions
 -- Don't ifdef-GHCI them because we want to fail gracefully
index bfbcdc5..f4fdc3b 100644 (file)
@@ -18,7 +18,7 @@ module RnHsSyn(
 
 import HsSyn
 import Class            ( FunDep )
-import TysWiredIn       ( tupleTyCon, listTyCon, parrTyCon, charTyCon )
+import TysWiredIn       ( tupleTyCon, listTyCon, parrTyCon, hetMetCodeTypeTyCon, charTyCon )
 import Name             ( Name, getName, isTyVarName )
 import NameSet
 import BasicTypes       ( Boxity )
@@ -38,6 +38,8 @@ charTyCon_name, listTyCon_name, parrTyCon_name :: Name
 charTyCon_name    = getName charTyCon
 listTyCon_name    = getName listTyCon
 parrTyCon_name    = getName parrTyCon
+hetMetCodeTypeTyCon_name :: Name
+hetMetCodeTypeTyCon_name = getName hetMetCodeTypeTyCon
 
 tupleTyCon_name :: Boxity -> Int -> Name
 tupleTyCon_name boxity n = getName (tupleTyCon boxity n)
@@ -57,6 +59,7 @@ extractHsTyNames ty
     get (HsAppTy ty1 ty2)      = getl ty1 `unionNameSets` getl ty2
     get (HsListTy ty)          = unitNameSet listTyCon_name `unionNameSets` getl ty
     get (HsPArrTy ty)          = unitNameSet parrTyCon_name `unionNameSets` getl ty
+    get (HsModalBoxType ecn ty) = (unitNameSet ecn) `unionNameSets` (unitNameSet hetMetCodeTypeTyCon_name) `unionNameSets` (getl ty)
     get (HsTupleTy _ tys)      = extractHsTyNames_s tys
     get (HsFunTy ty1 ty2)      = getl ty1 `unionNameSets` getl ty2
     get (HsPredTy p)           = extractHsPredTyNames p
index be90d7d..31382c2 100644 (file)
@@ -163,6 +163,11 @@ rnHsType doc (HsPArrTy ty) = do
     ty' <- rnLHsType doc ty
     return (HsPArrTy ty')
 
+rnHsType doc (HsModalBoxType ecn ty) = do
+    ecn' <- lookupOccRn ecn
+    ty' <- rnLHsType doc ty
+    return (HsModalBoxType ecn' ty')
+
 -- Unboxed tuples are allowed to have poly-typed arguments.  These
 -- sometimes crop up as a result of CPR worker-wrappering dictionaries.
 rnHsType doc (HsTupleTy tup_con tys) = do
index 96dc261..94daff0 100644 (file)
@@ -29,6 +29,7 @@ module TcEnv(
        tcLookupId, tcLookupTyVar, getScopedTyVarBinds,
        getInLocalScope,
        wrongThingErr, pprBinders,
+        getHetMetLevel,
 
        tcExtendRecEnv,         -- For knot-tying
 
@@ -405,11 +406,19 @@ tcExtendIdEnv ids thing_inside = tcExtendIdEnv2 [(idName id, id) | id <- ids] th
 tcExtendIdEnv1 :: Name -> TcId -> TcM a -> TcM a
 tcExtendIdEnv1 name id thing_inside = tcExtendIdEnv2 [(name,id)] thing_inside
 
+getHetMetLevel :: TcM [TyVar]
+getHetMetLevel =
+    do { env <- getEnv
+       ; return $ case env of Env { env_lcl = e' } -> case e' of TcLclEnv { tcl_hetMetLevel = x } -> x
+       }
+
 tcExtendIdEnv2 :: [(Name,TcId)] -> TcM a -> TcM a
 -- Invariant: the TcIds are fully zonked (see tcExtendIdEnv above)
 tcExtendIdEnv2 names_w_ids thing_inside
   = do { env <- getLclEnv
-       ; tc_extend_local_id_env env (thLevel (tcl_th_ctxt env)) names_w_ids thing_inside }
+        ; hetMetLevel <- getHetMetLevel
+       ; tc_extend_local_id_env env (thLevel (tcl_th_ctxt env)) hetMetLevel names_w_ids thing_inside }
+
 
 tcExtendGhciEnv :: [TcId] -> TcM a -> TcM a
 -- Used to bind Ids for GHCi identifiers bound earlier in the user interaction
@@ -418,11 +427,13 @@ tcExtendGhciEnv :: [TcId] -> TcM a -> TcM a
 -- GHCi has already compiled it to bytecode
 tcExtendGhciEnv ids thing_inside
   = do { env <- getLclEnv
-       ; tc_extend_local_id_env env impLevel [(idName id, id) | id <- ids] thing_inside }
+        ; hetMetLevel <- getHetMetLevel
+       ; tc_extend_local_id_env env impLevel hetMetLevel [(idName id, id) | id <- ids] thing_inside }
 
 tc_extend_local_id_env         -- This is the guy who does the work
        :: TcLclEnv
        -> ThLevel
+       -> [TyVar]
        -> [(Name,TcId)]
        -> TcM a -> TcM a
 -- Invariant: the TcIds are fully zonked. Reasons:
@@ -432,7 +443,7 @@ tc_extend_local_id_env              -- This is the guy who does the work
 --         in the types, because instantiation does not look through such things
 --     (c) The call to tyVarsOfTypes is ok without looking through refs
 
-tc_extend_local_id_env env th_lvl names_w_ids thing_inside
+tc_extend_local_id_env env th_lvl hetMetLevel names_w_ids thing_inside
   = do { traceTc "env2" (ppr extra_env)
        ; gtvs' <- tcExtendGlobalTyVars (tcl_tyvars env) extra_global_tyvars
        ; let env' = env {tcl_env = le', tcl_tyvars = gtvs', tcl_rdr = rdr_env'}
@@ -440,7 +451,9 @@ tc_extend_local_id_env env th_lvl names_w_ids thing_inside
   where
     extra_global_tyvars = tcTyVarsOfTypes [idType id | (_,id) <- names_w_ids]
     extra_env      = [ (name, ATcId { tct_id = id, 
-                                      tct_level = th_lvl })
+                                      tct_level = th_lvl,
+                                      tct_hetMetLevel = hetMetLevel
+                                     })
                      | (name,id) <- names_w_ids]
     le'                    = extendNameEnvList (tcl_env env) extra_env
     rdr_env'       = extendLocalRdrEnvList (tcl_rdr env) [name | (name,_) <- names_w_ids]
index ee6a34a..70592af 100644 (file)
@@ -42,12 +42,13 @@ import DataCon
 import Name
 import TyCon
 import Type
+import TypeRep
 import Coercion
 import Var
 import VarSet
 import VarEnv
 import TysWiredIn
-import TysPrim( intPrimTy )
+import TysPrim( intPrimTy, ecKind )
 import PrimOp( tagToEnumKey )
 import PrelNames
 import Module
@@ -139,17 +140,68 @@ tcInfExpr e             = tcInfer (tcExpr e)
 %************************************************************************
 
 \begin{code}
+
+updHetMetLevel :: ([TyVar] -> [TyVar]) -> TcM a -> TcM a
+updHetMetLevel f comp =
+    updEnv
+      (\oldenv -> let oldlev = (case oldenv of Env { env_lcl = e' } -> case e' of TcLclEnv { tcl_hetMetLevel = x } -> x)
+                  in (oldenv { env_lcl = (env_lcl oldenv) { tcl_hetMetLevel = f oldlev } }))
+                  
+      comp
+
+addEscapes :: [TyVar] -> HsExpr Name -> HsExpr Name
+addEscapes []     e = e
+addEscapes (t:ts) e = HsHetMetEsc (TyVarTy t) placeHolderType (noLoc (addEscapes ts e))
+
+getIdLevel :: Name -> TcM [TyVar]
+getIdLevel name
+       = do { thing <- tcLookup name
+           ; case thing of
+                ATcId { tct_hetMetLevel = variable_hetMetLevel } -> return $ variable_hetMetLevel
+                 _ -> return []
+            }
+
 tcExpr :: HsExpr Name -> TcRhoType -> TcM (HsExpr TcId)
 tcExpr e res_ty | debugIsOn && isSigmaTy res_ty     -- Sanity check
                        = pprPanic "tcExpr: sigma" (ppr res_ty $$ ppr e)
 
 tcExpr (HsVar name)  res_ty = tcCheckId name res_ty
 
-tcExpr (HsApp e1 e2) res_ty = tcApp e1 [e2] res_ty
+tcExpr (HsHetMetBrak _ e) res_ty =
+    do { (coi, [inferred_name,elt_ty]) <- matchExpectedTyConApp hetMetCodeTypeTyCon res_ty
+       ; fresh_ec_name <- newFlexiTyVar ecKind
+       ; expr' <-  updHetMetLevel (\old_lev -> (fresh_ec_name:old_lev))
+                   $ tcPolyExpr e elt_ty
+       ; unifyType (TyVarTy fresh_ec_name) inferred_name
+       ; return $ mkHsWrapCo coi (HsHetMetBrak (TyVarTy fresh_ec_name) expr') }
+tcExpr (HsHetMetEsc _ _ e) res_ty =
+    do { cur_level <- getHetMetLevel
+       ; expr' <-  updHetMetLevel (\old_lev -> tail old_lev)
+                   $ tcExpr (unLoc e) (mkTyConApp hetMetCodeTypeTyCon [(TyVarTy $ head cur_level),res_ty])
+       ; ty' <- zonkTcType res_ty
+       ; return $ HsHetMetEsc (TyVarTy $ head cur_level) ty' (noLoc expr') }
+tcExpr (HsHetMetCSP _ e) res_ty =
+    do { cur_level <- getHetMetLevel
+       ; expr' <-  updHetMetLevel (\old_lev -> tail old_lev)
+                   $ tcExpr (unLoc e) res_ty
+       ; return $ HsHetMetCSP (TyVarTy $ head cur_level) (noLoc expr') }
 
-tcExpr (HsLit lit)   res_ty = do { let lit_ty = hsLitType lit
-                                ; tcWrapResult (HsLit lit) lit_ty res_ty }
+tcExpr (HsApp e1 e2) res_ty = tcApp e1 [e2] res_ty
 
+tcExpr (HsLit lit)   res_ty =
+  getHetMetLevel >>= \lev ->
+   case lev of
+    []        -> do { let lit_ty = hsLitType lit
+                    ; tcWrapResult (HsLit lit) lit_ty res_ty }
+    (ec:rest) -> let n = case lit of
+                                (HsChar c)       -> hetmet_guest_char_literal_name
+                                (HsString str)   -> hetmet_guest_string_literal_name
+                                (HsInteger i _)  -> hetmet_guest_integer_literal_name
+                                (HsInt i)        -> hetmet_guest_integer_literal_name
+                                _                -> error "literals of this sort are not allowed at depth >0"
+                 in  tcExpr (HsHetMetEsc (TyVarTy ec) placeHolderType $ noLoc $
+                                         (HsApp (noLoc $ HsVar n) (noLoc $ HsLit lit))) res_ty
+  
 tcExpr (HsPar expr)  res_ty = do { expr' <- tcMonoExprNC expr res_ty
                                 ; return (HsPar expr') }
 
@@ -165,9 +217,18 @@ tcExpr (HsCoreAnn lbl expr) res_ty
   = do { expr' <- tcMonoExpr expr res_ty
        ; return (HsCoreAnn lbl expr') }
 
-tcExpr (HsOverLit lit) res_ty  
-  = do         { lit' <- newOverloadedLit (LiteralOrigin lit) lit res_ty
-       ; return (HsOverLit lit') }
+tcExpr (HsOverLit lit) res_ty =
+  getHetMetLevel >>= \lev ->
+   case lev of
+    []        -> do { lit' <- newOverloadedLit (LiteralOrigin lit) lit res_ty
+                   ; return (HsOverLit lit') }
+    (ec:rest) -> let n = case lit of
+                           (OverLit { ol_val = HsIntegral i   }) -> hetmet_guest_integer_literal_name
+                           (OverLit { ol_val = HsIsString fs  }) -> hetmet_guest_string_literal_name
+                           (OverLit { ol_val = HsFractional f }) -> error "fractional literals not allowed at depth >0"
+                 in  tcExpr (HsHetMetEsc (TyVarTy ec) placeHolderType $ noLoc $
+                                         (HsApp (noLoc $ HsVar n) (noLoc $ HsOverLit lit))) res_ty
+  
 
 tcExpr (NegApp expr neg_expr) res_ty
   = do { neg_expr' <- tcSyntaxOp NegateOrigin neg_expr
@@ -963,24 +1024,40 @@ tcInferId n = tcInferIdWithOrig (OccurrenceOf n) n
 tcInferIdWithOrig :: CtOrigin -> Name -> TcM (HsExpr TcId, TcRhoType)
 -- Look up an occurrence of an Id, and instantiate it (deeply)
 
-tcInferIdWithOrig orig id_name
-  = do { id <- lookup_id
-       ; (id_expr, id_rho) <- instantiateOuter orig id
-       ; (wrap, rho) <- deeplyInstantiate orig id_rho
-       ; return (mkHsWrap wrap id_expr, rho) }
+tcInferIdWithOrig orig id_name =
+ do { id_level  <- getIdLevel id_name
+    ; cur_level <- getHetMetLevel
+    ; if (length id_level < length cur_level)
+      then do { (lhexp, tcrho) <-
+                    tcInferRho (noLoc $ addEscapes (take ((length cur_level) - (length id_level)) cur_level) (HsVar id_name))
+              ; return (unLoc lhexp, tcrho)
+              }
+      else tcInferIdWithOrig' orig id_name
+    }
+
+tcInferIdWithOrig' orig id_name =
+  do { id <- lookup_id
+     ; (id_expr, id_rho) <- instantiateOuter orig id
+     ; (wrap, rho) <- deeplyInstantiate orig id_rho
+     ; return (mkHsWrap wrap id_expr, rho) }
   where
     lookup_id :: TcM TcId
     lookup_id 
        = do { thing <- tcLookup id_name
            ; case thing of
-                ATcId { tct_id = id, tct_level = lvl }
+                ATcId { tct_id = id, tct_level = lvl, tct_hetMetLevel = variable_hetMetLevel }
                   -> do { check_naughty id        -- Note [Local record selectors]
                          ; checkThLocalId id lvl
+                         ; current_hetMetLevel  <- getHetMetLevel
+                         ; mapM
+                             (\(name1,name2) -> unifyType (TyVarTy name1) (TyVarTy name2))
+                             (zip variable_hetMetLevel current_hetMetLevel)
                          ; return id }
 
                 AGlobal (AnId id) 
-                   -> do { check_naughty id; return id }
-                       -- A global cannot possibly be ill-staged
+                   -> do { check_naughty id
+                         ; return id }
+                       -- A global cannot possibly be ill-staged in Template Haskell
                        -- nor does it need the 'lifting' treatment
                         -- hence no checkTh stuff here
 
index 3b4afae..6ba78d9 100644 (file)
@@ -546,6 +546,22 @@ zonkExpr env (HsPar e)
   = zonkLExpr env e    `thenM` \new_e ->
     returnM (HsPar new_e)
 
+zonkExpr env (HsHetMetBrak c e)    
+  = do c' <- zonkTcTypeToType env c
+       e' <- zonkLExpr env e
+       return (HsHetMetBrak c' e')
+
+zonkExpr env (HsHetMetEsc c t e)    
+  = do c' <- zonkTcTypeToType env c
+       t' <- zonkTcTypeToType env t
+       e' <- zonkLExpr env e
+       return (HsHetMetEsc c' t' e')
+
+zonkExpr env (HsHetMetCSP c e)    
+  = do c' <- zonkTcTypeToType env c
+       e' <- zonkLExpr env e
+       return (HsHetMetCSP c' e')
+
 zonkExpr env (SectionL expr op)
   = zonkLExpr env expr `thenM` \ new_expr ->
     zonkLExpr env op           `thenM` \ new_op ->
index 7d9f93c..f826e72 100644 (file)
@@ -37,6 +37,7 @@ import TcMType
 import TcUnify
 import TcIface
 import TcType
+import TysPrim ( ecKind )
 import {- Kind parts of -} Type
 import Var
 import VarSet
@@ -364,6 +365,11 @@ kc_hs_type (HsPArrTy ty) = do
     ty' <- kcLiftedType ty
     return (HsPArrTy ty', liftedTypeKind)
 
+kc_hs_type (HsModalBoxType ecn ty) = do
+    kc_check_hs_type (HsTyVar ecn) (EK ecKind EkUnk)
+    ty' <- kcLiftedType ty
+    return (HsModalBoxType ecn ty', liftedTypeKind)
+
 kc_hs_type (HsKindSig ty k) = do
     ty' <- kc_check_lhs_type ty (EK k EkKindSig)
     return (HsKindSig ty' k, k)
@@ -570,6 +576,11 @@ ds_type (HsPArrTy ty) = do
     checkWiredInTyCon parrTyCon
     return (mkPArrTy tau_ty)
 
+ds_type (HsModalBoxType ecn ty) = do
+    tau_ty <- dsHsType ty
+    checkWiredInTyCon hetMetCodeTypeTyCon
+    return (mkHetMetCodeTypeTy (mkTyVar ecn ecKind) tau_ty)
+
 ds_type (HsTupleTy boxity tys) = do
     tau_tys <- dsHsTypes tys
     checkWiredInTyCon tycon
index ce84178..43232e5 100644 (file)
@@ -135,7 +135,8 @@ initTc hsc_env hsc_src keep_rn_syntax mod do_this
                tcl_tyvars     = tvs_var,
                tcl_lie        = lie_var,
                 tcl_meta       = meta_var,
-               tcl_untch      = initTyVarUnique
+               tcl_untch      = initTyVarUnique,
+                tcl_hetMetLevel    = []
             } ;
        } ;
    
index 17e5dcb..d94ecd7 100644 (file)
@@ -377,6 +377,7 @@ data TcLclEnv               -- Changes as we move inside an expression
                -- We still need the unsullied global name env so that
                --   we can look up record field names
 
+        tcl_hetMetLevel  :: [TyVar],    -- The current environment classifier level (list-of-names)
        tcl_env  :: TcTypeEnv,    -- The local type environment: Ids and
                                  -- TyVars defined in this module
                                        
@@ -513,7 +514,9 @@ data TcTyThing
 
   | ATcId   {          -- Ids defined in this module; may not be fully zonked
        tct_id    :: TcId,              
-       tct_level :: ThLevel }
+       tct_level :: ThLevel,
+       tct_hetMetLevel :: [TyVar]
+    }
 
   | ATyVar  Name TcType                -- The type to which the lexically scoped type vaiable
                                -- is currently refined. We only need the Name
@@ -528,7 +531,8 @@ instance Outputable TcTyThing where -- Debugging only
    ppr elt@(ATcId {})   = text "Identifier" <> 
                          brackets (ppr (tct_id elt) <> dcolon 
                                  <> ppr (varType (tct_id elt)) <> comma
-                                <+> ppr (tct_level elt))
+                                <+> ppr (tct_level elt)
+                                <+> ppr (tct_hetMetLevel elt))
    ppr (ATyVar tv _)    = text "Type variable" <+> quotes (ppr tv)
    ppr (AThing k)       = text "AThing" <+> ppr k
 
index 0594f7f..668ddda 100644 (file)
@@ -232,4 +232,5 @@ defaultKind k
   | isSubOpenTypeKind k = liftedTypeKind
   | isSubArgTypeKind k  = liftedTypeKind
   | otherwise        = k
+
 \end{code}
\ No newline at end of file
diff --git a/ghc.mk b/ghc.mk
index 4508b68..fe5e845 100644 (file)
--- a/ghc.mk
+++ b/ghc.mk
@@ -1211,3 +1211,15 @@ phase_0_builds: $(utils/genprimopcode_dist_depfile_c_asm)
 .PHONY: phase_1_builds
 phase_1_builds: $(PACKAGE_DATA_MKS)
 
+# -----------------------------------------------------------------------------
+# Support for writing GHC passes in Coq
+
+compiler/hetmet/Makefile:
+       git submodule update --init compiler/hetmet
+       cd compiler/hetmet/; git checkout master
+compiler/hetmet/build/CoqPass.hs: compiler/hetmet/Makefile $(wildcard compiler/hetmet/src/*.v) $(wildcard compiler/hetmet/src/*.hs)
+       cd compiler/hetmet; make build/CoqPass.hs
+compiler/stage1/build/CoqPass.hs: compiler/hetmet/build/CoqPass.hs
+       cp compiler/hetmet/build/CoqPass.hs $@
+compiler/stage2/build/CoqPass.hs: compiler/hetmet/build/CoqPass.hs
+       cp compiler/hetmet/build/CoqPass.hs $@
diff --git a/libraries/base b/libraries/base
new file mode 160000 (submodule)
index 0000000..9404945
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit 9404945188d8f4e4daf851c0bc53a61c80b8fdfc