
#13648: ApplicativeDo selects "GHC.Base.Monad.return" when actions are used without patterns. -------------------------------------+------------------------------------- Reporter: AaronFriel | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.2.1-rc1 Resolution: | Keywords: ApplicativeDo Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by AaronFriel): This turns out to be easier than I expected, which makes me expect it broke something else. The issue seems to be that the desugaring for `ApplicativeDo` had no casse for a `BodyStmt`. This was absent in three places: `stmtTreeToStmts`, `stmtTreeArg`, and `slurpIndependentStmts`. By adding a pattern match on `BodyStmt` and substituting the pattern where necessary with `nlWildPatName`, the desugaring now treats `BodyStmt` everywhere as a `BindStmt` with a wildcard pattern. This seems to work properly. Here is the renamer output before: {{{#!hs Main.testCase1 m1_a1O4 m2_a1O5 = do () <- do m1_a1O4 GHC.Base.return () | () <- do m2_a1O5 GHC.Base.return () return () }}} After adding the additional case to `stmtTreeToStmts`, I found the output was this: {{{#!hs Main.testCase1 m1_a259 m2_a25a = do () <- do _ <- m1_a259 () | () <- do _ <- m2_a25a () return () }}} While this ought to optimize just as well, it was clear the body statements were being grouped into separate applicative segments. To make sure this is handled correctly, I modified `stmtTreeArg` and `slurpIndependentStmts` as well. Now the renamer outputs the same AST for both wildcard pattern binds and body statements: {{{#!hs Main.testCase1 m1_a1N9 m2_a1Na = do _ <- m1_a1N9 | _ <- m2_a1Na return () Main.testCase2 m1_a1Nf m2_a1Ng = do _ <- m1_a1Nf | _ <- m2_a1Ng return () }}} I think if I did this correctly, the patch is pushed to phabricator here: https://phabricator.haskell.org/D3552 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/13648#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler