<!DOCTYPE html><html><head><title></title><style type="text/css">p.MsoNormal,p.MsoNoSpacing{margin:0}</style></head><body><div>I think some of what you want can be had from the Name type, and it seems you can get a Name from a Var with varName. See <a href="https://hackage.haskell.org/package/ghc-8.10.1/docs/Name.html#g:3">https://hackage.haskell.org/package/ghc-8.10.1/docs/Name.html#g:3</a> for some things that Names contain. For the type of a Var it seems you could use varType (<a href="https://hackage.haskell.org/package/ghc-8.10.1/docs/Var.html#v:varType">https://hackage.haskell.org/package/ghc-8.10.1/docs/Var.html#v:varType</a>).<br></div><div><br></div><div>I really recommend looking at the Haddocks, that's how I figured out what to do with Name's etc.<br></div><div><br></div><div id="sig22230037"><div>Adam Sandberg Eriksson<br></div></div><div><br></div><div><br></div><div>On Mon, 13 Jul 2020, at 19:24, Siddharth Bhat wrote:<br></div><blockquote type="cite" id="qt" style=""><div dir="ltr"><div><div><span style=""><span class="font" style="font-family:monospace;">Hello,</span></span><br></div><div><span style=""><span class="font" style="font-family:monospace;"></span></span><br></div><div><span style=""><span class="font" style="font-family:monospace;">I'm trying to understand how to query information about `Var`s from a</span></span><br></div><div><span style=""><span class="font" style="font-family:monospace;"></span></span><br></div><div><span style=""><span class="font" style="font-family:monospace;">Core plugin. Consider the snippet of haskell:<br><br>```<br>{-# LANGUAGE MagicHash #-}<br>import GHC.Prim<br>fib :: Int# -> Int#<br>fib i = case i of 0# ->  i; 1# ->  i; _ ->  (fib i) +# (fib (i -# 1#))<br>main :: IO (); main = let x = fib 10# in return ()<br>```<br><br>That compiles to the following (elided) GHC Core, dumped right after desugar:<br><br>```<span class="size" style="font-size:13px;"><br>Rec {<br>fib [Occ=LoopBreaker] :: Int# -> Int#<br>[LclId]<br>fib<br>  = ...<br>end Rec }<br><br>Main.$trModule :: GHC.Types.Module<br>[LclIdX]<br>Main.$trModule<br>  = GHC.Types.Module<br>      (GHC.Types.TrNameS "main"#) (GHC.Types.TrNameS "Main"#)<br><br>-- RHS size: {terms: 7, types: 3, coercions: 0, joins: 0/0}<br>main :: IO ()<br>[LclIdX]<br>main<br>  = case fib 10# of { __DEFAULT -><br>    return @ IO GHC.Base.$fMonadIO @ () GHC.Tuple.()<br>    }<br><br>-- RHS size: {terms: 2, types: 1, coercions: 0, joins: 0/0}<br>:Main.main :: IO ()<br>[LclIdX]<br>:Main.main = GHC.TopHandler.runMainIO @ () main</span><br>```<br><br>I've been  using `occNameString . getOccName` to manipulate names of `Var`s from the Core<br>module. I'm rapidly finding this insufficient, and want more information<br>about a variable. In particular, How to I figure out:<br><br>1. When I see the Var with occurence name `fib`, that it belongs to module `Main`?<br>2. When I see the Var with name `main`, whether it is `Main.main` or `:Main.main`?<br>3. When I see the Var with name `+#`, that this is an inbuilt name? Similarly<br>   for `-#` and `()`.</span></span></div></div><div><span style=""><span class="font" style="font-family:monospace;">4. When I see the binder $trModule, that it is added by GHC and has type `GHC.Types.Module`?</span></span><br></div><div><span style=""><span class="font" style="font-family:monospace;">5. In general, given a Var, how do I decide where it comes from, and whether it is<br>   user-defined or something GHC defined ('wired-in' I believe is the term I am<br>   looking for)?<br>6. When I see a `Var`, how do I learn its type?</span></span></div><div><span style=""><span class="font" style="font-family:monospace;">7. In general, is there a page that tells me how to 'query' Core/`ModGuts` from within a core plugin?</span></span><br></div><div><span style=""><span class="font" style="font-family:monospace;"></span></span><br></div><div><span style=""><span class="font" style="font-family:monospace;">Pointers on how to get this information is much appreciated. Also, pointers on </span></span><br></div><div><span style=""><span class="font" style="font-family:monospace;">"learning how to learn" --- that is, how I could have figured this out on my own /</span></span><br></div><div><span style=""><span class="font" style="font-family:monospace;">RTFMing better are also very appreciated!</span></span><br></div><div><span style=""><span class="font" style="font-family:monospace;"></span></span><br></div><div><span style=""><span class="font" style="font-family:monospace;">Thanks a lot,</span></span><br></div><div><span style=""><span class="font" style="font-family:monospace;">~Siddharth</span></span><br></div><div><span style=""><span class="font" style="font-family:monospace;"></span></span><br></div><div><div><span style=""><span class="font" style="font-family:monospace;"><br>-- <br></span></span></div><div dir="ltr" class="qt-gmail_signature"><div dir="ltr"><span style=""><span class="font" style="font-family:monospace;"><a href="https://bollu.github.io/" target="_blank">https://bollu.github.io/</a></span></span><br></div></div></div></div><div>_______________________________________________<br></div><div>ghc-devs mailing list<br></div><div><a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br></div><div><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br></div><div><br></div></blockquote><div><br></div></body></html>