Simon Peyton Jones pushed to branch wip/ani/no-ds-flag-cache at Glasgow Haskell Compiler / GHC
Commits:
-
6986cae3
by Simon Peyton Jones at 2026-03-30T17:05:10+01:00
7 changed files:
- compiler/GHC/Tc/Gen/App.hs
- compiler/GHC/Tc/Gen/Expr.hs
- compiler/GHC/Tc/Gen/Expr.hs-boot
- compiler/GHC/Tc/Gen/Head.hs
- compiler/GHC/Tc/Gen/Match.hs
- compiler/GHC/Tc/Utils/TcMType.hs
- compiler/GHC/Tc/Utils/Unify.hs
Changes:
| ... | ... | @@ -488,8 +488,8 @@ checkResultTy :: HsExpr GhcRn |
| 488 | 488 | -- expose foralls, but maybe not /deeply/ instantiated
|
| 489 | 489 | -> ExpRhoType -- Expected type; this is deeply skolemised
|
| 490 | 490 | -> TcM HsWrapper
|
| 491 | -checkResultTy rn_expr (tc_fun, _) _ app_res_rho (Infer inf_res)
|
|
| 492 | - = do { ds_flag <- getDeepSubsumptionFlag_DataConHead tc_fun
|
|
| 491 | +checkResultTy rn_expr _ _ app_res_rho (Infer inf_res)
|
|
| 492 | + = do { ds_flag <- getDeepSubsumptionFlag
|
|
| 493 | 493 | ; fillInferResult ds_flag (exprCtOrigin rn_expr) app_res_rho inf_res }
|
| 494 | 494 | |
| 495 | 495 | |
| ... | ... | @@ -636,7 +636,8 @@ tcValArg _ pos (fun, fun_lspan) (EValArgQL { |
| 636 | 636 | , text "app_lspan" <+> ppr lspan
|
| 637 | 637 | , text "head_lspan" <+> ppr fun_lspan
|
| 638 | 638 | , text "tc_head" <+> ppr tc_head])
|
| 639 | - ; ds_flag <- getDeepSubsumptionFlag_DataConHead (fst tc_head)
|
|
| 639 | + ; ds_flag <- getDeepSubsumptionFlag
|
|
| 640 | + -- NB: whether to do deep /skolemisation/ is independent of data constructors
|
|
| 640 | 641 | ; (wrap, arg')
|
| 641 | 642 | <- tcScalingUsage mult $
|
| 642 | 643 | tcSkolemise ds_flag GenSigCtxt exp_arg_ty $ \ exp_arg_rho ->
|
| ... | ... | @@ -894,8 +895,7 @@ tcInstFun do_ql inst_final (fun_orig, rn_fun, fun_lspan) tc_fun fun_sigma rn_arg |
| 894 | 895 | matchActualFunTy herald
|
| 895 | 896 | (Just $ HsExprTcThing tc_fun)
|
| 896 | 897 | (n_val_args, fun_sigma) fun_ty
|
| 897 | - ; ds_flag <- getDeepSubsumptionFlag_DataConHead tc_fun
|
|
| 898 | - ; arg' <- quickLookArg ds_flag do_ql pos ctxt (rn_fun, fun_lspan) arg arg_ty
|
|
| 898 | + ; arg' <- quickLookArg do_ql pos ctxt (rn_fun, fun_lspan) arg arg_ty
|
|
| 899 | 899 | ; let acc' = arg' : addArgWrap (mkWpCastN fun_co) acc
|
| 900 | 900 | ; go (pos+1) acc' res_ty rest_args }
|
| 901 | 901 | |
| ... | ... | @@ -1883,17 +1883,18 @@ This turned out to be more subtle than I expected. Wrinkles: |
| 1883 | 1883 | |
| 1884 | 1884 | -}
|
| 1885 | 1885 | |
| 1886 | -quickLookArg :: DeepSubsumptionFlag -> QLFlag -> Int
|
|
| 1886 | +quickLookArg :: QLFlag -> Int
|
|
| 1887 | 1887 | -> SrcSpan -- ^ location span of the whole application
|
| 1888 | 1888 | -> (HsExpr GhcRn, SrcSpan) -- ^ Head of the application chain and its source span
|
| 1889 | 1889 | -> LHsExpr GhcRn -- ^ Argument
|
| 1890 | 1890 | -> Scaled TcSigmaTypeFRR -- ^ Type expected by the function
|
| 1891 | 1891 | -> TcM (HsExprArg 'TcpInst)
|
| 1892 | 1892 | -- See Note [Quick Look at value arguments]
|
| 1893 | -quickLookArg _ NoQL _ app_lspan _ larg orig_arg_ty
|
|
| 1893 | +quickLookArg NoQL _ app_lspan _ larg orig_arg_ty
|
|
| 1894 | 1894 | = skipQuickLook app_lspan larg orig_arg_ty
|
| 1895 | -quickLookArg ds_flag DoQL pos app_lspan fun_and_lspan larg orig_arg_ty
|
|
| 1896 | - = do { is_rho <- tcIsDeepRho ds_flag (scaledThing orig_arg_ty)
|
|
| 1895 | +quickLookArg DoQL pos app_lspan fun_and_lspan larg orig_arg_ty
|
|
| 1896 | + = do { ds_flag <- getDeepSubsumptionFlag
|
|
| 1897 | + ; is_rho <- tcIsDeepRho ds_flag (scaledThing orig_arg_ty)
|
|
| 1897 | 1898 | ; traceTc "qla" (ppr orig_arg_ty $$ ppr is_rho)
|
| 1898 | 1899 | ; if not is_rho
|
| 1899 | 1900 | then skipQuickLook app_lspan larg orig_arg_ty
|
| ... | ... | @@ -13,7 +13,7 @@ |
| 13 | 13 | module GHC.Tc.Gen.Expr
|
| 14 | 14 | ( tcCheckPolyExpr, tcCheckPolyExprNC,
|
| 15 | 15 | tcCheckMonoExpr, tcCheckMonoExprNC,
|
| 16 | - tcInferExpr, tcInferSigma,
|
|
| 16 | + tcInferExpr, tcInferSigma, tcInferExprSigma,
|
|
| 17 | 17 | tcInferRho, tcInferRhoNC,
|
| 18 | 18 | tcMonoLExpr, tcMonoLExprNC,
|
| 19 | 19 | tcInferRhoFRR, tcInferRhoFRRNC,
|
| ... | ... | @@ -237,6 +237,9 @@ tcPolyExprCheck expr res_ty |
| 237 | 237 | tcInferSigma :: LHsExpr GhcRn -> TcM (LHsExpr GhcTc, TcSigmaType)
|
| 238 | 238 | tcInferSigma = tcInferExpr IIF_Sigma
|
| 239 | 239 | |
| 240 | +tcInferExprSigma :: HsExpr GhcRn -> TcM (HsExpr GhcTc, TcSigmaType)
|
|
| 241 | +tcInferExprSigma e = runInfer IIF_Sigma IFRR_Any (tcExpr e)
|
|
| 242 | + |
|
| 240 | 243 | tcInferRho, tcInferRhoNC :: LHsExpr GhcRn -> TcM (LHsExpr GhcTc, TcRhoType)
|
| 241 | 244 | -- Infer a *rho*-type. The return type is always instantiated.
|
| 242 | 245 | tcInferRho = tcInferExpr IIF_DeepRho
|
| ... | ... | @@ -321,7 +324,7 @@ tcExpr e@(HsAppType {}) res_ty = tcApp e res_ty |
| 321 | 324 | tcExpr e@(ExprWithTySig {}) res_ty = tcApp e res_ty
|
| 322 | 325 | |
| 323 | 326 | tcExpr (XExpr (ExpandedThingRn hse)) res_ty = tcHsExpansion hse res_ty
|
| 324 | -tcExpr e@(XExpr{}) res_ty = tcApp e res_ty
|
|
| 327 | +tcExpr e@(XExpr (HsRecSelRn {})) res_ty = tcApp e res_ty
|
|
| 325 | 328 | |
| 326 | 329 | -- Typecheck an occurrence of an unbound Id
|
| 327 | 330 | --
|
| ... | ... | @@ -527,8 +530,9 @@ tcExpr (HsCase ctxt scrut matches) res_ty |
| 527 | 530 | |
| 528 | 531 | tcExpr (HsIf x pred b1 b2) res_ty
|
| 529 | 532 | = do { pred' <- tcCheckMonoExpr pred boolTy
|
| 530 | - ; (u1,b1') <- tcCollectingUsage $ tcMonoLExpr b1 res_ty
|
|
| 531 | - ; (u2,b2') <- tcCollectingUsage $ tcMonoLExpr b2 res_ty
|
|
| 533 | + ; let res_ty' = adjustExpTypeForCaseBranches res_ty [b1,b2]
|
|
| 534 | + ; (u1,b1') <- tcCollectingUsage $ tcMonoLExpr b1 res_ty'
|
|
| 535 | + ; (u2,b2') <- tcCollectingUsage $ tcMonoLExpr b2 res_ty'
|
|
| 532 | 536 | ; tcEmitBindingUsage (supUE u1 u2)
|
| 533 | 537 | ; return (HsIf x pred' b1' b2') }
|
| 534 | 538 |
| ... | ... | @@ -35,6 +35,8 @@ tcInferRho, tcInferRhoNC :: |
| 35 | 35 | tcInferRhoFRR, tcInferRhoFRRNC ::
|
| 36 | 36 | FixedRuntimeRepContext -> LHsExpr GhcRn -> TcM (LHsExpr GhcTc, TcRhoType)
|
| 37 | 37 | |
| 38 | +tcInferExprSigma :: HsExpr GhcRn -> TcM (HsExpr GhcTc, TcSigmaType)
|
|
| 39 | + |
|
| 38 | 40 | tcInferExpr :: InferInstFlag -> LHsExpr GhcRn -> TcM (LHsExpr GhcTc, TcType)
|
| 39 | 41 | |
| 40 | 42 | tcSyntaxOp :: CtOrigin
|
| ... | ... | @@ -21,15 +21,14 @@ module GHC.Tc.Gen.Head |
| 21 | 21 | |
| 22 | 22 | , pprArgInst, addFunResCtxt ) where
|
| 23 | 23 | |
| 24 | -import {-# SOURCE #-} GHC.Tc.Gen.Expr( tcExpr, tcCheckPolyExprNC, tcPolyLExprSig )
|
|
| 24 | +import {-# SOURCE #-} GHC.Tc.Gen.Expr( tcCheckPolyExprNC, tcPolyLExprSig, tcInferExprSigma )
|
|
| 25 | 25 | import {-# SOURCE #-} GHC.Tc.Gen.Splice( getUntypedSpliceBody )
|
| 26 | -import {-# SOURCE #-} GHC.Tc.Gen.App( tcExprSigma )
|
|
| 27 | 26 | |
| 28 | 27 | import GHC.Prelude
|
| 29 | 28 | import GHC.Hs
|
| 30 | 29 | import GHC.Hs.Syn.Type
|
| 31 | 30 | |
| 32 | -import GHC.Rename.Utils (mkExpandedTc, mkExpandedExprTc)
|
|
| 31 | +import GHC.Rename.Utils (mkExpandedExprTc)
|
|
| 33 | 32 | |
| 34 | 33 | import GHC.Tc.Gen.HsType
|
| 35 | 34 | import GHC.Tc.Gen.Bind( chooseInferredQuantifiers )
|
| ... | ... | @@ -446,7 +445,7 @@ tcInferAppHead (fun,fun_lspan) |
| 446 | 445 | do { mb_tc_fun <- tcInferAppHead_maybe fun
|
| 447 | 446 | ; case mb_tc_fun of
|
| 448 | 447 | Just (fun', fun_sigma) -> return (fun', fun_sigma)
|
| 449 | - Nothing -> runInferRho (tcExpr fun)
|
|
| 448 | + Nothing -> tcInferExprSigma fun
|
|
| 450 | 449 | |
| 451 | 450 | }
|
| 452 | 451 | |
| ... | ... | @@ -465,13 +464,14 @@ tcInferAppHead_maybe fun = case fun of |
| 465 | 464 | -> Just <$> tcInferOverLit lit
|
| 466 | 465 | XExpr (HsRecSelRn f)
|
| 467 | 466 | -> Just <$> tcInferRecSelId f
|
| 468 | - XExpr (ExpandedThingRn (HSE o (L loc e)))
|
|
| 469 | - -> setSrcSpan (locA loc) $ Just <$>
|
|
| 470 | - do { (e', ty) <- tcExprSigma False (hsCtxtCtOrigin o) e
|
|
| 471 | - ; return (mkExpandedTc o (L loc e'), ty) }
|
|
| 472 | - -- We do not want to instantiate the type of the head as there may be
|
|
| 473 | - -- visible type applications in the argument.
|
|
| 474 | - -- c.f. T19167
|
|
| 467 | + |
|
| 468 | +-- XExpr (ExpandedThingRn (HSE o (L loc e)))
|
|
| 469 | +-- -> setSrcSpan (locA loc) $ Just <$>
|
|
| 470 | +-- do { (e', ty) <- tcExprSigma False (hsCtxtCtOrigin o) e
|
|
| 471 | +-- ; return (mkExpandedTc o (L loc e'), ty) }
|
|
| 472 | +-- -- We do not want to instantiate the type of the head as there may be
|
|
| 473 | +-- -- visible type applications in the argument.
|
|
| 474 | +-- -- c.f. T19167
|
|
| 475 | 475 | _
|
| 476 | 476 | -> return Nothing
|
| 477 | 477 |
| ... | ... | @@ -219,10 +219,10 @@ tcMatches :: (AnnoBody body, Outputable (body GhcTc)) |
| 219 | 219 | -> MatchGroup GhcRn (LocatedA (body GhcRn))
|
| 220 | 220 | -> TcM (MatchGroup GhcTc (LocatedA (body GhcTc)))
|
| 221 | 221 | |
| 222 | -tcMatches ctxt tc_body pat_tys rhs_ty (MG { mg_alts = L l matches
|
|
| 222 | +tcMatches ctxt tc_body pat_tys exp_ty (MG { mg_alts = L l matches
|
|
| 223 | 223 | , mg_ext = origin })
|
| 224 | 224 | | null matches -- Deal with case e of {}
|
| 225 | - -- Since there are no branches, no one else will fill in rhs_ty
|
|
| 225 | + -- Since there are no branches, no one else will fill in exp_ty
|
|
| 226 | 226 | -- when in inference mode, so we must do it ourselves,
|
| 227 | 227 | -- here, using expTypeToType
|
| 228 | 228 | = do { tcEmitBindingUsage bottomUE
|
| ... | ... | @@ -233,17 +233,19 @@ tcMatches ctxt tc_body pat_tys rhs_ty (MG { mg_alts = L l matches |
| 233 | 233 | [ExpForAllPatTy tvb] -> failWithTc $ TcRnEmptyCase ctxt (EmptyCaseForall tvb)
|
| 234 | 234 | [] -> panic "tcMatches: no arguments in EmptyCase"
|
| 235 | 235 | _t1:(_t2:_ts) -> panic "tcMatches: multiple arguments in EmptyCase"
|
| 236 | - ; rhs_ty <- expTypeToType rhs_ty
|
|
| 236 | + ; rhs_ty <- expTypeToType exp_ty
|
|
| 237 | 237 | ; return (MG { mg_alts = L l []
|
| 238 | 238 | , mg_ext = MatchGroupTc [pat_ty] rhs_ty origin
|
| 239 | 239 | }) }
|
| 240 | 240 | |
| 241 | 241 | | otherwise
|
| 242 | - = do { umatches <- mapM (tcCollectingUsage . tcMatch tc_body pat_tys rhs_ty) matches
|
|
| 243 | - ; let (usages, matches') = unzip umatches
|
|
| 242 | + = do { let exp_ty' = adjustExpTypeForCaseBranches exp_ty matches
|
|
| 243 | + tc_match match = tcCollectingUsage $
|
|
| 244 | + tcMatch tc_body pat_tys exp_ty' match
|
|
| 245 | + ; (usages, matches') <- mapAndUnzipM tc_match matches
|
|
| 244 | 246 | ; tcEmitBindingUsage $ supUEs usages
|
| 245 | 247 | ; pat_tys <- mapM readScaledExpType (filter_out_forall_pat_tys pat_tys)
|
| 246 | - ; rhs_ty <- readExpType rhs_ty
|
|
| 248 | + ; rhs_ty <- readExpType exp_ty
|
|
| 247 | 249 | ; traceTc "tcMatches" (ppr matches' $$ ppr pat_tys $$ ppr rhs_ty)
|
| 248 | 250 | ; return (MG { mg_alts = L l matches'
|
| 249 | 251 | , mg_ext = MatchGroupTc pat_tys rhs_ty origin
|
| ... | ... | @@ -63,7 +63,7 @@ module GHC.Tc.Utils.TcMType ( |
| 63 | 63 | mkCheckExpType, newInferExpType, newInferExpTypeFRR,
|
| 64 | 64 | runInfer, runInferRho, runInferSigma, runInferKind, runInferRhoFRR, runInferSigmaFRR,
|
| 65 | 65 | readExpType, readExpType_maybe, readScaledExpType,
|
| 66 | - expTypeToType, scaledExpTypeToType,
|
|
| 66 | + expTypeToType, scaledExpTypeToType, adjustExpTypeForCaseBranches,
|
|
| 67 | 67 | checkingExpType_maybe, checkingExpType,
|
| 68 | 68 | inferResultToType, ensureMonoType, promoteTcType,
|
| 69 | 69 | |
| ... | ... | @@ -499,6 +499,17 @@ inferResultToType (IR { ir_uniq = u, ir_lvl = tc_lvl |
| 499 | 499 | ; let conc_orig = ConcreteFRR $ FixedRuntimeRepOrigin tau frr
|
| 500 | 500 | ; return tau }
|
| 501 | 501 | |
| 502 | +adjustExpTypeForCaseBranches :: ExpRhoType -> [branch] -> ExpRhoType
|
|
| 503 | +-- See Note [fillInferResult: multiple branches]
|
|
| 504 | +adjustExpTypeForCaseBranches exp_ty branches
|
|
| 505 | + = case exp_ty of
|
|
| 506 | + Infer ir | IR { ir_inst = IIF_Sigma } <- ir
|
|
| 507 | + , branches `lengthAtLeast` 2
|
|
| 508 | + -> Infer (ir { ir_inst = IIF_DeepRho })
|
|
| 509 | + | otherwise
|
|
| 510 | + -> exp_ty
|
|
| 511 | + Check {} -> exp_ty
|
|
| 512 | + |
|
| 502 | 513 | {- Note [inferResultToType]
|
| 503 | 514 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 504 | 515 | expTypeToType and inferResultType convert an InferResult to a monotype.
|
| ... | ... | @@ -426,7 +426,7 @@ Some examples: |
| 426 | 426 | |
| 427 | 427 | tcSkolemiseGeneral
|
| 428 | 428 | :: HasDebugCallStack
|
| 429 | - => DeepSubsumptionFlag
|
|
| 429 | + => DeepSubsumptionFlag -- Ignores the DeepSubsumptionDepth
|
|
| 430 | 430 | -> UserTypeCtxt
|
| 431 | 431 | -> TcType -> TcType -- top_ty and expected_ty
|
| 432 | 432 | -- Here, top_ty is the type we started to skolemise; used only in SigSkol
|
| ... | ... | @@ -1169,7 +1169,7 @@ fillInferResultNoInst act_res_ty (IR { ir_uniq = u |
| 1169 | 1169 | |
| 1170 | 1170 | ; return final_co } }
|
| 1171 | 1171 | |
| 1172 | -fillInferResult :: DeepSubsumptionFlag -> CtOrigin -> TcType -> InferResult -> TcM HsWrapper
|
|
| 1172 | +fillInferResult :: DeepSubsumptionFlag -> CtOrigin -> TcSigmaType -> InferResult -> TcM HsWrapper
|
|
| 1173 | 1173 | -- See Note [Instantiation of InferResult]
|
| 1174 | 1174 | fillInferResult ds_flag ct_orig res_ty ires@(IR { ir_inst = iif })
|
| 1175 | 1175 | = case iif of
|
| ... | ... | @@ -1203,7 +1203,7 @@ There are two things to worry about: |
| 1203 | 1203 | T1 -> e1
|
| 1204 | 1204 | T2 -> e2
|
| 1205 | 1205 | |
| 1206 | -Our typing rules are:
|
|
| 1206 | +In general our typing rules are:
|
|
| 1207 | 1207 | |
| 1208 | 1208 | * The RHS of a existential or GADT alternative must always be a
|
| 1209 | 1209 | monotype, regardless of the number of alternatives.
|
| ... | ... | @@ -1218,17 +1218,13 @@ Our typing rules are: |
| 1218 | 1218 | We use choice (2) in that Section.
|
| 1219 | 1219 | (GHC 8.10 and earlier used choice (1).)
|
| 1220 | 1220 | |
| 1221 | - But note that
|
|
| 1222 | - case e of
|
|
| 1223 | - True -> hr
|
|
| 1224 | - False -> \x -> hr x
|
|
| 1225 | - will fail, because we still /infer/ both branches, so the \x will get
|
|
| 1226 | - a (monotype) unification variable, which will fail to unify with
|
|
| 1227 | - (forall a. a->a)
|
|
| 1221 | +Note [fillInferResult: GADTs and existentials]
|
|
| 1222 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 1223 | +We can detect the GADT/existential situation, case (1) of Note [fillInferResult],
|
|
| 1224 | +by seeing that the current TcLevel is greater than that stored in ir_lvl of the
|
|
| 1225 | +Infer ExpType. We bump the level whenever we go past a GADT/existential match.
|
|
| 1228 | 1226 | |
| 1229 | -For (1) we can detect the GADT/existential situation by seeing that
|
|
| 1230 | -the current TcLevel is greater than that stored in ir_lvl of the Infer
|
|
| 1231 | -ExpType. We bump the level whenever we go past a GADT/existential match.
|
|
| 1227 | +We insist that the RHS has a monotype, regardless of the number of alternatives.
|
|
| 1232 | 1228 | |
| 1233 | 1229 | Then, before filling the hole use promoteTcType to promote the type
|
| 1234 | 1230 | to the outer ir_lvl. promoteTcType does this
|
| ... | ... | @@ -1239,11 +1235,6 @@ That forces the type to be a monotype (since unification variables can |
| 1239 | 1235 | only unify with monotypes); and catches skolem-escapes because the
|
| 1240 | 1236 | alpha is untouchable until the equality floats out.
|
| 1241 | 1237 | |
| 1242 | -For (2), we simply look to see if the hole is filled already.
|
|
| 1243 | - - if not, we promote (as above) and fill the hole
|
|
| 1244 | - - if it is filled, we simply unify with the type that is
|
|
| 1245 | - already there
|
|
| 1246 | - |
|
| 1247 | 1238 | (FIR1) There is one wrinkle. Suppose we have
|
| 1248 | 1239 | case e of
|
| 1249 | 1240 | T1 -> e1 :: (forall a. a->a) -> Int
|
| ... | ... | @@ -1258,7 +1249,36 @@ For (2), we simply look to see if the hole is filled already. |
| 1258 | 1249 | So if we check G2 second, we still want to emit a constraint that restricts
|
| 1259 | 1250 | the RHS to be a monotype. This is done by ensureMonoType, and it works
|
| 1260 | 1251 | by simply generating a constraint (alpha ~ ty), where alpha is a fresh
|
| 1261 | -unification variable. We discard the evidence.
|
|
| 1252 | + unification variable. We discard the evidence.
|
|
| 1253 | + |
|
| 1254 | +Note [fillInferResult: multiple branches]
|
|
| 1255 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 1256 | +If there are multiple case branches, case (2) of Note [fillInferResult]
|
|
| 1257 | +we simply look to see if the hole is filled already.
|
|
| 1258 | + - if not, we promote (as above) and fill the hole
|
|
| 1259 | + - if it is filled, we simply unify with the type that is already there
|
|
| 1260 | + |
|
| 1261 | +But consider
|
|
| 1262 | + case x of
|
|
| 1263 | + True -> True
|
|
| 1264 | + False -> error "urk"
|
|
| 1265 | +and suppose we call `tcInferSigma` on this expression, so that the `ir_inst`
|
|
| 1266 | +field of the expected result type is `IIF_Sigma`. The danger is that we'll
|
|
| 1267 | +fill the hole with `Bool` (from the `True`) and then reject when we try to
|
|
| 1268 | +unify that with `forall a. a->a`, from the call to `error`.
|
|
| 1269 | + |
|
| 1270 | +To avoid this, we never infer a sigma-type from a multi-branch `case`. Instead
|
|
| 1271 | +we just zap the `IIF_Sigma` to `IIF_DeepRho` when walking inside the branches
|
|
| 1272 | +of multi-arm case-expression, or an if-expression. See calls to
|
|
| 1273 | +`adjustExpTypeForCaseBranches`.
|
|
| 1274 | + |
|
| 1275 | +Note that
|
|
| 1276 | + case e of
|
|
| 1277 | + True -> hr
|
|
| 1278 | + False -> \x -> hr x
|
|
| 1279 | + where hr :: (forall a. a->a) -> Int
|
|
| 1280 | +will fail, because we still /infer/ both branches, so the \x will get a
|
|
| 1281 | +(monotype) unification variable, which will fail to unify with (forall a. a->a)
|
|
| 1262 | 1282 | |
| 1263 | 1283 | Note [Instantiation of InferResult]
|
| 1264 | 1284 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ... | ... | @@ -2068,17 +2088,20 @@ getDeepSubsumptionFlag = |
| 2068 | 2088 | -- | Variant of 'getDeepSubsumptionFlag' which enables a top-level subsumption
|
| 2069 | 2089 | -- in order to implement the plan of Note [Typechecking data constructors].
|
| 2070 | 2090 | getDeepSubsumptionFlag_DataConHead :: HsExpr GhcTc -> TcM DeepSubsumptionFlag
|
| 2071 | -getDeepSubsumptionFlag_DataConHead app_head =
|
|
| 2072 | - do { user_ds <- xoptM LangExt.DeepSubsumption
|
|
| 2073 | - ; traceTc "getDeepSubsumptionFlag_DataConHead" (ppr app_head)
|
|
| 2074 | - ; return $
|
|
| 2075 | - if | user_ds
|
|
| 2076 | - -> Deep DeepSub
|
|
| 2077 | - | XExpr (ConLikeTc (RealDataCon {})) <- app_head
|
|
| 2078 | - -> Deep TopSub
|
|
| 2079 | - | otherwise
|
|
| 2080 | - -> Shallow
|
|
| 2081 | - }
|
|
| 2091 | +getDeepSubsumptionFlag_DataConHead app_head
|
|
| 2092 | + = do { user_ds <- xoptM LangExt.DeepSubsumption
|
|
| 2093 | + ; return $ if | user_ds -> Deep DeepSub
|
|
| 2094 | + | dc_head app_head -> Deep TopSub
|
|
| 2095 | + | otherwise -> Shallow }
|
|
| 2096 | + where
|
|
| 2097 | + dc_head (XExpr (ConLikeTc (RealDataCon {}))) = True
|
|
| 2098 | + dc_head (XExpr (WrapExpr _ f)) = dc_head f
|
|
| 2099 | + dc_head (HsApp _ (L _ f) _) = dc_head f
|
|
| 2100 | + dc_head (HsAppType _ (L _ f) _) = dc_head f
|
|
| 2101 | + dc_head (OpApp _ _ (L _ f) _) = dc_head f
|
|
| 2102 | + dc_head (HsPar _ (L _ f)) = dc_head f
|
|
| 2103 | + dc_head _ = False
|
|
| 2104 | + |
|
| 2082 | 2105 | |
| 2083 | 2106 | -- | 'tc_sub_type_deep' is where the actual work happens for deep subsumption.
|
| 2084 | 2107 | --
|