Skip to content

Make the runtime reflection API for names, modules, locations more systematic

Currently in base we have

  • GHC.SrcLoc: the data type SrcLoc contains srcLocPackage and srcLocModule
  • Data.Typeable.Internals: the data type TyCon contains tyConPackage, tyConModule and tyConName.
  • GHC.Generics: the data type Datatype contains dataTypePackage, dataTypeModule and dataTypeName
  • Data.Data: the data type DataType (yes the capitalisation differs!) contains a field tycon :: String, and there are functions tyconModule :: String -> String, and tyconUQname :: String -> String, for parsing that string and extracting the module name and tycon name.
  • GHC.StaticPtr: the data type StaticPtrInfo contains spInfoPackageKey, spInfoModuleName, spInfoName (all Strings). Oh, and spInfoSrcLoc :: (Int,Int) too!
  • GHC.Stack.ccSrcSpan :: Ptr CostCentre -> IO CString stores a source location in a C structure, and returns it as a CString.

This is madness! Six different representations for the same information in one package!

Let's fix this by defining some shared data types, for

  • Module = ModuleName + package
  • Entity = Module + unqualified name

There would be a tiresome changeover period; but Typeable and StaticPtr are in flux anyway.

Would anyone be willing to lead on this?

Edited by Simon Peyton Jones
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information