Opened 5 years ago

Last modified 21 months ago

#7335 new feature request

Need for extra warning pragma for accidental pattern matching in do blocks

Reported by: duncan Owned by:
Priority: normal Milestone:
Component: Compiler Version: 7.6.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Incorrect warning at compile-time Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

There are a few functions (actually monadic actions) where it's almost always an error to pattern match on the result, e.g.:

 (x,y) <- rpar $ ...    -- this is wrong!

 (x,y) <- unsafeInterleaveIO $ ...  -- this is also wrong!

We can help users by warning when they do this. To do this sensibly we would need a new warning pragma.

Here's a suggestion:

  {-# WARN_DO_PATTERNMATCH unsafeInterleaveIO
      "You don't want to use pattern matching directly on the
      result of unsafeInterleaveIO because that will immediately
      force the IO to be done, defeating the intention of lazily
      deferring it." #-}
  unsafeInterleaveIO :: IO a -> IO a
  unsafeInterleaveIO = ...

  {-# WARN_DO_PATTERNMATCH rpar "You don't want to use pattern
      matching directly on the result of rpar because that will
      immediately wait for the result to be evaluated, defeating
      the intention of doing it in parallel." #-}
  par :: Strategy a
  par = ...

The warning message should probably suggest using a ~ lazy irrefutable match. Perhaps that bit of the message should be generated rather than taken from the string in the pragma, since it can provide the actual pattern the user used, with the extra ~.

As far as I can tell, this is only needed in a 'do' context, not a pure 'case' context.

Change History (6)

comment:1 Changed 5 years ago by igloo

difficulty: Unknown
Milestone: 7.8.1

comment:2 Changed 3 years ago by thoughtpolice

Milestone: 7.8.37.10.1

Moving to 7.10.1

comment:3 Changed 3 years ago by thomie

Type of failure: None/UnknownIncorrect warning at compile-time

comment:4 Changed 3 years ago by thoughtpolice

Milestone: 7.10.17.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:5 Changed 2 years ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

comment:6 Changed 21 months ago by thomie

Milestone: 8.0.1
Note: See TracTickets for help on using tickets.