<html><head><meta http-equiv="Content-Type" content="text/html; charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class=""><div class=""><div></div><div><br class=""><blockquote type="cite" class=""><div class="">On Apr 11, 2019, at 11:06 PM, Brandon Allbery <<a href="mailto:allbery.b@gmail.com" class="">allbery.b@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">You might need to enable optimization for RULES to get picked up at all.</div><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div class="gmail_quote" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div dir="ltr" class="gmail_attr">On Thu, Apr 11, 2019 at 11:03 PM Bill Hallahan <<a href="mailto:william.hallahan@yale.edu" class="">william.hallahan@yale.edu</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;">Hi,<br class=""><br class="">I'm trying to use the GHC API (8.2.2) to extract the rewrite rules from a module, but have run into some difficulties.  I've written the following code (all code is also attached as files):<br class=""><br class="">   <span class="Apple-converted-space"> </span>module Main where<br class=""><br class="">   <span class="Apple-converted-space"> </span>import GHC<br class="">   <span class="Apple-converted-space"> </span>import GHC.Paths<br class="">   <span class="Apple-converted-space"> </span>import HscTypes<br class=""><br class="">   <span class="Apple-converted-space"> </span>main :: IO ()<br class="">   <span class="Apple-converted-space"> </span>main = do<br class="">       <span class="Apple-converted-space"> </span>loadProj "Test.hs"<br class=""><br class="">   <span class="Apple-converted-space"> </span>loadProj :: FilePath -> IO ()<br class="">   <span class="Apple-converted-space"> </span>loadProj src = do<br class="">       <span class="Apple-converted-space"> </span>modgutss <- runGhc (Just libdir) $ do<br class="">           <span class="Apple-converted-space"> </span>flags <- getSessionDynFlags<br class="">           <span class="Apple-converted-space"> </span>_ <- setSessionDynFlags flags<br class=""><br class="">           <span class="Apple-converted-space"> </span>target <- guessTarget src Nothing<br class="">           <span class="Apple-converted-space"> </span>_ <- setTargets [target]<br class="">           <span class="Apple-converted-space"> </span>_ <- load LoadAllTargets<br class=""><br class="">           <span class="Apple-converted-space"> </span>mod_graph <- getModuleGraph<br class="">           <span class="Apple-converted-space"> </span>parsed_mods <- mapM parseModule mod_graph<br class="">           <span class="Apple-converted-space"> </span>typed_mods <- mapM typecheckModule parsed_mods<br class="">           <span class="Apple-converted-space"> </span>desug_mods <- mapM desugarModule typed_mods<br class=""><br class="">           <span class="Apple-converted-space"> </span>return $ map coreModule desug_mods<br class=""><br class="">       <span class="Apple-converted-space"> </span>let rules = map (\mg -> ( moduleNameString . moduleName $ mg_module mg<br class="">                               <span class="Apple-converted-space"> </span>, length $ mg_rules mg)<br class="">                       <span class="Apple-converted-space"> </span>) modgutss<br class="">       <span class="Apple-converted-space"> </span>print $ rules<br class=""><br class="">       <span class="Apple-converted-space"> </span>return ()<br class=""><br class="">It loads Test.hs (see below my signature) which contains a single rewrite rule.  Then, it obtains the ModGuts, and prints a tuple of the name of the module, and the length of the rule list.  I would expect this to be ("Test", 1), but, in fact, what gets printed is ("Test", 0).  For some reason, the ModGuts does not have the rewrite rule from the file.<br class=""><br class="">I'm guessing I'm misunderstanding something about how the GHC API works.  If anyone has any advice about how to fix this code to load rewrite rules (or even where to begin looking) I would appreciate it!<br class=""><br class="">Thanks,<br class="">Bill Hallahan<br class=""><br class="">Test.hs:<br class="">   <span class="Apple-converted-space"> </span>module Test where<br class=""><br class="">   <span class="Apple-converted-space"> </span>import Prelude hiding (map)<br class=""><br class="">   <span class="Apple-converted-space"> </span>map :: (a -> b) -> [a] -> [b]<br class="">   <span class="Apple-converted-space"> </span>map f (x:xs) = f x:map f xs<br class="">   <span class="Apple-converted-space"> </span>map _ [] = []<br class="">   <span class="Apple-converted-space"> </span>{-# NOINLINE [0] map #-}<br class=""><br class="">   <span class="Apple-converted-space"> </span>{-# RULES<br class="">     "map/map"   forall f g xs . map f (map g xs) = map (f . g) xs<br class="">     <span class="Apple-converted-space"> </span>#-}<br class="">_______________________________________________<br class="">ghc-devs mailing list<br class=""><a href="mailto:ghc-devs@haskell.org" target="_blank" class="">ghc-devs@haskell.org</a><br class=""><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank" class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br class=""></blockquote></div><br clear="all" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><br class=""></div><span style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none; float: none; display: inline !important;" class="">--<span class="Apple-converted-space"> </span></span><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div dir="ltr" class="gmail_signature" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class="">brandon s allbery kf8nh</div><div class=""><a href="mailto:allbery.b@gmail.com" target="_blank" class="">allbery.b@gmail.com</a></div></div></div></div></div></div></blockquote></div><br class=""></div></div></body></html>