where
ty = exprType fun
- ignore_note InlineCall = True
- ignore_note InlineMe = True
- ignore_note _other = False
- -- we don't ignore SCCs, since they require some code generation
+ ignore_note (CoreNote _) = True
+ ignore_note InlineCall = True
+ ignore_note InlineMe = True
+ ignore_note _other = False
+ -- We don't ignore SCCs, since they require some code generation
------------------------------------------------------------------------------
-- Building the saturated syntax
| InlineMe -- Instructs simplifer to treat the enclosed expression
-- as very small, and inline it at its call sites
+ | CoreNote String -- A generic core annotation, propagated but not used by GHC
+
-- NOTE: we also treat expressions wrapped in InlineMe as
-- 'cheap' and 'dupable' (in the sense of exprIsCheap, exprIsDupable)
-- What this means is that we obediently inline even things that don't
seqExprs (e:es) = seqExpr e `seq` seqExprs es
seqNote (Coerce t1 t2) = seqType t1 `seq` seqType t2
+seqNote (CoreNote s) = s `seq` ()
seqNote other = ()
seqBndr b = b `seq` ()
eq_note env (SCC cc1) (SCC cc2) = cc1 == cc2
eq_note env (Coerce t1 f1) (Coerce t2 f2) = t1 `eqType` t2 && f1 `eqType` f2
eq_note env InlineCall InlineCall = True
+ eq_note env (CoreNote s1) (CoreNote s2) = s1 == s2
eq_note env other1 other2 = False
\end{code}
noteSize (Coerce t1 t2) = seqType t1 `seq` seqType t2 `seq` 1
noteSize InlineCall = 1
noteSize InlineMe = 1
+noteSize (CoreNote s) = s `seq` 1 -- hdaume: core annotations
varSize :: Var -> Int
varSize b | isTyVar b = 1
make_exp (Note (SCC cc) e) = C.Note "SCC" (make_exp e) -- temporary
make_exp (Note (Coerce t_to t_from) e) = C.Coerce (make_ty t_to) (make_exp e)
make_exp (Note InlineCall e) = C.Note "InlineCall" (make_exp e)
+make_exp (Note (CoreNote s) e) = C.Note s (make_exp e) -- hdaume: core annotations
make_exp (Note InlineMe e) = C.Note "InlineMe" (make_exp e)
make_exp _ = error "MkExternalCore died: make_exp"
import BasicTypes ( tupleParens )
import Util ( lengthIs )
import Outputable
+import FastString ( mkFastString )
\end{code}
%************************************************************************
ppr_expr add_par (Note InlineMe expr)
= add_par $ ptext SLIT("__inline_me") <+> pprParendExpr expr
+ppr_expr add_par (Note (CoreNote s) expr)
+ = add_par $
+ sep [sep [ptext SLIT("__core_note"), pprHsString (mkFastString s)],
+ pprParendExpr expr]
+
pprCoreAlt (con, args, rhs)
= hang (ppr_case_pat con args) 2 (pprCoreExpr rhs)
getModuleDs `thenDs` \ mod_name ->
returnDs (Note (SCC (mkUserCC cc mod_name)) core_expr)
+
+-- hdaume: core annotation
+
+dsExpr (HsCoreAnn fs expr)
+ = dsExpr expr `thenDs` \ core_expr ->
+ returnDs (Note (CoreNote $ unpackFS fs) core_expr)
+
-- special case to handle unboxed tuple patterns.
dsExpr (HsCase discrim matches src_loc)
ds3 <- repE e3
repFromThenTo ds1 ds2 ds3
repE (PArrSeqOut _ aseq) = panic "DsMeta.repE: parallel array seq.s missing"
+repE (HsCoreAnn _ _) = panic "DsMeta.repE: Can't represent CoreAnn" -- hdaume: core annotations
repE (HsCCall _ _ _ _ _) = panic "DsMeta.repE: Can't represent __ccall__"
repE (HsSCC _ _) = panic "DsMeta.repE: Can't represent SCC"
repE (HsBracketOut _ _) =
| UfCoerce (HsType name)
| UfInlineCall
| UfInlineMe
+ | UfCoreNote String
type UfAlt name = (UfConAlt name, [name], UfExpr name)
toUfNote (Coerce t1 _) = UfCoerce (toHsType t1)
toUfNote InlineCall = UfInlineCall
toUfNote InlineMe = UfInlineMe
+toUfNote (CoreNote s) = UfCoreNote s
---------------------
toUfBind (NonRec b r) = UfNonRec (toUfBndr b) (toUfExpr r)
ppr (UfCoerce ty) = ptext SLIT("__coerce") <+> pprParendHsType ty
ppr UfInlineCall = ptext SLIT("__inline_call")
ppr UfInlineMe = ptext SLIT("__inline_me")
+ ppr (UfCoreNote s)= ptext SLIT("__core_note") <+> pprHsString (mkFastString s)
instance Outputable name => Outputable (UfConAlt name) where
ppr UfDefault = text "__DEFAULT"
eq_ufNote (UfCoerce t1) (UfCoerce t2) = eq_hsType env t1 t2
eq_ufNote UfInlineCall UfInlineCall = True
eq_ufNote UfInlineMe UfInlineMe = True
+ eq_ufNote (UfCoreNote s1) (UfCoreNote s2) = s1==s2
eq_ufNote _ _ = False
eq_ufExpr env _ _ = False
| HsSCC FastString -- "set cost centre" (_scc_) annotation
(HsExpr id) -- expr whose cost is to be measured
+
+ | HsCoreAnn FastString -- hdaume: core annotation
+ (HsExpr id)
-- MetaHaskell Extensions
| HsBracket (HsBracket id) SrcLoc
putByte bh 2
put_ bh UfInlineMe = do
putByte bh 3
+ put_ bh (UfCoreNote s) = do
+ putByte bh 4
+ put_ bh s
get bh = do
h <- getByte bh
case h of
1 -> do ab <- get bh
return (UfCoerce ab)
2 -> do return UfInlineCall
- _ -> do return UfInlineMe
+ 3 -> do return UfInlineMe
+ _ -> do ac <- get bh
+ return (UfCoreNote ac)
instance (Binary name) => Binary (BangType name) where
put_ bh (BangType aa ab) = do
| ITdeprecated_prag
| ITline_prag
| ITscc_prag
+ | ITcore_prag -- hdaume: core annotations
| ITclose_prag
| ITdotdot -- reserved symbols
( "RULES", ITrules_prag ),
( "RULEZ", ITrules_prag ), -- american spelling :-)
( "SCC", ITscc_prag ),
+ ( "CORE", ITcore_prag ), -- hdaume: core annotation
( "DEPRECATED", ITdeprecated_prag )
]
{- -*-haskell-*-
-----------------------------------------------------------------------------
-$Id: Parser.y,v 1.115 2003/02/12 15:01:37 simonpj Exp $
+$Id: Parser.y,v 1.116 2003/02/20 18:33:53 simonpj Exp $
Haskell grammar.
'{-# INLINE' { ITinline_prag }
'{-# NOINLINE' { ITnoinline_prag }
'{-# RULES' { ITrules_prag }
+ '{-# CORE' { ITcore_prag } -- hdaume: annotated core
'{-# SCC' { ITscc_prag }
'{-# DEPRECATED' { ITdeprecated_prag }
'#-}' { ITclose_prag }
then HsSCC $1 $2
else HsPar $2 }
+ | '{-# CORE' STRING '#-}' exp { HsCoreAnn $2 $4 } -- hdaume: core annotation
+
| reifyexp { HsReify $1 }
| fexp { $1 }
cReturnableClassName,
ioDataConName])
+rnExpr (HsCoreAnn ann expr)
+ = rnExpr expr `thenM` \ (expr', fvs_expr) ->
+ returnM (HsCoreAnn ann expr', fvs_expr)
+
rnExpr (HsSCC lbl expr)
= rnExpr expr `thenM` \ (expr', fvs_expr) ->
returnM (HsSCC lbl expr', fvs_expr)
rnNote (UfSCC cc) = returnM (UfSCC cc)
rnNote UfInlineCall = returnM UfInlineCall
rnNote UfInlineMe = returnM UfInlineMe
-
+rnNote (UfCoreNote s) = returnM (UfCoreNote s)
rnUfCon UfDefault
= returnM UfDefault
fiExpr to_drop (_, AnnNote note@(Coerce _ _) expr)
= -- Just float in past coercion
Note note (fiExpr to_drop expr)
+
+fiExpr to_drop (_, AnnNote note@(CoreNote _) expr)
+ = Note note (fiExpr to_drop expr)
\end{code}
For @Lets@, the possible ``drop points'' for the \tr{to_drop}
-- an interesting context of any kind to combine with
-- (even a type application -- anything except Stop)
= simplExprF env e cont
+
+simplNote env (CoreNote s) e cont
+ = simplExpr env e `thenSmpl` \ e' ->
+ rebuild env (Note (CoreNote s) e') cont
\end{code}
-> TcM (Maybe Inst, Id)
-- mkMethId instantiates the selector Id at the specified types
--- THe
mkMethId origin clas sel_id inst_tys
= let
(tyvars,rho) = tcSplitForAllTys (idType sel_id)
tcMonoExpr (HsSCC lbl expr) res_ty = tcMonoExpr expr res_ty `thenM` \ expr' ->
returnM (HsSCC lbl expr')
-
+tcMonoExpr (HsCoreAnn lbl expr) res_ty = tcMonoExpr expr res_ty `thenM` \ expr' -> -- hdaume: core annotation
+ returnM (HsCoreAnn lbl expr')
tcMonoExpr (NegApp expr neg_name) res_ty
= tcMonoExpr (HsApp (HsVar neg_name) expr) res_ty
-- ToDo: use tcSyntaxName
= zonkExpr env expr `thenM` \ new_expr ->
returnM (HsSCC lbl new_expr)
+-- hdaume: core annotations
+zonkExpr env (HsCoreAnn lbl expr)
+ = zonkExpr env expr `thenM` \ new_expr ->
+ returnM (HsCoreAnn lbl new_expr)
+
zonkExpr env (TyLam tyvars expr)
= mappM zonkTcTyVarToTyVar tyvars `thenM` \ new_tyvars ->
-- No need to extend tyvar env; see AbsBinds