multiple top level Main.main binders in STG

Hello, I added an STG exporter to my modified GHC to do experiments with the STG representation of the program. I noticed that there are multiple top-level binders for *Main.main* function. Is this a convention or a bug? Regards, Csaba Hruska Here is an example code snippet of the exported STG of the Main module: Main.main2 = closure (F:) (B:) { case Main.$wupto 1# 10000000# of sat.s16537 { DEFAULT -> case Main.$wxsum 0# sat.s16537 of ww.s16538 { DEFAULT -> case GHC.Show.$wshowSignedInt 0# ww.s16538 GHC.Types.[] of ww4.s16539 { GHC.Prim.(#,#) ww5.s16540 ww6.s16541 -> GHC.Types.: ww5.s16540 ww6.s16541 } } }} Main.main1 = closure (F:) (B: void.040) { GHC.IO.Handle.Text.hPutStr2 GHC.IO.Handle.FD.stdout Main.main2 GHC.Types.True GHC.Prim.void#} *Main.main* = closure (F:) (B: void.040) { Main.main1 GHC.Prim.void#} Main.main3 = closure (F:) (B: void.040) { GHC.TopHandler.runMainIO1 Main.main1 GHC.Prim.void#} *Main.main* = closure (F:) (B: void.040) { Main.main3 GHC.Prim.void#}

P.S.
I'd like to emphasize that this is produced by GHC and GHC's codegen
compiles it properly to a working executable.
On Fri, Nov 2, 2018 at 10:18 PM Csaba Hruska
Hello,
I added an STG exporter to my modified GHC to do experiments with the STG representation of the program. I noticed that there are multiple top-level binders for *Main.main* function. Is this a convention or a bug?
Regards, Csaba Hruska
Here is an example code snippet of the exported STG of the Main module: Main.main2 = closure (F:) (B:) { case Main.$wupto 1# 10000000# of sat.s16537 { DEFAULT -> case Main.$wxsum 0# sat.s16537 of ww.s16538 { DEFAULT -> case GHC.Show.$wshowSignedInt 0# ww.s16538 GHC.Types.[] of ww4.s16539 { GHC.Prim.(#,#) ww5.s16540 ww6.s16541 -> GHC.Types.: ww5.s16540 ww6.s16541 } } }}
Main.main1 = closure (F:) (B: void.040) { GHC.IO.Handle.Text.hPutStr2 GHC.IO.Handle.FD.stdout Main.main2 GHC.Types.True GHC.Prim.void#}
*Main.main* = closure (F:) (B: void.040) { Main.main1 GHC.Prim.void#}
Main.main3 = closure (F:) (B: void.040) { GHC.TopHandler.runMainIO1 Main.main1 GHC.Prim.void#}
*Main.main* = closure (F:) (B: void.040) { Main.main3 GHC.Prim.void#}

Csaba Hruska
Hello,
I added an STG exporter to my modified GHC to do experiments with the STG representation of the program. I noticed that there are multiple top-level binders for *Main.main* function. Is this a convention or a bug?
What GHC command line did you use to produce this output? Is it possible that you passed -dsuppress-uniques? If so the multiple `main`s probably differ in unique. Cheers, - Ben

Unfortunately it is dumped by my custom added code. (source code
https://github.com/grin-tech/ghc-grin/blob/master/ghc-dump-core/GhcDump_StgC...
)
I rerun my custom stg dump and it seems the unique values (in {--}
comments) are different.
How can I tell which is the real *Main.main* function?
Cheers,
Csaba
*Main.main {-r1550-}* =
closure (F:) (B:
void.040 {-040-}) {
Main.main1 {-r16514-}
GHC.Prim.void# {-021-}}
Main.main3 {-r16518-} =
closure (F:) (B:
void.040 {-040-}) {
GHC.TopHandler.runMainIO1 {-r9161-}
Main.main1 {-r16514-}
GHC.Prim.void# {-021-}}
*Main.main {-0101-}* =
closure (F:) (B:
void.040 {-040-}) {
Main.main3 {-r16518-}
GHC.Prim.void# {-021-}}
On Fri, Nov 2, 2018 at 11:18 PM Ben Gamari
Csaba Hruska
writes: Hello,
I added an STG exporter to my modified GHC to do experiments with the STG representation of the program. I noticed that there are multiple top-level binders for *Main.main* function. Is this a convention or a bug?
What GHC command line did you use to produce this output? Is it possible that you passed -dsuppress-uniques? If so the multiple `main`s probably differ in unique.
Cheers,
- Ben
participants (2)
-
Ben Gamari
-
Csaba Hruska