commercialhaskell / hi-file-parser

Other
4 stars 4 forks source link

High-level description of what this library can be used for #26

Open jonkri opened 4 days ago

jonkri commented 4 days ago

I would like to suggest adding a high-level description about what this library can be used for.

I stumbled across this library looking for ways to analyze dependencies for my master's thesis.

I was expecting the library to produce a values corresponding to ghc --show-iface test.hi:

$ ghc --show-iface test.hi
Magic: Wanted 33214052,
       got    33214052
Version: Wanted 9066,
         got    9066
Way: Wanted ,
     got    
interface Data.Concurrent.Deque.Class 9066
  interface hash: be971b31955dd661cabd925ab557ee3a
  ABI hash: 53431666a9e0035a90ee821c63b7f152
  export-list hash: dbaff94797bb83b4aed4669580629100
  orphan hash: 693e9af84d3dfcc71e640e005bdc5e2e
  flag hash: c3846b4283ecb1cc5cffb857aa6c4d82
  opt_hash: 8b9adcef8b10eb72a908d73c2f903e52
  hpc_hash: 93b885adfe0da089cdf634904fd59f71
  plugin_hash: ad164012d6b1e14942349d58b1132007
  src_hash: fc500b810c9f56c642955aebde6ec75d
  sig of: Nothing
  used TH splices: False
  where
exports:
  Bound
  BoundedL{newBoundedQ tryPushL}
  BoundedR{tryPushR}
  ConcDeque
  ConcQueue
  D
  Deque
  DequeClass{leftThreadSafe newQ nullQ pushL rightThreadSafe tryPopR}
  DoubleEnd
  Dup
  Grow
  NT
  Nonthreadsafe
  PopL{tryPopL}
  PushR{pushR}
  Queue
  S
  Safe
  SingleEnd
  T
  Threadsafe
  WSDeque
direct module dependencies:
boot module dependencies:
direct package dependencies: base-4.18.2.1
plugin package dependencies:
trusted package dependencies: base-4.18.2.1
orphans: GHC.Base GHC.Float GHC.Prim.Ext
family instance modules: Control.Applicative Control.Arrow
                         Data.Functor.Const Data.Functor.Identity Data.Monoid
                         Data.Semigroup.Internal Data.Type.Ord GHC.Generics GHC.IO.Exception
                         GHC.RTS.Flags
import  -/  Prelude a1ae76d73d35cc0683dc06ee0b1f4dc2
import  -/  GHC.Types 40ada155ed73681c14b0e90149f6df94
addDependentFile "/Users/jonkri/.ghcup/ghc/9.6.6/lib/ghc-9.6.6/lib/../lib/aarch64-osx-ghc-9.6.6/rts-1.0.2/include/ghcversion.h" ed2abc0c378d044c7bbfd76a73a209e2
addDependentFile "/Volumes/Expansion/Haskell Packages/abstract-deque-0.3/dist-newstyle/build/aarch64-osx/ghc-9.6.6/abstract-deque-0.3/build/autogen/cabal_macros.h" 29dac48165758e24a27306fc1a7b6df8
b345c6a6298974352ce769ab9542a88e
  $tcBound :: GHC.Types.TyCon
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TyCon],
   Unfolding: Core: <vanilla>
              GHC.Types.TyCon
                5734071326913657733#Word64
                4788318159271753176#Word64
                $trModule
                $tcBound1
                0#
                GHC.Types.krep$*]
104ca42a1c7ed85a94158f5ed5b5210f
  $tcBound1 :: GHC.Types.TrName
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TrNameS],
   Unfolding: Core: <vanilla> GHC.Types.TrNameS $tcBound2]
559dc58567626bb7fbafd35c27c81e97
  $tcBound2 :: GHC.Prim.Addr#
  [HasNoCafRefs, LambdaFormInfo: LFUnlifted,
   Unfolding: Core: <vanilla> "Bound"#]
f07d00e78a3746dffd78e236bff48e12
  $tcBoundedL :: GHC.Types.TyCon
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TyCon],
   Unfolding: Core: <vanilla>
              GHC.Types.TyCon
                11243194520786696648#Word64
                4366407566199655600#Word64
                $trModule
                $tcBoundedL2
                0#
                $tcBoundedL1]
f0bab67c48eda22a4b8c55ce786d7a84
  $tcBoundedL1 :: GHC.Types.KindRep
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.KindRepFun], Inline: [~]]
90c1ac73623f5184c338f12a6c3a176d
  $tcBoundedL2 :: GHC.Types.TrName
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TrNameS],
   Unfolding: Core: <vanilla> GHC.Types.TrNameS $tcBoundedL3]
734c747c2d27bf4b5edff2466d5fe7df
  $tcBoundedL3 :: GHC.Prim.Addr#
  [HasNoCafRefs, LambdaFormInfo: LFUnlifted,
   Unfolding: Core: <vanilla> "BoundedL"#]
2177584d7754584fb707e6c2f6b97197
  $tcBoundedR :: GHC.Types.TyCon
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TyCon],
   Unfolding: Core: <vanilla>
              GHC.Types.TyCon
                4792522472785116984#Word64
                4689197699989819450#Word64
                $trModule
                $tcBoundedR1
                0#
                $tcBoundedL1]
4da33d75b94ddd8eeb041ab275856ffc
  $tcBoundedR1 :: GHC.Types.TrName
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TrNameS],
   Unfolding: Core: <vanilla> GHC.Types.TrNameS $tcBoundedR2]
ca8984a6d4ee52777bcb76896771d9f4
  $tcBoundedR2 :: GHC.Prim.Addr#
  [HasNoCafRefs, LambdaFormInfo: LFUnlifted,
   Unfolding: Core: <vanilla> "BoundedR"#]
774ea540193fcfa8ee3274867a05b057
  $tcDequeClass :: GHC.Types.TyCon
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TyCon],
   Unfolding: Core: <vanilla>
              GHC.Types.TyCon
                6287588905979801470#Word64
                16381463954667868489#Word64
                $trModule
                $tcDequeClass1
                0#
                $tcBoundedL1]
378b67ff11c257700a0f126d8e498398
  $tcDequeClass1 :: GHC.Types.TrName
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TrNameS],
   Unfolding: Core: <vanilla> GHC.Types.TrNameS $tcDequeClass2]
15e2b76eee0ca75469e9532c764d5e7e
  $tcDequeClass2 :: GHC.Prim.Addr#
  [HasNoCafRefs, LambdaFormInfo: LFUnlifted,
   Unfolding: Core: <vanilla> "DequeClass"#]
c4c309699e093ec0d5cfc8b46d8de2aa
  $tcDoubleEnd :: GHC.Types.TyCon
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TyCon],
   Unfolding: Core: <vanilla>
              GHC.Types.TyCon
                3529270782748119212#Word64
                6370034893458136113#Word64
                $trModule
                $tcDoubleEnd1
                0#
                GHC.Types.krep$*]
8d0ee7f954b7264d573ec0d89a4d7c39
  $tcDoubleEnd1 :: GHC.Types.TrName
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TrNameS],
   Unfolding: Core: <vanilla> GHC.Types.TrNameS $tcDoubleEnd2]
7cf63dd2ccbad738d8e0f59f8c576fca
  $tcDoubleEnd2 :: GHC.Prim.Addr#
  [HasNoCafRefs, LambdaFormInfo: LFUnlifted,
   Unfolding: Core: <vanilla> "DoubleEnd"#]
57bcd59fb241bdf813bd68122a3a0700
  $tcDup :: GHC.Types.TyCon
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TyCon],
   Unfolding: Core: <vanilla>
              GHC.Types.TyCon
                17538640860398841291#Word64
                4205238906443669901#Word64
                $trModule
                $tcDup1
                0#
                GHC.Types.krep$*]
4542dd6dd10176b14a39d8950b43fe3c
  $tcDup1 :: GHC.Types.TrName
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TrNameS],
   Unfolding: Core: <vanilla> GHC.Types.TrNameS $tcDup2]
81d15a41a5047abf2357b54e15cca6ea
  $tcDup2 :: GHC.Prim.Addr#
  [HasNoCafRefs, LambdaFormInfo: LFUnlifted,
   Unfolding: Core: <vanilla> "Dup"#]
8f528ed4a5b2819a144c2eb7f8135386
  $tcGrow :: GHC.Types.TyCon
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TyCon],
   Unfolding: Core: <vanilla>
              GHC.Types.TyCon
                5378586785421157705#Word64
                9954235479088698070#Word64
                $trModule
                $tcGrow1
                0#
                GHC.Types.krep$*]
4fef22ea99aae57c54f3ee2aa21ca44e
  $tcGrow1 :: GHC.Types.TrName
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TrNameS],
   Unfolding: Core: <vanilla> GHC.Types.TrNameS $tcGrow2]
e2aeb9af9bf15ae657e09e95796cd90c
  $tcGrow2 :: GHC.Prim.Addr#
  [HasNoCafRefs, LambdaFormInfo: LFUnlifted,
   Unfolding: Core: <vanilla> "Grow"#]
5cf87ceb5fe7d880141d412b6fb7e648
  $tcNonthreadsafe :: GHC.Types.TyCon
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TyCon],
   Unfolding: Core: <vanilla>
              GHC.Types.TyCon
                7096824407508871734#Word64
                11458768877643464331#Word64
                $trModule
                $tcNonthreadsafe1
                0#
                GHC.Types.krep$*]
6522fd9236f29f7470956107f7ae2e66
  $tcNonthreadsafe1 :: GHC.Types.TrName
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TrNameS],
   Unfolding: Core: <vanilla> GHC.Types.TrNameS $tcNonthreadsafe2]
8e3095194183297ad1099e3586f30bb8
  $tcNonthreadsafe2 :: GHC.Prim.Addr#
  [HasNoCafRefs, LambdaFormInfo: LFUnlifted,
   Unfolding: Core: <vanilla> "Nonthreadsafe"#]
53e88e69adf0226e7552774fcba3e87f
  $tcPopL :: GHC.Types.TyCon
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TyCon],
   Unfolding: Core: <vanilla>
              GHC.Types.TyCon
                1519910768257850892#Word64
                13880225080780079668#Word64
                $trModule
                $tcPopL1
                0#
                $tcBoundedL1]
b17495e153f4815f2ce3623c3f73a5fa
  $tcPopL1 :: GHC.Types.TrName
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TrNameS],
   Unfolding: Core: <vanilla> GHC.Types.TrNameS $tcPopL2]
c3bce0fd828a4e09d955c046e74463ae
  $tcPopL2 :: GHC.Prim.Addr#
  [HasNoCafRefs, LambdaFormInfo: LFUnlifted,
   Unfolding: Core: <vanilla> "PopL"#]
bdc9b00301d941d89cc835180475cc76
  $tcPushR :: GHC.Types.TyCon
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TyCon],
   Unfolding: Core: <vanilla>
              GHC.Types.TyCon
                1834854257007875960#Word64
                16666075753449422765#Word64
                $trModule
                $tcPushR1
                0#
                $tcBoundedL1]
a1b2d9dfc96919ce635601ea84a22f55
  $tcPushR1 :: GHC.Types.TrName
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TrNameS],
   Unfolding: Core: <vanilla> GHC.Types.TrNameS $tcPushR2]
b774ae85e29f30a1f1482dd10d9411dd
  $tcPushR2 :: GHC.Prim.Addr#
  [HasNoCafRefs, LambdaFormInfo: LFUnlifted,
   Unfolding: Core: <vanilla> "PushR"#]
9ed4c249d00cb7c41354652facdd8cd5
  $tcSafe :: GHC.Types.TyCon
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TyCon],
   Unfolding: Core: <vanilla>
              GHC.Types.TyCon
                10378679389160556332#Word64
                8644305233640533668#Word64
                $trModule
                $tcSafe1
                0#
                GHC.Types.krep$*]
4e88c2da7ee9bc4e68a0589c9c4a8b1b
  $tcSafe1 :: GHC.Types.TrName
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TrNameS],
   Unfolding: Core: <vanilla> GHC.Types.TrNameS $tcSafe2]
77bdae5d11dddfd2ed8e256399845685
  $tcSafe2 :: GHC.Prim.Addr#
  [HasNoCafRefs, LambdaFormInfo: LFUnlifted,
   Unfolding: Core: <vanilla> "Safe"#]
e676344e9f436f96758b1f8d19ca5507
  $tcSingleEnd :: GHC.Types.TyCon
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TyCon],
   Unfolding: Core: <vanilla>
              GHC.Types.TyCon
                10500215133324993602#Word64
                1877488317525303136#Word64
                $trModule
                $tcSingleEnd1
                0#
                GHC.Types.krep$*]
d51c0bbf02ea3b6f2358ec1da7a52cca
  $tcSingleEnd1 :: GHC.Types.TrName
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TrNameS],
   Unfolding: Core: <vanilla> GHC.Types.TrNameS $tcSingleEnd2]
a96252ab6e782bf5ff1b81b383001726
  $tcSingleEnd2 :: GHC.Prim.Addr#
  [HasNoCafRefs, LambdaFormInfo: LFUnlifted,
   Unfolding: Core: <vanilla> "SingleEnd"#]
a8d485f02f01b0632d93aee762c951d1
  $tcThreadsafe :: GHC.Types.TyCon
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TyCon],
   Unfolding: Core: <vanilla>
              GHC.Types.TyCon
                4399462646111817201#Word64
                7840761921392964001#Word64
                $trModule
                $tcThreadsafe1
                0#
                GHC.Types.krep$*]
79a989ea0bf372f9126593851a034c1d
  $tcThreadsafe1 :: GHC.Types.TrName
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TrNameS],
   Unfolding: Core: <vanilla> GHC.Types.TrNameS $tcThreadsafe2]
54b9b8b19d912a17b298d50a3aa2ebbb
  $tcThreadsafe2 :: GHC.Prim.Addr#
  [HasNoCafRefs, LambdaFormInfo: LFUnlifted,
   Unfolding: Core: <vanilla> "Threadsafe"#]
4cc2c0925ba1cdc26687ef31c1779ed0
  $trModule :: GHC.Types.Module
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.Module],
   Unfolding: Core: <vanilla> GHC.Types.Module $trModule3 $trModule1]
adac544bef412e1855e3c60108364f8d
  $trModule1 :: GHC.Types.TrName
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TrNameS],
   Unfolding: Core: <vanilla> GHC.Types.TrNameS $trModule2]
dd7becdb8a011b0372899e7a4b89c756
  $trModule2 :: GHC.Prim.Addr#
  [HasNoCafRefs, LambdaFormInfo: LFUnlifted,
   Unfolding: Core: <vanilla> "Data.Concurrent.Deque.Class"#]
05f0637980a4f7767e74b602234e2804
  $trModule3 :: GHC.Types.TrName
  [HasNoCafRefs, TagSig: <TagProper>,
   LambdaFormInfo: LFCon[GHC.Types.TrNameS],
   Unfolding: Core: <vanilla> GHC.Types.TrNameS $trModule4]
62de8bb5cb18f63954381190c99952c2
  $trModule4 :: GHC.Prim.Addr#
  [HasNoCafRefs, LambdaFormInfo: LFUnlifted,
   Unfolding: Core: <vanilla> "abstract-deque-0.3-inplace"#]
f43e3ccaf66db3394d342a0407085647
  type Bound :: *
  data Bound
fe6b2de7720555c4afe5dfe3127f87ce
  type BoundedL :: (* -> *) -> GHC.Types.Constraint
  class DequeClass d => BoundedL d where
    newBoundedQ :: GHC.Types.Int -> GHC.Types.IO (d elt)
    tryPushL :: d elt -> elt -> GHC.Types.IO GHC.Types.Bool
    {-# MINIMAL newBoundedQ, tryPushL #-}
41364fef8a86b4c0bfe5df2aa5f0bed3
  type BoundedR :: (* -> *) -> GHC.Types.Constraint
  class PushR d => BoundedR d where
    tryPushR :: d elt -> elt -> GHC.Types.IO GHC.Types.Bool
    {-# MINIMAL tryPushR #-}
a5a1201381b35a97c313de93ad0e5795
  type ConcDeque :: * -> *
  type ConcDeque a =
    Deque Threadsafe Threadsafe DoubleEnd DoubleEnd Grow Safe a
08eeb5fb883920aed5ae97a8c66f5ea4
  type ConcQueue :: * -> *
  type ConcQueue a =
    Deque Threadsafe Threadsafe SingleEnd SingleEnd Grow Safe a
256d37523a2482462e29bce5d48d26fe
  type D :: *
  type D = DoubleEnd
b1e482b7845cb8e7d401ab298ae152ca
  type Deque :: * -> * -> * -> * -> * -> * -> * -> *
  type family Deque lThreaded rThreaded lDbl rDbl bnd safe elt open
0d688a46da5065b87e1a23d2712cd21a
  type DequeClass :: (* -> *) -> GHC.Types.Constraint
  class DequeClass d where
    newQ :: GHC.Types.IO (d elt)
    nullQ :: d elt -> GHC.Types.IO GHC.Types.Bool
    pushL :: d elt -> elt -> GHC.Types.IO ()
    tryPopR :: d elt -> GHC.Types.IO (GHC.Maybe.Maybe elt)
    leftThreadSafe :: d elt -> GHC.Types.Bool
    rightThreadSafe :: d elt -> GHC.Types.Bool
    {-# MINIMAL newQ, nullQ, pushL, tryPopR, leftThreadSafe,
                rightThreadSafe #-}
41ca3b0769bc38bd312953fcc7e23345
  type DoubleEnd :: *
  data DoubleEnd
3d56547d14eaf06af8418f88ab75ed43
  type Dup :: *
  data Dup
80152b168cc387f92056cb348859bb3f
  type Grow :: *
  data Grow
a2d937cc15c15f63a7d87468363369cc
  type NT :: *
  type NT = Nonthreadsafe
0cb38eb942aff99d66005f43ca812835
  type Nonthreadsafe :: *
  data Nonthreadsafe
de2149eadd19dd0a6a9b837cd8782f51
  type PopL :: (* -> *) -> GHC.Types.Constraint
  class DequeClass d => PopL d where
    tryPopL :: d elt -> GHC.Types.IO (GHC.Maybe.Maybe elt)
    {-# MINIMAL tryPopL #-}
514df478a6e811573fa9a630dca0208a
  type PushR :: (* -> *) -> GHC.Types.Constraint
  class DequeClass d => PushR d where
    pushR :: d elt -> elt -> GHC.Types.IO ()
    {-# MINIMAL pushR #-}
d0732a1cbcd6d01dc46b27a284e43e66
  type Queue :: * -> *
  type Queue a =
    Deque Nonthreadsafe Nonthreadsafe SingleEnd SingleEnd Grow Safe a
9851bbbf6ba3e24dfe12f6309a9cd633
  type S :: *
  type S = SingleEnd
663cb12d435139b629f377d08be750f9
  type Safe :: *
  data Safe
eb2c289059f17ceca82b122e19d2e275
  type SingleEnd :: *
  data SingleEnd
358a20e66dee71dd4215e472776ca2f7
  type T :: *
  type T = Threadsafe
28b3fd1078ae36ff04f582d8422f38dd
  type Threadsafe :: *
  data Threadsafe
101795ee63946e49aba637f5ab563e58
  type WSDeque :: * -> *
  type WSDeque a =
    Deque Nonthreadsafe Threadsafe DoubleEnd SingleEnd Grow Safe a
trusted: safe-inferred
require own pkg trusted: False
docs:
  Nothing
extensible fields:

Instead, I got this:

Usage
["/Users/jonkri/.ghcup/ghc/9.6.6/lib/ghc-9.6.6/lib/../lib/aarch64-osx-ghc-9.6.6/rts-1.0.2/include/ghcversion.h","/Volumes/Expansion/Haskell Packages/abstract-deque-0.3/dist-newstyle/build/aarch64-osx/ghc-9.6.6/abstract-deque-0.3/build/autogen/cabal_macros.h"]
Dependencies
Dependencies {dmods = [], dpkgs = [("base",True)], dorphs = ["GHC.Base","GHC.Float","GHC.Prim.Ext"], dfinsts = ["Control.Applicative","Control.Arrow","Data.Functor.Const","Data.Functor.Identity","Data.Monoid","Data.Semigroup.Internal","Data.Type.Ord","GHC.Generics","GHC.IO.Exception","GHC.RTS.Flags"], dplugins = []}

The package and module in question is abstract-deque-0.3 and Data.Concurrent.Deque.Class.

Am I doing something wrong? Is there a way to use this library to parse additional details from the .hi files?

Thanks!

mpilgrem commented 4 days ago

@jonkri, I'll improve the package's documentation.

In advance of that, this package was spun out of the Stack project. Stack needs certain information (only) from GHC's *.hi files (which can vary in format from one version of GHC to another; GHC makes no promises in that regard) and also needs to work with different versions of GHC (so it can't be built against a single ghc package version). It also needs the information faster than GHC's --show-iface can provide.

The ghc package has module GHC.Iface.Load (and GHC.Iface.Load.readIface) if you are looking for GHC-version specific functionality.

In principle, this package could be extended to provide other information, in addition to what Stack itself needs. However, as Stack is dependent on it, that would need to be done carefully, so as not to break Stack.