[Git][ghc/ghc][wip/fendor/one-shot-no-eps] Port Matt's version of the type env handling
Hannes Siebenhandl pushed to branch wip/fendor/one-shot-no-eps at Glasgow Haskell Compiler / GHC Commits: f52db864 by Hannes Siebenhandl at 2026-11-30T17:46:49+01:00 Port Matt's version of the type env handling - - - - - 8 changed files: - compiler/GHC/Driver/Main/Compile.hs-boot - compiler/GHC/HsToCore/Monad.hs - compiler/GHC/Iface/Load.hs - compiler/GHC/IfaceToCore.hs - compiler/GHC/IfaceToCore.hs-boot - compiler/GHC/Tc/Types.hs - compiler/GHC/Tc/Utils/Monad.hs - compiler/GHC/Unit/Home/PackageTable.hs Changes: ===================================== compiler/GHC/Driver/Main/Compile.hs-boot ===================================== @@ -1,7 +1,7 @@ module GHC.Driver.Main.Compile where import GHC.Driver.Env.Types (HscEnv) -import GHC.Linker.Types (Linkable) +import GHC.Linker.Types (Linkable, LinkableWith, ModuleByteCode) import GHC.Prelude.Basic import GHC.Types.TypeEnv (TypeEnv) import GHC.Unit.Module.Location (ModLocation) @@ -16,6 +16,13 @@ loadIfaceByteCode :: TypeEnv -> Maybe (IO Linkable) +loadIfaceByteCodeLazy :: + HscEnv -> + ModIface -> + ModLocation -> + TypeEnv -> + IO (Maybe (LinkableWith ModuleByteCode)) + data CgInteractiveGuts mkCgInteractiveGuts :: CgGuts -> CgInteractiveGuts @@ -24,4 +31,4 @@ generateFreshByteCodeLinkable :: HscEnv -> ModuleName -> CgInteractiveGuts -> ModLocation - -> IO Linkable \ No newline at end of file + -> IO Linkable ===================================== compiler/GHC/HsToCore/Monad.hs ===================================== @@ -560,10 +560,15 @@ mkDsEnvs unit_env mod rdr_env type_env fam_inst_env tcm_plugins ptc msg_var -- of all the interactive modules. -- See Note [Why is KnotVars not a ModuleEnv] - knot_var_fun :: Module -> Maybe (IfG TypeEnv) + knot_var_fun :: Module -> Maybe (IfG TypeEnv, TypeEnv -> IfG ()) knot_var_fun that_mod - | that_mod == mod || isInteractiveModule mod = Just (return type_env) - | otherwise = Nothing + | that_mod == mod || isInteractiveModule mod = + Just + ( return type_env + , panic "mkDsEnvs:knotVars: attempting to write to type env variable" + ) + | otherwise = + Nothing if_lenv = mkIfLclEnv mod (text "GHC error in desugarer lookup in" <+> ppr mod) NotBoot ===================================== compiler/GHC/Iface/Load.hs ===================================== @@ -37,6 +37,7 @@ module GHC.Iface.Load ( flagsToIfCompression, moduleFreeHolesPrecise, needWiredInHomeIface, loadWiredInHomeIface, + lookupInKnotVars, WhereFrom(..), ModuleLookupScope(..), @@ -56,17 +57,19 @@ import GHC.Data.FastString (fastStringToShortText) import {-# SOURCE #-} GHC.IfaceToCore ( tcIfaceDecls, tcIfaceRules, tcIfaceInst, tcIfaceFamInst - , tcIfaceAnnotations, tcIfaceCompleteMatches, tcIfaceDefaults) + , tcIfaceAnnotations, tcIfaceCompleteMatches, tcIfaceDefaults + , typecheckIface + ) import GHC.Hs.Extension (GhcPass) import GHC.Hs.Doc +import {-# SOURCE #-} GHC.Driver.Main.Compile (loadIfaceByteCodeLazy) import GHC.Driver.DynFlags import GHC.Driver.Env import GHC.Driver.Env.KnotVars import GHC.Driver.Errors.Types import GHC.Driver.Hooks -import {-# source #-} GHC.Driver.Main.Compile (loadIfaceByteCode) import GHC.Driver.Plugins import GHC.Iface.Warnings @@ -100,7 +103,6 @@ import GHC.Builtin.PrimOps.Ids import GHC.Builtin.WiredIn.Prim import GHC.Builtin.WiredIn.Ids( seqId ) -import GHC.Core (CoreRule) import GHC.Core.FamInstEnv import GHC.Core.InstEnv import GHC.Core.Rules @@ -110,7 +112,6 @@ import GHC.Parser.Annotation (noAnn, noLocA) import GHC.Types.Annotations import GHC.Types.Avail -import GHC.Types.DefaultEnv (DefaultEnv) import GHC.Types.Fixity import GHC.Types.Fixity.Env import GHC.Types.Id @@ -135,9 +136,8 @@ import GHC.Unit.External import GHC.Unit.Finder import GHC.Unit.Home import GHC.Unit.Home.Graph qualified as HUG -import GHC.Unit.Home.ModInfo (HomeModInfo (..), emptyHomeModInfoLinkable) +import GHC.Unit.Home.ModInfo (HomeModInfo (..), HomeModLinkable (..)) import GHC.Unit.Home.PackageTable -import GHC.Unit.Home.PackageTable qualified as HomePackageTable import GHC.Unit.Module import GHC.Unit.Module.Deps import GHC.Unit.Module.Graph @@ -151,7 +151,6 @@ import GHC.Data.Maybe import Language.Haskell.Syntax.Lit (StringLiteral(..)) -import Control.Applicative ((<|>)) import Control.Monad import Data.Foldable qualified as Foldable import Data.Function ((&)) @@ -392,24 +391,14 @@ loadGlobalName :: forall lcl. -> Module -- Use this for non-External Names (maybe Backpack-related?) -> IfM lcl (MaybeErr IfaceMessage TyThing) -- Only works for External Names that have a Module -loadGlobalName name mod +loadGlobalName name _mod = do { env <- getGblEnv - ; case lookupKnotVars (if_rec_types env) mod of - -- Note [Tying the knot] - Just get_type_env - -> do -- It's defined in a module in the hs-boot loop - { type_env <- setLclEnv () get_type_env -- yuk - ; traceIf (text "loadGlobalName1" <+> ppr name) - ; case lookupNameEnv type_env name of - Just thing -> do { traceIf (text "loadGlobalName2" <+> ppr thing) - ; return (Succeeded thing) } - -- See Note [Knot-tying fallback on boot] - Nothing -> do { traceIf (text "loadGlobalName3" <+> ppr name) - ; via_external } - } - - _ -> do { traceIf (text "loadGlobalName4" <+> ppr name $$ ppr (if_rec_types env) $$ text "stack" <+> callStackDoc) - ; via_external } } + ; res <- lookupInKnotVars name + ; case res of + Just thing -> pure $ Succeeded thing + Nothing -> + do { traceIf (text "loadGlobalName4" <+> ppr name $$ ppr (if_rec_types env) $$ text "stack" <+> callStackDoc) + ; via_external } } where via_external = do { hsc_env <- getTopEnv ; mb_thing <- liftIO (lookupType hsc_env name) @@ -417,6 +406,19 @@ loadGlobalName name mod Just thing -> return (Succeeded thing) Nothing -> importDecl name } +lookupInKnotVars :: Name -> IfM lcl (Maybe TyThing) +lookupInKnotVars name = do + env <- getGblEnv + case lookupKnotVars (if_rec_types env) =<< (nameModule_maybe name) of -- Note [Tying the knot] + Just (get_type_env, _) -> do + -- It's defined in a module in the hs-boot loop + type_env <- setLclEnv () get_type_env -- yuk + case lookupNameEnv type_env name of + Just thing -> pure (Just thing) + -- See Note [Knot-tying fallback on boot] + Nothing -> pure Nothing + Nothing -> pure Nothing + -- Note [Tying the knot] -- ~~~~~~~~~~~~~~~~~~~~~ -- The if_rec_types field is used when we are compiling M.hs, which indirectly @@ -511,7 +513,10 @@ importDecl name do { logger <- getLogger ; liftIO $ trace_if logger nd_doc - -- Load the interface, which should populate the PTE + -- Load the interface, which will end up in one of three places. + -- 1. KnotVar + -- 2. HPT + -- 3. PTE ; mb_iface <- assertPpr (isExternalName name) (ppr name) $ loadInterface nd_doc (nameModule name) ImportBySystem ; case mb_iface of @@ -520,13 +525,18 @@ importDecl name ; Succeeded _ -> do -- Now look it up again; this time we should find it - { eps <- getEps -- @fendor: DONE - ; mb_home_thing <- queryHpt (`HomePackageTable.hptLookupLoadedType` name) - ; case mb_home_thing <|> lookupTypeEnv (eps_PTE eps) name of + { res <- lookupInKnotVars name + ; case res of Just thing -> return $ Succeeded thing - Nothing -> return $ Failed $ - Can'tFindNameInInterface name - (filter is_interesting $ nonDetNameEnvElts $ eps_PTE eps) + Nothing -> do + hsc_env <- getTopEnv + eps <- getEps + res <- liftIO $ lookupType hsc_env name + case res of + Just thing -> return $ Succeeded thing + Nothing -> return $ Failed $ + Can'tFindNameInInterface name + (filter is_interesting $ nonDetNameEnvElts $ eps_PTE eps) }}} where nd_doc = text "Need decl for" <+> ppr name @@ -834,8 +844,29 @@ loadInterface doc_str mod from then do -- TODO @fendor: document that we don't want/need 'dontLeakTheHUG' here massertPpr (moduleUnitId mod `Set.member` hsc_all_home_unit_ids hsc_env) (text "Attempting to load non-home package interface into the Home Loader State" $$ ppr (HUG.allUnits $ hsc_HUG hsc_env) $$ doc_str $$ ppr mod $$ ppr (moduleUnitId mod)) - tcParts <- tcPartsOfTheIface mod iface - addModIfacePartsToHpt gbl_env mod loc iface tcParts + hsc_env <- getTopEnv + let + bad_boot = mi_boot iface == IsBoot + && isJust (lookupKnotVars (if_rec_types gbl_env) mod) + -- Warn against an HPT-updating import + -- of one's own boot file! (one-shot only) + -- See Note [Loading your own hi-boot file] + + final_iface = stripLoadedIface "home package table" iface + + warnPprTrace bad_boot "loadInterface" (ppr mod) $ do + hpt <- getHpt + if bad_boot + then + initIfaceLcl (mi_semantic_module iface) (text (ml_hi_file loc)) (mi_boot iface) $ do + loadHiBootSelf iface + else do + details <- liftIfG $ typecheckIface iface + mb_object <- liftIO $ findObjectLinkableMaybe (mi_module iface) loc + mb_bytecode <- liftIO $ loadIfaceByteCodeLazy hsc_env iface loc (md_types details) + let hm_linkable = HomeModLinkable mb_bytecode mb_object + + liftIO $ addOnDemandHomeModule hpt (HomeModInfo final_iface details hm_linkable) else dontLeakTheHUG $ do -- Load the new ModIface into the External Package State -- @@ -856,8 +887,7 @@ loadInterface doc_str mod from massertPpr (moduleUnitId mod `Set.notMember` hsc_all_home_unit_ids hsc_env) (text "Attempting to load home package interface into the EPS" $$ ppr (HUG.allUnits $ hsc_HUG hsc_env) $$ doc_str $$ ppr mod $$ ppr (moduleUnitId mod)) - tcParts <- tcPartsOfTheIface mod iface - addModIfacePartsToEps mod iface tcParts + addModIfacePartsToEps mod iface ; -- invoke plugins with *full* interface, not final_iface, to ensure -- that plugins have access to declarations, etc. @@ -865,8 +895,25 @@ loadInterface doc_str mod from ; return (Succeeded res) }}}} -tcPartsOfTheIface :: Module -> ModIface -> IfL ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], CompleteMatches) -tcPartsOfTheIface mod iface = do +loadHiBootSelf :: ModIface -> IfL () +loadHiBootSelf iface + = do { env <- getGblEnv + ; ignore_prags <- goptM Opt_IgnoreInterfacePragmas + ; new_eps_decls <- tcIfaceDecls ignore_prags (mi_decls iface) + ; case lookupKnotVars (if_rec_types env) (mi_module iface) of + Just (get_types, write_types) -> liftIfG $ do + ty_env <- get_types + write_types (addDeclsToPTE ty_env new_eps_decls) + Nothing -> pprPanic "Could not load self-boot" (ppr (mi_module iface)) + } + +liftIfG :: IfG a -> IfM lcl a +liftIfG x = setLclEnv () x + +addModIfacePartsToEps :: Module -> ModIface -> IfL () +addModIfacePartsToEps mod iface = do + purged_hsc_env <- getTopEnv + ignore_prags <- goptM Opt_IgnoreInterfacePragmas new_decls <- tcIfaceDecls ignore_prags (mi_decls iface) new_insts <- mapM tcIfaceInst (mi_insts iface) @@ -875,50 +922,6 @@ tcPartsOfTheIface mod iface = do new_rules <- tcIfaceRules ignore_prags (mi_rules iface) new_anns <- tcIfaceAnnotations (mi_anns iface) new_complete_matches <- tcIfaceCompleteMatches (mi_complete_matches iface) - pure - ( new_decls - , new_insts - , new_defaults - , new_fam_insts - , new_rules - , new_anns - , new_complete_matches - ) - -addModIfacePartsToHpt :: IfGblEnv -> Module -> ModLocation -> ModIface -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], [CompleteMatch]) -> IfL () -addModIfacePartsToHpt gbl_env mod loc iface (new_decls, new_insts, new_defaults, new_fam_insts, new_rules, new_anns, new_complete_matches) = do - hsc_env <- getTopEnv - let - details = ModDetails - { md_types = mkNameEnv new_decls - , md_exports = mi_exports iface - , md_defaults = new_defaults - , md_insts = mkInstEnv new_insts - , md_fam_insts = new_fam_insts - , md_rules = new_rules - , md_anns = new_anns - , md_complete_matches = new_complete_matches - } - - bad_boot = mi_boot iface == IsBoot - && isJust (lookupKnotVars (if_rec_types gbl_env) mod) - -- Warn against an HPT-updating import - -- of one's own boot file! (one-shot only) - -- See Note [Loading your own hi-boot file] - - mb_bytecode = loadIfaceByteCode hsc_env iface loc (md_types details) - - final_iface = stripLoadedIface "home package table" iface - - warnPprTrace bad_boot "loadInterface" (ppr mod) $ do - hpt <- getHpt - liftIO $ if bad_boot - then hptAddOwnBootTypes hpt new_decls - else addOnDemandHomeModule hpt (HomeModInfo final_iface details emptyHomeModInfoLinkable) mb_bytecode - -addModIfacePartsToEps :: Module -> ModIface -> ([(Name, TyThing)], [ClsInst], DefaultEnv, [FamInst], [CoreRule], [Annotation], [CompleteMatch]) -> IfL () -addModIfacePartsToEps mod iface (new_decls, new_insts, new_defaults, new_fam_insts, new_rules, new_anns, new_complete_matches) = do - purged_hsc_env <- getTopEnv let final_iface = stripLoadedIface "PIT" iface ===================================== compiler/GHC/IfaceToCore.hs ===================================== @@ -2044,7 +2044,7 @@ tcUnfoldingRhs is_compulsory toplvl name expr get_in_scope = do { (gbl_env, lcl_env) <- getEnvs ; let type_envs = knotVarElems (if_rec_types gbl_env) - ; top_level_vars <- concat <$> mapM (fmap typeEnvIds . setLclEnv ()) type_envs + ; top_level_vars <- concat <$> mapM (fmap typeEnvIds . setLclEnv () . fst) type_envs ; return (bindingsVars (if_tv_env lcl_env) `unionVarSet` bindingsVars (if_id_env lcl_env) `unionVarSet` mkVarSet top_level_vars) } ===================================== compiler/GHC/IfaceToCore.hs-boot ===================================== @@ -4,7 +4,7 @@ import GHC.Prelude import GHC.Iface.Syntax ( IfaceDecl, IfaceDefault, IfaceClsInst, IfaceFamInst, IfaceRule , IfaceAnnotation, IfaceCompleteMatch ) import GHC.Types.TyThing ( TyThing ) -import GHC.Tc.Types ( IfL ) +import GHC.Tc.Types ( IfL, IfG ) import GHC.Core.InstEnv ( ClsInst ) import GHC.Core.FamInstEnv ( FamInst ) import GHC.Core ( CoreRule ) @@ -13,6 +13,8 @@ import GHC.Types.Annotations ( Annotation ) import GHC.Types.DefaultEnv ( DefaultEnv ) import GHC.Types.Name import GHC.Unit.Types ( Module ) +import GHC.Unit.Module.ModIface ( ModIface ) +import GHC.Unit.Module.ModDetails ( ModDetails ) import GHC.Fingerprint.Type @@ -24,3 +26,5 @@ tcIfaceFamInst :: IfaceFamInst -> IfL FamInst tcIfaceAnnotations :: [IfaceAnnotation] -> IfL [Annotation] tcIfaceCompleteMatches :: [IfaceCompleteMatch] -> IfL CompleteMatches tcIfaceDecls :: Bool -> [(Fingerprint, IfaceDecl)] -> IfL [(Name,TyThing)] + +typecheckIface :: ModIface -> IfG ModDetails ===================================== compiler/GHC/Tc/Types.hs ===================================== @@ -400,7 +400,11 @@ data IfGblEnv -- We need the module name so we can test when it's appropriate -- to look in this env. -- See Note [Tying the knot] in GHC.IfaceToCore - if_rec_types :: KnotVars (IfG TypeEnv) + if_rec_types :: (KnotVars (IfG TypeEnv, TypeEnv -> IfG ())) + -- The variable is mostly used for reading but + -- there is one case it is written to from loadIface. + -- Note [Loading own hi-boot file] + -- -- Allows a read effect, so it can be in a mutable -- variable; c.f. handling the external package type env } ===================================== compiler/GHC/Tc/Utils/Monad.hs ===================================== @@ -2589,7 +2589,7 @@ initIfaceTcRn thing_inside if_env = IfGblEnv { if_doc = text "initIfaceTcRn" , if_rec_types = if is_instantiate then emptyKnotVars - else readTcRef <$> knot_vars } + else mkTypeEnvLens <$> knot_vars } ; setEnvs (if_env, ()) thing_inside } @@ -2610,7 +2610,7 @@ initIfaceLoadModule :: HscEnv -> Module -> IfG a -> IO a initIfaceLoadModule hsc_env this_mod do_this = do let gbl_env = IfGblEnv { if_doc = text "initIfaceLoadModule", - if_rec_types = readTcRef <$> knotVarsWithout this_mod (hsc_type_env_vars hsc_env) + if_rec_types = mkTypeEnvLens <$> knotVarsWithout this_mod (hsc_type_env_vars hsc_env) } initTcRnIf IfaceTag hsc_env gbl_env () do_this @@ -2620,7 +2620,7 @@ initIfaceCheck :: SDoc -> HscEnv -> IfG a -> IO a initIfaceCheck doc hsc_env do_this = do let gbl_env = IfGblEnv { if_doc = text "initIfaceCheck" <+> doc, - if_rec_types = readTcRef <$> hsc_type_env_vars hsc_env + if_rec_types = mkTypeEnvLens <$> hsc_type_env_vars hsc_env } initTcRnIf IfaceTag hsc_env gbl_env () do_this @@ -2638,6 +2638,9 @@ initIfaceLclWithSubst mod loc_doc hi_boot_file nsubst thing_inside getIfModule :: IfL Module getIfModule = do { env <- getLclEnv; return (if_mod env) } +mkTypeEnvLens :: IORef TypeEnv -> (IfG TypeEnv, TypeEnv -> IfG ()) +mkTypeEnvLens ref = (readTcRef ref, writeTcRef ref) + -------------------- failIfM :: HasDebugCallStack => SDoc -> IfL a -- The Iface monad doesn't have a place to accumulate errors, so we ===================================== compiler/GHC/Unit/Home/PackageTable.hs ===================================== @@ -42,7 +42,6 @@ module GHC.Unit.Home.PackageTable , addHomeModInfoToHpt , addHomeModInfosToHpt , addOnDemandHomeModule - , hptAddOwnBootTypes -- * Restrict the HPT , restrictHpt @@ -120,7 +119,6 @@ import GHC.Unit.Module.ModDetails import GHC.Unit.Module.ModIface import GHC.Utils.Outputable import GHC.Types.Name -import GHC.Types.Name.Env (extendNameEnvList) -- | Helps us find information about modules in the home package data HomePackageTable @@ -157,7 +155,6 @@ data HomeLoaderState = HomeLoaderState { hls_table :: DModuleNameEnv HomeModInfo , hls_indices :: !LoaderIndices , hls_is_boot :: InstalledModuleEnv ModuleNameWithIsBoot - , hls_boot_type_env :: !TypeEnv , hls_iface_bytecode :: !(ModuleEnv (IO Linkable)) , hls_stats :: !HptStats } @@ -196,7 +193,6 @@ emptyHomeLoaderState = { hls_table = emptyUDFM , hls_indices = emptyLoaderIndices , hls_is_boot = emptyInstalledModuleEnv - , hls_boot_type_env = emptyTypeEnv , hls_iface_bytecode = emptyModuleEnv , hls_stats = emptyHptStats } @@ -252,13 +248,13 @@ hptLoadedIsBoot = queryOnDemandHpt emptyInstalledModuleEnv hls_is_boot hptLookupLoadedType :: HomePackageTable -> Name -> IO (Maybe TyThing) hptLookupLoadedType HPT_Make{} _ = pure Nothing -hptLookupLoadedType hpt@HPT_OneShot{loader} name = do +hptLookupLoadedType hpt@HPT_OneShot{} name = do mb_hmi <- case nameModule_maybe name of Just modl -> lookupHptByModule hpt modl Nothing -> pure Nothing case mb_hmi of Just hmi -> pure $! lookupTypeEnv (md_types (hm_details hmi)) name - Nothing -> (`lookupTypeEnv` name) . hls_boot_type_env <$> readIORef loader + Nothing -> pure Nothing hptLoadedModFamInsts :: HomePackageTable -> Module -> IO (Maybe FamInstEnv) hptLoadedModFamInsts HPT_Make{} _ = pure Nothing @@ -386,24 +382,14 @@ restrictHpt HPT_OneShot{} _ = pure () addListToHpt :: HomePackageTable -> [(ModuleName, HomeModInfo)] -> IO () addListToHpt hpt = mapM_ (uncurry (addToHpt hpt)) -addOnDemandHomeModule :: HomePackageTable -> HomeModInfo -> Maybe (IO Linkable) -> IO () -addOnDemandHomeModule hpt@HPT_Make{} hmi _ = addHomeModInfoToHpt hmi hpt -addOnDemandHomeModule HPT_OneShot{loader} hmi mb_bytecode = +addOnDemandHomeModule :: HomePackageTable -> HomeModInfo -> IO () +addOnDemandHomeModule hpt@HPT_Make{} hmi = addHomeModInfoToHpt hmi hpt +addOnDemandHomeModule HPT_OneShot{loader} hmi = atomicModifyIORef' loader $ \hls -> - let hls' = insertLoadedHomeModInfo (moduleName modl) hmi hls - in ( case mb_bytecode of - Nothing -> hls' - Just action -> hls' { hls_iface_bytecode = extendModuleEnv (hls_iface_bytecode hls') modl action } - , () ) + (insertLoadedHomeModInfo (moduleName modl) hmi hls , () ) where modl = mi_module (hm_iface hmi) -hptAddOwnBootTypes :: HomePackageTable -> [(Name, TyThing)] -> IO () -hptAddOwnBootTypes HPT_Make{} _ = pure () -hptAddOwnBootTypes HPT_OneShot{loader} decls = - atomicModifyIORef' loader $ \hls -> - (hls { hls_boot_type_env = extendNameEnvList (hls_boot_type_env hls) decls }, ()) - hptSetBootInfo :: HomePackageTable -> InstalledModuleEnv ModuleNameWithIsBoot -> IO () hptSetBootInfo HPT_Make{} _ = pure () hptSetBootInfo HPT_OneShot{loader} is_boot_env = View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f52db86488813bd0ed62fce3e2f44eed... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/f52db86488813bd0ed62fce3e2f44eed... 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)
-
Hannes Siebenhandl (@fendor)