Simon Peyton Jones pushed to branch wip/T24464 at Glasgow Haskell Compiler / GHC
Commits:
-
2b0c10d6
by Simon Peyton Jones at 2025-11-07T13:14:25+00:00
23 changed files:
- compiler/GHC/Hs/Binds.hs
- compiler/GHC/Tc/Errors.hs
- compiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/Bind.hs
- compiler/GHC/Tc/Gen/Expr.hs
- compiler/GHC/Tc/Gen/Head.hs
- compiler/GHC/Tc/Gen/Pat.hs
- compiler/GHC/Tc/Module.hs
- compiler/GHC/Tc/Solver.hs
- compiler/GHC/Tc/Solver/Monad.hs
- compiler/GHC/Tc/Solver/Solve.hs
- compiler/GHC/Tc/TyCl/Class.hs
- compiler/GHC/Tc/TyCl/Instance.hs
- compiler/GHC/Tc/TyCl/PatSyn.hs
- compiler/GHC/Tc/Types/BasicTypes.hs
- compiler/GHC/Tc/Types/Constraint.hs
- compiler/GHC/Tc/Types/Origin.hs
- compiler/GHC/Tc/Utils/Env.hs
- compiler/GHC/Tc/Utils/TcMType.hs
- − compiler/GHC/Tc/Utils/TcMType.hs-boot
- compiler/GHC/Tc/Utils/Unify.hs
- compiler/GHC/Tc/Zonk/TcType.hs
Changes:
| ... | ... | @@ -98,7 +98,7 @@ type instance HsValBindGroup GhcTc = (RecFlag, LHsBinds GhcTc, StaticFlag) |
| 98 | 98 | |
| 99 | 99 | data StaticFlag
|
| 100 | 100 | = IsStatic | NotStatic
|
| 101 | - deriving( Data )
|
|
| 101 | + deriving( Eq, Data )
|
|
| 102 | 102 | -- IsStatic <=> this binding consists only code; all free
|
| 103 | 103 | -- vars are top level (or themselves static).
|
| 104 | 104 | -- So it can be moved to top level
|
| ... | ... | @@ -412,7 +412,7 @@ warnRedundantConstraints ctxt env info redundant_evs |
| 412 | 412 | | null redundant_evs
|
| 413 | 413 | = return ()
|
| 414 | 414 | |
| 415 | - | SigSkol user_ctxt _ _ <- info
|
|
| 415 | + | SigSkol _ user_ctxt _ _ <- info
|
|
| 416 | 416 | -- When dealing with a user-written type signature,
|
| 417 | 417 | -- we want to add "In the type signature for f".
|
| 418 | 418 | = report_redundant_msg True (setCtLocEnvLoc env (redundantConstraintsSpan user_ctxt))
|
| ... | ... | @@ -5481,7 +5481,7 @@ suggestAddSig ctxt ty1 _ty2 |
| 5481 | 5481 | find [] _ _ = []
|
| 5482 | 5482 | find (implic:implics) seen_eqs tv
|
| 5483 | 5483 | | tv `elem` ic_skols implic
|
| 5484 | - , InferSkol prs <- ic_info implic
|
|
| 5484 | + , InferSkol _ prs <- ic_info implic
|
|
| 5485 | 5485 | , seen_eqs
|
| 5486 | 5486 | = map fst prs
|
| 5487 | 5487 | | otherwise
|
| ... | ... | @@ -5555,7 +5555,7 @@ ctxtFixes has_ambig_tvs pred implics |
| 5555 | 5555 | , isTyVarClassPred pred -- Don't suggest adding (Eq T) to the context, say
|
| 5556 | 5556 | , (skol:skols) <- usefulContext implics pred
|
| 5557 | 5557 | , let what | null skols
|
| 5558 | - , SigSkol (PatSynCtxt {}) _ _ <- skol
|
|
| 5558 | + , SigSkol _ (PatSynCtxt {}) _ _ <- skol
|
|
| 5559 | 5559 | = text "\"required\""
|
| 5560 | 5560 | | otherwise
|
| 5561 | 5561 | = empty
|
| ... | ... | @@ -5580,7 +5580,7 @@ usefulContext implics pred |
| 5580 | 5580 | go :: [Implication] -> [SkolemInfoAnon]
|
| 5581 | 5581 | go [] = []
|
| 5582 | 5582 | go (ic : ics)
|
| 5583 | - | StaticFormSkol <- ic_info ic = []
|
|
| 5583 | + | isStaticSkolInfo (ic_info ic) = []
|
|
| 5584 | 5584 | -- Stop at a static form, because all outer Givens are irrelevant
|
| 5585 | 5585 | -- See (SF3) in Note [Grand plan for static forms] in GHC.Iface.Tidy.StaticPtrTable
|
| 5586 | 5586 | | implausible ic = rest
|
| ... | ... | @@ -5595,7 +5595,7 @@ usefulContext implics pred |
| 5595 | 5595 | | implausible_info (ic_info ic) = True
|
| 5596 | 5596 | | otherwise = False
|
| 5597 | 5597 | |
| 5598 | - implausible_info (SigSkol (InfSigCtxt {}) _ _) = True
|
|
| 5598 | + implausible_info (SigSkol _ (InfSigCtxt {}) _ _) = True
|
|
| 5599 | 5599 | implausible_info _ = False
|
| 5600 | 5600 | -- Do not suggest adding constraints to an *inferred* type signature
|
| 5601 | 5601 | |
| ... | ... | @@ -5690,17 +5690,17 @@ tidySkolemInfo env (SkolemInfo u sk_anon) = SkolemInfo u (tidySkolemInfoAnon env |
| 5690 | 5690 | ----------------
|
| 5691 | 5691 | tidySkolemInfoAnon :: TidyEnv -> SkolemInfoAnon -> SkolemInfoAnon
|
| 5692 | 5692 | tidySkolemInfoAnon env (DerivSkol ty) = DerivSkol (tidyType env ty)
|
| 5693 | -tidySkolemInfoAnon env (SigSkol cx ty tv_prs) = tidySigSkol env cx ty tv_prs
|
|
| 5694 | -tidySkolemInfoAnon env (InferSkol ids) = InferSkol (mapSnd (tidyType env) ids)
|
|
| 5693 | +tidySkolemInfoAnon env (SigSkol st cx ty tv_prs) = tidySigSkol env st cx ty tv_prs
|
|
| 5694 | +tidySkolemInfoAnon env (InferSkol st ids) = InferSkol st (mapSnd (tidyType env) ids)
|
|
| 5695 | 5695 | tidySkolemInfoAnon env (UnifyForAllSkol ty) = UnifyForAllSkol (tidyType env ty)
|
| 5696 | 5696 | tidySkolemInfoAnon _ info = info
|
| 5697 | 5697 | |
| 5698 | -tidySigSkol :: TidyEnv -> UserTypeCtxt
|
|
| 5698 | +tidySigSkol :: TidyEnv -> StaticFlag -> UserTypeCtxt
|
|
| 5699 | 5699 | -> TcType -> [(Name,TcTyVar)] -> SkolemInfoAnon
|
| 5700 | 5700 | -- We need to take special care when tidying SigSkol
|
| 5701 | 5701 | -- See Note [SigSkol SkolemInfo] in "GHC.Tc.Types.Origin"
|
| 5702 | -tidySigSkol env cx ty tv_prs
|
|
| 5703 | - = SigSkol cx (tidy_ty env ty) tv_prs'
|
|
| 5702 | +tidySigSkol env st cx ty tv_prs
|
|
| 5703 | + = SigSkol st cx (tidy_ty env ty) tv_prs'
|
|
| 5704 | 5704 | where
|
| 5705 | 5705 | tv_prs' = mapSnd (tidyTyCoVarOcc env) tv_prs
|
| 5706 | 5706 | inst_env = mkNameEnv tv_prs'
|
| ... | ... | @@ -5530,8 +5530,8 @@ discardProvCtxtGivens orig givens -- See Note [discardProvCtxtGivens] |
| 5530 | 5530 | | otherwise
|
| 5531 | 5531 | = givens
|
| 5532 | 5532 | where
|
| 5533 | - discard n (Implic { ic_info = SigSkol (PatSynCtxt n') _ _ }) = n == n'
|
|
| 5534 | - discard _ _ = False
|
|
| 5533 | + discard n (Implic { ic_info = SigSkol _ (PatSynCtxt n') _ _ }) = n == n'
|
|
| 5534 | + discard _ _ = False
|
|
| 5535 | 5535 | |
| 5536 | 5536 | |
| 5537 | 5537 | -- | An error reported after constraint solving.
|
| ... | ... | @@ -366,6 +366,7 @@ tc_nonrec_group top_lvl sig_fn prag_fn [lbind] thing_inside |
| 366 | 366 | ; let final_closed = adjustClosedForUnlifted closed ids
|
| 367 | 367 | |
| 368 | 368 | ; thing <- tcExtendLetEnv top_lvl sig_fn final_closed ids thing_inside
|
| 369 | + |
|
| 369 | 370 | ; return ( (NonRecursive, bind', sendToTopLevel final_closed), thing ) }
|
| 370 | 371 | |
| 371 | 372 | tc_nonrec_group _ _ _ binds _ -- Non-rec groups should always be a singleton
|
| ... | ... | @@ -473,7 +474,9 @@ tcPolyBinds :: TopLevelFlag -> TcSigFun -> TcPragEnv |
| 473 | 474 | -- Knows nothing about the scope of the bindings
|
| 474 | 475 | -- None of the bindings are pattern synonyms
|
| 475 | 476 | |
| 476 | -tcPolyBinds top_lvl sig_fn prag_fn rec_group rec_tc closed bind_list
|
|
| 477 | +tcPolyBinds top_lvl sig_fn prag_fn rec_group rec_tc
|
|
| 478 | + closed@(IsGroupClosed {gc_static = static_flag})
|
|
| 479 | + bind_list
|
|
| 477 | 480 | = setSrcSpan loc $
|
| 478 | 481 | recoverM (recoveryCode binder_names sig_fn) $ do
|
| 479 | 482 | -- Set up main recover; take advantage of any type sigs
|
| ... | ... | @@ -481,12 +484,12 @@ tcPolyBinds top_lvl sig_fn prag_fn rec_group rec_tc closed bind_list |
| 481 | 484 | { traceTc "------------------------------------------------" Outputable.empty
|
| 482 | 485 | ; traceTc "Bindings for {" (ppr binder_names)
|
| 483 | 486 | ; dflags <- getDynFlags
|
| 484 | - ; let plan = decideGeneralisationPlan dflags top_lvl closed sig_fn bind_list
|
|
| 487 | + ; let plan = decideGeneralisationPlan dflags closed sig_fn bind_list
|
|
| 485 | 488 | ; traceTc "Generalisation plan" (ppr plan)
|
| 486 | 489 | ; result@(_, scaled_poly_ids) <- case plan of
|
| 487 | - NoGen -> tcPolyNoGen rec_tc prag_fn sig_fn bind_list
|
|
| 488 | - InferGen -> tcPolyInfer top_lvl rec_tc prag_fn sig_fn bind_list
|
|
| 489 | - CheckGen lbind sig -> tcPolyCheck prag_fn sig lbind
|
|
| 490 | + NoGen -> tcPolyNoGen rec_tc prag_fn sig_fn bind_list
|
|
| 491 | + InferGen -> tcPolyInfer top_lvl static_flag rec_tc prag_fn sig_fn bind_list
|
|
| 492 | + CheckGen lbind sig -> tcPolyCheck static_flag prag_fn sig lbind
|
|
| 490 | 493 | |
| 491 | 494 | ; let poly_ids = map scaledThing scaled_poly_ids
|
| 492 | 495 | |
| ... | ... | @@ -567,14 +570,13 @@ tcPolyNoGen rec_tc prag_fn tc_sig_fn bind_list |
| 567 | 570 | * *
|
| 568 | 571 | ********************************************************************* -}
|
| 569 | 572 | |
| 570 | -tcPolyCheck :: TcPragEnv
|
|
| 571 | - -> TcCompleteSig
|
|
| 573 | +tcPolyCheck :: StaticFlag -> TcPragEnv -> TcCompleteSig
|
|
| 572 | 574 | -> LHsBind GhcRn -- Must be a FunBind
|
| 573 | 575 | -> TcM (LHsBinds GhcTc, [Scaled TcId])
|
| 574 | 576 | -- There is just one binding,
|
| 575 | 577 | -- it is a FunBind
|
| 576 | 578 | -- it has a complete type signature,
|
| 577 | -tcPolyCheck prag_fn
|
|
| 579 | +tcPolyCheck static_flag prag_fn
|
|
| 578 | 580 | sig@(CSig { sig_bndr = poly_id, sig_ctxt = ctxt })
|
| 579 | 581 | (L bind_loc (FunBind { fun_id = L nm_loc name
|
| 580 | 582 | , fun_matches = matches }))
|
| ... | ... | @@ -589,7 +591,7 @@ tcPolyCheck prag_fn |
| 589 | 591 | |
| 590 | 592 | ; mult <- newMultiplicityVar
|
| 591 | 593 | ; (wrap_gen, (wrap_res, matches'))
|
| 592 | - <- tcSkolemiseCompleteSig sig $ \invis_pat_tys rho_ty ->
|
|
| 594 | + <- tcSkolemiseCompleteSig sig static_flag $ \invis_pat_tys rho_ty ->
|
|
| 593 | 595 | |
| 594 | 596 | let mono_id = mkLocalId mono_name (idMult poly_id) rho_ty in
|
| 595 | 597 | tcExtendBinderStack [TcIdBndr mono_id NotTopLevel] $
|
| ... | ... | @@ -632,7 +634,7 @@ tcPolyCheck prag_fn |
| 632 | 634 | |
| 633 | 635 | ; return ([abs_bind], [Scaled mult poly_id]) }
|
| 634 | 636 | |
| 635 | -tcPolyCheck _prag_fn sig bind
|
|
| 637 | +tcPolyCheck _static _prag_fn sig bind
|
|
| 636 | 638 | = pprPanic "tcPolyCheck" (ppr sig $$ ppr bind)
|
| 637 | 639 | |
| 638 | 640 | funBindTicks :: SrcSpan -> TcId -> Module -> [LSig GhcRn]
|
| ... | ... | @@ -719,13 +721,14 @@ To address this we to do a few things |
| 719 | 721 | -}
|
| 720 | 722 | |
| 721 | 723 | tcPolyInfer
|
| 722 | - :: TopLevelFlag
|
|
| 724 | + :: TopLevelFlag -- Syntactically top-leve
|
|
| 725 | + -> StaticFlag -- Static (morally top level)
|
|
| 723 | 726 | -> RecFlag -- Whether it's recursive after breaking
|
| 724 | 727 | -- dependencies based on type signatures
|
| 725 | 728 | -> TcPragEnv -> TcSigFun
|
| 726 | 729 | -> [LHsBind GhcRn]
|
| 727 | 730 | -> TcM (LHsBinds GhcTc, [Scaled TcId])
|
| 728 | -tcPolyInfer top_lvl rec_tc prag_fn tc_sig_fn bind_list
|
|
| 731 | +tcPolyInfer top_lvl static_flag rec_tc prag_fn tc_sig_fn bind_list
|
|
| 729 | 732 | = do { (tclvl, wanted, (binds', mono_infos))
|
| 730 | 733 | <- pushLevelAndCaptureConstraints $
|
| 731 | 734 | tcMonoBinds rec_tc tc_sig_fn LetLclBndr bind_list
|
| ... | ... | @@ -745,7 +748,8 @@ tcPolyInfer top_lvl rec_tc prag_fn tc_sig_fn bind_list |
| 745 | 748 | |
| 746 | 749 | ; traceTc "simplifyInfer call" (ppr tclvl $$ ppr name_taus $$ ppr wanted)
|
| 747 | 750 | ; ((qtvs, givens, ev_binds, insoluble), residual)
|
| 748 | - <- captureConstraints $ simplifyInfer top_lvl tclvl infer_mode sigs name_taus wanted
|
|
| 751 | + <- captureConstraints $
|
|
| 752 | + simplifyInfer top_lvl static_flag tclvl infer_mode sigs name_taus wanted
|
|
| 749 | 753 | |
| 750 | 754 | ; let inferred_theta = map evVarPred givens
|
| 751 | 755 | ; scaled_exports <- checkNoErrs $
|
| ... | ... | @@ -1804,29 +1808,32 @@ instance Outputable GeneralisationPlan where |
| 1804 | 1808 | ppr (CheckGen _ s) = text "CheckGen" <+> ppr s
|
| 1805 | 1809 | |
| 1806 | 1810 | decideGeneralisationPlan
|
| 1807 | - :: DynFlags -> TopLevelFlag -> IsGroupClosed -> TcSigFun
|
|
| 1811 | + :: DynFlags -> IsGroupClosed -> TcSigFun
|
|
| 1808 | 1812 | -> [LHsBind GhcRn] -> GeneralisationPlan
|
| 1809 | -decideGeneralisationPlan dflags top_lvl closed sig_fn lbinds
|
|
| 1813 | +decideGeneralisationPlan dflags (IsGroupClosed { gc_static = static_flag
|
|
| 1814 | + , gc_closed = closed_type })
|
|
| 1815 | + sig_fn lbinds
|
|
| 1810 | 1816 | | Just (bind, sig) <- one_funbind_with_sig = CheckGen bind sig
|
| 1811 | 1817 | | generalise_binds = InferGen
|
| 1812 | 1818 | | otherwise = NoGen
|
| 1813 | 1819 | where
|
| 1814 | 1820 | generalise_binds
|
| 1815 | - | isTopLevel top_lvl = True
|
|
| 1816 | - -- See Note [Always generalise top-level bindings]
|
|
| 1821 | + | null binders = False
|
|
| 1822 | + -- Not if `binders` is empty: there is no binder to generalise, so
|
|
| 1823 | + -- generalising does nothing. And trying to generalise hurts linear
|
|
| 1824 | + -- types (see #25428). So we don't force it.
|
|
| 1825 | + -- See (NVP5) in Note [Non-variable pattern bindings aren't linear] in GHC.Tc.Gen.Bind.
|
|
| 1826 | + |
|
| 1827 | + | IsStatic <- static_flag = True
|
|
| 1828 | + -- See Note [Always generalise syntactically top-level bindings]
|
|
| 1817 | 1829 | |
| 1818 | 1830 | | has_mult_anns_and_pats = False
|
| 1819 | 1831 | -- See (NVP1) and (NVP4) in Note [Non-variable pattern bindings aren't linear]
|
| 1820 | 1832 | |
| 1821 | - | IsGroupClosed _ _ True <- closed
|
|
| 1822 | - , not (null binders) = True
|
|
| 1823 | - -- The 'True' means that all of the group's
|
|
| 1833 | + | closed_type = True
|
|
| 1834 | + -- The `closed_type` means that all of the group's
|
|
| 1824 | 1835 | -- free vars have ClosedTypeId=True; so we can ignore
|
| 1825 | 1836 | -- -XMonoLocalBinds, and generalise anyway.
|
| 1826 | - -- Except if 'fv' is empty: there is no binder to generalise, so
|
|
| 1827 | - -- generalising does nothing. And trying to generalise hurts linear
|
|
| 1828 | - -- types (see #25428). So we don't force it.
|
|
| 1829 | - -- See (NVP5) in Note [Non-variable pattern bindings aren't linear] in GHC.Tc.Gen.Bind.
|
|
| 1830 | 1837 | |
| 1831 | 1838 | | has_partial_sigs = True
|
| 1832 | 1839 | -- See Note [Partial type signatures and generalisation]
|
| ... | ... | @@ -1855,7 +1862,9 @@ decideGeneralisationPlan dflags top_lvl closed sig_fn lbinds |
| 1855 | 1862 | |
| 1856 | 1863 | isClosedBndrGroup :: TcTypeEnv -> [LHsBind GhcRn] -> IsGroupClosed
|
| 1857 | 1864 | isClosedBndrGroup type_env binds
|
| 1858 | - = IsGroupClosed is_static fv_env type_closed
|
|
| 1865 | + = IsGroupClosed { gc_static = is_static
|
|
| 1866 | + , gc_fvs = fv_env
|
|
| 1867 | + , gc_closed = type_closed }
|
|
| 1859 | 1868 | where
|
| 1860 | 1869 | fv_env :: NameEnv NameSet
|
| 1861 | 1870 | fv_env = mkNameEnv $ [ (b,fvs) | (bs,fvs) <- bind_fvs, b <-bs ]
|
| ... | ... | @@ -1886,9 +1895,9 @@ isClosedBndrGroup type_env binds |
| 1886 | 1895 | id_is_static name
|
| 1887 | 1896 | | Just thing <- lookupNameEnv type_env name
|
| 1888 | 1897 | = case thing of
|
| 1889 | - AGlobal {} -> True
|
|
| 1890 | - ATcId { tct_info = LetBound { lb_top = IsStatic } } -> True
|
|
| 1891 | - _ -> False
|
|
| 1898 | + AGlobal {} -> True
|
|
| 1899 | + ATcId { tct_info = LetBound { lb_static = IsStatic } } -> True
|
|
| 1900 | + _ -> False
|
|
| 1892 | 1901 | |
| 1893 | 1902 | | otherwise -- Imported Ids
|
| 1894 | 1903 | = True
|
| ... | ... | @@ -1916,15 +1925,20 @@ isClosedBndrGroup type_env binds |
| 1916 | 1925 | -- Ditto class method etc from the current module
|
| 1917 | 1926 | |
| 1918 | 1927 | adjustClosedForUnlifted :: IsGroupClosed -> [Scaled TcId] -> IsGroupClosed
|
| 1919 | -adjustClosedForUnlifted closed@(IsGroupClosed top_lvl fv_env type_closed) ids
|
|
| 1920 | - | IsStatic <- top_lvl
|
|
| 1921 | - , all definitely_lifted ids = closed
|
|
| 1922 | - | otherwise = IsGroupClosed NotStatic fv_env type_closed
|
|
| 1928 | +adjustClosedForUnlifted closed ids
|
|
| 1929 | + | IsGroupClosed { gc_static = IsStatic } <- closed
|
|
| 1930 | + , not (all closed_and_lifted ids)
|
|
| 1931 | + = closed { gc_static = NotStatic }
|
|
| 1932 | + | otherwise
|
|
| 1933 | + = closed
|
|
| 1923 | 1934 | where
|
| 1924 | - definitely_lifted (Scaled _ id) = definitelyLiftedType (idType id)
|
|
| 1935 | + closed_and_lifted (Scaled _ id) = noFreeVarsOfType ty
|
|
| 1936 | + && definitelyLiftedType ty
|
|
| 1937 | + where
|
|
| 1938 | + ty = idType id
|
|
| 1925 | 1939 | |
| 1926 | 1940 | sendToTopLevel :: IsGroupClosed -> StaticFlag
|
| 1927 | -sendToTopLevel (IsGroupClosed top _ _) = top
|
|
| 1941 | +sendToTopLevel (IsGroupClosed { gc_static = is_static }) = is_static
|
|
| 1928 | 1942 | |
| 1929 | 1943 | lHsBindFreeVars :: LHsBind GhcRn -> NameSet
|
| 1930 | 1944 | lHsBindFreeVars (L _ (FunBind { fun_ext = fvs })) = fvs
|
| ... | ... | @@ -1932,16 +1946,17 @@ lHsBindFreeVars (L _ (PatBind { pat_ext = fvs })) = fvs |
| 1932 | 1946 | lHsBindFreeVars _ = emptyNameSet
|
| 1933 | 1947 | |
| 1934 | 1948 | |
| 1935 | -{- Note [Always generalise top-level bindings]
|
|
| 1936 | -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 1949 | +{- Note [Always generalise syntactically top-level bindings]
|
|
| 1950 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 1937 | 1951 | It is very confusing to apply NoGen to a top level binding. Consider (#20123):
|
| 1938 | 1952 | module M where
|
| 1939 | 1953 | x = 5
|
| 1940 | 1954 | f y = (x, y)
|
| 1941 | 1955 | |
| 1942 | -The MR means that x=5 is not generalise, so f's binding is no Closed. So we'd
|
|
| 1943 | -be tempted to use NoGen. But that leads to f :: Any -> (Integer, Any), which
|
|
| 1944 | -is plain stupid.
|
|
| 1956 | +The MR means that x=5 is not generalised, so f's binding has a free variable
|
|
| 1957 | +that is not ClosedTypeId. So we'd be tempted to use NoGen. But that leads to
|
|
| 1958 | + f :: Any -> (Integer, Any)
|
|
| 1959 | +which is plain stupid.
|
|
| 1945 | 1960 | |
| 1946 | 1961 | NoGen is good when we have call sites, but not at top level, where the
|
| 1947 | 1962 | function may be exported. And it's easier to grok "MonoLocalBinds" as
|
| ... | ... | @@ -204,7 +204,7 @@ tcPolyExprCheck expr res_ty |
| 204 | 204 | = do { (wrap, expr') <- tcSkolemiseExpectedType ty thing_inside
|
| 205 | 205 | ; return (mkHsWrap wrap expr') }
|
| 206 | 206 | outer_skolemise (Right sig) thing_inside
|
| 207 | - = do { (wrap, expr') <- tcSkolemiseCompleteSig sig thing_inside
|
|
| 207 | + = do { (wrap, expr') <- tcSkolemiseCompleteSig sig NotStatic thing_inside
|
|
| 208 | 208 | ; return (mkHsWrap wrap expr') }
|
| 209 | 209 | |
| 210 | 210 | -- inner_skolemise is used when we do not have a lambda
|
| ... | ... | @@ -689,7 +689,8 @@ tcExprSig expr sig@(TcPartialSig (PSig { psig_name = name, psig_loc = loc })) |
| 689 | 689 | = NoRestrictions
|
| 690 | 690 | ; ((qtvs, givens, ev_binds, _), residual)
|
| 691 | 691 | <- captureConstraints $
|
| 692 | - simplifyInfer NotTopLevel tclvl infer_mode [sig_inst] [(name, tau)] wanted
|
|
| 692 | + simplifyInfer NotTopLevel NotStatic tclvl infer_mode
|
|
| 693 | + [sig_inst] [(name, tau)] wanted
|
|
| 693 | 694 | ; emitConstraints residual
|
| 694 | 695 | |
| 695 | 696 | ; tau <- liftZonkM $ zonkTcType tau
|
| ... | ... | @@ -622,7 +622,7 @@ tc_pat pat_ty penv ps_pat thing_inside = case ps_pat of |
| 622 | 622 | |
| 623 | 623 | VarPat x (L l name) -> do
|
| 624 | 624 | { (wrap, id) <- tcPatBndr penv name pat_ty
|
| 625 | - ; res <- tcCheckUsage name (scaledMult pat_ty) $
|
|
| 625 | + ; res <- tcCheckUsage (Scaled (scaledMult pat_ty) id) $
|
|
| 626 | 626 | tcExtendIdEnv1 name id thing_inside
|
| 627 | 627 | ; pat_ty <- readExpType (scaledThing pat_ty)
|
| 628 | 628 | ; return (mkHsWrapPat wrap (VarPat x (L l id)) pat_ty, res) }
|
| ... | ... | @@ -1979,7 +1979,7 @@ setMainCtxt main_name io_ty thing_inside |
| 1979 | 1979 | checkConstraints skol_info [] [] $ -- Builds an implication if necessary
|
| 1980 | 1980 | thing_inside -- e.g. with -fdefer-type-errors
|
| 1981 | 1981 | where
|
| 1982 | - skol_info = SigSkol (FunSigCtxt main_name NoRRC) io_ty []
|
|
| 1982 | + skol_info = SigSkol IsStatic (FunSigCtxt main_name NoRRC) io_ty []
|
|
| 1983 | 1983 | |
| 1984 | 1984 | {- Note [Dealing with main]
|
| 1985 | 1985 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ... | ... | @@ -2635,7 +2635,7 @@ tcRnExpr hsc_env mode rdr_expr |
| 2635 | 2635 | let { fresh_it = itName uniq (getLocA rdr_expr) } ;
|
| 2636 | 2636 | ((qtvs, dicts, _, _), residual)
|
| 2637 | 2637 | <- captureConstraints $
|
| 2638 | - simplifyInfer TopLevel tclvl infer_mode
|
|
| 2638 | + simplifyInfer TopLevel IsStatic tclvl infer_mode
|
|
| 2639 | 2639 | [] {- No sig vars -}
|
| 2640 | 2640 | [(fresh_it, res_ty)]
|
| 2641 | 2641 | lie ;
|
| ... | ... | @@ -46,6 +46,8 @@ import GHC.Tc.Instance.FunDeps |
| 46 | 46 | import GHC.Tc.Types.Origin
|
| 47 | 47 | import GHC.Tc.Utils.TcType
|
| 48 | 48 | |
| 49 | +import GHC.Hs.Binds ( StaticFlag )
|
|
| 50 | + |
|
| 49 | 51 | import GHC.Core.Predicate
|
| 50 | 52 | import GHC.Core.Type
|
| 51 | 53 | import GHC.Core.Ppr
|
| ... | ... | @@ -908,7 +910,8 @@ instance Outputable InferMode where |
| 908 | 910 | ppr EagerDefaulting = text "EagerDefaulting"
|
| 909 | 911 | ppr NoRestrictions = text "NoRestrictions"
|
| 910 | 912 | |
| 911 | -simplifyInfer :: TopLevelFlag
|
|
| 913 | +simplifyInfer :: TopLevelFlag -- Syntactically top-level
|
|
| 914 | + -> StaticFlag -- Static (morally top level)
|
|
| 912 | 915 | -> TcLevel -- Used when generating the constraints
|
| 913 | 916 | -> InferMode
|
| 914 | 917 | -> [TcIdSigInst] -- Any signatures (possibly partial)
|
| ... | ... | @@ -920,7 +923,7 @@ simplifyInfer :: TopLevelFlag |
| 920 | 923 | TcEvBinds, -- ... binding these evidence variables
|
| 921 | 924 | Bool) -- True <=> the residual constraints are insoluble
|
| 922 | 925 | |
| 923 | -simplifyInfer top_lvl rhs_tclvl infer_mode sigs name_taus wanteds
|
|
| 926 | +simplifyInfer top_lvl static_flag rhs_tclvl infer_mode sigs name_taus wanteds
|
|
| 924 | 927 | | isEmptyWC wanteds
|
| 925 | 928 | = do { -- When quantifying, we want to preserve any order of variables as they
|
| 926 | 929 | -- appear in partial signatures. cf. decideQuantifiedTyVars
|
| ... | ... | @@ -931,7 +934,7 @@ simplifyInfer top_lvl rhs_tclvl infer_mode sigs name_taus wanteds |
| 931 | 934 | |
| 932 | 935 | ; dep_vars <- candidateQTyVarsOfTypes (psig_tv_tys ++ psig_theta ++ map snd name_taus)
|
| 933 | 936 | |
| 934 | - ; skol_info <- mkSkolemInfo (InferSkol name_taus)
|
|
| 937 | + ; skol_info <- mkSkolemInfo (InferSkol static_flag name_taus)
|
|
| 935 | 938 | ; qtkvs <- quantifyTyVars skol_info DefaultNonStandardTyVars dep_vars
|
| 936 | 939 | ; traceTc "simplifyInfer: empty WC" (ppr name_taus $$ ppr qtkvs)
|
| 937 | 940 | ; return (qtkvs, [], emptyTcEvBinds, False) }
|
| ... | ... | @@ -992,7 +995,8 @@ simplifyInfer top_lvl rhs_tclvl infer_mode sigs name_taus wanteds |
| 992 | 995 | ; bound_theta_vars <- mapM TcM.newEvVar bound_theta
|
| 993 | 996 | |
| 994 | 997 | ; let full_theta = map idType bound_theta_vars
|
| 995 | - skol_info = InferSkol [ (name, mkPhiTy full_theta ty)
|
|
| 998 | + skol_info = InferSkol static_flag
|
|
| 999 | + [ (name, mkPhiTy full_theta ty)
|
|
| 996 | 1000 | | (name, ty) <- name_taus ]
|
| 997 | 1001 | -- mkPhiTy: we don't add the quantified variables here, because
|
| 998 | 1002 | -- they are also bound in ic_skols and we want them to be tidied
|
| ... | ... | @@ -1284,7 +1284,7 @@ nestImplicTcS skol_info ev_binds_var inner_tclvl (TcS thing_inside) |
| 1284 | 1284 | -- start with a completely empty inert set; in particular, no Givens
|
| 1285 | 1285 | -- See (SF3) in Note [Grand plan for static forms]
|
| 1286 | 1286 | -- in GHC.Iface.Tidy.StaticPtrTable
|
| 1287 | - | StaticFormSkol <- skol_info
|
|
| 1287 | + | isStaticSkolInfo skol_info
|
|
| 1288 | 1288 | = emptyInertSet inner_tclvl
|
| 1289 | 1289 | |
| 1290 | 1290 | | otherwise
|
| ... | ... | @@ -533,7 +533,7 @@ findRedundantGivens (Implic { ic_info = info, ic_need = need, ic_given = givens |
| 533 | 533 | = any isImprovementPred (pred : transSuperClasses pred)
|
| 534 | 534 | |
| 535 | 535 | warnRedundantGivens :: SkolemInfoAnon -> Bool
|
| 536 | -warnRedundantGivens (SigSkol ctxt _ _)
|
|
| 536 | +warnRedundantGivens (SigSkol _ ctxt _ _)
|
|
| 537 | 537 | = case ctxt of
|
| 538 | 538 | FunSigCtxt _ rrc -> reportRedundantConstraints rrc
|
| 539 | 539 | ExprSigCtxt rrc -> reportRedundantConstraints rrc
|
| ... | ... | @@ -299,7 +299,7 @@ tcDefMeth clas tyvars this_dict binds_in hs_sig_fn prag_fn |
| 299 | 299 | |
| 300 | 300 | ; (ev_binds, (tc_bind, _))
|
| 301 | 301 | <- checkConstraints skol_info tyvars [this_dict] $
|
| 302 | - tcPolyCheck no_prag_fn local_dm_sig
|
|
| 302 | + tcPolyCheck NotStatic no_prag_fn local_dm_sig
|
|
| 303 | 303 | (L bind_loc lm_bind)
|
| 304 | 304 | |
| 305 | 305 | ; let export = ABE { abe_poly = global_dm_id
|
| ... | ... | @@ -2121,7 +2121,7 @@ tcMethodBodyHelp hs_sig_fn sel_id local_meth_id meth_bind |
| 2121 | 2121 | , sig_ctxt = ctxt
|
| 2122 | 2122 | , sig_loc = getLocA hs_sig_ty }
|
| 2123 | 2123 | |
| 2124 | - ; (tc_bind, [Scaled _ inner_id]) <- tcPolyCheck no_prag_fn inner_meth_sig meth_bind
|
|
| 2124 | + ; (tc_bind, [Scaled _ inner_id]) <- tcPolyCheck NotStatic no_prag_fn inner_meth_sig meth_bind
|
|
| 2125 | 2125 | |
| 2126 | 2126 | ; let export = ABE { abe_poly = local_meth_id
|
| 2127 | 2127 | , abe_mono = inner_id
|
| ... | ... | @@ -2146,7 +2146,7 @@ tcMethodBodyHelp hs_sig_fn sel_id local_meth_id meth_bind |
| 2146 | 2146 | -- instance C [c] where { op = <rhs> }
|
| 2147 | 2147 | -- In <rhs>, 'c' is scope but 'b' is not!
|
| 2148 | 2148 | |
| 2149 | - ; (tc_bind, _) <- tcPolyCheck no_prag_fn tc_sig meth_bind
|
|
| 2149 | + ; (tc_bind, _) <- tcPolyCheck NotStatic no_prag_fn tc_sig meth_bind
|
|
| 2150 | 2150 | ; return tc_bind }
|
| 2151 | 2151 | |
| 2152 | 2152 | where
|
| ... | ... | @@ -153,7 +153,7 @@ tcInferPatSynDecl (PSB { psb_id = lname@(L _ name), psb_args = details |
| 153 | 153 | |
| 154 | 154 | ; ((univ_tvs, req_dicts, ev_binds, _), residual)
|
| 155 | 155 | <- captureConstraints $
|
| 156 | - simplifyInfer TopLevel tclvl NoRestrictions [] named_taus wanted
|
|
| 156 | + simplifyInfer TopLevel IsStatic tclvl NoRestrictions [] named_taus wanted
|
|
| 157 | 157 | ; top_ev_binds <- checkNoErrs (simplifyTop residual)
|
| 158 | 158 | ; addTopEvBinds top_ev_binds $
|
| 159 | 159 | |
| ... | ... | @@ -392,7 +392,7 @@ tcCheckPatSynDecl psb@PSB{ psb_id = lname@(L _ name), psb_args = details |
| 392 | 392 | ; checkTc (all (isManyTy . scaledMult) arg_tys) $
|
| 393 | 393 | TcRnLinearPatSyn sig_body_ty
|
| 394 | 394 | |
| 395 | - ; skol_info <- mkSkolemInfo (SigSkol (PatSynCtxt name) pat_ty [])
|
|
| 395 | + ; skol_info <- mkSkolemInfo (SigSkol IsStatic (PatSynCtxt name) pat_ty [])
|
|
| 396 | 396 | -- The type here is a bit bogus, but we do not print
|
| 397 | 397 | -- the type for PatSynCtxt, so it doesn't matter
|
| 398 | 398 | -- See Note [Skolem info for pattern synonyms] in "GHC.Tc.Types.Origin"
|
| ... | ... | @@ -980,7 +980,7 @@ tcPatSynBuilderBind prag_fn (PSB { psb_id = ps_lname@(L loc ps_name) |
| 980 | 980 | ; traceTc "tcPatSynBuilderBind {" $
|
| 981 | 981 | vcat [ ppr patsyn
|
| 982 | 982 | , ppr builder_id <+> dcolon <+> ppr (idType builder_id) ]
|
| 983 | - ; (builder_binds, _) <- tcPolyCheck emptyPragEnv sig (noLocA bind)
|
|
| 983 | + ; (builder_binds, _) <- tcPolyCheck IsStatic emptyPragEnv sig (noLocA bind)
|
|
| 984 | 984 | ; traceTc "tcPatSynBuilderBind }" $ ppr builder_binds
|
| 985 | 985 | ; return builder_binds } } }
|
| 986 | 986 |
| ... | ... | @@ -351,7 +351,7 @@ data IdBindingInfo |
| 351 | 351 | = NotLetBound
|
| 352 | 352 | |
| 353 | 353 | | LetBound
|
| 354 | - { lb_top :: StaticFlag
|
|
| 354 | + { lb_static :: StaticFlag
|
|
| 355 | 355 | -- IsStatic <=> this binding may safely be moved to top level
|
| 356 | 356 | -- E.g f x = let ys = reverse [1,2]
|
| 357 | 357 | -- zs = reverse ys
|
| ... | ... | @@ -369,14 +369,17 @@ data IdBindingInfo |
| 369 | 369 | -- all free vars of `e` have lb_clos=ClosedTypeId
|
| 370 | 370 | }
|
| 371 | 371 | |
| 372 | --- | IsGroupClosed describes a group of
|
|
| 373 | --- mutually-recursive /renamed/ (but not yet typechecked) bindings
|
|
| 372 | +-- | IsGroupClosed describes a group of mutually-recursive /renamed/
|
|
| 373 | +-- (but not yet typechecked) bindings
|
|
| 374 | 374 | data IsGroupClosed
|
| 375 | 375 | = IsGroupClosed
|
| 376 | - StaticFlag -- IsStatic <=> all free vars of the group are top-level or static
|
|
| 377 | - (NameEnv RhsNames) -- Frees for the RHS of each binding in the group
|
|
| 378 | - -- (includes free vars of RHS bound in the same group)
|
|
| 379 | - ClosedTypeId -- True <=> all the free vars of the group have closed types
|
|
| 376 | + { gc_static :: StaticFlag -- IsStatic <=> all free vars of the group are top-level or static
|
|
| 377 | + |
|
| 378 | + , gc_fvs :: NameEnv RhsNames -- Free vars for the RHS of each binding in the group
|
|
| 379 | + -- (includes free vars of RHS bound in the same group)
|
|
| 380 | + |
|
| 381 | + , gc_closed :: ClosedTypeId -- True <=> all the free vars of the group have closed types
|
|
| 382 | + }
|
|
| 380 | 383 | |
| 381 | 384 | type RhsNames = NameSet -- Names of variables, mentioned on the RHS of
|
| 382 | 385 | -- a definition, that are not Global or ClosedLet
|
| ... | ... | @@ -536,7 +539,7 @@ in the type environment. |
| 536 | 539 | |
| 537 | 540 | instance Outputable IdBindingInfo where
|
| 538 | 541 | ppr NotLetBound = text "NotLetBound"
|
| 539 | - ppr (LetBound { lb_top = top_lvl, lb_fvs = fvs, lb_closed = cls })
|
|
| 542 | + ppr (LetBound { lb_static = top_lvl, lb_fvs = fvs, lb_closed = cls })
|
|
| 540 | 543 | = text "LetBound" <> braces (sep [ ppr top_lvl, text "closed-type=" <+> ppr cls
|
| 541 | 544 | , ppr fvs ])
|
| 542 | 545 |
| ... | ... | @@ -1642,7 +1642,7 @@ getUserGivensFromImplics implics |
| 1642 | 1642 | get acc [] = acc
|
| 1643 | 1643 | |
| 1644 | 1644 | get acc (implic : implics)
|
| 1645 | - | StaticFormSkol <- ic_info implic
|
|
| 1645 | + | isStaticSkolInfo (ic_info implic)
|
|
| 1646 | 1646 | = acc -- For static forms, ignore all outer givens
|
| 1647 | 1647 | -- See (SF3) in Note [Grand plan for static forms] in GHC.Iface.Tidy.StaticPtrTable
|
| 1648 | 1648 | |
| ... | ... | @@ -2150,7 +2150,9 @@ checkSkolInfoAnon :: SkolemInfoAnon -- From the implication |
| 2150 | 2150 | -- So it doesn't matter much if its's incomplete
|
| 2151 | 2151 | checkSkolInfoAnon sk1 sk2 = go sk1 sk2
|
| 2152 | 2152 | where
|
| 2153 | - go (SigSkol c1 t1 s1) (SigSkol c2 t2 s2) = c1==c2 && t1 `tcEqType` t2 && s1==s2
|
|
| 2153 | + go (SigSkol _ c1 t1 s1) (SigSkol _ c2 t2 s2) = c1==c2 && t1 `tcEqType` t2 && s1==s2
|
|
| 2154 | + go (InferSkol _ ids1) (InferSkol _ ids2) = equalLength ids1 ids2 &&
|
|
| 2155 | + and (zipWith eq_pr ids1 ids2)
|
|
| 2154 | 2156 | go (SigTypeSkol cx1) (SigTypeSkol cx2) = cx1==cx2
|
| 2155 | 2157 | |
| 2156 | 2158 | go (ForAllSkol _) (ForAllSkol _) = True
|
| ... | ... | @@ -2167,8 +2169,6 @@ checkSkolInfoAnon sk1 sk2 = go sk1 sk2 |
| 2167 | 2169 | go (SpecESkol n1) (SpecESkol n2) = n1==n2
|
| 2168 | 2170 | go (PatSkol c1 _) (PatSkol c2 _) = getName c1 == getName c2
|
| 2169 | 2171 | -- Too tedious to compare the HsMatchContexts
|
| 2170 | - go (InferSkol ids1) (InferSkol ids2) = equalLength ids1 ids2 &&
|
|
| 2171 | - and (zipWith eq_pr ids1 ids2)
|
|
| 2172 | 2172 | go (UnifyForAllSkol t1) (UnifyForAllSkol t2) = t1 `tcEqType` t2
|
| 2173 | 2173 | go ReifySkol ReifySkol = True
|
| 2174 | 2174 | go RuntimeUnkSkol RuntimeUnkSkol = True
|
| ... | ... | @@ -15,9 +15,9 @@ module GHC.Tc.Types.Origin ( |
| 15 | 15 | ReportRedundantConstraints(..), reportRedundantConstraints,
|
| 16 | 16 | redundantConstraintsSpan,
|
| 17 | 17 | |
| 18 | - -- * SkolemInfo
|
|
| 18 | + -- * SkolemInfo, SkolemInfoAnon
|
|
| 19 | 19 | SkolemInfo(..), SkolemInfoAnon(..), mkSkolemInfo, getSkolemInfo, pprSigSkolInfo, pprSkolInfo,
|
| 20 | - unkSkol, unkSkolAnon,
|
|
| 20 | + unkSkol, unkSkolAnon, isStaticSkolInfo,
|
|
| 21 | 21 | |
| 22 | 22 | -- * CtOrigin
|
| 23 | 23 | CtOrigin(..), exprCtOrigin, lexprCtOrigin, matchesCtOrigin, grhssCtOrigin,
|
| ... | ... | @@ -270,11 +270,18 @@ data SkolemInfoAnon |
| 270 | 270 | -- a programmer-supplied type signature
|
| 271 | 271 | -- Location of the binding site is on the TyVar
|
| 272 | 272 | -- See Note [SigSkol SkolemInfo]
|
| 273 | + StaticFlag
|
|
| 273 | 274 | UserTypeCtxt -- What sort of signature
|
| 274 | 275 | TcType -- Original type signature (before skolemisation)
|
| 275 | 276 | [(Name,TcTyVar)] -- Maps the original name of the skolemised tyvar
|
| 276 | 277 | -- to its instantiated version
|
| 277 | 278 | |
| 279 | + | InferSkol
|
|
| 280 | + StaticFlag
|
|
| 281 | + [(Name,TcType)] -- We have inferred a type for these (mutually recursive)
|
|
| 282 | + -- polymorphic Ids, and are now checking that their RHS
|
|
| 283 | + -- constraints are satisfied.
|
|
| 284 | + |
|
| 278 | 285 | | SigTypeSkol UserTypeCtxt
|
| 279 | 286 | -- like SigSkol, but when we're kind-checking the *type*
|
| 280 | 287 | -- hence, we have less info
|
| ... | ... | @@ -311,11 +318,6 @@ data SkolemInfoAnon |
| 311 | 318 | | RuleSkol RuleName -- The LHS of a RULE
|
| 312 | 319 | | SpecESkol Name -- A SPECIALISE pragma
|
| 313 | 320 | |
| 314 | - | InferSkol [(Name,TcType)]
|
|
| 315 | - -- We have inferred a type for these (mutually recursive)
|
|
| 316 | - -- polymorphic Ids, and are now checking that their RHS
|
|
| 317 | - -- constraints are satisfied.
|
|
| 318 | - |
|
| 319 | 321 | | BracketSkol -- Template Haskell bracket
|
| 320 | 322 | |
| 321 | 323 | | UnifyForAllSkol -- We are unifying two for-all types
|
| ... | ... | @@ -370,7 +372,7 @@ instance Outputable SkolemInfoAnon where |
| 370 | 372 | |
| 371 | 373 | pprSkolInfo :: SkolemInfoAnon -> SDoc
|
| 372 | 374 | -- Complete the sentence "is a rigid type variable bound by..."
|
| 373 | -pprSkolInfo (SigSkol cx ty _) = pprSigSkolInfo cx ty
|
|
| 375 | +pprSkolInfo (SigSkol _ cx ty _) = pprSigSkolInfo cx ty
|
|
| 374 | 376 | pprSkolInfo (SigTypeSkol cx) = pprUserTypeCtxt cx
|
| 375 | 377 | pprSkolInfo (ForAllSkol tvs) = text "an explicit forall" <+> ppr tvs
|
| 376 | 378 | pprSkolInfo (IPSkol ips) = text "the implicit-parameter binding" <> plural ips <+> text "for"
|
| ... | ... | @@ -388,7 +390,7 @@ pprSkolInfo (RuleSkol name) = text "the RULE" <+> pprRuleName name |
| 388 | 390 | pprSkolInfo (SpecESkol name) = text "a SPECIALISE pragma for" <+> quotes (ppr name)
|
| 389 | 391 | pprSkolInfo (PatSkol cl mc) = sep [ pprPatSkolInfo cl
|
| 390 | 392 | , text "in" <+> pprMatchContext mc ]
|
| 391 | -pprSkolInfo (InferSkol ids) = hang (text "the inferred type" <> plural ids <+> text "of")
|
|
| 393 | +pprSkolInfo (InferSkol _ ids) = hang (text "the inferred type" <> plural ids <+> text "of")
|
|
| 392 | 394 | 2 (vcat [ ppr name <+> dcolon <+> ppr ty
|
| 393 | 395 | | (name,ty) <- ids ])
|
| 394 | 396 | pprSkolInfo (UnifyForAllSkol ty) = text "the type" <+> ppr ty
|
| ... | ... | @@ -467,6 +469,13 @@ in the right place. So we proceed as follows: |
| 467 | 469 | the instantiated skolems lying around in other types.
|
| 468 | 470 | -}
|
| 469 | 471 | |
| 472 | +isStaticSkolInfo :: SkolemInfoAnon -> Bool
|
|
| 473 | +isStaticSkolInfo StaticFormSkol = True
|
|
| 474 | +isStaticSkolInfo (SigSkol IsStatic _ _ _) = True
|
|
| 475 | +isStaticSkolInfo (InferSkol IsStatic _) = True
|
|
| 476 | +isStaticSkolInfo _ = False
|
|
| 477 | + |
|
| 478 | + |
|
| 470 | 479 | {- *********************************************************************
|
| 471 | 480 | * *
|
| 472 | 481 | CtOrigin
|
| ... | ... | @@ -91,7 +91,7 @@ import GHC.Iface.Load |
| 91 | 91 | import GHC.Tc.Errors.Types
|
| 92 | 92 | import GHC.Tc.Utils.Monad
|
| 93 | 93 | import GHC.Tc.Utils.TcType
|
| 94 | -import {-# SOURCE #-} GHC.Tc.Utils.TcMType ( tcCheckUsage )
|
|
| 94 | +import GHC.Tc.Utils.TcMType ( tcCheckUsage )
|
|
| 95 | 95 | import GHC.Tc.Types.LclEnv
|
| 96 | 96 | |
| 97 | 97 | import GHC.Core.InstEnv
|
| ... | ... | @@ -675,7 +675,7 @@ tcExtendRecIds :: [(Name, TcId)] -> TcM a -> TcM a |
| 675 | 675 | tcExtendRecIds pairs thing_inside
|
| 676 | 676 | = tc_extend_local_env NotTopLevel
|
| 677 | 677 | [ (name, ATcId { tct_id = let_id
|
| 678 | - , tct_info = LetBound { lb_top = NotStatic
|
|
| 678 | + , tct_info = LetBound { lb_static = NotStatic
|
|
| 679 | 679 | , lb_fvs = emptyNameSet
|
| 680 | 680 | , lb_closed = False } })
|
| 681 | 681 | | (name, let_id) <- pairs ] $
|
| ... | ... | @@ -691,7 +691,7 @@ tcExtendSigIds top_lvl sig_ids thing_inside |
| 691 | 691 | , tct_info = info })
|
| 692 | 692 | | id <- sig_ids
|
| 693 | 693 | , let closed = isTypeClosedLetBndr id
|
| 694 | - info = LetBound { lb_top = NotStatic
|
|
| 694 | + info = LetBound { lb_static = NotStatic
|
|
| 695 | 695 | , lb_fvs = emptyNameSet
|
| 696 | 696 | , lb_closed = closed } ]
|
| 697 | 697 | thing_inside
|
| ... | ... | @@ -703,25 +703,21 @@ tcExtendLetEnv :: TopLevelFlag -> TcSigFun -> IsGroupClosed |
| 703 | 703 | -- Used for both top-level value bindings and nested let/where-bindings
|
| 704 | 704 | -- Used for a single NonRec or a single Rec
|
| 705 | 705 | -- Adds to the TcBinderStack too
|
| 706 | -tcExtendLetEnv top_lvl _sig_fn (IsGroupClosed group_static fv_env _)
|
|
| 706 | +tcExtendLetEnv top_lvl _sig_fn
|
|
| 707 | + (IsGroupClosed {gc_static = group_static, gc_fvs = fv_env})
|
|
| 707 | 708 | ids thing_inside
|
| 708 | 709 | = tcExtendBinderStack [TcIdBndr id top_lvl | Scaled _ id <- ids] $
|
| 709 | 710 | tc_extend_local_env top_lvl
|
| 710 | 711 | [ (idName id, ATcId { tct_id = id
|
| 711 | 712 | , tct_info = mk_tct_info id })
|
| 712 | 713 | | Scaled _ id <- ids ] $
|
| 713 | - foldr check_usage thing_inside scaled_names
|
|
| 714 | + foldr tcCheckUsage thing_inside ids
|
|
| 714 | 715 | where
|
| 715 | 716 | mk_tct_info id
|
| 716 | - = LetBound { lb_top = group_static
|
|
| 717 | + = LetBound { lb_static = group_static
|
|
| 717 | 718 | , lb_fvs = lookupNameEnv fv_env (idName id) `orElse` emptyNameSet
|
| 718 | 719 | , lb_closed = isTypeClosedLetBndr id }
|
| 719 | 720 | |
| 720 | - scaled_names = [Scaled p (idName id) | Scaled p id <- ids ]
|
|
| 721 | - |
|
| 722 | - check_usage :: Scaled Name -> TcM a -> TcM a
|
|
| 723 | - check_usage (Scaled p id) thing_inside = tcCheckUsage id p thing_inside
|
|
| 724 | - |
|
| 725 | 721 | tcExtendIdEnv :: [TcId] -> TcM a -> TcM a
|
| 726 | 722 | -- For lambda-bound and case-bound Ids
|
| 727 | 723 | -- Extends the TcBinderStack as well
|
| ... | ... | @@ -2227,13 +2227,15 @@ a \/\a in the final result but all the occurrences of a will be zonked to () |
| 2227 | 2227 | -- | @tcCheckUsage name mult thing_inside@ runs @thing_inside@, checks that the
|
| 2228 | 2228 | -- usage of @name@ is a submultiplicity of @mult@, and removes @name@ from the
|
| 2229 | 2229 | -- usage environment.
|
| 2230 | -tcCheckUsage :: Name -> Mult -> TcM a -> TcM a
|
|
| 2231 | -tcCheckUsage name id_mult thing_inside
|
|
| 2230 | +tcCheckUsage :: Scaled TcId -> TcM a -> TcM a
|
|
| 2231 | +tcCheckUsage (Scaled id_mult id) thing_inside
|
|
| 2232 | 2232 | = do { (local_usage, result) <- tcCollectingUsage thing_inside
|
| 2233 | 2233 | ; check_usage (lookupUE local_usage name)
|
| 2234 | 2234 | ; tcEmitBindingUsage (deleteUE local_usage name)
|
| 2235 | 2235 | ; return result }
|
| 2236 | 2236 | where
|
| 2237 | + name = idName id
|
|
| 2238 | + |
|
| 2237 | 2239 | check_usage :: Usage -> TcM ()
|
| 2238 | 2240 | -- Checks that the usage of the newly introduced binder is compatible with
|
| 2239 | 2241 | -- its multiplicity.
|
| 1 | -module GHC.Tc.Utils.TcMType where
|
|
| 2 | - |
|
| 3 | -import GHC.Tc.Types
|
|
| 4 | -import GHC.Types.Name
|
|
| 5 | -import GHC.Core.TyCo.Rep
|
|
| 6 | - |
|
| 7 | -tcCheckUsage :: Name -> Mult -> TcM a -> TcM a |
| ... | ... | @@ -421,6 +421,7 @@ Some examples: |
| 421 | 421 | |
| 422 | 422 | tcSkolemiseGeneral
|
| 423 | 423 | :: DeepSubsumptionFlag
|
| 424 | + -> StaticFlag
|
|
| 424 | 425 | -> UserTypeCtxt
|
| 425 | 426 | -> TcType -> TcType -- top_ty and expected_ty
|
| 426 | 427 | -- Here, top_ty is the type we started to skolemise; used only in SigSkol
|
| ... | ... | @@ -429,11 +430,11 @@ tcSkolemiseGeneral |
| 429 | 430 | -- keeping the same top_ty, but successively smaller expected_tys
|
| 430 | 431 | -> ([(Name, TcInvisTVBinder)] -> TcType -> TcM result)
|
| 431 | 432 | -> TcM (HsWrapper, result)
|
| 432 | -tcSkolemiseGeneral ds_flag ctxt top_ty expected_ty thing_inside
|
|
| 433 | +tcSkolemiseGeneral ds_flag static_flag ctxt top_ty expected_ty thing_inside
|
|
| 433 | 434 | | isRhoTyDS ds_flag expected_ty
|
| 434 | 435 | -- Fast path for a very very common case: no skolemisation to do
|
| 435 | 436 | -- But still call checkConstraints in case we need an implication regardless
|
| 436 | - = do { let sig_skol = SigSkol ctxt top_ty []
|
|
| 437 | + = do { let sig_skol = SigSkol static_flag ctxt top_ty []
|
|
| 437 | 438 | ; (ev_binds, result) <- checkConstraints sig_skol [] [] $
|
| 438 | 439 | thing_inside [] expected_ty
|
| 439 | 440 | ; return (mkWpLet ev_binds, result) }
|
| ... | ... | @@ -444,7 +445,7 @@ tcSkolemiseGeneral ds_flag ctxt top_ty expected_ty thing_inside |
| 444 | 445 | ; rec { (wrap, tv_prs, given, rho_ty) <- case ds_flag of
|
| 445 | 446 | Deep -> deeplySkolemise skol_info expected_ty
|
| 446 | 447 | Shallow -> topSkolemise skol_info expected_ty
|
| 447 | - ; let sig_skol = SigSkol ctxt top_ty (map (fmap binderVar) tv_prs)
|
|
| 448 | + ; let sig_skol = SigSkol static_flag ctxt top_ty (map (fmap binderVar) tv_prs)
|
|
| 448 | 449 | ; skol_info <- mkSkolemInfo sig_skol }
|
| 449 | 450 | |
| 450 | 451 | ; let skol_tvs = map (binderVar . snd) tv_prs
|
| ... | ... | @@ -457,6 +458,7 @@ tcSkolemiseGeneral ds_flag ctxt top_ty expected_ty thing_inside |
| 457 | 458 | -- often empty, in which case mkWpLet is a no-op
|
| 458 | 459 | |
| 459 | 460 | tcSkolemiseCompleteSig :: TcCompleteSig
|
| 461 | + -> StaticFlag
|
|
| 460 | 462 | -> ([ExpPatType] -> TcRhoType -> TcM result)
|
| 461 | 463 | -> TcM (HsWrapper, result)
|
| 462 | 464 | -- ^ The wrapper has type: spec_ty ~> expected_ty
|
| ... | ... | @@ -464,11 +466,11 @@ tcSkolemiseCompleteSig :: TcCompleteSig |
| 464 | 466 | -- tcSkolemiseCompleteSig and tcTopSkolemise
|
| 465 | 467 | |
| 466 | 468 | tcSkolemiseCompleteSig (CSig { sig_bndr = poly_id, sig_ctxt = ctxt, sig_loc = loc })
|
| 467 | - thing_inside
|
|
| 469 | + static_flag thing_inside
|
|
| 468 | 470 | = do { cur_loc <- getSrcSpanM
|
| 469 | 471 | ; let poly_ty = idType poly_id
|
| 470 | 472 | ; setSrcSpan loc $ -- Sets the location for the implication constraint
|
| 471 | - tcSkolemiseGeneral Shallow ctxt poly_ty poly_ty $ \tv_prs rho_ty ->
|
|
| 473 | + tcSkolemiseGeneral Shallow static_flag ctxt poly_ty poly_ty $ \tv_prs rho_ty ->
|
|
| 472 | 474 | setSrcSpan cur_loc $ -- Revert to the original location
|
| 473 | 475 | tcExtendNameTyVarEnv (map (fmap binderVar) tv_prs) $
|
| 474 | 476 | thing_inside (map (mkInvisExpPatType . snd) tv_prs) rho_ty }
|
| ... | ... | @@ -482,14 +484,14 @@ tcSkolemiseExpectedType :: TcSigmaType |
| 482 | 484 | -- In the call (f e) we will call tcSkolemiseExpectedType on (forall a.blah)
|
| 483 | 485 | -- before typececking `e`
|
| 484 | 486 | tcSkolemiseExpectedType exp_ty thing_inside
|
| 485 | - = tcSkolemiseGeneral Shallow GenSigCtxt exp_ty exp_ty $ \tv_prs rho_ty ->
|
|
| 487 | + = tcSkolemiseGeneral Shallow NotStatic GenSigCtxt exp_ty exp_ty $ \tv_prs rho_ty ->
|
|
| 486 | 488 | thing_inside (map (mkInvisExpPatType . snd) tv_prs) rho_ty
|
| 487 | 489 | |
| 488 | 490 | tcSkolemise :: DeepSubsumptionFlag -> UserTypeCtxt -> TcSigmaType
|
| 489 | 491 | -> (TcRhoType -> TcM result)
|
| 490 | 492 | -> TcM (HsWrapper, result)
|
| 491 | 493 | tcSkolemise ds_flag ctxt expected_ty thing_inside
|
| 492 | - = tcSkolemiseGeneral ds_flag ctxt expected_ty expected_ty $ \_ rho_ty ->
|
|
| 494 | + = tcSkolemiseGeneral ds_flag NotStatic ctxt expected_ty expected_ty $ \_ rho_ty ->
|
|
| 493 | 495 | thing_inside rho_ty
|
| 494 | 496 | |
| 495 | 497 | checkConstraints :: SkolemInfoAnon
|
| ... | ... | @@ -584,6 +586,7 @@ implicationNeeded skol_info skol_tvs given |
| 584 | 586 | |
| 585 | 587 | alwaysBuildImplication :: SkolemInfoAnon -> Bool
|
| 586 | 588 | -- See Note [When to build an implication]
|
| 589 | +alwaysBuildImplication (SigSkol IsStatic _ _ _) = True
|
|
| 587 | 590 | alwaysBuildImplication _ = False
|
| 588 | 591 | |
| 589 | 592 | {- Commmented out for now while I figure out about error messages.
|
| ... | ... | @@ -829,7 +832,7 @@ matchExpectedFunTys herald ctx arity (Check top_ty) thing_inside |
| 829 | 832 | | isSigmaTy ty -- An invisible quantifier at the top
|
| 830 | 833 | || (n_req > 0 && isForAllTy ty) -- A visible quantifier at top, and we need it
|
| 831 | 834 | = do { rec { (n_req', wrap_gen, tv_nms, bndrs, given, inner_ty) <- skolemiseRequired skol_info n_req ty
|
| 832 | - ; let sig_skol = SigSkol ctx top_ty (tv_nms `zip` skol_tvs)
|
|
| 835 | + ; let sig_skol = SigSkol NotStatic ctx top_ty (tv_nms `zip` skol_tvs)
|
|
| 833 | 836 | skol_tvs = binderVars bndrs
|
| 834 | 837 | ; skol_info <- mkSkolemInfo sig_skol }
|
| 835 | 838 | -- rec {..}: see Note [Keeping SkolemInfo inside a SkolemTv]
|
| ... | ... | @@ -854,7 +857,7 @@ matchExpectedFunTys herald ctx arity (Check top_ty) thing_inside |
| 854 | 857 | ; case ds_flag of
|
| 855 | 858 | Shallow -> do { res <- thing_inside pat_tys (mkCheckExpType rho_ty)
|
| 856 | 859 | ; return (idHsWrapper, res) }
|
| 857 | - Deep -> tcSkolemiseGeneral Deep ctx top_ty rho_ty $ \_ rho_ty ->
|
|
| 860 | + Deep -> tcSkolemiseGeneral Deep NotStatic ctx top_ty rho_ty $ \_ rho_ty ->
|
|
| 858 | 861 | -- "_" drop the /deeply/-skolemise binders
|
| 859 | 862 | -- They do not line up with binders in the Match
|
| 860 | 863 | thing_inside pat_tys (mkCheckExpType rho_ty) }
|
| ... | ... | @@ -2054,7 +2057,7 @@ tc_sub_type_deep pos unify inst_orig ctxt ty_actual ty_expected |
| 2054 | 2057 | arg_wrap res_wrap
|
| 2055 | 2058 | }
|
| 2056 | 2059 | where
|
| 2057 | - given_orig = GivenOrigin (SigSkol GenSigCtxt exp_arg [])
|
|
| 2060 | + given_orig = GivenOrigin (SigSkol NotStatic GenSigCtxt exp_arg [])
|
|
| 2058 | 2061 | |
| 2059 | 2062 | -- | Like 'mkWpFun', except that it performs the necessary
|
| 2060 | 2063 | -- representation-polymorphism checks on the argument type in the case that
|
| ... | ... | @@ -521,10 +521,10 @@ zonkSkolemInfo :: SkolemInfo -> ZonkM SkolemInfo |
| 521 | 521 | zonkSkolemInfo (SkolemInfo u sk) = SkolemInfo u <$> zonkSkolemInfoAnon sk
|
| 522 | 522 | |
| 523 | 523 | zonkSkolemInfoAnon :: SkolemInfoAnon -> ZonkM SkolemInfoAnon
|
| 524 | -zonkSkolemInfoAnon (SigSkol cx ty tv_prs) = do { ty' <- zonkTcType ty
|
|
| 525 | - ; return (SigSkol cx ty' tv_prs) }
|
|
| 526 | -zonkSkolemInfoAnon (InferSkol ntys) = do { ntys' <- mapM do_one ntys
|
|
| 527 | - ; return (InferSkol ntys') }
|
|
| 524 | +zonkSkolemInfoAnon (SigSkol st cx ty tv_prs) = do { ty' <- zonkTcType ty
|
|
| 525 | + ; return (SigSkol st cx ty' tv_prs) }
|
|
| 526 | +zonkSkolemInfoAnon (InferSkol st ntys) = do { ntys' <- mapM do_one ntys
|
|
| 527 | + ; return (InferSkol st ntys') }
|
|
| 528 | 528 | where
|
| 529 | 529 | do_one (n, ty) = do { ty' <- zonkTcType ty; return (n, ty') }
|
| 530 | 530 | zonkSkolemInfoAnon skol_info = return skol_info
|