• rwbarton's avatar
    Re-sort case alternatives after scrutinee constant folding (#13170) · abaa6815
    rwbarton authored
    Commit d3b546b1 added a "scrutinee constant folding" pass
    that rewrites a case expression whose scrutinee is an expression like
    x +# 3#. But case expressions are supposed to have their alternatives in
    sorted order, so when the scrutinee is (for example) negateInt# x#, we
    need to re-sort the alternatives after mapping their values.
    This showed up as a core lint failure when compiling System.Process.Posix:
        isSigIntQuit n = sig == sigINT || sig == sigQUIT
            where sig = fromIntegral (-n)
    Data.List.sortBy is supposed to be linear-time on sorted or reverse-sorted
    input, so it is probably not worth doing anything more clever than this.
    Test Plan: Added a new test T13170 for the above case.
    Reviewers: austin, hsyl20, simonpj, bgamari
    Reviewed By: hsyl20, simonpj, bgamari
    Subscribers: thomie
    Differential Revision: https://phabricator.haskell.org/D3008
    GHC Trac Issues: #13170
T13170.hs 75 Bytes