[Git][ghc/ghc][wip/rafl/meaningful-main-return] Does this reduce allocations?
Florian Ragwitz pushed to branch wip/rafl/meaningful-main-return at Glasgow Haskell Compiler / GHC Commits: 0d680170 by Florian Ragwitz at 2026-10-10T01:37:24-07:00 Does this reduce allocations? - - - - - 1 changed file: - compiler/GHC/Tc/Module.hs Changes: ===================================== compiler/GHC/Tc/Module.hs ===================================== @@ -100,7 +100,7 @@ import GHC.Iface.Decl ( coAxiomToIfaceDecl ) import GHC.Iface.Env ( externaliseName ) import GHC.Iface.Load -import GHC.Builtin.WiredIn.Types ( mkListTy, anyTypeOfKind, unitTy ) +import GHC.Builtin.WiredIn.Types ( mkListTy, anyTypeOfKind {- , unitTy -} ) import GHC.Builtin.Modules( mAIN_NAME, gHC_PRIM, rOOT_MAIN, isWiredInOnlyModule ) import GHC.Builtin.KnownKeys import GHC.Builtin.KnownOccs @@ -124,7 +124,7 @@ import GHC.Core.TyCo.Tidy( tidyTopType ) import GHC.Core.FamInstEnv ( FamInst, pprFamInst, famInstsRepTyCons, orphNamesOfFamInst , famInstEnvElts, extendFamInstEnvList, normaliseType ) -import GHC.Core.Unify ( tcUnifyTy ) +-- import GHC.Core.Unify ( tcUnifyTy ) import GHC.Parser.Header ( mkImplicitImports, mkUnresolvedImport ) @@ -1975,10 +1975,12 @@ generateMainBinding tcg_env main_name = do main_expr_rn = L (noAnnSrcSpan loc) (mkHsVar (L (noAnnSrcSpan loc) main_name)) -- Solve the constraints arising from checking `main` before deciding how -- to handle its result. - ; ((ev_binds, main_expr), main_wanteds) <- captureTopConstraints $ - setMainCtxt main_name io_ty $ tcCheckMonoExpr main_expr_rn io_ty - ; main_ev_binds <- simplifyTop main_wanteds - ; main_action <- handleMainReturn main_name res_ty ev_binds main_expr + -- ; ((ev_binds, main_expr), main_wanteds) <- captureTopConstraints $ + -- setMainCtxt main_name io_ty $ tcCheckMonoExpr main_expr_rn io_ty + -- ; main_ev_binds <- simplifyTop main_wanteds + -- ; main_action <- handleMainReturn main_name res_ty ev_binds main_expr + ; (ev_binds, main_expr) <- setMainCtxt main_name io_ty $ + tcCheckMonoExpr main_expr_rn io_ty -- See Note [Root-main Id] -- Construct the binding @@ -1993,7 +1995,9 @@ generateMainBinding tcg_env main_name = do -- type errors when type of `main` is not `IO a`. The `ev_binds` -- must be put inside `runMainIO` to ensure the deferred type -- error can be emitted correctly. See #13838. - ; rhs = nlHsApp (mkLHsWrap co (nlHsVar run_main_id)) main_action + -- ; rhs = nlHsApp (mkLHsWrap co (nlHsVar run_main_id)) main_action + ; rhs = nlHsApp (mkLHsWrap co (nlHsVar run_main_id)) $ + mkHsDictLet ev_binds main_expr ; main_bind = mkVarBind root_main_id rhs } ; return (tcg_env { tcg_main = Just main_name @@ -2003,9 +2007,12 @@ generateMainBinding tcg_env main_name = do `plusDU` usesOnly (unitFN main_name) } -- Record the use of 'main', so that we don't -- complain about it being defined but not used - `addEvBinds` main_ev_binds) + -- `addEvBinds` main_ev_binds) + ) } +{- + -- Implement GHC proposal #631 -- (https://github.com/ghc-proposals/ghc-proposals/blob/master/proposals/0631-ma...). -- @@ -2072,6 +2079,8 @@ handleMainReturn main_name res_ty ev_binds main_expr = do nlHsTyApps bind_io_id [exit_code_ty, exit_code_ty] [ main_action, nlHsTyApp exit_with_id [exit_code_ty] ] +-} + getIOType :: TcM (TcType, TcType) -- Return (IO alpha, alpha) for fresh alpha getIOType = do { ioTyCon <- tcLookupKnownKeyTyCon ioTyConKey View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0d6801704e2fdf448ab3337f76d30f3c... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/0d6801704e2fdf448ab3337f76d30f3c... You're receiving this email because of your account on gitlab.haskell.org. Manage all notifications: https://gitlab.haskell.org/-/profile/notifications | Help: https://gitlab.haskell.org/help
participants (1)
-
Florian Ragwitz (@rafl)