[Git][ghc/ghc][wip/27323] Don't report -XStrict-generated bangs under -Wredundant-bang-patterns
by sheaf (@sheaf) 26 Oct '26
by sheaf (@sheaf) 26 Oct '26
26 Oct '26
sheaf pushed to branch wip/27323 at Glasgow Haskell Compiler / GHC
Commits:
b991d4a5 by Sasha Bogicevic at 2026-10-26T17:07:13+01:00
Don't report -XStrict-generated bangs under -Wredundant-bang-patterns
The -XStrict flag causes the desugarer to insert bang patterns.
These are not user-written, so -Wredundant-bang-patterns must not
report them.
To achieve this, the desugarer now tracks whether it is desugaring
compiler-generated code (similar to the typechecker's 'tcl_in_gen_code').
Bangs inserted by -XStrict are given generated spans, which suppresses
the "redundant bang" warnings without otherwise affecting pattern-match
warnings.
Fixes #27323
- - - - -
15 changed files:
- + changelog.d/T27323
- compiler/GHC/HsToCore/Match.hs
- compiler/GHC/HsToCore/Match/Literal.hs
- compiler/GHC/HsToCore/Monad.hs
- compiler/GHC/HsToCore/Pmc.hs
- compiler/GHC/HsToCore/Pmc/Desugar.hs
- compiler/GHC/HsToCore/Types.hs
- compiler/GHC/HsToCore/Utils.hs
- + testsuite/tests/pmcheck/should_compile/T27323.hs
- + testsuite/tests/pmcheck/should_compile/T27323b.hs
- testsuite/tests/pmcheck/should_compile/all.T
- testsuite/tests/warnings/should_compile/Overflow.stderr-ws-32
- testsuite/tests/warnings/should_compile/Overflow.stderr-ws-64
- testsuite/tests/warnings/should_compile/T13256.stderr-ws-32
- testsuite/tests/warnings/should_compile/T13256.stderr-ws-64
Changes:
=====================================
changelog.d/T27323
=====================================
@@ -0,0 +1,7 @@
+section: compiler
+synopsis: Don't report ``-XStrict``-generated bang patterns under ``-Wredundant-bang-patterns``
+description:
+ Bangs introduced by ``-XStrict`` are no longer reported as redundant under
+ ``-Wredundant-bang-patterns``, as they are not user-written.
+issues: #27323
+mrs: !16395
=====================================
compiler/GHC/HsToCore/Match.hs
=====================================
@@ -383,12 +383,14 @@ tidyEqnInfo :: MatchId -> EquationInfo
tidyEqnInfo _ eqn@(EqnDone {}) = return (idDsWrapper, eqn)
-tidyEqnInfo v eqn@(EqnMatch { eqn_pat = (L loc pat) }) = do
- (wrap, pat') <- tidy1 v (not . isGoodSrcSpan . locA $ loc) pat
+tidyEqnInfo v eqn@(EqnMatch { eqn_pat = p@(L loc _) }) = do
+ (wrap, pat') <- tidyLPat v p
return (wrap, eqn{eqn_pat = L loc pat' })
+tidyLPat :: MatchId -> LPat GhcTc -> DsM (DsWrapper, Pat GhcTc)
+tidyLPat v (L loc pat) = putSrcSpanDsA loc (tidy1 v pat)
+
tidy1 :: MatchId -- The scrutinee
- -> Bool -- `True` if the pattern was generated, `False` if it was user-written
-> Pat GhcTc -- The pattern against which it is to be matched
-> DsM (DsWrapper, -- Extra bindings to do before the match
Pat GhcTc) -- Equivalent pattern
@@ -399,21 +401,22 @@ tidy1 :: MatchId -- The scrutinee
-- It eliminates many pattern forms (as-patterns, variable patterns,
-- list patterns, etc) and returns any created bindings in the wrapper.
-tidy1 v g (ParPat _ pat) = tidy1 v g (unLoc pat)
-tidy1 v g (SigPat _ pat _) = tidy1 v g (unLoc pat)
-tidy1 _ _ (WildPat ty) = return (idDsWrapper, WildPat ty)
-tidy1 v g (BangPat _ (L l p)) = tidy_bang_pat v g l p
-tidy1 v g (ModifiedPat _ _ pat) = tidy1 v g (unLoc pat)
+tidy1 v (ParPat _ pat) = tidyLPat v pat
+tidy1 v (SigPat _ pat _) = tidyLPat v pat
+tidy1 _ (WildPat ty) = return (idDsWrapper, WildPat ty)
+tidy1 v (BangPat _ (L l p)) = putSrcSpanDsA l $ tidy_bang_pat v l p
+tidy1 v (ModifiedPat _ _ pat) = tidyLPat v pat
-- case v of { x -> mr[] }
-- = case v of { _ -> let x=v in mr[] }
-tidy1 v _ (VarPat _ (L _ var))
+tidy1 v (VarPat _ (L _ var))
= return (bindMatchId var v, WildPat (idType var))
-- case v of { x@p -> mr[] }
-- = case v of { p -> let x=v in mr[] }
-tidy1 v g (AsPat _ (L _ var) pat)
- = do { (wrap, pat') <- tidy1 v g (unLoc pat)
+tidy1 v (AsPat _ (L _ var) pat)
+
+ = do { (wrap, pat') <- tidyLPat v pat
; return (bindMatchId var v . wrap, pat') }
{- now, here we handle lazy patterns:
@@ -427,7 +430,7 @@ tidy1 v g (AsPat _ (L _ var) pat)
The case expr for v_i is just: match [v] [(p, [], \ x -> Var v_i)] any_expr
-}
-tidy1 v _ (LazyPat _ pat)
+tidy1 v (LazyPat _ pat)
-- This is a convenient place to check for unlifted types under a lazy pattern.
-- Doing this check during type-checking is unsatisfactory because we may
-- not fully know the zonked types yet. We sure do here.
@@ -441,14 +444,14 @@ tidy1 v _ (LazyPat _ pat)
; let sel_binds = [NonRec b rhs | (b,rhs) <- sel_prs]
; return (mkCoreLets sel_binds, WildPat (matchIdType v)) }
-tidy1 _ _ (ListPat ty pats)
+tidy1 _ (ListPat ty pats)
= return (idDsWrapper, unLoc list_ConPat)
where
list_ConPat = foldr (\ x y -> mkPrefixConPat consDataCon [x, y] [ty])
(mkNilPat ty)
pats
-tidy1 _ _ (TuplePat tys pats boxity)
+tidy1 _ (TuplePat tys pats boxity)
= return (idDsWrapper, unLoc tuple_ConPat)
where
arity = length pats
@@ -458,34 +461,37 @@ tidy1 _ _ (TuplePat tys pats boxity)
Boxed -> tys
-- See Note [Unboxed tuple RuntimeRep vars] in TyCon
-tidy1 _ _ (SumPat tys pat alt arity)
+tidy1 _ (SumPat tys pat alt arity)
= return (idDsWrapper, unLoc sum_ConPat)
where
sum_ConPat = mkPrefixConPat (sumDataCon alt arity) [pat] (map getRuntimeRep tys ++ tys)
-- See Note [Unboxed tuple RuntimeRep vars] in TyCon
-- LitPats: we *might* be able to replace these w/ a simpler form
-tidy1 _ g (LitPat _ lit)
- = do { unless g $
+tidy1 _ (LitPat _ lit)
+ = do { in_gen <- inGeneratedCodeDs;
+ unless in_gen $
warnAboutOverflowedLit lit
; return (idDsWrapper, tidyLitPat lit) }
-- NPats: we *might* be able to replace these w/ a simpler form
-tidy1 _ g (NPat ty (L _ lit@OverLit { ol_val = v }) mb_neg eq)
- = do { unless g $
+tidy1 _ (NPat ty (L _ lit@OverLit { ol_val = v }) mb_neg eq)
+ = do { in_gen <- inGeneratedCodeDs;
+ unless in_gen $
let lit' | Just _ <- mb_neg = lit{ ol_val = negateOverLitVal v }
| otherwise = lit
in warnAboutOverflowedOverLit lit'
; return (idDsWrapper, tidyNPat lit mb_neg eq ty) }
-- NPlusKPat: we may want to warn about the literals
-tidy1 _ g n@(NPlusKPat _ _ (L _ lit1) lit2 _ _)
- = do { unless g $ do
+tidy1 _ n@(NPlusKPat _ _ (L _ lit1) lit2 _ _)
+ = do { in_gen <- inGeneratedCodeDs;
+ unless in_gen $ do
warnAboutOverflowedOverLit lit1
warnAboutOverflowedOverLit lit2
; return (idDsWrapper, n) }
-tidy1 _ _ (OrPat ty lpats)
+tidy1 _ (OrPat ty lpats)
-- See Note [Implementation of OrPatterns]. We desugar
-- (1; 2; 3)
-- to
@@ -514,44 +520,44 @@ tidy1 _ _ (OrPat ty lpats)
single_grhs e = GRHSs emptyComments [noLocA $ GRHS noAnn [] e] (EmptyLocalBinds noExtField)
-- Everything else goes through unchanged...
-tidy1 _ _ non_interesting_pat
+tidy1 _ non_interesting_pat
= return (idDsWrapper, non_interesting_pat)
--------------------
-tidy_bang_pat :: MatchId -> Bool -> SrcSpanAnnA -> Pat GhcTc
+tidy_bang_pat :: MatchId -> SrcSpanAnnA -> Pat GhcTc
-> DsM (DsWrapper, Pat GhcTc)
-- Discard par/sig under a bang
-tidy_bang_pat v g _ (ParPat _ (L l p)) = tidy_bang_pat v g l p
-tidy_bang_pat v g _ (SigPat _ (L l p) _) = tidy_bang_pat v g l p
+tidy_bang_pat v _ (ParPat _ (L l p)) = putSrcSpanDsA l $ tidy_bang_pat v l p
+tidy_bang_pat v _ (SigPat _ (L l p) _) = putSrcSpanDsA l $ tidy_bang_pat v l p
-- Push the bang-pattern inwards, in the hope that
-- it may disappear next time
-tidy_bang_pat v g l (AsPat x v' p)
- = tidy1 v g (AsPat x v' (L l (BangPat noExtField p)))
-tidy_bang_pat v g l (XPat (CoPat w p t))
- = tidy1 v g (XPat $ CoPat w (BangPat noExtField (L l p)) t)
-tidy_bang_pat v g l (OrPat x (p:|ps)) -- push bang into first pat alt
- = tidy1 v g (OrPat x (L l (BangPat noExtField p) :| ps))
+tidy_bang_pat v l (AsPat x v' p)
+ = tidy1 v (AsPat x v' (L l (BangPat noExtField p)))
+tidy_bang_pat v l (XPat (CoPat w p t))
+ = tidy1 v (XPat $ CoPat w (BangPat noExtField (L l p)) t)
+tidy_bang_pat v l (OrPat x (p:|ps)) -- push bang into first pat alt
+ = tidy1 v (OrPat x (L l (BangPat noExtField p) :| ps))
-- Discard bang around strict pattern
-tidy_bang_pat v g _ p@(LitPat {}) = tidy1 v g p
-tidy_bang_pat v g _ p@(ListPat {}) = tidy1 v g p
-tidy_bang_pat v g _ p@(TuplePat {}) = tidy1 v g p
-tidy_bang_pat v g _ p@(SumPat {}) = tidy1 v g p
+tidy_bang_pat v _ p@(LitPat {}) = tidy1 v p
+tidy_bang_pat v _ p@(ListPat {}) = tidy1 v p
+tidy_bang_pat v _ p@(TuplePat {}) = tidy1 v p
+tidy_bang_pat v _ p@(SumPat {}) = tidy1 v p
-- Data/newtype constructors
-tidy_bang_pat v g l p@(ConPat { pat_con = L _ (RealDataCon dc)
- , pat_args = args
- , pat_con_ext = ConPatTc
- { cpt_arg_tys = arg_tys
- }
- })
+tidy_bang_pat v l p@(ConPat { pat_con = L _ (RealDataCon dc)
+ , pat_args = args
+ , pat_con_ext = ConPatTc
+ { cpt_arg_tys = arg_tys
+ }
+ })
-- Newtypes: push bang inwards (#9844)
=
if isNewTyCon (dataConTyCon dc)
- then tidy1 v g (p { pat_args = push_bang_into_newtype_arg l (scaledThing ty) args })
- else tidy1 v g p -- Data types: discard the bang
+ then tidy1 v (p { pat_args = push_bang_into_newtype_arg l (scaledThing ty) args })
+ else tidy1 v p -- Data types: discard the bang
where
(ty:_) = dataConInstArgTys dc arg_tys
@@ -570,7 +576,7 @@ tidy_bang_pat v g l p@(ConPat { pat_con = L _ (RealDataCon dc)
--
-- NB: SigPatIn, ConPatIn should not happen
-tidy_bang_pat _ _ l p = return (idDsWrapper, BangPat noExtField (L l p))
+tidy_bang_pat _ l p = return (idDsWrapper, BangPat noExtField (L l p))
-------------------
push_bang_into_newtype_arg :: SrcSpanAnnA
@@ -954,7 +960,7 @@ matchSinglePatVar var mb_scrut ctx pat ty match_result
; ldi_nablas <-
if isMatchContextPmChecked_SinglePat dflags FromSource ctx pat
then addCoreScrutTmCs (maybeToList mb_scrut) [var] $
- pmcPatBind (DsMatchContext ctx locn) var (unLoc pat)
+ pmcPatBind (DsMatchContext ctx locn) var pat
else getLdiNablas
; let eqn_info = EqnMatch { eqn_pat = decideBangHood dflags pat
=====================================
compiler/GHC/HsToCore/Match/Literal.hs
=====================================
@@ -33,6 +33,7 @@ import GHC.HsToCore.Utils
import GHC.Hs
+import GHC.Rename.Utils (wrapGenSpan)
import GHC.Tc.Utils.TcMType ( shortCutLit )
import GHC.Tc.Utils.TcType
@@ -580,7 +581,8 @@ tidyNPat (OverLit (OverLitTc False _ ty) val) mb_neg _eq outer_ty
mk_con_pat :: DataCon -> HsLit GhcTc -> Pat GhcTc
mk_con_pat con lit
- = unLoc (mkPrefixConPat con [noLocA $ LitPat noExtField lit] [])
+ -- Mark the generated literal to avoid duplicate -Woverflowed-literals.
+ = unLoc (mkPrefixConPat con [wrapGenSpan $ LitPat noExtField lit] [])
mb_int_lit :: Maybe Integer
mb_int_lit = case (mb_neg, val) of
=====================================
compiler/GHC/HsToCore/Monad.hs
=====================================
@@ -15,7 +15,7 @@ module GHC.HsToCore.Monad (
duplicateLocalDs, newSysLocalDs, newSysLocalsDs,
newSysLocalMDs, newSysLocalsMDs, newFailLocalMDs,
newUniqueId, newPredVarDs, newStaticId,
- getSrcSpanDs, putSrcSpanDs, putSrcSpanDsA,
+ getSrcSpanDs, inGeneratedCodeDs, putSrcSpanDs, putSrcSpanDsA,
mkNamePprCtxDs,
newUnique,
UniqSupply, newUniqueSupply,
@@ -584,6 +584,7 @@ mkDsEnvs unit_env mod rdr_env type_env fam_inst_env tcm_plugins ptc msg_var
, dsl_loc = real_span
, dsl_nablas = Ldi initNablas
, dsl_unspecables = Just emptyVarSet
+ , dsl_in_generated_code = False
}
in (gbl_env, lcl_env)
@@ -676,13 +677,17 @@ getSrcSpanDs :: DsM SrcSpan
getSrcSpanDs = do { env <- getLclEnv
; return (RealSrcSpan (dsl_loc env) Strict.Nothing) }
+-- | See 'dsl_in_generated_code'
+inGeneratedCodeDs :: DsM Bool
+inGeneratedCodeDs = dsl_in_generated_code <$> getLclEnv
+
putSrcSpanDs :: SrcSpan -> DsM a -> DsM a
putSrcSpanDs (RealSrcSpan real_span _) thing_inside
- = updLclEnv (\ env -> env {dsl_loc = real_span}) thing_inside
+ = updLclEnv (\ env -> env {dsl_loc = real_span, dsl_in_generated_code = False}) thing_inside
putSrcSpanDs UnhelpfulSpan{} thing_inside
= thing_inside
putSrcSpanDs GeneratedSrcSpan{} thing_inside
- = thing_inside
+ = updLclEnv (\ env -> env {dsl_in_generated_code = True}) thing_inside
putSrcSpanDsA :: EpAnn ann -> DsM a -> DsM a
putSrcSpanDsA loc = putSrcSpanDs (locA loc)
=====================================
compiler/GHC/HsToCore/Pmc.hs
=====================================
@@ -104,7 +104,7 @@ whenDoingPmc no_pmc thing_inside
Ldi nablas -> thing_inside nablas }
-- | Check a pattern binding (let, where) for exhaustiveness.
-pmcPatBind :: DsMatchContext -> Id -> Pat GhcTc -> DsM LdiNablas
+pmcPatBind :: DsMatchContext -> Id -> LPat GhcTc -> DsM LdiNablas
pmcPatBind ctxt@(DsMatchContext match_ctxt loc) var p
= whenDoingPmc NoPmc $ \ !missing ->
mb_discard_warnings $ do
=====================================
compiler/GHC/HsToCore/Pmc/Desugar.hs
=====================================
@@ -155,11 +155,15 @@ desugarPat x pat = case pat of
VarPat _ y -> pure (mkPmLetVar (unLoc y) x)
ParPat _ p -> desugarLPat x p
LazyPat _ _ -> pure GdEnd -- like a wildcard
- BangPat _ p@(L l p') ->
+ BangPat _ p@(L l p') -> do
-- Add the bang in front of the list, because it will happen before any
-- nested stuff.
+ in_gen <- inGeneratedCodeDs
+ -- A bang inserted by -XStrict (decideBangHood) has no SrcInfo: it is
+ -- divergence-checked but never reported as redundant (#27323).
+ let pm_loc | in_gen = Nothing
+ | otherwise = Just (SrcInfo (L (locA l) (ppr p')))
consGrdDag (PmBang x pm_loc) <$> desugarLPat x p
- where pm_loc = Just (SrcInfo (L (locA l) (ppr p')))
-- (x@pat) ==> Desugar pat with x as match var and handle impedance
-- mismatch with incoming match var
@@ -311,11 +315,11 @@ desugarPatV pat = do
pure (x, grds)
desugarLPat :: Id -> LPat GhcTc -> DsM GrdDag
-desugarLPat x = desugarPat x . unLoc
+desugarLPat x (L loc pat) = putSrcSpanDsA loc (desugarPat x pat)
-- | 'desugarLPat', but also select and return a new match var.
desugarLPatV :: LPat GhcTc -> DsM (Id, GrdDag)
-desugarLPatV = desugarPatV . unLoc
+desugarLPatV (L loc pat) = putSrcSpanDsA loc (desugarPatV pat)
-- | @desugarListPat _ x [p1, ..., pn]@ is basically
-- @desugarConPatOut _ x $(mkListConPatOuts [p1, ..., pn]>@ without ever
@@ -374,11 +378,11 @@ desugarConPatOut x con univ_tys ex_tvs dicts = \case
-- tracePm "ConPatOut" (ppr x $$ ppr con $$ ppr arg_ids)
pure (con_grd `consGrdDag` arg_grds)
-desugarPatBind :: SrcSpan -> Id -> Pat GhcTc -> DsM (PmPatBind Pre)
+desugarPatBind :: SrcSpan -> Id -> LPat GhcTc -> DsM (PmPatBind Pre)
-- See 'GrdPatBind' for how this simply repurposes GrdGRHS.
-- See Note [Suppress warnings in PMC desugaring]
desugarPatBind loc var pat = discardWarningsDs $
- PmPatBind . flip PmGRHS (SrcInfo (L loc (ppr pat))) <$> desugarPat var pat
+ PmPatBind . flip PmGRHS (SrcInfo (L loc (ppr pat))) <$> desugarLPat var pat
desugarEmptyCase :: Id -> DsM PmEmptyCase
desugarEmptyCase var = pure PmEmptyCase { pe_var = var }
@@ -633,21 +637,16 @@ Consider (#21761)
idV :: Void -> Void
idV v = v
-Without -XStrict, we would not warn here. But with -XStrict, there is an
-implicit bang on `v` and we should give an inaccessible warning for the RHS.
-The way we account for that is by calling `decideBangHood` on patterns
-in a `Match`, which inserts the implicit bang.
+With -XStrict, there is an implicit bang pattern on `v` as per
+Note [decideBangHood], so the RHS is inaccessible and we must report it as such.
-Making the call here actually seems redundant with the call to `decideBangHood`
-in `GHC.HsToCore.Match.matchWrapper`, which does it *after* it calls the
-pattern-match checker on the Match's patterns. It would be great if we could expect
-`matchWrapper` to pass the bang-adorned `Match` to the pattern-match checker,
-but sadly then we get worse warning messages which would print `idV` as if the
-user *had* written a bang:
+The natural way to achieve this is described in #27677: insert the bang using
+'ExpansionPat' (see Note [Handling overloaded and rebindable constructs] in
+GHC.Rename.Expr). Then the pattern-match checker sees the bang pattern, while
+warning messages display the user-written pattern.
- Pattern match has inaccessible right hand side
-- In an equation for ‘idV’: idV v = ...
-+ In an equation for ‘idV’: idV !v = ...
-
-So we live with the duplication.
+This approach hasn't been implemented yet, so for the time being 'desugarMatches'
+calls 'decideBangHood' itself, duplicating the call in 'GHC.HsToCore.Match.matchWrapper'.
+'decideBangHood' gives the bangs it inserts a generated span, so that they are
+never reported as redundant (see Note [Dead bang patterns] in GHC.HsToCore.Pmc.Check).
-}
=====================================
compiler/GHC/HsToCore/Types.hs
=====================================
@@ -11,7 +11,7 @@ module GHC.HsToCore.Types (
DsMetaEnv, DsMetaVal(..), CompleteMatches
) where
-import GHC.Prelude (Int)
+import GHC.Prelude (Bool, Int)
import Data.IORef
@@ -125,6 +125,7 @@ data DsLclEnv
-- ^ See Note [Desugaring non-canonical evidence]
-- This field collects all un-specialisable evidence variables in scope.
-- Nothing <=> don't collect this info (used for the LHS of Rules)
+ , dsl_in_generated_code :: Bool -- ^ Are we desugaring compiler-generated code?
}
-- Inside [| |] brackets, the desugarer looks
=====================================
compiler/GHC/HsToCore/Utils.hs
=====================================
@@ -72,6 +72,7 @@ import GHC.Unit.Module
import GHC.Builtin.KnownKeys
import GHC.Utils.Outputable
import GHC.Utils.Panic
+import GHC.Rename.Utils (wrapGenSpan')
import GHC.Types.SrcLoc
import GHC.Types.Tickish
import GHC.Utils.Misc
@@ -1024,8 +1025,9 @@ Specifically:
-}
--- | Use -XStrict to add a ! or remove a ~
--- See Note [decideBangHood]
+-- | Use -XStrict to add a ! or remove a ~, as per Note [decideBangHood].
+--
+-- The inserted bang is compiler-generated: see Note [Desugaring -XStrict matches in Pmc].
decideBangHood :: DynFlags
-> LPat GhcTc -- ^ Original pattern
-> LPat GhcTc -- Pattern with bang if necessary
@@ -1040,7 +1042,7 @@ decideBangHood dflags lpat
ParPat x p -> L l (ParPat x (go p))
LazyPat _ lp' -> lp'
BangPat _ _ -> lp
- _ -> L l (BangPat noExtField lp)
+ _ -> wrapGenSpan' (locA l) (BangPat noExtField lp)
isTrueLHsExpr :: LHsExpr GhcTc -> Maybe (CoreExpr -> DsM CoreExpr)
=====================================
testsuite/tests/pmcheck/should_compile/T27323.hs
=====================================
@@ -0,0 +1,9 @@
+{-# LANGUAGE MagicHash, Strict #-}
+{-# OPTIONS_GHC -Wredundant-bang-patterns #-}
+
+import GHC.Prim (Int#)
+
+idInt# :: Int# -> Int#
+idInt# x = x
+
+main = pure ()
=====================================
testsuite/tests/pmcheck/should_compile/T27323b.hs
=====================================
@@ -0,0 +1,6 @@
+{-# LANGUAGE Strict, MonoLocalBinds #-}
+{-# OPTIONS_GHC -Wredundant-bang-patterns #-}
+module T27323b where
+
+f :: Int -> Int
+f x = let (a, b) = (x, x) in a + b
=====================================
testsuite/tests/pmcheck/should_compile/all.T
=====================================
@@ -190,4 +190,6 @@ test('T24845', [], compile, [overlapping_incomplete])
test('T22652', [], compile, [overlapping_incomplete])
test('T22652a', [], compile, [overlapping_incomplete])
test('T24867', [], compile_fail, [overlapping_incomplete])
+test('T27323', normal, compile, ['-Wredundant-bang-patterns'])
+test('T27323b', normal, compile, ['-Wredundant-bang-patterns'])
test('T27360', normal, compile, [overlapping_incomplete + '-g3'])
=====================================
testsuite/tests/warnings/should_compile/Overflow.stderr-ws-32
=====================================
@@ -1,18 +1,18 @@
-
Overflow.hs:8:15: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal 10000000000000000000000000000000 is out of the Int# range -2147483648..2147483647
-Overflow.hs:13:1: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
+Overflow.hs:13:3: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal 100000000000000000000000000 is out of the Int# range -2147483648..2147483647
Overflow.hs:18:5: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal 1000000000000000000000000000000 is out of the Int range -2147483648..2147483647
-Overflow.hs:22:1: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
+Overflow.hs:22:3: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal 100000000000000000000000000000000 is out of the Int range -2147483648..2147483647
Overflow.hs:27:6: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal -1 is out of the Word range 0..4294967295
-Overflow.hs:31:1: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
+Overflow.hs:31:4: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal -1 is out of the Word range 0..4294967295
+
=====================================
testsuite/tests/warnings/should_compile/Overflow.stderr-ws-64
=====================================
@@ -1,18 +1,18 @@
-
Overflow.hs:8:15: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal 10000000000000000000000000000000 is out of the Int# range -9223372036854775808..9223372036854775807
-Overflow.hs:13:1: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
+Overflow.hs:13:3: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal 100000000000000000000000000 is out of the Int# range -9223372036854775808..9223372036854775807
Overflow.hs:18:5: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal 1000000000000000000000000000000 is out of the Int range -9223372036854775808..9223372036854775807
-Overflow.hs:22:1: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
+Overflow.hs:22:3: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal 100000000000000000000000000000000 is out of the Int range -9223372036854775808..9223372036854775807
Overflow.hs:27:6: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal -1 is out of the Word range 0..18446744073709551615
-Overflow.hs:31:1: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
+Overflow.hs:31:4: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal -1 is out of the Word range 0..18446744073709551615
+
=====================================
testsuite/tests/warnings/should_compile/T13256.stderr-ws-32
=====================================
@@ -1,3 +1,3 @@
-
-T13256.hs:4:12: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
+T13256.hs:4:31: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal 100000000000000000000000000000000 is out of the Int range -2147483648..2147483647
+
=====================================
testsuite/tests/warnings/should_compile/T13256.stderr-ws-64
=====================================
@@ -1,3 +1,3 @@
-
-T13256.hs:4:12: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
+T13256.hs:4:31: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal 100000000000000000000000000000000 is out of the Int range -9223372036854775808..9223372036854775807
+
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b991d4a536874184dbace81abcb5582…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/b991d4a536874184dbace81abcb5582…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc] Pushed new branch wip/davide/windows-dlls-rts_public
by David Eichmann (@DavidEichmann) 26 Oct '26
by David Eichmann (@DavidEichmann) 26 Oct '26
26 Oct '26
David Eichmann pushed new branch wip/davide/windows-dlls-rts_public at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/davide/windows-dlls-rts_public
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc][wip/romes/async-rpc] interp: wip: let interpProcess survive async exceptions
by Andrea Vezzosi (@trac-Saizan) 26 Oct '26
by Andrea Vezzosi (@trac-Saizan) 26 Oct '26
26 Oct '26
Andrea Vezzosi pushed to branch wip/romes/async-rpc at Glasgow Haskell Compiler / GHC
Commits:
a3a21767 by Andrea Vezzosi at 2026-10-26T16:40:53+01:00
interp: wip: let interpProcess survive async exceptions
- - - - -
1 changed file:
- compiler/GHC/Runtime/Interpreter/Process.hs
Changes:
=====================================
compiler/GHC/Runtime/Interpreter/Process.hs
=====================================
@@ -77,8 +77,10 @@ sendTHComputation i msg reqHandler = mask $ \restore -> do
else loop
in loop
-handleInterpProcessFailure :: InterpProcess -> SomeException -> IO a
-handleInterpProcessFailure i e = do
+handleInterpProcessFailure :: Interp -> InterpProcess -> SomeException -> IO a
+handleInterpProcessFailure interp i e
+ | Just SomeAsyncException{} <- fromException e = throw e
+ | otherwise = do
let hdl = interpHandle i
ex <- getProcessExitCode hdl
case ex of
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a3a217670526335a827a72241538f45…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a3a217670526335a827a72241538f45…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc][wip/romes/async-rpc] interp: cancel requests if async exceptions while waiting for reply.
by Andrea Vezzosi (@trac-Saizan) 26 Oct '26
by Andrea Vezzosi (@trac-Saizan) 26 Oct '26
26 Oct '26
Andrea Vezzosi pushed to branch wip/romes/async-rpc at Glasgow Haskell Compiler / GHC
Commits:
ea1dd1c7 by Andrea Vezzosi at 2026-10-26T09:50:00+01:00
interp: cancel requests if async exceptions while waiting for reply.
- - - - -
5 changed files:
- compiler/GHC/Runtime/Interpreter/Process.hs
- libraries/ghci/GHCi/Message.hs
- libraries/ghci/GHCi/Message/Async.hs
- libraries/ghci/GHCi/Server.hs
- libraries/ghci/GHCi/Server/Threads.hs
Changes:
=====================================
compiler/GHC/Runtime/Interpreter/Process.hs
=====================================
@@ -64,7 +64,7 @@ sendTHComputation i msg reqHandler = mask $ \restore -> do
where
proc = instProcess i
handleOne mbox doneRef = do
- handleRemoteTHCall (interpPipe proc) mbox $ \req -> do
+ handleRemoteTHCall (interpPipe proc) mbox $ \_setCancel req -> do
(stop, res) <- reqHandler req
writeIORef doneRef stop
return res
=====================================
libraries/ghci/GHCi/Message.hs
=====================================
@@ -75,6 +75,7 @@ import GHC.Stack.CCS
import qualified GHC.Boot.TH.Syntax as TH
import qualified GHC.Boot.TH.Monad as TH
import GHCi.Message.Async
+import Control.Monad.STM
-- -----------------------------------------------------------------------------
-- The RPC protocol between GHC and the interactive server
@@ -666,12 +667,12 @@ remoteCall pipe msg = either throwIO (pure . runGet get)
-- | Handle a single 'Message' request on the interpreter and reply to the host
handleRemoteCall :: Pipe
-> (Msg -> IO Msg) {-^ Msg hook -}
- -> (forall a. (Show a, Binary a) => WriteReply a %1 -> Message a -> IO r)
+ -> (forall a. (Show a, Binary a) => WriteReply a %1 -> (IO () -> IO ()) -> Message a -> IO r)
-> IO r
handleRemoteCall pipe hook k =
- handleAsyncReq pipe getMessage Nothing \(WriteReply writer) msg0 -> IO \s0 ->
+ handleAsyncReq pipe getMessage Nothing \(WriteReply writer) sa msg0 -> IO \s0 ->
case hook msg0 |#> s0 of -- unIO for linearity checking
- (# s1, Msg msg #) -> k (WriteReply \x -> writer (fmap put x)) msg |#> s1
+ (# s1, Msg msg #) -> k (WriteReply \x -> writer (fmap put x)) sa msg |#> s1
-- | Send a 'THMessage' request to the host and wait for a reply from the host
-- to the interpreter.
@@ -687,9 +688,9 @@ remoteTHCall pipe ii msg = either throwIO (pure . runGet get)
-- Symmterically to 'remoteTHCall', we always want to specify the 'InboxId' for
-- RunTH "reverse requests"
handleRemoteTHCall
- :: Pipe -> InboxId -> (forall a. (Show a, Binary a) => THMessage a -> IO a) -> IO ()
+ :: Pipe -> InboxId -> (forall a. (Show a, Binary a) => (IO () -> IO ()) -> THMessage a -> IO a) -> IO ()
handleRemoteTHCall pipe ii k =
- handleAsyncReq pipe getTHMessage (Just ii) \writer (THMsg msg) -> IO \s0 ->
- case k msg |#> s0 of -- unIO for linearity checking
+ handleAsyncReq pipe getTHMessage (Just ii) \writer sa (THMsg msg) -> IO \s0 ->
+ case k sa msg |#> s0 of -- unIO for linearity checking
(# s1, a #) -> writeReply writer (put a) |#> s1
=====================================
libraries/ghci/GHCi/Message/Async.hs
=====================================
@@ -160,14 +160,19 @@ instance Exception PipeWriteClosedException
-- and identify whether they are requests or replies.
writePipe :: Pipe -> IddMsg -> IO ()
-writePipe Pipe{..} msg = do
- var <- newEmptyTMVarIO
- atomically $ do
+writePipe p msg = do
+ var <- atomically $ writePipeAsync p msg
+ either throwIO pure =<< atomically (takeTMVar var)
+
+writePipeAsync :: Pipe -> IddMsg -> STM (TMVar (Either SomeException ()))
+writePipeAsync Pipe{..} msg = do
+ var <- newEmptyTMVar
readTVar pipeWriteClosed >>= \case
True -> throwSTM PipeWriteClosedException
False -> pure ()
writeTQueue (writeQueue pipeAsyncMngr) (msg, var)
- either throwIO pure =<< atomically (takeTMVar var)
+ pure var
+
-- | Only the 'drainPipe' thread should read from the pipe directly. Other
-- functions should wait for the matching reply to be delivered asynchronously.
@@ -239,14 +244,18 @@ remoteAsyncReq pipe msg ii = do
-- Write request
writePipe pipe (Request uq ii (runPut msg))
`onException`
- -- the req wasn't done, or no one will be reading the reply:
- -- in either case, drop it from the pending map.
- atomically (modifyTVar pendingReplies (IntMap.delete uq))
+ -- the req wasn't done, or no one will be reading the reply:
+ -- in either case, drop it from the pending map.
+ atomically (modifyTVar pendingReplies (IntMap.delete uq))
-- Block waiting for reply
atomically (takeTMVar wv)
`onException`
- atomically (modifyTVar pendingReplies (IntMap.delete uq))
+ atomically (do
+ modifyTVar pendingReplies (IntMap.delete uq)
+ -- we don't wait for Cancel to be written on the pipe,
+ -- and won't get a reply: nowhere to report it anyway.
+ writePipeAsync pipe (Cancel uq))
-- | Receive a single asynchronous request and send a matching reply
-- asynchronously (the handler may fork a computation that eventually replies
@@ -258,7 +267,7 @@ remoteAsyncReq pipe msg ii = do
-- branch, and if the handler otherwise throws, it is handled by 'handleAsyncReq'.
--
-- See Note [Exceptions during serialization] about exceptions the 'Put' argument might raise.
-handleAsyncReq :: Pipe -> Get a -> (Maybe InboxId) -> (WriteReply Put %1 -> a -> IO r) -> IO r
+handleAsyncReq :: Pipe -> Get a -> (Maybe InboxId) -> (WriteReply Put %1 -> (IO () -> IO ()) -> a -> IO r) -> IO r
handleAsyncReq pipe getit mii k = mask $ \restore -> do
let am = pipeAsyncMngr pipe
ack <- newEmptyMVar
@@ -274,7 +283,7 @@ handleAsyncReq pipe getit mii k = mask $ \restore -> do
Nothing -> tryReadTQueue $ requestsQueue am
Just ii -> tryReadTQueue =<< getMailbox am ii
case taken of
- Just req -> pure (Just req)
+ Just req@(uq,_) -> fetchedRequest am uq >> pure (Just req)
Nothing | isClosed -> pure Nothing -- empty and closed
| otherwise -> retry -- wait for msg
@@ -282,9 +291,9 @@ handleAsyncReq pipe getit mii k = mask $ \restore -> do
Nothing -> throwIO PipeReadClosedException -- can't expect reqs
Just (uq, bs) -> do
let reply p = do
- writePipe pipe (Reply uq (bimap toSerializableException runPut p))
- putMVar ack ()
-
+ b <- atomically $ doneHandling am uq
+ when b $ writePipe pipe (Reply uq (bimap toSerializableException runPut p))
+ putMVar ack () -- TODO: superfluous?
-- Run the continuation which must reply exactly once with 'writeReply'
case runGetOrFail getit bs of
Left (_, _, err) -> do
@@ -292,7 +301,7 @@ handleAsyncReq pipe getit mii k = mask $ \restore -> do
reply (Left (toException exc))
throwIO exc
Right (_, _, it) ->
- restore (k (WriteReply reply) it)
+ restore (k (WriteReply reply) (setActive am uq) it)
-- If there's an exception before the reply is sent, reply with an error instead.
`catch` \(e :: SomeException) -> do
@@ -306,6 +315,7 @@ handleAsyncReq pipe getit mii k = mask $ \restore -> do
reply (Left e)
throwIO e
+
-- | 'handleSyncReq' failed to decode an incoming request payload using the given @'Get' a@
newtype DecodeAsyncReqException = DecodeAsyncReqException String deriving Show
instance Exception DecodeAsyncReqException
@@ -347,6 +357,15 @@ getMailbox am (InboxId ii) = do
-- ** Async matching "internals" -----------------------------------------------
+-- | Requests go
+-- requestsQueue -> Fetched -> Active cancel -> gone
+-- .. -> Canceling -> gone
+-- Canceling is needed to avoid race condition in gap between Fetched and Active.
+data RequestStatus
+ = Fetched
+ | Active (IO ()) -- ^ must not be blocking.
+ | Canceling
+
data AsyncManager = AsyncManager
{ pendingReply :: !(TVar (IntMap (TMVar (Either SomeException LB.ByteString))))
-- ^ When a request is sent, keep track that we're expecting a reply. The
@@ -357,6 +376,9 @@ data AsyncManager = AsyncManager
-- /without/ a specific 'InboxId', queue it here. A request handler will
-- pop the next request from it. (Nothing except the 'drainPipe' thread
-- should read from the pipe). Read with @'handleAsyncReq' p get Nothing@.
+ , cancelStatus :: !(TVar (IntMap RequestStatus))
+ -- ^ When a `Cancel uq` is received, we lookup `uq` in this map and call the
+ -- callback if present.
, mailboxQueues :: !(TVar (IntMap (TQueue (CorrelationId, LB.ByteString))))
-- ^ Requests for a specific 'InboxId' that can be read using
-- @'handleAsyncReq' p get (Just <mailboxid>)@.
@@ -389,15 +411,21 @@ type CorrelationId = Int
-- exclusively.
data IddMsg = Request !CorrelationId !(Maybe InboxId) LB.ByteString
| Reply !CorrelationId (Either SerializableException LB.ByteString)
+ | Cancel !CorrelationId -- !(Maybe InboxId) --? ^ Technically a
+ -- Request, but no Reply is expected, the CorrelationId is the
+ -- one of the Request being canceled.
instance Binary IddMsg where
put (Request i ii bs) = putWord8 0 >> put i >> put ii >> put bs
put (Reply i bs) = putWord8 1 >> put i >> put bs
+ put (Cancel i) = putWord8 2 >> put i
+
get = do
b <- getWord8
case b of
0 -> Request <$> get <*> get <*> get
1 -> Reply <$> get <*> get
+ 2 -> Cancel <$> get
_ -> fail $ "impossible: Binary IddMsg - " ++ show b
newAsyncManager :: Pipe -> IO AsyncManager
@@ -405,6 +433,7 @@ newAsyncManager pipe = do
asyncFreshId <- newIORef 0
pendingReply <- newTVarIO IntMap.empty
requestsQueue <- newTQueueIO
+ cancelStatus <- newTVarIO IntMap.empty
mailboxQueues <- newTVarIO IntMap.empty
writeQueue <- newTQueueIO
@@ -430,41 +459,84 @@ drainPipe :: Pipe -> (forall x. IO x -> IO x) -> IO ()
drainPipe p unmask = catch (unmask $ loop `finally` pipeCloseRead p) replyToPendings where
loop = do
readPipe p >>= \case
- -- Receive a reply to a pending notification
- Just (Reply uq bs) -> do
- atomically $ do
- m <- readTVar (pendingReply am)
- case IntMap.lookup uq m of
- Nothing ->
- -- the req was dropped from pending bc there was an exception, and no
- -- one's listening any more. the reply is ignored
- pure ()
- Just wv -> do
- writeTVar (pendingReply am) (IntMap.delete uq m)
- -- signal matching request
- putTMVar wv (bimap (toException . RemoteProcessException) id bs)
- loop
- -- Receive a request and queue it
- Just (Request uq mbi bs) -> do
- atomically $ case mbi of
- Nothing ->
- -- "Global" request
- writeTQueue (requestsQueue am) (uq,bs)
- Just ii -> do
- -- "Specific mailbox" request
- q <- getMailbox am ii
- writeTQueue q (uq,bs)
+ Just msg -> do
+ handleMsg msg
loop
-- EOF on read handle
Nothing -> do
-- clean up pipe then exit loop
replyToPendings (toException PipeReadClosedException)
pure ()
+ handleMsg = \case
+ -- Receive a reply to a pending notification
+ Reply uq bs -> do
+ atomically $ do
+ m <- readTVar (pendingReply am)
+ case IntMap.lookup uq m of
+ Nothing ->
+ -- the req was dropped from pending bc there was an exception, and no
+ -- one's listening any more. the reply is ignored
+ pure ()
+ Just wv -> do
+ writeTVar (pendingReply am) (IntMap.delete uq m)
+ -- signal matching request
+ putTMVar wv (bimap (toException . RemoteProcessException) id bs)
+ -- Receive a request and queue it
+ Request uq mbi bs -> do
+ atomically $ case mbi of
+ Nothing ->
+ -- "Global" request
+ writeTQueue (requestsQueue am) (uq,bs)
+ Just ii -> do
+ -- "Specific mailbox" request
+ q <- getMailbox am ii
+ writeTQueue q (uq,bs)
+ Cancel uq -> cancelRequest am uq
replyToPendings e = atomically $ failPendingReplies p e
am = pipeAsyncMngr p
+cancelRequest :: AsyncManager -> CorrelationId -> IO ()
+cancelRequest am uq = join . atomically $ do
+ cs <- readTVar (cancelStatus am)
+ case IntMap.lookup uq cs of
+ Nothing -> pure (pure ())
+ Just Fetched -> writeTVar (cancelStatus am) (IntMap.insert uq Canceling cs) >> pure (pure ())
+ Just (Active cancel) -> writeTVar (cancelStatus am) (IntMap.delete uq cs) >> pure cancel
+ Just Canceling -> pure (pure ())
+
+doneHandling :: AsyncManager -> CorrelationId -> STM Bool
+doneHandling am uq = do
+ cs <- readTVar (cancelStatus am)
+ case IntMap.lookup uq cs of
+ Nothing -> pure False
+ Just s -> do
+ writeTVar (cancelStatus am) $ IntMap.delete uq cs
+ case s of
+ Canceling -> pure False
+ _ -> pure True
+
+setActive :: AsyncManager -> CorrelationId -> IO () -> IO ()
+setActive am uq cancel = join . atomically $ do
+ cs <- readTVar (cancelStatus am)
+ case IntMap.lookup uq cs of
+ Nothing -> pure (pure ()) -- reply already received.
+ Just Fetched -> writeTVar (cancelStatus am) (IntMap.insert uq (Active cancel) cs) >> pure (pure ())
+ Just (Active _) -> writeTVar (cancelStatus am) (IntMap.insert uq (Active cancel) cs) >> pure (pure ())
+ Just Canceling -> pure cancel
+
+fetchedRequest :: AsyncManager -> CorrelationId -> STM ()
+fetchedRequest am uq = do
+ cs <- readTVar (cancelStatus am)
+ case IntMap.lookup uq cs of
+ Nothing -> writeTVar (cancelStatus am) (IntMap.insert uq Fetched cs)
+ Just Fetched -> error "impossible"
+ Just (Active _) -> error "impossible"
+ Just Canceling -> error "impossible"
+
+
+
{-
Note [Exceptions during serialization]
-----------------------------------------------------------------------------
@@ -553,7 +625,7 @@ runWriteReply (WriteReply r) = r
(|#>) (IO fs) s = fs s
(%>>=) :: (IO a) -> (a -> IO b) %1 -> IO b
-(%>>=) = \ m f -> IO (\s0 ->
+(%>>=) = \ m -> \ f -> IO (\s0 ->
case m |#> s0 of -- unIO for linearity checking
(# s1, x #) -> f x |#> s1)
infixl 1 %>>=
=====================================
libraries/ghci/GHCi/Server.hs
=====================================
@@ -39,6 +39,7 @@ import System.Exit
import System.IO
import Control.Concurrent
+import Control.Monad.STM
import GHCi.Message.Async (runWriteReply, (%>>=))
import GHCi.Server.Threads
@@ -66,13 +67,13 @@ servWithCustom
-> IO ()
servWithCustom verbose hook pipe restore customHandler = do
ref <- newIORef False
- withThreadManager $ \mngr ->
+ withThreadManager $ \mngr -> do
loop ref mngr `finally` closePipe pipe
where
loop doneRef mngr = do
when verbose $ trace "reading pipe..."
- handleRemoteCall pipe hook $ \wr (msg :: Message a) ->
+ handleRemoteCall pipe hook $ \wr setCancel (msg :: Message a) ->
discardCtrlC %>>= \_ ->
when verbose (trace ("msg: " ++ (show msg))) %>>= \_ ->
@@ -83,8 +84,10 @@ servWithCustom verbose hook pipe restore customHandler = do
reply () %>>= writeReply wr
RunTH ii st q ty loc -> spawnFinally mngr (runWriteReply wr)
(wrapRunTH ii (runTH pipe ii st q ty loc))
+ (setCancel . void . forkIO . killThread)
RunModFinalizers ii st qs -> spawnFinally mngr (runWriteReply wr)
(wrapRunTH ii (runModFinalizerRefs pipe ii st qs))
+ (setCancel . void . forkIO . killThread)
_other -> run msg >>= reply %>>= writeReply wr
isDone <- readIORef doneRef
=====================================
libraries/ghci/GHCi/Server/Threads.hs
=====================================
@@ -41,8 +41,8 @@ withThreadManager k = do
-- | Linear and resource-safe because 'ThreadManager' is guaranteed to wait or
-- cancel all threads.
-spawnFinally :: ThreadManager -> (Either SomeException a -> IO ()) %1 -> IO a -> IO ()
-spawnFinally ThreadManager{..} = unsafe_linear \fin -> \action -> void $
+spawnFinally :: ThreadManager -> (Either SomeException a -> IO ()) %1 -> IO a -> (ThreadId -> IO b) -> IO b
+spawnFinally ThreadManager{..} = unsafe_linear \fin -> \action -> \k ->
forkFinally
( mask $ \unmask -> do
tid <- myThreadId
@@ -57,6 +57,7 @@ spawnFinally ThreadManager{..} = unsafe_linear \fin -> \action -> void $
else throwIO ThreadKilled
)
( \ea -> fin ea )
+ >>= k
unsafe_linear :: (a -> b) %1 -> (a %1 -> b)
unsafe_linear = Unsafe.unsafeCoerce (Unsafe.unsafeCoerce :: (a -> b) -> (a %1 -> b))
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ea1dd1c7cb103a159b7c1ec21b60e76…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/ea1dd1c7cb103a159b7c1ec21b60e76…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc][wip/dcoutts/signals-cleanup] 2 commits: Use the shared I/O manager data structure for MIO for signals
by Duncan Coutts (@dcoutts) 26 Oct '26
by Duncan Coutts (@dcoutts) 26 Oct '26
26 Oct '26
Duncan Coutts pushed to branch wip/dcoutts/signals-cleanup at Glasgow Haskell Compiler / GHC
Commits:
f066a992 by Duncan Coutts at 2026-10-26T14:49:20+00:00
Use the shared I/O manager data structure for MIO for signals
Move the MIO I/O manager's timer manager control fd from a global
variable into the shared I/O manager struct.
Soon we will use the same mechanism for the same purpose of signal
handling for the other posix I/O managers.
- - - - -
0267a165 by Duncan Coutts at 2026-10-26T14:49:20+00:00
Extract and add more utility functions for the signal self-pipe trick
Extract a utility function writeSignalInfoToPipe from the MIO I/O
manager so we can use it in other I/O managers too.
Also add related utility functions readSignalInfoFromPipe,
newNonBlockingPipe and startSignalHandler.
We will use these in the poll and selectbis I/O managers.
- - - - -
7 changed files:
- rts/IOManager.c
- rts/IOManagerInternals.h
- rts/configure.ac
- rts/posix/IOManSignals.c
- rts/posix/IOManSignals.h
- rts/posix/MIO.c
- rts/posix/MIO.h
Changes:
=====================================
rts/IOManager.c
=====================================
@@ -412,7 +412,7 @@ void initCapabilityIOManager(CapIOManager *iomgr)
#if defined(IOMGR_ENABLED_MIO_POSIX)
case IO_MANAGER_MIO_POSIX:
- iomgr->control_fd = -1;
+ initCapabilityIOManagerMIO(iomgr);
break;
#endif
default:
=====================================
rts/IOManagerInternals.h
=====================================
@@ -113,6 +113,12 @@ struct _CapIOManager {
*/
struct _CapIOManagerShared {
+#if defined(IOMGR_ENABLED_MIO_POSIX)
+ /* The timer manager control pipe (write end). This is the pipe into which
+ * we will send our signals.
+ */
+ int timer_manager_control_wr_fd;
+#endif
};
=====================================
rts/configure.ac
=====================================
@@ -221,10 +221,6 @@ AC_LINK_IFELSE([AC_LANG_CALL([], [printf\$LDBLStub])],
FP_CHECK_PTHREAD_FUNCS
-dnl ** check for eventfd which is needed by the I/O manager
-AC_CHECK_HEADERS([sys/eventfd.h])
-AC_CHECK_FUNCS([eventfd])
-
AC_CHECK_FUNCS([getpid getuid raise])
dnl large address space support (see rts/include/rts/storage/MBlock.h)
@@ -359,6 +355,10 @@ dnl -------------------------------------------------------------------
dnl Here we check for platform constraints. The result is the CPP flag
dnl IOMGR_BUILD_<name> and a EnableIOManager<Name> var for use here later.
+dnl Check for functions (optionally) used by several I/O managers
+AC_CHECK_HEADERS([sys/eventfd.h])
+AC_CHECK_FUNCS([eventfd pipe2])
+
GHC_IOMANAGER_ENABLE([select], [EnableIOManagerSelect], [IOMGR_BUILD_SELECT],
[if test "$HostOS" = "mingw32"; then
EnableIOManagerSelect=NO
=====================================
rts/posix/IOManSignals.c
=====================================
@@ -22,6 +22,7 @@
#include <unistd.h>
#include <signal.h>
+#include <fcntl.h>
#include <string.h>
/* -----------------------------------------------------------------------------
@@ -286,12 +287,27 @@ startPendingSignalHandlers(Capability *cap)
continue; // handler has been changed.
}
- info = stgMallocBytes(sizeof(siginfo_t), "startPendingSignalHandlers");
- // freed by runHandler
- memcpy(info, next_pending_handler, sizeof(siginfo_t));
+ info = next_pending_handler;
+ startSignalHandler(cap, sig, info);
+ }
+
+ unblockUserSignals();
+}
+#endif
+
+void startSignalHandler(Capability *cap, int sig, siginfo_t *info)
+{
+ /* Allocate a copy. This is freed by runHandler. */
+ // TODO: this could be improved to use a GC'd pinned byte array, but this
+ // would need coordination with the unix library.
+ siginfo_t *info_copy = stgMallocBytes(sizeof(siginfo_t), "startSignalHandler");
+ *info_copy = *info;
+
+ /* The info structure can be zero on solaris. So at least set the signo. */
+ info_copy->si_signo = sig;
debugTrace(DEBUG_iomanager,
- "Handling pending signal, no %d", info->si_signo);
+ "Handling pending signal, no %d", info_copy->si_signo);
StgTSO *t =
createIOThread(cap,
@@ -299,14 +315,75 @@ startPendingSignalHandlers(Capability *cap)
rts_apply(cap,
rts_apply(cap,
runHandlersPtr_closure,
- rts_mkPtr(cap, info)),
- rts_mkInt(cap, info->si_signo)));
+ rts_mkPtr(cap, info_copy)),
+ rts_mkInt(cap, info_copy->si_signo)));
scheduleThread(cap, t);
setThreadLabel(cap, t, "signal handler thread");
- }
-
- unblockUserSignals();
}
+
+void newNonBlockingPipe(int *pipe_fd_r, int *pipe_fd_w)
+{
+ int pipefd[2];
+#if defined(HAVE_PIPE2)
+ int res = pipe2(pipefd, O_CLOEXEC | O_NONBLOCK);
+#else
+ int res = pipe(pipefd);
+#endif
+ if (RTS_UNLIKELY(res < 0)) {
+ sysErrorBelch("newNonBlockingPipe");
+ stg_exit(EXIT_FAILURE);
+ }
+#if !defined(HAVE_PIPE2)
+ for (int i = 0; i < 2; i++) {
+ int res1 = fcntl(pipefd[i], F_SETFD, FD_CLOEXEC);
+ int res2 = fcntl(pipefd[i], F_SETFL, O_NONBLOCK);
+ if (RTS_UNLIKELY(res1 < 0 || res2 < 0)) {
+ sysErrorBelch("newFdWakeup fcntl()");
+ stg_exit(EXIT_FAILURE);
+ }
+ }
#endif
+ *pipe_fd_r = pipefd[0]; /* read end */
+ *pipe_fd_w = pipefd[1]; /* write end */
+}
+
+/* Write the signal number and siginfo into the given fd (which is
+ * typically a pipe in non-blocking mode).
+ */
+void writeSignalInfoToPipe(int sig, siginfo_t *info, int fd)
+{
+ StgWord8 buf[sizeof(siginfo_t) + 1];
+
+ buf[0] = sig;
+ if (info) {
+ memcpy(buf+1, info, sizeof(siginfo_t));
+ } else {
+ // info may be NULL on Solaris (see #3790)
+ memset(buf+1, 0, sizeof(siginfo_t));
+ }
+
+ int r = write(fd, buf, sizeof(siginfo_t)+1);
+ if (r == -1 && errno == EAGAIN) {
+ errorBelch("lost signal due to full pipe: %d\n", sig);
+ }
+}
+
+bool readSignalInfoFromPipe(int *sig, siginfo_t *info, int fd)
+{
+ StgWord8 buf[sizeof(siginfo_t) + 1];
+
+ int r = read(fd, buf, sizeof(siginfo_t)+1);
+
+ if (r == sizeof(siginfo_t)+1) {
+ *sig = (int) buf[0];
+ memcpy(info, buf+1, sizeof(siginfo_t));
+ return true;
+ } else {
+ // TODO: if r is >0 and < expected then we're kind of screwed
+ // it means we're all out of sync with the protocol.
+ // it _should_ never happen of course!
+ return false;
+ }
+}
#endif /* RTS_USER_SIGNALS */
=====================================
rts/posix/IOManSignals.h
=====================================
@@ -35,11 +35,18 @@ void finiUserSignals(void);
void startPendingSignalHandlers(Capability *cap);
#endif
+void startSignalHandler(Capability *cap, int sig, siginfo_t *info);
+
typedef void (*SignalHandler)(int sig, siginfo_t *info, void *p);
int installSignalHandler(int sig, int spi, sigset_t *mask, bool nocldstop,
SignalHandler handler);
+/* Utilities to help with the self-pipe trick for signal handling. */
+void newNonBlockingPipe(int *pipe_fd_r, int *pipe_fd_w);
+void writeSignalInfoToPipe (int sig, siginfo_t *info, int fd);
+bool readSignalInfoFromPipe(int *sig, siginfo_t *info, int fd);
+
/* Temporary */
void generic_handler(int sig USED_IF_THREADS,
siginfo_t *info,
=====================================
rts/posix/MIO.c
=====================================
@@ -13,16 +13,19 @@
#include "rts/PosixSource.h"
#include "Rts.h"
-#include "Schedule.h"
-#include "RtsUtils.h"
-#include "Prelude.h"
-#include "ThreadLabels.h"
+#include "IOManager.h"
+
+#if defined(IOMGR_ENABLED_MIO_POSIX)
#include "MIO.h"
-#include "IOManager.h"
#include "IOManagerInternals.h"
#include "IOManSignals.h"
+#include "Schedule.h"
+#include "RtsUtils.h"
+#include "Prelude.h"
+#include "ThreadLabels.h"
+
#if defined(HAVE_ERRNO_H)
# include <errno.h>
#endif
@@ -30,39 +33,33 @@
#include <stdlib.h>
#include <unistd.h>
-// Here's the pipe into which we will send our signals
-static int timer_manager_control_wr_fd = -1;
-// TODO: Eliminate these globals. Put then into the CapIOManager, but the
-// problem is these are shared across all caps, not per cap.
-
#define IO_MANAGER_DIE 0xfe
+void initCapabilityIOManagerMIO(CapIOManager *iomgr)
+{
+ iomgr->control_fd = -1;
+ if (iomgr->cap->no == 0) {
+ iomgr->shared->timer_manager_control_wr_fd = -1;
+ }
+}
+
void setTimerManagerControlFd(int fd) {
- RELAXED_STORE(&timer_manager_control_wr_fd, fd);
+ int *timer_manager_control_wr_fd =
+ &getCapability(0)->iomgr->shared->timer_manager_control_wr_fd;
+ RELAXED_STORE(timer_manager_control_wr_fd, fd);
}
-#if defined(THREADED_RTS)
-static void timerManagerNotifySignal(int sig, siginfo_t *info,
- void *p STG_UNUSED)
+static void signal_handler(int sig, siginfo_t *info, void *p STG_UNUSED)
{
- StgWord8 buf[sizeof(siginfo_t) + 1];
- int r;
-
- buf[0] = sig;
- if (info == NULL) {
- // info may be NULL on Solaris (see #3790)
- memset(buf+1, 0, sizeof(siginfo_t));
- } else {
- memcpy(buf+1, info, sizeof(siginfo_t));
- }
-
- int timer_control_fd = RELAXED_LOAD(&timer_manager_control_wr_fd);
+ /* In the signal handler we do not have Capability context, so access the
+ * control fd via capability 0.
+ */
+ int *timer_manager_control_wr_fd =
+ &getCapability(0)->iomgr->shared->timer_manager_control_wr_fd;
+ int timer_control_fd = RELAXED_LOAD(timer_manager_control_wr_fd);
if (0 <= timer_control_fd)
{
- r = write(timer_control_fd, buf, sizeof(siginfo_t)+1);
- if (r == -1 && errno == EAGAIN) {
- errorBelch("lost signal due to full pipe: %d\n", sig);
- }
+ writeSignalInfoToPipe(sig, info, timer_control_fd);
}
// If the IO manager hasn't told us what the FD of the write end
@@ -73,29 +70,28 @@ static void timerManagerNotifySignal(int sig, siginfo_t *info,
int installUserSignalHandlerMIO(int sig, int spi, sigset_t *mask,
bool nocldstop)
{
- return installSignalHandler(sig, spi, mask, nocldstop,
- timerManagerNotifySignal);
+ return installSignalHandler(sig, spi, mask, nocldstop, signal_handler);
}
-#endif
-
-#if defined(THREADED_RTS)
void
ioManagerDie (void)
{
finiUserSignals();
+ int *timer_manager_control_wr_fd =
+ &getCapability(0)->iomgr->shared->timer_manager_control_wr_fd;
+
StgWord8 byte = (StgWord8)IO_MANAGER_DIE;
uint32_t i;
int r;
{
// Shut down timer manager
- const int fd = RELAXED_LOAD(&timer_manager_control_wr_fd);
+ const int fd = RELAXED_LOAD(timer_manager_control_wr_fd);
if (0 <= fd) {
r = write(fd, &byte, 1);
if (r == -1) { sysErrorBelch("ioManagerDie: write"); }
- RELAXED_STORE(&timer_manager_control_wr_fd, -1);
+ RELAXED_STORE(timer_manager_control_wr_fd, -1);
}
}
@@ -123,13 +119,21 @@ ioManagerStart (void)
{
initUserSignals();
+ int *timer_manager_control_wr_fd =
+ &getCapability(0)->iomgr->shared->timer_manager_control_wr_fd;
+
// Make sure the IO manager thread is running
Capability *cap;
- if (SEQ_CST_LOAD(&timer_manager_control_wr_fd) < 0) {
+ if (SEQ_CST_LOAD(timer_manager_control_wr_fd) < 0) {
cap = rts_lock();
ioManagerStartCap(&cap);
rts_unlock(cap);
}
}
-#endif
+#else // !IOMGR_ENABLED_MIO_POSIX
+
+/* This is exported from the RTS unconditionally, but only used for MIO. */
+void setTimerManagerControlFd(int fd STG_UNUSED) { /* do nothing */ }
+
+#endif // IOMGR_ENABLED_MIO_POSIX
=====================================
rts/posix/MIO.h
=====================================
@@ -19,6 +19,8 @@
/* Communicating with the IO manager thread (see GHC.Conc).
*/
#if defined(THREADED_RTS)
+void initCapabilityIOManagerMIO(CapIOManager *iomgr);
+
void ioManagerDie (void);
void ioManagerStart (void);
void ioManagerStartCap (/* inout */ Capability **cap);
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0e5c12c264aa39945a631586da17b7…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0e5c12c264aa39945a631586da17b7…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc][wip/mangoiv/bp-16719] 3 commits: tag inference: don't confuse functions with their return values
by Magnus (@MangoIV) 26 Oct '26
by Magnus (@MangoIV) 26 Oct '26
26 Oct '26
Magnus pushed to branch wip/mangoiv/bp-16719 at Glasgow Haskell Compiler / GHC
Commits:
af470330 by Luite Stegeman at 2026-10-26T15:26:44+01:00
tag inference: don't confuse functions with their return values
inferTagRhs was mixing up taggedness for closures and return values
for function closures. We really shouldn't assign TagTuple to a
properly tagged function returning a tuple.
We fix this by keeping track of functions (TagFun) separately from
values (TagVal) and keeping track of their return value. TagFun is
also used for join points.
fixes #27005
(cherry picked from commit 7fe4f2ec3ce12ea138177c81a019dcfc148fe5d4)
- - - - -
ac17dd4f by Andreas Klebinger at 2026-10-26T15:26:44+01:00
Fix a few tag inference bugs.
* Treat bottoming functions and nullary join points as functions.
* When generating bytecode don't rely on imported tag sigs.
Fixes #27831, #27841 and #27842.
(cherry picked from commit 6bbca56943ef68ba32520bcf8712a8faf9021ed6)
- - - - -
97e87e29 by mangoiv at 2026-10-26T15:48:56+01:00
fixup! Fix a few tag inference bugs.
- - - - -
43 changed files:
- + changelog.d/T27831-bottoming-strict-field
- + changelog.d/T27842-bytecode-imported-tags
- + changelog.d/tag-inference-27005
- compiler/GHC/Core/Utils.hs
- compiler/GHC/Stg/InferTags.hs
- compiler/GHC/Stg/InferTags/Rewrite.hs
- compiler/GHC/Stg/InferTags/TagSig.hs
- compiler/GHC/Stg/InferTags/Types.hs
- testsuite/tests/bytecode/T27001.stdout
- + testsuite/tests/bytecode/T27842.hs
- + testsuite/tests/bytecode/T27842.stdout
- + testsuite/tests/bytecode/T27842A.hs
- + testsuite/tests/bytecode/T27842N.hs
- testsuite/tests/bytecode/all.T
- testsuite/tests/core-to-stg/T14895.stderr
- testsuite/tests/linters/notes.stdout
- testsuite/tests/simplCore/should_compile/T4201.stdout
- + testsuite/tests/simplCore/should_run/T27005.hs
- + testsuite/tests/simplCore/should_run/T27005.stdout
- + testsuite/tests/simplCore/should_run/T27005_aux.hs
- testsuite/tests/simplCore/should_run/all.T
- testsuite/tests/simplStg/should_compile/T24806.hs
- testsuite/tests/simplStg/should_compile/T24806.stderr
- + testsuite/tests/simplStg/should_compile/T27005b.hs
- + testsuite/tests/simplStg/should_compile/T27005b.stderr
- testsuite/tests/simplStg/should_compile/all.T
- testsuite/tests/simplStg/should_compile/inferTags004.hs
- testsuite/tests/simplStg/should_compile/inferTags004.stderr
- + testsuite/tests/simplStg/should_compile/inferTags005.hs
- + testsuite/tests/simplStg/should_compile/inferTags005.stderr
- + testsuite/tests/simplStg/should_compile/inferTags006.hs
- + testsuite/tests/simplStg/should_compile/inferTags006.stderr
- + testsuite/tests/simplStg/should_run/InferTags007_A.hs
- testsuite/tests/simplStg/should_run/T22042.stdout
- + testsuite/tests/simplStg/should_run/T27005a.hs
- + testsuite/tests/simplStg/should_run/T27005a.stdout
- + testsuite/tests/simplStg/should_run/T27831.hs
- + testsuite/tests/simplStg/should_run/T27831.stdout
- + testsuite/tests/simplStg/should_run/T27857.hs
- + testsuite/tests/simplStg/should_run/T27857.stdout
- testsuite/tests/simplStg/should_run/all.T
- + testsuite/tests/simplStg/should_run/inferTags007.hs
- + testsuite/tests/simplStg/should_run/inferTags007.stdout
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/5ba51d68ee23b472fcd902f04643f5…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/5ba51d68ee23b472fcd902f04643f5…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
26 Oct '26
Mikolaj Konarski pushed new branch wip/T27984-inline-boring at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T27984-inline-boring
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc][wip/sjakobi/T27722-cbe-exclude-entry] Cmm: exclude the entry block from common block elimination
by Simon Jakobi (@sjakobi) 26 Oct '26
by Simon Jakobi (@sjakobi) 26 Oct '26
26 Oct '26
Simon Jakobi pushed to branch wip/sjakobi/T27722-cbe-exclude-entry at Glasgow Haskell Compiler / GHC
Commits:
a233854f by Simon Jakobi at 2026-10-26T12:54:33+01:00
Cmm: exclude the entry block from common block elimination
a1d8139054c had fixed #27722 only partially, because it didn't prevent
elimination of the entry block in later rounds, where the entry block is
no longer guaranteed to come first.
To close this loophole, we exclude the entry block from the CBE merge
logic. See Note [Retain entry block during common block elimination] for
details.
This also deletes a misleading comment regarding unreachable blocks: the
control-flow optimiser doesn't actually guarantee that no unreachable
blocks reach CBE.
Fixes #27722.
Assisted-by: Claude Fable 5.1
- - - - -
5 changed files:
- changelog.d/T27722-cbe-entry-block.md
- compiler/GHC/Cmm/CommonBlockElim.hs
- + testsuite/tests/cmm/should_run/T27722.hs
- + testsuite/tests/cmm/should_run/T27722_cmm.cmm
- testsuite/tests/cmm/should_run/all.T
Changes:
=====================================
changelog.d/T27722-cbe-entry-block.md
=====================================
@@ -1,5 +1,5 @@
section: cmm
issues: #27722
-mrs: !16592
+mrs: !16592 !16861
synopsis:
Fix common block elimination dropping entry block info table in hand written cmm.
=====================================
compiler/GHC/Cmm/CommonBlockElim.hs
=====================================
@@ -66,25 +66,23 @@ elimCommonBlocks g =
where
g' = replaceLabels env $ copyTicks env g
env = iterate mapEmpty blocks_with_key
- -- The order of blocks doesn't matter here. While we could use
- -- revPostorder which drops unreachable blocks this is done in
- -- ContFlowOpt already which runs before this pass. So we use
- -- toBlockList since it is faster.
- -- One exception: The entry block most come first or we risk eliminating it
- -- in favour of another block. See Note [Retain entry block during common block elimination.]
- groups = groupByInt hash_block (toBlockListEntryFirst g) :: [[CmmBlock]]
blocks_with_key = [ [ (successors b, [b]) | b <- bs] | bs <- groups]
-
--- Note [Retain entry block during common block elimination.]
--- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
--- At the stage we run common block elimination (CBE) we only have one info
--- table for the entry label. Which means we can get away without applying the
--- block label substitution to the info table *as long as we keep the first block*.
--- When combining blocks the first block in the list of blocks is kept, and the later
--- one eliminated, so we can achieve this by simply using toBlockListEntryFirst.
+ groups = groupByInt hash_block candidates :: [[CmmBlock]]
+ -- See Note [Retain entry block during common block elimination]
+ candidates = filter ((/= g_entry g) . entryLabel) (toBlockList g)
+
+-- Note [Retain entry block during common block elimination]
+-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+-- When CBE runs, only the entry label has an info table, so we can get away
+-- without applying the block label substitution to info tables, as long as we
+-- preserve the entry block (#27722). We achieve this by simply keeping it out
+-- of the list of candidates for elimination.
--
--- If we don't we end up with #27722 where the entry block was eliminated in favour
--- of another block.
+-- The downside is that any duplicates of the entry block stay unmerged. This
+-- should be very rare though, and only affects hand-written Cmm: the entry
+-- block of any proc generated from STG contains the stack check (see
+-- entryHeapCheck in GHC.StgToCmm.Heap) and is therefore distinct from any
+-- other block in the same proc.
-- Invariant: The blocks in the list are pairwise distinct
-- (so avoid comparing them again)
=====================================
testsuite/tests/cmm/should_run/T27722.hs
=====================================
@@ -0,0 +1,8 @@
+import Control.Monad
+import Foreign.Ptr
+import System.Exit
+
+foreign import ccall "&zork_info" zork_info :: Ptr ()
+
+main :: IO ()
+main = when (zork_info == nullPtr) exitFailure
=====================================
testsuite/tests/cmm/should_run/T27722_cmm.cmm
=====================================
@@ -0,0 +1,29 @@
+#include "Cmm.h"
+
+// Regression test for #27722: common block elimination (CBE) must not
+// eliminate the entry block, because the proc's info table refers to it.
+// With the bug, zork_info is never emitted and T27722.hs fails to link.
+//
+// The entry block only becomes a duplicate in the third round of CBE:
+// round 1 merges the two then-blocks (both duplicates of the entry
+// block), round 2 merges E1 and E2, and only then does the entry block
+// match the surviving then-block.
+//
+// The then-blocks are braced if-bodies so that, like the entry block,
+// they carry two source notes (braces and statement): CBE's block hash
+// counts tick nodes (#27877), and blocks with different hashes are never
+// compared.
+INFO_TABLE_RET (zork, RET_SMALL)
+ return ()
+{
+ bits64 x;
+ x = 1 :: bits64;
+ goto E1;
+E1:
+ if (x > 0 :: bits64) { x = 1 :: bits64; goto E2; } else { goto D; }
+E2:
+ if (x > 0 :: bits64) { x = 1 :: bits64; goto E2; } else { goto D; }
+D:
+ if (x > 1 :: bits64) goto E1;
+ goto E2;
+}
=====================================
testsuite/tests/cmm/should_run/all.T
=====================================
@@ -60,3 +60,6 @@ test('T27447',
],
multi_compile_and_run,
['T27447', [('T27447_cmm.cmm', '')], ''])
+
+test('T27722', [req_cmm], multi_compile_and_run,
+ ['T27722', [('T27722_cmm.cmm', '')], '-O'])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a233854fc92f11367a3a57bc29fdd96…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a233854fc92f11367a3a57bc29fdd96…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
[Git][ghc/ghc][wip/marge_bot_batch_merge_job] 4 commits: Refactor QuickLook a bit
by Marge Bot (@marge-bot) 26 Oct '26
by Marge Bot (@marge-bot) 26 Oct '26
26 Oct '26
Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC
Commits:
7f73f515 by Simon Peyton Jones at 2026-10-24T17:29:19-04:00
Refactor QuickLook a bit
This MR simply refactors QuickLook a bit. In particular, it
simplifies `tcApp`, and moves shared code into `finishApp`.
It also adds `Note [QuickLook: arguments before result]`
responding to #26599.
There should be no user-visible changes, except perhaps in error messages,
which improve marginally.
For some reason T24984 compiles 8% faster. I'll take the win!
Metric Decrease:
T24984
- - - - -
a4a3a964 by Alan Zimmerman at 2026-10-24T17:30:03-04:00
EPA: Use AnnList for XClosedTypeFamily
We now have TTG annotations for FamilyInfo.
Make use of it to store the AnnList annotations for a closed type
family.
- - - - -
2b89a579 by Sasha Bogicevic at 2026-10-26T08:14:10+01:00
Don't report -XStrict-generated bangs under -Wredundant-bang-patterns
The -XStrict flag causes the desugarer to insert bang patterns.
These are not user-written, so -Wredundant-bang-patterns must not
report them.
To achieve this, the desugarer now tracks whether it is desugaring
compiler-generated code (similar to the typechecker's 'tcl_in_gen_code').
Bangs inserted by -XStrict are given generated spans, which suppresses
the "redundant bang" warnings without otherwise affecting pattern-match
warnings.
Fixes #27323
- - - - -
49be1871 by Alan Zimmerman at 2026-10-26T06:26:46-04:00
EPA: Update AnnClsInstDecl to contain AnnList
It was already separately tracking the '{', '}' and leading ';' values.
This aligns it with layout-introducing parser productions ('vocurly'),
so the layout processing can be handled uniformly
- - - - -
30 changed files:
- + changelog.d/T27323
- compiler/GHC/Hs/Decls.hs
- compiler/GHC/Hs/Dump.hs
- compiler/GHC/HsToCore/Match.hs
- compiler/GHC/HsToCore/Match/Literal.hs
- compiler/GHC/HsToCore/Monad.hs
- compiler/GHC/HsToCore/Pmc.hs
- compiler/GHC/HsToCore/Pmc/Desugar.hs
- compiler/GHC/HsToCore/Types.hs
- compiler/GHC/HsToCore/Utils.hs
- compiler/GHC/Parser.y
- compiler/GHC/Tc/Gen/App.hs
- compiler/GHC/ThToHs.hs
- testsuite/tests/ghci.debugger/scripts/T14628.stderr
- testsuite/tests/haddock/should_compile_flag_haddock/T17544.stderr
- testsuite/tests/parser/should_compile/DumpParsedAst.stderr
- testsuite/tests/parser/should_compile/DumpRenamedAst.stderr
- testsuite/tests/parser/should_compile/KindSigs.stderr
- + testsuite/tests/pmcheck/should_compile/T27323.hs
- + testsuite/tests/pmcheck/should_compile/T27323b.hs
- testsuite/tests/pmcheck/should_compile/all.T
- testsuite/tests/printer/Test24533.stdout
- testsuite/tests/typecheck/should_fail/T22707.stderr
- testsuite/tests/typecheck/should_fail/T25950.stderr
- testsuite/tests/typecheck/should_fail/T8450.stderr
- testsuite/tests/warnings/should_compile/Overflow.stderr-ws-64
- testsuite/tests/warnings/should_compile/T13256.stderr-ws-64
- utils/check-exact/ExactPrint.hs
- utils/haddock/haddock-api/src/Haddock/Convert.hs
- utils/haddock/haddock-api/src/Haddock/Types.hs
Changes:
=====================================
changelog.d/T27323
=====================================
@@ -0,0 +1,7 @@
+section: compiler
+synopsis: Don't report ``-XStrict``-generated bang patterns under ``-Wredundant-bang-patterns``
+description:
+ Bangs introduced by ``-XStrict`` are no longer reported as redundant under
+ ``-Wredundant-bang-patterns``, as they are not user-written.
+issues: #27323
+mrs: !16395
=====================================
compiler/GHC/Hs/Decls.hs
=====================================
@@ -708,13 +708,11 @@ data AnnFamilyDecl
afd_equal :: EpToken "=",
afd_vbar :: EpToken "|",
afd_where :: EpToken "where",
- afd_openc :: EpToken "{",
- afd_dotdot :: EpToken "..",
- afd_closec :: EpToken "}"
+ afd_dotdot :: EpToken ".."
} deriving Data
instance NoAnn AnnFamilyDecl where
- noAnn = AnnFamilyDecl noAnn noAnn noAnn noAnn noAnn noAnn noAnn noAnn noAnn noAnn noAnn noAnn
+ noAnn = AnnFamilyDecl noAnn noAnn noAnn noAnn noAnn noAnn noAnn noAnn noAnn noAnn
------------- Functions over FamilyDecls -----------
@@ -744,7 +742,7 @@ type instance XXInjectivityAnn (GhcPass _) = DataConCantHappen
type instance XDataFamily (GhcPass _) = NoExtField
type instance XOpenTypeFamily (GhcPass _) = NoExtField
-type instance XClosedTypeFamily (GhcPass _) = NoExtField
+type instance XClosedTypeFamily (GhcPass _) = AnnList
type instance XXFamilyInfo (GhcPass _) = DataConCantHappen
instance OutputableBndrId p
@@ -1044,9 +1042,7 @@ data AnnClsInstDecl
= AnnClsInstDecl {
acid_instance :: EpToken "instance",
acid_where :: EpToken "where",
- acid_openc :: EpToken "{",
- acid_semis :: [EpToken ";"],
- acid_closec :: EpToken "}"
+ acid_decls :: AnnList
} deriving Data
@@ -1063,7 +1059,7 @@ type instance XTyFamInstD GhcTc = NoExtField
type instance XXInstDecl (GhcPass _) = DataConCantHappen
instance NoAnn AnnClsInstDecl where
- noAnn = AnnClsInstDecl noAnn noAnn noAnn noAnn noAnn
+ noAnn = AnnClsInstDecl noAnn noAnn noAnn
cidDeprecation :: forall p. IsPass p
=> ClsInstDecl (GhcPass p)
=====================================
compiler/GHC/Hs/Dump.hs
=====================================
@@ -258,22 +258,21 @@ showAstData bs ba a0 = blankLine $$ showAstData' a0
showAstData' j, showAstData' k]
annFamilyDecl :: AnnFamilyDecl -> SDoc
- annFamilyDecl (AnnFamilyDecl a b c d e f g h i j k l) = case ba of
+ annFamilyDecl (AnnFamilyDecl a b c d e f g h i j) = case ba of
BlankEpAnnotations -> parens $ text "blanked:" <+> text "AnnFamilyDecl"
NoBlankEpAnnotations ->
parens $ text "AnnFamilyDecl"
$$ vcat [showAstData' a, showAstData' b, showAstData' c,
showAstData' d, showAstData' e, showAstData' f,
showAstData' g, showAstData' h, showAstData' i,
- showAstData' j, showAstData' k, showAstData' l]
+ showAstData' j]
annClsInstDecl :: AnnClsInstDecl -> SDoc
- annClsInstDecl (AnnClsInstDecl a b c d e) = case ba of
+ annClsInstDecl (AnnClsInstDecl a b c) = case ba of
BlankEpAnnotations -> parens $ text "blanked:" <+> text "AnnFamilyDecl"
NoBlankEpAnnotations ->
parens $ text "AnnClsInstDecl"
- $$ vcat [showAstData' a, showAstData' b, showAstData' c,
- showAstData' d, showAstData' e]
+ $$ vcat [showAstData' a, showAstData' b, showAstData' c]
annotationExprBracket :: BracketAnn (EpUniToken "[|" "⟦") (EpToken "[e|") -> SDoc
=====================================
compiler/GHC/HsToCore/Match.hs
=====================================
@@ -383,12 +383,14 @@ tidyEqnInfo :: MatchId -> EquationInfo
tidyEqnInfo _ eqn@(EqnDone {}) = return (idDsWrapper, eqn)
-tidyEqnInfo v eqn@(EqnMatch { eqn_pat = (L loc pat) }) = do
- (wrap, pat') <- tidy1 v (not . isGoodSrcSpan . locA $ loc) pat
+tidyEqnInfo v eqn@(EqnMatch { eqn_pat = p@(L loc _) }) = do
+ (wrap, pat') <- tidyLPat v p
return (wrap, eqn{eqn_pat = L loc pat' })
+tidyLPat :: MatchId -> LPat GhcTc -> DsM (DsWrapper, Pat GhcTc)
+tidyLPat v (L loc pat) = putSrcSpanDsA loc (tidy1 v pat)
+
tidy1 :: MatchId -- The scrutinee
- -> Bool -- `True` if the pattern was generated, `False` if it was user-written
-> Pat GhcTc -- The pattern against which it is to be matched
-> DsM (DsWrapper, -- Extra bindings to do before the match
Pat GhcTc) -- Equivalent pattern
@@ -399,21 +401,22 @@ tidy1 :: MatchId -- The scrutinee
-- It eliminates many pattern forms (as-patterns, variable patterns,
-- list patterns, etc) and returns any created bindings in the wrapper.
-tidy1 v g (ParPat _ pat) = tidy1 v g (unLoc pat)
-tidy1 v g (SigPat _ pat _) = tidy1 v g (unLoc pat)
-tidy1 _ _ (WildPat ty) = return (idDsWrapper, WildPat ty)
-tidy1 v g (BangPat _ (L l p)) = tidy_bang_pat v g l p
-tidy1 v g (ModifiedPat _ _ pat) = tidy1 v g (unLoc pat)
+tidy1 v (ParPat _ pat) = tidyLPat v pat
+tidy1 v (SigPat _ pat _) = tidyLPat v pat
+tidy1 _ (WildPat ty) = return (idDsWrapper, WildPat ty)
+tidy1 v (BangPat _ (L l p)) = putSrcSpanDsA l $ tidy_bang_pat v l p
+tidy1 v (ModifiedPat _ _ pat) = tidyLPat v pat
-- case v of { x -> mr[] }
-- = case v of { _ -> let x=v in mr[] }
-tidy1 v _ (VarPat _ (L _ var))
+tidy1 v (VarPat _ (L _ var))
= return (bindMatchId var v, WildPat (idType var))
-- case v of { x@p -> mr[] }
-- = case v of { p -> let x=v in mr[] }
-tidy1 v g (AsPat _ (L _ var) pat)
- = do { (wrap, pat') <- tidy1 v g (unLoc pat)
+tidy1 v (AsPat _ (L _ var) pat)
+
+ = do { (wrap, pat') <- tidyLPat v pat
; return (bindMatchId var v . wrap, pat') }
{- now, here we handle lazy patterns:
@@ -427,7 +430,7 @@ tidy1 v g (AsPat _ (L _ var) pat)
The case expr for v_i is just: match [v] [(p, [], \ x -> Var v_i)] any_expr
-}
-tidy1 v _ (LazyPat _ pat)
+tidy1 v (LazyPat _ pat)
-- This is a convenient place to check for unlifted types under a lazy pattern.
-- Doing this check during type-checking is unsatisfactory because we may
-- not fully know the zonked types yet. We sure do here.
@@ -441,14 +444,14 @@ tidy1 v _ (LazyPat _ pat)
; let sel_binds = [NonRec b rhs | (b,rhs) <- sel_prs]
; return (mkCoreLets sel_binds, WildPat (matchIdType v)) }
-tidy1 _ _ (ListPat ty pats)
+tidy1 _ (ListPat ty pats)
= return (idDsWrapper, unLoc list_ConPat)
where
list_ConPat = foldr (\ x y -> mkPrefixConPat consDataCon [x, y] [ty])
(mkNilPat ty)
pats
-tidy1 _ _ (TuplePat tys pats boxity)
+tidy1 _ (TuplePat tys pats boxity)
= return (idDsWrapper, unLoc tuple_ConPat)
where
arity = length pats
@@ -458,34 +461,37 @@ tidy1 _ _ (TuplePat tys pats boxity)
Boxed -> tys
-- See Note [Unboxed tuple RuntimeRep vars] in TyCon
-tidy1 _ _ (SumPat tys pat alt arity)
+tidy1 _ (SumPat tys pat alt arity)
= return (idDsWrapper, unLoc sum_ConPat)
where
sum_ConPat = mkPrefixConPat (sumDataCon alt arity) [pat] (map getRuntimeRep tys ++ tys)
-- See Note [Unboxed tuple RuntimeRep vars] in TyCon
-- LitPats: we *might* be able to replace these w/ a simpler form
-tidy1 _ g (LitPat _ lit)
- = do { unless g $
+tidy1 _ (LitPat _ lit)
+ = do { in_gen <- inGeneratedCodeDs;
+ unless in_gen $
warnAboutOverflowedLit lit
; return (idDsWrapper, tidyLitPat lit) }
-- NPats: we *might* be able to replace these w/ a simpler form
-tidy1 _ g (NPat ty (L _ lit@OverLit { ol_val = v }) mb_neg eq)
- = do { unless g $
+tidy1 _ (NPat ty (L _ lit@OverLit { ol_val = v }) mb_neg eq)
+ = do { in_gen <- inGeneratedCodeDs;
+ unless in_gen $
let lit' | Just _ <- mb_neg = lit{ ol_val = negateOverLitVal v }
| otherwise = lit
in warnAboutOverflowedOverLit lit'
; return (idDsWrapper, tidyNPat lit mb_neg eq ty) }
-- NPlusKPat: we may want to warn about the literals
-tidy1 _ g n@(NPlusKPat _ _ (L _ lit1) lit2 _ _)
- = do { unless g $ do
+tidy1 _ n@(NPlusKPat _ _ (L _ lit1) lit2 _ _)
+ = do { in_gen <- inGeneratedCodeDs;
+ unless in_gen $ do
warnAboutOverflowedOverLit lit1
warnAboutOverflowedOverLit lit2
; return (idDsWrapper, n) }
-tidy1 _ _ (OrPat ty lpats)
+tidy1 _ (OrPat ty lpats)
-- See Note [Implementation of OrPatterns]. We desugar
-- (1; 2; 3)
-- to
@@ -514,44 +520,44 @@ tidy1 _ _ (OrPat ty lpats)
single_grhs e = GRHSs emptyComments [noLocA $ GRHS noAnn [] e] (EmptyLocalBinds noExtField)
-- Everything else goes through unchanged...
-tidy1 _ _ non_interesting_pat
+tidy1 _ non_interesting_pat
= return (idDsWrapper, non_interesting_pat)
--------------------
-tidy_bang_pat :: MatchId -> Bool -> SrcSpanAnnA -> Pat GhcTc
+tidy_bang_pat :: MatchId -> SrcSpanAnnA -> Pat GhcTc
-> DsM (DsWrapper, Pat GhcTc)
-- Discard par/sig under a bang
-tidy_bang_pat v g _ (ParPat _ (L l p)) = tidy_bang_pat v g l p
-tidy_bang_pat v g _ (SigPat _ (L l p) _) = tidy_bang_pat v g l p
+tidy_bang_pat v _ (ParPat _ (L l p)) = putSrcSpanDsA l $ tidy_bang_pat v l p
+tidy_bang_pat v _ (SigPat _ (L l p) _) = putSrcSpanDsA l $ tidy_bang_pat v l p
-- Push the bang-pattern inwards, in the hope that
-- it may disappear next time
-tidy_bang_pat v g l (AsPat x v' p)
- = tidy1 v g (AsPat x v' (L l (BangPat noExtField p)))
-tidy_bang_pat v g l (XPat (CoPat w p t))
- = tidy1 v g (XPat $ CoPat w (BangPat noExtField (L l p)) t)
-tidy_bang_pat v g l (OrPat x (p:|ps)) -- push bang into first pat alt
- = tidy1 v g (OrPat x (L l (BangPat noExtField p) :| ps))
+tidy_bang_pat v l (AsPat x v' p)
+ = tidy1 v (AsPat x v' (L l (BangPat noExtField p)))
+tidy_bang_pat v l (XPat (CoPat w p t))
+ = tidy1 v (XPat $ CoPat w (BangPat noExtField (L l p)) t)
+tidy_bang_pat v l (OrPat x (p:|ps)) -- push bang into first pat alt
+ = tidy1 v (OrPat x (L l (BangPat noExtField p) :| ps))
-- Discard bang around strict pattern
-tidy_bang_pat v g _ p@(LitPat {}) = tidy1 v g p
-tidy_bang_pat v g _ p@(ListPat {}) = tidy1 v g p
-tidy_bang_pat v g _ p@(TuplePat {}) = tidy1 v g p
-tidy_bang_pat v g _ p@(SumPat {}) = tidy1 v g p
+tidy_bang_pat v _ p@(LitPat {}) = tidy1 v p
+tidy_bang_pat v _ p@(ListPat {}) = tidy1 v p
+tidy_bang_pat v _ p@(TuplePat {}) = tidy1 v p
+tidy_bang_pat v _ p@(SumPat {}) = tidy1 v p
-- Data/newtype constructors
-tidy_bang_pat v g l p@(ConPat { pat_con = L _ (RealDataCon dc)
- , pat_args = args
- , pat_con_ext = ConPatTc
- { cpt_arg_tys = arg_tys
- }
- })
+tidy_bang_pat v l p@(ConPat { pat_con = L _ (RealDataCon dc)
+ , pat_args = args
+ , pat_con_ext = ConPatTc
+ { cpt_arg_tys = arg_tys
+ }
+ })
-- Newtypes: push bang inwards (#9844)
=
if isNewTyCon (dataConTyCon dc)
- then tidy1 v g (p { pat_args = push_bang_into_newtype_arg l (scaledThing ty) args })
- else tidy1 v g p -- Data types: discard the bang
+ then tidy1 v (p { pat_args = push_bang_into_newtype_arg l (scaledThing ty) args })
+ else tidy1 v p -- Data types: discard the bang
where
(ty:_) = dataConInstArgTys dc arg_tys
@@ -570,7 +576,7 @@ tidy_bang_pat v g l p@(ConPat { pat_con = L _ (RealDataCon dc)
--
-- NB: SigPatIn, ConPatIn should not happen
-tidy_bang_pat _ _ l p = return (idDsWrapper, BangPat noExtField (L l p))
+tidy_bang_pat _ l p = return (idDsWrapper, BangPat noExtField (L l p))
-------------------
push_bang_into_newtype_arg :: SrcSpanAnnA
@@ -954,7 +960,7 @@ matchSinglePatVar var mb_scrut ctx pat ty match_result
; ldi_nablas <-
if isMatchContextPmChecked_SinglePat dflags FromSource ctx pat
then addCoreScrutTmCs (maybeToList mb_scrut) [var] $
- pmcPatBind (DsMatchContext ctx locn) var (unLoc pat)
+ pmcPatBind (DsMatchContext ctx locn) var pat
else getLdiNablas
; let eqn_info = EqnMatch { eqn_pat = decideBangHood dflags pat
=====================================
compiler/GHC/HsToCore/Match/Literal.hs
=====================================
@@ -33,6 +33,7 @@ import GHC.HsToCore.Utils
import GHC.Hs
+import GHC.Rename.Utils (wrapGenSpan)
import GHC.Tc.Utils.TcMType ( shortCutLit )
import GHC.Tc.Utils.TcType
@@ -580,7 +581,8 @@ tidyNPat (OverLit (OverLitTc False _ ty) val) mb_neg _eq outer_ty
mk_con_pat :: DataCon -> HsLit GhcTc -> Pat GhcTc
mk_con_pat con lit
- = unLoc (mkPrefixConPat con [noLocA $ LitPat noExtField lit] [])
+ -- Mark the generated literal to avoid duplicate -Woverflowed-literals.
+ = unLoc (mkPrefixConPat con [wrapGenSpan $ LitPat noExtField lit] [])
mb_int_lit :: Maybe Integer
mb_int_lit = case (mb_neg, val) of
=====================================
compiler/GHC/HsToCore/Monad.hs
=====================================
@@ -15,7 +15,7 @@ module GHC.HsToCore.Monad (
duplicateLocalDs, newSysLocalDs, newSysLocalsDs,
newSysLocalMDs, newSysLocalsMDs, newFailLocalMDs,
newUniqueId, newPredVarDs, newStaticId,
- getSrcSpanDs, putSrcSpanDs, putSrcSpanDsA,
+ getSrcSpanDs, inGeneratedCodeDs, putSrcSpanDs, putSrcSpanDsA,
mkNamePprCtxDs,
newUnique,
UniqSupply, newUniqueSupply,
@@ -584,6 +584,7 @@ mkDsEnvs unit_env mod rdr_env type_env fam_inst_env tcm_plugins ptc msg_var
, dsl_loc = real_span
, dsl_nablas = Ldi initNablas
, dsl_unspecables = Just emptyVarSet
+ , dsl_in_generated_code = False
}
in (gbl_env, lcl_env)
@@ -676,13 +677,17 @@ getSrcSpanDs :: DsM SrcSpan
getSrcSpanDs = do { env <- getLclEnv
; return (RealSrcSpan (dsl_loc env) Strict.Nothing) }
+-- | See 'dsl_in_generated_code'
+inGeneratedCodeDs :: DsM Bool
+inGeneratedCodeDs = dsl_in_generated_code <$> getLclEnv
+
putSrcSpanDs :: SrcSpan -> DsM a -> DsM a
putSrcSpanDs (RealSrcSpan real_span _) thing_inside
- = updLclEnv (\ env -> env {dsl_loc = real_span}) thing_inside
+ = updLclEnv (\ env -> env {dsl_loc = real_span, dsl_in_generated_code = False}) thing_inside
putSrcSpanDs UnhelpfulSpan{} thing_inside
= thing_inside
putSrcSpanDs GeneratedSrcSpan{} thing_inside
- = thing_inside
+ = updLclEnv (\ env -> env {dsl_in_generated_code = True}) thing_inside
putSrcSpanDsA :: EpAnn ann -> DsM a -> DsM a
putSrcSpanDsA loc = putSrcSpanDs (locA loc)
=====================================
compiler/GHC/HsToCore/Pmc.hs
=====================================
@@ -104,7 +104,7 @@ whenDoingPmc no_pmc thing_inside
Ldi nablas -> thing_inside nablas }
-- | Check a pattern binding (let, where) for exhaustiveness.
-pmcPatBind :: DsMatchContext -> Id -> Pat GhcTc -> DsM LdiNablas
+pmcPatBind :: DsMatchContext -> Id -> LPat GhcTc -> DsM LdiNablas
pmcPatBind ctxt@(DsMatchContext match_ctxt loc) var p
= whenDoingPmc NoPmc $ \ !missing ->
mb_discard_warnings $ do
=====================================
compiler/GHC/HsToCore/Pmc/Desugar.hs
=====================================
@@ -155,11 +155,15 @@ desugarPat x pat = case pat of
VarPat _ y -> pure (mkPmLetVar (unLoc y) x)
ParPat _ p -> desugarLPat x p
LazyPat _ _ -> pure GdEnd -- like a wildcard
- BangPat _ p@(L l p') ->
+ BangPat _ p@(L l p') -> do
-- Add the bang in front of the list, because it will happen before any
-- nested stuff.
+ in_gen <- inGeneratedCodeDs
+ -- A bang inserted by -XStrict (decideBangHood) has no SrcInfo: it is
+ -- divergence-checked but never reported as redundant (#27323).
+ let pm_loc | in_gen = Nothing
+ | otherwise = Just (SrcInfo (L (locA l) (ppr p')))
consGrdDag (PmBang x pm_loc) <$> desugarLPat x p
- where pm_loc = Just (SrcInfo (L (locA l) (ppr p')))
-- (x@pat) ==> Desugar pat with x as match var and handle impedance
-- mismatch with incoming match var
@@ -311,11 +315,11 @@ desugarPatV pat = do
pure (x, grds)
desugarLPat :: Id -> LPat GhcTc -> DsM GrdDag
-desugarLPat x = desugarPat x . unLoc
+desugarLPat x (L loc pat) = putSrcSpanDsA loc (desugarPat x pat)
-- | 'desugarLPat', but also select and return a new match var.
desugarLPatV :: LPat GhcTc -> DsM (Id, GrdDag)
-desugarLPatV = desugarPatV . unLoc
+desugarLPatV (L loc pat) = putSrcSpanDsA loc (desugarPatV pat)
-- | @desugarListPat _ x [p1, ..., pn]@ is basically
-- @desugarConPatOut _ x $(mkListConPatOuts [p1, ..., pn]>@ without ever
@@ -374,11 +378,11 @@ desugarConPatOut x con univ_tys ex_tvs dicts = \case
-- tracePm "ConPatOut" (ppr x $$ ppr con $$ ppr arg_ids)
pure (con_grd `consGrdDag` arg_grds)
-desugarPatBind :: SrcSpan -> Id -> Pat GhcTc -> DsM (PmPatBind Pre)
+desugarPatBind :: SrcSpan -> Id -> LPat GhcTc -> DsM (PmPatBind Pre)
-- See 'GrdPatBind' for how this simply repurposes GrdGRHS.
-- See Note [Suppress warnings in PMC desugaring]
desugarPatBind loc var pat = discardWarningsDs $
- PmPatBind . flip PmGRHS (SrcInfo (L loc (ppr pat))) <$> desugarPat var pat
+ PmPatBind . flip PmGRHS (SrcInfo (L loc (ppr pat))) <$> desugarLPat var pat
desugarEmptyCase :: Id -> DsM PmEmptyCase
desugarEmptyCase var = pure PmEmptyCase { pe_var = var }
@@ -633,21 +637,16 @@ Consider (#21761)
idV :: Void -> Void
idV v = v
-Without -XStrict, we would not warn here. But with -XStrict, there is an
-implicit bang on `v` and we should give an inaccessible warning for the RHS.
-The way we account for that is by calling `decideBangHood` on patterns
-in a `Match`, which inserts the implicit bang.
+With -XStrict, there is an implicit bang pattern on `v` as per
+Note [decideBangHood], so the RHS is inaccessible and we must report it as such.
-Making the call here actually seems redundant with the call to `decideBangHood`
-in `GHC.HsToCore.Match.matchWrapper`, which does it *after* it calls the
-pattern-match checker on the Match's patterns. It would be great if we could expect
-`matchWrapper` to pass the bang-adorned `Match` to the pattern-match checker,
-but sadly then we get worse warning messages which would print `idV` as if the
-user *had* written a bang:
+The natural way to achieve this is described in #27677: insert the bang using
+'ExpansionPat' (see Note [Handling overloaded and rebindable constructs] in
+GHC.Rename.Expr). Then the pattern-match checker sees the bang pattern, while
+warning messages display the user-written pattern.
- Pattern match has inaccessible right hand side
-- In an equation for ‘idV’: idV v = ...
-+ In an equation for ‘idV’: idV !v = ...
-
-So we live with the duplication.
+This approach hasn't been implemented yet, so for the time being 'desugarMatches'
+calls 'decideBangHood' itself, duplicating the call in 'GHC.HsToCore.Match.matchWrapper'.
+'decideBangHood' gives the bangs it inserts a generated span, so that they are
+never reported as redundant (see Note [Dead bang patterns] in GHC.HsToCore.Pmc.Check).
-}
=====================================
compiler/GHC/HsToCore/Types.hs
=====================================
@@ -11,7 +11,7 @@ module GHC.HsToCore.Types (
DsMetaEnv, DsMetaVal(..), CompleteMatches
) where
-import GHC.Prelude (Int)
+import GHC.Prelude (Bool, Int)
import Data.IORef
@@ -125,6 +125,7 @@ data DsLclEnv
-- ^ See Note [Desugaring non-canonical evidence]
-- This field collects all un-specialisable evidence variables in scope.
-- Nothing <=> don't collect this info (used for the LHS of Rules)
+ , dsl_in_generated_code :: Bool -- ^ Are we desugaring compiler-generated code?
}
-- Inside [| |] brackets, the desugarer looks
=====================================
compiler/GHC/HsToCore/Utils.hs
=====================================
@@ -72,6 +72,7 @@ import GHC.Unit.Module
import GHC.Builtin.KnownKeys
import GHC.Utils.Outputable
import GHC.Utils.Panic
+import GHC.Rename.Utils (wrapGenSpan')
import GHC.Types.SrcLoc
import GHC.Types.Tickish
import GHC.Utils.Misc
@@ -1024,8 +1025,9 @@ Specifically:
-}
--- | Use -XStrict to add a ! or remove a ~
--- See Note [decideBangHood]
+-- | Use -XStrict to add a ! or remove a ~, as per Note [decideBangHood].
+--
+-- The inserted bang is compiler-generated: see Note [Desugaring -XStrict matches in Pmc].
decideBangHood :: DynFlags
-> LPat GhcTc -- ^ Original pattern
-> LPat GhcTc -- Pattern with bang if necessary
@@ -1040,7 +1042,7 @@ decideBangHood dflags lpat
ParPat x p -> L l (ParPat x (go p))
LazyPat _ lp' -> lp'
BangPat _ _ -> lp
- _ -> L l (BangPat noExtField lp)
+ _ -> wrapGenSpan' (locA l) (BangPat noExtField lp)
isTrueLHsExpr :: LHsExpr GhcTc -> Maybe (CoreExpr -> DsM CoreExpr)
=====================================
compiler/GHC/Parser.y
=====================================
@@ -1355,10 +1355,10 @@ ty_decl :: { LTyClDecl GhcPs }
-- infix type constructors to be declared
{% do { let { (tdcolon, tequal) = fst $ unLoc $4 }
; let { tvbar = fst $ unLoc $5 }
- ; let { (twhere, (toc, tdd, tcc)) = fst $ unLoc $6 }
+ ; let { (twhere, tdd) = fst $ unLoc $6 }
; mkFamDecl (comb5 $1 $3 $4 $5 $6) (snd $ unLoc $6) TopLevel $3
(snd $ unLoc $4) (snd $ unLoc $5)
- (AnnFamilyDecl [] [] (epTok $1) noAnn (epTok $2) tdcolon tequal tvbar twhere toc tdd tcc) }}
+ (AnnFamilyDecl [] [] (epTok $1) noAnn (epTok $2) tdcolon tequal tvbar twhere tdd ) }}
-- ordinary data type or newtype declaration
| type_data_or_newtype capi_ctype tycl_hdr constrs maybe_derivings
@@ -1391,7 +1391,7 @@ ty_decl :: { LTyClDecl GhcPs }
{% do { let { tdcolon = fst $ unLoc $4 }
; mkFamDecl (comb4 $1 $2 $3 $4) (DataFamily noExtField) TopLevel $3
(snd $ unLoc $4) Nothing
- (AnnFamilyDecl [] [] noAnn (epTok $1) (epTok $2) tdcolon noAnn noAnn noAnn noAnn noAnn noAnn) }}
+ (AnnFamilyDecl [] [] noAnn (epTok $1) (epTok $2) tdcolon noAnn noAnn noAnn noAnn) }}
-- standalone kind signature
standalone_kind_sig :: { LStandaloneKindSig GhcPs }
@@ -1435,8 +1435,8 @@ expModifiers1 :: { forall b. DisambECP b => PV (Located [LHsModifierOf (LocatedA
inst_decl :: { LInstDecl GhcPs }
: 'instance' maybe_warning_pragma overlap_pragma inst_type where_inst
{% do { decls <- cvBindsAndSigs (snd $ unLoc $5)
- ; let (twhere, (openc, closec, semis)) = fst $ unLoc $5
- ; let anns = AnnClsInstDecl (epTok $1) twhere openc semis closec
+ ; let (twhere, ann_list) = fst $ unLoc $5
+ ; let anns = AnnClsInstDecl (epTok $1) twhere ann_list
; let cid = ClsInstDecl
{ cid_ext = ($2, anns)
, cid_poly_ty = $4
@@ -1522,20 +1522,20 @@ inj_varids :: { Located [LocatedN RdrName] }
-- Closed type families
-where_type_family :: { Located ((EpToken "where", (EpToken "{", EpToken "..", EpToken "}")),FamilyInfo GhcPs) }
+where_type_family :: { Located ((EpToken "where", EpToken ".."),FamilyInfo GhcPs) }
: {- empty -} { noLoc (noAnn,OpenTypeFamily noExtField) }
| 'where' ty_fam_inst_eqn_list
- { sLL $1 $> ((epTok $1,(fst $ unLoc $2))
- , ClosedTypeFamily noExtField (fmap reverse $ snd $ unLoc $2)) }
+ { sLL $1 $> ((epTok $1, (snd $ fst $ unLoc $2))
+ , ClosedTypeFamily (fst $ fst $ unLoc $2) (fmap reverse $ snd $ unLoc $2)) }
-ty_fam_inst_eqn_list :: { Located ((EpToken "{", EpToken "..", EpToken "}"),Maybe [LTyFamInstEqn GhcPs]) }
- : '{' ty_fam_inst_eqns '}' { sLL $1 $> ((epTok $1,noAnn, epTok $3)
+ty_fam_inst_eqn_list :: { Located ((AnnList, EpToken ".."),Maybe [LTyFamInstEqn GhcPs]) }
+ : '{' ty_fam_inst_eqns '}' { sLL $1 $> ((AnnList AnnListBraces (ListBraces (epTok $1) (epTok $3)) [], noAnn)
,Just (unLoc $2)) }
| vocurly ty_fam_inst_eqns close { let (L loc _) = $2 in
- L loc (noAnn,Just (unLoc $2)) }
- | '{' '..' '}' { sLL $1 $> ((epTok $1,epTok $2 ,epTok $3),Nothing) }
+ L loc ((AnnList (AnnListLayout (glR $1)) ListNone [], noAnn),Just (unLoc $2)) }
+ | '{' '..' '}' { sLL $1 $> ((AnnList AnnListBraces (ListBraces (epTok $1) (epTok $3)) [], epTok $2), Nothing) }
| vocurly '..' close { let (L loc _) = $2 in
- L loc ((noAnn,epTok $2, noAnn),Nothing) }
+ L loc ((AnnList (AnnListLayout (glR $1)) ListNone [], epTok $2),Nothing) }
ty_fam_inst_eqns :: { Located [LTyFamInstEqn GhcPs] }
: ty_fam_inst_eqns ';' ty_fam_inst_eqn
@@ -1580,7 +1580,7 @@ at_decl_cls :: { LHsDecl GhcPs }
{% do { let { tdcolon = fst $ unLoc $4 }
; liftM mkTyClD (mkFamDecl (comb3 $1 $3 $4) (DataFamily noExtField) NotTopLevel $3
(snd $ unLoc $4) Nothing
- (AnnFamilyDecl [] [] noAnn (epTok $1) $2 tdcolon noAnn noAnn noAnn noAnn noAnn noAnn)) }}
+ (AnnFamilyDecl [] [] noAnn (epTok $1) $2 tdcolon noAnn noAnn noAnn noAnn)) }}
-- type family declarations, with optional 'family' keyword
-- (can't use opt_instance because you get shift/reduce errors
@@ -1590,14 +1590,14 @@ at_decl_cls :: { LHsDecl GhcPs }
(mkFamDecl (comb3 $1 $2 $3) (OpenTypeFamily noExtField) NotTopLevel $2
(fst . snd $ unLoc $3)
(snd . snd $ unLoc $3)
- (AnnFamilyDecl [] [] (epTok $1) noAnn noAnn tdcolon tequal tvbar noAnn noAnn noAnn noAnn)) }}
+ (AnnFamilyDecl [] [] (epTok $1) noAnn noAnn tdcolon tequal tvbar noAnn noAnn)) }}
| 'type' 'family' type opt_at_kind_inj_sig
{% do { let { (tdcolon, tequal, tvbar) = fst $ unLoc $4 }
; liftM mkTyClD
(mkFamDecl (comb3 $1 $3 $4) (OpenTypeFamily noExtField) NotTopLevel $3
(fst . snd $ unLoc $4)
(snd . snd $ unLoc $4)
- (AnnFamilyDecl [] [] (epTok $1) noAnn (epTok $2) tdcolon tequal tvbar noAnn noAnn noAnn noAnn)) }}
+ (AnnFamilyDecl [] [] (epTok $1) noAnn (epTok $2) tdcolon tequal tvbar noAnn noAnn)) }}
-- default type instances, with optional 'instance' keyword
| 'type' ty_fam_inst_eqn
{% liftM mkInstD (mkTyFamInst (comb2 $1 $2) (unLoc $2)
@@ -1896,14 +1896,13 @@ decls_inst :: { Located ([EpToken ";"],OrdList (LHsDecl GhcPs)) } -- Reversed
| {- empty -} { noLoc ([],nilOL) }
decllist_inst
- :: { Located ((EpToken "{", EpToken "}", [EpToken ";"])
- , OrdList (LHsDecl GhcPs)) } -- Reversed
- : '{' decls_inst '}' { sLL $1 $> ((epTok $1,epTok $3,fst $ unLoc $2),snd $ unLoc $2) }
- | vocurly decls_inst close { L (gl $2) ((noAnn,noAnn,fst $ unLoc $2),snd $ unLoc $2) }
+ :: { Located (AnnList, OrdList (LHsDecl GhcPs)) } -- Reversed
+ : '{' decls_inst '}' { sLL $1 $> (AnnList AnnListBraces (ListBraces (epTok $1) (epTok $3)) (fst $ unLoc $2), snd $ unLoc $2) }
+ | vocurly decls_inst close { L (gl $2) (AnnList (AnnListLayout (glR $1)) ListNone (fst $ unLoc $2), snd $ unLoc $2) }
-- Instance body
--
-where_inst :: { Located ((EpToken "where", (EpToken "{", EpToken "}", [EpToken ";"]))
+where_inst :: { Located ((EpToken "where", AnnList)
, OrdList (LHsDecl GhcPs)) } -- Reversed
-- No implicit parameters
-- May have type declarations
=====================================
compiler/GHC/Tc/Gen/App.hs
=====================================
@@ -114,10 +114,11 @@ Note [Instantiation variables are short lived]
* Ordinary unification variables always stand for monotypes; only instantiation
variables can be unified with a polytype (by `qlUnify`).
-* When we start typechecking the arguments of the call, in tcValArgs, we will
- (a) monomorphise any un-filled-in instantiation variables
+* Before we start typechecking the arguments of the call, in tcValArgs, we will
+ (a) Monomorphise any un-filled-in instantiation variables
(see Note [Monomorphise instantiation variables]),
- (b) zonk the argument type to reveal any polytypes before typechecking that
+ This happens in Step 4, at the start of `finishApp`.
+ (b) Zonk the argument type to reveal any polytypes before typechecking that
argument (see calls to `zonkTcType` and "Crucial step" in tcValArg).
See Section 4.3 "Applications and instantiation" of the paper.
@@ -277,39 +278,30 @@ tcApp works on the application chain by:
variables", written using \kappa in the paper.
See Note [Instantiating type variables in QuickLook]
-Now we split into two cases:
+ Note that we take a quick look at the arguments before quick-looking
+ the result type; see Note [QuickLook: arguments before result]
-3. Case NoQL: no Quick Look
+3. In case DoQL, when we are checking, use quickLookResultType to take a
+ quick look at the result type.
- 3.1 Use checkResultTy to connect the the result type.
- Do this /before/ checking the arguments; see
- Note [Unify with expected type before typechecking arguments]
+The next steps are in `finishApp`:
- 3.2 Check the arguments with `tcValArgs`.
+4. In case DoQL:
+ 4.1 Monomorphise any as-yet-ununified instantiation variables (`qlMonoInstArgs`)
+ See Note [Monomorphise instantiation variables]
+ 4.2 Use `zonkTcType` to expose the polymorphism hidden under instantiation
+ variables in `app_res_rho`, and the monomorphic versions of any
+ un-unified instantiation variables.
- 3.3 Use `finishApp` to wrap up.
+5. Use `checkResultTy` to connect the result type.
+ Do this /before/ checking the arguments; see
+ Note [Unify with expected type before typechecking arguments]
-4. Case DoQL: use Quick Look
+6. Check the arguments with `tcValArgs`. Importantly, we must remember to zonk in
+ the EValArg case, to expose polymorphism
- 4.1 Use `quickLookResultType` to take a quick look at the result type,
- when in checking mode. This is the shaded part of APP-Downarrow
- in Fig 4. It also implements the key part of
- Note [Unify with expected type before typechecking arguments]
-
- 4.2 Check the arguments with `tcValArgs`. Importantly, this will
- monomorphise all the instantiation variables of the call.
- See Note [Monomorphise instantiation variables].
-
- 4.3 Use `zonkTcType` to expose the polymophism hidden under instantiation
- variables in `app_res_rho`, and the monomorphic versions of any
- un-unified instantiation variables.
-
- 4.4 Use `checkResTy` to do the subsumption check as usual
-
- 4.5 Use `finishApp` to wrap up
-
-The funcion `finishApp` mainly calls `rebuildHsApps` to rebuild the
-application; but it also has a horrile special case for `tagToEnum`.
+7. The function `finishApp` mainly calls `rebuildHsApps` to rebuild the
+ application; but it also has a horrible special case for `tagToEnum`.
Note [Quick Look for particular Ids]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -328,6 +320,53 @@ particular Ids:
so that (f `op`), say, will work OK even if `f` is higher rank.
See Note [Left and right sections] in GHC.Rename.Expr.
+Note [QuickLook: arguments before result]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Generally we try to push the expected result type into the call;
+see Note [Unify with expected type before typechecking arguments].
+But surprisingly we can't do that for QuickLook. (#26599 was a failed
+attempt to suggest this.) Consider
+ h :: (Int->Int) -> Int ids :: [forall a. a->a]
+and the call
+ h (head ids)
+Let's say we instantiate `head :: [a] -> a` with `a:=kappa`.
+We QuickLook at the argument with expected type (Int->Int). We must NOT
+unify kappa:=(Int->Int), because kappa:=forall a. a->a is the only
+solution, and one that we will find if we look at the argument first.
+
+TL;DR: we must do `quickLookArg` on all arguments before doing `quickLookResultType`
+on the result type.
+
+Remember: `quickLookResultType` is really anticipating a /subsumption/ test, not
+an equality test. Doing `qlUnify` on the result type (always a rho-type) is
+in general wrong if there is an un-guarded kappa in the result type. It's wrong
+UNLESS we have already gotten all the info about `kappa` (from the
+arguments) that we are going to get. That's why we QuickLook the arguments first.
+
+This is a bit sad, as #26599 shows. Consider
+
+ woo :: (x, [forall a. a->a])
+ bar1 = snd woo
+ bar2 = snd (id woo)
+
+For `bar1` we instantiate `snd` at [a:=k1,b:=k2]. Then we QL on the argument `woo`
+(instantiating with `x:=k3`). Since the result type is guarded we qlUnify
+ (k3,forall a.a->a) ~ (k1,k2)
+and thus succeed in discovering k2:=forall a.a->a, as desired.
+
+But for `bar2` we fail. When quick-looking (id woo) we instantiate `id` with [a:=k],
+and quick-look the argument `woo` with expected type `k`. That's not guarded,
+so we get no information. Adding the `id` call makes it un-typeable. Boo.
+
+This is a bit tricky.
+* We QuickLook the arguments (tcInstFun)
+ THEN QuickLook the result type (quickLookResultType).
+ See this Note
+* and then...
+* We typecheck the result type (checkResultTy)
+ THEN typecheck the arguments (tcValArgs)
+ see Note [Unify with expected type before typechecking arguments]
+
Note [Unify with expected type before typechecking arguments]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider this (#19364)
@@ -353,7 +392,7 @@ Unify result type /before/ typechecking the args
Actual: String
• In the first argument of ‘Pair’, namely ‘"yes"’
-The latter is much better. That is why we call `checkResultTy` before tcValArgs.
+The latter is much better. That is why we call `checkResultTy` before `tcValArgs`.
-}
--------------------
@@ -365,18 +404,18 @@ tcApp :: HsExpr GhcRn -- ^ The whole application (For error messages)
-- See Note [tcApp: typechecking applications]
-- See Note [splitHsApps] in GHC.Tc.Head
tcApp rn_expr rn_fun rn_args exp_res_ty
- = do { fun_lspan <- getFunSrcSpan rn_args
+ = do { do_ql <- wantQuickLook rn_fun
+ ; fun_lspan <- getFunSrcSpan rn_args
; traceTc "tcApp {" $
vcat [ text "rn_fun:" <+> ppr rn_fun
, text "fun_lspan:" <+> ppr fun_lspan
, text "rn_args:" <+> ppr rn_args ]
- ; let rn_head = (rn_fun, fun_lspan)
-- Step 1: Infer the type of `fun`, the head of the application
+ ; let rn_head = (rn_fun, fun_lspan)
; (tc_fun, fun_sigma) <- tcInferAppHead rn_head
- ; let tc_head = (tc_fun, fun_lspan)
- -- inst_final: top-instantiate the result type of the application,
+ ; let -- inst_final: top-instantiate the result type of the application,
-- EXCEPT if we are trying to infer a sigma-type
inst_final = case exp_res_ty of
Check {} -> True
@@ -386,75 +425,73 @@ tcApp rn_expr rn_fun rn_args exp_res_ty
IIF_DeepRho -> True
IIF_Sigma -> False
- -- Step 2: Instantiate the function type (taking a quick look at args)
- -- See Note [Quick Look for particular Ids]
- ; do_ql <- wantQuickLook rn_fun
-
; traceTc "tcApp:inferAppHead" $
vcat [ text "tc_fun:" <+> ppr tc_fun
, text "fun_sigma:" <+> ppr fun_sigma
, text "do_ql:" <+> ppr do_ql]
- ; (inst_args, app_res_rho)
- <- tcInstFun do_ql inst_final rn_head tc_fun fun_sigma rn_args
- -- See (TCAPP1) and (TCAPP2) in
- -- Note [tcApp: typechecking applications]
-
- ; case do_ql of
- NoQL -> do { traceTc "tcApp:NoQL" (ppr rn_fun $$ ppr app_res_rho)
-
- -- Step 3.1: subsumption check against expected result type
- -- See Note [Unify with expected type before typechecking arguments]
- ; res_wrap <- checkResultTy rn_expr tc_head inst_args
- app_res_rho exp_res_ty
- -- Step 3.2: typecheck the arguments
- ; tc_args <- tcValArgs NoQL rn_head inst_args
-
- -- Step 3.3: wrap up
- ; finishApp tc_fun tc_args app_res_rho res_wrap }
-
- DoQL -> do { traceTc "tcApp:DoQL" (ppr rn_fun $$ ppr app_res_rho)
-
- -- Step 4.1: Take a quick look at the result type
- ; quickLookResultType app_res_rho exp_res_ty
-
- -- Step 4.2: typecheck the arguments, and monomorphise
- -- any un-unified instantiation variables
- ; tc_args <- tcValArgs DoQL rn_head inst_args
-
- -- Step 4.3: zonk to expose the polymorphism hidden under
- -- QuickLook instantiation variables in `app_res_rho`
- ; app_res_rho <- liftZonkM $ zonkTcType app_res_rho
-
- -- Step 4.4: subsumption check against the expected type
- ; res_wrap <- checkResultTy rn_expr tc_head inst_args
- app_res_rho exp_res_ty
- -- Step 4.5: wrap up
- ; finishApp tc_fun tc_args app_res_rho res_wrap } }
-
-quickLookResultType :: TcRhoType -> ExpRhoType -> TcM ()
--- This function implements the shaded bit of rule APP-Downarrow in
--- Fig 5 of the QL paper: "A quick look at impredicativity" (ICFP'20).
-quickLookResultType app_res_rho (Check exp_rho) = qlUnify app_res_rho exp_rho
-quickLookResultType _ _ = return ()
-finishApp :: HsExpr GhcTc -> [HsExprArg 'TcpTc]
- -> TcRhoType -> HsWrapper
+ -- Step 2: Instantiate the function type (taking a quick look at args)
+ -- See Note [Quick Look for particular Ids]
+ ; (inst_args, app_res_rho) <- tcInstFun do_ql inst_final rn_head tc_fun fun_sigma rn_args
+
+ ; -- Step 3: Take a quick look at the result type
+ -- See Note [QuickLook: arguments before result]
+ case (do_ql, exp_res_ty) of
+ (DoQL, Check exp_rho) -> quickLookResultType app_res_rho exp_rho
+ _ -> return ()
+
+ ; finishApp do_ql rn_expr fun_lspan rn_fun tc_fun
+ inst_args app_res_rho exp_res_ty }
+
+finishApp :: QLFlag
+ -> HsExpr GhcRn -- The whole application
+ -> SrcSpan -- Span for the /head/ of the application
+ -> HsExpr GhcRn -- The head of the application (renamed)
+ -> HsExpr GhcTc -- The head of the application (typechecked)
+ -> [HsExprArg 'TcpInst] -- Arguments
+ -> TcRhoType -> ExpRhoType
-> TcM (HsExpr GhcTc)
--- Do final checks and wrap up the result
-finishApp tc_fun tc_args app_res_rho res_wrap
- = do {
- -- Reconstruct, with a horrible special case for tagToEnum#.
- res_expr <- if isTagToEnum tc_fun
+-- Instantiation and Quick Look are done. Now do typechecking,
+-- of both the result type and the arguments, before rebuilding.
+finishApp do_ql rn_expr fun_loc rn_fun tc_fun inst_args
+ app_res_rho exp_res_ty
+ = do { -- Step 4.1: monomorphise un-unified QuickLook instantiation variables
+ -- Step 4.2: zonk app_res_rho to expose the polymorphism hidden under
+ -- instantiation variables in `app_res_rho`
+ app_res_rho <- case do_ql of
+ NoQL -> return app_res_rho
+ DoQL -> liftZonkM $
+ do { qlMonoInstArgs inst_args
+ ; zonkTcType app_res_rho }
+
+ -- Step 5: subsumption check against the expected type
+ -- See Note [Unify with expected type before typechecking arguments]
+ ; res_wrap <- checkResultTy rn_expr (tc_fun, fun_loc) inst_args
+ app_res_rho exp_res_ty
+
+ -- Step 6: Typecheck the arguments
+ ; tc_args <- tcValArgs do_ql (rn_fun, fun_loc) inst_args
+
+ -- Step 7: Horrible special case for tagToEnum#.
+ ; res_expr <- if isTagToEnum tc_fun
then tcTagToEnum tc_fun tc_args app_res_rho
else return (rebuildHsApps tc_fun tc_args)
+
; traceTc "End tcApp }" (ppr tc_fun)
; return (mkHsWrap res_wrap res_expr) }
+quickLookResultType :: TcRhoType -> TcRhoType -> TcM ()
+-- This function implements the shaded bit of rule APP-Downarrow in
+-- Fig 5 of the QL paper: "A quick look at impredicativity" (ICFP'20).
+-- See Note [QuickLook: arguments before result]
+quickLookResultType app_res_rho exp_res_rho
+ = qlUnify app_res_rho exp_res_rho
+
-- | Connect up the inferred type of an application with the expected type.
-- This is usually just a unification, but with deep subsumption there is more to do.
checkResultTy :: HsExpr GhcRn
-> (HsExpr GhcTc, SrcSpan) -- Head
- -> [HsExprArg p] -- Arguments, just error messages
+ -> [HsExprArg p] -- Arguments, just for error messages
-> TcRhoType -- Inferred type of the application; zonked to
-- expose foralls, but maybe not /deeply/ instantiated
-> ExpRhoType -- Expected type; this is deeply skolemised
@@ -476,13 +513,10 @@ checkResultTy rn_expr (tc_fun, fun_loc) inst_args app_res_rho res_ty
----------------
tcValArgs :: QLFlag
- -> (HsExpr GhcRn, SrcSpan) -- Head of the application chain (used only for error message generation)
+ -> (HsExpr GhcRn, SrcSpan) -- Head of the application chain
+ -- (used only for error message generation)
-> [HsExprArg 'TcpInst]
-> TcM [HsExprArg 'TcpTc]
--- Importantly, tcValArgs works left-to-right, so that by the time we
--- encounter an argument, we have monomorphised all the instantiation
--- variables that its type contains. All that is left to do is an ordinary
--- zonkTcType. See Note [Monomorphise instantiation variables].
tcValArgs do_ql rn_head args = go do_ql 0 args
where
go _ _ [] = return []
@@ -505,16 +539,15 @@ tcValArg :: QLFlag -- ^ Are we typechecking with Quick Look tur
-> (HsExpr GhcRn, SrcSpan) -- ^ Head of the application chain (used only for error message generation)
-> HsExprArg 'TcpInst -- ^ Actual argument
-> TcM (HsExprArg 'TcpTc) -- ^ Resulting argument
-tcValArg _ _ _ (EPrag l p) = return (EPrag l (tcExprPrag p))
-tcValArg _ _ _ (ETypeArg l hty ty) = return (ETypeArg l hty ty)
-tcValArg do_ql _ _ (EWrap (EHsWrap w)) = do { whenQL do_ql $ qlMonoHsWrapper w
- ; return (EWrap (EHsWrap w)) }
- -- qlMonoHsWrapper: see Note [Monomorphise instantiation variables]
-tcValArg _ _ _ (EWrap ew) = return (EWrap ew)
-
-tcValArg do_ql pos rn_fun_head (EValArg { ea_loc_span = lspan
- , ea_arg = larg@(L arg_loc arg)
- , ea_arg_ty = sc_arg_ty })
+tcValArg _ _ _ (EPrag l p) = return (EPrag l (tcExprPrag p))
+tcValArg _ _ _ (ETypeArg l hty ty) = return (ETypeArg l hty ty)
+tcValArg _ _ _ (EWrap (EHsWrap w)) = return (EWrap (EHsWrap w))
+tcValArg _ _ _ (EWrap ew) = return (EWrap ew)
+
+tcValArg do_ql pos rn_fun_head
+ (EValArg { ea_loc_span = lspan
+ , ea_arg = larg@(L arg_loc arg)
+ , ea_arg_ty = sc_arg_ty })
= addArgCtxt pos rn_fun_head larg $
do { -- Crucial step: expose QL results before checking exp_arg_ty
-- So far as the paper is concerned, this step applies
@@ -546,17 +579,17 @@ tcValArg do_ql pos rn_fun_head (EValArg { ea_loc_span = lspan
, ea_arg = L arg_loc arg'
, ea_arg_ty = noExtField }) }
-tcValArg _ pos rn_fun_head (EValArgQL {
- eaql_wanted = wanted
- , eaql_loc_span = lspan
- , eaql_arg_ty = sc_arg_ty
- , eaql_larg = larg@(L arg_loc rn_expr)
- , eaql_tc_fun = tc_arg_head@(tc_fun,arg_head_loc)
- , eaql_rn_fun = rn_arg_head
- , eaql_fun_ue = head_ue
- , eaql_args = inst_args
- , eaql_encl = arg_influences_enclosing_call
- , eaql_res_rho = app_res_rho })
+tcValArg _ pos rn_fun_head
+ (EValArgQL { eaql_wanted = wanted
+ , eaql_loc_span = lspan
+ , eaql_arg_ty = sc_arg_ty
+ , eaql_larg = larg@(L arg_loc rn_expr)
+ , eaql_rn_fun = rn_fun
+ , eaql_tc_fun = tc_arg_head@(tc_fun,arg_head_loc)
+ , eaql_fun_ue = head_ue
+ , eaql_args = inst_args
+ , eaql_encl = arg_influences_enclosing_call
+ , eaql_res_rho = app_res_rho })
= addArgCtxt pos rn_fun_head larg $
do { -- Expose QL results to tcSkolemise, as in EValArg case
Scaled mult exp_arg_ty <- liftZonkM $ zonkScaledTcType sc_arg_ty
@@ -582,14 +615,11 @@ tcValArg _ pos rn_fun_head (EValArgQL {
-- Unify with context if we have not already done so
-- See (QLA4) in Note [Quick Look at value arguments]
- ; unless arg_influences_enclosing_call $ -- Don't repeat
- qlUnify app_res_rho exp_arg_rho -- the qlUnify
+ ; unless arg_influences_enclosing_call $ -- Don't repeat
+ qlUnify app_res_rho exp_arg_rho -- the qlUnify
- ; tc_args <- tcValArgs DoQL (rn_arg_head, arg_head_loc) inst_args
- ; app_res_rho <- liftZonkM $ zonkTcType app_res_rho
- ; res_wrap <- checkResultTy rn_expr tc_arg_head inst_args
- app_res_rho (mkCheckExpType exp_arg_rho)
- ; finishApp tc_fun tc_args app_res_rho res_wrap }
+ ; finishApp DoQL rn_expr arg_head_loc rn_fun tc_fun inst_args app_res_rho
+ (mkCheckExpType exp_arg_rho) }
; traceTc "tcEValArgQL }" $
vcat [ text "app_res_rho:" <+> ppr app_res_rho ]
@@ -606,6 +636,13 @@ wantQuickLook (HsVar _ (L _ (WithUserRdr _ f)))
wantQuickLook _ = do { impred <- xoptM LangExt.ImpredicativeTypes
; if impred then return DoQL else return NoQL }
+skipQuickLook :: HsExprLoc -> LHsExpr GhcRn -> Scaled TcRhoType
+ -> TcM (HsExprArg 'TcpInst)
+skipQuickLook loc larg arg_ty
+ = return (EValArg { ea_loc_span = loc
+ , ea_arg = larg
+ , ea_arg_ty = arg_ty })
+
quickLookKeys :: [Unique]
-- See Note [Quick Look for particular Ids]
quickLookKeys = [dollarIdKey, leftSectionKey, rightSectionKey]
@@ -1860,17 +1897,6 @@ quickLookArg DoQL pos app_lspan fun_and_lspan larg orig_arg_ty
then skipQuickLook app_lspan larg orig_arg_ty
else quickLookArg1 pos app_lspan fun_and_lspan larg orig_arg_ty }
-skipQuickLook :: HsExprLoc -> LHsExpr GhcRn -> Scaled TcRhoType
- -> TcM (HsExprArg 'TcpInst)
-skipQuickLook app_lspan larg arg_ty
- = return (EValArg { ea_loc_span = app_lspan
- , ea_arg = larg
- , ea_arg_ty = arg_ty })
-
-whenQL :: QLFlag -> ZonkM () -> TcM ()
-whenQL DoQL thing_inside = liftZonkM thing_inside
-whenQL NoQL _ = return ()
-
qlArgHasRhoType :: TcType -> TcM Bool
-- `qlArgHasRhoType` checks that the expected argument type in rule
-- App-lightning-bolt (Fig 5 in the paper) is indeed a rho-type.
@@ -1959,7 +1985,7 @@ quickLookArg1 pos app_lspan rn_head larg@(L _ arg) sc_arg_ty@(Scaled _ orig_arg_
<- captureConstraints $
tcInstFun do_ql True (rn_fun_arg, fun_lspan_arg) tc_fun_arg_head fun_sigma_arg_head rn_args
-- We must capture type-class and equality constraints here, but
- -- not usage information. See (QLA6) in Note [Quick Look at
+ -- not usage constraints. See (QLA6) in Note [Quick Look at
-- value arguments]
; traceTc "quickLookArg 2" $
@@ -1969,13 +1995,16 @@ quickLookArg1 pos app_lspan rn_head larg@(L _ arg) sc_arg_ty@(Scaled _ orig_arg_
-- Step 3: Check the two other premises of APP-lightning-bolt (Fig 5 in the paper)
-- Namely: (A) is orig_arg_rho is guarded
- -- or: (B) fiv(app_res_rho) = emptyset
+ -- or: (B) fiv(app_res_rho) = emptyset
+ -- then Step 4: do quick-look unification if either (A) or (B) hold
+ --
+ -- For (B) see Note [The fiv test in quickLookArg]
-- This tells us if the quick look at the argument yields information that
-- influences the enclosing function call
- -- NB: guardedness is computed based on the original,
- -- unzonked orig_arg_rho, so that we deliberately do
- -- not exploit guardedness that emerges a result of QL on earlier args
- -- We must do the anyFreeKappa test /after/ tcInstFun; see (QLA3).
+ -- NB: `isGuardedTy` is computed based on the original,
+ -- unzonked orig_arg_rho, so that we deliberately do not exploit
+ -- guardedness that emerges a result of QL on earlier args
+ -- In contrast, we must do the `anyFreeKappa` test /after/ tcInstFun; see (QLA3).
; arg_influences_enclosing_call
<- if isGuardedTy orig_arg_rho
then return True
@@ -1983,6 +2012,7 @@ quickLookArg1 pos app_lspan rn_head larg@(L _ arg) sc_arg_ty@(Scaled _ orig_arg_
-- For (B) see Note [The fiv test in quickLookArg]
-- Step 4: do quick-look unification if either (A) or (B) hold
+ -- This is part of APP-lightning-bolt (Fig 5 in the paper)
-- NB: orig_arg_rho may not be zonked, but that's ok
; when arg_influences_enclosing_call $
qlUnify app_res_rho orig_arg_rho
@@ -2000,7 +2030,6 @@ quickLookArg1 pos app_lspan rn_head larg@(L _ arg) sc_arg_ty@(Scaled _ orig_arg_
, eaql_encl = arg_influences_enclosing_call
, eaql_res_rho = app_res_rho }) }}}
-
{- *********************************************************************
* *
Folding over instantiation variables
@@ -2014,20 +2043,16 @@ When we are done with Quick Look on a call, we must turn any un-unified
lower-case 'theta' (a mono-substitution) in the APP-DOWN rule of Fig 5 of the
Quick Look paper.
-We so this by look at the arguments, left to right, monomorphising the free
-instantiation variables of the /type/ arguments of the call. Those type
-arguments appear (only) in
+We do this in `qlMonoInstArgs` by looking at the arguments, monomorphising
+the free instantiation variables of the /type/ arguments of the call. Those
+type arguments appear (only) in
* the `WpTyApp` components of
* the `HsWrapper` of
* a `EWrap` argument
-See `qlMonoHsWrapper`.
-
-By going left to right, we are sure to monomorphise instantiation variables
-before we encounter them in an argument type (in `tcValArg`).
All instantiation variables for a call will be reachable from the type(s)
at which the function is instantiated -- i.e. those WpTyApps. Even instantiation
-variables allocoated by tcInstFun itself, such as in the IRESULT rule, end up
+variables allocated by tcInstFun itself, such as in the IRESULT rule, end up
connected to the original type(s) at which the function is instantiated.
To monomorphise the free QL instantiation variables of a type, we use
@@ -2048,6 +2073,16 @@ Wrinkles:
we want to monomrphise it. Hence the do_hole in `foldQLInstTyVars`
-}
+
+qlMonoInstArgs :: [HsExprArg 'TcpInst] -> ZonkM ()
+-- See Note [Monomorphise instantiation variables]
+qlMonoInstArgs args = mapM_ qlMonoInstArg args
+
+qlMonoInstArg :: HsExprArg 'TcpInst -> ZonkM ()
+-- See Note [Monomorphise instantiation variables]
+qlMonoInstArg (EWrap (EHsWrap w)) = qlMonoHsWrapper w
+qlMonoInstArg _ = return ()
+
qlMonoHsWrapper :: HsWrapper -> ZonkM ()
-- See Note [Monomorphise instantiation variables]
qlMonoHsWrapper (WpCompose w1 w2) = qlMonoHsWrapper w1 >> qlMonoHsWrapper w2
@@ -2108,13 +2143,14 @@ We will instantiate Just with kappa, say, and then call
quickLookArg1 False {kappa} (ids ++ ids) kappa
The call to tcInstFun will return with app_res_rho = [forall a. a->a]
which has no free instantiation variables, so we can QL-unify
- kappa ~ [Forall a. a->a]
+ kappa ~ [forall a. a->a]
-}
anyFreeKappa :: TcType -> TcM Bool
-- True if there is a free instantiation variable
-- in the argument type, after zonking
-- See Note [The fiv test in quickLookArg]
+-- The function is monadic; it does not require a zonked type as input
anyFreeKappa ty = unTcMBool (foldQLInstVars go_tv ty)
where
go_tv tv = TCMB $ do { info <- readMetaTyVar tv
=====================================
compiler/GHC/ThToHs.hs
=====================================
@@ -434,7 +434,7 @@ cvtDec (ClosedTypeFamilyD head eqns)
= do { (tc', tyvars', result', injectivity') <- cvt_tyfam_head head
; eqns' <- mapM cvtTySynEqn eqns
; returnJustLA $ TyClD noExtField $ FamDecl noExtField $
- FamilyDecl noAnn (ClosedTypeFamily noExtField (Just eqns')) TopLevel tc' tyvars' Prefix
+ FamilyDecl noAnn (ClosedTypeFamily noAnn (Just eqns')) TopLevel tc' tyvars' Prefix
result' injectivity' }
cvtDec (TH.RoleAnnotD tc roles)
=====================================
testsuite/tests/ghci.debugger/scripts/T14628.stderr
=====================================
@@ -1,9 +1,9 @@
-<interactive>:4:7: error: [GHC-25897]
+<interactive>:4:17: error: [GHC-25897]
• Couldn't match type ‘m’ with ‘(,) a0’
- Expected: (a0, ((), Int))
- Actual: m ((), Int)
+ Expected: StateT Int ((,) a0) ()
+ Actual: StateT Int m ()
‘m’ is an interactive-debugger skolem
- • In the second argument of ‘($)’, namely ‘runStateT _result 0’
+ • In the first argument of ‘runStateT’, namely ‘_result’
+ In the second argument of ‘($)’, namely ‘runStateT _result 0’
In the expression: snd $ runStateT _result 0
- In an equation for ‘it’: it = snd $ runStateT _result 0
=====================================
testsuite/tests/haddock/should_compile_flag_haddock/T17544.stderr
=====================================
@@ -926,10 +926,8 @@
(EpaSpan { <no location info> }))
(EpTok
(EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> }))
(EpTok
- (EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> })))
+ (EpaSpan { <no location info> })))
(DataFamily
(NoExtField))
(NotTopLevel)
@@ -1001,9 +999,11 @@
(EpTok (EpaSpan { T17544.hs:23:1-8 }))
(EpTok
(EpaSpan { T17544.hs:23:17-21 }))
- (EpTok (EpaSpan { <no location info> }))
- []
- (EpTok (EpaSpan { <no location info> }))))
+ (AnnList
+ (AnnListLayout
+ (EpaSpan { T17544.hs:24:3 }))
+ (ListNone)
+ [])))
[]
(L
(EpAnn
@@ -1322,10 +1322,8 @@
(EpaSpan { <no location info> }))
(EpTok
(EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> }))
(EpTok
- (EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> })))
+ (EpaSpan { <no location info> })))
(DataFamily
(NoExtField))
(NotTopLevel)
@@ -1397,9 +1395,11 @@
(EpTok (EpaSpan { T17544.hs:29:1-8 }))
(EpTok
(EpaSpan { T17544.hs:29:17-21 }))
- (EpTok (EpaSpan { <no location info> }))
- []
- (EpTok (EpaSpan { <no location info> }))))
+ (AnnList
+ (AnnListLayout
+ (EpaSpan { T17544.hs:30:3 }))
+ (ListNone)
+ [])))
[]
(L
(EpAnn
@@ -1718,10 +1718,8 @@
(EpaSpan { <no location info> }))
(EpTok
(EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> }))
(EpTok
- (EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> })))
+ (EpaSpan { <no location info> })))
(DataFamily
(NoExtField))
(NotTopLevel)
@@ -1793,9 +1791,11 @@
(EpTok (EpaSpan { T17544.hs:35:1-8 }))
(EpTok
(EpaSpan { T17544.hs:35:17-21 }))
- (EpTok (EpaSpan { <no location info> }))
- []
- (EpTok (EpaSpan { <no location info> }))))
+ (AnnList
+ (AnnListLayout
+ (EpaSpan { T17544.hs:36:3 }))
+ (ListNone)
+ [])))
[]
(L
(EpAnn
@@ -2114,10 +2114,8 @@
(EpaSpan { <no location info> }))
(EpTok
(EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> }))
(EpTok
- (EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> })))
+ (EpaSpan { <no location info> })))
(DataFamily
(NoExtField))
(NotTopLevel)
@@ -2189,9 +2187,11 @@
(EpTok (EpaSpan { T17544.hs:41:1-8 }))
(EpTok
(EpaSpan { T17544.hs:41:17-21 }))
- (EpTok (EpaSpan { <no location info> }))
- []
- (EpTok (EpaSpan { <no location info> }))))
+ (AnnList
+ (AnnListLayout
+ (EpaSpan { T17544.hs:42:3 }))
+ (ListNone)
+ [])))
[]
(L
(EpAnn
@@ -2510,10 +2510,8 @@
(EpaSpan { <no location info> }))
(EpTok
(EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> }))
(EpTok
- (EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> })))
+ (EpaSpan { <no location info> })))
(DataFamily
(NoExtField))
(NotTopLevel)
@@ -2585,9 +2583,11 @@
(EpTok (EpaSpan { T17544.hs:47:1-8 }))
(EpTok
(EpaSpan { T17544.hs:47:17-21 }))
- (EpTok (EpaSpan { <no location info> }))
- []
- (EpTok (EpaSpan { <no location info> }))))
+ (AnnList
+ (AnnListLayout
+ (EpaSpan { T17544.hs:48:3 }))
+ (ListNone)
+ [])))
[]
(L
(EpAnn
@@ -2906,10 +2906,8 @@
(EpaSpan { <no location info> }))
(EpTok
(EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> }))
(EpTok
- (EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> })))
+ (EpaSpan { <no location info> })))
(DataFamily
(NoExtField))
(NotTopLevel)
@@ -2981,9 +2979,11 @@
(EpTok (EpaSpan { T17544.hs:53:1-8 }))
(EpTok
(EpaSpan { T17544.hs:53:18-22 }))
- (EpTok (EpaSpan { <no location info> }))
- []
- (EpTok (EpaSpan { <no location info> }))))
+ (AnnList
+ (AnnListLayout
+ (EpaSpan { T17544.hs:54:3 }))
+ (ListNone)
+ [])))
[]
(L
(EpAnn
=====================================
testsuite/tests/parser/should_compile/DumpParsedAst.stderr
=====================================
@@ -359,12 +359,14 @@
(EpaSpan { <no location info> }))
(EpTok
(EpaSpan { DumpParsedAst.hs:10:41-45 }))
- (EpTok (EpaSpan { <no location info> }))
(EpTok
- (EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> })))
+ (EpaSpan { <no location info> })))
(ClosedTypeFamily
- (NoExtField)
+ (AnnList
+ (AnnListLayout
+ (EpaSpan { DumpParsedAst.hs:11:3 }))
+ (ListNone)
+ [])
(Just
[(L
(EpAnn
@@ -1144,12 +1146,14 @@
(EpaSpan { <no location info> }))
(EpTok
(EpaSpan { DumpParsedAst.hs:18:50-54 }))
- (EpTok (EpaSpan { <no location info> }))
(EpTok
- (EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> })))
+ (EpaSpan { <no location info> })))
(ClosedTypeFamily
- (NoExtField)
+ (AnnList
+ (AnnListLayout
+ (EpaSpan { DumpParsedAst.hs:19:3 }))
+ (ListNone)
+ [])
(Just
[(L
(EpAnn
@@ -1543,10 +1547,8 @@
(EpaSpan { <no location info> }))
(EpTok
(EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> }))
(EpTok
- (EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> })))
+ (EpaSpan { <no location info> })))
(DataFamily
(NoExtField))
(TopLevel)
=====================================
testsuite/tests/parser/should_compile/DumpRenamedAst.stderr
=====================================
@@ -306,12 +306,14 @@
(EpaSpan { <no location info> }))
(EpTok
(EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> }))
(EpTok
- (EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> })))
+ (EpaSpan { <no location info> })))
(ClosedTypeFamily
- (NoExtField)
+ (AnnList
+ (AnnListLayout
+ (EpaSpan { DumpRenamedAst.hs:13:3 }))
+ (ListNone)
+ [])
(Just
[(L
(EpAnn
@@ -795,10 +797,8 @@
(EpaSpan { <no location info> }))
(EpTok
(EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> }))
(EpTok
- (EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> })))
+ (EpaSpan { <no location info> })))
(DataFamily
(NoExtField))
(TopLevel)
@@ -1180,12 +1180,14 @@
(EpaSpan { <no location info> }))
(EpTok
(EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> }))
(EpTok
- (EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> })))
+ (EpaSpan { <no location info> })))
(ClosedTypeFamily
- (NoExtField)
+ (AnnList
+ (AnnListLayout
+ (EpaSpan { DumpRenamedAst.hs:26:3 }))
+ (ListNone)
+ [])
(Just
[(L
(EpAnn
@@ -1765,10 +1767,8 @@
(EpaSpan { <no location info> }))
(EpTok
(EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> }))
(EpTok
- (EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> })))
+ (EpaSpan { <no location info> })))
(OpenTypeFamily
(NoExtField))
(NotTopLevel)
=====================================
testsuite/tests/parser/should_compile/KindSigs.stderr
=====================================
@@ -108,12 +108,14 @@
(EpaSpan { <no location info> }))
(EpTok
(EpaSpan { KindSigs.hs:11:19-23 }))
- (EpTok (EpaSpan { <no location info> }))
(EpTok
- (EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> })))
+ (EpaSpan { <no location info> })))
(ClosedTypeFamily
- (NoExtField)
+ (AnnList
+ (AnnListLayout
+ (EpaSpan { KindSigs.hs:12:3 }))
+ (ListNone)
+ [])
(Just
[(L
(EpAnn
=====================================
testsuite/tests/pmcheck/should_compile/T27323.hs
=====================================
@@ -0,0 +1,9 @@
+{-# LANGUAGE MagicHash, Strict #-}
+{-# OPTIONS_GHC -Wredundant-bang-patterns #-}
+
+import GHC.Prim (Int#)
+
+idInt# :: Int# -> Int#
+idInt# x = x
+
+main = pure ()
=====================================
testsuite/tests/pmcheck/should_compile/T27323b.hs
=====================================
@@ -0,0 +1,6 @@
+{-# LANGUAGE Strict, MonoLocalBinds #-}
+{-# OPTIONS_GHC -Wredundant-bang-patterns #-}
+module T27323b where
+
+f :: Int -> Int
+f x = let (a, b) = (x, x) in a + b
=====================================
testsuite/tests/pmcheck/should_compile/all.T
=====================================
@@ -190,4 +190,6 @@ test('T24845', [], compile, [overlapping_incomplete])
test('T22652', [], compile, [overlapping_incomplete])
test('T22652a', [], compile, [overlapping_incomplete])
test('T24867', [], compile_fail, [overlapping_incomplete])
+test('T27323', normal, compile, ['-Wredundant-bang-patterns'])
+test('T27323b', normal, compile, ['-Wredundant-bang-patterns'])
test('T27360', normal, compile, [overlapping_incomplete + '-g3'])
=====================================
testsuite/tests/printer/Test24533.stdout
=====================================
@@ -64,9 +64,10 @@
(EpTok (EpaSpan { Test24533.hs:4:1-8 }))
(EpTok
(EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> }))
- []
- (EpTok (EpaSpan { <no location info> }))))
+ (AnnList
+ (AnnListNoLayout)
+ (ListNone)
+ [])))
[]
(L
(EpAnn
@@ -451,9 +452,11 @@
(EpTok (EpaSpan { Test24533.hs:14:1-8 }))
(EpTok
(EpaSpan { Test24533.hs:14:17-21 }))
- (EpTok (EpaSpan { <no location info> }))
- []
- (EpTok (EpaSpan { <no location info> }))))
+ (AnnList
+ (AnnListLayout
+ (EpaSpan { Test24533.hs:16:3 }))
+ (ListNone)
+ [])))
[]
(L
(EpAnn
@@ -724,9 +727,10 @@
(EpTok (EpaSpan { Test24533.ppr.hs:3:1-8 }))
(EpTok
(EpaSpan { <no location info> }))
- (EpTok (EpaSpan { <no location info> }))
- []
- (EpTok (EpaSpan { <no location info> }))))
+ (AnnList
+ (AnnListNoLayout)
+ (ListNone)
+ [])))
[]
(L
(EpAnn
@@ -1038,9 +1042,11 @@
(EpTok (EpaSpan { Test24533.ppr.hs:5:1-8 }))
(EpTok
(EpaSpan { Test24533.ppr.hs:5:17-21 }))
- (EpTok (EpaSpan { <no location info> }))
- []
- (EpTok (EpaSpan { <no location info> }))))
+ (AnnList
+ (AnnListLayout
+ (EpaSpan { Test24533.ppr.hs:6:3 }))
+ (ListNone)
+ [])))
[]
(L
(EpAnn
=====================================
testsuite/tests/typecheck/should_fail/T22707.stderr
=====================================
@@ -1,11 +1,38 @@
+T22707.hs:6:59: error: [GHC-25897]
+ • Couldn't match expected type ‘i1’
+ with actual type ‘m0
+ GHC.Internal.Types.LiftedRep GHC.Internal.Types.LiftedRep b0’
+ ‘i1’ is a rigid type variable bound by
+ the type signature for:
+ t1 :: forall i2 o i1 a. Cont (i2 -> o) i1 a -> Cont o i2 (a -> i1)
+ at T22707.hs:5:1-47
+ • In the expression: evalCont (t1 c) >>== \ ati1 -> return ati1 xa
+ In the second argument of ‘($)’, namely
+ ‘\ xa -> evalCont (t1 c) >>== \ ati1 -> return ati1 xa’
+ In the second argument of ‘runCont’, namely
+ ‘(ati1tti2 $ \ xa -> evalCont (t1 c) >>== \ ati1 -> return ...)’
+ • Relevant bindings include
+ ati1tti2 :: (a -> i1) -> i2 (bound at T22707.hs:6:16)
+ c :: Cont (i2 -> o) i1 a (bound at T22707.hs:6:4)
+ t1 :: Cont (i2 -> o) i1 a -> Cont o i2 (a -> i1)
+ (bound at T22707.hs:6:1)
+
T22707.hs:6:72: error: [GHC-25897]
- • Couldn't match type ‘i2’ with ‘a -> i1’
+ • Couldn't match type ‘o’
+ with ‘m0
+ GHC.Internal.Types.LiftedRep
+ GHC.Internal.Types.LiftedRep
+ (m0 GHC.Internal.Types.LiftedRep GHC.Internal.Types.LiftedRep b0)’
Expected: Cont
- ((a -> i1) -> m0 (a -> i1) (a -> i1) (m0 (a -> i1) (a -> i1) b0))
+ ((a -> i1)
+ -> m0
+ GHC.Internal.Types.LiftedRep
+ GHC.Internal.Types.LiftedRep
+ (m0 GHC.Internal.Types.LiftedRep GHC.Internal.Types.LiftedRep b0))
i1
a
Actual: Cont (i2 -> o) i1 a
- ‘i2’ is a rigid type variable bound by
+ ‘o’ is a rigid type variable bound by
the type signature for:
t1 :: forall i2 o i1 a. Cont (i2 -> o) i1 a -> Cont o i2 (a -> i1)
at T22707.hs:5:1-47
@@ -13,9 +40,6 @@ T22707.hs:6:72: error: [GHC-25897]
In the first argument of ‘evalCont’, namely ‘(t1 c)’
In the first argument of ‘(>>==)’, namely ‘evalCont (t1 c)’
• Relevant bindings include
- xa :: a (bound at T22707.hs:6:53)
- ati1tti2 :: (a -> m0 (a -> i1) (a -> i1) b0) -> a -> i1
- (bound at T22707.hs:6:16)
c :: Cont (i2 -> o) i1 a (bound at T22707.hs:6:4)
t1 :: Cont (i2 -> o) i1 a -> Cont o i2 (a -> i1)
(bound at T22707.hs:6:1)
=====================================
testsuite/tests/typecheck/should_fail/T25950.stderr
=====================================
@@ -1,9 +1,10 @@
-T25950.hs:6:9: error: [GHC-25897]
+T25950.hs:6:14: error: [GHC-25897]
• Couldn't match expected type ‘a’ with actual type ‘()’
‘a’ is a rigid type variable bound by
the inferred type of fails :: a
at T25950.hs:5:1-15
- • In the expression: id $ ()
+ • In the second argument of ‘($)’, namely ‘()’
+ In the expression: id $ ()
In an equation for ‘fails’: fails = id $ ()
• Relevant bindings include fails :: a (bound at T25950.hs:6:1)
=====================================
testsuite/tests/typecheck/should_fail/T8450.stderr
=====================================
@@ -1,6 +1,6 @@
T8450.hs:8:19: error: [GHC-25897]
• Couldn't match type ‘a’ with ‘Bool’
- Expected: Either Bool ()
+ Expected: Either Bool a
Actual: Either a ()
‘a’ is a rigid type variable bound by
the type signature for:
=====================================
testsuite/tests/warnings/should_compile/Overflow.stderr-ws-64
=====================================
@@ -1,18 +1,18 @@
-
Overflow.hs:8:15: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal 10000000000000000000000000000000 is out of the Int# range -9223372036854775808..9223372036854775807
-Overflow.hs:13:1: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
+Overflow.hs:13:3: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal 100000000000000000000000000 is out of the Int# range -9223372036854775808..9223372036854775807
Overflow.hs:18:5: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal 1000000000000000000000000000000 is out of the Int range -9223372036854775808..9223372036854775807
-Overflow.hs:22:1: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
+Overflow.hs:22:3: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal 100000000000000000000000000000000 is out of the Int range -9223372036854775808..9223372036854775807
Overflow.hs:27:6: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal -1 is out of the Word range 0..18446744073709551615
-Overflow.hs:31:1: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
+Overflow.hs:31:4: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal -1 is out of the Word range 0..18446744073709551615
+
=====================================
testsuite/tests/warnings/should_compile/T13256.stderr-ws-64
=====================================
@@ -1,3 +1,3 @@
-
-T13256.hs:4:12: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
+T13256.hs:4:31: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
Literal 100000000000000000000000000000000 is out of the Int range -9223372036854775808..9223372036854775807
+
=====================================
utils/check-exact/ExactPrint.hs
=====================================
@@ -1161,7 +1161,7 @@ limportDeclAnnPackage k annImp = fmap (\new -> annImp { importDeclAnnPackage = n
-- data AnnList
-- = AnnList {
--- al_anchor :: Maybe Anchor, -- ^ start point of a list having layout
+-- al_layout :: !AnnListLayout,
-- al_brackets :: !AnnListBrackets,
-- al_semis :: [EpToken ";"], -- decls
-- al_trailing :: [TrailingAnn] -- ^ items appearing after the
@@ -2406,18 +2406,17 @@ instance ExactPrint (ClsInstDecl GhcPs) where
getAnnotationEntry _ = NoEntryVal
setAnnotationAnchor a _ _ _ = a
- exact (ClsInstDecl { cid_ext = (mbWarn, AnnClsInstDecl i w oc semis cc)
+ exact (ClsInstDecl { cid_ext = (mbWarn, AnnClsInstDecl i w ann_list)
, cid_poly_ty = inst_ty
, cid_decls = decls
, cid_overlap_mode = mbOverlap
, cid_modifiers = mods })
= do
(mbWarn', i', w', mbOverlap', inst_ty', mods') <- top_matter
- oc' <- markEpToken oc
- semis' <- mapM markEpToken semis
- decls' <- mapM markAnnotated decls
- cc' <- markEpToken cc
- return (ClsInstDecl { cid_ext = (mbWarn', AnnClsInstDecl i' w' oc' semis' cc')
+ (ann_list', decls') <- markAnnListA' ann_list $ \a -> do
+ r <- setLayoutBoth $ mapM markAnnotated decls
+ return (a,r)
+ return (ClsInstDecl { cid_ext = (mbWarn', AnnClsInstDecl i' w' ann_list')
, cid_poly_ty = inst_ty'
, cid_decls = decls'
, cid_overlap_mode = mbOverlap'
@@ -3820,7 +3819,7 @@ instance ExactPrint (FamilyDecl GhcPs) where
getAnnotationEntry _ = NoEntryVal
setAnnotationAnchor a _ _ _ = a
- exact (FamilyDecl { fdExt = AnnFamilyDecl ops cps t d f dc eq vb w oc dd cc
+ exact (FamilyDecl { fdExt = AnnFamilyDecl ops cps t d f dc eq vb w dd
, fdInfo = info
, fdTopLevel = top_level
, fdLName = ltycon
@@ -3842,23 +3841,21 @@ instance ExactPrint (FamilyDecl GhcPs) where
vb' <- markEpToken vb
inj' <- markAnnotated inj
return (vb', Just inj')
- (w', oc', dd', cc', info') <-
+ (w', dd', info') <-
case info of
- ClosedTypeFamily x mb_eqns -> do
+ ClosedTypeFamily an mb_eqns -> do
w' <- markEpToken w
- oc' <- markEpToken oc
- (dd', mb_eqns') <-
+ (an', dd', mb_eqns') <-
case mb_eqns of
Nothing -> do
dd' <- markEpToken dd
- return (dd', mb_eqns)
+ return (an, dd', mb_eqns)
Just eqns -> do
- eqns' <- mapM markAnnotated eqns
- return (dd, Just eqns')
- cc' <- markEpToken cc
- return (w',oc',dd',cc', ClosedTypeFamily x mb_eqns')
- _ -> return (w,oc,dd,cc, info)
- return (FamilyDecl { fdExt = AnnFamilyDecl [] [] t' d' f' dc' eq' vb' w' oc' dd' cc'
+ (an',eqns') <- markAnnList' an $ setLayoutBoth $ mapM markAnnotated eqns
+ return (an', dd, Just eqns')
+ return (w', dd', ClosedTypeFamily an' mb_eqns')
+ _ -> return (w, dd, info)
+ return (FamilyDecl { fdExt = AnnFamilyDecl [] [] t' d' f' dc' eq' vb' w' dd'
, fdInfo = info'
, fdTopLevel = top_level
, fdLName = ltycon'
=====================================
utils/haddock/haddock-api/src/Haddock/Convert.hs
=====================================
@@ -313,13 +313,13 @@ synifyTyCon _prr _coax tc
CTF mb
| Just (CoAxiom{co_ax_branches = branches}) <- mb
-> mkFamDecl $
- ClosedTypeFamily noExtField $
+ ClosedTypeFamily noAnn $
Just $
map (noLocA . synifyAxBranch tc) (fromBranches branches)
| otherwise
- -> mkFamDecl $ ClosedTypeFamily noExtField $ Just []
- CTF_BuiltIn {} -> mkFamDecl $ ClosedTypeFamily noExtField $ Just []
- CTF_Abstract -> mkFamDecl $ ClosedTypeFamily noExtField Nothing
+ -> mkFamDecl $ ClosedTypeFamily noAnn $ Just []
+ CTF_BuiltIn {} -> mkFamDecl $ ClosedTypeFamily noAnn $ Just []
+ CTF_Abstract -> mkFamDecl $ ClosedTypeFamily noAnn Nothing
where
resultVar = tyConFamilyResVar_maybe tc
mkFamDecl i =
=====================================
utils/haddock/haddock-api/src/Haddock/Types.hs
=====================================
@@ -1038,7 +1038,7 @@ type instance XCInjectivityAnn DocNameI = NoExtField
type instance XDataFamily DocNameI = NoExtField
type instance XOpenTypeFamily DocNameI = NoExtField
-type instance XClosedTypeFamily DocNameI = NoExtField
+type instance XClosedTypeFamily DocNameI = AnnList
type instance XXFamilyInfo DocNameI = DataConCantHappen
type instance XCFunDep DocNameI = NoExtField
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/5e96ea01bdc0bbbe68d89c8a269329…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/5e96ea01bdc0bbbe68d89c8a269329…
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0
Magnus pushed new branch wip/mangoiv/27895 at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/mangoiv/27895
You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
1
0