Ben Gamari pushed new branch wip/backports-9.14 at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/backports-9.14
You're receiving this email because of your account on gitlab.haskell.org.
1
0
Ben Gamari pushed new branch wip/T26538 at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T26538
You're receiving this email because of your account on gitlab.haskell.org.
1
0
Ben Gamari pushed new branch wip/T26539 at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/T26539
You're receiving this email because of your account on gitlab.haskell.org.
1
0
Ben Gamari pushed new tag ghc-9.14.1-rc1 at Glasgow Haskell Compiler / GHC
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/tree/ghc-9.14.1-rc1
You're receiving this email because of your account on gitlab.haskell.org.
1
0
[Git][ghc/ghc][wip/ani/kill-popErrCtxt] pass in the location of the head of the application chain to addArgCtxt to...
by Apoorv Ingle (@ani) 30 Oct '25
by Apoorv Ingle (@ani) 30 Oct '25
30 Oct '25
Apoorv Ingle pushed to branch wip/ani/kill-popErrCtxt at Glasgow Haskell Compiler / GHC
Commits:
eb9ac0c9 by Apoorv Ingle at 2025-10-30T13:27:46-05:00
pass in the location of the head of the application chain to addArgCtxt to print better error messages
- - - - -
3 changed files:
- compiler/GHC/Tc/Gen/App.hs
- compiler/GHC/Tc/Gen/Do.hs
- compiler/GHC/Tc/Gen/Head.hs
Changes:
=====================================
compiler/GHC/Tc/Gen/App.hs
=====================================
@@ -175,6 +175,9 @@ Note [Instantiation variables are short lived]
-- CAUTION: Any changes to tcApp should be reflected here
-- cf. T19167. the head is an expanded expression applied to a type
-- TODO: Use runInfer for tcExprSigma?
+-- Caution: Currently we assume that the expression is compiler generated/expanded
+-- Becuase that is that T19167 testcase generates. This function can possibly
+-- take in the rn_expr and its location to pass into tcValArgs
tcExprSigma :: Bool -> HsExpr GhcRn -> TcM (HsExpr GhcTc, TcSigmaType)
tcExprSigma inst rn_expr
= do { (fun@(rn_fun,fun_ctxt), rn_args) <- splitHsApps rn_expr
@@ -183,7 +186,7 @@ tcExprSigma inst rn_expr
; code_orig <- getSrcCodeOrigin
; let fun_orig = srcCodeOriginCtOrigin rn_expr code_orig
; (inst_args, app_res_sigma) <- tcInstFun do_ql inst fun_orig (tc_fun, rn_fun, fun_ctxt) fun_sigma rn_args
- ; tc_args <- tcValArgs do_ql rn_fun inst_args
+ ; tc_args <- tcValArgs do_ql (rn_fun, generatedSrcSpan) inst_args
; let tc_expr = rebuildHsApps (tc_fun, fun_ctxt) tc_args
; return (tc_expr, app_res_sigma) }
@@ -396,18 +399,18 @@ tcApp :: HsExpr GhcRn
-- See Note [tcApp: typechecking applications]
tcApp rn_expr exp_res_ty
= do { -- Step 1: Split the application chain
- (fun@(rn_fun, fun_loc), rn_args) <- splitHsApps rn_expr
+ (fun@(rn_fun, fun_lspan), rn_args) <- splitHsApps rn_expr
; inGenCode <- inGeneratedCode
; traceTc "tcApp {" $
vcat [ text "generated? " <+> ppr inGenCode
, text "rn_expr:" <+> ppr rn_expr
, text "rn_fun:" <+> ppr rn_fun
- , text "fun_loc:" <+> ppr fun_loc
+ , text "fun_lspan:" <+> ppr fun_lspan
, text "rn_args:" <+> ppr rn_args ]
-- Step 2: Infer the type of `fun`, the head of the application
; (tc_fun, fun_sigma) <- tcInferAppHead fun
- ; let tc_head = (tc_fun, fun_loc)
+ ; let tc_head = (tc_fun, fun_lspan)
-- inst_final: top-instantiate the result type of the application,
-- EXCEPT if we are trying to infer a sigma-type
inst_final = case exp_res_ty of
@@ -438,7 +441,7 @@ tcApp rn_expr exp_res_ty
, text "fun_origin" <+> ppr fun_orig
, text "do_ql:" <+> ppr do_ql]
; (inst_args, app_res_rho)
- <- tcInstFun do_ql inst_final fun_orig (tc_fun, rn_fun, fun_loc) fun_sigma rn_args
+ <- tcInstFun do_ql inst_final fun_orig (tc_fun, rn_fun, fun_lspan) fun_sigma rn_args
-- See (TCAPP1) and (TCAPP2) in
-- Note [tcApp: typechecking applications]
@@ -451,7 +454,7 @@ tcApp rn_expr exp_res_ty
app_res_rho exp_res_ty
-- Step 4.2: typecheck the arguments
- ; tc_args <- tcValArgs NoQL rn_fun inst_args
+ ; tc_args <- tcValArgs NoQL (rn_fun, fun_lspan) inst_args
-- Step 4.3: wrap up
; finishApp tc_head tc_args app_res_rho res_wrap }
@@ -462,7 +465,7 @@ tcApp rn_expr exp_res_ty
-- Step 5.2: typecheck the arguments, and monomorphise
-- any un-unified instantiation variables
- ; tc_args <- tcValArgs DoQL rn_fun inst_args
+ ; tc_args <- tcValArgs DoQL (rn_fun, fun_lspan) inst_args
-- Step 5.3: zonk to expose the polymorphism hidden under
-- QuickLook instantiation variables in `app_res_rho`
; app_res_rho <- liftZonkM $ zonkTcType app_res_rho
@@ -549,16 +552,16 @@ checkResultTy rn_expr (tc_fun, fun_loc) inst_args app_res_rho (Check res_ty)
thing_inside
----------------
-tcValArgs :: QLFlag -> HsExpr GhcRn -> [HsExprArg 'TcpInst] -> TcM [HsExprArg 'TcpTc]
+tcValArgs :: QLFlag -> (HsExpr GhcRn, SrcSpan) -> [HsExprArg 'TcpInst] -> TcM [HsExprArg 'TcpTc]
-- Importantly, tcValArgs works left-to-right, so that by the time we
-- encounter an argument, we have monomorphised all the instantiation
-- variables that its type contains. All that is left to do is an ordinary
-- zonkTcType. See Note [Monomorphise instantiation variables].
-tcValArgs do_ql fun args = go do_ql 0 args
+tcValArgs do_ql (fun, fun_lspan) args = go do_ql 0 args
where
go _ _ [] = return []
go do_ql pos (arg : args) =
- do { arg' <- tcValArg do_ql pos' fun arg
+ do { arg' <- tcValArg do_ql pos' (fun, fun_lspan) arg
; args' <- go do_ql pos' args
; return (arg' : args') }
where
@@ -574,7 +577,7 @@ tcValArgs do_ql fun args = go do_ql 0 args
= pos
-tcValArg :: QLFlag -> Int -> HsExpr GhcRn -> HsExprArg 'TcpInst -- Actual argument
+tcValArg :: QLFlag -> Int -> (HsExpr GhcRn, SrcSpan) -> HsExprArg 'TcpInst -- Actual argument
-> TcM (HsExprArg 'TcpTc) -- Resulting argument
tcValArg _ _ _ (EPrag l p) = return (EPrag l (tcExprPrag p))
tcValArg _ _ _ (ETypeArg l hty ty) = return (ETypeArg l hty ty)
@@ -583,10 +586,10 @@ tcValArg do_ql _ _ (EWrap (EHsWrap w)) = do { whenQL do_ql $ qlMonoHsWrapper w
-- qlMonoHsWrapper: see Note [Monomorphise instantiation variables]
tcValArg _ _ _ (EWrap ew) = return (EWrap ew)
-tcValArg do_ql pos fun (EValArg { ea_loc_span = lspan
+tcValArg do_ql pos (fun, fun_lspan) (EValArg { ea_loc_span = lspan
, ea_arg = larg@(L arg_loc arg)
, ea_arg_ty = sc_arg_ty })
- = addArgCtxt pos fun larg $
+ = addArgCtxt pos (fun, fun_lspan) larg $
do { -- Crucial step: expose QL results before checking exp_arg_ty
-- So far as the paper is concerned, this step applies
-- the poly-substitution Theta, learned by QL, so that we
@@ -601,6 +604,7 @@ tcValArg do_ql pos fun (EValArg { ea_loc_span = lspan
NoQL -> return sc_arg_ty
; traceTc "tcValArg {" $
vcat [ text "lspan:" <+> ppr lspan
+ , text "fun_lspan" <+> ppr fun_lspan
, text "sigma_type" <+> ppr (mkCheckExpType exp_arg_ty)
, text "arg:" <+> ppr larg
]
@@ -615,7 +619,7 @@ tcValArg do_ql pos fun (EValArg { ea_loc_span = lspan
, ea_arg = L arg_loc arg'
, ea_arg_ty = noExtField }) }
-tcValArg _ pos fun (EValArgQL {
+tcValArg _ pos (fun, fun_lspan) (EValArgQL {
eaql_wanted = wanted
, eaql_loc_span = lspan
, eaql_arg_ty = sc_arg_ty
@@ -626,7 +630,7 @@ tcValArg _ pos fun (EValArgQL {
, eaql_args = inst_args
, eaql_encl = arg_influences_enclosing_call
, eaql_res_rho = app_res_rho })
- = addArgCtxt pos fun larg $
+ = addArgCtxt pos (fun, fun_lspan) larg $
do { -- Expose QL results to tcSkolemise, as in EValArg case
Scaled mult exp_arg_ty <- liftZonkM $ zonkScaledTcType sc_arg_ty
@@ -635,6 +639,8 @@ tcValArg _ pos fun (EValArgQL {
, text "args:" <+> ppr inst_args
, text "mult:" <+> ppr mult
, text "fun" <+> ppr fun
+ , text "app_lspan" <+> ppr lspan
+ , text "head_lspan" <+> ppr fun_lspan
, text "tc_head" <+> ppr tc_head])
; ds_flag <- getDeepSubsumptionFlag
@@ -653,7 +659,7 @@ tcValArg _ pos fun (EValArgQL {
; unless arg_influences_enclosing_call $ -- Don't repeat
qlUnify app_res_rho exp_arg_rho -- the qlUnify
- ; tc_args <- tcValArgs DoQL rn_fun inst_args
+ ; tc_args <- tcValArgs DoQL (rn_fun, snd tc_head) inst_args
; app_res_rho <- liftZonkM $ zonkTcType app_res_rho
; res_wrap <- checkResultTy rn_expr tc_head inst_args
app_res_rho (mkCheckExpType exp_arg_rho)
@@ -696,20 +702,20 @@ tcInstFun :: QLFlag
-- Generally speaking we pass in True; in Fig 5 of the paper
-- |-inst returns a rho-type
-> CtOrigin
- -> (HsExpr GhcTc, HsExpr GhcRn, SrcSpan)
+ -> (HsExpr GhcTc, HsExpr GhcRn, SrcSpan) -- ANI: TODO, move HsExpr GhcRn, SrcSpan to CtOrigin
-> TcSigmaType -> [HsExprArg 'TcpRn]
-> TcM ( [HsExprArg 'TcpInst]
, TcSigmaType ) -- Does not instantiate trailing invisible foralls
-- This crucial function implements the |-inst judgement in Fig 4, plus the
-- modification in Fig 5, of the QL paper:
-- "A quick look at impredicativity" (ICFP'20).
-tcInstFun do_ql inst_final fun_orig (tc_fun, rn_fun, fun_ctxt) fun_sigma rn_args
+tcInstFun do_ql inst_final fun_orig (tc_fun, rn_fun, fun_lspan) fun_sigma rn_args
= do { traceTc "tcInstFun" (vcat [ text "origin" <+> ppr fun_orig
, text "tc_fun" <+> ppr tc_fun
, text "fun_sigma" <+> ppr fun_sigma
, text "args:" <+> ppr rn_args
, text "do_ql" <+> ppr do_ql
- , text "ctx" <+> ppr fun_ctxt])
+ , text "ctx" <+> ppr fun_lspan])
; setQLInstLevel do_ql $ -- See (TCAPP1) and (TCAPP2) in
-- Note [tcApp: typechecking applications]
go 1 [] fun_sigma rn_args }
@@ -786,7 +792,7 @@ tcInstFun do_ql inst_final fun_orig (tc_fun, rn_fun, fun_ctxt) fun_sigma rn_args
= do { (_inst_tvs, wrap, fun_rho) <-
-- addHeadCtxt: important for the class constraints
-- that may be emitted from instantiating fun_sigma
- setSrcSpan fun_ctxt $
+ setSrcSpan fun_lspan $
instantiateSigma fun_orig fun_conc_tvs tvs theta body2
-- See Note [Representation-polymorphism checking built-ins]
-- in GHC.Tc.Utils.Concrete.
@@ -881,7 +887,7 @@ tcInstFun do_ql inst_final fun_orig (tc_fun, rn_fun, fun_ctxt) fun_sigma rn_args
(Just $ HsExprTcThing tc_fun)
(n_val_args, fun_sigma) fun_ty
- ; arg' <- quickLookArg do_ql pos ctxt rn_fun arg arg_ty
+ ; arg' <- quickLookArg do_ql pos ctxt (rn_fun, fun_lspan) arg arg_ty
; let acc' = arg' : addArgWrap wrap acc
; go (pos+1) acc' res_ty rest_args }
@@ -931,7 +937,7 @@ looks_like_type_arg EValArg{ ea_arg = L _ e } =
_ -> False
looks_like_type_arg _ = False
-addArgCtxt :: Int -> HsExpr GhcRn -> LHsExpr GhcRn
+addArgCtxt :: Int -> (HsExpr GhcRn, SrcSpan) -> LHsExpr GhcRn
-> TcM a -> TcM a
-- There are 2 cases:
-- 1. In the normal case, we add an informative context (<=> `inGeneratedCode` is `False`)
@@ -942,7 +948,7 @@ addArgCtxt :: Int -> HsExpr GhcRn -> LHsExpr GhcRn
-- (iii) if arg_loc is RealSrcLoc then update tcl_loc and add "In the expression: arg" to ErrCtxtStack
-- See Note [Rebindable syntax and XXExprGhcRn] in GHC.Hs.Expr
-- See Note [Expanding HsDo with XXExprGhcRn] in GHC.Tc.Gen.Do
-addArgCtxt arg_no fun (L arg_loc arg) thing_inside
+addArgCtxt arg_no (fun, fun_lspan) (L arg_loc arg) thing_inside
= do { in_generated_code <- inGeneratedCode
; err_ctx <- getErrCtxt
; env0 <- liftZonkM tcInitTidyEnv
@@ -951,12 +957,14 @@ addArgCtxt arg_no fun (L arg_loc arg) thing_inside
, text "arg: " <+> ppr (arg, arg_no)
, text "arg_loc:" <+> ppr arg_loc
, text "fun:" <+> ppr fun
- , text "err_ctx" <+> vcat (fmap (\ (x, y) -> case x of
- MkErrCtxt (ExpansionCodeCtxt{}) _ -> text "<EXPN>" <+> pprErrCtxtMsg y
- _ -> text "<USER>" <+> pprErrCtxtMsg y)
- (take 4 (zip err_ctx err_ctx_msg)))
+ , text "fun_lspan" <+> ppr fun_lspan
+ , text "err_ctx" <+> vcat (fmap (\ (x, y) ->
+ case x of
+ MkErrCtxt (ExpansionCodeCtxt{}) _ -> text "<EXPN>" <+> pprErrCtxtMsg y
+ _ -> text "<USER>" <+> pprErrCtxtMsg y)
+ (take 4 (zip err_ctx err_ctx_msg)))
])
- ; if in_generated_code
+ ; if in_generated_code && isGeneratedSrcSpan fun_lspan
then updCtxtForArg (L arg_loc arg) $
thing_inside
else do setSrcSpanA arg_loc $
@@ -1745,24 +1753,26 @@ This turned out to be more subtle than I expected. Wrinkles:
-}
-quickLookArg :: QLFlag -> Int -> SrcSpan -> HsExpr GhcRn
+quickLookArg :: QLFlag -> Int
+ -> SrcSpan -- ^ location span of the whole application
+ -> (HsExpr GhcRn, SrcSpan) -- ^ Head of the application chain and its source span
-> LHsExpr GhcRn -- ^ Argument
-> Scaled TcSigmaTypeFRR -- ^ Type expected by the function
-> TcM (HsExprArg 'TcpInst)
-- See Note [Quick Look at value arguments]
-quickLookArg NoQL _ ctxt _ larg orig_arg_ty
- = skipQuickLook ctxt larg orig_arg_ty
-quickLookArg DoQL pos ctxt fun larg orig_arg_ty
+quickLookArg NoQL _ app_lspan _ larg orig_arg_ty
+ = skipQuickLook app_lspan larg orig_arg_ty
+quickLookArg DoQL pos app_lspan fun_and_lspan larg orig_arg_ty
= do { is_rho <- tcIsDeepRho (scaledThing orig_arg_ty)
; traceTc "qla" (ppr orig_arg_ty $$ ppr is_rho)
; if not is_rho
- then skipQuickLook ctxt larg orig_arg_ty
- else quickLookArg1 pos ctxt fun larg orig_arg_ty }
+ then skipQuickLook app_lspan larg orig_arg_ty
+ else quickLookArg1 pos app_lspan fun_and_lspan larg orig_arg_ty }
skipQuickLook :: SrcSpan -> LHsExpr GhcRn -> Scaled TcRhoType
-> TcM (HsExprArg 'TcpInst)
-skipQuickLook ctxt larg arg_ty
- = return (EValArg { ea_loc_span = ctxt
+skipQuickLook app_lspan larg arg_ty
+ = return (EValArg { ea_loc_span = app_lspan
, ea_arg = larg
, ea_arg_ty = arg_ty })
@@ -1800,14 +1810,14 @@ isGuardedTy ty
| Just {} <- tcSplitAppTy_maybe ty = True
| otherwise = False
-quickLookArg1 :: Int -> SrcSpan -> HsExpr GhcRn -> LHsExpr GhcRn
+quickLookArg1 :: Int -> SrcSpan -> (HsExpr GhcRn, SrcSpan) -> LHsExpr GhcRn
-> Scaled TcRhoType -- Deeply skolemised
-> TcM (HsExprArg 'TcpInst)
-- quickLookArg1 implements the "QL Argument" judgement in Fig 5 of the paper
-quickLookArg1 pos ctxt fun larg@(L _ arg) sc_arg_ty@(Scaled _ orig_arg_rho)
- = addArgCtxt pos fun larg $ -- Context needed for constraints
+quickLookArg1 pos app_lspan (fun, fun_lspan) larg@(L _ arg) sc_arg_ty@(Scaled _ orig_arg_rho)
+ = addArgCtxt pos (fun, fun_lspan) larg $ -- Context needed for constraints
-- generated by calls in arg
- do { ((rn_fun, fun_ctxt), rn_args) <- splitHsApps arg
+ do { ((rn_fun, fun_lspan), rn_args) <- splitHsApps arg
-- Step 1: get the type of the head of the argument
; (fun_ue, mb_fun_ty) <- tcCollectingUsage $ tcInferAppHead_maybe rn_fun
@@ -1823,15 +1833,15 @@ quickLookArg1 pos ctxt fun larg@(L _ arg) sc_arg_ty@(Scaled _ orig_arg_rho)
, text "args:" <+> ppr rn_args ]
; case mb_fun_ty of {
- Nothing -> skipQuickLook ctxt larg sc_arg_ty ; -- fun is too complicated
+ Nothing -> skipQuickLook app_lspan larg sc_arg_ty ; -- fun is too complicated
Just (tc_fun, fun_sigma) ->
-- step 2: use |-inst to instantiate the head applied to the arguments
- do { let tc_head = (tc_fun, fun_ctxt)
+ do { let tc_head = (tc_fun, fun_lspan)
; do_ql <- wantQuickLook rn_fun
; ((inst_args, app_res_rho), wanted)
<- captureConstraints $
- tcInstFun do_ql True (exprCtOrigin arg) (tc_fun, rn_fun, fun_ctxt) fun_sigma rn_args
+ tcInstFun do_ql True (exprCtOrigin arg) (tc_fun, rn_fun, fun_lspan) fun_sigma rn_args
-- We must capture type-class and equality constraints here, but
-- not equality constraints. See (QLA6) in Note [Quick Look at
-- value arguments]
@@ -1863,7 +1873,7 @@ quickLookArg1 pos ctxt fun larg@(L _ arg) sc_arg_ty@(Scaled _ orig_arg_rho)
; traceTc "quickLookArg done }" (ppr rn_fun)
- ; return (EValArgQL { eaql_loc_span = ctxt
+ ; return (EValArgQL { eaql_loc_span = app_lspan
, eaql_arg_ty = sc_arg_ty
, eaql_larg = larg
, eaql_tc_fun = tc_head
=====================================
compiler/GHC/Tc/Gen/Do.hs
=====================================
@@ -81,7 +81,7 @@ expand_do_stmts flav [stmt@(L sloc (LastStmt _ body@(L body_loc _) _ ret_expr))]
-- See `checkLastStmt` and `Syntax.Expr.StmtLR.LastStmt`
| NoSyntaxExprRn <- ret_expr
-- Last statement is just body if we are not in ListComp context. See Syntax.Expr.LastStmt
- = return $ L sloc (mkExpandedLastStmt (HsPar noExtField body))
+ = return $ L sloc (mkExpandedStmt stmt flav (HsPar noExtField body))
| SyntaxExprRn ret <- ret_expr -- We have unfortunately lost the location on the return function :(
--
@@ -89,7 +89,7 @@ expand_do_stmts flav [stmt@(L sloc (LastStmt _ body@(L body_loc _) _ ret_expr))]
-- return e ~~> return e
-- to make T18324 work
= do let expansion = L body_loc (genHsApp ret body)
- return $ L sloc (mkExpandedLastStmt (HsPar noExtField expansion))
+ return $ L sloc (mkExpandedStmt stmt flav (HsPar noExtField expansion))
expand_do_stmts doFlavour (stmt@(L loc (LetStmt _ bs)) : lstmts) =
-- See Note [Expanding HsDo with XXExprGhcRn] Equation (3) below
@@ -118,7 +118,7 @@ expand_do_stmts doFlavour (stmt@(L loc (BindStmt xbsrn pat e)): lstmts)
| otherwise
= pprPanic "expand_do_stmts: The impossible happened, missing bind operator from renamer" (text "stmt" <+> ppr stmt)
-expand_do_stmts doFlavour (stmt@(L loc (BodyStmt _ e (SyntaxExprRn then_op) _)) : lstmts) =
+expand_do_stmts doFlavour (stmt@(L loc (BodyStmt _ (L e_lspan e) (SyntaxExprRn then_op) _)) : lstmts) =
-- See Note [BodyStmt] in Language.Haskell.Syntax.Expr
-- See Note [Expanding HsDo with XXExprGhcRn] Equation (1) below
-- stmts ~~> stmts'
@@ -126,7 +126,7 @@ expand_do_stmts doFlavour (stmt@(L loc (BodyStmt _ e (SyntaxExprRn then_op) _))
-- e ; stmts ~~> (>>) e stmts'
do expand_stmts_expr <- expand_do_stmts doFlavour lstmts
let expansion = genHsExpApps then_op -- (>>)
- [ e
+ [ L e_lspan (mkExpandedStmt stmt doFlavour e)
, expand_stmts_expr ]
return $ L loc (mkExpandedStmt stmt doFlavour expansion)
@@ -486,3 +486,6 @@ It stores the original statement (with location) and the expanded expression
mkExpandedPatRn :: Pat GhcRn -> HsExpr GhcRn -> HsExpr GhcRn
mkExpandedPatRn pat e = XExpr (ExpandedThingRn (OrigPat pat) e)
+
+mkPopErrCtxtExprRn :: HsExpr GhcRn -> HsExpr GhcRn
+mkPopErrCtxtExprRn e = XExpr (ExpandedThingRn PopErrCtxt e)
=====================================
compiler/GHC/Tc/Gen/Head.hs
=====================================
@@ -175,7 +175,7 @@ data HsExprArg (p :: TcPass) where -- See Note [HsExprArg]
, eaql_larg :: LHsExpr GhcRn -- Original application, for
-- location and error msgs
, eaql_rn_fun :: HsExpr GhcRn -- Head of the argument if it is an application
- , eaql_tc_fun :: (HsExpr GhcTc, SrcSpan) -- Typechecked head
+ , eaql_tc_fun :: (HsExpr GhcTc, SrcSpan) -- Typechecked head and its location span
, eaql_fun_ue :: UsageEnv -- Usage environment of the typechecked head (QLA5)
, eaql_args :: [HsExprArg 'TcpInst] -- Args: instantiated, not typechecked
, eaql_wanted :: WantedConstraints
@@ -456,8 +456,8 @@ tcInferAppHead :: (HsExpr GhcRn, SrcSpan)
-- cases are dealt with by splitHsApps.
--
-- See Note [tcApp: typechecking applications] in GHC.Tc.Gen.App
-tcInferAppHead (fun,fun_loc)
- = setSrcSpan fun_loc $
+tcInferAppHead (fun,fun_lspan)
+ = setSrcSpan fun_lspan $
do { mb_tc_fun <- tcInferAppHead_maybe fun
; case mb_tc_fun of
Just (fun', fun_sigma) -> return (fun', fun_sigma)
@@ -471,7 +471,8 @@ tcInferAppHead_maybe fun =
case fun of
HsVar _ nm -> Just <$> tcInferId nm
XExpr (HsRecSelRn f) -> Just <$> tcInferRecSelId f
- XExpr (ExpandedThingRn o e) -> Just <$> (addExpansionErrCtxt o (srcCodeOriginErrCtxMsg o) $ -- We do not want to instantiate c.f. T19167
+ XExpr (ExpandedThingRn o e) -> Just <$> (addExpansionErrCtxt o (srcCodeOriginErrCtxMsg o) $
+ -- We do not want to instantiate c.f. T19167
tcExprSigma False e)
ExprWithTySig _ e hs_ty -> Just <$> tcExprWithSig e hs_ty
HsOverLit _ lit -> Just <$> tcInferOverLit lit
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/eb9ac0c913c9c4218eb868081aab64e…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/eb9ac0c913c9c4218eb868081aab64e…
You're receiving this email because of your account on gitlab.haskell.org.
1
0
[Git][ghc/ghc][wip/T26425] 22 commits: Handle implications between x86 feature flags
by Simon Peyton Jones (@simonpj) 30 Oct '25
by Simon Peyton Jones (@simonpj) 30 Oct '25
30 Oct '25
Simon Peyton Jones pushed to branch wip/T26425 at Glasgow Haskell Compiler / GHC
Commits:
d4a9d6d6 by ARATA Mizuki at 2025-10-19T18:43:47+09:00
Handle implications between x86 feature flags
This includes:
* Multiple -msse* options can be specified
* -mavx implies -msse4.2
* -mavx2 implies -mavx
* -mfma implies -mavx
* -mavx512f implies -mavx2 and -mfma
* -mavx512{cd,er,pf} imply -mavx512f
Closes #24989
Co-authored-by: sheaf <sam.derbyshire(a)gmail.com>
- - - - -
c9b8465c by Cheng Shao at 2025-10-20T10:16:00-04:00
wasm: workaround WebKit bug in dyld
This patch works around a WebKit bug and allows dyld to run on WebKit
based platforms as well. See added note for detailed explanation.
Co-authored-by: Codex <codex(a)openai.com>
- - - - -
91b6be10 by Julian Ospald at 2025-10-20T18:21:03-04:00
Improve error handling in 'getPackageArchives'
When the library dirs in the package conf files are not set up correctly,
the JS linker will happily ignore such packages and not link against them,
although they're part of the link plan.
Fixes #26383
- - - - -
6c5269da by Sven Tennie at 2025-10-20T18:21:44-04:00
Align coding style
Improve readability by using the same style for all constructor calls in
this function.
- - - - -
3d305889 by Sven Tennie at 2025-10-20T18:21:44-04:00
Reduce complexity by removing joins with mempty
ldArgs, cArgs and cppArgs are all `mempty`. Thus concatenating them adds
nothing but some complexity while reading the code.
- - - - -
38d65187 by Matthew Pickering at 2025-10-21T13:12:20+01:00
Fix stack decoding when using profiled runtime
There are three fixes in this commit.
* We need to replicate the `InfoTable` and `InfoTableProf`
approach for the other stack constants (see the new Stack.ConstantsProf
file).
* Then we need to appropiately import the profiled or non-profiled
versions.
* Finally, there was an incorrect addition in `stackFrameSize`. We need
to cast after performing addition on words.
Fixes #26507
- - - - -
17231bfb by fendor at 2025-10-21T13:12:20+01:00
Add regression test for #26507
- - - - -
4f5bf93b by Simon Peyton Jones at 2025-10-25T04:05:34-04:00
Postscript to fix for #26255
This MR has comments only
- - - - -
6ef22fa0 by IC Rainbow at 2025-10-26T18:23:01-04:00
Add SIMD primops for bitwise logical operations
This adds 128-bit wide and/or/xor instructions for X86 NCG,
with both SSE and AVX encodings.
```
andFloatX4# :: FloatX4# -> FloatX4# -> FloatX4# -- andps / vandps
andDoubleX2# :: DoubleX2# -> DoubleX2# -> DoubleX2# -- andpd / vandpd
andInt8X16# :: Int8X16# -> Int8X16# -> Int8X16# -- pand / vpand
```
The new primops are available on ARM when using LLVM backend.
Tests added:
- simd015 (floats and doubles)
- simd016 (integers)
- simd017 (words)
Fixes #26417
- - - - -
fbdc623a by sheaf at 2025-10-26T18:23:52-04:00
Add hints for unsolved HasField constraints
This commit adds hints and explanations for unsolved 'HasField'
constraints.
GHC will now provide additional explanations for an unsolved constraint
of the form 'HasField fld_name rec_ty fld_ty'; the details are laid out in
Note [Error messages for unsolved HasField constraints], but briefly:
1. Provide similar name suggestions (e.g. mis-spelled field name)
and import suggestions (record field not in scope).
These result in actionable 'GhcHints', which is helpful to provide
code actions in HLS.
2. Explain why GHC did not solve the constraint, e.g.:
- 'fld_name' is not a string literal (e.g. a type variable)
- 'rec_ty' is a TyCon without any fields, e.g. 'Int' or 'Bool'.
- 'fld_ty' contains existentials variables or foralls.
- The record field is a pattern synonym field (GHC does not generate
HasField instances for those).
- 'HasField' is a custom 'TyCon', not actually the built-in
'HasField' typeclass from 'GHC.Records'.
On the way, we slightly refactor the mechanisms for import suggestions
in GHC.Rename.Unbound. This is to account for the fact that, for
'HasField', we don't care whether the field is imported qualified or
unqualified. 'importSuggestions' was refactored, we now have
'sameQualImportSuggestions' and 'anyQualImportSuggestions'.
Fixes #18776 #22382 #26480
- - - - -
99d5707f by sheaf at 2025-10-26T18:23:52-04:00
Rename PatSyn MatchContext to PatSynCtx to avoid punning
- - - - -
5dc2e9ea by Julian Ospald at 2025-10-27T18:17:23-04:00
Skip uniques test if sources are not available
- - - - -
544b9ec9 by Vladislav Zavialov at 2025-10-27T18:18:06-04:00
Re-export GHC.Hs.Basic from GHC.Hs
Clean up some import sections in GHC by re-exporting GHC.Hs.Basic
from GHC.Hs.
- - - - -
643ce801 by Julian Ospald at 2025-10-28T18:18:55-04:00
rts: remove unneccesary cabal flags
We perform those checks via proper autoconf macros
instead that do the right thing and then add those
libs to the rts buildinfo.
- - - - -
d69ea8fe by Vladislav Zavialov at 2025-10-28T18:19:37-04:00
Test case for #17705
Starting with GHC 9.12 (the first release to include 5745dbd3),
all examples in this ticket are handled as expected.
- - - - -
4038a28b by Andreas Klebinger at 2025-10-30T12:38:52-04:00
Add a perf test for #26425
- - - - -
f997618e by Andreas Klebinger at 2025-10-30T12:38:52-04:00
OccAnal: Be stricter for better compiler perf.
In particular we are now stricter:
* When combining usageDetails.
* When computing binder info.
In combineUsageDetails when combining the underlying adds we compute a
new `LocalOcc` for each entry by combining the two existing ones.
Rather than wait for those entries to be forced down the road we now
force them immediately. Speeding up T26425 by about 10% with little
effect on the common case.
We also force binders we put into the Core AST everywhere now.
Failure to do so risks leaking the occ env used to set the binders
OccInfo.
For T26425 compiler residency went down by a factor of ~10x.
Compile time also improved by a factor of ~1.6.
-------------------------
Metric Decrease:
T18698a
T26425
T9233
-------------------------
- - - - -
5618645b by Vladislav Zavialov at 2025-10-30T12:39:33-04:00
Fix namespace specifiers in subordinate exports (#12488)
This patch fixes an oversight in the `lookupChildrenExport` function that
caused explicit namespace specifiers of subordinate export items to be
ignored:
module M (T (type A)) where -- should be rejected
data T = A
Based on the `IEWrappedName` data type, there are 5 cases to consider:
1. Unadorned name: P(X)
2. Named default: P(default X)
3. Pattern synonym: P(pattern X)
4. Type name: P(type X)
5. Data name: P(data X)
Case 1 is already handled correctly; cases 2 and 3 are parse errors; and
it is cases 4 and 5 that we are concerned with in this patch.
Following the precedent established in `LookupExactName`, we introduce
a boolean flag in `LookupChildren` to control whether to look up in all
namespaces or in a specific one. If an export item is accompanied by an
explicit namespace specifier `type` or `data`, we restrict the lookup in
`lookupGRE` to a specific namespace.
The newly introduced diagnostic `TcRnExportedSubordinateNotFound`
provides error messages and suggestions more tailored to this context
than the previously used `reportUnboundName`.
- - - - -
68b987fa by Simon Peyton Jones at 2025-10-30T16:55:03+00:00
Experimental occ-anal patch
... needs documenation...
- - - - -
0f087284 by Simon Peyton Jones at 2025-10-30T16:55:03+00:00
Wibble
- - - - -
a0566bf0 by Simon Peyton Jones at 2025-10-30T16:55:03+00:00
Fix buglet that led to non-termination!
- - - - -
193bf312 by Simon Peyton Jones at 2025-10-30T17:09:24+00:00
Fixes
- - - - -
143 changed files:
- compiler/GHC/Builtin/primops.txt.pp
- compiler/GHC/Cmm/MachOp.hs
- compiler/GHC/CmmToAsm/AArch64/CodeGen.hs
- compiler/GHC/CmmToAsm/Config.hs
- compiler/GHC/CmmToAsm/X86/CodeGen.hs
- compiler/GHC/CmmToAsm/X86/Instr.hs
- compiler/GHC/CmmToAsm/X86/Ppr.hs
- compiler/GHC/CmmToC.hs
- compiler/GHC/CmmToLlvm/CodeGen.hs
- compiler/GHC/Core/ConLike.hs
- compiler/GHC/Core/Opt/OccurAnal.hs
- compiler/GHC/Core/Opt/Simplify/Iteration.hs
- compiler/GHC/Driver/Config/CmmToAsm.hs
- compiler/GHC/Driver/DynFlags.hs
- compiler/GHC/Driver/Session.hs
- compiler/GHC/Hs.hs
- compiler/GHC/Hs/Decls.hs
- compiler/GHC/Hs/Expr.hs
- compiler/GHC/HsToCore/Foreign/Wasm.hs
- compiler/GHC/HsToCore/Pmc/Utils.hs
- compiler/GHC/HsToCore/Quote.hs
- compiler/GHC/HsToCore/Utils.hs
- compiler/GHC/Parser/Errors/Types.hs
- compiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Platform.hs
- compiler/GHC/Rename/Bind.hs
- compiler/GHC/Rename/Env.hs
- compiler/GHC/Rename/Expr.hs
- compiler/GHC/Rename/HsType.hs
- compiler/GHC/Rename/Names.hs
- compiler/GHC/Rename/Pat.hs
- compiler/GHC/Rename/Unbound.hs
- compiler/GHC/Rename/Utils.hs
- compiler/GHC/StgToCmm/Prim.hs
- compiler/GHC/StgToJS/Linker/Linker.hs
- compiler/GHC/StgToJS/Prim.hs
- compiler/GHC/Tc/Deriv/Generate.hs
- compiler/GHC/Tc/Deriv/Generics.hs
- compiler/GHC/Tc/Errors.hs
- compiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/App.hs
- compiler/GHC/Tc/Gen/Export.hs
- compiler/GHC/Tc/Gen/Expr.hs
- compiler/GHC/Tc/Gen/Pat.hs
- compiler/GHC/Tc/Instance/Class.hs
- compiler/GHC/Tc/TyCl.hs
- compiler/GHC/Tc/TyCl/Instance.hs
- compiler/GHC/Tc/TyCl/PatSyn.hs
- compiler/GHC/Tc/TyCl/Utils.hs
- compiler/GHC/Tc/Types/Origin.hs
- compiler/GHC/Tc/Validity.hs
- compiler/GHC/ThToHs.hs
- compiler/GHC/Types/Error/Codes.hs
- compiler/GHC/Types/Hint.hs
- compiler/GHC/Types/Hint/Ppr.hs
- compiler/GHC/Types/Name/Reader.hs
- compiler/GHC/Types/Unique/FM.hs
- compiler/GHC/Types/Unique/Set.hs
- compiler/GHC/Types/Var/Env.hs
- compiler/Language/Haskell/Syntax/Expr.hs
- docs/users_guide/9.16.1-notes.rst
- docs/users_guide/using.rst
- hadrian/src/Rules/Gmp.hs
- hadrian/src/Rules/Libffi.hs
- hadrian/src/Settings/Builders/Cabal.hs
- hadrian/src/Settings/Builders/Common.hs
- hadrian/src/Settings/Builders/DeriveConstants.hs
- hadrian/src/Settings/Builders/Hsc2Hs.hs
- libraries/base/src/GHC/Base.hs
- libraries/base/src/GHC/Exts.hs
- libraries/ghc-experimental/CHANGELOG.md
- libraries/ghc-internal/cbits/Stack_c.c
- libraries/ghc-internal/ghc-internal.cabal.in
- + libraries/ghc-internal/src/GHC/Internal/Stack/ConstantsProf.hsc
- libraries/ghc-internal/src/GHC/Internal/Stack/Decode.hs
- + libraries/ghc-internal/tests/backtraces/T26507.hs
- + libraries/ghc-internal/tests/backtraces/T26507.stderr
- libraries/ghc-internal/tests/backtraces/all.T
- libraries/ghc-internal/tests/stack-annotation/all.T
- libraries/ghc-prim/changelog.md
- m4/fp_check_pthreads.m4
- rts/configure.ac
- + rts/rts.buildinfo.in
- rts/rts.cabal
- testsuite/tests/codeGen/should_gen_asm/all.T
- + testsuite/tests/codeGen/should_gen_asm/mavx-should-enable-popcnt.asm
- + testsuite/tests/codeGen/should_gen_asm/mavx-should-enable-popcnt.hs
- + testsuite/tests/codeGen/should_gen_asm/msse-option-order.asm
- + testsuite/tests/codeGen/should_gen_asm/msse-option-order.hs
- testsuite/tests/interface-stability/ghc-experimental-exports.stdout
- testsuite/tests/interface-stability/ghc-experimental-exports.stdout-mingw32
- testsuite/tests/interface-stability/ghc-prim-exports.stdout
- testsuite/tests/interface-stability/ghc-prim-exports.stdout-mingw32
- testsuite/tests/linters/all.T
- testsuite/tests/module/mod4.stderr
- + testsuite/tests/overloadedrecflds/should_fail/T26480.hs
- + testsuite/tests/overloadedrecflds/should_fail/T26480.stderr
- + testsuite/tests/overloadedrecflds/should_fail/T26480_aux1.hs
- + testsuite/tests/overloadedrecflds/should_fail/T26480_aux2.hs
- + testsuite/tests/overloadedrecflds/should_fail/T26480b.hs
- + testsuite/tests/overloadedrecflds/should_fail/T26480b.stderr
- testsuite/tests/overloadedrecflds/should_fail/all.T
- testsuite/tests/overloadedrecflds/should_fail/hasfieldfail01.stderr
- testsuite/tests/overloadedrecflds/should_fail/hasfieldfail02.stderr
- testsuite/tests/parser/should_fail/RecordDotSyntaxFail11.stderr
- testsuite/tests/parser/should_fail/RecordDotSyntaxFail8.hs
- testsuite/tests/parser/should_fail/RecordDotSyntaxFail8.stderr
- + testsuite/tests/parser/should_fail/T12488c.hs
- + testsuite/tests/parser/should_fail/T12488c.stderr
- + testsuite/tests/parser/should_fail/T12488d.hs
- + testsuite/tests/parser/should_fail/T12488d.stderr
- testsuite/tests/parser/should_fail/all.T
- + testsuite/tests/perf/compiler/T26425.hs
- testsuite/tests/perf/compiler/all.T
- + testsuite/tests/rename/should_compile/T12488b.hs
- + testsuite/tests/rename/should_compile/T12488f.hs
- testsuite/tests/rename/should_compile/all.T
- + testsuite/tests/rename/should_fail/T12488a.hs
- + testsuite/tests/rename/should_fail/T12488a.stderr
- + testsuite/tests/rename/should_fail/T12488a_foo.hs
- + testsuite/tests/rename/should_fail/T12488a_foo.stderr
- + testsuite/tests/rename/should_fail/T12488e.hs
- + testsuite/tests/rename/should_fail/T12488e.stderr
- + testsuite/tests/rename/should_fail/T12488g.hs
- + testsuite/tests/rename/should_fail/T12488g.stderr
- testsuite/tests/rename/should_fail/T19843h.stderr
- testsuite/tests/rename/should_fail/T25899e2.stderr
- testsuite/tests/rename/should_fail/all.T
- testsuite/tests/simd/should_run/all.T
- + testsuite/tests/simd/should_run/simd015.hs
- + testsuite/tests/simd/should_run/simd015.stdout
- + testsuite/tests/simd/should_run/simd016.hs
- + testsuite/tests/simd/should_run/simd016.stdout
- + testsuite/tests/simd/should_run/simd017.hs
- + testsuite/tests/simd/should_run/simd017.stdout
- + testsuite/tests/typecheck/should_compile/T17705.hs
- testsuite/tests/typecheck/should_compile/all.T
- utils/check-exact/ExactPrint.hs
- utils/haddock/haddock-api/src/Haddock/Convert.hs
- utils/haddock/haddock-api/src/Haddock/Interface/Rename.hs
- utils/haddock/haddock-api/src/Haddock/Types.hs
- utils/jsffi/dyld.mjs
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0675a96cd150475fb8f0a6ac303cfe…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/0675a96cd150475fb8f0a6ac303cfe…
You're receiving this email because of your account on gitlab.haskell.org.
1
0
[Git][ghc/ghc][wip/T23162-spj] 14 commits: Add a perf test for #26425
by Simon Peyton Jones (@simonpj) 30 Oct '25
by Simon Peyton Jones (@simonpj) 30 Oct '25
30 Oct '25
Simon Peyton Jones pushed to branch wip/T23162-spj at Glasgow Haskell Compiler / GHC
Commits:
4038a28b by Andreas Klebinger at 2025-10-30T12:38:52-04:00
Add a perf test for #26425
- - - - -
f997618e by Andreas Klebinger at 2025-10-30T12:38:52-04:00
OccAnal: Be stricter for better compiler perf.
In particular we are now stricter:
* When combining usageDetails.
* When computing binder info.
In combineUsageDetails when combining the underlying adds we compute a
new `LocalOcc` for each entry by combining the two existing ones.
Rather than wait for those entries to be forced down the road we now
force them immediately. Speeding up T26425 by about 10% with little
effect on the common case.
We also force binders we put into the Core AST everywhere now.
Failure to do so risks leaking the occ env used to set the binders
OccInfo.
For T26425 compiler residency went down by a factor of ~10x.
Compile time also improved by a factor of ~1.6.
-------------------------
Metric Decrease:
T18698a
T26425
T9233
-------------------------
- - - - -
5618645b by Vladislav Zavialov at 2025-10-30T12:39:33-04:00
Fix namespace specifiers in subordinate exports (#12488)
This patch fixes an oversight in the `lookupChildrenExport` function that
caused explicit namespace specifiers of subordinate export items to be
ignored:
module M (T (type A)) where -- should be rejected
data T = A
Based on the `IEWrappedName` data type, there are 5 cases to consider:
1. Unadorned name: P(X)
2. Named default: P(default X)
3. Pattern synonym: P(pattern X)
4. Type name: P(type X)
5. Data name: P(data X)
Case 1 is already handled correctly; cases 2 and 3 are parse errors; and
it is cases 4 and 5 that we are concerned with in this patch.
Following the precedent established in `LookupExactName`, we introduce
a boolean flag in `LookupChildren` to control whether to look up in all
namespaces or in a specific one. If an export item is accompanied by an
explicit namespace specifier `type` or `data`, we restrict the lookup in
`lookupGRE` to a specific namespace.
The newly introduced diagnostic `TcRnExportedSubordinateNotFound`
provides error messages and suggestions more tailored to this context
than the previously used `reportUnboundName`.
- - - - -
2cc9924e by Richard Eisenberg at 2025-10-30T17:08:32+00:00
Refactor fundep solving
This commit is a large-scale refactor of the increasingly-messy code that
handles functional dependencies. It has virtually no effect on what compiles
but improves error messages a bit. And it does the groundwork for #23162.
The big picture is described in
Note [Overview of functional dependencies in type inference]
in GHC.Tc.Solver.FunDeps
* New module GHC.Tc.Solver.FunDeps contains all the fundep-handling
code for the constraint solver.
* Fundep-equalities are solved in a nested scope; they may generate
unifications but otherwise have no other effect.
See GHC.Tc.Solver.FunDeps.solveFunDeps
The nested needs to start from the Givens in the inert set, but
not the Wanteds; hence a new function `resetInertCans`, used in
`nestFunDepsTcS`.
* That in turn means that fundep equalities never show up in error
messages, so the complicated FunDepOrigin tracking can all disappear.
* We need to be careful about tracking unifications, so we kick out
constraints from the inert set after doing unifications. Unification
tracking has been majorly reformed: see Note [WhatUnifications] in
GHC.Tc.Utils.Unify.
A good consequence is that the hard-to-grok `resetUnificationFlag`
has been replaced with a simpler use of
`reportCoarseGrainUnifications`
Smaller things:
* Rename `FunDepEqn` to `FunDepEqns` since it contains multiple
type equalities.
Some compile time improvement
Metrics: compile_time/bytes allocated
Baseline
Test value New value Change
---------------------- --------------------------------------
T5030(normal) 173,839,232 148,115,248 -14.8% GOOD
hard_hole_fits(normal) 286,768,048 284,015,416 -1.0%
geo. mean -0.2%
minimum -14.8%
maximum +0.3%
Metric Decrease:
T5030
- - - - -
072466a4 by Simon Peyton Jones at 2025-10-30T17:08:32+00:00
QuickLook's tcInstFun should make instantiation variables directly
tcInstFun must make "instantiation variables", not regular
unification variables, when instantiating function types. That was
previously implemented by a hack: set the /ambient/ level to QLInstTyVar.
But the hack finally bit me, when I was refactoring WhatUnifications.
And it was always wrong: see the now-expunged (TCAPP2) note.
This commit does it right, by making tcInstFun call its own
instantiation functions. That entails a small bit of duplication,
but the result is much, much cleaner.
- - - - -
0c9e957c by Simon Peyton Jones at 2025-10-30T17:08:32+00:00
Build implication for constraints from (static e)
This commit addresses #26466, by buiding an implication for the
constraints arising from a (static e) form. The implication has
a special ic_info field of StaticFormSkol, which tells the constraint
solver to use an empty set of Givens.
See (SF3) in Note [Grand plan for static forms]
in GHC.Iface.Tidy.StaticPtrTable
This commit also reinstates an `assert` in GHC.Tc.Solver.Equality.
The test `StaticPtrTypeFamily` was failing with an assertion failure,
but it now works.
- - - - -
fbb2a831 by Simon Peyton Jones at 2025-10-30T17:08:32+00:00
Comments about defaulting representation equalities
- - - - -
b59a8713 by Simon Peyton Jones at 2025-10-30T17:08:32+00:00
Improve tracking of rewriter-sets
This refactor substantially improves the treatment of so-called
"rewriter-sets" in the constraint solver.
The story is described in the rewritten
Note [Wanteds rewrite Wanteds: rewriter-sets]
in GHC.Tc.Types.Constraint
Some highlights
* Trace the free coercion holes of a filled CoercionHole,
in CoercionPlusHoles. See Note [Coercion holes] (COH5)
This avoids taking having to take the free coercion variables
of a coercion when zonking a rewrriter-set
* Many knock on changes
* Make fillCoercionHole take CoercionPlusHoles as its argument
rather than to separate arguments.
* Similarly setEqIfWanted, setWantedE, wrapUnifierAndEmit.
* Be more careful about passing the correct CoHoleSet to
`rewriteEqEvidence` and friends
* Make kickOurAfterFillingCoercionHole more clever. See
new Note [Kick out after filling a coercion hole]
Smaller matters
* Rename RewriterSet to CoHoleSet
* Add special-case helper `rewriteEqEvidenceSwapOnly`
- - - - -
02de4352 by Simon Peyton Jones at 2025-10-30T17:08:32+00:00
Tidy up constraint solving for foralls
* In `can_eq_nc_forall` make sure to track Givens that are used
in the nested solve step.
* Tiny missing-swap bug-fix in `lookup_eq_in_qcis`
* Fix some leftover mess from
commit 14123ee646f2b9738a917b7cec30f9d3941c13de
Author: Simon Peyton Jones <simon.peytonjones(a)gmail.com>
Date: Wed Aug 20 00:35:48 2025 +0100
Solve forall-constraints via an implication, again
Specifically, trySolveImplication is now dead.
- - - - -
27b3b406 by Simon Peyton Jones at 2025-10-30T17:08:32+00:00
Do not treat CoercionHoles as free variables in coercions
This fixes a long-standing wart in the free-variable finder;
now CoercionHoles are no longer treated as a "free variable"
of a coercion.
I got big and unexpected performance regressions when making
this change. Turned out that CallArity didn't discover that
the free variable finder could be eta-expanded, which gave very
poor code.
So I re-used Note [The one-shot state monad trick] for Endo,
resulting in GHC.Utils.EndoOS. Very simple, big win.
- - - - -
49a558ed by Simon Peyton Jones at 2025-10-30T17:08:32+00:00
Update debug-tracing in CallArity
No effect on behaviour, and commented out anyway
- - - - -
c35ab399 by Simon Peyton Jones at 2025-10-30T17:08:33+00:00
Comments only -- remove dangling Note references
- - - - -
eaf505bd by Simon Peyton Jones at 2025-10-30T17:08:33+00:00
Accept error message wibbles
- - - - -
09161c1f by Simon Peyton Jones at 2025-10-30T17:08:33+00:00
Comments only
- - - - -
125 changed files:
- compiler/GHC/Core/Opt/CallArity.hs
- compiler/GHC/Core/Opt/OccurAnal.hs
- compiler/GHC/Core/Opt/Simplify/Iteration.hs
- compiler/GHC/Core/Opt/Simplify/Utils.hs
- compiler/GHC/Core/TyCo/FVs.hs
- compiler/GHC/Core/TyCo/Rep.hs
- compiler/GHC/Core/TyCon.hs
- compiler/GHC/Iface/Tidy/StaticPtrTable.hs
- compiler/GHC/Rename/Env.hs
- compiler/GHC/Rename/Names.hs
- compiler/GHC/Runtime/Eval.hs
- compiler/GHC/Tc/Errors.hs
- compiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/App.hs
- compiler/GHC/Tc/Gen/Export.hs
- compiler/GHC/Tc/Gen/Expr.hs
- compiler/GHC/Tc/Gen/Sig.hs
- compiler/GHC/Tc/Instance/FunDeps.hs
- compiler/GHC/Tc/Solver.hs
- compiler/GHC/Tc/Solver/Default.hs
- compiler/GHC/Tc/Solver/Dict.hs
- compiler/GHC/Tc/Solver/Equality.hs
- + compiler/GHC/Tc/Solver/FunDeps.hs
- compiler/GHC/Tc/Solver/InertSet.hs
- compiler/GHC/Tc/Solver/Irred.hs
- compiler/GHC/Tc/Solver/Monad.hs
- compiler/GHC/Tc/Solver/Rewrite.hs
- compiler/GHC/Tc/Solver/Solve.hs
- compiler/GHC/Tc/Solver/Solve.hs-boot
- compiler/GHC/Tc/Types.hs
- compiler/GHC/Tc/Types/Constraint.hs
- compiler/GHC/Tc/Types/Evidence.hs
- compiler/GHC/Tc/Types/Origin.hs
- compiler/GHC/Tc/Utils/Concrete.hs
- compiler/GHC/Tc/Utils/Instantiate.hs
- compiler/GHC/Tc/Utils/Monad.hs
- compiler/GHC/Tc/Utils/TcMType.hs
- compiler/GHC/Tc/Utils/TcType.hs
- compiler/GHC/Tc/Utils/Unify.hs
- compiler/GHC/Tc/Zonk/TcType.hs
- compiler/GHC/Tc/Zonk/Type.hs
- compiler/GHC/Types/Basic.hs
- compiler/GHC/Types/Error/Codes.hs
- compiler/GHC/Types/Hint.hs
- compiler/GHC/Types/Hint/Ppr.hs
- compiler/GHC/Types/Name/Reader.hs
- compiler/GHC/Types/Unique/DSM.hs
- compiler/GHC/Types/Unique/FM.hs
- compiler/GHC/Types/Var/Env.hs
- + compiler/GHC/Utils/EndoOS.hs
- compiler/ghc.cabal.in
- testsuite/tests/count-deps/CountDepsAst.stdout
- testsuite/tests/count-deps/CountDepsParser.stdout
- testsuite/tests/default/default-fail05.stderr
- testsuite/tests/dependent/should_fail/T13135_simple.stderr
- testsuite/tests/deriving/should_fail/T3621.stderr
- testsuite/tests/indexed-types/should_fail/T14369.stderr
- testsuite/tests/indexed-types/should_fail/T1897b.stderr
- testsuite/tests/linters/notes.stdout
- testsuite/tests/module/mod4.stderr
- testsuite/tests/parser/should_fail/RecordDotSyntaxFail10.stderr
- testsuite/tests/parser/should_fail/RecordDotSyntaxFail13.stderr
- + testsuite/tests/parser/should_fail/T12488c.hs
- + testsuite/tests/parser/should_fail/T12488c.stderr
- + testsuite/tests/parser/should_fail/T12488d.hs
- + testsuite/tests/parser/should_fail/T12488d.stderr
- testsuite/tests/parser/should_fail/T20654a.stderr
- testsuite/tests/parser/should_fail/all.T
- testsuite/tests/partial-sigs/should_fail/T14584a.stderr
- + testsuite/tests/perf/compiler/T26425.hs
- testsuite/tests/perf/compiler/all.T
- testsuite/tests/polykinds/T6068.stdout
- testsuite/tests/quantified-constraints/T15359.hs
- + testsuite/tests/rename/should_compile/T12488b.hs
- + testsuite/tests/rename/should_compile/T12488f.hs
- testsuite/tests/rename/should_compile/all.T
- + testsuite/tests/rename/should_fail/T12488a.hs
- + testsuite/tests/rename/should_fail/T12488a.stderr
- + testsuite/tests/rename/should_fail/T12488a_foo.hs
- + testsuite/tests/rename/should_fail/T12488a_foo.stderr
- + testsuite/tests/rename/should_fail/T12488e.hs
- + testsuite/tests/rename/should_fail/T12488e.stderr
- + testsuite/tests/rename/should_fail/T12488g.hs
- + testsuite/tests/rename/should_fail/T12488g.stderr
- testsuite/tests/rename/should_fail/T25899e2.stderr
- testsuite/tests/rename/should_fail/all.T
- testsuite/tests/rep-poly/RepPolyNPlusK.stderr
- testsuite/tests/rep-poly/RepPolyRightSection.stderr
- testsuite/tests/rep-poly/T13233.stderr
- testsuite/tests/rep-poly/T19709b.stderr
- testsuite/tests/rep-poly/T23903.stderr
- testsuite/tests/typecheck/no_skolem_info/T13499.stderr
- testsuite/tests/typecheck/should_compile/T13651.hs
- − testsuite/tests/typecheck/should_compile/T13651.stderr
- + testsuite/tests/typecheck/should_compile/T14745.hs
- testsuite/tests/typecheck/should_compile/all.T
- testsuite/tests/typecheck/should_compile/hole_constraints_nested.stderr
- testsuite/tests/typecheck/should_compile/tc126.hs
- testsuite/tests/typecheck/should_fail/AmbigFDs.hs
- − testsuite/tests/typecheck/should_fail/AmbigFDs.stderr
- testsuite/tests/typecheck/should_fail/FD3.stderr
- testsuite/tests/typecheck/should_fail/FDsFromGivens2.stderr
- testsuite/tests/typecheck/should_fail/T13506.stderr
- testsuite/tests/typecheck/should_fail/T16512a.stderr
- testsuite/tests/typecheck/should_fail/T18851b.hs
- − testsuite/tests/typecheck/should_fail/T18851b.stderr
- testsuite/tests/typecheck/should_fail/T18851c.hs
- − testsuite/tests/typecheck/should_fail/T18851c.stderr
- testsuite/tests/typecheck/should_fail/T19415.stderr
- testsuite/tests/typecheck/should_fail/T19415b.stderr
- testsuite/tests/typecheck/should_fail/T22684.stderr
- + testsuite/tests/typecheck/should_fail/T23162a.hs
- + testsuite/tests/typecheck/should_fail/T23162a.stderr
- testsuite/tests/typecheck/should_fail/T25325.stderr
- testsuite/tests/typecheck/should_fail/T5246.stderr
- testsuite/tests/typecheck/should_fail/T5978.stderr
- testsuite/tests/typecheck/should_fail/T7368a.stderr
- testsuite/tests/typecheck/should_fail/T7696.stderr
- testsuite/tests/typecheck/should_fail/T8603.stderr
- testsuite/tests/typecheck/should_fail/T9612.stderr
- testsuite/tests/typecheck/should_fail/TcStaticPointersFail03.stderr
- testsuite/tests/typecheck/should_fail/all.T
- testsuite/tests/typecheck/should_fail/tcfail122.stderr
- testsuite/tests/typecheck/should_fail/tcfail143.stderr
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/040919fec6783a2b2e0b9c4b54fbc0…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/040919fec6783a2b2e0b9c4b54fbc0…
You're receiving this email because of your account on gitlab.haskell.org.
1
0
[Git][ghc/ghc][wip/T26349] 10 commits: Skip uniques test if sources are not available
by Simon Peyton Jones (@simonpj) 30 Oct '25
by Simon Peyton Jones (@simonpj) 30 Oct '25
30 Oct '25
Simon Peyton Jones pushed to branch wip/T26349 at Glasgow Haskell Compiler / GHC
Commits:
5dc2e9ea by Julian Ospald at 2025-10-27T18:17:23-04:00
Skip uniques test if sources are not available
- - - - -
544b9ec9 by Vladislav Zavialov at 2025-10-27T18:18:06-04:00
Re-export GHC.Hs.Basic from GHC.Hs
Clean up some import sections in GHC by re-exporting GHC.Hs.Basic
from GHC.Hs.
- - - - -
643ce801 by Julian Ospald at 2025-10-28T18:18:55-04:00
rts: remove unneccesary cabal flags
We perform those checks via proper autoconf macros
instead that do the right thing and then add those
libs to the rts buildinfo.
- - - - -
d69ea8fe by Vladislav Zavialov at 2025-10-28T18:19:37-04:00
Test case for #17705
Starting with GHC 9.12 (the first release to include 5745dbd3),
all examples in this ticket are handled as expected.
- - - - -
4038a28b by Andreas Klebinger at 2025-10-30T12:38:52-04:00
Add a perf test for #26425
- - - - -
f997618e by Andreas Klebinger at 2025-10-30T12:38:52-04:00
OccAnal: Be stricter for better compiler perf.
In particular we are now stricter:
* When combining usageDetails.
* When computing binder info.
In combineUsageDetails when combining the underlying adds we compute a
new `LocalOcc` for each entry by combining the two existing ones.
Rather than wait for those entries to be forced down the road we now
force them immediately. Speeding up T26425 by about 10% with little
effect on the common case.
We also force binders we put into the Core AST everywhere now.
Failure to do so risks leaking the occ env used to set the binders
OccInfo.
For T26425 compiler residency went down by a factor of ~10x.
Compile time also improved by a factor of ~1.6.
-------------------------
Metric Decrease:
T18698a
T26425
T9233
-------------------------
- - - - -
5618645b by Vladislav Zavialov at 2025-10-30T12:39:33-04:00
Fix namespace specifiers in subordinate exports (#12488)
This patch fixes an oversight in the `lookupChildrenExport` function that
caused explicit namespace specifiers of subordinate export items to be
ignored:
module M (T (type A)) where -- should be rejected
data T = A
Based on the `IEWrappedName` data type, there are 5 cases to consider:
1. Unadorned name: P(X)
2. Named default: P(default X)
3. Pattern synonym: P(pattern X)
4. Type name: P(type X)
5. Data name: P(data X)
Case 1 is already handled correctly; cases 2 and 3 are parse errors; and
it is cases 4 and 5 that we are concerned with in this patch.
Following the precedent established in `LookupExactName`, we introduce
a boolean flag in `LookupChildren` to control whether to look up in all
namespaces or in a specific one. If an export item is accompanied by an
explicit namespace specifier `type` or `data`, we restrict the lookup in
`lookupGRE` to a specific namespace.
The newly introduced diagnostic `TcRnExportedSubordinateNotFound`
provides error messages and suggestions more tailored to this context
than the previously used `reportUnboundName`.
- - - - -
ce0773a7 by Simon Peyton Jones at 2025-10-30T17:02:14+00:00
Add a HsWrapper optimiser
This is an experimental MR. The big change is adding
`GHC.Tc.Types.Evidence.optHsWrapper
Addresses #26349
A bit more
Working, I think
Remove silly trace
Better now
Added WpSubType
Remove trace
better
More
Comments and one test wibble
- - - - -
9f6aee01 by Simon Peyton Jones at 2025-10-30T17:02:14+00:00
Improve mkWpFun_FRR
This commit ensures that `mkWpFun_FRR` directly produces a `FunCo` in
the cases where it can.
(Previously called `mkWpFun` which in turn optimised to a `FunCo`, but
that made the smarts in `mkWpFun` /essential/ rather than (as they
should be) optional.
- - - - -
f4f71579 by Simon Peyton Jones at 2025-10-30T17:02:14+00:00
Comments only
- - - - -
82 changed files:
- compiler/GHC/Core/Coercion.hs
- compiler/GHC/Core/Opt/OccurAnal.hs
- compiler/GHC/Hs.hs
- compiler/GHC/Hs/Decls.hs
- compiler/GHC/Hs/Syn/Type.hs
- compiler/GHC/HsToCore/Binds.hs
- compiler/GHC/HsToCore/Foreign/Wasm.hs
- compiler/GHC/HsToCore/Match.hs
- compiler/GHC/HsToCore/Quote.hs
- compiler/GHC/HsToCore/Utils.hs
- compiler/GHC/Iface/Ext/Ast.hs
- compiler/GHC/Parser/Errors/Types.hs
- compiler/GHC/Parser/PostProcess.hs
- compiler/GHC/Rename/Bind.hs
- compiler/GHC/Rename/Env.hs
- compiler/GHC/Rename/Expr.hs
- compiler/GHC/Rename/HsType.hs
- compiler/GHC/Rename/Names.hs
- compiler/GHC/Rename/Pat.hs
- compiler/GHC/Rename/Utils.hs
- compiler/GHC/Tc/Deriv/Generate.hs
- compiler/GHC/Tc/Deriv/Generics.hs
- compiler/GHC/Tc/Errors/Hole.hs
- compiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/App.hs
- compiler/GHC/Tc/Gen/Export.hs
- compiler/GHC/Tc/Gen/Expr.hs
- compiler/GHC/Tc/Gen/Head.hs
- compiler/GHC/Tc/Gen/Pat.hs
- compiler/GHC/Tc/TyCl.hs
- compiler/GHC/Tc/TyCl/Instance.hs
- compiler/GHC/Tc/TyCl/Utils.hs
- compiler/GHC/Tc/Types/Evidence.hs
- compiler/GHC/Tc/Types/Origin.hs
- compiler/GHC/Tc/Utils/Concrete.hs
- compiler/GHC/Tc/Utils/Unify.hs
- compiler/GHC/Tc/Validity.hs
- compiler/GHC/Tc/Zonk/Type.hs
- compiler/GHC/ThToHs.hs
- compiler/GHC/Types/Error/Codes.hs
- compiler/GHC/Types/Hint.hs
- compiler/GHC/Types/Hint/Ppr.hs
- compiler/GHC/Types/Name/Reader.hs
- compiler/GHC/Types/Unique/FM.hs
- compiler/GHC/Types/Var/Env.hs
- m4/fp_check_pthreads.m4
- rts/configure.ac
- + rts/rts.buildinfo.in
- rts/rts.cabal
- testsuite/tests/linters/all.T
- testsuite/tests/module/mod4.stderr
- + testsuite/tests/parser/should_fail/T12488c.hs
- + testsuite/tests/parser/should_fail/T12488c.stderr
- + testsuite/tests/parser/should_fail/T12488d.hs
- + testsuite/tests/parser/should_fail/T12488d.stderr
- testsuite/tests/parser/should_fail/all.T
- + testsuite/tests/perf/compiler/T26425.hs
- testsuite/tests/perf/compiler/all.T
- + testsuite/tests/rename/should_compile/T12488b.hs
- + testsuite/tests/rename/should_compile/T12488f.hs
- testsuite/tests/rename/should_compile/all.T
- + testsuite/tests/rename/should_fail/T12488a.hs
- + testsuite/tests/rename/should_fail/T12488a.stderr
- + testsuite/tests/rename/should_fail/T12488a_foo.hs
- + testsuite/tests/rename/should_fail/T12488a_foo.stderr
- + testsuite/tests/rename/should_fail/T12488e.hs
- + testsuite/tests/rename/should_fail/T12488e.stderr
- + testsuite/tests/rename/should_fail/T12488g.hs
- + testsuite/tests/rename/should_fail/T12488g.stderr
- testsuite/tests/rename/should_fail/T25899e2.stderr
- testsuite/tests/rename/should_fail/all.T
- + testsuite/tests/simplCore/should_compile/T26349.hs
- + testsuite/tests/simplCore/should_compile/T26349.stderr
- testsuite/tests/simplCore/should_compile/all.T
- testsuite/tests/simplCore/should_compile/rule2.stderr
- + testsuite/tests/typecheck/should_compile/T17705.hs
- testsuite/tests/typecheck/should_compile/all.T
- utils/check-exact/ExactPrint.hs
- utils/haddock/haddock-api/src/Haddock/Convert.hs
- utils/haddock/haddock-api/src/Haddock/Interface/Rename.hs
- utils/haddock/haddock-api/src/Haddock/Types.hs
The diff was not included because it is too large.
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/6676d34dab1bc325de619605b2d8ea…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/6676d34dab1bc325de619605b2d8ea…
You're receiving this email because of your account on gitlab.haskell.org.
1
0
[Git][ghc/ghc][wip/torsten.schmits/mercury-ghc910-mhu-transitive-th-deps] Load TH deps from home unit states of the modules that import them
by Torsten Schmits (@torsten.schmits) 30 Oct '25
by Torsten Schmits (@torsten.schmits) 30 Oct '25
30 Oct '25
Torsten Schmits pushed to branch wip/torsten.schmits/mercury-ghc910-mhu-transitive-th-deps at Glasgow Haskell Compiler / GHC
Commits:
1c80ba27 by Torsten Schmits at 2025-10-30T17:58:26+01:00
Load TH deps from home unit states of the modules that import them
- - - - -
3 changed files:
- compiler/GHC/Linker/Deps.hs
- compiler/GHC/Linker/Loader.hs
- compiler/GHC/Linker/Types.hs
Changes:
=====================================
compiler/GHC/Linker/Deps.hs
=====================================
@@ -11,6 +11,7 @@
module GHC.Linker.Deps
( LinkDepsOpts (..)
, LinkDeps (..)
+ , LibraryUnits (..)
, getLinkDeps
)
where
@@ -83,10 +84,16 @@ data LinkDepsOpts = LinkDepsOpts
data LinkDeps = LinkDeps
{ ldNeededLinkables :: [Linkable]
, ldAllLinkables :: [Linkable]
- , ldNeededUnits :: [UnitId]
+ , ldNeededUnits :: [LibraryUnits]
, ldAllUnits :: UniqDSet UnitId
}
+data LibraryUnits
+ = LibraryUnits
+ { home_unit :: !UnitId
+ , library_unit :: !UnitId
+ }
+
-- | Find all the packages and linkables that a set of modules depends on
--
-- Return the module and package dependencies for the needed modules.
@@ -155,10 +162,10 @@ get_link_deps opts pls maybe_normal_osuf span mods = do
link_mods =
listToUDFM [(moduleName (mi_module (hm_iface m)), m) | m <- mmods]
link_libs =
- uniqDSetToList (unionManyUniqDSets (init_pkg_set : pkgs))
+ eltsUDFM (foldl' plusUDFM emptyUDFM (init_pkg_set : pkgs))
pure $
LinkModules (LinkHomeModule <$> link_mods) :
- (LinkLibrary <$> link_libs)
+ link_libs
-- This code is used in `--make` mode to calculate the home package and unit dependencies
-- for a set of modules.
@@ -168,7 +175,7 @@ get_link_deps opts pls maybe_normal_osuf span mods = do
-- It is also a matter of correctness to use the module graph so that dependencies between home units
-- is resolved correctly.
- make_deps_loop :: (UniqDSet UnitId, Set.Set NodeKey) -> [ModNodeKeyWithUid] -> (UniqDSet UnitId, Set.Set NodeKey)
+ make_deps_loop :: (UniqDFM UnitId LinkDep, Set.Set NodeKey) -> [ModNodeKeyWithUid] -> (UniqDFM UnitId LinkDep, Set.Set NodeKey)
make_deps_loop found [] = found
make_deps_loop found@(found_units, found_mods) (nk:nexts)
| NodeKey_Module nk `Set.member` found_mods = make_deps_loop found nexts
@@ -176,7 +183,7 @@ get_link_deps opts pls maybe_normal_osuf span mods = do
case fmap mkNodeKey <$> mgReachable mod_graph (NodeKey_Module nk) of
Nothing ->
let (ModNodeKeyWithUid _ uid) = nk
- in make_deps_loop (addOneToUniqDSet found_units uid, found_mods) nexts
+ in make_deps_loop (addToUDFM found_units uid (LinkLibrary LibraryUnits {library_unit = uid, home_unit = (ue_current_unit (ldUnitEnv opts))}), found_mods) nexts
Just trans_deps ->
let deps = Set.insert (NodeKey_Module nk) (Set.fromList trans_deps)
-- See #936 and the ghci.prog007 test for why we have to continue traversing through
@@ -185,7 +192,7 @@ get_link_deps opts pls maybe_normal_osuf span mods = do
in make_deps_loop (found_units, deps `Set.union` found_mods) (todo_boot_mods ++ nexts)
mkNk m = ModNodeKeyWithUid (GWIB (moduleName m) NotBoot) (moduleUnitId m)
- (init_pkg_set, all_deps) = make_deps_loop (emptyUniqDSet, Set.empty) $ map mkNk (filterOut isInteractiveModule mods)
+ (init_pkg_set, all_deps) = make_deps_loop (emptyUDFM, Set.empty) $ map mkNk (filterOut isInteractiveModule mods)
all_home_mods = [with_uid | NodeKey_Module with_uid <- Set.toList all_deps]
@@ -195,7 +202,7 @@ get_link_deps opts pls maybe_normal_osuf span mods = do
let iface = hm_iface hmi
case mi_hsc_src iface of
HsBootFile -> throwProgramError opts $ link_boot_mod_error (mi_module iface)
- _ -> pure (mkUniqDSet $ Set.toList $ dep_direct_pkgs (mi_deps iface), hmi)
+ _ -> pure (listToUDFM [(u, LinkLibrary LibraryUnits {library_unit = u, home_unit = (moduleUnitId (mi_module iface))}) | u <- Set.toList $ dep_direct_pkgs (mi_deps iface)], hmi)
Nothing -> throwProgramError opts $
text "getLinkDeps: Home module not loaded" <+> ppr (gwib_mod gwib) <+> ppr uid
@@ -279,12 +286,13 @@ instance Outputable LinkModule where
data LinkDep =
LinkModules (UniqDFM ModuleName LinkModule)
|
- LinkLibrary UnitId
+ LinkLibrary LibraryUnits
instance Outputable LinkDep where
ppr = \case
LinkModules mods -> text "modules:" <+> ppr (eltsUDFM mods)
- LinkLibrary uid -> text "library:" <+> ppr uid
+ LinkLibrary (LibraryUnits {home_unit, library_unit}) ->
+ text "library:" <+> ppr library_unit <+> parens (ppr home_unit)
data OneshotError =
NoLocation Module
@@ -337,7 +345,7 @@ oneshot_deps_loop opts (mod : mods) acc = do
already_seen
| Just (LinkModules mods) <- mod_dep
= elemUDFM mod_name mods
- | Just (LinkLibrary _) <- mod_dep
+ | Just (LinkLibrary {}) <- mod_dep
= True
| otherwise
= False
@@ -362,7 +370,7 @@ oneshot_deps_loop opts (mod : mods) acc = do
| otherwise
= add_library
- add_library = pure (addToUDFM acc mod_unit_id (LinkLibrary mod_unit_id), [])
+ add_library = pure (addToUDFM acc mod_unit_id (LinkLibrary LibraryUnits {library_unit = mod_unit_id, home_unit}), [])
add_module iface lmod =
(addListToUDFM with_mod (direct_pkgs iface), new_deps iface)
@@ -378,7 +386,7 @@ oneshot_deps_loop opts (mod : mods) acc = do
| bytecode
= []
| otherwise
- = [(u, LinkLibrary u) | u <- Set.toList (dep_direct_pkgs (mi_deps iface))]
+ = [(u, LinkLibrary LibraryUnits {library_unit = u, home_unit}) | u <- Set.toList (dep_direct_pkgs (mi_deps iface))]
new_deps iface
| bytecode
@@ -418,6 +426,7 @@ oneshot_deps_loop opts (mod : mods) acc = do
text "due to use of Template Haskell"
bytecode = ldUseByteCode opts
+ home_unit = homeUnitId (expectJust "oneshot_deps" mb_home)
mb_home = ue_homeUnit (ldUnitEnv opts)
link_boot_mod_error :: Module -> SDoc
@@ -428,7 +437,7 @@ link_boot_mod_error mod =
classify_deps ::
LoaderState ->
[LinkDep] ->
- ([Linkable], [LinkModule], UniqDSet UnitId, [UnitId])
+ ([Linkable], [LinkModule], UniqDSet UnitId, [LibraryUnits])
classify_deps pls deps =
(loaded_modules, needed_modules, all_packages, needed_packages)
where
@@ -436,13 +445,15 @@ classify_deps pls deps =
partitionWith loaded_or_needed (concatMap eltsUDFM modules)
needed_packages =
- eltsUDFM (getUniqDSet all_packages `minusUDFM` pkgs_loaded pls)
+ eltsUDFM (packages `minusUDFM` pkgs_loaded pls)
+
+ packages = listToUDFM [(library_unit p, p) | p <- packages_with_home_units]
- all_packages = mkUniqDSet packages
+ all_packages = mkUniqDSet (map library_unit packages_with_home_units)
- (modules, packages) = flip partitionWith deps $ \case
+ (modules, packages_with_home_units) = flip partitionWith deps $ \case
LinkModules mods -> Left mods
- LinkLibrary lib -> Right lib
+ LinkLibrary units -> Right units
loaded_or_needed lm =
maybe (Right lm) Left (loaded_linkable (mi_module (link_module_iface lm)))
=====================================
compiler/GHC/Linker/Loader.hs
=====================================
@@ -93,8 +93,9 @@ import Control.Monad
import qualified Data.Set as Set
import Data.Char (isSpace)
+import Data.Foldable (for_)
import Data.IORef
-import Data.List (intercalate, isPrefixOf, nub, partition)
+import Data.List (intercalate, isPrefixOf, nub, partition, sortOn)
import Data.Maybe
import Control.Concurrent.MVar
import qualified Control.Monad.Catch as MC
@@ -109,6 +110,7 @@ import System.Win32.Info (getSystemDirectory)
#endif
import GHC.Utils.Exception
+import qualified Data.List.NonEmpty as NE
-- Note [Linkers and loaders]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -173,7 +175,7 @@ emptyLoaderState = LoaderState
--
-- The linker's symbol table is populated with RTS symbols using an
-- explicit list. See rts/Linker.c for details.
- where init_pkgs = unitUDFM rtsUnitId (LoadedPkgInfo rtsUnitId [] [] [] emptyUniqDSet)
+ where init_pkgs = unitUDFM rtsUnitId (LoadedPkgInfo rtsUnitId Nothing [] [] [] emptyUniqDSet)
extendLoadedEnv :: Interp -> [(Name,ForeignHValue)] -> IO ()
extendLoadedEnv interp new_bindings =
@@ -325,9 +327,8 @@ reallyInitLoaderState interp hsc_env = do
-- (a) initialise the C dynamic linker
initObjLinker interp
-
-- (b) Load packages from the command-line (Note [preload packages])
- pls <- unitEnv_foldWithKey (\k u env -> k >>= \pls' -> loadPackages' interp (hscSetActiveUnitId u hsc_env) (preloadUnits (homeUnitEnv_units env)) pls') (return pls0) (hsc_HUG hsc_env)
+ pls <- unitEnv_foldWithKey (\k u env -> k >>= \pls' -> loadPackages' interp hsc_env [LibraryUnits {home_unit = u, library_unit = pre} | pre <- preloadUnits (homeUnitEnv_units env)] pls') (return pls0) (hsc_HUG hsc_env)
-- steps (c), (d) and (e)
loadCmdLineLibs' interp hsc_env pls
@@ -855,7 +856,13 @@ dynLoadObjs interp hsc_env pls@LoaderState{..} objs = do
-- link all "loaded packages" so symbols in those can be resolved
-- Note: We are loading packages with local scope, so to see the
-- symbols in this link we must link all loaded packages again.
- linkDynLib logger tmpfs dflags2 unit_env objs (loaded_pkg_uid <$> eltsUDFM pkgs_loaded)
+ do
+ let groupedLoadedPackageInfos = groupLoadedPackageInfosByParent pkgs_loaded
+ for_ groupedLoadedPackageInfos $ \(mParent, loaded_pkg_uids) -> do
+ let unit_env' = case mParent of
+ Nothing -> unit_env
+ Just parent -> ue_setActiveUnit parent unit_env
+ linkDynLib logger tmpfs dflags2 unit_env' objs loaded_pkg_uids
-- if we got this far, extend the lifetime of the library file
changeTempFilesLifetime tmpfs TFL_GhcSession [soFile]
@@ -866,6 +873,19 @@ dynLoadObjs interp hsc_env pls@LoaderState{..} objs = do
where
msg = "GHC.Linker.Loader.dynLoadObjs: Loading temp shared object failed"
+ groupOn :: Eq k => (a -> k) -> [a] -> [NE.NonEmpty a]
+ groupOn f = NE.groupBy ((==) `on2` f)
+ -- redefine on so we avoid duplicate computation for most values.
+ where (.*.) `on2` f = \x -> let fx = f x in \y -> fx .*. f y
+
+ groupLoadedPackageInfosByParent :: PkgsLoaded -> [(Maybe UnitId, [UnitId])]
+ groupLoadedPackageInfosByParent pkgs =
+ map (\l -> (loaded_pkg_parent (NE.head l), NE.toList $ NE.map loaded_pkg_uid l))
+ $ groupOn loaded_pkg_parent
+ $ sortOn loaded_pkg_parent
+ $ eltsUDFM pkgs
+
+
rmDupLinkables :: LinkableSet -- Already loaded
-> [Linkable] -- New linkables
-> (LinkableSet, -- New loaded set (including new ones)
@@ -1075,36 +1095,39 @@ loadPackages interp hsc_env new_pkgs = do
-- a lock.
initLoaderState interp hsc_env
modifyLoaderState_ interp $ \pls ->
- loadPackages' interp hsc_env new_pkgs pls
+ loadPackages' interp hsc_env [LibraryUnits {home_unit = hscActiveUnitId hsc_env, library_unit} | library_unit <- new_pkgs] pls
-loadPackages' :: Interp -> HscEnv -> [UnitId] -> LoaderState -> IO LoaderState
-loadPackages' interp hsc_env new_pks pls = do
+loadPackages' :: Interp -> HscEnv -> [LibraryUnits] -> LoaderState -> IO LoaderState
+loadPackages' interp hsc_env0 new_pks pls = do
pkgs' <- link (pkgs_loaded pls) new_pks
return $! pls { pkgs_loaded = pkgs'
}
where
- link :: PkgsLoaded -> [UnitId] -> IO PkgsLoaded
+ link :: PkgsLoaded -> [LibraryUnits] -> IO PkgsLoaded
link pkgs new_pkgs =
foldM link_one pkgs new_pkgs
- link_one pkgs new_pkg
- | new_pkg `elemUDFM` pkgs -- Already linked
+ link_one pkgs (LibraryUnits {home_unit, library_unit})
+ | library_unit `elemUDFM` pkgs -- Already linked
= return pkgs
- | Just pkg_cfg <- lookupUnitId (hsc_units hsc_env) new_pkg
+ | Just pkg_cfg <- lookupUnitId (hsc_units (hscSetActiveUnitId home_unit hsc_env)) library_unit
= do { let deps = unitDepends pkg_cfg
-- Link dependents first
- ; pkgs' <- link pkgs deps
+ ; pkgs' <- link pkgs [LibraryUnits {home_unit, library_unit} | library_unit <- deps]
+
-- Now link the package itself
; (hs_cls, extra_cls, loaded_dlls) <- loadPackage interp hsc_env pkg_cfg
; let trans_deps = unionManyUniqDSets [ addOneToUniqDSet (loaded_pkg_trans_deps loaded_pkg_info) dep_pkg
| dep_pkg <- deps
, Just loaded_pkg_info <- pure (lookupUDFM pkgs' dep_pkg)
]
- ; return (addToUDFM pkgs' new_pkg (LoadedPkgInfo new_pkg hs_cls extra_cls loaded_dlls trans_deps)) }
+ ; return (addToUDFM pkgs' library_unit (LoadedPkgInfo library_unit (Just home_unit) hs_cls extra_cls loaded_dlls trans_deps)) }
| otherwise
- = throwGhcExceptionIO (CmdLineError ("unknown package: " ++ unpackFS (unitIdFS new_pkg)))
+ = throwGhcExceptionIO (CmdLineError ("unknown package: " ++ unpackFS (unitIdFS library_unit)))
+ where
+ hsc_env = hscSetActiveUnitId home_unit hsc_env0
loadPackage :: Interp -> HscEnv -> UnitInfo -> IO ([LibrarySpec], [LibrarySpec], [RemotePtr LoadedDLL])
=====================================
compiler/GHC/Linker/Types.hs
=====================================
@@ -192,6 +192,7 @@ type PkgsLoaded = UniqDFM UnitId LoadedPkgInfo
data LoadedPkgInfo
= LoadedPkgInfo
{ loaded_pkg_uid :: !UnitId
+ , loaded_pkg_parent :: !(Maybe UnitId)
, loaded_pkg_hs_objs :: ![LibrarySpec]
, loaded_pkg_non_hs_objs :: ![LibrarySpec]
, loaded_pkg_hs_dlls :: ![RemotePtr LoadedDLL]
@@ -200,8 +201,9 @@ data LoadedPkgInfo
}
instance Outputable LoadedPkgInfo where
- ppr (LoadedPkgInfo uid hs_objs non_hs_objs _ trans_deps) =
- vcat [ppr uid
+ ppr (LoadedPkgInfo uid parent_uid hs_objs non_hs_objs _ trans_deps) =
+ vcat [ ppr uid
+ , ppr parent_uid
, ppr hs_objs
, ppr non_hs_objs
, ppr trans_deps ]
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1c80ba274d942b854db9fd8f029a5c2…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/1c80ba274d942b854db9fd8f029a5c2…
You're receiving this email because of your account on gitlab.haskell.org.
1
0
[Git][ghc/ghc][master] Fix namespace specifiers in subordinate exports (#12488)
by Marge Bot (@marge-bot) 30 Oct '25
by Marge Bot (@marge-bot) 30 Oct '25
30 Oct '25
Marge Bot pushed to branch master at Glasgow Haskell Compiler / GHC
Commits:
5618645b by Vladislav Zavialov at 2025-10-30T12:39:33-04:00
Fix namespace specifiers in subordinate exports (#12488)
This patch fixes an oversight in the `lookupChildrenExport` function that
caused explicit namespace specifiers of subordinate export items to be
ignored:
module M (T (type A)) where -- should be rejected
data T = A
Based on the `IEWrappedName` data type, there are 5 cases to consider:
1. Unadorned name: P(X)
2. Named default: P(default X)
3. Pattern synonym: P(pattern X)
4. Type name: P(type X)
5. Data name: P(data X)
Case 1 is already handled correctly; cases 2 and 3 are parse errors; and
it is cases 4 and 5 that we are concerned with in this patch.
Following the precedent established in `LookupExactName`, we introduce
a boolean flag in `LookupChildren` to control whether to look up in all
namespaces or in a specific one. If an export item is accompanied by an
explicit namespace specifier `type` or `data`, we restrict the lookup in
`lookupGRE` to a specific namespace.
The newly introduced diagnostic `TcRnExportedSubordinateNotFound`
provides error messages and suggestions more tailored to this context
than the previously used `reportUnboundName`.
- - - - -
28 changed files:
- compiler/GHC/Rename/Env.hs
- compiler/GHC/Rename/Names.hs
- compiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/Export.hs
- compiler/GHC/Types/Error/Codes.hs
- compiler/GHC/Types/Hint.hs
- compiler/GHC/Types/Hint/Ppr.hs
- compiler/GHC/Types/Name/Reader.hs
- testsuite/tests/module/mod4.stderr
- + testsuite/tests/parser/should_fail/T12488c.hs
- + testsuite/tests/parser/should_fail/T12488c.stderr
- + testsuite/tests/parser/should_fail/T12488d.hs
- + testsuite/tests/parser/should_fail/T12488d.stderr
- testsuite/tests/parser/should_fail/all.T
- + testsuite/tests/rename/should_compile/T12488b.hs
- + testsuite/tests/rename/should_compile/T12488f.hs
- testsuite/tests/rename/should_compile/all.T
- + testsuite/tests/rename/should_fail/T12488a.hs
- + testsuite/tests/rename/should_fail/T12488a.stderr
- + testsuite/tests/rename/should_fail/T12488a_foo.hs
- + testsuite/tests/rename/should_fail/T12488a_foo.stderr
- + testsuite/tests/rename/should_fail/T12488e.hs
- + testsuite/tests/rename/should_fail/T12488e.stderr
- + testsuite/tests/rename/should_fail/T12488g.hs
- + testsuite/tests/rename/should_fail/T12488g.stderr
- testsuite/tests/rename/should_fail/T25899e2.stderr
- testsuite/tests/rename/should_fail/all.T
Changes:
=====================================
compiler/GHC/Rename/Env.hs
=====================================
@@ -679,19 +679,20 @@ lookupGlobalOccRn will find it.
-}
-- | Used in export lists to lookup the children.
-lookupSubBndrOcc_helper :: Bool
+lookupSubBndrOcc_helper :: Bool -- ^ must have a parent
+ -> Bool -- ^ look up in all namespaces
-> DeprecationWarnings
-> ParentGRE -- ^ parent
-> RdrName -- ^ thing we are looking up
-> RnM ChildLookupResult
-lookupSubBndrOcc_helper must_have_parent warn_if_deprec parent_gre rdr_name
+lookupSubBndrOcc_helper must_have_parent all_ns warn_if_deprec parent_gre rdr_name
| isUnboundName (parentGRE_name parent_gre)
-- Avoid an error cascade
= return (FoundChild (mkUnboundGRERdr rdr_name))
| otherwise = do
gre_env <- getGlobalRdrEnv
- let original_gres = lookupGRE gre_env (LookupChildren parent_gre (rdrNameOcc rdr_name))
+ let original_gres = lookupGRE gre_env (LookupChildren parent_gre (rdrNameOcc rdr_name) all_ns)
picked_gres = pick_gres original_gres
-- The remaining GREs are things that we *could* export here.
-- Note that this includes things which have `NoParent`;
@@ -844,7 +845,7 @@ lookupSubBndrOcc :: DeprecationWarnings
lookupSubBndrOcc warn_if_deprec the_parent what_subordinate rdr_name =
lookupExactOrOrig rdr_name (Right . greName) $
-- This happens for built-in classes, see mod052 for example
- do { child <- lookupSubBndrOcc_helper True warn_if_deprec the_parent rdr_name
+ do { child <- lookupSubBndrOcc_helper True True warn_if_deprec the_parent rdr_name
; return $ case child of
FoundChild g -> Right (greName g)
NameNotFound -> Left unknown_sub
=====================================
compiler/GHC/Rename/Names.hs
=====================================
@@ -23,6 +23,7 @@ module GHC.Rename.Names (
checkConName,
mkChildEnv,
findChildren,
+ mkBadExportSubordinate,
findImportUsage,
getMinimalImports,
printMinimalImports,
@@ -1423,6 +1424,15 @@ filterImports hsc_env iface decl_spec (Just (want_hiding, L l import_items))
where
name = greName gre
+-- | Assuming a subordinate item could not be found, do another lookup for a
+-- more specific error message.
+mkBadExportSubordinate :: [GlobalRdrElt] -> LIEWrappedName GhcPs -> BadExportSubordinate
+mkBadExportSubordinate child_gres n =
+ case lookupChildren child_gres [n] of
+ (LookupChildNonType {lce_nontype_item = g} : _, _) -> BadExportSubordinateNonType g
+ (LookupChildNonData {lce_nondata_item = g} : _, _) -> BadExportSubordinateNonData g
+ _ -> BadExportSubordinateNotFound n
+
type IELookupM = MaybeErr IELookupError
data IELookupWarning
=====================================
compiler/GHC/Tc/Errors/Ppr.hs
=====================================
@@ -675,6 +675,43 @@ instance Diagnostic TcRnMessage where
what_is = pp_category ty_thing
thing = ppr $ nameOccName child
parents = map ppr parent_names
+ TcRnExportedSubordinateNotFound parent_gre k _ ->
+ mkSimpleDecorated $
+ case k of
+ BadExportSubordinateNotFound wname ->
+ let child_name = lieWrappedName wname
+ child_name_fs = occNameFS (rdrNameOcc child_name)
+ suggest_patsyn = allow_patsyn && could_be_patsyn
+ could_be_patsyn =
+ case unLoc wname of
+ IEName{} -> isLexCon child_name_fs
+ IEData{} -> isLexCon child_name_fs
+ IEPattern{} -> True
+ IEType{} -> False
+ IEDefault{} -> False
+ basic_msg =
+ what_parent <+> quotes (ppr parent_name)
+ <+> "does not define a child named" <+> quotes (ppr child_name)
+ patsyn_msg =
+ text "nor is there a pattern synonym of that name in scope"
+ combined_msg
+ | suggest_patsyn = basic_msg <> comma $$ patsyn_msg <> dot
+ | otherwise = basic_msg <> dot
+ in combined_msg
+ BadExportSubordinateNonType gre ->
+ let child_name = greName gre
+ in what_parent <+> quotes (ppr parent_name) <+> "defines a child named" <+> quotes (ppr child_name) <> comma
+ $$ text "but it is not in the type namespace."
+ BadExportSubordinateNonData gre ->
+ let child_name = greName gre
+ in what_parent <+> quotes (ppr parent_name) <+> "defines a child named" <+> quotes (ppr child_name) <> comma
+ $$ text "but it is not in the data namespace."
+ where
+ parent_name = greName parent_gre
+ (what_parent, allow_patsyn) = case greInfo parent_gre of
+ IAmTyCon ClassFlavour -> (text "The class", False)
+ IAmTyCon _ -> (text "The data type", True)
+ _ -> (text "The item", False)
TcRnConflictingExports occ child_gre1 ie1 child_gre2 ie2
-> mkSimpleDecorated $
vcat [ text "Conflicting exports for" <+> quotes (ppr occ) <> colon
@@ -2204,6 +2241,8 @@ instance Diagnostic TcRnMessage where
-> WarningWithFlag Opt_WarnDuplicateExports
TcRnExportedParentChildMismatch{}
-> ErrorWithoutFlag
+ TcRnExportedSubordinateNotFound{}
+ -> ErrorWithoutFlag
TcRnConflictingExports{}
-> ErrorWithoutFlag
TcRnDuplicateFieldExport {}
@@ -2875,6 +2914,13 @@ instance Diagnostic TcRnMessage where
-> noHints
TcRnExportedParentChildMismatch{}
-> noHints
+ TcRnExportedSubordinateNotFound _ k similar_names
+ -> ns_spec_hints ++ similar_names
+ where
+ ns_spec_hints = case k of
+ BadExportSubordinateNotFound{} -> noHints
+ BadExportSubordinateNonType{} -> [SuggestChangeExportItem ExportItemRemoveSubordinateType]
+ BadExportSubordinateNonData{} -> [SuggestChangeExportItem ExportItemRemoveSubordinateData]
TcRnConflictingExports{}
-> noHints
TcRnDuplicateFieldExport {}
=====================================
compiler/GHC/Tc/Errors/Types.hs
=====================================
@@ -83,7 +83,6 @@ module GHC.Tc.Errors.Types (
, Subordinate(..), pprSubordinate
, ImportError(..)
, WhatLooking(..)
- , lookingForSubordinate
, HoleError(..)
, CoercibleMsg(..)
, NoBuiltinInstanceMsg(..)
@@ -117,6 +116,7 @@ module GHC.Tc.Errors.Types (
, HsTyVarBndrExistentialFlag(..)
, TySynCycleTyCons
, BadImportKind(..)
+ , BadExportSubordinate(..)
, DodgyImportsReason (..)
, ImportLookupExtensions (..)
, ImportLookupReason (..)
@@ -1664,6 +1664,26 @@ data TcRnMessage where
-> Name -- ^ child
-> [Name] -> TcRnMessage
+ {-| TcRnExportedSubordinateNotFound is an error that occurs when the name of a
+ subordinate export item is not in scope.
+
+ Example:
+ module M (T(X)) where -- X is not in scope
+ data T = Y
+
+ Test cases: module/mod4
+ rename/should_fail/T12488a
+ rename/should_fail/T12488a_foo
+ rename/should_fail/T12488e
+ rename/should_fail/T12488g
+ rename/should_fail/T25899e2
+ -}
+ TcRnExportedSubordinateNotFound
+ :: GlobalRdrElt -- ^ parent
+ -> BadExportSubordinate
+ -> [GhcHint] -- ^ similar name suggestions
+ -> TcRnMessage
+
{-| TcRnConflictingExports is an error that occurs when different identifiers that
have the same name are being exported by a module.
@@ -5829,6 +5849,11 @@ data BadImportKind
| BadImportAvailVar
deriving Generic
+data BadExportSubordinate
+ = BadExportSubordinateNotFound !(LIEWrappedName GhcPs)
+ | BadExportSubordinateNonType !GlobalRdrElt
+ | BadExportSubordinateNonData !GlobalRdrElt
+
{- Note [Reasons for BadImportAvailTyCon]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BadImportAvailTyCon means a name is available in the TcCls namespace
@@ -6065,15 +6090,6 @@ data WhatLooking = WL_Anything
-- is no point in suggesting alternative spellings
deriving (Eq, Show)
--- | In what namespaces should we look for a subordinate
--- of the given 'GlobalRdrElt'.
-lookingForSubordinate :: GlobalRdrElt -> WhatLooking
-lookingForSubordinate parent_gre =
- case greInfo parent_gre of
- IAmTyCon ClassFlavour
- -> WL_TyCon_or_TermVar
- _ -> WL_Term
-
-- | This datatype collates instances that match or unifier,
-- in order to report an error message for an unsolved typeclass constraint.
data PotentialInstances
=====================================
compiler/GHC/Tc/Gen/Export.hs
=====================================
@@ -22,7 +22,7 @@ import GHC.Rename.Doc
import GHC.Rename.Module
import GHC.Rename.Names
import GHC.Rename.Env
-import GHC.Rename.Unbound ( reportUnboundName )
+import GHC.Rename.Unbound ( mkUnboundNameRdr )
import GHC.Rename.Splice
import GHC.Unit.Module
import GHC.Unit.Module.Imported
@@ -30,13 +30,13 @@ import GHC.Unit.Module.Warnings
import GHC.Core.TyCon
import GHC.Utils.Outputable
import GHC.Utils.Panic
+import GHC.Utils.Misc (fuzzyLookup)
import GHC.Core.ConLike
import GHC.Core.PatSyn
import GHC.Data.Maybe
import GHC.Data.FastString (fsLit)
import GHC.Driver.Env
import GHC.Driver.DynFlags
-import GHC.Parser.PostProcess ( setRdrNameSpace )
import qualified GHC.LanguageExtensions as LangExt
import GHC.Types.Unique.Map
@@ -50,6 +50,7 @@ import GHC.Types.SourceFile
import GHC.Types.Id
import GHC.Types.Id.Info
import GHC.Types.Name.Reader
+import GHC.Types.Hint
import Control.Arrow ( first )
import Control.Monad ( when )
@@ -590,8 +591,9 @@ exports_from_avail (Just (L _ rdr_items)) rdr_env imports this_mod
lookup_ie_kids_with :: GlobalRdrElt -> [LIEWrappedName GhcPs]
-> RnM ([LIEWrappedName GhcRn], [GlobalRdrElt])
lookup_ie_kids_with gre sub_rdrs =
- do { kids <- lookupChildrenExport gre sub_rdrs
- ; return (map fst kids, map snd kids) }
+ do { let child_gres = findChildren kids_env (greName gre)
+ ; kids <- lookupChildrenExport gre child_gres sub_rdrs
+ ; return (unzip kids) }
lookup_ie_kids_all :: IE GhcPs -> LIEWrappedName GhcPs -> GlobalRdrElt
-> RnM [GlobalRdrElt]
@@ -782,9 +784,10 @@ If the module has NO main function:
lookupChildrenExport :: GlobalRdrElt
+ -> [GlobalRdrElt]
-> [LIEWrappedName GhcPs]
-> RnM ([(LIEWrappedName GhcRn, GlobalRdrElt)])
-lookupChildrenExport parent_gre rdr_items = mapAndReportM doOne rdr_items
+lookupChildrenExport parent_gre child_gres rdr_items = mapAndReportM doOne rdr_items
where
spec_parent = greName parent_gre
-- Process an individual child
@@ -792,24 +795,23 @@ lookupChildrenExport parent_gre rdr_items = mapAndReportM doOne rdr_items
-> RnM (LIEWrappedName GhcRn, GlobalRdrElt)
doOne n = do
- let bareName = (ieWrappedName . unLoc) n
+ let all_ns = case unLoc n of
+ IEName{} -> True -- Ignore the namespace iff the name is unadorned
+ _ -> False
+ let bareName = lieWrappedName n
-- Do not report export list declaration deprecations
- name <- lookupSubBndrOcc_helper False ExportDeprecationWarnings
+ name <- lookupSubBndrOcc_helper False all_ns ExportDeprecationWarnings
(ParentGRE spec_parent (greInfo parent_gre)) bareName
traceRn "lookupChildrenExport" (ppr name)
- -- Default to data constructors for slightly better error
- -- messages
- let unboundName :: RdrName
- unboundName = if rdrNameSpace bareName == varName
- then bareName
- else setRdrNameSpace bareName dataName
case name of
NameNotFound ->
- do { ub <- reportUnboundName (lookingForSubordinate parent_gre) unboundName
- ; let l = getLoc n
+ do { let err = mkBadExportSubordinate child_gres n
+ similar_names = subordinateExportSimilarNames bareName child_gres
+ ; addDiagnosticTc (TcRnExportedSubordinateNotFound parent_gre err similar_names)
+ ; let ub = mkUnboundNameRdr bareName
gre = mkLocalGRE UnboundGRE NoParent ub
- ; return (L l (IEName noExtField (L (l2l l) ub)), gre)}
+ ; return (replaceLWrappedName n ub, gre)}
FoundChild child@(GRE { gre_name = child_nm, gre_par = par }) ->
do { checkPatSynParent spec_parent par child_nm
; checkThLocalNameNoLift (ieLWrappedUserRdrName n child_nm)
@@ -817,6 +819,22 @@ lookupChildrenExport parent_gre rdr_items = mapAndReportM doOne rdr_items
}
IncorrectParent p c gs -> failWithDcErr (parentGRE_name p) (greName c) gs
+subordinateExportSimilarNames :: RdrName -> [GlobalRdrElt] -> [GhcHint]
+subordinateExportSimilarNames rdr_name child_gres =
+ -- At the moment, we only suggest other children of the same parent.
+ -- One possible improvement would be to suggest bundling pattern synonyms with
+ -- data types, but not with classes or type data.
+ case NE.nonEmpty similar_names of
+ Nothing -> []
+ Just nms -> [SuggestSimilarNames rdr_name (fmap SimilarName nms)]
+ where
+ occ_name = rdrNameOcc rdr_name
+ similar_names =
+ fuzzyLookup (occNameString occ_name)
+ [(occNameString child_occ_name, greName gre)
+ | gre <- child_gres
+ , let child_occ_name = greOccName gre
+ , occNameFS occ_name /= occNameFS child_occ_name ]
-- Note [Typing Pattern Synonym Exports]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
=====================================
compiler/GHC/Types/Error/Codes.hs
=====================================
@@ -510,6 +510,7 @@ type family GhcDiagnosticCode c = n | n -> c where
GhcDiagnosticCode "TcRnDuplicateExport" = 47854
GhcDiagnosticCode "TcRnDuplicateNamedDefaultExport" = 31584
GhcDiagnosticCode "TcRnExportedParentChildMismatch" = 88993
+ GhcDiagnosticCode "TcRnExportedSubordinateNotFound" = 11592
GhcDiagnosticCode "TcRnConflictingExports" = 69158
GhcDiagnosticCode "TcRnDuplicateFieldExport" = 97219
GhcDiagnosticCode "TcRnAmbiguousFieldInUpdate" = 56428
=====================================
compiler/GHC/Types/Hint.hs
=====================================
@@ -7,6 +7,7 @@ module GHC.Types.Hint (
, LanguageExtensionHint(..)
, ImportItemSuggestion(..)
, ImportSuggestion(..)
+ , ExportItemSuggestion(..)
, HowInScope(..)
, SimilarName(..)
, StarIsType(..)
@@ -419,6 +420,12 @@ data GhcHint
-}
| ImportSuggestion OccName ImportSuggestion
+ {-| Suggest to change an export item, e.g. to remove a namespace specifier.
+
+ Test cases: T12488a, T12488a_foo, T12488e, T12488g, T25899e2
+ -}
+ | SuggestChangeExportItem ExportItemSuggestion
+
{-| Found a pragma in the body of a module, suggest placing it in the header.
-}
| SuggestPlacePragmaInHeader
@@ -556,6 +563,11 @@ data ImportItemSuggestion =
-- Why no 'ImportItemAddData'? Because the suggestion to add 'data' is
-- represented by the 'ImportDataCon' constructor of 'ImportSuggestion'.
+-- | Suggest to change an export item.
+data ExportItemSuggestion =
+ ExportItemRemoveSubordinateType
+ | ExportItemRemoveSubordinateData
+
-- | Suggest how to fix an import.
data ImportSuggestion
-- | Some module exports what we want, but we aren't explicitly importing it.
=====================================
compiler/GHC/Types/Hint/Ppr.hs
=====================================
@@ -214,6 +214,10 @@ instance Outputable GhcHint where
<+> pprQuotedList parents
ImportSuggestion occ_name import_suggestion
-> pprImportSuggestion occ_name import_suggestion
+ SuggestChangeExportItem export_item_suggestion
+ -> case export_item_suggestion of
+ ExportItemRemoveSubordinateType -> text "Remove the" <+> quotes (text "type") <+> text "keyword"
+ ExportItemRemoveSubordinateData -> text "Remove the" <+> quotes (text "data") <+> text "keyword"
SuggestPlacePragmaInHeader
-> text "Perhaps you meant to place it in the module header?"
$$ text "The module header is the section at the top of the file, before the" <+> quotes (text "module") <+> text "keyword"
=====================================
compiler/GHC/Types/Name/Reader.hs
=====================================
@@ -1182,8 +1182,12 @@ data LookupGRE info where
-- | Look up children 'GlobalRdrElt's with a given 'Parent'.
LookupChildren
- :: ParentGRE -- ^ the parent
- -> OccName -- ^ the child 'OccName' to look up
+ :: { lookupParentGRE :: ParentGRE -- ^ the parent
+ , lookupChildOccName :: OccName -- ^ the child 'OccName' to look up
+ , lookupChildrenInAllNameSpaces :: Bool
+ -- ^ whether to look in *all* 'NameSpace's, or just
+ -- in the 'NameSpace' of the 'OccName'
+ }
-> LookupGRE GREInfo
-- | How should we look up in a 'GlobalRdrEnv'?
@@ -1420,10 +1424,15 @@ lookupGRE env = \case
occ = nameOccName nm
lkup | all_ns = concat $ lookupOccEnv_AllNameSpaces env occ
| otherwise = fromMaybe [] $ lookupOccEnv env occ
- LookupChildren parent child_occ ->
- let ns = occNameSpace child_occ
- all_gres = concat $ lookupOccEnv_AllNameSpaces env child_occ
- in highestPriorityGREs (childGREPriority parent ns) all_gres
+ LookupChildren { lookupParentGRE = parent
+ , lookupChildOccName = child_occ
+ , lookupChildrenInAllNameSpaces = all_ns } ->
+ highestPriorityGREs (childGREPriority parent ns) $
+ concat $ lkup env child_occ
+ where
+ ns = occNameSpace child_occ
+ lkup | all_ns = lookupOccEnv_AllNameSpaces
+ | otherwise = lookupOccEnv_WithFields
-- | Collect the 'GlobalRdrElt's with the highest priority according
-- to the given function (lower value <=> higher priority).
=====================================
testsuite/tests/module/mod4.stderr
=====================================
@@ -1,5 +1,6 @@
-
-mod4.hs:2:10: error: [GHC-76037]
- • Not in scope: data constructor ‘K2’
+mod4.hs:2:10: error: [GHC-11592]
+ • The data type ‘T’ does not define a child named ‘K2’,
+ nor is there a pattern synonym of that name in scope.
• In the export: T(K1, K2)
- Suggested fix: Perhaps use ‘K1’ (line 3)
+ Suggested fix: Perhaps use ‘K1’ (Defined at mod4.hs:3:10)
+
=====================================
testsuite/tests/parser/should_fail/T12488c.hs
=====================================
@@ -0,0 +1,4 @@
+{-# LANGUAGE PatternSynonyms #-}
+module T12488c ( T (pattern A) ) where
+
+data T = A
\ No newline at end of file
=====================================
testsuite/tests/parser/should_fail/T12488c.stderr
=====================================
@@ -0,0 +1,2 @@
+T12488c.hs:2:21: error: [GHC-58481] parse error on input ‘pattern’
+
=====================================
testsuite/tests/parser/should_fail/T12488d.hs
=====================================
@@ -0,0 +1,6 @@
+{-# LANGUAGE NamedDefaults #-}
+module T12488d ( T (default C) ) where
+
+class C a where
+
+data T = A
\ No newline at end of file
=====================================
testsuite/tests/parser/should_fail/T12488d.stderr
=====================================
@@ -0,0 +1,2 @@
+T12488d.hs:2:21: error: [GHC-58481] parse error on input ‘default’
+
=====================================
testsuite/tests/parser/should_fail/all.T
=====================================
@@ -242,3 +242,5 @@ test('T25258b', normal, compile_fail, [''])
test('T25258c', normal, compile_fail, [''])
test('T25530', normal, compile_fail, [''])
test('T26418', normal, compile_fail, [''])
+test('T12488c', normal, compile_fail, [''])
+test('T12488d', normal, compile_fail, [''])
=====================================
testsuite/tests/rename/should_compile/T12488b.hs
=====================================
@@ -0,0 +1,24 @@
+{-# LANGUAGE ExplicitNamespaces #-}
+{-# LANGUAGE TypeFamilies #-}
+
+module T12488b
+ ( T ( data A, -- data constructor (alphanumeric name)
+ data fld, -- record field (alphanumeric name)
+ data (:!!), -- data constructor (symbolic name)
+ data (///) -- record field (symbolic name)
+ ),
+ C ( type F, -- associated type (alphanumeric name)
+ data meth, -- class method (alphanumeric name)
+ type (+++), -- associated type (symbolic name)
+ data (***) -- class method (symbolic name)
+ ),
+ ) where
+
+data T = A { fld :: Int }
+ | (:!!) { (///) :: Int -> Int }
+
+class C a where
+ type F a
+ type (+++) a
+ meth :: a -> a
+ (***) :: a -> a -> a
=====================================
testsuite/tests/rename/should_compile/T12488f.hs
=====================================
@@ -0,0 +1,14 @@
+{-# LANGUAGE ExplicitNamespaces #-}
+{-# LANGUAGE TypeFamilies #-}
+
+module T12488f
+ ( C ( type (+++), -- associated type (symbolic name)
+ data (++-) -- class method (symbolic name)
+ ),
+ ) where
+
+class C a where
+ type (+++) a -- exported
+ type (++-) a -- not exported
+ (+++) :: a -> a -- not exported
+ (++-) :: a -> a -- exported
=====================================
testsuite/tests/rename/should_compile/all.T
=====================================
@@ -245,3 +245,5 @@ test('T25899a', normal, compile, [''])
test('T25899b', normal, compile, [''])
test('T25899c', [extra_files(['T25899c_helper.hs'])], multimod_compile, ['T25899c', '-v0'])
test('T25899d', combined_output, ghci_script, ['T25899d.script'])
+test('T12488b', normal, compile, [''])
+test('T12488f', normal, compile, [''])
=====================================
testsuite/tests/rename/should_fail/T12488a.hs
=====================================
@@ -0,0 +1,9 @@
+{-# LANGUAGE ExplicitNamespaces #-}
+module T12488a
+ ( T (type A)
+ , (:!) (type (:/))
+ ) where
+
+data T = A
+
+data (:!) = (:/)
\ No newline at end of file
=====================================
testsuite/tests/rename/should_fail/T12488a.stderr
=====================================
@@ -0,0 +1,12 @@
+T12488a.hs:3:5: error: [GHC-11592]
+ • The data type ‘T’ defines a child named ‘A’,
+ but it is not in the type namespace.
+ • In the export: T(type A)
+ Suggested fix: Remove the ‘type’ keyword
+
+T12488a.hs:4:5: error: [GHC-11592]
+ • The data type ‘:!’ defines a child named ‘:/’,
+ but it is not in the type namespace.
+ • In the export: (:!)(type (:/))
+ Suggested fix: Remove the ‘type’ keyword
+
=====================================
testsuite/tests/rename/should_fail/T12488a_foo.hs
=====================================
@@ -0,0 +1,9 @@
+{-# LANGUAGE ExplicitNamespaces #-}
+{-# LANGUAGE TypeFamilies #-}
+module T12488a_foo ( T (type A) ) where
+
+data T = A
+
+class Foo a where
+ type A a
+ foo :: a -> Int
=====================================
testsuite/tests/rename/should_fail/T12488a_foo.stderr
=====================================
@@ -0,0 +1,6 @@
+T12488a_foo.hs:3:22: error: [GHC-11592]
+ • The data type ‘T’ defines a child named ‘A’,
+ but it is not in the type namespace.
+ • In the export: T(type A)
+ Suggested fix: Remove the ‘type’ keyword
+
=====================================
testsuite/tests/rename/should_fail/T12488e.hs
=====================================
@@ -0,0 +1,12 @@
+{-# LANGUAGE ExplicitNamespaces #-}
+{-# LANGUAGE TypeFamilies #-}
+module T12488e
+ ( C (data A)
+ , D (data (+++))
+ ) where
+
+class C a where
+ type A a
+
+class D a where
+ type (+++) a
\ No newline at end of file
=====================================
testsuite/tests/rename/should_fail/T12488e.stderr
=====================================
@@ -0,0 +1,12 @@
+T12488e.hs:4:5: error: [GHC-11592]
+ • The class ‘C’ defines a child named ‘A’,
+ but it is not in the data namespace.
+ • In the export: C(data A)
+ Suggested fix: Remove the ‘data’ keyword
+
+T12488e.hs:5:5: error: [GHC-11592]
+ • The class ‘D’ defines a child named ‘+++’,
+ but it is not in the data namespace.
+ • In the export: D(data (+++))
+ Suggested fix: Remove the ‘data’ keyword
+
=====================================
testsuite/tests/rename/should_fail/T12488g.hs
=====================================
@@ -0,0 +1,10 @@
+{-# LANGUAGE ExplicitNamespaces #-}
+{-# LANGUAGE TypeFamilies #-}
+module T12488g
+ ( C (data (+++),
+ type (++-))
+ ) where
+
+class C a where
+ type (+++) a
+ (++-) :: a -> a
=====================================
testsuite/tests/rename/should_fail/T12488g.stderr
=====================================
@@ -0,0 +1,16 @@
+T12488g.hs:4:5: error: [GHC-11592]
+ • The class ‘C’ defines a child named ‘++-’,
+ but it is not in the type namespace.
+ • In the export: C(data (+++), type (++-))
+ Suggested fixes:
+ • Remove the ‘type’ keyword
+ • Perhaps use ‘+++’ (Defined at T12488g.hs:9:3)
+
+T12488g.hs:4:5: error: [GHC-11592]
+ • The class ‘C’ defines a child named ‘+++’,
+ but it is not in the data namespace.
+ • In the export: C(data (+++), type (++-))
+ Suggested fixes:
+ • Remove the ‘data’ keyword
+ • Perhaps use ‘++-’ (Defined at T12488g.hs:10:3)
+
=====================================
testsuite/tests/rename/should_fail/T25899e2.stderr
=====================================
@@ -1,4 +1,6 @@
-T25899e2.hs:5:5: error: [GHC-76037]
- • Not in scope: data constructor ‘MkT’
+T25899e2.hs:5:5: error: [GHC-11592]
+ • The data type ‘T’ defines a child named ‘MkT’,
+ but it is not in the data namespace.
• In the export: type T(data MkT)
+ Suggested fix: Remove the ‘data’ keyword
=====================================
testsuite/tests/rename/should_fail/all.T
=====================================
@@ -246,3 +246,7 @@ test('T25899e1', normal, compile_fail, [''])
test('T25899e2', normal, compile_fail, [''])
test('T25899e3', [extra_files(['T25899e_helper.hs'])], multimod_compile_fail, ['T25899e3', '-v0'])
test('T25899f', [extra_files(['T25899f_helper.hs'])], multimod_compile_fail, ['T25899f', '-v0'])
+test('T12488a', normal, compile_fail, [''])
+test('T12488a_foo', normal, compile_fail, [''])
+test('T12488e', normal, compile_fail, [''])
+test('T12488g', normal, compile_fail, [''])
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5618645b5860bf65546108e578a7ebf…
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/5618645b5860bf65546108e578a7ebf…
You're receiving this email because of your account on gitlab.haskell.org.
1
0