From 2c88170c73c3afcbad532385f25fa8482990293f Mon Sep 17 00:00:00 2001 From: simonmar Date: Fri, 12 Aug 2005 08:10:50 +0000 Subject: [PATCH] [project @ 2005-08-12 08:10:50 by simonmar] exprIsCheap: fix a bug whereby an over-applied ClassOp or RecordSel would be considered cheap. --- ghc/compiler/coreSyn/CoreUtils.lhs | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/ghc/compiler/coreSyn/CoreUtils.lhs b/ghc/compiler/coreSyn/CoreUtils.lhs index 53761d5..a8c7eae 100644 --- a/ghc/compiler/coreSyn/CoreUtils.lhs +++ b/ghc/compiler/coreSyn/CoreUtils.lhs @@ -450,17 +450,20 @@ idAppIsCheap id n_val_args | n_val_args == 0 = True -- Just a type application of -- a variable (f t1 t2 t3) -- counts as WHNF - | otherwise = case globalIdDetails id of - DataConWorkId _ -> True - RecordSelId _ _ -> True -- I'm experimenting with making record selection - ClassOpId _ -> True -- look cheap, so we will substitute it inside a - -- lambda. Particularly for dictionary field selection - - PrimOpId op -> primOpIsCheap op -- In principle we should worry about primops - -- that return a type variable, since the result - -- might be applied to something, but I'm not going - -- to bother to check the number of args - other -> n_val_args < idArity id + | otherwise + = case globalIdDetails id of + DataConWorkId _ -> True + RecordSelId _ _ -> n_val_args == 1 -- I'm experimenting with making record selection + ClassOpId _ -> n_val_args == 1 -- look cheap, so we will substitute it inside a + -- lambda. Particularly for dictionary field selection. + -- BUT: Take care with (sel d x)! The (sel d) might be cheap, but + -- there's no guarantee that (sel d x) will be too. Hence (n_val_args == 1) + + PrimOpId op -> primOpIsCheap op -- In principle we should worry about primops + -- that return a type variable, since the result + -- might be applied to something, but I'm not going + -- to bother to check the number of args + other -> n_val_args < idArity id \end{code} exprOkForSpeculation returns True of an expression that it is -- 1.7.10.4