Simon Peyton Jones pushed to branch wip/26543 at Glasgow Haskell Compiler / GHC

Commits:

4 changed files:

Changes:

  • compiler/GHC/Core/TyCo/FVs.hs
    ... ... @@ -1022,7 +1022,7 @@ afvFolder check_fv = TyCoFolder { tcf_view = noView -- See Note [Free vars and
    1022 1022
         do_tcv is tv    = Any (not (tv `elemVarSet` is) && check_fv tv)
    
    1023 1023
         do_bndr is tv _ = is `extendVarSet` tv
    
    1024 1024
         do_hole _ hole  = Any (anyFreeVarsOfType check_fv (varType (coHoleCoVar hole)))
    
    1025
    -      -- See Note [CoercionHoles and their variables]
    
    1025
    +      -- See Note [CoercionHoles and their free variables]
    
    1026 1026
           -- NB: that call to `anyFreeVarsOfType` on the kind starts again with the
    
    1027 1027
           --     empty in-scope set; see Note [Closing over free variable kinds]
    
    1028 1028
     
    

  • compiler/GHC/Core/TyCo/Rep.hs
    ... ... @@ -1817,7 +1817,7 @@ Other notes about CoercionHole and HoleCo:
    1817 1817
       * It carries a type which makes `coercionKind` and `coercionRole` work
    
    1818 1818
       * It has a Unique, which gives the hole an identity; see calls to `ctEvEvId`
    
    1819 1819
     
    
    1820
    -(COH3) See Note [CoercionHoles and coercion free variables] in GHC.Core.TyCo.FVs
    
    1820
    +(COH3) See Note [CoercionHoles and their free variables] in GHC.Core.TyCo.FVs
    
    1821 1821
     
    
    1822 1822
     (COH4) Coercion holes can be compared for equality like other coercions:
    
    1823 1823
            by looking at the types coerced.
    

  • compiler/GHC/Tc/Gen/App.hs
    ... ... @@ -424,68 +424,43 @@ tcApp rn_expr exp_res_ty
    424 424
            ; do_ql <- wantQuickLook rn_fun
    
    425 425
            ; (inst_args, app_res_rho) <- tcInstFun do_ql inst_final tc_head fun_sigma rn_args
    
    426 426
     
    
    427
    -       ; case do_ql of
    
    428
    -            NoQL -> do { traceTc "tcApp:NoQL" (ppr rn_fun $$ ppr app_res_rho)
    
    429
    -
    
    430
    -                         -- Step 4.1: subsumption check against expected result type
    
    431
    -                         -- See Note [Unify with expected type before typechecking arguments]
    
    432
    -                       ; res_wrap <- checkResultTy rn_expr tc_head inst_args
    
    433
    -                                                   app_res_rho exp_res_ty
    
    434
    -
    
    435
    -                         -- Step 4.2: typecheck the arguments
    
    436
    -                       ; tc_args <- tcValArgs NoQL inst_args
    
    437
    -
    
    438
    -                         -- Step 4.3: wrap up
    
    439
    -                       ; finishApp tc_head tc_args app_res_rho res_wrap }
    
    440
    -
    
    441
    -            DoQL -> do { traceTc "tcApp:DoQL" (ppr rn_fun $$ ppr app_res_rho)
    
    442
    -
    
    443
    -                         -- Step 5.1: Take a quick look at the result type
    
    427
    +       ; app_res_rho <- case do_ql of
    
    428
    +            NoQL -> return app_res_rho
    
    429
    +            DoQL -> do { -- Step 5.1: Take a quick look at the result type
    
    444 430
                              -- See Note [QuickLook: arguments before result]
    
    445
    -                       ; case exp_res_ty of
    
    446
    -                             Check exp_rho -> quickLookResultType app_res_rho exp_rho
    
    447
    -                             Infer {}      -> return ()
    
    431
    +                         case exp_res_ty of
    
    432
    +                           Check exp_rho -> quickLookResultType app_res_rho exp_rho
    
    433
    +                           Infer {}      -> return ()
    
    448 434
     
    
    449 435
                              -- Step 5.3: zonk to expose the polymorphism hidden under
    
    450 436
                              --           QuickLook instantiation variables in `app_res_rho`
    
    451
    -                       ; app_res_rho <- liftZonkM $ zonkTcType app_res_rho
    
    437
    +                         --           from either quickLookArg or quickLookResultType
    
    438
    +                       ; liftZonkM $ zonkTcType app_res_rho }
    
    452 439
     
    
    453
    -                         -- Step 5.4: subsumption check against the expected type
    
    454
    -                         -- See Note [Unify with expected type before typechecking arguments]
    
    455
    -                       ; res_wrap <- checkResultTy rn_expr tc_head inst_args
    
    456
    -                                                   app_res_rho exp_res_ty
    
    457
    -
    
    458
    -                         -- Step 5.2: typecheck the arguments, and monomorphise
    
    459
    -                         --           any un-unified instantiation variables
    
    460
    -                       ; tc_args <- tcValArgs DoQL inst_args
    
    461
    -
    
    462
    -                         -- Step 5.5: wrap up
    
    463
    -                       ; finishApp tc_head tc_args app_res_rho res_wrap } }
    
    464
    -
    
    465
    --- | Variant of 'getDeepSubsumptionFlag' which enables a top-level subsumption
    
    466
    --- in order to implement the plan of Note [Typechecking data constructors].
    
    467
    -getDeepSubsumptionFlag_DataConHead :: HsExpr GhcTc -> TcM DeepSubsumptionFlag
    
    468
    -getDeepSubsumptionFlag_DataConHead app_head =
    
    469
    -  do { user_ds <- xoptM LangExt.DeepSubsumption
    
    470
    -     ; return $
    
    471
    -         if | user_ds
    
    472
    -            -> Deep DeepSub
    
    473
    -            | XExpr (ConLikeTc (RealDataCon {})) <- app_head
    
    474
    -            -> Deep TopSub
    
    475
    -            | otherwise
    
    476
    -            -> Shallow
    
    477
    -    }
    
    440
    +       ; finishApp do_ql rn_expr tc_head inst_args app_res_rho exp_res_ty }
    
    478 441
     
    
    479
    -finishApp :: (HsExpr GhcTc, AppCtxt) -> [HsExprArg 'TcpTc]
    
    480
    -          -> TcRhoType -> HsWrapper
    
    442
    +finishApp :: QLFlag -> HsExpr GhcRn
    
    443
    +          -> (HsExpr GhcTc, AppCtxt) -> [HsExprArg 'TcpInst]
    
    444
    +          -> TcRhoType -> ExpRhoType
    
    481 445
               -> TcM (HsExpr GhcTc)
    
    482 446
     -- Do final checks and wrap up the result
    
    483
    -finishApp tc_head@(tc_fun,_) tc_args app_res_rho res_wrap
    
    484
    -  = do {
    
    485
    -       -- Reconstruct, with a horrible special case for tagToEnum#.
    
    486
    -         res_expr <- if isTagToEnum tc_fun
    
    447
    +-- Precondition: app_res_rho has no polymorphism hidden under instantiation variables
    
    448
    +finishApp do_ql rn_expr tc_head@(tc_fun,_) inst_args
    
    449
    +          app_res_rho exp_res_ty
    
    450
    +  = do { -- Step 5.4: subsumption check against the expected type
    
    451
    +         -- See Note [Unify with expected type before typechecking arguments]
    
    452
    +         res_wrap <- checkResultTy rn_expr tc_head inst_args
    
    453
    +                                   app_res_rho exp_res_ty
    
    454
    +
    
    455
    +         -- Step 5.2: Typecheck the arguments, and monomorphise
    
    456
    +         --           any un-unified instantiation variables
    
    457
    +       ; tc_args <- tcValArgs do_ql inst_args
    
    458
    +
    
    459
    +         -- Horrible special case for tagToEnum#.
    
    460
    +       ; res_expr <- if isTagToEnum tc_fun
    
    487 461
                          then tcTagToEnum tc_head tc_args app_res_rho
    
    488 462
                          else return (rebuildHsApps tc_head tc_args)
    
    463
    +
    
    489 464
            ; traceTc "End tcApp }" (ppr tc_fun)
    
    490 465
            ; return (mkHsWrap res_wrap res_expr) }
    
    491 466
     
    
    ... ... @@ -630,10 +605,8 @@ tcValArg _ (EValArgQL { eaql_wanted = wanted
    630 605
                         quickLookResultType app_res_rho exp_arg_rho -- the qlUnify
    
    631 606
     
    
    632 607
                       ; app_res_rho <- liftZonkM $ zonkTcType app_res_rho
    
    633
    -                  ; res_wrap <- checkResultTy rn_expr tc_head inst_args
    
    634
    -                                              app_res_rho (mkCheckExpType exp_arg_rho)
    
    635
    -                  ; tc_args <- tcValArgs DoQL inst_args
    
    636
    -                  ; finishApp tc_head tc_args app_res_rho res_wrap }
    
    608
    +                  ; finishApp DoQL rn_expr tc_head inst_args app_res_rho
    
    609
    +                              (mkCheckExpType exp_arg_rho) }
    
    637 610
     
    
    638 611
            ; traceTc "tcEValArgQL }" $
    
    639 612
                vcat [ text "app_res_rho:" <+> ppr app_res_rho ]
    
    ... ... @@ -644,6 +617,20 @@ tcValArg _ (EValArgQL { eaql_wanted = wanted
    644 617
     
    
    645 618
     
    
    646 619
     --------------------
    
    620
    +-- | Variant of 'getDeepSubsumptionFlag' which enables a top-level subsumption
    
    621
    +-- in order to implement the plan of Note [Typechecking data constructors].
    
    622
    +getDeepSubsumptionFlag_DataConHead :: HsExpr GhcTc -> TcM DeepSubsumptionFlag
    
    623
    +getDeepSubsumptionFlag_DataConHead app_head =
    
    624
    +  do { user_ds <- xoptM LangExt.DeepSubsumption
    
    625
    +     ; return $
    
    626
    +         if | user_ds
    
    627
    +            -> Deep DeepSub
    
    628
    +            | XExpr (ConLikeTc (RealDataCon {})) <- app_head
    
    629
    +            -> Deep TopSub
    
    630
    +            | otherwise
    
    631
    +            -> Shallow
    
    632
    +    }
    
    633
    +
    
    647 634
     whenQL :: QLFlag -> ZonkM () -> TcM ()
    
    648 635
     whenQL DoQL thing_inside = liftZonkM thing_inside
    
    649 636
     whenQL NoQL _            = return ()
    

  • compiler/GHC/Tc/Utils/Unify.hs
    ... ... @@ -3555,7 +3555,7 @@ mkOccFolders lhs_tv = (getAny . check_ty, getAny . check_co)
    3555 3555
     
    
    3556 3556
         do_hole _is hole = check_ty (varType (coHoleCoVar hole))
    
    3557 3557
            -- For coercion holes, look in the kind of the hole
    
    3558
    -       -- See Note [CorecionHoles and their free variables] in GHC.Core.TyCo.FVs
    
    3558
    +       -- See Note [CoercionHoles and their free variables] in GHC.Core.TyCo.FVs
    
    3559 3559
     
    
    3560 3560
     {- *********************************************************************
    
    3561 3561
     *                                                                      *
    
    ... ... @@ -4190,7 +4190,7 @@ checkCo flags co =
    4190 4190
                     else PuFail reason }
    
    4191 4191
     
    
    4192 4192
             -- Occurs check (no promotion)
    
    4193
    -        -- See Note [CorecionHoles and their free variables] in GHC.Core.TyCo.FVs
    
    4193
    +        -- See Note [CoercionHoles and their free variables] in GHC.Core.TyCo.FVs
    
    4194 4194
             | OC_Check lhs_tv occ_prob <- occ
    
    4195 4195
             , let (_, check_co) = mkOccFolders lhs_tv
    
    4196 4196
             , check_co co