<div dir="ltr"><div><div><span style="font-family:monospace">Hello,</span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace">I'm trying to understand how to query information about `Var`s from a</span></div><div><span style="font-family:monospace"></span></div><span 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>```<font size="2"><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</font><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></div><div><span style="font-family:monospace">4. When I see the binder $trModule, that it is added by GHC and has type `GHC.Types.Module`?</span></div><div><span 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></div><div><span style="font-family:monospace">7. In general, is there a page that tells me how to 'query' Core/`ModGuts` from within a core plugin?<br></span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace">Pointers on how to get this information is much appreciated. Also, pointers on <br></span></div><div><span style="font-family:monospace">"learning how to learn" --- that is, how I could have figured this out on my own /</span></div><div><span style="font-family:monospace">RTFMing better are also very appreciated!<br></span></div><div><span style="font-family:monospace"><br></span></div><div><span style="font-family:monospace">Thanks a lot,</span></div><div><span style="font-family:monospace">~Siddharth<br></span></div><div><span style="font-family:monospace"></span></div><div><span style="font-family:monospace"><br>-- <br></span><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><span style="font-family:monospace"><a href="https://bollu.github.io/" target="_blank">https://bollu.github.io/</a><br></span></div></div></div></div>