Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC
Commits:
-
3a9fcb50
by Luite Stegeman at 2026-04-13T09:35:10-04:00
-
41db422e
by Phil de Joux at 2026-04-13T09:35:20-04:00
-
70a21718
by Luite Stegeman at 2026-04-13T09:35:24-04:00
7 changed files:
- + changelog.d/fix-duplicate-pmc-warnings
- + changelog.d/fix-ghci-duplicate-warnings-26233
- compiler/GHC/HsToCore/Pmc/Desugar.hs
- docs/users_guide/packages.rst
- + testsuite/tests/deSugar/should_compile/T25996.hs
- + testsuite/tests/deSugar/should_compile/T25996.stderr
- testsuite/tests/deSugar/should_compile/all.T
Changes:
| 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 |
| 1 | +section: ghci
|
|
| 2 | +synopsis: Fix duplicate warnings in GHCi when typechecking statements.
|
|
| 3 | +issues: #26233
|
|
| 4 | +mrs: !15860 |
| ... | ... | @@ -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)
|
| ... | ... | @@ -600,7 +600,7 @@ must be relative to the location of the package environment file. |
| 600 | 600 | :category:
|
| 601 | 601 | |
| 602 | 602 | Use the package environment in ⟨file⟩, or in
|
| 603 | - ``$XDG_DATA_HOME/ghc/arch-os-version/environments/⟨name⟩``
|
|
| 603 | + ``$XDG_DATA_HOME/.ghc/arch-os-version/environments/⟨name⟩``
|
|
| 604 | 604 | If set to ``-`` no package environment is read.
|
| 605 | 605 | |
| 606 | 606 | .. envvar:: GHC_ENVIRONMENT
|
| ... | ... | @@ -613,13 +613,13 @@ locations: |
| 613 | 613 | |
| 614 | 614 | - File ⟨file⟩ if you pass the option :ghc-flag:`-package-env ⟨file⟩|⟨name⟩`.
|
| 615 | 615 | |
| 616 | -- File ``$XDG_DATA_HOME/ghc/arch-os-version/environments/name`` if you pass the
|
|
| 616 | +- File ``$XDG_DATA_HOME/.ghc/arch-os-version/environments/name`` if you pass the
|
|
| 617 | 617 | option ``-package-env ⟨name⟩``.
|
| 618 | 618 | |
| 619 | 619 | - File ⟨file⟩ if the environment variable :envvar:`GHC_ENVIRONMENT` is set to
|
| 620 | 620 | ⟨file⟩.
|
| 621 | 621 | |
| 622 | -- File ``$XDG_DATA_HOME/ghc/arch-os-version/environments/name`` if the
|
|
| 622 | +- File ``$XDG_DATA_HOME/.ghc/arch-os-version/environments/name`` if the
|
|
| 623 | 623 | environment variable :envvar:`GHC_ENVIRONMENT` is set to ⟨name⟩.
|
| 624 | 624 | |
| 625 | 625 | Additionally, unless ``-hide-all-packages`` is specified ``ghc`` will also
|
| ... | ... | @@ -628,7 +628,7 @@ look for the package environment in the following locations: |
| 628 | 628 | - File ``.ghc.environment.arch-os-version`` if it exists in the current
|
| 629 | 629 | directory or any parent directory (but not the user's home directory).
|
| 630 | 630 | |
| 631 | -- File ``$XDG_DATA_HOME/ghc/arch-os-version/environments/default`` if it
|
|
| 631 | +- File ``$XDG_DATA_HOME/.ghc/arch-os-version/environments/default`` if it
|
|
| 632 | 632 | exists.
|
| 633 | 633 | |
| 634 | 634 | Package environments can be modified by further command line arguments;
|
| 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 () |
| 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 | + |
| ... | ... | @@ -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, ['']) |