Turn on MonadFail desugaring by default
Concern Raisedaab8656ba056

Authored by hvr on Aug 6 2018, 11:53 AM.

Description

Turn on MonadFail desugaring by default

Summary:
This contains two commits:


Make GHC's code-base compatible w/ MonadFail

There were a couple of use-sites which implicitly used pattern-matches
in do-notation even though the underlying Monad didn't explicitly
support fail

This refactoring turns those use-sites into explicit case
discrimations and adds an MonadFail instance for UniqSM
(UniqSM was the worst offender so this has been postponed for a
follow-up refactoring)


Turn on MonadFail desugaring by default

This finally implements the phase scheduled for GHC 8.6 according to

https://prime.haskell.org/wiki/Libraries/Proposals/MonadFail#Transitionalstrategy

This also preserves some tests that assumed MonadFail desugaring to be
active; all ghc boot libs were already made compatible with this
MonadFail long ago, so no changes were needed there.

Test Plan: Locally performed ./validate --fast

Reviewers: bgamari, simonmar, jrtc27, RyanGlScott

Reviewed By: bgamari

Subscribers: bgamari, RyanGlScott, rwbarton, thomie, carter

Differential Revision: https://phabricator.haskell.org/D5028

nomeata raised a concern with this commit.Aug 11 2018, 12:56 PM
nomeata added a subscriber: nomeata.

This broke nofib:

==nofib== lambda: time to compile Main follows...
/home/nomeata/logs/ghc-tmp-REV/inplace/bin/ghc-stage2 -O2 -Rghc-timing -H32m -hisuf hi -package transformers -rtsopts -c Main.hs -o Main.o

Main.hs:128:9: error:
    • Could not deduce (Control.Monad.Fail.MonadFail m)
        arising from a do statement
        with the failable pattern ‘Con v'’
      from the context: EvalEnvMonad m
        bound by the type signature for:
                   eval :: forall (m :: * -> *). EvalEnvMonad m => Term -> m Term
        at Main.hs:121:1-42
      Possible fix:
        add (Control.Monad.Fail.MonadFail m) to the context of
          the type signature for:
            eval :: forall (m :: * -> *). EvalEnvMonad m => Term -> m Term
    • In a stmt of a 'do' block: Con v' <- traverseTerm v
      In the expression:
        do Con u' <- traverseTerm u
           Con v' <- traverseTerm v
           return (Con (u' + v'))
      In an equation for ‘eval’:
          eval (Add u v)
            = do Con u' <- traverseTerm u
                 Con v' <- traverseTerm v
                 return (Con (u' + v'))
    |
128 |         Con v' <- traverseTerm v;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^

Main.hs:177:9: error:
    • No instance for (Control.Monad.Fail.MonadFail Id)
        arising from a do statement
        with the failable pattern ‘Con v'’
    • In a stmt of a 'do' block: Con v' <- simpleEval env v
      In the expression:
        do Con u' <- simpleEval env u
           Con v' <- simpleEval env v
           return (Con (u' + v'))
      In an equation for ‘simpleEval’:
          simpleEval env (Add u v)
            = do Con u' <- simpleEval env u
                 Con v' <- simpleEval env v
                 return (Con (u' + v'))
            where
                addCons (Con a) (Con b) = return (Con (a + b))
                addCons (Con _) b
                  = fail ("type error in second arg of Add: " ++ pp b)
                addCons a (Con _)
                  = fail ("type error in first arg of Add: " ++ pp a)
    |
177 |         Con v' <- simpleEval env v;
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^
<<ghc: 123480288 bytes, 37 GCs, 8658200/18548160 avg/max bytes residency (5 samples), 39M in use, 0.001 INIT (0.001 elapsed), 0.100 MUT (0.099 elapsed), 0.139 GC (0.140 elapsed) :ghc>>
make[2]: *** [../../mk/suffix.mk:23: Main.o] Error 1

Can you please update nofib, to unbreak perf.haskell.org?

This commit now has outstanding concerns.Aug 11 2018, 12:56 PM