-newtype TickEnv = TickEnv { locals :: OccEnv Id }
-
-data TM a = TM { unTM :: TickEnv -> TickTransState -> (a,TickTransState) }
+type FreeVars = OccEnv Id
+noFVs = emptyOccEnv
+
+-- Note [freevars]
+-- For breakpoints we want to collect the free variables of an
+-- expression for pinning on the HsTick. We don't want to collect
+-- *all* free variables though: in particular there's no point pinning
+-- on free variables that are will otherwise be in scope at the GHCi
+-- prompt, which means all top-level bindings. Unfortunately detecting
+-- top-level bindings isn't easy (collectHsBindsBinders on the top-level
+-- bindings doesn't do it), so we keep track of a set of "in-scope"
+-- variables in addition to the free variables, and the former is used
+-- to filter additions to the latter. This gives us complete control
+-- over what free variables we track.
+
+data TM a = TM { unTM :: TickTransState -> (a,FreeVars,TickTransState) }
+ -- a combination of a state monad (TickTransState) and a writer
+ -- monad (FreeVars).