compiler: Do not look up fail in RnExpr if bind pattern is irrefutible.
authorAaron Friel <mayreply@aaronfriel.com>
Thu, 11 May 2017 19:41:22 +0000 (15:41 -0400)
committerBen Gamari <ben@smart-cactus.org>
Thu, 11 May 2017 21:33:11 +0000 (17:33 -0400)
Adds a check in `rnStmt`, in sub-expr `getFailFunction`, to determine if
the pattern of a bind statement is irrefutible. If so, skip looking up
the `fail` name.

Reviewers: austin, bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie

GHC Trac Issues: #13649

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

compiler/rename/RnExpr.hs

index 154e270..ce22784 100644 (file)
@@ -833,6 +833,10 @@ rnStmt ctxt rnBody (L loc (BindStmt pat body _ _ _)) thing_inside
 
         ; xMonadFailEnabled <- fmap (xopt LangExt.MonadFailDesugaring) getDynFlags
         ; let getFailFunction
+                -- If the pattern is irrefutible (e.g.: wildcard, tuple,
+                -- ~pat, etc.) we should not need to fail.
+                | isIrrefutableHsPat pat
+                                    = return (noSyntaxExpr, emptyFVs)
                 -- For non-monadic contexts (e.g. guard patterns, list
                 -- comprehensions, etc.) we should not need to fail.
                 -- See Note [Failing pattern matches in Stmts]