From d21c80ead2ab829c1bb760943233dd9c0751ea13 Mon Sep 17 00:00:00 2001 From: "simonpj@microsoft.com" Date: Thu, 19 Nov 2009 11:57:36 +0000 Subject: [PATCH] Fix a nasty infelicity in the size computation of CoreUnfold The size computation was treating gigantic case expressions as practically free, which they really aren't. It was exacerbated by recent decisions to charge 0 for naked variables and constructors, so the RHS of the case might look free too. A good example was Foreign.C.Error.errnoToIOError, which hsa lots of join points that were getting inlined way to vigorously, so we had: *** Simplifier Phase 2 [main]: Result size = 2983 *** Core Linted result of Simplifier mode 2 [main], iteration 1 out of 4: Result size = 640327 *** Core Linted result of Simplifier mode 2 [main], iteration 2 out of 4: Result size = 1659 Notice that gigantic intermediate! This patch adds a small charge for each *alternative*. Of course, that'll also mean that there's a bit less inling of things involving case expressions. --- compiler/coreSyn/CoreUnfold.lhs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/coreSyn/CoreUnfold.lhs b/compiler/coreSyn/CoreUnfold.lhs index f83521c..654cfa7 100644 --- a/compiler/coreSyn/CoreUnfold.lhs +++ b/compiler/coreSyn/CoreUnfold.lhs @@ -319,9 +319,13 @@ sizeExpr bOMB_OUT_SIZE top_args expr _ -> funSize top_args fun (length val_args) ------------ - size_up_alt (_con, _bndrs, rhs) = size_up rhs + size_up_alt (_con, _bndrs, rhs) = size_up rhs `addSizeN` 1 -- Don't charge for args, so that wrappers look cheap -- (See comments about wrappers with Case) + -- + -- IMPORATANT: *do* charge 1 for the alternative, else we + -- find that giant case nests are treated as practically free + -- A good example is Foreign.C.Error.errrnoToIOError ------------ -- These addSize things have to be here because -- 1.7.10.4