[Git][ghc/ghc][wip/torsten.schmits/persistent-worker-test-2024-09-10] compiler: implement --show-iface-abi-hash major mode

Torsten Schmits (@torsten.schmits) gitlab at gitlab.haskell.org
Wed Sep 18 12:17:14 UTC 2024



Torsten Schmits pushed to branch wip/torsten.schmits/persistent-worker-test-2024-09-10 at Glasgow Haskell Compiler / GHC


Commits:
4ab7031d by Cheng Shao at 2024-09-16T20:54:44+02:00
compiler: implement --show-iface-abi-hash major mode

- - - - -


3 changed files:

- compiler/GHC/Iface/Load.hs
- docs/users_guide/expected-undocumented-flags.txt
- ghc/Main.hs


Changes:

=====================================
compiler/GHC/Iface/Load.hs
=====================================
@@ -33,7 +33,7 @@ module GHC.Iface.Load (
         WhereFrom(..),
 
         pprModIfaceSimple,
-        ifaceStats, pprModIface, showIface,
+        ifaceStats, pprModIface, showIface, showIfaceAbiHash,
 
         module Iface_Errors -- avoids boot files in Ppr modules
    ) where
@@ -1090,6 +1090,19 @@ showIface logger dflags unit_state name_cache filename = do
       $ withPprStyle (mkDumpStyle name_ppr_ctx)
       $ pprModIface unit_state iface
 
+-- | Read binary interface, and print ABI hash. Unlike the
+-- @--abi-hash@ major mode, the output is the ABI hash deserialized
+-- from the interface directly.
+showIfaceAbiHash :: Logger -> DynFlags -> NameCache -> FilePath -> IO ()
+showIfaceAbiHash logger dflags name_cache filename = do
+   let profile = targetProfile dflags
+
+   -- skip the hi way check and silence warnings
+   iface <- readBinIface profile name_cache IgnoreHiWay QuietBinIFace filename
+
+   logMsg logger MCDump noSrcSpan
+      $ ppr $ mi_mod_hash $ mi_final_exts iface
+
 -- | Show a ModIface but don't display details; suitable for ModIfaces stored in
 -- the EPT.
 pprModIfaceSimple :: UnitState -> ModIface -> SDoc


=====================================
docs/users_guide/expected-undocumented-flags.txt
=====================================
@@ -1,6 +1,7 @@
 -#include
 --abi-hash
 --backpack
+--show-iface-abi-hash
 --show-packages
 -Onot
 -Walternative-layout-rule-transitional


=====================================
ghc/Main.hs
=====================================
@@ -291,6 +291,10 @@ main' postLoadMode units dflags0 args flagWarnings = do
                                                     (hsc_units  hsc_env)
                                                     (hsc_NC     hsc_env)
                                                     f
+       ShowInterfaceAbiHash f -> liftIO $ showIfaceAbiHash logger
+                                                           (hsc_dflags hsc_env)
+                                                           (hsc_NC     hsc_env)
+                                                           f
        DoMake                 -> doMake units srcs
        DoMkDependHS           -> doMkDependHS (map fst srcs)
        StopBefore p           -> liftIO (oneShot hsc_env p srcs)
@@ -481,6 +485,8 @@ isShowGhciUsageMode _ = False
 
 data PostLoadMode
   = ShowInterface FilePath  -- ghc --show-iface
+  | ShowInterfaceAbiHash FilePath
+                            -- ghc --show-iface-abi-hash
   | DoMkDependHS            -- ghc -M
   | StopBefore StopPhase    -- ghc -E | -C | -S
                             -- StopBefore StopLn is the default
@@ -505,6 +511,9 @@ showUnitsMode = mkPostLoadMode ShowPackages
 showInterfaceMode :: FilePath -> Mode
 showInterfaceMode fp = mkPostLoadMode (ShowInterface fp)
 
+showInterfaceAbiHashMode :: FilePath -> Mode
+showInterfaceAbiHashMode fp = mkPostLoadMode (ShowInterfaceAbiHash fp)
+
 stopBeforeMode :: StopPhase -> Mode
 stopBeforeMode phase = mkPostLoadMode (StopBefore phase)
 
@@ -639,6 +648,9 @@ mode_flags =
   [ defFlag "-show-iface"  (HasArg (\f -> setMode (showInterfaceMode f)
                                                "--show-iface"))
 
+  , defFlag "-show-iface-abi-hash" (HasArg (\f -> setMode (showInterfaceAbiHashMode f)
+                                               "--show-iface-abi-hash"))
+
       ------- primary modes ------------------------------------------------
   , defFlag "c"            (PassFlag (\f -> do setMode (stopBeforeMode NoStop) f
                                                addFlag "-no-link" f))



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4ab7031d16db4e94bd9eb195455d85c923b9177c

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4ab7031d16db4e94bd9eb195455d85c923b9177c
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240918/11891b36/attachment-0001.html>


More information about the ghc-commits mailing list