Inspecting function arguments in GHCi

Simon Peyton Jones simonpj at microsoft.com
Mon Jan 25 12:22:47 UTC 2021


Andrew

We have very poor documentation of the inner workings of the entire breakpoint
and debugging mechanism.   And very few (zero?) people who truly understand it.

You could do a great service by starting a Note or a wiki page or something
that lays out the moving parts.  You may not feel that you are well equipped to
do so, but you'd almost certainly improve matters!

Has anyone else been working in this space.  Matthew P perhaps?

|  So I'm wondering where would be a good place in the pipeline to
|  transform patterns like these into at-patterns, to give them Id's.

I'm not sure what you have in mind. Could you say more about (a) what you'd like
the user experience to be, and (b) how you are considering implementing it.

|  However, the breakpoint logic only looks at the free variables of the
|  right-hand sides and not transitively, which means that e.g. in the
|  following example neither ':print arg1' nor ':print as' works when the
|  interpreter hits a breakpoint in the top level expression on the RHS:
 
Perhaps you are suggesting that each breakpoint should capture bindings for
*all in-scope variables* rather than *all free variable of the sub-expression".
If so, that sounds pretty feasible.  It might risk keeping variables alive
that would otherwise have been garbage-collected, but maybe that's a price
worth paying.

Simon


|  -----Original Message-----
|  From: ghc-devs <ghc-devs-bounces at haskell.org> On Behalf Of Andrew
|  Kvapil
|  Sent: 25 January 2021 11:06
|  To: ghc-devs at haskell.org
|  Subject: Inspecting function arguments in GHCi
|  
|  Hello,
|  
|  I'm interested in inspecting the strictness of functions at runtime
|  and the depth of thunks "in the wild." For this reason I'm modifying
|  GHC 8.10.2, essentially to add additional information to breakpoints.
|  I'd like to reuse the logic behind GHCi's :print command
|  (pprintClosureCommand, obtainTermFromId, ...) for which I suppose I
|  need Id's. Those however don't exist for destructuring patterns, such
|  as those in the following equations:
|  
|       last [x] = x
|       last (_:xs) = last xs
|  
|  So I'm wondering where would be a good place in the pipeline to
|  transform patterns like these into at-patterns, to give them Id's.
|  However, the breakpoint logic only looks at the free variables of the
|  right-hand sides and not transitively, which means that e.g. in the
|  following example neither ':print arg1' nor ':print as' works when the
|  interpreter hits a breakpoint in the top level expression on the RHS:
|  
|       qsort arg1@(a:as) = qsort left ++ [a] ++ qsort right
|         where (left, right) = (filter (<=a) as, filter (>a) as)
|  
|  Thus I'd also like to know how to extend the free var logic for
|  Tickish that eventually leads to CgBreakInfo and :print's ability to
|  inspect these bindings at runtime. My goal would be to determine to
|  what extent was a thunk evaluated during function application.
|  
|  Any advice would be greatly appreciated!
|  
|  Regards,
|  Andrew Kvapil
|  _______________________________________________
|  ghc-devs mailing list
|  ghc-devs at haskell.org
|  https://nam06.safelinks.protection.outlook.com/?url=http%3A%2F%2Fmail.
|  haskell.org%2Fcgi-bin%2Fmailman%2Flistinfo%2Fghc-
|  devs&data=04%7C01%7Csimonpj%40microsoft.com%7C329b12ba7bb74a2657d2
|  08d8c1213bcc%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637471695782
|  207814%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJ
|  BTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C1000&sdata=uAi4NmjQLj3QG3B7ton5GeFDy
|  IWJecxtXoXiTIP11tE%3D&reserved=0


More information about the ghc-devs mailing list