2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
4 \section[CoreUtils]{Utility functions on @Core@ syntax}
9 mkNote, mkInlineMe, mkSCC, mkCoerce,
10 bindNonRec, mkIfThenElse, mkAltExpr,
13 -- Properties of expressions
14 exprType, coreAltsType,
15 exprIsBottom, exprIsDupable, exprIsTrivial, exprIsCheap,
16 exprIsValue,exprOkForSpeculation, exprIsBig,
18 idAppIsBottom, idAppIsCheap,
20 -- Expr transformation
21 etaReduceExpr, exprEtaExpandArity,
30 cheapEqExpr, eqExpr, applyTypeToArgs
33 #include "HsVersions.h"
36 import GlaExts -- For `xori`
39 import CoreFVs ( exprFreeVars )
40 import PprCore ( pprCoreExpr )
41 import Var ( Var, isId, isTyVar )
44 import Name ( isLocallyDefined, hashName )
45 import Literal ( Literal, hashLiteral, literalType, litIsDupable )
46 import DataCon ( DataCon, dataConRepArity )
47 import PrimOp ( primOpOkForSpeculation, primOpIsCheap,
49 import Id ( Id, idType, idFlavour, idStrictness, idLBVarInfo,
50 mkWildId, idArity, idName, idUnfolding, idInfo,
51 isDataConId_maybe, isPrimOpId_maybe
53 import IdInfo ( arityLowerBound, InlinePragInfo(..),
57 import Demand ( appIsBottom )
58 import Type ( Type, mkFunTy, mkForAllTy,
59 splitFunTy_maybe, tyVarsOfType, tyVarsOfTypes,
60 isNotUsgTy, mkUsgTy, unUsgTy, UsageAnn(..),
61 applyTys, isUnLiftedType, seqType
63 import TysWiredIn ( boolTy, stringTy, trueDataCon, falseDataCon )
64 import CostCentre ( CostCentre )
65 import Unique ( buildIdKey, augmentIdKey )
66 import Util ( zipWithEqual, mapAccumL )
67 import Maybes ( maybeToBool )
69 import TysPrim ( alphaTy ) -- Debugging only
73 %************************************************************************
75 \subsection{Find the type of a Core atom/expression}
77 %************************************************************************
80 exprType :: CoreExpr -> Type
82 exprType (Var var) = idType var
83 exprType (Lit lit) = literalType lit
84 exprType (Let _ body) = exprType body
85 exprType (Case _ _ alts) = coreAltsType alts
86 exprType (Note (Coerce ty _) e) = ty -- **! should take usage from e
87 exprType (Note (TermUsg u) e) = mkUsgTy u (unUsgTy (exprType e))
88 exprType (Note other_note e) = exprType e
89 exprType (Lam binder expr) = mkPiType binder (exprType expr)
91 = case collectArgs e of
92 (fun, args) -> applyTypeToArgs e (exprType fun) args
94 exprType other = pprTrace "exprType" (pprCoreExpr other) alphaTy
96 coreAltsType :: [CoreAlt] -> Type
97 coreAltsType ((_,_,rhs) : _) = exprType rhs
100 @mkPiType@ makes a (->) type or a forall type, depending on whether
101 it is given a type variable or a term variable. We cleverly use the
102 lbvarinfo field to figure out the right annotation for the arrove in
103 case of a term variable.
106 mkPiType :: Var -> Type -> Type -- The more polymorphic version doesn't work...
107 mkPiType v ty | isId v = (case idLBVarInfo v of
108 IsOneShotLambda -> mkUsgTy UsOnce
110 mkFunTy (idType v) ty
111 | isTyVar v = mkForAllTy v ty
115 -- The first argument is just for debugging
116 applyTypeToArgs :: CoreExpr -> Type -> [CoreExpr] -> Type
117 applyTypeToArgs e op_ty [] = op_ty
119 applyTypeToArgs e op_ty (Type ty : args)
120 = -- Accumulate type arguments so we can instantiate all at once
121 ASSERT2( all isNotUsgTy tys,
122 ppr e <+> text "of" <+> ppr op_ty <+> text "to" <+>
123 ppr (Type ty : args) <+> text "i.e." <+> ppr tys )
124 applyTypeToArgs e (applyTys op_ty tys) rest_args
126 (tys, rest_args) = go [ty] args
127 go tys (Type ty : args) = go (ty:tys) args
128 go tys rest_args = (reverse tys, rest_args)
130 applyTypeToArgs e op_ty (other_arg : args)
131 = case (splitFunTy_maybe op_ty) of
132 Just (_, res_ty) -> applyTypeToArgs e res_ty args
133 Nothing -> pprPanic "applyTypeToArgs" (pprCoreExpr e)
138 %************************************************************************
140 \subsection{Attaching notes}
142 %************************************************************************
144 mkNote removes redundant coercions, and SCCs where possible
147 mkNote :: Note -> CoreExpr -> CoreExpr
148 mkNote (Coerce to_ty from_ty) expr = mkCoerce to_ty from_ty expr
149 mkNote (SCC cc) expr = mkSCC cc expr
150 mkNote InlineMe expr = mkInlineMe expr
151 mkNote note expr = Note note expr
153 -- Slide InlineCall in around the function
154 -- No longer necessary I think (SLPJ Apr 99)
155 -- mkNote InlineCall (App f a) = App (mkNote InlineCall f) a
156 -- mkNote InlineCall (Var v) = Note InlineCall (Var v)
157 -- mkNote InlineCall expr = expr
160 Drop trivial InlineMe's. This is somewhat important, because if we have an unfolding
161 that looks like (Note InlineMe (Var v)), the InlineMe doesn't go away because it may
162 not be *applied* to anything.
165 mkInlineMe e | exprIsTrivial e = e
166 | otherwise = Note InlineMe e
172 mkCoerce :: Type -> Type -> CoreExpr -> CoreExpr
174 mkCoerce to_ty from_ty (Note (Coerce to_ty2 from_ty2) expr)
175 = ASSERT( from_ty == to_ty2 )
176 mkCoerce to_ty from_ty2 expr
178 mkCoerce to_ty from_ty expr
179 | to_ty == from_ty = expr
180 | otherwise = ASSERT( from_ty == exprType expr )
181 Note (Coerce to_ty from_ty) expr
185 mkSCC :: CostCentre -> Expr b -> Expr b
186 -- Note: Nested SCC's *are* preserved for the benefit of
187 -- cost centre stack profiling (Durham)
189 mkSCC cc (Lit lit) = Lit lit
190 mkSCC cc (Lam x e) = Lam x (mkSCC cc e) -- Move _scc_ inside lambda
191 mkSCC cc expr = Note (SCC cc) expr
195 %************************************************************************
197 \subsection{Other expression construction}
199 %************************************************************************
202 bindNonRec :: Id -> CoreExpr -> CoreExpr -> CoreExpr
203 -- (bindNonRec x r b) produces either
206 -- case r of x { _DEFAULT_ -> b }
208 -- depending on whether x is unlifted or not
209 -- It's used by the desugarer to avoid building bindings
210 -- that give Core Lint a heart attack. Actually the simplifier
211 -- deals with them perfectly well.
212 bindNonRec bndr rhs body
213 | isUnLiftedType (idType bndr) = Case rhs bndr [(DEFAULT,[],body)]
214 | otherwise = Let (NonRec bndr rhs) body
218 mkAltExpr :: AltCon -> [CoreBndr] -> [Type] -> CoreExpr
219 -- This guy constructs the value that the scrutinee must have
220 -- when you are in one particular branch of a case
221 mkAltExpr (DataAlt con) args inst_tys
222 = mkConApp con (map Type inst_tys ++ map varToCoreExpr args)
223 mkAltExpr (LitAlt lit) [] []
226 mkIfThenElse :: CoreExpr -> CoreExpr -> CoreExpr -> CoreExpr
227 mkIfThenElse guard then_expr else_expr
228 = Case guard (mkWildId boolTy)
229 [ (DataAlt trueDataCon, [], then_expr),
230 (DataAlt falseDataCon, [], else_expr) ]
233 %************************************************************************
235 \subsection{Figuring out things about expressions}
237 %************************************************************************
239 @exprIsTrivial@ is true of expressions we are unconditionally happy to
240 duplicate; simple variables and constants, and type
241 applications. Note that primop Ids aren't considered
244 @exprIsBottom@ is true of expressions that are guaranteed to diverge
248 exprIsTrivial (Var v)
249 | Just op <- isPrimOpId_maybe v = primOpIsDupable op
251 exprIsTrivial (Type _) = True
252 exprIsTrivial (Lit lit) = True
253 exprIsTrivial (App e arg) = isTypeArg arg && exprIsTrivial e
254 exprIsTrivial (Note _ e) = exprIsTrivial e
255 exprIsTrivial (Lam b body) | isTyVar b = exprIsTrivial body
256 exprIsTrivial other = False
260 @exprIsDupable@ is true of expressions that can be duplicated at a modest
261 cost in code size. This will only happen in different case
262 branches, so there's no issue about duplicating work.
264 That is, exprIsDupable returns True of (f x) even if
265 f is very very expensive to call.
267 Its only purpose is to avoid fruitless let-binding
268 and then inlining of case join points
272 exprIsDupable (Type _) = True
273 exprIsDupable (Var v) = True
274 exprIsDupable (Lit lit) = litIsDupable lit
275 exprIsDupable (Note _ e) = exprIsDupable e
279 go (Var v) n_args = True
280 go (App f a) n_args = n_args < dupAppSize
283 go other n_args = False
286 dupAppSize = 4 -- Size of application we are prepared to duplicate
289 @exprIsCheap@ looks at a Core expression and returns \tr{True} if
290 it is obviously in weak head normal form, or is cheap to get to WHNF.
291 [Note that that's not the same as exprIsDupable; an expression might be
292 big, and hence not dupable, but still cheap.]
294 By ``cheap'' we mean a computation we're willing to:
295 push inside a lambda, or
296 inline at more than one place
297 That might mean it gets evaluated more than once, instead of being
298 shared. The main examples of things which aren't WHNF but are
303 (where e, and all the ei are cheap)
306 (where e and b are cheap)
309 (where op is a cheap primitive operator)
312 (because we are happy to substitute it inside a lambda)
314 Notice that a variable is considered 'cheap': we can push it inside a lambda,
315 because sharing will make sure it is only evaluated once.
318 exprIsCheap :: CoreExpr -> Bool
319 exprIsCheap (Lit lit) = True
320 exprIsCheap (Type _) = True
321 exprIsCheap (Var _) = True
322 exprIsCheap (Note _ e) = exprIsCheap e
323 exprIsCheap (Lam x e) = if isId x then True else exprIsCheap e
324 exprIsCheap (Case e _ alts) = exprIsCheap e &&
325 and [exprIsCheap rhs | (_,_,rhs) <- alts]
326 -- Experimentally, treat (case x of ...) as cheap
327 -- (and case __coerce x etc.)
328 -- This improves arities of overloaded functions where
329 -- there is only dictionary selection (no construction) involved
330 exprIsCheap (Let (NonRec x _) e)
331 | isUnLiftedType (idType x) = exprIsCheap e
333 -- strict lets always have cheap right hand sides, and
336 exprIsCheap other_expr
337 = go other_expr 0 True
339 go (Var f) n_args args_cheap
340 = (idAppIsCheap f n_args && args_cheap)
341 -- A constructor, cheap primop, or partial application
343 || idAppIsBottom f n_args
344 -- Application of a function which
345 -- always gives bottom; we treat this as cheap
346 -- because it certainly doesn't need to be shared!
348 go (App f a) n_args args_cheap
349 | isTypeArg a = go f n_args args_cheap
350 | otherwise = go f (n_args + 1) (exprIsCheap a && args_cheap)
352 go other n_args args_cheap = False
354 idAppIsCheap :: Id -> Int -> Bool
355 idAppIsCheap id n_val_args
356 | n_val_args == 0 = True -- Just a type application of
357 -- a variable (f t1 t2 t3)
359 | otherwise = case idFlavour id of
361 RecordSelId _ -> True -- I'm experimenting with making record selection
362 -- look cheap, so we will substitute it inside a
363 -- lambda. Particularly for dictionary field selection
365 PrimOpId op -> primOpIsCheap op -- In principle we should worry about primops
366 -- that return a type variable, since the result
367 -- might be applied to something, but I'm not going
368 -- to bother to check the number of args
369 other -> n_val_args < idArity id
372 exprOkForSpeculation returns True of an expression that it is
374 * safe to evaluate even if normal order eval might not
375 evaluate the expression at all, or
377 * safe *not* to evaluate even if normal order would do so
381 the expression guarantees to terminate,
383 without raising an exception,
384 without causing a side effect (e.g. writing a mutable variable)
387 let x = case y# +# 1# of { r# -> I# r# }
390 case y# +# 1# of { r# ->
395 We can only do this if the (y+1) is ok for speculation: it has no
396 side effects, and can't diverge or raise an exception.
399 exprOkForSpeculation :: CoreExpr -> Bool
400 exprOkForSpeculation (Lit _) = True
401 exprOkForSpeculation (Var v) = isUnLiftedType (idType v)
402 exprOkForSpeculation (Note _ e) = exprOkForSpeculation e
403 exprOkForSpeculation other_expr
404 = go other_expr 0 True
406 go (Var f) n_args args_ok
407 = case idFlavour f of
408 DataConId _ -> True -- The strictness of the constructor has already
409 -- been expressed by its "wrapper", so we don't need
410 -- to take the arguments into account
412 PrimOpId op -> primOpOkForSpeculation op && args_ok
413 -- A bit conservative: we don't really need
414 -- to care about lazy arguments, but this is easy
418 go (App f a) n_args args_ok
419 | isTypeArg a = go f n_args args_ok
420 | otherwise = go f (n_args + 1) (exprOkForSpeculation a && args_ok)
422 go other n_args args_ok = False
427 exprIsBottom :: CoreExpr -> Bool -- True => definitely bottom
428 exprIsBottom e = go 0 e
430 -- n is the number of args
431 go n (Note _ e) = go n e
432 go n (Let _ e) = go n e
433 go n (Case e _ _) = go 0 e -- Just check the scrut
434 go n (App e _) = go (n+1) e
435 go n (Var v) = idAppIsBottom v n
437 go n (Lam _ _) = False
439 idAppIsBottom :: Id -> Int -> Bool
440 idAppIsBottom id n_val_args = appIsBottom (idStrictness id) n_val_args
443 @exprIsValue@ returns true for expressions that are certainly *already*
444 evaluated to WHNF. This is used to decide wether it's ok to change
445 case x of _ -> e ===> e
447 and to decide whether it's safe to discard a `seq`
449 So, it does *not* treat variables as evaluated, unless they say they are
452 exprIsValue :: CoreExpr -> Bool -- True => Value-lambda, constructor, PAP
453 exprIsValue (Type ty) = True -- Types are honorary Values; we don't mind
455 exprIsValue (Lit l) = True
456 exprIsValue (Lam b e) = isId b || exprIsValue e
457 exprIsValue (Note _ e) = exprIsValue e
458 exprIsValue other_expr
461 go (Var f) n_args = idAppIsValue f n_args
464 | isTypeArg a = go f n_args
465 | otherwise = go f (n_args + 1)
467 go (Note _ f) n_args = go f n_args
469 go other n_args = False
471 idAppIsValue :: Id -> Int -> Bool
472 idAppIsValue id n_val_args
473 = case idFlavour id of
475 PrimOpId _ -> n_val_args < idArity id
476 other | n_val_args == 0 -> isEvaldUnfolding (idUnfolding id)
477 | otherwise -> n_val_args < idArity id
478 -- A worry: what if an Id's unfolding is just itself:
479 -- then we could get an infinite loop...
483 exprIsConApp_maybe :: CoreExpr -> Maybe (DataCon, [CoreExpr])
484 exprIsConApp_maybe expr
485 = analyse (collectArgs expr)
487 analyse (Var fun, args)
488 | maybeToBool maybe_con_app = maybe_con_app
490 maybe_con_app = case isDataConId_maybe fun of
491 Just con | length args >= dataConRepArity con
492 -- Might be > because the arity excludes type args
496 analyse (Var fun, [])
497 = case maybeUnfoldingTemplate (idUnfolding fun) of
499 Just unf -> exprIsConApp_maybe unf
501 analyse other = Nothing
505 %************************************************************************
507 \subsection{Eta reduction and expansion}
509 %************************************************************************
511 @etaReduceExpr@ trys an eta reduction at the top level of a Core Expr.
513 e.g. \ x y -> f x y ===> f
515 But we only do this if it gets rid of a whole lambda, not part.
516 The idea is that lambdas are often quite helpful: they indicate
517 head normal forms, so we don't want to chuck them away lightly.
520 etaReduceExpr :: CoreExpr -> CoreExpr
521 -- ToDo: we should really check that we don't turn a non-bottom
522 -- lambda into a bottom variable. Sigh
524 etaReduceExpr expr@(Lam bndr body)
525 = check (reverse binders) body
527 (binders, body) = collectBinders expr
530 | not (any (`elemVarSet` body_fvs) binders)
533 body_fvs = exprFreeVars body
535 check (b : bs) (App fun arg)
536 | (varToCoreExpr b `cheapEqExpr` arg)
539 check _ _ = expr -- Bale out
541 etaReduceExpr expr = expr -- The common case
546 exprEtaExpandArity :: CoreExpr -> Int -- The number of args the thing can be applied to
547 -- without doing much work
548 -- This is used when eta expanding
549 -- e ==> \xy -> e x y
551 -- It returns 1 (or more) to:
552 -- case x of p -> \s -> ...
553 -- because for I/O ish things we really want to get that \s to the top.
554 -- We are prepared to evaluate x each time round the loop in order to get that
555 -- Hence "generous" arity
558 = go e `max` 0 -- Never go -ve!
560 go (Var v) = idArity v
561 go (App f (Type _)) = go f
562 go (App f a) | exprIsCheap a = go f - 1
563 go (Lam x e) | isId x = go e + 1
565 go (Note n e) | ok_note n = go e
566 go (Case scrut _ alts)
567 | exprIsCheap scrut = min_zero [go rhs | (_,_,rhs) <- alts]
569 | all exprIsCheap (rhssOfBind b) = go e
573 ok_note (Coerce _ _) = True
574 ok_note InlineCall = True
575 ok_note other = False
576 -- Notice that we do not look through __inline_me__
577 -- This one is a bit more surprising, but consider
578 -- f = _inline_me (\x -> e)
579 -- We DO NOT want to eta expand this to
580 -- f = \x -> (_inline_me (\x -> e)) x
581 -- because the _inline_me gets dropped now it is applied,
586 min_zero :: [Int] -> Int -- Find the minimum, but zero is the smallest
587 min_zero (x:xs) = go x xs
589 go 0 xs = 0 -- Nothing beats zero
591 go min (x:xs) | x < min = go x xs
592 | otherwise = go min xs
597 %************************************************************************
599 \subsection{Equality}
601 %************************************************************************
603 @cheapEqExpr@ is a cheap equality test which bales out fast!
604 True => definitely equal
605 False => may or may not be equal
608 cheapEqExpr :: Expr b -> Expr b -> Bool
610 cheapEqExpr (Var v1) (Var v2) = v1==v2
611 cheapEqExpr (Lit lit1) (Lit lit2) = lit1 == lit2
612 cheapEqExpr (Type t1) (Type t2) = t1 == t2
614 cheapEqExpr (App f1 a1) (App f2 a2)
615 = f1 `cheapEqExpr` f2 && a1 `cheapEqExpr` a2
617 cheapEqExpr _ _ = False
619 exprIsBig :: Expr b -> Bool
620 -- Returns True of expressions that are too big to be compared by cheapEqExpr
621 exprIsBig (Lit _) = False
622 exprIsBig (Var v) = False
623 exprIsBig (Type t) = False
624 exprIsBig (App f a) = exprIsBig f || exprIsBig a
625 exprIsBig other = True
630 eqExpr :: CoreExpr -> CoreExpr -> Bool
631 -- Works ok at more general type, but only needed at CoreExpr
633 = eq emptyVarEnv e1 e2
635 -- The "env" maps variables in e1 to variables in ty2
636 -- So when comparing lambdas etc,
637 -- we in effect substitute v2 for v1 in e1 before continuing
638 eq env (Var v1) (Var v2) = case lookupVarEnv env v1 of
639 Just v1' -> v1' == v2
642 eq env (Lit lit1) (Lit lit2) = lit1 == lit2
643 eq env (App f1 a1) (App f2 a2) = eq env f1 f2 && eq env a1 a2
644 eq env (Lam v1 e1) (Lam v2 e2) = eq (extendVarEnv env v1 v2) e1 e2
645 eq env (Let (NonRec v1 r1) e1)
646 (Let (NonRec v2 r2) e2) = eq env r1 r2 && eq (extendVarEnv env v1 v2) e1 e2
647 eq env (Let (Rec ps1) e1)
648 (Let (Rec ps2) e2) = length ps1 == length ps2 &&
649 and (zipWith eq_rhs ps1 ps2) &&
652 env' = extendVarEnvList env [(v1,v2) | ((v1,_),(v2,_)) <- zip ps1 ps2]
653 eq_rhs (_,r1) (_,r2) = eq env' r1 r2
654 eq env (Case e1 v1 a1)
655 (Case e2 v2 a2) = eq env e1 e2 &&
656 length a1 == length a2 &&
657 and (zipWith (eq_alt env') a1 a2)
659 env' = extendVarEnv env v1 v2
661 eq env (Note n1 e1) (Note n2 e2) = eq_note env n1 n2 && eq env e1 e2
662 eq env (Type t1) (Type t2) = t1 == t2
665 eq_list env [] [] = True
666 eq_list env (e1:es1) (e2:es2) = eq env e1 e2 && eq_list env es1 es2
667 eq_list env es1 es2 = False
669 eq_alt env (c1,vs1,r1) (c2,vs2,r2) = c1==c2 &&
670 eq (extendVarEnvList env (vs1 `zip` vs2)) r1 r2
672 eq_note env (SCC cc1) (SCC cc2) = cc1 == cc2
673 eq_note env (Coerce t1 f1) (Coerce t2 f2) = t1==t2 && f1==f2
674 eq_note env InlineCall InlineCall = True
675 eq_note env other1 other2 = False
679 %************************************************************************
681 \subsection{The size of an expression}
683 %************************************************************************
686 coreBindsSize :: [CoreBind] -> Int
687 coreBindsSize bs = foldr ((+) . bindSize) 0 bs
689 exprSize :: CoreExpr -> Int
690 -- A measure of the size of the expressions
691 -- It also forces the expression pretty drastically as a side effect
692 exprSize (Var v) = varSize v
693 exprSize (Lit lit) = lit `seq` 1
694 exprSize (App f a) = exprSize f + exprSize a
695 exprSize (Lam b e) = varSize b + exprSize e
696 exprSize (Let b e) = bindSize b + exprSize e
697 exprSize (Case e b as) = exprSize e + varSize b + foldr ((+) . altSize) 0 as
698 exprSize (Note n e) = noteSize n + exprSize e
699 exprSize (Type t) = seqType t `seq` 1
701 noteSize (SCC cc) = cc `seq` 1
702 noteSize (Coerce t1 t2) = seqType t1 `seq` seqType t2 `seq` 1
703 noteSize InlineCall = 1
704 noteSize InlineMe = 1
705 noteSize (TermUsg usg) = usg `seq` 1
707 exprsSize = foldr ((+) . exprSize) 0
709 varSize :: Var -> Int
710 varSize b | isTyVar b = 1
711 | otherwise = seqType (idType b) `seq`
712 megaSeqIdInfo (idInfo b) `seq`
715 varsSize = foldr ((+) . varSize) 0
717 bindSize (NonRec b e) = varSize b + exprSize e
718 bindSize (Rec prs) = foldr ((+) . pairSize) 0 prs
720 pairSize (b,e) = varSize b + exprSize e
722 altSize (c,bs,e) = c `seq` varsSize bs + exprSize e
726 %************************************************************************
730 %************************************************************************
733 hashExpr :: CoreExpr -> Int
734 hashExpr e | hash < 0 = 77 -- Just in case we hit -maxInt
737 hash = abs (hash_expr e) -- Negative numbers kill UniqFM
739 hash_expr (Note _ e) = hash_expr e
740 hash_expr (Let (NonRec b r) e) = hashId b
741 hash_expr (Let (Rec ((b,r):_)) e) = hashId b
742 hash_expr (Case _ b _) = hashId b
743 hash_expr (App f e) = hash_expr f * fast_hash_expr e
744 hash_expr (Var v) = hashId v
745 hash_expr (Lit lit) = hashLiteral lit
746 hash_expr (Lam b _) = hashId b
747 hash_expr (Type t) = trace "hash_expr: type" 1 -- Shouldn't happen
749 fast_hash_expr (Var v) = hashId v
750 fast_hash_expr (Lit lit) = hashLiteral lit
751 fast_hash_expr (App f (Type _)) = fast_hash_expr f
752 fast_hash_expr (App f a) = fast_hash_expr a
753 fast_hash_expr (Lam b _) = hashId b
754 fast_hash_expr other = 1
757 hashId id = hashName (idName id)