Marge Bot pushed to branch wip/marge_bot_batch_merge_job at Glasgow Haskell Compiler / GHC

Commits:

30 changed files:

Changes:

  • changelog.d/T27323
    1
    +section: compiler
    
    2
    +synopsis: Don't report ``-XStrict``-generated bang patterns under ``-Wredundant-bang-patterns``
    
    3
    +description:
    
    4
    +  Bangs introduced by ``-XStrict`` are no longer reported as redundant under
    
    5
    +  ``-Wredundant-bang-patterns``, as they are not user-written.
    
    6
    +issues: #27323
    
    7
    +mrs: !16395

  • compiler/GHC/Hs/Decls.hs
    ... ... @@ -708,13 +708,11 @@ data AnnFamilyDecl
    708 708
           afd_equal  :: EpToken "=",
    
    709 709
           afd_vbar   :: EpToken "|",
    
    710 710
           afd_where  :: EpToken "where",
    
    711
    -      afd_openc  :: EpToken "{",
    
    712
    -      afd_dotdot :: EpToken "..",
    
    713
    -      afd_closec :: EpToken "}"
    
    711
    +      afd_dotdot :: EpToken ".."
    
    714 712
       } deriving Data
    
    715 713
     
    
    716 714
     instance NoAnn AnnFamilyDecl where
    
    717
    -  noAnn = AnnFamilyDecl noAnn noAnn noAnn noAnn noAnn noAnn noAnn noAnn noAnn noAnn noAnn noAnn
    
    715
    +  noAnn = AnnFamilyDecl noAnn noAnn noAnn noAnn noAnn noAnn noAnn noAnn noAnn noAnn
    
    718 716
     
    
    719 717
     ------------- Functions over FamilyDecls -----------
    
    720 718
     
    
    ... ... @@ -744,7 +742,7 @@ type instance XXInjectivityAnn (GhcPass _) = DataConCantHappen
    744 742
     
    
    745 743
     type instance XDataFamily       (GhcPass _) = NoExtField
    
    746 744
     type instance XOpenTypeFamily   (GhcPass _) = NoExtField
    
    747
    -type instance XClosedTypeFamily (GhcPass _) = NoExtField
    
    745
    +type instance XClosedTypeFamily (GhcPass _) = AnnList
    
    748 746
     type instance XXFamilyInfo      (GhcPass _) = DataConCantHappen
    
    749 747
     
    
    750 748
     instance OutputableBndrId p
    
    ... ... @@ -1044,9 +1042,7 @@ data AnnClsInstDecl
    1044 1042
       = AnnClsInstDecl {
    
    1045 1043
         acid_instance :: EpToken "instance",
    
    1046 1044
         acid_where    :: EpToken "where",
    
    1047
    -    acid_openc    :: EpToken "{",
    
    1048
    -    acid_semis    :: [EpToken ";"],
    
    1049
    -    acid_closec   :: EpToken "}"
    
    1045
    +    acid_decls    :: AnnList
    
    1050 1046
       } deriving Data
    
    1051 1047
     
    
    1052 1048
     
    
    ... ... @@ -1063,7 +1059,7 @@ type instance XTyFamInstD GhcTc = NoExtField
    1063 1059
     type instance XXInstDecl    (GhcPass _) = DataConCantHappen
    
    1064 1060
     
    
    1065 1061
     instance NoAnn AnnClsInstDecl where
    
    1066
    -  noAnn = AnnClsInstDecl noAnn noAnn noAnn noAnn noAnn
    
    1062
    +  noAnn = AnnClsInstDecl noAnn noAnn noAnn
    
    1067 1063
     
    
    1068 1064
     cidDeprecation :: forall p. IsPass p
    
    1069 1065
                    => ClsInstDecl (GhcPass p)
    

  • compiler/GHC/Hs/Dump.hs
    ... ... @@ -258,22 +258,21 @@ showAstData bs ba a0 = blankLine $$ showAstData' a0
    258 258
                                      showAstData' j, showAstData' k]
    
    259 259
     
    
    260 260
                 annFamilyDecl :: AnnFamilyDecl -> SDoc
    
    261
    -            annFamilyDecl (AnnFamilyDecl a b c d e f g h i j k l) = case ba of
    
    261
    +            annFamilyDecl (AnnFamilyDecl a b c d e f g h i j) = case ba of
    
    262 262
                  BlankEpAnnotations -> parens $ text "blanked:" <+> text "AnnFamilyDecl"
    
    263 263
                  NoBlankEpAnnotations ->
    
    264 264
                   parens $ text "AnnFamilyDecl"
    
    265 265
                             $$ vcat [showAstData' a, showAstData' b, showAstData' c,
    
    266 266
                                      showAstData' d, showAstData' e, showAstData' f,
    
    267 267
                                      showAstData' g, showAstData' h, showAstData' i,
    
    268
    -                                 showAstData' j, showAstData' k, showAstData' l]
    
    268
    +                                 showAstData' j]
    
    269 269
     
    
    270 270
                 annClsInstDecl :: AnnClsInstDecl -> SDoc
    
    271
    -            annClsInstDecl (AnnClsInstDecl a b c d e) = case ba of
    
    271
    +            annClsInstDecl (AnnClsInstDecl a b c) = case ba of
    
    272 272
                  BlankEpAnnotations -> parens $ text "blanked:" <+> text "AnnFamilyDecl"
    
    273 273
                  NoBlankEpAnnotations ->
    
    274 274
                   parens $ text "AnnClsInstDecl"
    
    275
    -                        $$ vcat [showAstData' a, showAstData' b, showAstData' c,
    
    276
    -                                 showAstData' d, showAstData' e]
    
    275
    +                        $$ vcat [showAstData' a, showAstData' b, showAstData' c]
    
    277 276
     
    
    278 277
     
    
    279 278
                 annotationExprBracket :: BracketAnn (EpUniToken "[|" "⟦") (EpToken "[e|") -> SDoc
    

  • compiler/GHC/HsToCore/Match.hs
    ... ... @@ -383,12 +383,14 @@ tidyEqnInfo :: MatchId -> EquationInfo
    383 383
     
    
    384 384
     tidyEqnInfo _ eqn@(EqnDone {}) = return (idDsWrapper, eqn)
    
    385 385
     
    
    386
    -tidyEqnInfo v eqn@(EqnMatch { eqn_pat = (L loc pat) }) = do
    
    387
    -  (wrap, pat') <- tidy1 v (not . isGoodSrcSpan . locA $ loc) pat
    
    386
    +tidyEqnInfo v eqn@(EqnMatch { eqn_pat = p@(L loc _) }) = do
    
    387
    +  (wrap, pat') <- tidyLPat v p
    
    388 388
       return (wrap, eqn{eqn_pat = L loc pat' })
    
    389 389
     
    
    390
    +tidyLPat :: MatchId -> LPat GhcTc -> DsM (DsWrapper, Pat GhcTc)
    
    391
    +tidyLPat v (L loc pat) = putSrcSpanDsA loc (tidy1 v pat)
    
    392
    +
    
    390 393
     tidy1 :: MatchId             -- The scrutinee
    
    391
    -      -> Bool                -- `True` if the pattern was generated, `False` if it was user-written
    
    392 394
           -> Pat GhcTc           -- The pattern against which it is to be matched
    
    393 395
           -> DsM (DsWrapper,     -- Extra bindings to do before the match
    
    394 396
                   Pat GhcTc)     -- Equivalent pattern
    
    ... ... @@ -399,21 +401,22 @@ tidy1 :: MatchId -- The scrutinee
    399 401
     -- It eliminates many pattern forms (as-patterns, variable patterns,
    
    400 402
     -- list patterns, etc) and returns any created bindings in the wrapper.
    
    401 403
     
    
    402
    -tidy1 v g (ParPat _ pat)      = tidy1 v g (unLoc pat)
    
    403
    -tidy1 v g (SigPat _ pat _)    = tidy1 v g (unLoc pat)
    
    404
    -tidy1 _ _ (WildPat ty)        = return (idDsWrapper, WildPat ty)
    
    405
    -tidy1 v g (BangPat _ (L l p)) = tidy_bang_pat v g l p
    
    406
    -tidy1 v g (ModifiedPat _ _ pat) = tidy1 v g (unLoc pat)
    
    404
    +tidy1 v (ParPat _ pat)        = tidyLPat v pat
    
    405
    +tidy1 v (SigPat _ pat _)      = tidyLPat v pat
    
    406
    +tidy1 _ (WildPat ty)          = return (idDsWrapper, WildPat ty)
    
    407
    +tidy1 v (BangPat _ (L l p))   = putSrcSpanDsA l $ tidy_bang_pat v l p
    
    408
    +tidy1 v (ModifiedPat _ _ pat) = tidyLPat v pat
    
    407 409
     
    
    408 410
             -- case v of { x -> mr[] }
    
    409 411
             -- = case v of { _ -> let x=v in mr[] }
    
    410
    -tidy1 v _ (VarPat _ (L _ var))
    
    412
    +tidy1 v (VarPat _ (L _ var))
    
    411 413
       = return (bindMatchId var v, WildPat (idType var))
    
    412 414
     
    
    413 415
             -- case v of { x@p -> mr[] }
    
    414 416
             -- = case v of { p -> let x=v in mr[] }
    
    415
    -tidy1 v g (AsPat _ (L _ var) pat)
    
    416
    -  = do  { (wrap, pat') <- tidy1 v g (unLoc pat)
    
    417
    +tidy1 v (AsPat _ (L _ var) pat)
    
    418
    +
    
    419
    +  = do  { (wrap, pat') <- tidyLPat v pat
    
    417 420
             ; return (bindMatchId var v . wrap, pat') }
    
    418 421
     
    
    419 422
     {- now, here we handle lazy patterns:
    
    ... ... @@ -427,7 +430,7 @@ tidy1 v g (AsPat _ (L _ var) pat)
    427 430
         The case expr for v_i is just: match [v] [(p, [], \ x -> Var v_i)] any_expr
    
    428 431
     -}
    
    429 432
     
    
    430
    -tidy1 v _ (LazyPat _ pat)
    
    433
    +tidy1 v (LazyPat _ pat)
    
    431 434
         -- This is a convenient place to check for unlifted types under a lazy pattern.
    
    432 435
         -- Doing this check during type-checking is unsatisfactory because we may
    
    433 436
         -- not fully know the zonked types yet. We sure do here.
    
    ... ... @@ -441,14 +444,14 @@ tidy1 v _ (LazyPat _ pat)
    441 444
             ; let sel_binds =  [NonRec b rhs | (b,rhs) <- sel_prs]
    
    442 445
             ; return (mkCoreLets sel_binds, WildPat (matchIdType v)) }
    
    443 446
     
    
    444
    -tidy1 _ _ (ListPat ty pats)
    
    447
    +tidy1 _ (ListPat ty pats)
    
    445 448
       = return (idDsWrapper, unLoc list_ConPat)
    
    446 449
       where
    
    447 450
         list_ConPat = foldr (\ x y -> mkPrefixConPat consDataCon [x, y] [ty])
    
    448 451
                             (mkNilPat ty)
    
    449 452
                             pats
    
    450 453
     
    
    451
    -tidy1 _ _ (TuplePat tys pats boxity)
    
    454
    +tidy1 _ (TuplePat tys pats boxity)
    
    452 455
       = return (idDsWrapper, unLoc tuple_ConPat)
    
    453 456
       where
    
    454 457
         arity = length pats
    
    ... ... @@ -458,34 +461,37 @@ tidy1 _ _ (TuplePat tys pats boxity)
    458 461
                  Boxed   -> tys
    
    459 462
                -- See Note [Unboxed tuple RuntimeRep vars] in TyCon
    
    460 463
     
    
    461
    -tidy1 _ _ (SumPat tys pat alt arity)
    
    464
    +tidy1 _ (SumPat tys pat alt arity)
    
    462 465
       = return (idDsWrapper, unLoc sum_ConPat)
    
    463 466
       where
    
    464 467
         sum_ConPat = mkPrefixConPat (sumDataCon alt arity) [pat] (map getRuntimeRep tys ++ tys)
    
    465 468
                      -- See Note [Unboxed tuple RuntimeRep vars] in TyCon
    
    466 469
     
    
    467 470
     -- LitPats: we *might* be able to replace these w/ a simpler form
    
    468
    -tidy1 _ g (LitPat _ lit)
    
    469
    -  = do { unless g $
    
    471
    +tidy1 _ (LitPat _ lit)
    
    472
    +  = do { in_gen <- inGeneratedCodeDs;
    
    473
    +         unless in_gen $
    
    470 474
                warnAboutOverflowedLit lit
    
    471 475
            ; return (idDsWrapper, tidyLitPat lit) }
    
    472 476
     
    
    473 477
     -- NPats: we *might* be able to replace these w/ a simpler form
    
    474
    -tidy1 _ g (NPat ty (L _ lit@OverLit { ol_val = v }) mb_neg eq)
    
    475
    -  = do { unless g $
    
    478
    +tidy1 _ (NPat ty (L _ lit@OverLit { ol_val = v }) mb_neg eq)
    
    479
    +  = do { in_gen <- inGeneratedCodeDs;
    
    480
    +         unless in_gen $
    
    476 481
                let lit' | Just _ <- mb_neg = lit{ ol_val = negateOverLitVal v }
    
    477 482
                         | otherwise = lit
    
    478 483
                in warnAboutOverflowedOverLit lit'
    
    479 484
            ; return (idDsWrapper, tidyNPat lit mb_neg eq ty) }
    
    480 485
     
    
    481 486
     -- NPlusKPat: we may want to warn about the literals
    
    482
    -tidy1 _ g n@(NPlusKPat _ _ (L _ lit1) lit2 _ _)
    
    483
    -  = do { unless g $ do
    
    487
    +tidy1 _ n@(NPlusKPat _ _ (L _ lit1) lit2 _ _)
    
    488
    +  = do { in_gen <- inGeneratedCodeDs;
    
    489
    +         unless in_gen $ do
    
    484 490
                warnAboutOverflowedOverLit lit1
    
    485 491
                warnAboutOverflowedOverLit lit2
    
    486 492
            ; return (idDsWrapper, n) }
    
    487 493
     
    
    488
    -tidy1 _ _ (OrPat ty lpats)
    
    494
    +tidy1 _ (OrPat ty lpats)
    
    489 495
       -- See Note [Implementation of OrPatterns]. We desugar
    
    490 496
       --   (1; 2; 3)
    
    491 497
       -- to
    
    ... ... @@ -514,44 +520,44 @@ tidy1 _ _ (OrPat ty lpats)
    514 520
         single_grhs e = GRHSs emptyComments [noLocA $ GRHS noAnn [] e] (EmptyLocalBinds noExtField)
    
    515 521
     
    
    516 522
     -- Everything else goes through unchanged...
    
    517
    -tidy1 _ _ non_interesting_pat
    
    523
    +tidy1 _ non_interesting_pat
    
    518 524
       = return (idDsWrapper, non_interesting_pat)
    
    519 525
     
    
    520 526
     --------------------
    
    521
    -tidy_bang_pat :: MatchId -> Bool -> SrcSpanAnnA -> Pat GhcTc
    
    527
    +tidy_bang_pat :: MatchId -> SrcSpanAnnA -> Pat GhcTc
    
    522 528
                   -> DsM (DsWrapper, Pat GhcTc)
    
    523 529
     
    
    524 530
     -- Discard par/sig under a bang
    
    525
    -tidy_bang_pat v g _ (ParPat _ (L l p))   = tidy_bang_pat v g l p
    
    526
    -tidy_bang_pat v g _ (SigPat _ (L l p) _) = tidy_bang_pat v g l p
    
    531
    +tidy_bang_pat v _ (ParPat _ (L l p))   = putSrcSpanDsA l $ tidy_bang_pat v l p
    
    532
    +tidy_bang_pat v _ (SigPat _ (L l p) _) = putSrcSpanDsA l $ tidy_bang_pat v l p
    
    527 533
     
    
    528 534
     -- Push the bang-pattern inwards, in the hope that
    
    529 535
     -- it may disappear next time
    
    530
    -tidy_bang_pat v g l (AsPat x v' p)
    
    531
    -  = tidy1 v g (AsPat x v' (L l (BangPat noExtField p)))
    
    532
    -tidy_bang_pat v g l (XPat (CoPat w p t))
    
    533
    -  = tidy1 v g (XPat $ CoPat w (BangPat noExtField (L l p)) t)
    
    534
    -tidy_bang_pat v g l (OrPat x (p:|ps)) -- push bang into first pat alt
    
    535
    -  = tidy1 v g (OrPat x (L l (BangPat noExtField p) :| ps))
    
    536
    +tidy_bang_pat v l (AsPat x v' p)
    
    537
    +  = tidy1 v (AsPat x v' (L l (BangPat noExtField p)))
    
    538
    +tidy_bang_pat v l (XPat (CoPat w p t))
    
    539
    +  = tidy1 v (XPat $ CoPat w (BangPat noExtField (L l p)) t)
    
    540
    +tidy_bang_pat v l (OrPat x (p:|ps)) -- push bang into first pat alt
    
    541
    +  = tidy1 v (OrPat x (L l (BangPat noExtField p) :| ps))
    
    536 542
     
    
    537 543
     -- Discard bang around strict pattern
    
    538
    -tidy_bang_pat v g _ p@(LitPat {})    = tidy1 v g p
    
    539
    -tidy_bang_pat v g _ p@(ListPat {})   = tidy1 v g p
    
    540
    -tidy_bang_pat v g _ p@(TuplePat {})  = tidy1 v g p
    
    541
    -tidy_bang_pat v g _ p@(SumPat {})    = tidy1 v g p
    
    544
    +tidy_bang_pat v _ p@(LitPat {})    = tidy1 v p
    
    545
    +tidy_bang_pat v _ p@(ListPat {})   = tidy1 v p
    
    546
    +tidy_bang_pat v _ p@(TuplePat {})  = tidy1 v p
    
    547
    +tidy_bang_pat v _ p@(SumPat {})    = tidy1 v p
    
    542 548
     
    
    543 549
     -- Data/newtype constructors
    
    544
    -tidy_bang_pat v g l p@(ConPat { pat_con = L _ (RealDataCon dc)
    
    545
    -                              , pat_args = args
    
    546
    -                              , pat_con_ext = ConPatTc
    
    547
    -                                { cpt_arg_tys = arg_tys
    
    548
    -                                }
    
    549
    -                              })
    
    550
    +tidy_bang_pat v l p@(ConPat { pat_con = L _ (RealDataCon dc)
    
    551
    +                            , pat_args = args
    
    552
    +                            , pat_con_ext = ConPatTc
    
    553
    +                              { cpt_arg_tys = arg_tys
    
    554
    +                              }
    
    555
    +                            })
    
    550 556
       -- Newtypes: push bang inwards (#9844)
    
    551 557
       =
    
    552 558
         if isNewTyCon (dataConTyCon dc)
    
    553
    -      then tidy1 v g (p { pat_args = push_bang_into_newtype_arg l (scaledThing ty) args })
    
    554
    -      else tidy1 v g p  -- Data types: discard the bang
    
    559
    +      then tidy1 v (p { pat_args = push_bang_into_newtype_arg l (scaledThing ty) args })
    
    560
    +      else tidy1 v p  -- Data types: discard the bang
    
    555 561
         where
    
    556 562
           (ty:_) = dataConInstArgTys dc arg_tys
    
    557 563
     
    
    ... ... @@ -570,7 +576,7 @@ tidy_bang_pat v g l p@(ConPat { pat_con = L _ (RealDataCon dc)
    570 576
     --
    
    571 577
     -- NB: SigPatIn, ConPatIn should not happen
    
    572 578
     
    
    573
    -tidy_bang_pat _ _ l p = return (idDsWrapper, BangPat noExtField (L l p))
    
    579
    +tidy_bang_pat _ l p = return (idDsWrapper, BangPat noExtField (L l p))
    
    574 580
     
    
    575 581
     -------------------
    
    576 582
     push_bang_into_newtype_arg :: SrcSpanAnnA
    
    ... ... @@ -954,7 +960,7 @@ matchSinglePatVar var mb_scrut ctx pat ty match_result
    954 960
            ; ldi_nablas <-
    
    955 961
              if  isMatchContextPmChecked_SinglePat dflags FromSource ctx pat
    
    956 962
              then addCoreScrutTmCs (maybeToList mb_scrut) [var] $
    
    957
    -              pmcPatBind (DsMatchContext ctx locn) var (unLoc pat)
    
    963
    +              pmcPatBind (DsMatchContext ctx locn) var pat
    
    958 964
              else getLdiNablas
    
    959 965
     
    
    960 966
            ; let eqn_info = EqnMatch { eqn_pat = decideBangHood dflags pat
    

  • compiler/GHC/HsToCore/Match/Literal.hs
    ... ... @@ -33,6 +33,7 @@ import GHC.HsToCore.Utils
    33 33
     
    
    34 34
     import GHC.Hs
    
    35 35
     
    
    36
    +import GHC.Rename.Utils (wrapGenSpan)
    
    36 37
     import GHC.Tc.Utils.TcMType ( shortCutLit )
    
    37 38
     import GHC.Tc.Utils.TcType
    
    38 39
     
    
    ... ... @@ -580,7 +581,8 @@ tidyNPat (OverLit (OverLitTc False _ ty) val) mb_neg _eq outer_ty
    580 581
     
    
    581 582
         mk_con_pat :: DataCon -> HsLit GhcTc -> Pat GhcTc
    
    582 583
         mk_con_pat con lit
    
    583
    -      = unLoc (mkPrefixConPat con [noLocA $ LitPat noExtField lit] [])
    
    584
    +      -- Mark the generated literal to avoid duplicate -Woverflowed-literals.
    
    585
    +      = unLoc (mkPrefixConPat con [wrapGenSpan $ LitPat noExtField lit] [])
    
    584 586
     
    
    585 587
         mb_int_lit :: Maybe Integer
    
    586 588
         mb_int_lit = case (mb_neg, val) of
    

  • compiler/GHC/HsToCore/Monad.hs
    ... ... @@ -15,7 +15,7 @@ module GHC.HsToCore.Monad (
    15 15
             duplicateLocalDs, newSysLocalDs, newSysLocalsDs,
    
    16 16
             newSysLocalMDs, newSysLocalsMDs, newFailLocalMDs,
    
    17 17
             newUniqueId, newPredVarDs, newStaticId,
    
    18
    -        getSrcSpanDs, putSrcSpanDs, putSrcSpanDsA,
    
    18
    +        getSrcSpanDs, inGeneratedCodeDs, putSrcSpanDs, putSrcSpanDsA,
    
    19 19
             mkNamePprCtxDs,
    
    20 20
             newUnique,
    
    21 21
             UniqSupply, newUniqueSupply,
    
    ... ... @@ -584,6 +584,7 @@ mkDsEnvs unit_env mod rdr_env type_env fam_inst_env tcm_plugins ptc msg_var
    584 584
                                , dsl_loc         = real_span
    
    585 585
                                , dsl_nablas      = Ldi initNablas
    
    586 586
                                , dsl_unspecables = Just emptyVarSet
    
    587
    +                           , dsl_in_generated_code = False
    
    587 588
                                }
    
    588 589
         in (gbl_env, lcl_env)
    
    589 590
     
    
    ... ... @@ -676,13 +677,17 @@ getSrcSpanDs :: DsM SrcSpan
    676 677
     getSrcSpanDs = do { env <- getLclEnv
    
    677 678
                       ; return (RealSrcSpan (dsl_loc env) Strict.Nothing) }
    
    678 679
     
    
    680
    +-- | See 'dsl_in_generated_code'
    
    681
    +inGeneratedCodeDs :: DsM Bool
    
    682
    +inGeneratedCodeDs = dsl_in_generated_code <$> getLclEnv
    
    683
    +
    
    679 684
     putSrcSpanDs :: SrcSpan -> DsM a -> DsM a
    
    680 685
     putSrcSpanDs (RealSrcSpan real_span _) thing_inside
    
    681
    -  = updLclEnv (\ env -> env {dsl_loc = real_span}) thing_inside
    
    686
    +  = updLclEnv (\ env -> env {dsl_loc = real_span, dsl_in_generated_code = False}) thing_inside
    
    682 687
     putSrcSpanDs UnhelpfulSpan{} thing_inside
    
    683 688
       = thing_inside
    
    684 689
     putSrcSpanDs GeneratedSrcSpan{} thing_inside
    
    685
    -  = thing_inside
    
    690
    +  = updLclEnv (\ env -> env {dsl_in_generated_code = True}) thing_inside
    
    686 691
     
    
    687 692
     putSrcSpanDsA :: EpAnn ann -> DsM a -> DsM a
    
    688 693
     putSrcSpanDsA loc = putSrcSpanDs (locA loc)
    

  • compiler/GHC/HsToCore/Pmc.hs
    ... ... @@ -104,7 +104,7 @@ whenDoingPmc no_pmc thing_inside
    104 104
                 Ldi nablas -> thing_inside nablas }
    
    105 105
     
    
    106 106
     -- | Check a pattern binding (let, where) for exhaustiveness.
    
    107
    -pmcPatBind :: DsMatchContext -> Id -> Pat GhcTc -> DsM LdiNablas
    
    107
    +pmcPatBind :: DsMatchContext -> Id -> LPat GhcTc -> DsM LdiNablas
    
    108 108
     pmcPatBind ctxt@(DsMatchContext match_ctxt loc) var p
    
    109 109
       = whenDoingPmc NoPmc $ \ !missing ->
    
    110 110
         mb_discard_warnings $ do
    

  • compiler/GHC/HsToCore/Pmc/Desugar.hs
    ... ... @@ -155,11 +155,15 @@ desugarPat x pat = case pat of
    155 155
       VarPat _ y   -> pure (mkPmLetVar (unLoc y) x)
    
    156 156
       ParPat _ p   -> desugarLPat x p
    
    157 157
       LazyPat _ _  -> pure GdEnd -- like a wildcard
    
    158
    -  BangPat _ p@(L l p') ->
    
    158
    +  BangPat _ p@(L l p') -> do
    
    159 159
         -- Add the bang in front of the list, because it will happen before any
    
    160 160
         -- nested stuff.
    
    161
    +    in_gen <- inGeneratedCodeDs
    
    162
    +    -- A bang inserted by -XStrict (decideBangHood) has no SrcInfo: it is
    
    163
    +    -- divergence-checked but never reported as redundant (#27323).
    
    164
    +    let pm_loc | in_gen    = Nothing
    
    165
    +               | otherwise = Just (SrcInfo (L (locA l) (ppr p')))
    
    161 166
         consGrdDag (PmBang x pm_loc) <$> desugarLPat x p
    
    162
    -      where pm_loc = Just (SrcInfo (L (locA l) (ppr p')))
    
    163 167
     
    
    164 168
       -- (x@pat)   ==>   Desugar pat with x as match var and handle impedance
    
    165 169
       --                 mismatch with incoming match var
    
    ... ... @@ -311,11 +315,11 @@ desugarPatV pat = do
    311 315
       pure (x, grds)
    
    312 316
     
    
    313 317
     desugarLPat :: Id -> LPat GhcTc -> DsM GrdDag
    
    314
    -desugarLPat x = desugarPat x . unLoc
    
    318
    +desugarLPat x (L loc pat) = putSrcSpanDsA loc (desugarPat x pat)
    
    315 319
     
    
    316 320
     -- | 'desugarLPat', but also select and return a new match var.
    
    317 321
     desugarLPatV :: LPat GhcTc -> DsM (Id, GrdDag)
    
    318
    -desugarLPatV = desugarPatV . unLoc
    
    322
    +desugarLPatV (L loc pat) = putSrcSpanDsA loc (desugarPatV pat)
    
    319 323
     
    
    320 324
     -- | @desugarListPat _ x [p1, ..., pn]@ is basically
    
    321 325
     --   @desugarConPatOut _ x $(mkListConPatOuts [p1, ..., pn]>@ without ever
    
    ... ... @@ -374,11 +378,11 @@ desugarConPatOut x con univ_tys ex_tvs dicts = \case
    374 378
           -- tracePm "ConPatOut" (ppr x $$ ppr con $$ ppr arg_ids)
    
    375 379
           pure (con_grd `consGrdDag` arg_grds)
    
    376 380
     
    
    377
    -desugarPatBind :: SrcSpan -> Id -> Pat GhcTc -> DsM (PmPatBind Pre)
    
    381
    +desugarPatBind :: SrcSpan -> Id -> LPat GhcTc -> DsM (PmPatBind Pre)
    
    378 382
     -- See 'GrdPatBind' for how this simply repurposes GrdGRHS.
    
    379 383
     -- See Note [Suppress warnings in PMC desugaring]
    
    380 384
     desugarPatBind loc var pat = discardWarningsDs $
    
    381
    -  PmPatBind . flip PmGRHS (SrcInfo (L loc (ppr pat))) <$> desugarPat var pat
    
    385
    +  PmPatBind . flip PmGRHS (SrcInfo (L loc (ppr pat))) <$> desugarLPat var pat
    
    382 386
     
    
    383 387
     desugarEmptyCase :: Id -> DsM PmEmptyCase
    
    384 388
     desugarEmptyCase var = pure PmEmptyCase { pe_var = var }
    
    ... ... @@ -633,21 +637,16 @@ Consider (#21761)
    633 637
       idV :: Void -> Void
    
    634 638
       idV v = v
    
    635 639
     
    
    636
    -Without -XStrict, we would not warn here. But with -XStrict, there is an
    
    637
    -implicit bang on `v` and we should give an inaccessible warning for the RHS.
    
    638
    -The way we account for that is by calling `decideBangHood` on patterns
    
    639
    -in a `Match`, which inserts the implicit bang.
    
    640
    +With -XStrict, there is an implicit bang pattern on `v` as per
    
    641
    +Note [decideBangHood], so the RHS is inaccessible and we must report it as such.
    
    640 642
     
    
    641
    -Making the call here actually seems redundant with the call to `decideBangHood`
    
    642
    -in `GHC.HsToCore.Match.matchWrapper`, which does it *after* it calls the
    
    643
    -pattern-match checker on the Match's patterns. It would be great if we could expect
    
    644
    -`matchWrapper` to pass the bang-adorned `Match` to the pattern-match checker,
    
    645
    -but sadly then we get worse warning messages which would print `idV` as if the
    
    646
    -user *had* written a bang:
    
    643
    +The natural way to achieve this is described in #27677: insert the bang using
    
    644
    +'ExpansionPat' (see Note [Handling overloaded and rebindable constructs] in
    
    645
    +GHC.Rename.Expr). Then the pattern-match checker sees the bang pattern, while
    
    646
    +warning messages display the user-written pattern.
    
    647 647
     
    
    648
    -     Pattern match has inaccessible right hand side
    
    649
    --    In an equation for ‘idV’: idV v = ...
    
    650
    -+    In an equation for ‘idV’: idV !v = ...
    
    651
    -
    
    652
    -So we live with the duplication.
    
    648
    +This approach hasn't been implemented yet, so for the time being 'desugarMatches'
    
    649
    +calls 'decideBangHood' itself, duplicating the call in 'GHC.HsToCore.Match.matchWrapper'.
    
    650
    +'decideBangHood' gives the bangs it inserts a generated span, so that they are
    
    651
    +never reported as redundant (see Note [Dead bang patterns] in GHC.HsToCore.Pmc.Check).
    
    653 652
     -}

  • compiler/GHC/HsToCore/Types.hs
    ... ... @@ -11,7 +11,7 @@ module GHC.HsToCore.Types (
    11 11
             DsMetaEnv, DsMetaVal(..), CompleteMatches
    
    12 12
         ) where
    
    13 13
     
    
    14
    -import GHC.Prelude (Int)
    
    14
    +import GHC.Prelude (Bool, Int)
    
    15 15
     
    
    16 16
     import Data.IORef
    
    17 17
     
    
    ... ... @@ -125,6 +125,7 @@ data DsLclEnv
    125 125
       -- ^ See Note [Desugaring non-canonical evidence]
    
    126 126
       -- This field collects all un-specialisable evidence variables in scope.
    
    127 127
       -- Nothing <=> don't collect this info (used for the LHS of Rules)
    
    128
    +  , dsl_in_generated_code :: Bool -- ^ Are we desugaring compiler-generated code?
    
    128 129
       }
    
    129 130
     
    
    130 131
     -- Inside [| |] brackets, the desugarer looks
    

  • compiler/GHC/HsToCore/Utils.hs
    ... ... @@ -72,6 +72,7 @@ import GHC.Unit.Module
    72 72
     import GHC.Builtin.KnownKeys
    
    73 73
     import GHC.Utils.Outputable
    
    74 74
     import GHC.Utils.Panic
    
    75
    +import GHC.Rename.Utils (wrapGenSpan')
    
    75 76
     import GHC.Types.SrcLoc
    
    76 77
     import GHC.Types.Tickish
    
    77 78
     import GHC.Utils.Misc
    
    ... ... @@ -1024,8 +1025,9 @@ Specifically:
    1024 1025
     -}
    
    1025 1026
     
    
    1026 1027
     
    
    1027
    --- | Use -XStrict to add a ! or remove a ~
    
    1028
    --- See Note [decideBangHood]
    
    1028
    +-- | Use -XStrict to add a ! or remove a ~, as per  Note [decideBangHood].
    
    1029
    +--
    
    1030
    +-- The inserted bang is compiler-generated: see Note [Desugaring -XStrict matches in Pmc].
    
    1029 1031
     decideBangHood :: DynFlags
    
    1030 1032
                    -> LPat GhcTc  -- ^ Original pattern
    
    1031 1033
                    -> LPat GhcTc  -- Pattern with bang if necessary
    
    ... ... @@ -1040,7 +1042,7 @@ decideBangHood dflags lpat
    1040 1042
                ParPat x p -> L l (ParPat x (go p))
    
    1041 1043
                LazyPat _ lp' -> lp'
    
    1042 1044
                BangPat _ _   -> lp
    
    1043
    -           _             -> L l (BangPat noExtField lp)
    
    1045
    +           _             -> wrapGenSpan' (locA l) (BangPat noExtField lp)
    
    1044 1046
     
    
    1045 1047
     isTrueLHsExpr :: LHsExpr GhcTc -> Maybe (CoreExpr -> DsM CoreExpr)
    
    1046 1048
     
    

  • compiler/GHC/Parser.y
    ... ... @@ -1355,10 +1355,10 @@ ty_decl :: { LTyClDecl GhcPs }
    1355 1355
                     -- infix type constructors to be declared
    
    1356 1356
                  {% do { let { (tdcolon, tequal) = fst $ unLoc $4 }
    
    1357 1357
                        ; let { tvbar = fst $ unLoc $5 }
    
    1358
    -                   ; let { (twhere, (toc, tdd, tcc)) = fst $ unLoc $6  }
    
    1358
    +                   ; let { (twhere, tdd) = fst $ unLoc $6  }
    
    1359 1359
                        ; mkFamDecl (comb5 $1 $3 $4 $5 $6) (snd $ unLoc $6) TopLevel $3
    
    1360 1360
                                        (snd $ unLoc $4) (snd $ unLoc $5)
    
    1361
    -                           (AnnFamilyDecl [] [] (epTok $1) noAnn (epTok $2) tdcolon tequal tvbar twhere toc tdd tcc) }}
    
    1361
    +                           (AnnFamilyDecl [] [] (epTok $1) noAnn (epTok $2) tdcolon tequal tvbar twhere tdd ) }}
    
    1362 1362
     
    
    1363 1363
               -- ordinary data type or newtype declaration
    
    1364 1364
             | type_data_or_newtype capi_ctype tycl_hdr constrs maybe_derivings
    
    ... ... @@ -1391,7 +1391,7 @@ ty_decl :: { LTyClDecl GhcPs }
    1391 1391
                  {% do { let { tdcolon = fst $ unLoc $4 }
    
    1392 1392
                        ; mkFamDecl (comb4 $1 $2 $3 $4) (DataFamily noExtField) TopLevel $3
    
    1393 1393
                                        (snd $ unLoc $4) Nothing
    
    1394
    -                           (AnnFamilyDecl [] [] noAnn (epTok $1) (epTok $2) tdcolon noAnn noAnn noAnn noAnn noAnn noAnn) }}
    
    1394
    +                           (AnnFamilyDecl [] [] noAnn (epTok $1) (epTok $2) tdcolon noAnn noAnn noAnn noAnn) }}
    
    1395 1395
     
    
    1396 1396
     -- standalone kind signature
    
    1397 1397
     standalone_kind_sig :: { LStandaloneKindSig GhcPs }
    
    ... ... @@ -1435,8 +1435,8 @@ expModifiers1 :: { forall b. DisambECP b => PV (Located [LHsModifierOf (LocatedA
    1435 1435
     inst_decl :: { LInstDecl GhcPs }
    
    1436 1436
             : 'instance' maybe_warning_pragma overlap_pragma inst_type where_inst
    
    1437 1437
            {% do { decls <- cvBindsAndSigs (snd $ unLoc $5)
    
    1438
    -             ; let (twhere, (openc, closec, semis)) = fst $ unLoc $5
    
    1439
    -             ; let anns = AnnClsInstDecl (epTok $1) twhere openc semis closec
    
    1438
    +             ; let (twhere, ann_list) = fst $ unLoc $5
    
    1439
    +             ; let anns = AnnClsInstDecl (epTok $1) twhere ann_list
    
    1440 1440
                  ; let cid = ClsInstDecl
    
    1441 1441
                                       { cid_ext = ($2, anns)
    
    1442 1442
                                       , cid_poly_ty = $4
    
    ... ... @@ -1522,20 +1522,20 @@ inj_varids :: { Located [LocatedN RdrName] }
    1522 1522
     
    
    1523 1523
     -- Closed type families
    
    1524 1524
     
    
    1525
    -where_type_family :: { Located ((EpToken "where", (EpToken "{", EpToken "..", EpToken "}")),FamilyInfo GhcPs) }
    
    1525
    +where_type_family :: { Located ((EpToken "where",  EpToken ".."),FamilyInfo GhcPs) }
    
    1526 1526
             : {- empty -}                      { noLoc (noAnn,OpenTypeFamily noExtField) }
    
    1527 1527
             | 'where' ty_fam_inst_eqn_list
    
    1528
    -               { sLL $1 $> ((epTok $1,(fst $ unLoc $2))
    
    1529
    -                    , ClosedTypeFamily noExtField (fmap reverse $ snd $ unLoc $2)) }
    
    1528
    +               { sLL $1 $> ((epTok $1, (snd $ fst $ unLoc $2))
    
    1529
    +                    , ClosedTypeFamily (fst $ fst $ unLoc $2) (fmap reverse $ snd $ unLoc $2)) }
    
    1530 1530
     
    
    1531
    -ty_fam_inst_eqn_list :: { Located ((EpToken "{", EpToken "..", EpToken "}"),Maybe [LTyFamInstEqn GhcPs]) }
    
    1532
    -        :     '{' ty_fam_inst_eqns '}'     { sLL $1 $> ((epTok $1,noAnn, epTok $3)
    
    1531
    +ty_fam_inst_eqn_list :: { Located ((AnnList, EpToken ".."),Maybe [LTyFamInstEqn GhcPs]) }
    
    1532
    +        :     '{' ty_fam_inst_eqns '}'     { sLL $1 $> ((AnnList AnnListBraces (ListBraces (epTok $1) (epTok $3)) [], noAnn)
    
    1533 1533
                                                     ,Just (unLoc $2)) }
    
    1534 1534
             | vocurly ty_fam_inst_eqns close   { let (L loc _) = $2 in
    
    1535
    -                                             L loc (noAnn,Just (unLoc $2)) }
    
    1536
    -        |     '{' '..' '}'                 { sLL $1 $> ((epTok $1,epTok $2 ,epTok $3),Nothing) }
    
    1535
    +                                             L loc ((AnnList (AnnListLayout (glR $1)) ListNone [], noAnn),Just (unLoc $2)) }
    
    1536
    +        |     '{' '..' '}'                 { sLL $1 $> ((AnnList AnnListBraces (ListBraces (epTok $1) (epTok $3)) [], epTok $2), Nothing) }
    
    1537 1537
             | vocurly '..' close               { let (L loc _) = $2 in
    
    1538
    -                                             L loc ((noAnn,epTok $2, noAnn),Nothing) }
    
    1538
    +                                             L loc ((AnnList (AnnListLayout (glR $1)) ListNone [], epTok $2),Nothing) }
    
    1539 1539
     
    
    1540 1540
     ty_fam_inst_eqns :: { Located [LTyFamInstEqn GhcPs] }
    
    1541 1541
             : ty_fam_inst_eqns ';' ty_fam_inst_eqn
    
    ... ... @@ -1580,7 +1580,7 @@ at_decl_cls :: { LHsDecl GhcPs }
    1580 1580
                  {% do { let { tdcolon = fst $ unLoc $4 }
    
    1581 1581
                        ; liftM mkTyClD (mkFamDecl (comb3 $1 $3 $4) (DataFamily noExtField) NotTopLevel $3
    
    1582 1582
                                                       (snd $ unLoc $4) Nothing
    
    1583
    -                           (AnnFamilyDecl [] [] noAnn (epTok $1) $2 tdcolon noAnn noAnn noAnn noAnn noAnn noAnn)) }}
    
    1583
    +                           (AnnFamilyDecl [] [] noAnn (epTok $1) $2 tdcolon noAnn noAnn noAnn noAnn)) }}
    
    1584 1584
     
    
    1585 1585
                -- type family declarations, with optional 'family' keyword
    
    1586 1586
                -- (can't use opt_instance because you get shift/reduce errors
    
    ... ... @@ -1590,14 +1590,14 @@ at_decl_cls :: { LHsDecl GhcPs }
    1590 1590
                             (mkFamDecl (comb3 $1 $2 $3) (OpenTypeFamily noExtField) NotTopLevel $2
    
    1591 1591
                                        (fst . snd $ unLoc $3)
    
    1592 1592
                                        (snd . snd $ unLoc $3)
    
    1593
    -                         (AnnFamilyDecl [] [] (epTok $1) noAnn noAnn tdcolon tequal tvbar noAnn noAnn noAnn noAnn)) }}
    
    1593
    +                         (AnnFamilyDecl [] [] (epTok $1) noAnn noAnn tdcolon tequal tvbar noAnn noAnn)) }}
    
    1594 1594
             | 'type' 'family' type opt_at_kind_inj_sig
    
    1595 1595
                 {% do { let { (tdcolon, tequal, tvbar) = fst $ unLoc $4 }
    
    1596 1596
                       ; liftM mkTyClD
    
    1597 1597
                             (mkFamDecl (comb3 $1 $3 $4) (OpenTypeFamily noExtField) NotTopLevel $3
    
    1598 1598
                                        (fst . snd $ unLoc $4)
    
    1599 1599
                                        (snd . snd $ unLoc $4)
    
    1600
    -                           (AnnFamilyDecl [] [] (epTok $1) noAnn (epTok $2) tdcolon tequal tvbar noAnn noAnn noAnn noAnn)) }}
    
    1600
    +                           (AnnFamilyDecl [] [] (epTok $1) noAnn (epTok $2) tdcolon tequal tvbar noAnn noAnn)) }}
    
    1601 1601
                -- default type instances, with optional 'instance' keyword
    
    1602 1602
             | 'type' ty_fam_inst_eqn
    
    1603 1603
                     {% liftM mkInstD (mkTyFamInst (comb2 $1 $2) (unLoc $2)
    
    ... ... @@ -1896,14 +1896,13 @@ decls_inst :: { Located ([EpToken ";"],OrdList (LHsDecl GhcPs)) } -- Reversed
    1896 1896
                | {- empty -}                { noLoc ([],nilOL) }
    
    1897 1897
     
    
    1898 1898
     decllist_inst
    
    1899
    -        :: { Located ((EpToken "{", EpToken "}", [EpToken ";"])
    
    1900
    -                     , OrdList (LHsDecl GhcPs)) }      -- Reversed
    
    1901
    -        : '{'         decls_inst '}'    { sLL $1 $> ((epTok $1,epTok $3,fst $ unLoc $2),snd $ unLoc $2) }
    
    1902
    -        |     vocurly decls_inst close  { L (gl $2) ((noAnn,noAnn,fst $ unLoc $2),snd $ unLoc $2) }
    
    1899
    +        :: { Located (AnnList, OrdList (LHsDecl GhcPs)) }      -- Reversed
    
    1900
    +        : '{'         decls_inst '}'    { sLL $1 $> (AnnList AnnListBraces (ListBraces (epTok $1) (epTok $3)) (fst $ unLoc $2), snd $ unLoc $2) }
    
    1901
    +        |     vocurly decls_inst close  { L (gl $2) (AnnList (AnnListLayout (glR $1)) ListNone (fst $ unLoc $2),                snd $ unLoc $2) }
    
    1903 1902
     
    
    1904 1903
     -- Instance body
    
    1905 1904
     --
    
    1906
    -where_inst :: { Located ((EpToken "where", (EpToken "{", EpToken "}", [EpToken ";"]))
    
    1905
    +where_inst :: { Located ((EpToken "where", AnnList)
    
    1907 1906
                             , OrdList (LHsDecl GhcPs)) }   -- Reversed
    
    1908 1907
                                     -- No implicit parameters
    
    1909 1908
                                     -- May have type declarations
    

  • compiler/GHC/Tc/Gen/App.hs
    ... ... @@ -114,10 +114,11 @@ Note [Instantiation variables are short lived]
    114 114
     * Ordinary unification variables always stand for monotypes; only instantiation
    
    115 115
       variables can be unified with a polytype (by `qlUnify`).
    
    116 116
     
    
    117
    -* When we start typechecking the arguments of the call, in tcValArgs, we will
    
    118
    -  (a) monomorphise any un-filled-in instantiation variables
    
    117
    +* Before we start typechecking the arguments of the call, in tcValArgs, we will
    
    118
    +  (a) Monomorphise any un-filled-in instantiation variables
    
    119 119
           (see Note [Monomorphise instantiation variables]),
    
    120
    -  (b) zonk the argument type to reveal any polytypes before typechecking that
    
    120
    +      This happens in Step 4, at the start of `finishApp`.
    
    121
    +  (b) Zonk the argument type to reveal any polytypes before typechecking that
    
    121 122
           argument (see calls to `zonkTcType` and "Crucial step" in tcValArg).
    
    122 123
       See Section 4.3 "Applications and instantiation" of the paper.
    
    123 124
     
    
    ... ... @@ -277,39 +278,30 @@ tcApp works on the application chain by:
    277 278
        variables", written using \kappa in the paper.
    
    278 279
        See Note [Instantiating type variables in QuickLook]
    
    279 280
     
    
    280
    -Now we split into two cases:
    
    281
    +   Note that we take a quick look at the arguments before quick-looking
    
    282
    +   the result type; see Note [QuickLook: arguments before result]
    
    281 283
     
    
    282
    -3. Case NoQL: no Quick Look
    
    284
    +3. In case DoQL, when we are checking, use quickLookResultType to take a
    
    285
    +   quick look at the result type.
    
    283 286
     
    
    284
    -   3.1 Use checkResultTy to connect the the result type.
    
    285
    -       Do this /before/ checking the arguments; see
    
    286
    -       Note [Unify with expected type before typechecking arguments]
    
    287
    +The next steps are in `finishApp`:
    
    287 288
     
    
    288
    -   3.2 Check the arguments with `tcValArgs`.
    
    289
    +4. In case DoQL:
    
    290
    +   4.1  Monomorphise any as-yet-ununified instantiation variables (`qlMonoInstArgs`)
    
    291
    +        See Note [Monomorphise instantiation variables]
    
    292
    +   4.2  Use `zonkTcType` to expose the polymorphism hidden under instantiation
    
    293
    +        variables in `app_res_rho`, and the monomorphic versions of any
    
    294
    +        un-unified instantiation variables.
    
    289 295
     
    
    290
    -   3.3 Use `finishApp` to wrap up.
    
    296
    +5. Use `checkResultTy` to connect the result type.
    
    297
    +   Do this /before/ checking the arguments; see
    
    298
    +   Note [Unify with expected type before typechecking arguments]
    
    291 299
     
    
    292
    -4. Case DoQL: use Quick Look
    
    300
    +6.  Check the arguments with `tcValArgs`. Importantly, we must remember to zonk in
    
    301
    +    the EValArg case, to expose polymorphism
    
    293 302
     
    
    294
    -   4.1 Use `quickLookResultType` to take a quick look at the result type,
    
    295
    -       when in checking mode.  This is the shaded part of APP-Downarrow
    
    296
    -       in Fig 4.  It also implements the key part of
    
    297
    -       Note [Unify with expected type before typechecking arguments]
    
    298
    -
    
    299
    -   4.2 Check the arguments with `tcValArgs`. Importantly, this will
    
    300
    -       monomorphise all the instantiation variables of the call.
    
    301
    -       See Note [Monomorphise instantiation variables].
    
    302
    -
    
    303
    -   4.3 Use `zonkTcType` to expose the polymophism hidden under instantiation
    
    304
    -       variables in `app_res_rho`, and the monomorphic versions of any
    
    305
    -       un-unified instantiation variables.
    
    306
    -
    
    307
    -   4.4 Use `checkResTy` to do the subsumption check as usual
    
    308
    -
    
    309
    -   4.5 Use `finishApp` to wrap up
    
    310
    -
    
    311
    -The funcion `finishApp` mainly calls `rebuildHsApps` to rebuild the
    
    312
    -application; but it also has a horrile special case for `tagToEnum`.
    
    303
    +7. The function `finishApp` mainly calls `rebuildHsApps` to rebuild the
    
    304
    +   application; but it also has a horrible special case for `tagToEnum`.
    
    313 305
     
    
    314 306
     Note [Quick Look for particular Ids]
    
    315 307
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    ... ... @@ -328,6 +320,53 @@ particular Ids:
    328 320
       so that (f `op`), say, will work OK even if `f` is higher rank.
    
    329 321
       See Note [Left and right sections] in GHC.Rename.Expr.
    
    330 322
     
    
    323
    +Note [QuickLook: arguments before result]
    
    324
    +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    325
    +Generally we try to push the expected result type into the call;
    
    326
    +see Note [Unify with expected type before typechecking arguments].
    
    327
    +But surprisingly we can't do that for QuickLook.  (#26599 was a failed
    
    328
    +attempt to suggest this.)  Consider
    
    329
    +   h :: (Int->Int) -> Int    ids :: [forall a. a->a]
    
    330
    +and the call
    
    331
    +   h (head ids)
    
    332
    +Let's say we instantiate `head :: [a] -> a` with `a:=kappa`.
    
    333
    +We QuickLook at the argument with expected type (Int->Int). We must NOT
    
    334
    +unify kappa:=(Int->Int), because kappa:=forall a. a->a is the only
    
    335
    +solution, and one that we will find if we look at the argument first.
    
    336
    +
    
    337
    +TL;DR: we must do `quickLookArg` on all arguments before doing `quickLookResultType`
    
    338
    +on the result type.
    
    339
    +
    
    340
    +Remember: `quickLookResultType` is really anticipating a /subsumption/ test, not
    
    341
    +an equality test.  Doing `qlUnify` on the result type (always a rho-type) is
    
    342
    +in general wrong if there is an un-guarded kappa in the result type.  It's wrong
    
    343
    +UNLESS we have already gotten all the info about `kappa` (from the
    
    344
    +arguments) that we are going to get.  That's why we QuickLook the arguments first.
    
    345
    +
    
    346
    +This is a bit sad, as #26599 shows.  Consider
    
    347
    +
    
    348
    +  woo :: (x, [forall a. a->a])
    
    349
    +  bar1 = snd woo
    
    350
    +  bar2 = snd (id woo)
    
    351
    +
    
    352
    +For `bar1` we instantiate `snd` at [a:=k1,b:=k2].  Then we QL on the argument `woo`
    
    353
    +(instantiating with `x:=k3`).  Since the result type is guarded we qlUnify
    
    354
    +    (k3,forall a.a->a) ~ (k1,k2)
    
    355
    +and thus succeed in discovering k2:=forall a.a->a, as desired.
    
    356
    +
    
    357
    +But for `bar2` we fail. When quick-looking (id woo) we instantiate `id` with [a:=k],
    
    358
    +and quick-look the argument `woo` with expected type `k`.  That's not guarded,
    
    359
    +so we get no information.  Adding the `id` call makes it un-typeable. Boo.
    
    360
    +
    
    361
    +This is a bit tricky.
    
    362
    +* We QuickLook the arguments (tcInstFun)
    
    363
    +     THEN QuickLook the result type (quickLookResultType).
    
    364
    +  See this Note
    
    365
    +* and then...
    
    366
    +* We typecheck the result type (checkResultTy)
    
    367
    +     THEN typecheck the arguments (tcValArgs)
    
    368
    +  see Note [Unify with expected type before typechecking arguments]
    
    369
    +
    
    331 370
     Note [Unify with expected type before typechecking arguments]
    
    332 371
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    333 372
     Consider this (#19364)
    
    ... ... @@ -353,7 +392,7 @@ Unify result type /before/ typechecking the args
    353 392
             Actual: String
    
    354 393
         • In the first argument of ‘Pair’, namely ‘"yes"’
    
    355 394
     
    
    356
    -The latter is much better. That is why we call `checkResultTy` before tcValArgs.
    
    395
    +The latter is much better. That is why we call `checkResultTy` before `tcValArgs`.
    
    357 396
     -}
    
    358 397
     
    
    359 398
     --------------------
    
    ... ... @@ -365,18 +404,18 @@ tcApp :: HsExpr GhcRn -- ^ The whole application (For error messages)
    365 404
     -- See Note [tcApp: typechecking applications]
    
    366 405
     -- See Note [splitHsApps] in GHC.Tc.Head
    
    367 406
     tcApp rn_expr rn_fun rn_args exp_res_ty
    
    368
    -  = do { fun_lspan <- getFunSrcSpan rn_args
    
    407
    +  = do { do_ql     <- wantQuickLook rn_fun
    
    408
    +       ; fun_lspan <- getFunSrcSpan rn_args
    
    369 409
            ; traceTc "tcApp {" $
    
    370 410
                vcat [ text "rn_fun:" <+> ppr rn_fun
    
    371 411
                     , text "fun_lspan:" <+> ppr fun_lspan
    
    372 412
                     , text "rn_args:" <+> ppr rn_args ]
    
    373 413
     
    
    374
    -       ; let rn_head = (rn_fun, fun_lspan)
    
    375 414
     
    
    376 415
            -- Step 1: Infer the type of `fun`, the head of the application
    
    416
    +       ; let rn_head = (rn_fun, fun_lspan)
    
    377 417
            ; (tc_fun, fun_sigma) <- tcInferAppHead rn_head
    
    378
    -       ; let tc_head = (tc_fun, fun_lspan)
    
    379
    -             -- inst_final: top-instantiate the result type of the application,
    
    418
    +       ; let -- inst_final: top-instantiate the result type of the application,
    
    380 419
                  -- EXCEPT if we are trying to infer a sigma-type
    
    381 420
                  inst_final = case exp_res_ty of
    
    382 421
                                  Check {} -> True
    
    ... ... @@ -386,75 +425,73 @@ tcApp rn_expr rn_fun rn_args exp_res_ty
    386 425
                                       IIF_DeepRho    -> True
    
    387 426
                                       IIF_Sigma      -> False
    
    388 427
     
    
    389
    -       -- Step 2: Instantiate the function type (taking a quick look at args)
    
    390
    -       -- See Note [Quick Look for particular Ids]
    
    391
    -       ; do_ql <- wantQuickLook rn_fun
    
    392
    -
    
    393 428
            ; traceTc "tcApp:inferAppHead" $
    
    394 429
              vcat [ text "tc_fun:" <+> ppr tc_fun
    
    395 430
                   , text "fun_sigma:" <+> ppr fun_sigma
    
    396 431
                   , text "do_ql:" <+> ppr do_ql]
    
    397
    -       ; (inst_args, app_res_rho)
    
    398
    -              <- tcInstFun do_ql inst_final rn_head tc_fun fun_sigma rn_args
    
    399
    -         -- See (TCAPP1) and (TCAPP2) in
    
    400
    -         -- Note [tcApp: typechecking applications]
    
    401
    -
    
    402
    -       ; case do_ql of
    
    403
    -            NoQL -> do { traceTc "tcApp:NoQL" (ppr rn_fun $$ ppr app_res_rho)
    
    404
    -
    
    405
    -                         -- Step 3.1: subsumption check against expected result type
    
    406
    -                         -- See Note [Unify with expected type before typechecking arguments]
    
    407
    -                       ; res_wrap <- checkResultTy rn_expr tc_head inst_args
    
    408
    -                                                   app_res_rho exp_res_ty
    
    409
    -                         -- Step 3.2: typecheck the  arguments
    
    410
    -                       ; tc_args <- tcValArgs NoQL rn_head inst_args
    
    411
    -
    
    412
    -                         -- Step 3.3: wrap up
    
    413
    -                       ; finishApp tc_fun tc_args app_res_rho res_wrap }
    
    414
    -
    
    415
    -            DoQL -> do { traceTc "tcApp:DoQL" (ppr rn_fun $$ ppr app_res_rho)
    
    416
    -
    
    417
    -                         -- Step 4.1: Take a quick look at the result type
    
    418
    -                       ; quickLookResultType app_res_rho exp_res_ty
    
    419
    -
    
    420
    -                         -- Step 4.2: typecheck the arguments, and monomorphise
    
    421
    -                         --           any un-unified instantiation variables
    
    422
    -                       ; tc_args <- tcValArgs DoQL rn_head inst_args
    
    423
    -
    
    424
    -                         -- Step 4.3: zonk to expose the polymorphism hidden under
    
    425
    -                         --           QuickLook instantiation variables in `app_res_rho`
    
    426
    -                       ; app_res_rho <- liftZonkM $ zonkTcType app_res_rho
    
    427
    -
    
    428
    -                         -- Step 4.4: subsumption check against the expected type
    
    429
    -                       ; res_wrap <- checkResultTy rn_expr tc_head inst_args
    
    430
    -                                                    app_res_rho exp_res_ty
    
    431
    -                         -- Step 4.5: wrap up
    
    432
    -                       ; finishApp tc_fun tc_args app_res_rho res_wrap } }
    
    433
    -
    
    434
    -quickLookResultType :: TcRhoType -> ExpRhoType -> TcM ()
    
    435
    --- This function implements the shaded bit of rule APP-Downarrow in
    
    436
    --- Fig 5 of the QL paper: "A quick look at impredicativity" (ICFP'20).
    
    437
    -quickLookResultType app_res_rho (Check exp_rho) = qlUnify app_res_rho exp_rho
    
    438
    -quickLookResultType _           _               = return ()
    
    439 432
     
    
    440
    -finishApp :: HsExpr GhcTc -> [HsExprArg 'TcpTc]
    
    441
    -          -> TcRhoType -> HsWrapper
    
    433
    +       -- Step 2: Instantiate the function type (taking a quick look at args)
    
    434
    +       -- See Note [Quick Look for particular Ids]
    
    435
    +       ; (inst_args, app_res_rho) <- tcInstFun do_ql inst_final rn_head tc_fun fun_sigma rn_args
    
    436
    +
    
    437
    +       ; -- Step 3: Take a quick look at the result type
    
    438
    +         -- See Note [QuickLook: arguments before result]
    
    439
    +         case (do_ql, exp_res_ty) of
    
    440
    +            (DoQL, Check exp_rho) -> quickLookResultType app_res_rho exp_rho
    
    441
    +            _                     -> return ()
    
    442
    +
    
    443
    +       ; finishApp do_ql rn_expr fun_lspan rn_fun tc_fun
    
    444
    +                         inst_args app_res_rho exp_res_ty }
    
    445
    +
    
    446
    +finishApp :: QLFlag
    
    447
    +          -> HsExpr GhcRn           -- The whole application
    
    448
    +          -> SrcSpan                -- Span for the /head/ of the application
    
    449
    +          -> HsExpr GhcRn           -- The head of the application (renamed)
    
    450
    +          -> HsExpr GhcTc           -- The head of the application (typechecked)
    
    451
    +          -> [HsExprArg 'TcpInst]   -- Arguments
    
    452
    +          -> TcRhoType -> ExpRhoType
    
    442 453
               -> TcM (HsExpr GhcTc)
    
    443
    --- Do final checks and wrap up the result
    
    444
    -finishApp tc_fun tc_args app_res_rho res_wrap
    
    445
    -  = do {
    
    446
    -       -- Reconstruct, with a horrible special case for tagToEnum#.
    
    447
    -         res_expr <- if isTagToEnum tc_fun
    
    454
    +-- Instantiation and Quick Look are done.  Now do typechecking,
    
    455
    +-- of both the result type and the arguments, before rebuilding.
    
    456
    +finishApp do_ql rn_expr fun_loc rn_fun tc_fun inst_args
    
    457
    +          app_res_rho exp_res_ty
    
    458
    +  = do { -- Step 4.1: monomorphise un-unified QuickLook instantiation variables
    
    459
    +         -- Step 4.2: zonk app_res_rho to expose the polymorphism hidden under
    
    460
    +         --           instantiation variables in `app_res_rho`
    
    461
    +         app_res_rho <- case do_ql of
    
    462
    +           NoQL -> return app_res_rho
    
    463
    +           DoQL -> liftZonkM $
    
    464
    +                   do { qlMonoInstArgs inst_args
    
    465
    +                      ; zonkTcType app_res_rho }
    
    466
    +
    
    467
    +         -- Step 5: subsumption check against the expected type
    
    468
    +         -- See Note [Unify with expected type before typechecking arguments]
    
    469
    +       ; res_wrap <- checkResultTy rn_expr (tc_fun, fun_loc) inst_args
    
    470
    +                                   app_res_rho exp_res_ty
    
    471
    +
    
    472
    +         -- Step 6: Typecheck the arguments
    
    473
    +       ; tc_args <- tcValArgs do_ql (rn_fun, fun_loc) inst_args
    
    474
    +
    
    475
    +         -- Step 7: Horrible special case for tagToEnum#.
    
    476
    +       ; res_expr <- if isTagToEnum tc_fun
    
    448 477
                          then tcTagToEnum tc_fun tc_args app_res_rho
    
    449 478
                          else return (rebuildHsApps tc_fun tc_args)
    
    479
    +
    
    450 480
            ; traceTc "End tcApp }" (ppr tc_fun)
    
    451 481
            ; return (mkHsWrap res_wrap res_expr) }
    
    452 482
     
    
    483
    +quickLookResultType :: TcRhoType -> TcRhoType -> TcM ()
    
    484
    +-- This function implements the shaded bit of rule APP-Downarrow in
    
    485
    +-- Fig 5 of the QL paper: "A quick look at impredicativity" (ICFP'20).
    
    486
    +-- See Note [QuickLook: arguments before result]
    
    487
    +quickLookResultType app_res_rho exp_res_rho
    
    488
    +  = qlUnify app_res_rho exp_res_rho
    
    489
    +
    
    453 490
     -- | Connect up the inferred type of an application with the expected type.
    
    454 491
     -- This is usually just a unification, but with deep subsumption there is more to do.
    
    455 492
     checkResultTy :: HsExpr GhcRn
    
    456 493
                   -> (HsExpr GhcTc, SrcSpan)  -- Head
    
    457
    -              -> [HsExprArg p]            -- Arguments, just error messages
    
    494
    +              -> [HsExprArg p]            -- Arguments, just for error messages
    
    458 495
                   -> TcRhoType  -- Inferred type of the application; zonked to
    
    459 496
                                 --   expose foralls, but maybe not /deeply/ instantiated
    
    460 497
                   -> 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
    476 513
     
    
    477 514
     ----------------
    
    478 515
     tcValArgs :: QLFlag
    
    479
    -          -> (HsExpr GhcRn, SrcSpan) -- Head of the application chain (used only for error message generation)
    
    516
    +          -> (HsExpr GhcRn, SrcSpan) -- Head of the application chain
    
    517
    +                                     -- (used only for error message generation)
    
    480 518
               -> [HsExprArg 'TcpInst]
    
    481 519
               -> TcM [HsExprArg 'TcpTc]
    
    482
    --- Importantly, tcValArgs works left-to-right, so that by the time we
    
    483
    --- encounter an argument, we have monomorphised all the instantiation
    
    484
    --- variables that its type contains.  All that is left to do is an ordinary
    
    485
    --- zonkTcType.  See Note [Monomorphise instantiation variables].
    
    486 520
     tcValArgs do_ql rn_head args = go do_ql 0 args
    
    487 521
       where
    
    488 522
         go _ _ [] = return []
    
    ... ... @@ -505,16 +539,15 @@ tcValArg :: QLFlag -- ^ Are we typechecking with Quick Look tur
    505 539
              -> (HsExpr GhcRn, SrcSpan) -- ^ Head of the application chain (used only for error message generation)
    
    506 540
              -> HsExprArg 'TcpInst      -- ^ Actual argument
    
    507 541
              -> TcM (HsExprArg 'TcpTc)  -- ^ Resulting argument
    
    508
    -tcValArg _     _ _ (EPrag l p)         = return (EPrag l (tcExprPrag p))
    
    509
    -tcValArg _     _ _ (ETypeArg l hty ty) = return (ETypeArg l hty ty)
    
    510
    -tcValArg do_ql _ _ (EWrap (EHsWrap w)) = do { whenQL do_ql $ qlMonoHsWrapper w
    
    511
    -                                            ; return (EWrap (EHsWrap w)) }
    
    512
    -  -- qlMonoHsWrapper: see Note [Monomorphise instantiation variables]
    
    513
    -tcValArg _     _ _ (EWrap ew)          = return (EWrap ew)
    
    514
    -
    
    515
    -tcValArg do_ql pos rn_fun_head (EValArg { ea_loc_span  = lspan
    
    516
    -                            , ea_arg    = larg@(L arg_loc arg)
    
    517
    -                            , ea_arg_ty = sc_arg_ty })
    
    542
    +tcValArg _ _ _ (EPrag l p)         = return (EPrag l (tcExprPrag p))
    
    543
    +tcValArg _ _ _ (ETypeArg l hty ty) = return (ETypeArg l hty ty)
    
    544
    +tcValArg _ _ _ (EWrap (EHsWrap w)) = return (EWrap (EHsWrap w))
    
    545
    +tcValArg _ _ _ (EWrap ew)          = return (EWrap ew)
    
    546
    +
    
    547
    +tcValArg do_ql pos rn_fun_head
    
    548
    +         (EValArg { ea_loc_span  = lspan
    
    549
    +                  , ea_arg    = larg@(L arg_loc arg)
    
    550
    +                  , ea_arg_ty = sc_arg_ty })
    
    518 551
       = addArgCtxt pos rn_fun_head larg $
    
    519 552
         do { -- Crucial step: expose QL results before checking exp_arg_ty
    
    520 553
              -- 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
    546 579
                              , ea_arg = L arg_loc arg'
    
    547 580
                              , ea_arg_ty = noExtField }) }
    
    548 581
     
    
    549
    -tcValArg _ pos rn_fun_head (EValArgQL {
    
    550
    -                        eaql_wanted   = wanted
    
    551
    -                      , eaql_loc_span = lspan
    
    552
    -                      , eaql_arg_ty   = sc_arg_ty
    
    553
    -                      , eaql_larg     = larg@(L arg_loc rn_expr)
    
    554
    -                      , eaql_tc_fun   = tc_arg_head@(tc_fun,arg_head_loc)
    
    555
    -                      , eaql_rn_fun   = rn_arg_head
    
    556
    -                      , eaql_fun_ue   = head_ue
    
    557
    -                      , eaql_args     = inst_args
    
    558
    -                      , eaql_encl     = arg_influences_enclosing_call
    
    559
    -                      , eaql_res_rho  = app_res_rho })
    
    582
    +tcValArg _ pos rn_fun_head
    
    583
    +         (EValArgQL { eaql_wanted   = wanted
    
    584
    +                    , eaql_loc_span = lspan
    
    585
    +                    , eaql_arg_ty   = sc_arg_ty
    
    586
    +                    , eaql_larg     = larg@(L arg_loc rn_expr)
    
    587
    +                    , eaql_rn_fun   = rn_fun
    
    588
    +                    , eaql_tc_fun   = tc_arg_head@(tc_fun,arg_head_loc)
    
    589
    +                    , eaql_fun_ue   = head_ue
    
    590
    +                    , eaql_args     = inst_args
    
    591
    +                    , eaql_encl     = arg_influences_enclosing_call
    
    592
    +                    , eaql_res_rho  = app_res_rho })
    
    560 593
       = addArgCtxt pos rn_fun_head larg $
    
    561 594
         do { -- Expose QL results to tcSkolemise, as in EValArg case
    
    562 595
              Scaled mult exp_arg_ty <- liftZonkM $ zonkScaledTcType sc_arg_ty
    
    ... ... @@ -582,14 +615,11 @@ tcValArg _ pos rn_fun_head (EValArgQL {
    582 615
     
    
    583 616
                         -- Unify with context if we have not already done so
    
    584 617
                         -- See (QLA4) in Note [Quick Look at value arguments]
    
    585
    -                  ; unless arg_influences_enclosing_call $  -- Don't repeat
    
    586
    -                    qlUnify app_res_rho exp_arg_rho         -- the qlUnify
    
    618
    +                  ; unless arg_influences_enclosing_call $   -- Don't repeat
    
    619
    +                    qlUnify app_res_rho exp_arg_rho          -- the qlUnify
    
    587 620
     
    
    588
    -                  ; tc_args <- tcValArgs DoQL (rn_arg_head, arg_head_loc) inst_args
    
    589
    -                  ; app_res_rho <- liftZonkM $ zonkTcType app_res_rho
    
    590
    -                  ; res_wrap <- checkResultTy rn_expr tc_arg_head inst_args
    
    591
    -                                              app_res_rho (mkCheckExpType exp_arg_rho)
    
    592
    -                  ; finishApp tc_fun tc_args app_res_rho res_wrap }
    
    621
    +                  ; finishApp DoQL rn_expr arg_head_loc rn_fun tc_fun inst_args app_res_rho
    
    622
    +                              (mkCheckExpType exp_arg_rho) }
    
    593 623
     
    
    594 624
            ; traceTc "tcEValArgQL }" $
    
    595 625
                vcat [ text "app_res_rho:" <+> ppr app_res_rho ]
    
    ... ... @@ -606,6 +636,13 @@ wantQuickLook (HsVar _ (L _ (WithUserRdr _ f)))
    606 636
     wantQuickLook _                      = do { impred <- xoptM LangExt.ImpredicativeTypes
    
    607 637
                                               ; if impred then return DoQL else return NoQL }
    
    608 638
     
    
    639
    +skipQuickLook :: HsExprLoc -> LHsExpr GhcRn -> Scaled TcRhoType
    
    640
    +              -> TcM (HsExprArg 'TcpInst)
    
    641
    +skipQuickLook loc larg arg_ty
    
    642
    +  = return (EValArg { ea_loc_span = loc
    
    643
    +                    , ea_arg      = larg
    
    644
    +                    , ea_arg_ty   = arg_ty })
    
    645
    +
    
    609 646
     quickLookKeys :: [Unique]
    
    610 647
     -- See Note [Quick Look for particular Ids]
    
    611 648
     quickLookKeys = [dollarIdKey, leftSectionKey, rightSectionKey]
    
    ... ... @@ -1860,17 +1897,6 @@ quickLookArg DoQL pos app_lspan fun_and_lspan larg orig_arg_ty
    1860 1897
              then skipQuickLook app_lspan larg orig_arg_ty
    
    1861 1898
              else quickLookArg1 pos app_lspan fun_and_lspan larg orig_arg_ty }
    
    1862 1899
     
    
    1863
    -skipQuickLook :: HsExprLoc -> LHsExpr GhcRn -> Scaled TcRhoType
    
    1864
    -              -> TcM (HsExprArg 'TcpInst)
    
    1865
    -skipQuickLook app_lspan larg arg_ty
    
    1866
    -  = return (EValArg { ea_loc_span   = app_lspan
    
    1867
    -                    , ea_arg    = larg
    
    1868
    -                    , ea_arg_ty = arg_ty })
    
    1869
    -
    
    1870
    -whenQL :: QLFlag -> ZonkM () -> TcM ()
    
    1871
    -whenQL DoQL thing_inside = liftZonkM thing_inside
    
    1872
    -whenQL NoQL _            = return ()
    
    1873
    -
    
    1874 1900
     qlArgHasRhoType :: TcType -> TcM Bool
    
    1875 1901
     -- `qlArgHasRhoType` checks that the expected argument type in rule
    
    1876 1902
     -- 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_
    1959 1985
                  <- captureConstraints $
    
    1960 1986
                     tcInstFun do_ql True (rn_fun_arg, fun_lspan_arg) tc_fun_arg_head fun_sigma_arg_head rn_args
    
    1961 1987
                     -- We must capture type-class and equality constraints here, but
    
    1962
    -                -- not usage information.  See (QLA6) in Note [Quick Look at
    
    1988
    +                -- not usage constraints.  See (QLA6) in Note [Quick Look at
    
    1963 1989
                     -- value arguments]
    
    1964 1990
     
    
    1965 1991
            ; traceTc "quickLookArg 2" $
    
    ... ... @@ -1969,13 +1995,16 @@ quickLookArg1 pos app_lspan rn_head larg@(L _ arg) sc_arg_ty@(Scaled _ orig_arg_
    1969 1995
     
    
    1970 1996
            -- Step 3: Check the two other premises of APP-lightning-bolt (Fig 5 in the paper)
    
    1971 1997
            --         Namely: (A) is orig_arg_rho is guarded
    
    1972
    -         --           or: (B) fiv(app_res_rho) = emptyset
    
    1998
    +       --             or: (B) fiv(app_res_rho) = emptyset
    
    1999
    +       -- then Step 4: do quick-look unification if either (A) or (B) hold
    
    2000
    +       --
    
    2001
    +       -- For (B) see Note [The fiv test in quickLookArg]
    
    1973 2002
            -- This tells us if the quick look at the argument yields information that
    
    1974 2003
            -- influences the enclosing function call
    
    1975
    -       -- NB: guardedness is computed based on the original,
    
    1976
    -       -- unzonked orig_arg_rho, so that we deliberately do
    
    1977
    -       -- not exploit guardedness that emerges a result of QL on earlier args
    
    1978
    -       -- We must do the anyFreeKappa test /after/ tcInstFun; see (QLA3).
    
    2004
    +       -- NB: `isGuardedTy` is computed based on the original,
    
    2005
    +       --         unzonked orig_arg_rho, so that we deliberately do not exploit
    
    2006
    +       --         guardedness that emerges a result of QL on earlier args
    
    2007
    +       --     In contrast, we must do the `anyFreeKappa` test /after/ tcInstFun; see (QLA3).
    
    1979 2008
            ; arg_influences_enclosing_call
    
    1980 2009
                 <- if isGuardedTy orig_arg_rho
    
    1981 2010
                    then return True
    
    ... ... @@ -1983,6 +2012,7 @@ quickLookArg1 pos app_lspan rn_head larg@(L _ arg) sc_arg_ty@(Scaled _ orig_arg_
    1983 2012
                         -- For (B) see Note [The fiv test in quickLookArg]
    
    1984 2013
     
    
    1985 2014
            -- Step 4: do quick-look unification if either (A) or (B) hold
    
    2015
    +       -- This is part of APP-lightning-bolt (Fig 5 in the paper)
    
    1986 2016
            -- NB: orig_arg_rho may not be zonked, but that's ok
    
    1987 2017
            ; when arg_influences_enclosing_call $
    
    1988 2018
              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_
    2000 2030
                                , eaql_encl     = arg_influences_enclosing_call
    
    2001 2031
                                , eaql_res_rho  = app_res_rho }) }}}
    
    2002 2032
     
    
    2003
    -
    
    2004 2033
     {- *********************************************************************
    
    2005 2034
     *                                                                      *
    
    2006 2035
                      Folding over instantiation variables
    
    ... ... @@ -2014,20 +2043,16 @@ When we are done with Quick Look on a call, we must turn any un-unified
    2014 2043
     lower-case 'theta' (a mono-substitution) in the APP-DOWN rule of Fig 5 of the
    
    2015 2044
     Quick Look paper.
    
    2016 2045
     
    
    2017
    -We so this by look at the arguments, left to right, monomorphising the free
    
    2018
    -instantiation variables of the /type/ arguments of the call.  Those type
    
    2019
    -arguments appear (only) in
    
    2046
    +We do this in `qlMonoInstArgs` by looking at the arguments, monomorphising
    
    2047
    +the free instantiation variables of the /type/ arguments of the call.  Those
    
    2048
    +type arguments appear (only) in
    
    2020 2049
       * the `WpTyApp` components of
    
    2021 2050
       * the `HsWrapper` of
    
    2022 2051
       * a `EWrap` argument
    
    2023
    -See `qlMonoHsWrapper`.
    
    2024
    -
    
    2025
    -By going left to right, we are sure to monomorphise instantiation variables
    
    2026
    -before we encounter them in an argument type (in `tcValArg`).
    
    2027 2052
     
    
    2028 2053
     All instantiation variables for a call will be reachable from the type(s)
    
    2029 2054
     at which the function is instantiated -- i.e. those WpTyApps.  Even instantiation
    
    2030
    -variables allocoated by tcInstFun itself, such as in the IRESULT rule, end up
    
    2055
    +variables allocated by tcInstFun itself, such as in the IRESULT rule, end up
    
    2031 2056
     connected to the original type(s) at which the function is instantiated.
    
    2032 2057
     
    
    2033 2058
     To monomorphise the free QL instantiation variables of a type, we use
    
    ... ... @@ -2048,6 +2073,16 @@ Wrinkles:
    2048 2073
       we want to monomrphise it.  Hence the do_hole in `foldQLInstTyVars`
    
    2049 2074
     -}
    
    2050 2075
     
    
    2076
    +
    
    2077
    +qlMonoInstArgs :: [HsExprArg 'TcpInst] -> ZonkM ()
    
    2078
    +-- See Note [Monomorphise instantiation variables]
    
    2079
    +qlMonoInstArgs args = mapM_ qlMonoInstArg args
    
    2080
    +
    
    2081
    +qlMonoInstArg :: HsExprArg 'TcpInst -> ZonkM ()
    
    2082
    +-- See Note [Monomorphise instantiation variables]
    
    2083
    +qlMonoInstArg (EWrap (EHsWrap w)) = qlMonoHsWrapper w
    
    2084
    +qlMonoInstArg _                   = return ()
    
    2085
    +
    
    2051 2086
     qlMonoHsWrapper :: HsWrapper -> ZonkM ()
    
    2052 2087
     -- See Note [Monomorphise instantiation variables]
    
    2053 2088
     qlMonoHsWrapper (WpCompose w1 w2) = qlMonoHsWrapper w1 >> qlMonoHsWrapper w2
    
    ... ... @@ -2108,13 +2143,14 @@ We will instantiate Just with kappa, say, and then call
    2108 2143
         quickLookArg1 False {kappa} (ids ++ ids) kappa
    
    2109 2144
     The call to tcInstFun will return with app_res_rho = [forall a. a->a]
    
    2110 2145
     which has no free instantiation variables, so we can QL-unify
    
    2111
    -  kappa ~ [Forall a. a->a]
    
    2146
    +  kappa ~ [forall a. a->a]
    
    2112 2147
     -}
    
    2113 2148
     
    
    2114 2149
     anyFreeKappa :: TcType -> TcM Bool
    
    2115 2150
     -- True if there is a free instantiation variable
    
    2116 2151
     -- in the argument type, after zonking
    
    2117 2152
     -- See Note [The fiv test in quickLookArg]
    
    2153
    +-- The function is monadic; it does not require a zonked type as input
    
    2118 2154
     anyFreeKappa ty = unTcMBool (foldQLInstVars go_tv ty)
    
    2119 2155
       where
    
    2120 2156
         go_tv tv = TCMB $ do { info <- readMetaTyVar tv
    

  • compiler/GHC/ThToHs.hs
    ... ... @@ -434,7 +434,7 @@ cvtDec (ClosedTypeFamilyD head eqns)
    434 434
       = do { (tc', tyvars', result', injectivity') <- cvt_tyfam_head head
    
    435 435
            ; eqns' <- mapM cvtTySynEqn eqns
    
    436 436
            ; returnJustLA $ TyClD noExtField $ FamDecl noExtField $
    
    437
    -         FamilyDecl noAnn (ClosedTypeFamily noExtField (Just eqns')) TopLevel tc' tyvars' Prefix
    
    437
    +         FamilyDecl noAnn (ClosedTypeFamily noAnn (Just eqns')) TopLevel tc' tyvars' Prefix
    
    438 438
                                result' injectivity' }
    
    439 439
     
    
    440 440
     cvtDec (TH.RoleAnnotD tc roles)
    

  • testsuite/tests/ghci.debugger/scripts/T14628.stderr
    1
    -<interactive>:4:7: error: [GHC-25897]
    
    1
    +<interactive>:4:17: error: [GHC-25897]
    
    2 2
         • Couldn't match type ‘m’ with ‘(,) a0’
    
    3
    -      Expected: (a0, ((), Int))
    
    4
    -        Actual: m ((), Int)
    
    3
    +      Expected: StateT Int ((,) a0) ()
    
    4
    +        Actual: StateT Int m ()
    
    5 5
           ‘m’ is an interactive-debugger skolem
    
    6
    -    • In the second argument of ‘($)’, namely ‘runStateT _result 0’
    
    6
    +    • In the first argument of ‘runStateT’, namely ‘_result’
    
    7
    +      In the second argument of ‘($)’, namely ‘runStateT _result 0’
    
    7 8
           In the expression: snd $ runStateT _result 0
    
    8
    -      In an equation for ‘it’: it = snd $ runStateT _result 0
    
    9 9
     

  • testsuite/tests/haddock/should_compile_flag_haddock/T17544.stderr
    ... ... @@ -926,10 +926,8 @@
    926 926
                  (EpaSpan { <no location info> }))
    
    927 927
                 (EpTok
    
    928 928
                  (EpaSpan { <no location info> }))
    
    929
    -            (EpTok (EpaSpan { <no location info> }))
    
    930 929
                 (EpTok
    
    931
    -             (EpaSpan { <no location info> }))
    
    932
    -            (EpTok (EpaSpan { <no location info> })))
    
    930
    +             (EpaSpan { <no location info> })))
    
    933 931
                (DataFamily
    
    934 932
                 (NoExtField))
    
    935 933
                (NotTopLevel)
    
    ... ... @@ -1001,9 +999,11 @@
    1001 999
              (EpTok (EpaSpan { T17544.hs:23:1-8 }))
    
    1002 1000
              (EpTok
    
    1003 1001
               (EpaSpan { T17544.hs:23:17-21 }))
    
    1004
    -         (EpTok (EpaSpan { <no location info> }))
    
    1005
    -         []
    
    1006
    -         (EpTok (EpaSpan { <no location info> }))))
    
    1002
    +         (AnnList
    
    1003
    +          (AnnListLayout
    
    1004
    +           (EpaSpan { T17544.hs:24:3 }))
    
    1005
    +          (ListNone)
    
    1006
    +          [])))
    
    1007 1007
            []
    
    1008 1008
            (L
    
    1009 1009
             (EpAnn
    
    ... ... @@ -1322,10 +1322,8 @@
    1322 1322
                  (EpaSpan { <no location info> }))
    
    1323 1323
                 (EpTok
    
    1324 1324
                  (EpaSpan { <no location info> }))
    
    1325
    -            (EpTok (EpaSpan { <no location info> }))
    
    1326 1325
                 (EpTok
    
    1327
    -             (EpaSpan { <no location info> }))
    
    1328
    -            (EpTok (EpaSpan { <no location info> })))
    
    1326
    +             (EpaSpan { <no location info> })))
    
    1329 1327
                (DataFamily
    
    1330 1328
                 (NoExtField))
    
    1331 1329
                (NotTopLevel)
    
    ... ... @@ -1397,9 +1395,11 @@
    1397 1395
              (EpTok (EpaSpan { T17544.hs:29:1-8 }))
    
    1398 1396
              (EpTok
    
    1399 1397
               (EpaSpan { T17544.hs:29:17-21 }))
    
    1400
    -         (EpTok (EpaSpan { <no location info> }))
    
    1401
    -         []
    
    1402
    -         (EpTok (EpaSpan { <no location info> }))))
    
    1398
    +         (AnnList
    
    1399
    +          (AnnListLayout
    
    1400
    +           (EpaSpan { T17544.hs:30:3 }))
    
    1401
    +          (ListNone)
    
    1402
    +          [])))
    
    1403 1403
            []
    
    1404 1404
            (L
    
    1405 1405
             (EpAnn
    
    ... ... @@ -1718,10 +1718,8 @@
    1718 1718
                  (EpaSpan { <no location info> }))
    
    1719 1719
                 (EpTok
    
    1720 1720
                  (EpaSpan { <no location info> }))
    
    1721
    -            (EpTok (EpaSpan { <no location info> }))
    
    1722 1721
                 (EpTok
    
    1723
    -             (EpaSpan { <no location info> }))
    
    1724
    -            (EpTok (EpaSpan { <no location info> })))
    
    1722
    +             (EpaSpan { <no location info> })))
    
    1725 1723
                (DataFamily
    
    1726 1724
                 (NoExtField))
    
    1727 1725
                (NotTopLevel)
    
    ... ... @@ -1793,9 +1791,11 @@
    1793 1791
              (EpTok (EpaSpan { T17544.hs:35:1-8 }))
    
    1794 1792
              (EpTok
    
    1795 1793
               (EpaSpan { T17544.hs:35:17-21 }))
    
    1796
    -         (EpTok (EpaSpan { <no location info> }))
    
    1797
    -         []
    
    1798
    -         (EpTok (EpaSpan { <no location info> }))))
    
    1794
    +         (AnnList
    
    1795
    +          (AnnListLayout
    
    1796
    +           (EpaSpan { T17544.hs:36:3 }))
    
    1797
    +          (ListNone)
    
    1798
    +          [])))
    
    1799 1799
            []
    
    1800 1800
            (L
    
    1801 1801
             (EpAnn
    
    ... ... @@ -2114,10 +2114,8 @@
    2114 2114
                  (EpaSpan { <no location info> }))
    
    2115 2115
                 (EpTok
    
    2116 2116
                  (EpaSpan { <no location info> }))
    
    2117
    -            (EpTok (EpaSpan { <no location info> }))
    
    2118 2117
                 (EpTok
    
    2119
    -             (EpaSpan { <no location info> }))
    
    2120
    -            (EpTok (EpaSpan { <no location info> })))
    
    2118
    +             (EpaSpan { <no location info> })))
    
    2121 2119
                (DataFamily
    
    2122 2120
                 (NoExtField))
    
    2123 2121
                (NotTopLevel)
    
    ... ... @@ -2189,9 +2187,11 @@
    2189 2187
              (EpTok (EpaSpan { T17544.hs:41:1-8 }))
    
    2190 2188
              (EpTok
    
    2191 2189
               (EpaSpan { T17544.hs:41:17-21 }))
    
    2192
    -         (EpTok (EpaSpan { <no location info> }))
    
    2193
    -         []
    
    2194
    -         (EpTok (EpaSpan { <no location info> }))))
    
    2190
    +         (AnnList
    
    2191
    +          (AnnListLayout
    
    2192
    +           (EpaSpan { T17544.hs:42:3 }))
    
    2193
    +          (ListNone)
    
    2194
    +          [])))
    
    2195 2195
            []
    
    2196 2196
            (L
    
    2197 2197
             (EpAnn
    
    ... ... @@ -2510,10 +2510,8 @@
    2510 2510
                  (EpaSpan { <no location info> }))
    
    2511 2511
                 (EpTok
    
    2512 2512
                  (EpaSpan { <no location info> }))
    
    2513
    -            (EpTok (EpaSpan { <no location info> }))
    
    2514 2513
                 (EpTok
    
    2515
    -             (EpaSpan { <no location info> }))
    
    2516
    -            (EpTok (EpaSpan { <no location info> })))
    
    2514
    +             (EpaSpan { <no location info> })))
    
    2517 2515
                (DataFamily
    
    2518 2516
                 (NoExtField))
    
    2519 2517
                (NotTopLevel)
    
    ... ... @@ -2585,9 +2583,11 @@
    2585 2583
              (EpTok (EpaSpan { T17544.hs:47:1-8 }))
    
    2586 2584
              (EpTok
    
    2587 2585
               (EpaSpan { T17544.hs:47:17-21 }))
    
    2588
    -         (EpTok (EpaSpan { <no location info> }))
    
    2589
    -         []
    
    2590
    -         (EpTok (EpaSpan { <no location info> }))))
    
    2586
    +         (AnnList
    
    2587
    +          (AnnListLayout
    
    2588
    +           (EpaSpan { T17544.hs:48:3 }))
    
    2589
    +          (ListNone)
    
    2590
    +          [])))
    
    2591 2591
            []
    
    2592 2592
            (L
    
    2593 2593
             (EpAnn
    
    ... ... @@ -2906,10 +2906,8 @@
    2906 2906
                  (EpaSpan { <no location info> }))
    
    2907 2907
                 (EpTok
    
    2908 2908
                  (EpaSpan { <no location info> }))
    
    2909
    -            (EpTok (EpaSpan { <no location info> }))
    
    2910 2909
                 (EpTok
    
    2911
    -             (EpaSpan { <no location info> }))
    
    2912
    -            (EpTok (EpaSpan { <no location info> })))
    
    2910
    +             (EpaSpan { <no location info> })))
    
    2913 2911
                (DataFamily
    
    2914 2912
                 (NoExtField))
    
    2915 2913
                (NotTopLevel)
    
    ... ... @@ -2981,9 +2979,11 @@
    2981 2979
              (EpTok (EpaSpan { T17544.hs:53:1-8 }))
    
    2982 2980
              (EpTok
    
    2983 2981
               (EpaSpan { T17544.hs:53:18-22 }))
    
    2984
    -         (EpTok (EpaSpan { <no location info> }))
    
    2985
    -         []
    
    2986
    -         (EpTok (EpaSpan { <no location info> }))))
    
    2982
    +         (AnnList
    
    2983
    +          (AnnListLayout
    
    2984
    +           (EpaSpan { T17544.hs:54:3 }))
    
    2985
    +          (ListNone)
    
    2986
    +          [])))
    
    2987 2987
            []
    
    2988 2988
            (L
    
    2989 2989
             (EpAnn
    

  • testsuite/tests/parser/should_compile/DumpParsedAst.stderr
    ... ... @@ -359,12 +359,14 @@
    359 359
              (EpaSpan { <no location info> }))
    
    360 360
             (EpTok
    
    361 361
              (EpaSpan { DumpParsedAst.hs:10:41-45 }))
    
    362
    -        (EpTok (EpaSpan { <no location info> }))
    
    363 362
             (EpTok
    
    364
    -         (EpaSpan { <no location info> }))
    
    365
    -        (EpTok (EpaSpan { <no location info> })))
    
    363
    +         (EpaSpan { <no location info> })))
    
    366 364
            (ClosedTypeFamily
    
    367
    -        (NoExtField)
    
    365
    +        (AnnList
    
    366
    +         (AnnListLayout
    
    367
    +          (EpaSpan { DumpParsedAst.hs:11:3 }))
    
    368
    +         (ListNone)
    
    369
    +         [])
    
    368 370
             (Just
    
    369 371
              [(L
    
    370 372
                (EpAnn
    
    ... ... @@ -1144,12 +1146,14 @@
    1144 1146
              (EpaSpan { <no location info> }))
    
    1145 1147
             (EpTok
    
    1146 1148
              (EpaSpan { DumpParsedAst.hs:18:50-54 }))
    
    1147
    -        (EpTok (EpaSpan { <no location info> }))
    
    1148 1149
             (EpTok
    
    1149
    -         (EpaSpan { <no location info> }))
    
    1150
    -        (EpTok (EpaSpan { <no location info> })))
    
    1150
    +         (EpaSpan { <no location info> })))
    
    1151 1151
            (ClosedTypeFamily
    
    1152
    -        (NoExtField)
    
    1152
    +        (AnnList
    
    1153
    +         (AnnListLayout
    
    1154
    +          (EpaSpan { DumpParsedAst.hs:19:3 }))
    
    1155
    +         (ListNone)
    
    1156
    +         [])
    
    1153 1157
             (Just
    
    1154 1158
              [(L
    
    1155 1159
                (EpAnn
    
    ... ... @@ -1543,10 +1547,8 @@
    1543 1547
              (EpaSpan { <no location info> }))
    
    1544 1548
             (EpTok
    
    1545 1549
              (EpaSpan { <no location info> }))
    
    1546
    -        (EpTok (EpaSpan { <no location info> }))
    
    1547 1550
             (EpTok
    
    1548
    -         (EpaSpan { <no location info> }))
    
    1549
    -        (EpTok (EpaSpan { <no location info> })))
    
    1551
    +         (EpaSpan { <no location info> })))
    
    1550 1552
            (DataFamily
    
    1551 1553
             (NoExtField))
    
    1552 1554
            (TopLevel)
    

  • testsuite/tests/parser/should_compile/DumpRenamedAst.stderr
    ... ... @@ -306,12 +306,14 @@
    306 306
                (EpaSpan { <no location info> }))
    
    307 307
               (EpTok
    
    308 308
                (EpaSpan { <no location info> }))
    
    309
    -          (EpTok (EpaSpan { <no location info> }))
    
    310 309
               (EpTok
    
    311
    -           (EpaSpan { <no location info> }))
    
    312
    -          (EpTok (EpaSpan { <no location info> })))
    
    310
    +           (EpaSpan { <no location info> })))
    
    313 311
              (ClosedTypeFamily
    
    314
    -          (NoExtField)
    
    312
    +          (AnnList
    
    313
    +           (AnnListLayout
    
    314
    +            (EpaSpan { DumpRenamedAst.hs:13:3 }))
    
    315
    +           (ListNone)
    
    316
    +           [])
    
    315 317
               (Just
    
    316 318
                [(L
    
    317 319
                  (EpAnn
    
    ... ... @@ -795,10 +797,8 @@
    795 797
                (EpaSpan { <no location info> }))
    
    796 798
               (EpTok
    
    797 799
                (EpaSpan { <no location info> }))
    
    798
    -          (EpTok (EpaSpan { <no location info> }))
    
    799 800
               (EpTok
    
    800
    -           (EpaSpan { <no location info> }))
    
    801
    -          (EpTok (EpaSpan { <no location info> })))
    
    801
    +           (EpaSpan { <no location info> })))
    
    802 802
              (DataFamily
    
    803 803
               (NoExtField))
    
    804 804
              (TopLevel)
    
    ... ... @@ -1180,12 +1180,14 @@
    1180 1180
                (EpaSpan { <no location info> }))
    
    1181 1181
               (EpTok
    
    1182 1182
                (EpaSpan { <no location info> }))
    
    1183
    -          (EpTok (EpaSpan { <no location info> }))
    
    1184 1183
               (EpTok
    
    1185
    -           (EpaSpan { <no location info> }))
    
    1186
    -          (EpTok (EpaSpan { <no location info> })))
    
    1184
    +           (EpaSpan { <no location info> })))
    
    1187 1185
              (ClosedTypeFamily
    
    1188
    -          (NoExtField)
    
    1186
    +          (AnnList
    
    1187
    +           (AnnListLayout
    
    1188
    +            (EpaSpan { DumpRenamedAst.hs:26:3 }))
    
    1189
    +           (ListNone)
    
    1190
    +           [])
    
    1189 1191
               (Just
    
    1190 1192
                [(L
    
    1191 1193
                  (EpAnn
    
    ... ... @@ -1765,10 +1767,8 @@
    1765 1767
                    (EpaSpan { <no location info> }))
    
    1766 1768
                   (EpTok
    
    1767 1769
                    (EpaSpan { <no location info> }))
    
    1768
    -              (EpTok (EpaSpan { <no location info> }))
    
    1769 1770
                   (EpTok
    
    1770
    -               (EpaSpan { <no location info> }))
    
    1771
    -              (EpTok (EpaSpan { <no location info> })))
    
    1771
    +               (EpaSpan { <no location info> })))
    
    1772 1772
                  (OpenTypeFamily
    
    1773 1773
                   (NoExtField))
    
    1774 1774
                  (NotTopLevel)
    

  • testsuite/tests/parser/should_compile/KindSigs.stderr
    ... ... @@ -108,12 +108,14 @@
    108 108
              (EpaSpan { <no location info> }))
    
    109 109
             (EpTok
    
    110 110
              (EpaSpan { KindSigs.hs:11:19-23 }))
    
    111
    -        (EpTok (EpaSpan { <no location info> }))
    
    112 111
             (EpTok
    
    113
    -         (EpaSpan { <no location info> }))
    
    114
    -        (EpTok (EpaSpan { <no location info> })))
    
    112
    +         (EpaSpan { <no location info> })))
    
    115 113
            (ClosedTypeFamily
    
    116
    -        (NoExtField)
    
    114
    +        (AnnList
    
    115
    +         (AnnListLayout
    
    116
    +          (EpaSpan { KindSigs.hs:12:3 }))
    
    117
    +         (ListNone)
    
    118
    +         [])
    
    117 119
             (Just
    
    118 120
              [(L
    
    119 121
                (EpAnn
    

  • testsuite/tests/pmcheck/should_compile/T27323.hs
    1
    +{-# LANGUAGE MagicHash, Strict #-}
    
    2
    +{-# OPTIONS_GHC -Wredundant-bang-patterns #-}
    
    3
    +
    
    4
    +import GHC.Prim (Int#)
    
    5
    +
    
    6
    +idInt# :: Int# -> Int#
    
    7
    +idInt# x = x
    
    8
    +
    
    9
    +main = pure ()

  • testsuite/tests/pmcheck/should_compile/T27323b.hs
    1
    +{-# LANGUAGE Strict, MonoLocalBinds #-}
    
    2
    +{-# OPTIONS_GHC -Wredundant-bang-patterns #-}
    
    3
    +module T27323b where
    
    4
    +
    
    5
    +f :: Int -> Int
    
    6
    +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])
    190 190
     test('T22652', [], compile, [overlapping_incomplete])
    
    191 191
     test('T22652a', [], compile, [overlapping_incomplete])
    
    192 192
     test('T24867', [], compile_fail, [overlapping_incomplete])
    
    193
    +test('T27323', normal, compile, ['-Wredundant-bang-patterns'])
    
    194
    +test('T27323b', normal, compile, ['-Wredundant-bang-patterns'])
    
    193 195
     test('T27360', normal, compile, [overlapping_incomplete + '-g3'])

  • testsuite/tests/printer/Test24533.stdout
    ... ... @@ -64,9 +64,10 @@
    64 64
              (EpTok (EpaSpan { Test24533.hs:4:1-8 }))
    
    65 65
              (EpTok
    
    66 66
               (EpaSpan { <no location info> }))
    
    67
    -         (EpTok (EpaSpan { <no location info> }))
    
    68
    -         []
    
    69
    -         (EpTok (EpaSpan { <no location info> }))))
    
    67
    +         (AnnList
    
    68
    +          (AnnListNoLayout)
    
    69
    +          (ListNone)
    
    70
    +          [])))
    
    70 71
            []
    
    71 72
            (L
    
    72 73
             (EpAnn
    
    ... ... @@ -451,9 +452,11 @@
    451 452
              (EpTok (EpaSpan { Test24533.hs:14:1-8 }))
    
    452 453
              (EpTok
    
    453 454
               (EpaSpan { Test24533.hs:14:17-21 }))
    
    454
    -         (EpTok (EpaSpan { <no location info> }))
    
    455
    -         []
    
    456
    -         (EpTok (EpaSpan { <no location info> }))))
    
    455
    +         (AnnList
    
    456
    +          (AnnListLayout
    
    457
    +           (EpaSpan { Test24533.hs:16:3 }))
    
    458
    +          (ListNone)
    
    459
    +          [])))
    
    457 460
            []
    
    458 461
            (L
    
    459 462
             (EpAnn
    
    ... ... @@ -724,9 +727,10 @@
    724 727
              (EpTok (EpaSpan { Test24533.ppr.hs:3:1-8 }))
    
    725 728
              (EpTok
    
    726 729
               (EpaSpan { <no location info> }))
    
    727
    -         (EpTok (EpaSpan { <no location info> }))
    
    728
    -         []
    
    729
    -         (EpTok (EpaSpan { <no location info> }))))
    
    730
    +         (AnnList
    
    731
    +          (AnnListNoLayout)
    
    732
    +          (ListNone)
    
    733
    +          [])))
    
    730 734
            []
    
    731 735
            (L
    
    732 736
             (EpAnn
    
    ... ... @@ -1038,9 +1042,11 @@
    1038 1042
              (EpTok (EpaSpan { Test24533.ppr.hs:5:1-8 }))
    
    1039 1043
              (EpTok
    
    1040 1044
               (EpaSpan { Test24533.ppr.hs:5:17-21 }))
    
    1041
    -         (EpTok (EpaSpan { <no location info> }))
    
    1042
    -         []
    
    1043
    -         (EpTok (EpaSpan { <no location info> }))))
    
    1045
    +         (AnnList
    
    1046
    +          (AnnListLayout
    
    1047
    +           (EpaSpan { Test24533.ppr.hs:6:3 }))
    
    1048
    +          (ListNone)
    
    1049
    +          [])))
    
    1044 1050
            []
    
    1045 1051
            (L
    
    1046 1052
             (EpAnn
    

  • testsuite/tests/typecheck/should_fail/T22707.stderr
    1
    +T22707.hs:6:59: error: [GHC-25897]
    
    2
    +    • Couldn't match expected type ‘i1’
    
    3
    +                  with actual type ‘m0
    
    4
    +                                      GHC.Internal.Types.LiftedRep GHC.Internal.Types.LiftedRep b0’
    
    5
    +      ‘i1’ is a rigid type variable bound by
    
    6
    +        the type signature for:
    
    7
    +          t1 :: forall i2 o i1 a. Cont (i2 -> o) i1 a -> Cont o i2 (a -> i1)
    
    8
    +        at T22707.hs:5:1-47
    
    9
    +    • In the expression: evalCont (t1 c) >>== \ ati1 -> return ati1 xa
    
    10
    +      In the second argument of ‘($)’, namely
    
    11
    +        ‘\ xa -> evalCont (t1 c) >>== \ ati1 -> return ati1 xa’
    
    12
    +      In the second argument of ‘runCont’, namely
    
    13
    +        ‘(ati1tti2 $ \ xa -> evalCont (t1 c) >>== \ ati1 -> return ...)’
    
    14
    +    • Relevant bindings include
    
    15
    +        ati1tti2 :: (a -> i1) -> i2 (bound at T22707.hs:6:16)
    
    16
    +        c :: Cont (i2 -> o) i1 a (bound at T22707.hs:6:4)
    
    17
    +        t1 :: Cont (i2 -> o) i1 a -> Cont o i2 (a -> i1)
    
    18
    +          (bound at T22707.hs:6:1)
    
    19
    +
    
    1 20
     T22707.hs:6:72: error: [GHC-25897]
    
    2
    -    • Couldn't match type ‘i2’ with ‘a -> i1’
    
    21
    +    • Couldn't match type ‘o’
    
    22
    +                     with ‘m0
    
    23
    +                             GHC.Internal.Types.LiftedRep
    
    24
    +                             GHC.Internal.Types.LiftedRep
    
    25
    +                             (m0 GHC.Internal.Types.LiftedRep GHC.Internal.Types.LiftedRep b0)’
    
    3 26
           Expected: Cont
    
    4
    -                  ((a -> i1) -> m0 (a -> i1) (a -> i1) (m0 (a -> i1) (a -> i1) b0))
    
    27
    +                  ((a -> i1)
    
    28
    +                   -> m0
    
    29
    +                        GHC.Internal.Types.LiftedRep
    
    30
    +                        GHC.Internal.Types.LiftedRep
    
    31
    +                        (m0 GHC.Internal.Types.LiftedRep GHC.Internal.Types.LiftedRep b0))
    
    5 32
                       i1
    
    6 33
                       a
    
    7 34
             Actual: Cont (i2 -> o) i1 a
    
    8
    -      ‘i2’ is a rigid type variable bound by
    
    35
    +      ‘o’ is a rigid type variable bound by
    
    9 36
             the type signature for:
    
    10 37
               t1 :: forall i2 o i1 a. Cont (i2 -> o) i1 a -> Cont o i2 (a -> i1)
    
    11 38
             at T22707.hs:5:1-47
    
    ... ... @@ -13,9 +40,6 @@ T22707.hs:6:72: error: [GHC-25897]
    13 40
           In the first argument of ‘evalCont’, namely ‘(t1 c)’
    
    14 41
           In the first argument of ‘(>>==)’, namely ‘evalCont (t1 c)’
    
    15 42
         • Relevant bindings include
    
    16
    -        xa :: a (bound at T22707.hs:6:53)
    
    17
    -        ati1tti2 :: (a -> m0 (a -> i1) (a -> i1) b0) -> a -> i1
    
    18
    -          (bound at T22707.hs:6:16)
    
    19 43
             c :: Cont (i2 -> o) i1 a (bound at T22707.hs:6:4)
    
    20 44
             t1 :: Cont (i2 -> o) i1 a -> Cont o i2 (a -> i1)
    
    21 45
               (bound at T22707.hs:6:1)
    

  • testsuite/tests/typecheck/should_fail/T25950.stderr
    1
    -T25950.hs:6:9: error: [GHC-25897]
    
    1
    +T25950.hs:6:14: error: [GHC-25897]
    
    2 2
         • Couldn't match expected type ‘a’ with actual type ‘()’
    
    3 3
           ‘a’ is a rigid type variable bound by
    
    4 4
             the inferred type of fails :: a
    
    5 5
             at T25950.hs:5:1-15
    
    6
    -    • In the expression: id $ ()
    
    6
    +    • In the second argument of ‘($)’, namely ‘()’
    
    7
    +      In the expression: id $ ()
    
    7 8
           In an equation for ‘fails’: fails = id $ ()
    
    8 9
         • Relevant bindings include fails :: a (bound at T25950.hs:6:1)
    
    9 10
     

  • testsuite/tests/typecheck/should_fail/T8450.stderr
    1 1
     T8450.hs:8:19: error: [GHC-25897]
    
    2 2
         • Couldn't match type ‘a’ with ‘Bool’
    
    3
    -      Expected: Either Bool ()
    
    3
    +      Expected: Either Bool a
    
    4 4
             Actual: Either a ()
    
    5 5
           ‘a’ is a rigid type variable bound by
    
    6 6
             the type signature for:
    

  • testsuite/tests/warnings/should_compile/Overflow.stderr-ws-64
    1
    -
    
    2 1
     Overflow.hs:8:15: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
    
    3 2
         Literal 10000000000000000000000000000000 is out of the Int# range -9223372036854775808..9223372036854775807
    
    4 3
     
    
    5
    -Overflow.hs:13:1: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
    
    4
    +Overflow.hs:13:3: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
    
    6 5
         Literal 100000000000000000000000000 is out of the Int# range -9223372036854775808..9223372036854775807
    
    7 6
     
    
    8 7
     Overflow.hs:18:5: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
    
    9 8
         Literal 1000000000000000000000000000000 is out of the Int range -9223372036854775808..9223372036854775807
    
    10 9
     
    
    11
    -Overflow.hs:22:1: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
    
    10
    +Overflow.hs:22:3: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
    
    12 11
         Literal 100000000000000000000000000000000 is out of the Int range -9223372036854775808..9223372036854775807
    
    13 12
     
    
    14 13
     Overflow.hs:27:6: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
    
    15 14
         Literal -1 is out of the Word range 0..18446744073709551615
    
    16 15
     
    
    17
    -Overflow.hs:31:1: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
    
    16
    +Overflow.hs:31:4: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
    
    18 17
         Literal -1 is out of the Word range 0..18446744073709551615
    
    18
    +

  • testsuite/tests/warnings/should_compile/T13256.stderr-ws-64
    1
    -
    
    2
    -T13256.hs:4:12: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
    
    1
    +T13256.hs:4:31: warning: [GHC-97441] [-Woverflowed-literals (in -Wdefault)]
    
    3 2
         Literal 100000000000000000000000000000000 is out of the Int range -9223372036854775808..9223372036854775807
    
    3
    +

  • utils/check-exact/ExactPrint.hs
    ... ... @@ -1161,7 +1161,7 @@ limportDeclAnnPackage k annImp = fmap (\new -> annImp { importDeclAnnPackage = n
    1161 1161
     
    
    1162 1162
     -- data AnnList
    
    1163 1163
     --   = AnnList {
    
    1164
    ---       al_anchor    :: Maybe Anchor, -- ^ start point of a list having layout
    
    1164
    +--       al_layout    :: !AnnListLayout,
    
    1165 1165
     --       al_brackets  :: !AnnListBrackets,
    
    1166 1166
     --       al_semis     :: [EpToken ";"], -- decls
    
    1167 1167
     --       al_trailing  :: [TrailingAnn] -- ^ items appearing after the
    
    ... ... @@ -2406,18 +2406,17 @@ instance ExactPrint (ClsInstDecl GhcPs) where
    2406 2406
       getAnnotationEntry _ = NoEntryVal
    
    2407 2407
       setAnnotationAnchor a _ _ _ = a
    
    2408 2408
     
    
    2409
    -  exact (ClsInstDecl { cid_ext = (mbWarn, AnnClsInstDecl i w oc semis cc)
    
    2409
    +  exact (ClsInstDecl { cid_ext = (mbWarn, AnnClsInstDecl i w ann_list)
    
    2410 2410
                          , cid_poly_ty = inst_ty
    
    2411 2411
                          , cid_decls = decls
    
    2412 2412
                          , cid_overlap_mode = mbOverlap
    
    2413 2413
                          , cid_modifiers = mods })
    
    2414 2414
           = do
    
    2415 2415
               (mbWarn', i', w', mbOverlap', inst_ty', mods') <- top_matter
    
    2416
    -          oc' <- markEpToken oc
    
    2417
    -          semis' <- mapM markEpToken semis
    
    2418
    -          decls' <- mapM markAnnotated decls
    
    2419
    -          cc' <- markEpToken cc
    
    2420
    -          return (ClsInstDecl { cid_ext = (mbWarn', AnnClsInstDecl i' w' oc' semis' cc')
    
    2416
    +          (ann_list',  decls') <- markAnnListA' ann_list $ \a -> do
    
    2417
    +            r <- setLayoutBoth $ mapM markAnnotated decls
    
    2418
    +            return (a,r)
    
    2419
    +          return (ClsInstDecl { cid_ext = (mbWarn', AnnClsInstDecl i' w' ann_list')
    
    2421 2420
                                   , cid_poly_ty = inst_ty'
    
    2422 2421
                                   , cid_decls = decls'
    
    2423 2422
                                   , cid_overlap_mode = mbOverlap'
    
    ... ... @@ -3820,7 +3819,7 @@ instance ExactPrint (FamilyDecl GhcPs) where
    3820 3819
       getAnnotationEntry _ = NoEntryVal
    
    3821 3820
       setAnnotationAnchor a _ _ _ = a
    
    3822 3821
     
    
    3823
    -  exact (FamilyDecl { fdExt = AnnFamilyDecl ops cps t d f dc eq vb w oc dd cc
    
    3822
    +  exact (FamilyDecl { fdExt = AnnFamilyDecl ops cps t d f dc eq vb w dd
    
    3824 3823
                         , fdInfo = info
    
    3825 3824
                         , fdTopLevel = top_level
    
    3826 3825
                         , fdLName = ltycon
    
    ... ... @@ -3842,23 +3841,21 @@ instance ExactPrint (FamilyDecl GhcPs) where
    3842 3841
               vb' <- markEpToken vb
    
    3843 3842
               inj' <- markAnnotated inj
    
    3844 3843
               return (vb', Just inj')
    
    3845
    -    (w', oc', dd', cc', info') <-
    
    3844
    +    (w', dd', info') <-
    
    3846 3845
                  case info of
    
    3847
    -               ClosedTypeFamily x mb_eqns -> do
    
    3846
    +               ClosedTypeFamily an mb_eqns -> do
    
    3848 3847
                      w' <- markEpToken w
    
    3849
    -                 oc' <- markEpToken oc
    
    3850
    -                 (dd', mb_eqns') <-
    
    3848
    +                 (an', dd', mb_eqns') <-
    
    3851 3849
                        case mb_eqns of
    
    3852 3850
                          Nothing -> do
    
    3853 3851
                            dd' <- markEpToken dd
    
    3854
    -                       return (dd', mb_eqns)
    
    3852
    +                       return (an, dd', mb_eqns)
    
    3855 3853
                          Just eqns -> do
    
    3856
    -                       eqns' <- mapM markAnnotated eqns
    
    3857
    -                       return (dd, Just eqns')
    
    3858
    -                 cc' <- markEpToken cc
    
    3859
    -                 return (w',oc',dd',cc', ClosedTypeFamily x mb_eqns')
    
    3860
    -               _ -> return (w,oc,dd,cc, info)
    
    3861
    -    return (FamilyDecl { fdExt = AnnFamilyDecl [] [] t' d' f' dc' eq' vb' w' oc' dd' cc'
    
    3854
    +                       (an',eqns') <- markAnnList' an $ setLayoutBoth $ mapM markAnnotated eqns
    
    3855
    +                       return (an', dd, Just eqns')
    
    3856
    +                 return (w', dd', ClosedTypeFamily an' mb_eqns')
    
    3857
    +               _ -> return (w, dd, info)
    
    3858
    +    return (FamilyDecl { fdExt = AnnFamilyDecl [] [] t' d' f' dc' eq' vb' w' dd'
    
    3862 3859
                            , fdInfo = info'
    
    3863 3860
                            , fdTopLevel = top_level
    
    3864 3861
                            , fdLName = ltycon'
    

  • utils/haddock/haddock-api/src/Haddock/Convert.hs
    ... ... @@ -313,13 +313,13 @@ synifyTyCon _prr _coax tc
    313 313
                 CTF mb
    
    314 314
                   | Just (CoAxiom{co_ax_branches = branches}) <- mb
    
    315 315
                   -> mkFamDecl $
    
    316
    -                   ClosedTypeFamily noExtField $
    
    316
    +                   ClosedTypeFamily noAnn $
    
    317 317
                          Just $
    
    318 318
                            map (noLocA . synifyAxBranch tc) (fromBranches branches)
    
    319 319
                   | otherwise
    
    320
    -              -> mkFamDecl $ ClosedTypeFamily noExtField $ Just []
    
    321
    -            CTF_BuiltIn {} -> mkFamDecl $ ClosedTypeFamily noExtField $ Just []
    
    322
    -            CTF_Abstract -> mkFamDecl $ ClosedTypeFamily noExtField Nothing
    
    320
    +              -> mkFamDecl $ ClosedTypeFamily noAnn $ Just []
    
    321
    +            CTF_BuiltIn {} -> mkFamDecl $ ClosedTypeFamily noAnn $ Just []
    
    322
    +            CTF_Abstract -> mkFamDecl $ ClosedTypeFamily noAnn Nothing
    
    323 323
       where
    
    324 324
         resultVar = tyConFamilyResVar_maybe tc
    
    325 325
         mkFamDecl i =
    

  • utils/haddock/haddock-api/src/Haddock/Types.hs
    ... ... @@ -1038,7 +1038,7 @@ type instance XCInjectivityAnn DocNameI = NoExtField
    1038 1038
     
    
    1039 1039
     type instance XDataFamily       DocNameI = NoExtField
    
    1040 1040
     type instance XOpenTypeFamily   DocNameI = NoExtField
    
    1041
    -type instance XClosedTypeFamily DocNameI = NoExtField
    
    1041
    +type instance XClosedTypeFamily DocNameI = AnnList
    
    1042 1042
     type instance XXFamilyInfo      DocNameI = DataConCantHappen
    
    1043 1043
     
    
    1044 1044
     type instance XCFunDep DocNameI = NoExtField