• simonpj@microsoft.com's avatar
    Fix Trac #2581: inlining of record selectors · 112ad197
    simonpj@microsoft.com authored
    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.
CoreUnfold.lhs 30 KB