Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC

Commits:

5 changed files:

Changes:

  • changelog.d/fix-duplicate-pmc-warnings
    1
    +section: compiler
    
    2
    +synopsis: Fix duplicate desugaring warnings emitted by the pattern match checker.
    
    3
    +  The pattern match checker now suppresses warnings that are already reported
    
    4
    +  by the main desugaring pass.
    
    5
    +issues: #25996
    
    6
    +mrs: !15859

  • compiler/GHC/HsToCore/Pmc/Desugar.hs
    ... ... @@ -375,16 +375,18 @@ desugarConPatOut x con univ_tys ex_tvs dicts = \case
    375 375
     
    
    376 376
     desugarPatBind :: SrcSpan -> Id -> Pat GhcTc -> DsM (PmPatBind Pre)
    
    377 377
     -- See 'GrdPatBind' for how this simply repurposes GrdGRHS.
    
    378
    -desugarPatBind loc var pat =
    
    378
    +-- See Note [Suppress warnings in PMC desugaring]
    
    379
    +desugarPatBind loc var pat = discardWarningsDs $
    
    379 380
       PmPatBind . flip PmGRHS (SrcInfo (L loc (ppr pat))) <$> desugarPat var pat
    
    380 381
     
    
    381 382
     desugarEmptyCase :: Id -> DsM PmEmptyCase
    
    382 383
     desugarEmptyCase var = pure PmEmptyCase { pe_var = var }
    
    383 384
     
    
    384 385
     -- | Desugar the non-empty 'Match'es of a 'MatchGroup'.
    
    386
    +-- See Note [Suppress warnings in PMC desugaring]
    
    385 387
     desugarMatches :: [Id] -> NonEmpty (LMatch GhcTc (LHsExpr GhcTc))
    
    386 388
                    -> DsM (PmMatchGroup Pre)
    
    387
    -desugarMatches vars matches =
    
    389
    +desugarMatches vars matches = discardWarningsDs $
    
    388 390
       PmMatchGroup <$> traverse (desugarMatch vars) matches
    
    389 391
     
    
    390 392
     -- Desugar a single match
    
    ... ... @@ -398,8 +400,9 @@ desugarMatch vars (L match_loc (Match { m_pats = L _ pats, m_grhss = grhss })) =
    398 400
       -- tracePm "desugarMatch" (vcat [ppr pats, ppr pats', ppr grhss'])
    
    399 401
       return PmMatch { pm_pats = pats', pm_grhss = grhss' }
    
    400 402
     
    
    403
    +-- See Note [Suppress warnings in PMC desugaring]
    
    401 404
     desugarGRHSs :: SrcSpan -> SDoc -> GRHSs GhcTc (LHsExpr GhcTc) -> DsM (PmGRHSs Pre)
    
    402
    -desugarGRHSs match_loc pp_pats grhss = do
    
    405
    +desugarGRHSs match_loc pp_pats grhss = discardWarningsDs $ do
    
    403 406
       lcls <- desugarLocalBinds (grhssLocalBinds grhss)
    
    404 407
       grhss' <- traverse (desugarLGRHS match_loc pp_pats) (grhssGRHSs grhss)
    
    405 408
       return PmGRHSs { pgs_lcls = lcls, pgs_grhss = grhss' }
    
    ... ... @@ -593,6 +596,17 @@ The place to store the 'PmLet' guards for @where@ clauses (which are per
    593 596
     'GRHSs') is as a field of 'PmGRHSs'. For plain @let@ guards as in the guards of
    
    594 597
     @x@, we can simply add them to the 'pg_grds' field of 'PmGRHS'.
    
    595 598
     
    
    599
    +Note [Suppress warnings in PMC desugaring]
    
    600
    +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    601
    +This module uses 'dsLExpr', 'dsExpr', and 'dsSyntaxExpr' to desugar
    
    602
    +expressions into Core for pattern match checking. The main desugaring
    
    603
    +pass in GHC.HsToCore processes these same expressions too, so without
    
    604
    +suppression any warnings would be emitted twice (#25996).
    
    605
    +
    
    606
    +To avoid this, the exported functions ('desugarPatBind', 'desugarMatches',
    
    607
    +'desugarGRHSs') are wrapped in 'discardWarningsDs', covering all internal
    
    608
    +desugarer calls without having to wrap each one individually.
    
    609
    +
    
    596 610
     Note [Desugaring -XStrict matches in Pmc]
    
    597 611
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    598 612
     Consider (#21761)
    

  • testsuite/tests/deSugar/should_compile/T25996.hs
    1
    +{-# OPTIONS_GHC -Wall #-}
    
    2
    +{-# OPTIONS_GHC -Wno-unused-local-binds #-}
    
    3
    +{-# OPTIONS_GHC -Wno-unused-top-binds #-}
    
    4
    +
    
    5
    +main :: IO ()
    
    6
    +main = do
    
    7
    +  pure ()
    
    8
    +  where
    
    9
    +    biz :: IO ()
    
    10
    +    biz = do
    
    11
    +      pure (10 :: Integer)
    
    12
    +      pure ()
    
    13
    +
    
    14
    +biz' :: IO ()
    
    15
    +biz' = do
    
    16
    +  pure (10 :: Integer)
    
    17
    +  pure ()

  • testsuite/tests/deSugar/should_compile/T25996.stderr
    1
    +T25996.hs:11:7: warning: [GHC-81995] [-Wunused-do-bind (in -Wall)]
    
    2
    +    A do-notation statement discarded a result of type ‘Integer’
    
    3
    +    Suggested fix:
    
    4
    +      Suppress this warning by saying ‘_ <- pure (10 :: Integer)’
    
    5
    +
    
    6
    +T25996.hs:16:3: warning: [GHC-81995] [-Wunused-do-bind (in -Wall)]
    
    7
    +    A do-notation statement discarded a result of type ‘Integer’
    
    8
    +    Suggested fix:
    
    9
    +      Suppress this warning by saying ‘_ <- pure (10 :: Integer)’
    
    10
    +

  • testsuite/tests/deSugar/should_compile/all.T
    ... ... @@ -115,3 +115,4 @@ test('T19883', normal, compile, [''])
    115 115
     test('T22719', normal, compile, ['-ddump-simpl -dsuppress-uniques -dno-typeable-binds'])
    
    116 116
     test('T23550', normal, compile, [''])
    
    117 117
     test('T24489', normal, compile, ['-O'])
    
    118
    +test('T25996', normal, compile, [''])