Skip to content

Commit 233a623

Browse files
committed
Address PR 118 review comments
This commit addresses all review comments from PR 118: 1. Fix HAVE_INTERPRETER vs HAVE_JS_BACKEND mismatch (Critical) - Split CPP guards: HAVE_INTERPRETER for bytecode/interpreter - Use HAVE_JS_BACKEND for StgToJS modules - Affected files: GHC/Driver/Main.hs, Pipeline.hs, Pipeline/Execute.hs 2. Clean up "MINIMAL build" references - Replace with explicit CPP flag references - e.g., "HAVE_INTERPRETER not defined" instead of "MINIMAL build" - Affected files: GHC.hs, Driver/Main.hs, Driver/Make.hs, Driver/Session/Inspect.hs, Driver/Pipeline/Execute.hs, Tc/Types.hs, Tc/Gen/Splice.hs 3. Refactor RegTarget to GADT-based approach - Introduce ArchKind data type for type-level architecture tags - Use GADT RegTarget with architecture-specific constructors - Add SomeRegTarget existential wrapper for runtime dispatch - Define RegOps typeclass with per-architecture instances - Add withRegTarget helper using rank-2 types - Add INLINE pragmas for performance
1 parent 38f722e commit 233a623

9 files changed

Lines changed: 202 additions & 134 deletions

File tree

compiler/GHC.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ setTopSessionDynFlags dflags = do
826826
return Nothing
827827
#endif
828828
#else
829-
-- MINIMAL build: no interpreter support
829+
-- No interpreter support (HAVE_INTERPRETER not defined)
830830
let interp = Nothing
831831
#endif
832832

@@ -1181,7 +1181,7 @@ initialiseInteractiveDynFlags dflags hsc_env0 = do
11811181
}
11821182
}
11831183
#else
1184-
-- MINIMAL build: no plugin support, no IC modifications
1184+
-- No plugin support (HAVE_INTERPRETER not defined)
11851185
return hsc_env0
11861186
#endif
11871187

compiler/GHC/CmmToAsm/Reg/Target.hs

Lines changed: 174 additions & 111 deletions
Large diffs are not rendered by default.

compiler/GHC/Driver/Main.hs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ import GHC.Driver.Config.Stg.Pipeline (initStgPipelineOpts)
145145
import GHC.Driver.Config.StgToCmm (initStgToCmmConfig)
146146
import GHC.Driver.Config.Cmm (initCmmConfig)
147147
import GHC.Driver.LlvmConfigCache (initLlvmConfigCache)
148-
#if defined(HAVE_INTERPRETER)
148+
#if defined(HAVE_JS_BACKEND)
149149
import GHC.Driver.Config.StgToJS (initStgToJSConfig)
150150
#endif
151151
import GHC.Driver.Config.Diagnostic
@@ -176,6 +176,8 @@ import GHC.HsToCore
176176

177177
#if defined(HAVE_INTERPRETER)
178178
import GHC.StgToByteCode ( byteCodeGen )
179+
#endif
180+
#if defined(HAVE_JS_BACKEND)
179181
import GHC.StgToJS ( stgToJS )
180182
import GHC.StgToJS.Ids
181183
import GHC.StgToJS.Types
@@ -326,15 +328,18 @@ import qualified GHC.Unit.Home.Graph as HUG
326328
import GHC.Unit.Home.PackageTable
327329

328330
#if !defined(HAVE_INTERPRETER)
329-
-- Stub implementations for MINIMAL build
331+
-- Stub when interpreter not available
330332
initializePlugins :: HscEnv -> IO HscEnv
331333
initializePlugins = return
334+
#endif
332335

336+
#if !defined(HAVE_JS_BACKEND)
337+
-- Stub when JS backend not available
333338
initStgToJSConfig :: DynFlags -> StgToJSConfig
334339
initStgToJSConfig _ = StgToJSConfig -- StgToJSConfig stub is from GHC.Runtime.Interpreter.Types
335340

336341
stgToJS :: Logger -> StgToJSConfig -> [CgStgTopBinding] -> Module -> [SptEntry] -> ForeignStubs -> ([CostCentre], [CostCentreStack]) -> FilePath -> IO ()
337-
stgToJS _ _ _ _ _ _ _ _ = panic "stgToJS: not available in MINIMAL build"
342+
stgToJS _ _ _ _ _ _ _ _ = panic "stgToJS: not available (HAVE_JS_BACKEND not defined)"
338343
#endif
339344

340345
{- **********************************************************************
@@ -1313,7 +1318,7 @@ hscDesugarAndSimplify summary (FrontendTypecheck tc_result) tc_warnings mb_old_h
13131318
-- Just cause we desugared doesn't mean we are generating code, see above.
13141319
Just desugared_guts | backendGeneratesCode bcknd -> do
13151320
#if !defined(HAVE_INTERPRETER)
1316-
-- In MINIMAL builds, no TH plugins can be registered
1321+
-- No TH plugins can be registered (HAVE_INTERPRETER not defined)
13171322
let plugins = []
13181323
#else
13191324
plugins <- liftIO $ readIORef (tcg_th_coreplugins tc_result)
@@ -1341,7 +1346,7 @@ hscDesugarAndSimplify summary (FrontendTypecheck tc_result) tc_warnings mb_old_h
13411346
-- in order to inline data con wrappers but we honour whatever level of simplificication the
13421347
-- user requested. See #22008 for some discussion.
13431348
#if !defined(HAVE_INTERPRETER)
1344-
-- In MINIMAL builds, no TH plugins can be registered
1349+
-- No TH plugins can be registered (HAVE_INTERPRETER not defined)
13451350
let plugins = []
13461351
#else
13471352
plugins <- liftIO $ readIORef (tcg_th_coreplugins tc_result)

compiler/GHC/Driver/Make.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,7 +1266,7 @@ addSptEntries hsc_env mlinkable =
12661266
, spt <- bc_spt_entries bco
12671267
]
12681268
#else
1269-
addSptEntries _ _ = return () -- No bytecode support in MINIMAL build
1269+
addSptEntries _ _ = return () -- No bytecode support (HAVE_INTERPRETER not defined)
12701270
#endif
12711271

12721272

compiler/GHC/Driver/Pipeline.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ import GHC.Linker.Static
7878
import GHC.Linker.Static.Utils
7979
import GHC.Linker.Types
8080

81-
#if defined(HAVE_INTERPRETER)
81+
#if defined(HAVE_JS_BACKEND)
8282
import GHC.Driver.Config.StgToJS
8383
import GHC.StgToJS.Linker.Linker
8484
#endif

compiler/GHC/Driver/Pipeline/Execute.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ import GHC.Unit.Module.Env
7979
import GHC.Driver.Env.KnotVars
8080
import GHC.Driver.Config.Finder
8181
import GHC.Rename.Names
82-
#if defined(HAVE_INTERPRETER)
82+
#if defined(HAVE_JS_BACKEND)
8383
import GHC.StgToJS.Linker.Linker (embedJsFile)
8484
#endif
8585

@@ -635,7 +635,7 @@ runHscBackendPhase pipe_env hsc_env mod_name src_flavour location result = do
635635
bc <- generateFreshByteCode hsc_env mod_name (mkCgInteractiveGuts cgguts) mod_location
636636
return ([], final_iface, emptyHomeModInfoLinkable { homeMod_bytecode = Just bc } , panic "interpreter")
637637
#else
638-
panic "GHC.Driver.Pipeline.Execute.runHscPhase: bytecode generation not supported in MINIMAL build"
638+
panic "GHC.Driver.Pipeline.Execute.runHscPhase: bytecode generation not supported (HAVE_INTERPRETER not defined)"
639639
#endif
640640

641641

compiler/GHC/Driver/Session/Inspect.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import GHC.Utils.Outputable
4444
import qualified GHC.Unit.Home.Graph as HUG
4545

4646
#if !defined(HAVE_INTERPRETER)
47-
-- Stub type for MINIMAL build (replaces GHC.ByteCode.Breakpoints.InternalModBreaks)
47+
-- Stub type when interpreter is not available (replaces GHC.ByteCode.Breakpoints.InternalModBreaks)
4848
data InternalModBreaks = InternalModBreaks
4949
#endif
5050

@@ -164,7 +164,7 @@ getHomeModuleInfo hsc_env mdl =
164164
#if defined(HAVE_INTERPRETER)
165165
minf_modBreaks = getModBreaks hmi
166166
#else
167-
minf_modBreaks = Nothing -- No bytecode support in MINIMAL build
167+
minf_modBreaks = Nothing -- No bytecode support (HAVE_INTERPRETER not defined)
168168
#endif
169169
}))
170170

compiler/GHC/Tc/Gen/Splice.hs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,32 +1969,32 @@ getAnnotationsByTypeRep th_name tyrep
19691969
; let selectedTcgAnns = findAnnsByTypeRep (tcg_ann_env tcg) name tyrep
19701970
; return (selectedEpsHptAnns ++ selectedTcgAnns) }
19711971
#else
1972-
-- MINIMAL build: Template Haskell execution not supported
1972+
-- Template Haskell execution not supported (HAVE_INTERPRETER not defined)
19731973
-- Provide stub implementations that error at runtime for functions called from unguarded code
19741974

19751975
runMetaE :: LHsExpr GhcTc -> TcM (LHsExpr GhcPs)
1976-
runMetaE _ = fail "Template Haskell execution is not supported in MINIMAL build"
1976+
runMetaE _ = fail "Template Haskell execution is not supported (HAVE_INTERPRETER not defined)"
19771977

19781978
runMetaP :: LHsExpr GhcTc -> TcM (LPat GhcPs)
1979-
runMetaP _ = fail "Template Haskell execution is not supported in MINIMAL build"
1979+
runMetaP _ = fail "Template Haskell execution is not supported (HAVE_INTERPRETER not defined)"
19801980

19811981
runMetaT :: LHsExpr GhcTc -> TcM (LHsType GhcPs)
1982-
runMetaT _ = fail "Template Haskell execution is not supported in MINIMAL build"
1982+
runMetaT _ = fail "Template Haskell execution is not supported (HAVE_INTERPRETER not defined)"
19831983

19841984
runMetaD :: LHsExpr GhcTc -> TcM [LHsDecl GhcPs]
1985-
runMetaD _ = fail "Template Haskell execution is not supported in MINIMAL build"
1985+
runMetaD _ = fail "Template Haskell execution is not supported (HAVE_INTERPRETER not defined)"
19861986

19871987
runMetaAW :: LHsExpr GhcTc -> TcM Serialized
1988-
runMetaAW _ = fail "Template Haskell execution is not supported in MINIMAL build"
1988+
runMetaAW _ = fail "Template Haskell execution is not supported (HAVE_INTERPRETER not defined)"
19891989

19901990
runTH :: THResultType -> ForeignHValue -> TcM a
1991-
runTH _ _ = fail "Template Haskell execution is not supported in MINIMAL build"
1991+
runTH _ _ = fail "Template Haskell execution is not supported (HAVE_INTERPRETER not defined)"
19921992

19931993
finishTH :: TcM ()
1994-
finishTH = return () -- Nothing to finish in MINIMAL build
1994+
finishTH = return () -- Nothing to finish (HAVE_INTERPRETER not defined)
19951995

19961996
runRemoteModFinalizers :: ThModFinalizers -> TcM ()
1997-
runRemoteModFinalizers _ = fail "Template Haskell mod finalizers not supported in MINIMAL build"
1997+
runRemoteModFinalizers _ = fail "Template Haskell mod finalizers not supported (HAVE_INTERPRETER not defined)"
19981998
#endif
19991999

20002000
{-

compiler/GHC/Tc/Types.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ import Data.Typeable ( TypeRep )
195195
import Data.Maybe ( mapMaybe )
196196

197197
#if !defined(HAVE_INTERPRETER)
198-
-- Stub types for MINIMAL build (no ghci dependency)
198+
-- Stub types when interpreter is not available (no ghci dependency)
199199
data QState = QState -- Stub for Template Haskell state
200200
#endif
201201

0 commit comments

Comments
 (0)