Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User-curated list of functions in scope #6

Open
isovector opened this issue Sep 29, 2020 · 3 comments
Open

User-curated list of functions in scope #6

isovector opened this issue Sep 29, 2020 · 3 comments

Comments

@isovector
Copy link
Owner

Let users decide which functions are in scope when running auto.

Maybe we could use a module level annotation with TH names?

@isovector
Copy link
Owner Author

from bgamari:

{-# LANGUAGE CPP #-}
module Plugin where

#if MIN_VERSION_ghc(9,0,0)
import GHC.Tc.Utils.Monad
import GHC.ThToHs (convertToHsExpr)
import GHC.Types.Basic (Origin(..))
import GHC.Utils.Error (MsgDoc)
#elif MIN_VERSION_ghc(8,10,0)
import TcRnMonad as GHC.Tc.Utils.Monad
import GHC.ThToHs (convertToHsExpr)
import RnEnv (lookupOccRn)
import Plugins (Plugin)
import BasicTypes (Origin(..))
import ErrUtils (MsgDoc)
import TcEnv (tcLookupId)
import Annotations
#endif

import GHC
import Language.Haskell.TH.Syntax as TH

resolveTHName :: TypecheckedModule -> TH.Name -> RealSrcSpan -> Ghc (Maybe Id)
resolveTHName tcm th_name src_span = do
  hsc_env <- getSession
  let (gbl_env, _) = tm_internals_ tcm
  (msgs, mb_id) <- liftIO $ GHC.Tc.Utils.Monad.initTcWithGbl hsc_env gbl_env src_span $ do
    Right rdr <- pure $ cvtName FromSource undefined th_name
    name <- lookupOccRn (unLoc rdr)
    tcLookupId (unLoc name)
  return mb_id

cvtName :: Origin -> SrcSpan -> TH.Name -> Either MsgDoc (Located GHC.RdrName)
cvtName origin span v =
  fmap (f . unLoc) (convertToHsExpr origin span (VarE v))
    where
      f (HsVar _ v') = v'
      f _ = error "this shouldn't happen"

@googleson78
Copy link

googleson78 commented Nov 2, 2020

Inspiration could also be taken from Tritlos work - e.g. writing names in holes (this is also how you "add names to scope" for Agdas auto)?

Also this mr - https://gitlab.haskell.org/ghc/ghc/-/merge_requests/1766, which is unfortunately not ready yet.

@Tritlo
Copy link

Tritlo commented Oct 6, 2021

Inspiration could also be taken from Tritlos work - e.g. writing names in holes (this is also how you "add names to scope" for Agdas auto)?

Also this mr - https://gitlab.haskell.org/ghc/ghc/-/merge_requests/1766, which is unfortunately not ready yet.

Yes! Unfortunately, that MR requires a change in syntax, which means going through the whole GHC proposal process first. Though I've since worked on hole-fit plugins and now have a running use case, so I'll pick this thread up again soon!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants