Fix Trac #2581: inlining of record selectors
authorsimonpj@microsoft.com <unknown>
Wed, 10 Sep 2008 08:30:14 +0000 (08:30 +0000)
committersimonpj@microsoft.com <unknown>
Wed, 10 Sep 2008 08:30:14 +0000 (08:30 +0000)
commit112ad1978f8c03d26a7df9ac892915dc93724b66
treea1e19e00b569137168a11f3912bc6aeed341636c
parent911a3e09ad48ff8dac5ee1399fe9294edf58d30c
Fix Trac #2581: inlining of record selectors

Bryan discovered that a non-trivial record selector (non-trivial in
the sense that it has to reconstruct the result value because of
UNPACK directives) weren't being inlined.  The reason was that the
unfolding generated by MkId.mRecordSelId was never being optimised
*at all*, and hence looked big, and hence wasn't inlined.

(The out-of-line version *is* put into the code of the module
and *is* optimised, which made this bug pretty puzzling.  But the
unfolding inside the record-selector-Id itself, which is a GlobalId
and hence does not get its inlining updated like LocalIds, was
big and fat.)

Solution: I wrote a very simple optimiser, CoreUnfold.simplOptExpr,
which does enough optimisation to solve this particular problem.
It's short, simple, and will be useful in other contexts.
compiler/basicTypes/MkId.lhs
compiler/coreSyn/CoreUnfold.lhs