summaryrefslogtreecommitdiff
path: root/compiler
diff options
context:
space:
mode:
authorMatthew Pickering <matthewtpickering@gmail.com>2022-11-09 12:17:57 +0000
committerMarge Bot <ben+marge-bot@smart-cactus.org>2022-12-02 19:46:43 -0500
commit85ecc1a0fd6536149ae2b54f4b1985d80c0e21cb (patch)
treecc2b165d482960a7251e8e4bb494b8392f40dd50 /compiler
parent74c767df770766d8d52e87b9ff7da10f94620a91 (diff)
downloadhaskell-85ecc1a0fd6536149ae2b54f4b1985d80c0e21cb.tar.gz
Add special case for :Main module in `GHC.IfaceToCore.mk_top_id`
See Note [Root-main Id] The `:Main` special binding is actually defined in the current module (hence don't go looking for it externally) but the module name is rOOT_MAIN rather than the current module so we need this special case. There was already some similar logic in `GHC.Rename.Env` for External Core, but now the "External Core" is in interface files it needs to be moved here instead. Fixes #22405
Diffstat (limited to 'compiler')
-rw-r--r--compiler/GHC/IfaceToCore.hs13
-rw-r--r--compiler/GHC/Rename/Env.hs5
-rw-r--r--compiler/GHC/Tc/Module.hs8
3 files changed, 25 insertions, 1 deletions
diff --git a/compiler/GHC/IfaceToCore.hs b/compiler/GHC/IfaceToCore.hs
index a2d63bb779..f4bb4057c9 100644
--- a/compiler/GHC/IfaceToCore.hs
+++ b/compiler/GHC/IfaceToCore.hs
@@ -123,6 +123,7 @@ import GHC.Driver.Env.KnotVars
import GHC.Unit.Module.WholeCoreBindings
import Data.IORef
import Data.Foldable
+import GHC.Builtin.Names (ioTyConName, rOOT_MAIN)
{-
This module takes
@@ -930,7 +931,17 @@ tc_iface_binding i IfUseUnfoldingRhs = return (unfoldingTemplate $ realIdUnfoldi
tc_iface_binding _ (IfRhs rhs) = tcIfaceExpr rhs
mk_top_id :: IfaceTopBndrInfo -> IfL Id
-mk_top_id (IfGblTopBndr gbl_name) = tcIfaceExtId gbl_name
+mk_top_id (IfGblTopBndr gbl_name)
+ -- See Note [Root-main Id]
+ -- This special binding is actually defined in the current module
+ -- (hence don't go looking for it externally) but the module name is rOOT_MAIN
+ -- rather than the current module so we need this special case.
+ -- See some similar logic in `GHC.Rename.Env`.
+ | Just rOOT_MAIN == nameModule_maybe gbl_name
+ = do
+ ATyCon ioTyCon <- tcIfaceGlobal ioTyConName
+ return $ mkExportedVanillaId gbl_name (mkTyConApp ioTyCon [unitTy])
+ | otherwise = tcIfaceExtId gbl_name
mk_top_id (IfLclTopBndr raw_name iface_type info details) = do
name <- newIfaceName (mkVarOccFS raw_name)
ty <- tcIfaceType iface_type
diff --git a/compiler/GHC/Rename/Env.hs b/compiler/GHC/Rename/Env.hs
index 3d3ded48f0..90c9f38faf 100644
--- a/compiler/GHC/Rename/Env.hs
+++ b/compiler/GHC/Rename/Env.hs
@@ -207,6 +207,11 @@ newTopSrcBinder (L loc rdr_name)
-- the nice Exact name for the TyCon gets swizzled to an Orig name.
-- Hence the badOrigBinding error message.
--
+
+ -- MP 2022: I suspect this code path is never called for `rOOT_MAIN` anymore
+ -- because External Core has been removed but we instead have some similar logic for
+ -- serialising whole programs into interface files in GHC.IfaceToCore.mk_top_id.
+
-- Except for the ":Main.main = ..." definition inserted into
-- the Main module; ugh!
diff --git a/compiler/GHC/Tc/Module.hs b/compiler/GHC/Tc/Module.hs
index 76c5f0fb66..24a5d07090 100644
--- a/compiler/GHC/Tc/Module.hs
+++ b/compiler/GHC/Tc/Module.hs
@@ -2047,6 +2047,14 @@ This is unusual: it's a LocalId whose Name has a Module from another
module. Tiresomely, we must filter it out again in GHC.Iface.Make, less we
get two defns for 'main' in the interface file!
+When using `-fwrite-if-simplified-core` the root_main_id can end up in an interface file.
+When the interface is read back in we have to add a special case when creating the
+Id because otherwise we would go looking for the :Main module which obviously doesn't
+exist. For this logic see GHC.IfaceToCore.mk_top_id.
+
+There is also some similar (probably dead) logic in GHC.Rename.Env which says it
+was added for External Core which faced a similar issue.
+
*********************************************************
* *