Florian Ragwitz pushed to branch wip/rafl/meaningful-main-return at Glasgow Haskell Compiler / GHC Commits: f9b6b8cb by Florian Ragwitz at 2026-10-10T10:22:56-07:00 Does this introduce the allocations? - - - - - 1 changed file: - compiler/GHC/Tc/Module.hs Changes: ===================================== compiler/GHC/Tc/Module.hs ===================================== @@ -1975,12 +1975,10 @@ 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) <- setMainCtxt main_name io_ty $ - tcCheckMonoExpr main_expr_rn io_ty + ; ((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 -- See Note [Root-main Id] -- Construct the binding @@ -1995,9 +1993,7 @@ 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)) $ - mkHsDictLet ev_binds main_expr + ; rhs = nlHsApp (mkLHsWrap co (nlHsVar run_main_id)) main_action ; main_bind = mkVarBind root_main_id rhs } ; return (tcg_env { tcg_main = Just main_name @@ -2007,12 +2003,9 @@ 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...). -- @@ -2048,7 +2041,10 @@ generateMainBinding tcg_env main_name = do -- An amendment to the original proposal to this effect has been submitted at -- https://github.com/ghc-proposals/ghc-proposals/pull/771. handleMainReturn :: Name -> TcType -> TcEvBinds -> LHsExpr GhcTc -> TcM (LHsExpr GhcTc) -handleMainReturn main_name res_ty ev_binds main_expr = do +handleMainReturn _main_name _res_ty ev_binds main_expr = do + pure (mkHsDictLet ev_binds main_expr) + +{- meaningful_main <- xoptM LangExt.MeaningfulMainReturn void_ty <- mkTyConTy <$> tcLookupKnownOccTyCon voidTyConOcc exit_code_ty <- mkTyConTy <$> tcLookupKnownOccTyCon exitCodeTyConOcc View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f9b6b8cb6638edc464fda235c0f51284... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f9b6b8cb6638edc464fda235c0f51284... 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