X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2FcoreSyn%2FCoreSyn.lhs;h=e580bed20c0a78d024a90915db2b5b09a2d429b6;hp=f83845f3f5b26fd35074854fef8745aca6a04ade;hb=8100cd4395e46ae747be4298c181a4730d6206bc;hpb=afbc90b056b31768e243f3b4900034aec1c6b706 diff --git a/compiler/coreSyn/CoreSyn.lhs b/compiler/coreSyn/CoreSyn.lhs index f83845f..e580bed 100644 --- a/compiler/coreSyn/CoreSyn.lhs +++ b/compiler/coreSyn/CoreSyn.lhs @@ -1,7 +1,9 @@ % +% (c) The University of Glasgow 2006 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 % -\section[CoreSyn]{A data type for the Haskell compiler midsection} + +CoreSyn: A data type for the Haskell compiler midsection \begin{code} module CoreSyn ( @@ -40,22 +42,22 @@ module CoreSyn ( -- Core rules CoreRule(..), -- CoreSubst, CoreTidy, CoreFVs, PprCore only - RuleName, seqRules, + RuleName, seqRules, ruleArity, isBuiltinRule, ruleName, isLocalRule, ruleIdName ) where #include "HsVersions.h" -import StaticFlags ( opt_RuntimeTypes ) -import CostCentre ( CostCentre, noCostCentre ) -import Var ( Var, Id, TyVar, isTyVar, isId ) -import Type ( Type, mkTyVarTy, seqType ) -import Coercion ( Coercion ) -import Name ( Name ) -import OccName ( OccName ) -import Literal ( Literal, mkMachInt ) -import DataCon ( DataCon, dataConWorkId, dataConTag ) -import BasicTypes ( Activation ) +import StaticFlags +import CostCentre +import Var +import Type +import Coercion +import Name +import OccName +import Literal +import DataCon +import BasicTypes import FastString import Outputable @@ -112,7 +114,8 @@ type Arg b = Expr b -- Can be a Type type Alt b = (AltCon, [b], Expr b) -- (DEFAULT, [], rhs) is the default alternative -data AltCon = DataAlt DataCon +data AltCon = DataAlt DataCon -- Invariant: the DataCon is always from + -- a *data* type, and never from a *newtype* | LitAlt Literal | DEFAULT deriving (Eq, Ord) @@ -200,18 +203,23 @@ data CoreRule ru_local :: Bool, -- The fn at the head of the rule is -- defined in the same module as the rule - -- Orphan-hood; see comments is InstEnv.Instance( is_orph ) + -- Orphan-hood; see Note [Orphans] in InstEnv ru_orph :: Maybe OccName } | BuiltinRule { -- Built-in rules are used for constant folding ru_name :: RuleName, -- and suchlike. It has no free variables. ru_fn :: Name, -- Name of the Id at -- the head of this rule + ru_nargs :: Int, -- Number of args that ru_try expects ru_try :: [CoreExpr] -> Maybe CoreExpr } isBuiltinRule (BuiltinRule {}) = True isBuiltinRule _ = False +ruleArity :: CoreRule -> Int +ruleArity (BuiltinRule {ru_nargs = n}) = n +ruleArity (Rule {ru_args = args}) = length args + ruleName :: CoreRule -> RuleName ruleName = ru_name @@ -439,7 +447,7 @@ mkLets :: [Bind b] -> Expr b -> Expr b mkLams :: [b] -> Expr b -> Expr b mkLit lit = Lit lit -mkConApp con args = pprTrace "mkConApp" (ppr con) $ mkApps (Var (dataConWorkId con)) args +mkConApp con args = mkApps (Var (dataConWorkId con)) args mkLams binders body = foldr Lam body binders mkLets binds body = foldr Let body binds @@ -603,7 +611,6 @@ seqExpr (Lit lit) = lit `seq` () seqExpr (App f a) = seqExpr f `seq` seqExpr a seqExpr (Lam b e) = seqBndr b `seq` seqExpr e seqExpr (Let b e) = seqBind b `seq` seqExpr e --- gaw 2004 seqExpr (Case e b t as) = seqExpr e `seq` seqBndr b `seq` seqType t `seq` seqAlts as seqExpr (Cast e co) = seqExpr e `seq` seqType co seqExpr (Note n e) = seqNote n `seq` seqExpr e @@ -651,7 +658,6 @@ data AnnExpr' bndr annot | AnnLit Literal | AnnLam bndr (AnnExpr bndr annot) | AnnApp (AnnExpr bndr annot) (AnnExpr bndr annot) --- gaw 2004 | AnnCase (AnnExpr bndr annot) bndr Type [AnnAlt bndr annot] | AnnLet (AnnBind bndr annot) (AnnExpr bndr annot) | AnnCast (AnnExpr bndr annot) Coercion @@ -683,7 +689,6 @@ deAnnotate' (AnnLet bind body) deAnnBind (AnnNonRec var rhs) = NonRec var (deAnnotate rhs) deAnnBind (AnnRec pairs) = Rec [(v,deAnnotate rhs) | (v,rhs) <- pairs] --- gaw 2004 deAnnotate' (AnnCase scrut v t alts) = Case (deAnnotate scrut) v t (map deAnnAlt alts)