@@ -36,29 +36,36 @@ fputState field x = fmodifyState field (const x)
3636fmodifyState :: MonadState s m => Field s a -> (a -> a) -> m ()
3737fmodifyState field f = modify $ fmodify field f
3838
39+-- Until now, we'd have just ad-hoc empty lists and Falses thrown around
40+-- whenever a new instance of a record was to be created.
41+--
42+-- This class formalises the notion of an initial value for a record.
3943class InitialValue a where
4044 initialValue :: a
4145
46+-- Exact-name context lookup; uses the initial value if needed.
4247ctxt_lookupExact :: InitialValue a => Name -> Field (Ctxt a) a
4348ctxt_lookupExact n = Field
4449 { fget = fromMaybe initialValue . lookupCtxtExact n
4550 , fset = addDef n
4651 }
4752
53+
4854-----------------------------------
4955-- Individual records and fields --
5056-----------------------------------
5157
58+
59+-- OptInfo
60+----------
61+
5262instance InitialValue OptInfo where
5363 initialValue = Optimise [] False
5464
55−-- raw context, probably won't be used much
56−ist_optimisation_ctxt :: Field IState (Ctxt OptInfo)
57−ist_optimisation_ctxt = Field idris_optimisation (\v ist -> ist{ idris_optimisation = v })
58−
59−-- the optimisation record for the given name
65+-- the optimisation record for the given (exact) name
6066ist_optimisation :: Name -> Field IState OptInfo
61−ist_optimisation n = ctxt_lookupExact n . ist_optimisation_ctxt
67+ist_optimisation n = ctxt_lookupExact n
68+ . Field idris_optimisation (\v ist -> ist{ idris_optimisation = v })
6269
6370-- two fields of the optimisation record
6471opt_inaccessible :: Field OptInfo [(Int, Name)]
@@ -66,3 +73,19 @@ opt_inaccessible = Field inaccessible (\v opt -> opt{ inaccessible = v })
6673
6774opt_detaggable :: Field OptInfo Bool
6875opt_detaggable = Field detaggable (\v opt -> opt{ detaggable = v })
76+
77+
78+-- CGInfo
79+---------
80+
81+instance InitialValue CGInfo where
82+ initialValue = CGInfo [] [] [] [] []
83+
84+-- callgraph record for the given (exact) name
85+ist_callgraph :: Name -> Field IState CGInfo
86+ist_callgraph n = ctxt_lookupExact n
87+ . Field idris_callgraph (\v ist -> ist{ idris_callgraph = v })
88+
89+-- some fields of the CGInfo record
90+cg_usedpos :: Field CGInfo [(Int, [UsageReason])]
91+cg_usedpos = Field usedpos (\v cg -> cg{ usedpos = v })