Matthew Pickering pushed to branch wip/gdc-files at Glasgow Haskell Compiler / GHC

Commits:

10 changed files:

Changes:

  • compiler/GHC.hs
    ... ... @@ -30,7 +30,7 @@ module GHC (
    30 30
     
    
    31 31
             -- * Flags and settings
    
    32 32
             DynFlags(..), GeneralFlag(..), Severity(..), Backend, gopt,
    
    33
    -        ncgBackend, llvmBackend, viaCBackend, interpreterBackend, noBackend,
    
    33
    +        ncgBackend, llvmBackend, viaCBackend, bytecodeBackend, noBackend,
    
    34 34
             GhcMode(..), GhcLink(..),
    
    35 35
             parseDynamicFlags, parseTargetFiles,
    
    36 36
             getSessionDynFlags,
    

  • compiler/GHC/Driver/Backend.hs
    ... ... @@ -47,7 +47,7 @@ module GHC.Driver.Backend
    47 47
        , llvmBackend
    
    48 48
        , jsBackend
    
    49 49
        , viaCBackend
    
    50
    -   , interpreterBackend
    
    50
    +   , bytecodeBackend
    
    51 51
        , noBackend
    
    52 52
        , allBackends
    
    53 53
     
    
    ... ... @@ -252,7 +252,7 @@ instance Show Backend where
    252 252
       show = backendDescription
    
    253 253
     
    
    254 254
     
    
    255
    -ncgBackend, llvmBackend, viaCBackend, interpreterBackend, jsBackend, noBackend
    
    255
    +ncgBackend, llvmBackend, viaCBackend, bytecodeBackend, jsBackend, noBackend
    
    256 256
         :: Backend
    
    257 257
     
    
    258 258
     -- | The native code generator.
    
    ... ... @@ -310,7 +310,7 @@ viaCBackend = Named ViaC
    310 310
     -- (foreign primops).
    
    311 311
     --
    
    312 312
     -- See "GHC.StgToByteCode"
    
    313
    -interpreterBackend = Named Interpreter
    
    313
    +bytecodeBackend = Named Bytecode
    
    314 314
     
    
    315 315
     -- | A dummy back end that generates no code.
    
    316 316
     --
    
    ... ... @@ -419,7 +419,7 @@ backendDescription (Named NCG) = "native code generator"
    419 419
     backendDescription (Named LLVM)        = "LLVM"
    
    420 420
     backendDescription (Named ViaC)        = "compiling via C"
    
    421 421
     backendDescription (Named JavaScript)  = "compiling to JavaScript"
    
    422
    -backendDescription (Named Interpreter) = "byte-code interpreter"
    
    422
    +backendDescription (Named Bytecode) = "byte-code interpreter"
    
    423 423
     backendDescription (Named NoBackend)   = "no code generated"
    
    424 424
     
    
    425 425
     -- | This flag tells the compiler driver whether the back
    
    ... ... @@ -431,7 +431,7 @@ backendWritesFiles (Named NCG) = True
    431 431
     backendWritesFiles (Named LLVM)        = True
    
    432 432
     backendWritesFiles (Named ViaC)        = True
    
    433 433
     backendWritesFiles (Named JavaScript)  = True
    
    434
    -backendWritesFiles (Named Interpreter) = False
    
    434
    +backendWritesFiles (Named Bytecode) = False
    
    435 435
     backendWritesFiles (Named NoBackend)   = False
    
    436 436
     
    
    437 437
     -- | When the back end does write files, this value tells
    
    ... ... @@ -442,7 +442,7 @@ backendPipelineOutput (Named NCG) = Persistent
    442 442
     backendPipelineOutput (Named LLVM) = Persistent
    
    443 443
     backendPipelineOutput (Named ViaC) = Persistent
    
    444 444
     backendPipelineOutput (Named JavaScript)  = Persistent
    
    445
    -backendPipelineOutput (Named Interpreter) = NoOutputFile
    
    445
    +backendPipelineOutput (Named Bytecode) = NoOutputFile
    
    446 446
     backendPipelineOutput (Named NoBackend)   = NoOutputFile
    
    447 447
     
    
    448 448
     -- | This flag tells the driver whether the back end can
    
    ... ... @@ -453,7 +453,7 @@ backendCanReuseLoadedCode (Named NCG) = False
    453 453
     backendCanReuseLoadedCode (Named LLVM)        = False
    
    454 454
     backendCanReuseLoadedCode (Named ViaC)        = False
    
    455 455
     backendCanReuseLoadedCode (Named JavaScript)  = False
    
    456
    -backendCanReuseLoadedCode (Named Interpreter) = True
    
    456
    +backendCanReuseLoadedCode (Named Bytecode) = True
    
    457 457
     backendCanReuseLoadedCode (Named NoBackend)   = False
    
    458 458
     
    
    459 459
     -- | It is is true of every back end except @-fno-code@
    
    ... ... @@ -478,7 +478,7 @@ backendGeneratesCode (Named NCG) = True
    478 478
     backendGeneratesCode (Named LLVM)        = True
    
    479 479
     backendGeneratesCode (Named ViaC)        = True
    
    480 480
     backendGeneratesCode (Named JavaScript)  = True
    
    481
    -backendGeneratesCode (Named Interpreter) = True
    
    481
    +backendGeneratesCode (Named Bytecode) = True
    
    482 482
     backendGeneratesCode (Named NoBackend)   = False
    
    483 483
     
    
    484 484
     backendGeneratesCodeForHsBoot :: Backend -> Bool
    
    ... ... @@ -486,7 +486,7 @@ backendGeneratesCodeForHsBoot (Named NCG) = True
    486 486
     backendGeneratesCodeForHsBoot (Named LLVM)        = True
    
    487 487
     backendGeneratesCodeForHsBoot (Named ViaC)        = True
    
    488 488
     backendGeneratesCodeForHsBoot (Named JavaScript)  = True
    
    489
    -backendGeneratesCodeForHsBoot (Named Interpreter) = False
    
    489
    +backendGeneratesCodeForHsBoot (Named Bytecode) = False
    
    490 490
     backendGeneratesCodeForHsBoot (Named NoBackend)   = False
    
    491 491
     
    
    492 492
     -- | When set, this flag turns on interface writing for
    
    ... ... @@ -498,7 +498,7 @@ backendSupportsInterfaceWriting (Named NCG) = True
    498 498
     backendSupportsInterfaceWriting (Named LLVM)        = True
    
    499 499
     backendSupportsInterfaceWriting (Named ViaC)        = True
    
    500 500
     backendSupportsInterfaceWriting (Named JavaScript)  = True
    
    501
    -backendSupportsInterfaceWriting (Named Interpreter) = True
    
    501
    +backendSupportsInterfaceWriting (Named Bytecode) = True
    
    502 502
     backendSupportsInterfaceWriting (Named NoBackend)   = False
    
    503 503
     
    
    504 504
     -- | When preparing code for this back end, the type
    
    ... ... @@ -510,7 +510,7 @@ backendRespectsSpecialise (Named NCG) = True
    510 510
     backendRespectsSpecialise (Named LLVM)        = True
    
    511 511
     backendRespectsSpecialise (Named ViaC)        = True
    
    512 512
     backendRespectsSpecialise (Named JavaScript)  = True
    
    513
    -backendRespectsSpecialise (Named Interpreter) = False
    
    513
    +backendRespectsSpecialise (Named Bytecode) = False
    
    514 514
     backendRespectsSpecialise (Named NoBackend)   = False
    
    515 515
     
    
    516 516
     -- | This back end wants the `mi_top_env` field of a
    
    ... ... @@ -522,7 +522,7 @@ backendWantsGlobalBindings (Named LLVM) = False
    522 522
     backendWantsGlobalBindings (Named ViaC)        = False
    
    523 523
     backendWantsGlobalBindings (Named JavaScript)  = False
    
    524 524
     backendWantsGlobalBindings (Named NoBackend)   = False
    
    525
    -backendWantsGlobalBindings (Named Interpreter) = True
    
    525
    +backendWantsGlobalBindings (Named Bytecode) = True
    
    526 526
     
    
    527 527
     -- | The back end targets a technology that implements
    
    528 528
     -- `switch` natively.  (For example, LLVM or C.) Therefore
    
    ... ... @@ -534,7 +534,7 @@ backendHasNativeSwitch (Named NCG) = False
    534 534
     backendHasNativeSwitch (Named LLVM)        = True
    
    535 535
     backendHasNativeSwitch (Named ViaC)        = True
    
    536 536
     backendHasNativeSwitch (Named JavaScript)  = True
    
    537
    -backendHasNativeSwitch (Named Interpreter) = False
    
    537
    +backendHasNativeSwitch (Named Bytecode) = False
    
    538 538
     backendHasNativeSwitch (Named NoBackend)   = False
    
    539 539
     
    
    540 540
     -- | As noted in the documentation for
    
    ... ... @@ -548,7 +548,7 @@ backendPrimitiveImplementation (Named NCG) = NcgPrimitives
    548 548
     backendPrimitiveImplementation (Named LLVM)        = LlvmPrimitives
    
    549 549
     backendPrimitiveImplementation (Named JavaScript)  = JSPrimitives
    
    550 550
     backendPrimitiveImplementation (Named ViaC)        = GenericPrimitives
    
    551
    -backendPrimitiveImplementation (Named Interpreter) = GenericPrimitives
    
    551
    +backendPrimitiveImplementation (Named Bytecode) = GenericPrimitives
    
    552 552
     backendPrimitiveImplementation (Named NoBackend)   = GenericPrimitives
    
    553 553
     
    
    554 554
     -- | When this value is `IsValid`, the back end is
    
    ... ... @@ -560,7 +560,7 @@ backendSimdValidity (Named NCG) = IsValid
    560 560
     backendSimdValidity (Named LLVM)        = IsValid
    
    561 561
     backendSimdValidity (Named ViaC)        = NotValid $ unlines ["SIMD vector instructions require using the NCG or the LLVM backend."]
    
    562 562
     backendSimdValidity (Named JavaScript)  = NotValid $ unlines ["SIMD vector instructions require using the NCG or the LLVM backend."]
    
    563
    -backendSimdValidity (Named Interpreter) = NotValid $ unlines ["SIMD vector instructions require using the NCG or the LLVM backend."]
    
    563
    +backendSimdValidity (Named Bytecode) = NotValid $ unlines ["SIMD vector instructions require using the NCG or the LLVM backend."]
    
    564 564
     backendSimdValidity (Named NoBackend)   = NotValid $ unlines ["SIMD vector instructions require using the NCG or the LLVM backend."]
    
    565 565
     
    
    566 566
     -- | This flag says whether the back end supports large
    
    ... ... @@ -571,7 +571,7 @@ backendSupportsEmbeddedBlobs (Named NCG) = True
    571 571
     backendSupportsEmbeddedBlobs (Named LLVM)        = False
    
    572 572
     backendSupportsEmbeddedBlobs (Named ViaC)        = False
    
    573 573
     backendSupportsEmbeddedBlobs (Named JavaScript)  = False
    
    574
    -backendSupportsEmbeddedBlobs (Named Interpreter) = False
    
    574
    +backendSupportsEmbeddedBlobs (Named Bytecode) = False
    
    575 575
     backendSupportsEmbeddedBlobs (Named NoBackend)   = False
    
    576 576
     
    
    577 577
     -- | This flag tells the compiler driver that the back end
    
    ... ... @@ -586,7 +586,7 @@ backendNeedsPlatformNcgSupport (Named NCG) = True
    586 586
     backendNeedsPlatformNcgSupport (Named LLVM)        = False
    
    587 587
     backendNeedsPlatformNcgSupport (Named ViaC)        = False
    
    588 588
     backendNeedsPlatformNcgSupport (Named JavaScript)  = False
    
    589
    -backendNeedsPlatformNcgSupport (Named Interpreter) = False
    
    589
    +backendNeedsPlatformNcgSupport (Named Bytecode) = False
    
    590 590
     backendNeedsPlatformNcgSupport (Named NoBackend)   = False
    
    591 591
     
    
    592 592
     -- | This flag is set if the back end can generate code
    
    ... ... @@ -598,7 +598,7 @@ backendSupportsUnsplitProcPoints (Named NCG) = True
    598 598
     backendSupportsUnsplitProcPoints (Named LLVM)        = False
    
    599 599
     backendSupportsUnsplitProcPoints (Named ViaC)        = False
    
    600 600
     backendSupportsUnsplitProcPoints (Named JavaScript)  = False
    
    601
    -backendSupportsUnsplitProcPoints (Named Interpreter) = False
    
    601
    +backendSupportsUnsplitProcPoints (Named Bytecode) = False
    
    602 602
     backendSupportsUnsplitProcPoints (Named NoBackend)   = False
    
    603 603
     
    
    604 604
     -- | This flag guides the driver in resolving issues about
    
    ... ... @@ -616,7 +616,7 @@ backendSwappableWithViaC (Named NCG) = True
    616 616
     backendSwappableWithViaC (Named LLVM)        = True
    
    617 617
     backendSwappableWithViaC (Named ViaC)        = False
    
    618 618
     backendSwappableWithViaC (Named JavaScript)  = False
    
    619
    -backendSwappableWithViaC (Named Interpreter) = False
    
    619
    +backendSwappableWithViaC (Named Bytecode) = False
    
    620 620
     backendSwappableWithViaC (Named NoBackend)   = False
    
    621 621
     
    
    622 622
     -- | This flag is true if the back end works *only* with
    
    ... ... @@ -626,7 +626,7 @@ backendUnregisterisedAbiOnly (Named NCG) = False
    626 626
     backendUnregisterisedAbiOnly (Named LLVM)        = False
    
    627 627
     backendUnregisterisedAbiOnly (Named ViaC)        = True
    
    628 628
     backendUnregisterisedAbiOnly (Named JavaScript)  = False
    
    629
    -backendUnregisterisedAbiOnly (Named Interpreter) = False
    
    629
    +backendUnregisterisedAbiOnly (Named Bytecode) = False
    
    630 630
     backendUnregisterisedAbiOnly (Named NoBackend)   = False
    
    631 631
     
    
    632 632
     -- | This flag is set if the back end generates C code in
    
    ... ... @@ -637,7 +637,7 @@ backendGeneratesHc (Named NCG) = False
    637 637
     backendGeneratesHc (Named LLVM)        = False
    
    638 638
     backendGeneratesHc (Named ViaC)        = True
    
    639 639
     backendGeneratesHc (Named JavaScript)  = False
    
    640
    -backendGeneratesHc (Named Interpreter) = False
    
    640
    +backendGeneratesHc (Named Bytecode) = False
    
    641 641
     backendGeneratesHc (Named NoBackend)   = False
    
    642 642
     
    
    643 643
     -- | This flag says whether SPT (static pointer table)
    
    ... ... @@ -649,7 +649,7 @@ backendSptIsDynamic (Named NCG) = False
    649 649
     backendSptIsDynamic (Named LLVM)        = False
    
    650 650
     backendSptIsDynamic (Named ViaC)        = False
    
    651 651
     backendSptIsDynamic (Named JavaScript)  = False
    
    652
    -backendSptIsDynamic (Named Interpreter) = True
    
    652
    +backendSptIsDynamic (Named Bytecode) = True
    
    653 653
     backendSptIsDynamic (Named NoBackend)   = False
    
    654 654
     
    
    655 655
     -- | If this flag is unset, then the driver ignores the flag @-fbreak-points@,
    
    ... ... @@ -660,7 +660,7 @@ backendSupportsBreakpoints = \case
    660 660
       Named LLVM        -> False
    
    661 661
       Named ViaC        -> False
    
    662 662
       Named JavaScript  -> False
    
    663
    -  Named Interpreter -> True
    
    663
    +  Named Bytecode -> True
    
    664 664
       Named NoBackend   -> False
    
    665 665
     
    
    666 666
     -- | If this flag is set, then the driver forces the
    
    ... ... @@ -671,7 +671,7 @@ backendForcesOptimization0 (Named NCG) = False
    671 671
     backendForcesOptimization0 (Named LLVM)        = False
    
    672 672
     backendForcesOptimization0 (Named ViaC)        = False
    
    673 673
     backendForcesOptimization0 (Named JavaScript)  = False
    
    674
    -backendForcesOptimization0 (Named Interpreter) = True
    
    674
    +backendForcesOptimization0 (Named Bytecode) = True
    
    675 675
     backendForcesOptimization0 (Named NoBackend)   = False
    
    676 676
     
    
    677 677
     -- | I don't understand exactly how this works.  But if
    
    ... ... @@ -683,7 +683,7 @@ backendNeedsFullWays (Named NCG) = False
    683 683
     backendNeedsFullWays (Named LLVM)        = False
    
    684 684
     backendNeedsFullWays (Named ViaC)        = False
    
    685 685
     backendNeedsFullWays (Named JavaScript)  = False
    
    686
    -backendNeedsFullWays (Named Interpreter) = True
    
    686
    +backendNeedsFullWays (Named Bytecode) = True
    
    687 687
     backendNeedsFullWays (Named NoBackend)   = False
    
    688 688
     
    
    689 689
     -- | This flag is also special for the interpreter: if a
    
    ... ... @@ -695,7 +695,7 @@ backendSpecialModuleSource (Named NCG) = const Nothing
    695 695
     backendSpecialModuleSource (Named LLVM)        = const Nothing
    
    696 696
     backendSpecialModuleSource (Named ViaC)        = const Nothing
    
    697 697
     backendSpecialModuleSource (Named JavaScript)  = const Nothing
    
    698
    -backendSpecialModuleSource (Named Interpreter) = \b -> if b then Just "interpreted" else Nothing
    
    698
    +backendSpecialModuleSource (Named Bytecode) = \b -> if b then Just "interpreted" else Nothing
    
    699 699
     backendSpecialModuleSource (Named NoBackend)   = const (Just "nothing")
    
    700 700
     
    
    701 701
     -- | This flag says whether the back end supports Haskell
    
    ... ... @@ -707,7 +707,7 @@ backendSupportsHpc (Named NCG) = True
    707 707
     backendSupportsHpc (Named LLVM)        = True
    
    708 708
     backendSupportsHpc (Named ViaC)        = True
    
    709 709
     backendSupportsHpc (Named JavaScript)  = False
    
    710
    -backendSupportsHpc (Named Interpreter) = False
    
    710
    +backendSupportsHpc (Named Bytecode) = False
    
    711 711
     backendSupportsHpc (Named NoBackend)   = True
    
    712 712
     
    
    713 713
     -- | This flag says whether the back end supports foreign
    
    ... ... @@ -718,7 +718,7 @@ backendSupportsCImport (Named NCG) = True
    718 718
     backendSupportsCImport (Named LLVM)        = True
    
    719 719
     backendSupportsCImport (Named ViaC)        = True
    
    720 720
     backendSupportsCImport (Named JavaScript)  = True
    
    721
    -backendSupportsCImport (Named Interpreter) = True
    
    721
    +backendSupportsCImport (Named Bytecode) = True
    
    722 722
     backendSupportsCImport (Named NoBackend)   = True
    
    723 723
     
    
    724 724
     -- | This flag says whether the back end supports foreign
    
    ... ... @@ -728,7 +728,7 @@ backendSupportsCExport (Named NCG) = True
    728 728
     backendSupportsCExport (Named LLVM)        = True
    
    729 729
     backendSupportsCExport (Named ViaC)        = True
    
    730 730
     backendSupportsCExport (Named JavaScript)  = True
    
    731
    -backendSupportsCExport (Named Interpreter) = False
    
    731
    +backendSupportsCExport (Named Bytecode) = False
    
    732 732
     backendSupportsCExport (Named NoBackend)   = True
    
    733 733
     
    
    734 734
     -- | When using this back end, it may be necessary or
    
    ... ... @@ -749,7 +749,7 @@ backendCDefs (Named NCG) = NoCDefs
    749 749
     backendCDefs (Named LLVM)        = LlvmCDefs
    
    750 750
     backendCDefs (Named ViaC)        = NoCDefs
    
    751 751
     backendCDefs (Named JavaScript)  = NoCDefs
    
    752
    -backendCDefs (Named Interpreter) = NoCDefs
    
    752
    +backendCDefs (Named Bytecode) = NoCDefs
    
    753 753
     backendCDefs (Named NoBackend)   = NoCDefs
    
    754 754
     
    
    755 755
     -- | This (defunctionalized) function generates code and
    
    ... ... @@ -768,7 +768,7 @@ backendCodeOutput (Named NCG) = NcgCodeOutput
    768 768
     backendCodeOutput (Named LLVM)        = LlvmCodeOutput
    
    769 769
     backendCodeOutput (Named ViaC)        = ViaCCodeOutput
    
    770 770
     backendCodeOutput (Named JavaScript)  = JSCodeOutput
    
    771
    -backendCodeOutput (Named Interpreter) = panic "backendCodeOutput: interpreterBackend"
    
    771
    +backendCodeOutput (Named Bytecode) = panic "backendCodeOutput: interpreterBackend"
    
    772 772
     backendCodeOutput (Named NoBackend)   = panic "backendCodeOutput: noBackend"
    
    773 773
     
    
    774 774
     backendUseJSLinker :: Backend -> Bool
    
    ... ... @@ -776,7 +776,7 @@ backendUseJSLinker (Named NCG) = False
    776 776
     backendUseJSLinker (Named LLVM)        = False
    
    777 777
     backendUseJSLinker (Named ViaC)        = False
    
    778 778
     backendUseJSLinker (Named JavaScript)  = True
    
    779
    -backendUseJSLinker (Named Interpreter) = False
    
    779
    +backendUseJSLinker (Named Bytecode) = False
    
    780 780
     backendUseJSLinker (Named NoBackend)   = False
    
    781 781
     
    
    782 782
     -- | This (defunctionalized) function tells the compiler
    
    ... ... @@ -795,7 +795,7 @@ backendPostHscPipeline (Named NCG) = NcgPostHscPipeline
    795 795
     backendPostHscPipeline (Named LLVM) = LlvmPostHscPipeline
    
    796 796
     backendPostHscPipeline (Named ViaC) = ViaCPostHscPipeline
    
    797 797
     backendPostHscPipeline (Named JavaScript)  = JSPostHscPipeline
    
    798
    -backendPostHscPipeline (Named Interpreter) = NoPostHscPipeline
    
    798
    +backendPostHscPipeline (Named Bytecode) = NoPostHscPipeline
    
    799 799
     backendPostHscPipeline (Named NoBackend) = NoPostHscPipeline
    
    800 800
     
    
    801 801
     -- | Somewhere in the compiler driver, when compiling
    
    ... ... @@ -809,7 +809,7 @@ backendNormalSuccessorPhase (Named NCG) = As False
    809 809
     backendNormalSuccessorPhase (Named LLVM) = LlvmOpt
    
    810 810
     backendNormalSuccessorPhase (Named ViaC) = HCc
    
    811 811
     backendNormalSuccessorPhase (Named JavaScript)  = StopLn
    
    812
    -backendNormalSuccessorPhase (Named Interpreter) = StopLn
    
    812
    +backendNormalSuccessorPhase (Named Bytecode) = StopLn
    
    813 813
     backendNormalSuccessorPhase (Named NoBackend)   = StopLn
    
    814 814
     
    
    815 815
     -- | Name of the back end, if any.  Used to migrate legacy
    
    ... ... @@ -820,7 +820,7 @@ backendName (Named NCG) = NCG
    820 820
     backendName (Named LLVM) = LLVM
    
    821 821
     backendName (Named ViaC) = ViaC
    
    822 822
     backendName (Named JavaScript)  = JavaScript
    
    823
    -backendName (Named Interpreter) = Interpreter
    
    823
    +backendName (Named Bytecode) = Bytecode
    
    824 824
     backendName (Named NoBackend)   = NoBackend
    
    825 825
     
    
    826 826
     
    
    ... ... @@ -833,7 +833,7 @@ allBackends = [ ncgBackend
    833 833
                   , llvmBackend
    
    834 834
                   , viaCBackend
    
    835 835
                   , jsBackend
    
    836
    -              , interpreterBackend
    
    836
    +              , bytecodeBackend
    
    837 837
                   , noBackend
    
    838 838
                   ]
    
    839 839
     
    

  • compiler/GHC/Driver/Backend/Internal.hs
    ... ... @@ -28,6 +28,6 @@ data BackendName
    28 28
        | LLVM          -- ^ Names the LLVM backend.
    
    29 29
        | ViaC          -- ^ Names the Via-C backend.
    
    30 30
        | JavaScript    -- ^ Names the JS backend.
    
    31
    -   | Interpreter   -- ^ Names the ByteCode interpreter.
    
    31
    +   | Bytecode      -- ^ Names the ByteCode interpreter.
    
    32 32
        | NoBackend     -- ^ Names the `-fno-code` backend.
    
    33 33
      deriving (Eq, Show)

  • compiler/GHC/Driver/Downsweep.hs
    ... ... @@ -916,7 +916,7 @@ enableCodeGenWhen logger tmpfs staticLife dynLife unit_env mod_graph = do
    916 916
                        else (,) <$> (new_temp_file (hiSuf_ dflags) (dynHiSuf_ dflags))
    
    917 917
                                 <*> (new_temp_file (objectSuf_ dflags) (dynObjectSuf_ dflags))
    
    918 918
                    let new_dflags = case enable_spec of
    
    919
    -                                  EnableByteCode -> dflags { backend = interpreterBackend }
    
    919
    +                                  EnableByteCode -> dflags { backend = bytecodeBackend }
    
    920 920
                                       EnableObject   -> dflags { backend = defaultBackendOf ms }
    
    921 921
                                       EnableByteCodeAndObject -> (gopt_set dflags Opt_ByteCodeAndObjectCode) { backend = defaultBackendOf ms}
    
    922 922
                    let ms' = ms
    

  • compiler/GHC/Driver/Main.hs
    ... ... @@ -105,7 +105,6 @@ module GHC.Driver.Main
    105 105
         , showModuleIndex
    
    106 106
         , hscAddSptEntries
    
    107 107
         , writeInterfaceOnlyMode
    
    108
    -    , loadByteCode
    
    109 108
         , genModDetails
    
    110 109
         ) where
    
    111 110
     
    
    ... ... @@ -869,25 +868,24 @@ hscRecompStatus
    869 868
                   return $ HscRecompNeeded $ Just $ mi_iface_hash $ checked_iface
    
    870 869
     
    
    871 870
                | otherwise -> do
    
    872
    -               -- Do need linkable
    
    873
    -               -- 1. Just check whether we have bytecode/object linkables and then
    
    874
    -               -- we will decide if we need them or not.
    
    875
    -               bc_linkable <- checkByteCode hsc_env checked_iface mod_details mod_summary (homeMod_bytecode old_linkable)
    
    871
    +               -- Check the status of all the linkable types we might need.
    
    872
    +               -- 1. The in-memory linkable we had at hand.
    
    873
    +               bc_in_memory_linkable <- checkByteCodeInMemory hsc_env mod_summary (homeMod_bytecode old_linkable)
    
    874
    +               -- 2. The bytecode object file
    
    875
    +               bc_obj_linkable <- checkByteCodeFromObject hsc_env mod_summary
    
    876
    +               -- 3. Bytecode from an interface whole core bindings.
    
    877
    +               bc_core_linkable <- checkByteCodeFromCoreBindings hsc_env checked_iface mod_details mod_summary
    
    878
    +               -- 4. The object file.
    
    876 879
                    obj_linkable <- liftIO $ checkObjects lcl_dflags (homeMod_object old_linkable) mod_summary
    
    877
    -               trace_if (hsc_logger hsc_env) (vcat [text "BCO linkable", nest 2 (ppr bc_linkable), text "Object Linkable", ppr obj_linkable])
    
    880
    +               trace_if (hsc_logger hsc_env)
    
    881
    +                (vcat [text "BCO linkable", nest 2 (ppr bc_in_memory_linkable)
    
    882
    +                      , text "BCO obj linkable", ppr bc_obj_linkable
    
    883
    +                      , text "BCO core linkable", ppr bc_core_linkable
    
    884
    +                      , text "Object Linkable", ppr obj_linkable])
    
    878 885
     
    
    879
    -               let just_bc = justBytecode <$> bc_linkable
    
    880
    -                   just_o  = justObjects  <$> obj_linkable
    
    881
    -                   _maybe_both_os = case (bc_linkable, obj_linkable) of
    
    882
    -                               (UpToDateItem bc, UpToDateItem o) -> UpToDateItem (bytecodeAndObjects bc o)
    
    883
    -                               -- If missing object code, just say we need to recompile because of object code.
    
    884
    -                               (_, OutOfDateItem reason _) -> OutOfDateItem reason Nothing
    
    885
    -                               -- If just missing byte code, just use the object code
    
    886
    -                               -- so you should use -fprefer-byte-code with -fwrite-if-simplified-core or you'll
    
    887
    -                               -- end up using bytecode on recompilation
    
    888
    -                               (_, UpToDateItem {} ) -> just_o
    
    886
    +               let just_o  = justObjects  <$> obj_linkable
    
    889 887
     
    
    890
    -                   definitely_both_os = case (bc_linkable, obj_linkable) of
    
    888
    +                   definitely_both_os = case (definitely_bc, obj_linkable) of
    
    891 889
                                    (UpToDateItem bc, UpToDateItem o) -> UpToDateItem (bytecodeAndObjects bc o)
    
    892 890
                                    -- If missing object code, just say we need to recompile because of object code.
    
    893 891
                                    (_, OutOfDateItem reason _) -> OutOfDateItem reason Nothing
    
    ... ... @@ -896,17 +894,21 @@ hscRecompStatus
    896 894
                                    -- end up using bytecode on recompilation
    
    897 895
                                    (OutOfDateItem reason _,  _ ) -> OutOfDateItem reason Nothing
    
    898 896
     
    
    897
    +                   -- When -fwrite-byte-code, we definitely need to have up-to-date bytecode.
    
    898
    +                   definitely_bc =  bc_obj_linkable `prefer` bc_in_memory_linkable
    
    899
    +
    
    900
    +                   -- If not -fwrite-byte-code, then we could use core bindings or object code if that's available.
    
    901
    +                   maybe_bc = ((bc_obj_linkable `choose` bc_core_linkable) `prefer` bc_in_memory_linkable)
    
    902
    +                              `choose` obj_linkable
    
    903
    +
    
    899 904
     --               pprTraceM "recomp" (ppr just_bc <+> ppr just_o)
    
    900 905
                    -- 2. Decide which of the products we will need
    
    901 906
                    let recomp_linkable_result = case () of
    
    902 907
                          _ | backendCanReuseLoadedCode (backend lcl_dflags) ->
    
    903
    -                           case bc_linkable of
    
    904
    -                             -- If bytecode is available for Interactive then don't load object code
    
    905
    -                             UpToDateItem _ -> just_bc
    
    906
    -                             _ -> case obj_linkable of
    
    907
    -                                     -- If o is availabe, then just use that
    
    908
    -                                     UpToDateItem _ -> just_o
    
    909
    -                                     _ -> outOfDateItemBecause MissingBytecode Nothing
    
    908
    +                           if gopt Opt_WriteByteCode lcl_dflags
    
    909
    +                              -- If the byte-code artifact needs to be produced, then we certainly need bytecode.
    
    910
    +                              then justBytecode <$> definitely_bc
    
    911
    +                              else justBytecode <$> maybe_bc
    
    910 912
                             -- Need object files for making object files
    
    911 913
                             | backendWritesFiles (backend lcl_dflags) ->
    
    912 914
                                if gopt Opt_ByteCodeAndObjectCode lcl_dflags
    
    ... ... @@ -924,6 +926,20 @@ hscRecompStatus
    924 926
                        msg $ NeedsRecompile reason
    
    925 927
                        return $ HscRecompNeeded $ Just $ mi_iface_hash $ checked_iface
    
    926 928
     
    
    929
    +-- | Prefer requires both arguments to be up-to-date.
    
    930
    +-- but prefers to use the second argument.
    
    931
    +prefer :: MaybeValidated Linkable -> MaybeValidated Linkable -> MaybeValidated Linkable
    
    932
    +prefer (UpToDateItem _) (UpToDateItem l2) = UpToDateItem l2
    
    933
    +prefer r1 _ = r1
    
    934
    +
    
    935
    +-- | Disjunction, choose either argument, but prefer the first one.
    
    936
    +-- Report the failure of the first argument.
    
    937
    +choose :: MaybeValidated Linkable -> MaybeValidated Linkable -> MaybeValidated Linkable
    
    938
    +choose (UpToDateItem l1) _ = UpToDateItem l1
    
    939
    +choose _ (UpToDateItem l2) = UpToDateItem l2
    
    940
    +choose l1 _ = l1
    
    941
    +
    
    942
    +
    
    927 943
     -- | Check that the .o files produced by compilation are already up-to-date
    
    928 944
     -- or not.
    
    929 945
     checkObjects :: DynFlags -> Maybe Linkable -> ModSummary -> IO (MaybeValidated Linkable)
    
    ... ... @@ -959,34 +975,24 @@ checkObjects dflags mb_old_linkable summary = do
    959 975
     -- | Check to see if we can reuse the old linkable, by this point we will
    
    960 976
     -- have just checked that the old interface matches up with the source hash, so
    
    961 977
     -- no need to check that again here
    
    962
    -checkByteCode :: HscEnv -> ModIface -> ModDetails -> ModSummary -> Maybe Linkable -> IO (MaybeValidated Linkable)
    
    963
    -checkByteCode hsc_env iface mod_details mod_sum mb_old_linkable =
    
    978
    +checkByteCodeInMemory :: HscEnv -> ModSummary -> Maybe Linkable -> IO (MaybeValidated Linkable)
    
    979
    +checkByteCodeInMemory hsc_env mod_sum mb_old_linkable =
    
    964 980
       case mb_old_linkable of
    
    965 981
         Just old_linkable
    
    966 982
           | not (linkableIsNativeCodeOnly old_linkable)
    
    983
    +      -- If `-fwrite-byte-code` is enabled, then check that the .gbc file is
    
    984
    +      -- up-to-date with the linkable we have in our hand.
    
    985
    +      -- If ms_bytecode_date is Nothing, then the .gbc file does not exist yet.
    
    986
    +      -- Otherwise, check that the date matches the linkable date exactly.
    
    987
    +      , if gopt Opt_WriteByteCode (hsc_dflags hsc_env)
    
    988
    +          then maybe False (linkableTime old_linkable ==) (ms_bytecode_date mod_sum)
    
    989
    +          else True
    
    967 990
           -> return $ (UpToDateItem old_linkable)
    
    968
    -    _ -> do
    
    969
    -      load_result <- loadByteCodeFromCoreBindings hsc_env iface mod_details mod_sum
    
    970
    -      case load_result of
    
    971
    -        Just linkable -> return $ UpToDateItem linkable
    
    972
    -        Nothing -> loadByteCode hsc_env iface mod_details mod_sum
    
    973
    -
    
    974
    --- | First attempt to use the bytecode object linkable if it exists.
    
    975
    --- If that doesn't exist, then try to load bytecode from whole core bindings.
    
    976
    -loadByteCode :: HscEnv -> ModIface -> ModDetails -> ModSummary -> IO (MaybeValidated Linkable)
    
    977
    -loadByteCode hsc_env iface mod_details mod_sum = do
    
    978
    -  obj_result <- loadByteCodeFromObject hsc_env mod_sum
    
    979
    -  case obj_result of
    
    980
    -    Just linkable -> return $ UpToDateItem linkable
    
    981
    -    Nothing -> do
    
    982
    -      core_result <- loadByteCodeFromCoreBindings hsc_env iface mod_details mod_sum
    
    983
    -      case core_result of
    
    984
    -        Just linkable -> return $ UpToDateItem linkable
    
    985
    -        Nothing -> return $ outOfDateItemBecause MissingBytecode Nothing
    
    991
    +    _ -> return $ outOfDateItemBecause MissingBytecode Nothing
    
    986 992
     
    
    987 993
     -- | Load bytecode from a ".gbc" object file if it exists and is up-to-date
    
    988
    -loadByteCodeFromObject :: HscEnv -> ModSummary -> IO (Maybe Linkable)
    
    989
    -loadByteCodeFromObject hsc_env mod_sum = do
    
    994
    +checkByteCodeFromObject :: HscEnv -> ModSummary -> IO (MaybeValidated Linkable)
    
    995
    +checkByteCodeFromObject hsc_env mod_sum = do
    
    990 996
       let
    
    991 997
         obj_fn = ml_bytecode_file (ms_location mod_sum)
    
    992 998
         obj_date = ms_bytecode_date mod_sum
    
    ... ... @@ -994,14 +1000,18 @@ loadByteCodeFromObject hsc_env mod_sum = do
    994 1000
       case (,) <$> obj_date <*> if_date of
    
    995 1001
         Just (obj_date, if_date)
    
    996 1002
           | obj_date >= if_date -> do
    
    997
    -        bco <- readBinByteCode hsc_env obj_fn
    
    998
    -        Just <$> loadByteCodeObjectLinkable hsc_env obj_date (ms_location mod_sum) bco
    
    999
    -    _ -> return Nothing
    
    1003
    +          -- Don't force this if we reuse the linkable already loaded into memory, but we have to check
    
    1004
    +          -- that the one we have on disk would be suitable as well.
    
    1005
    +          linkable <- unsafeInterleaveIO $ do
    
    1006
    +            bco <- readBinByteCode hsc_env obj_fn
    
    1007
    +            loadByteCodeObjectLinkable hsc_env obj_date (ms_location mod_sum) bco
    
    1008
    +          return $ UpToDateItem linkable
    
    1009
    +    _ -> return $ outOfDateItemBecause MissingBytecode Nothing
    
    1000 1010
     
    
    1001 1011
     -- | Attempt to load bytecode from whole core bindings in the interface if they exist.
    
    1002 1012
     -- This is a legacy code-path, these days it should be preferred to use the bytecode object linkable.
    
    1003
    -loadByteCodeFromCoreBindings :: HscEnv -> ModIface -> ModDetails -> ModSummary -> IO (Maybe Linkable)
    
    1004
    -loadByteCodeFromCoreBindings hsc_env iface mod_details mod_sum = do
    
    1013
    +checkByteCodeFromCoreBindings :: HscEnv -> ModIface -> ModDetails -> ModSummary -> IO (MaybeValidated Linkable)
    
    1014
    +checkByteCodeFromCoreBindings hsc_env iface mod_details mod_sum = do
    
    1005 1015
         let
    
    1006 1016
           this_mod   = ms_mod mod_sum
    
    1007 1017
           if_date    = fromJust $ ms_iface_date mod_sum
    
    ... ... @@ -1010,8 +1020,8 @@ loadByteCodeFromCoreBindings hsc_env iface mod_details mod_sum = do
    1010 1020
             ~(bco, fos) <- unsafeInterleaveIO $
    
    1011 1021
                            compileWholeCoreBindings hsc_env (md_types mod_details) fi
    
    1012 1022
             let bco' = LazyBCOs bco fos
    
    1013
    -        return (Just (Linkable if_date this_mod (NE.singleton bco')))
    
    1014
    -      _ -> return Nothing
    
    1023
    +        return $ UpToDateItem (Linkable if_date this_mod (NE.singleton bco'))
    
    1024
    +      _ -> return $ outOfDateItemBecause MissingBytecode Nothing
    
    1015 1025
     
    
    1016 1026
     --------------------------------------------------------------
    
    1017 1027
     -- Compilers
    
    ... ... @@ -2231,8 +2241,11 @@ generateAndWriteByteCode hsc_env cgguts mod_location = do
    2231 2241
     
    
    2232 2242
     generateAndWriteByteCodeLinkable :: HscEnv -> CgInteractiveGuts -> ModLocation -> IO Linkable
    
    2233 2243
     generateAndWriteByteCodeLinkable hsc_env cgguts mod_location = do
    
    2234
    -  bco_time <- getCurrentTime
    
    2235 2244
       bco_object <- generateAndWriteByteCode hsc_env cgguts mod_location
    
    2245
    +  -- Either, get the same time as the .gbc file if it exists, or just the current time.
    
    2246
    +  -- It's important the time of the linkable matches the time of the .gbc file for recompilation
    
    2247
    +  -- checking.
    
    2248
    +  bco_time <- maybe getCurrentTime pure =<< modificationTimeIfExists (ml_bytecode_file mod_location)
    
    2236 2249
       loadByteCodeObjectLinkable hsc_env bco_time mod_location bco_object
    
    2237 2250
     
    
    2238 2251
     -- | Write foreign sources and foreign stubs to temporary files and compile them.
    

  • compiler/GHC/Driver/Pipeline.hs
    ... ... @@ -279,8 +279,8 @@ compileOne' mHscMessage
    279 279
              -- was set), force it to generate byte-code. This is NOT transitive and
    
    280 280
              -- only applies to direct targets.
    
    281 281
              | loadAsByteCode
    
    282
    -         = ( interpreterBackend
    
    283
    -           , gopt_set (lcl_dflags { backend = interpreterBackend }) Opt_ForceRecomp
    
    282
    +         = ( bytecodeBackend
    
    283
    +           , gopt_set (lcl_dflags { backend = bytecodeBackend }) Opt_ForceRecomp
    
    284 284
                )
    
    285 285
     
    
    286 286
              | otherwise
    

  • compiler/GHC/Driver/Session.hs
    ... ... @@ -1925,9 +1925,9 @@ dynamic_flags_deps = [
    1925 1925
       , make_ord_flag defFlag "fno-code"         (NoArg ((upd $ \d ->
    
    1926 1926
                       d { ghcLink=NoLink }) >> setBackend noBackend))
    
    1927 1927
       , make_ord_flag defFlag "fbyte-code"
    
    1928
    -      (noArgM $ \dflags -> do
    
    1929
    -        setBackend interpreterBackend
    
    1930
    -        pure $ flip gopt_unset Opt_ByteCodeAndObjectCode (gopt_set dflags Opt_ByteCode))
    
    1928
    +      (NoArg $ do
    
    1929
    +        setBackend bytecodeBackend
    
    1930
    +        upd $ \dflags -> flip gopt_unset Opt_ByteCodeAndObjectCode (gopt_set dflags Opt_ByteCode))
    
    1931 1931
       , make_ord_flag defFlag "fobject-code"     $ noArgM $ \dflags -> do
    
    1932 1932
           setBackend $ platformDefaultBackend (targetPlatform dflags)
    
    1933 1933
           dflags' <- liftEwM getCmdLineState
    
    ... ... @@ -3185,10 +3185,8 @@ parseReexportedModule str
    3185 3185
     -- If we're linking a binary, then only backends that produce object
    
    3186 3186
     -- code are allowed (requests for other target types are ignored).
    
    3187 3187
     setBackend :: Backend -> DynP ()
    
    3188
    -setBackend l = upd $ \ dfs ->
    
    3189
    -  if ghcLink dfs /= LinkBinary || backendWritesFiles l
    
    3190
    -  then dfs{ backend = l }
    
    3191
    -  else dfs
    
    3188
    +setBackend l = do
    
    3189
    +  upd $ \ dfs -> dfs{ backend = l }
    
    3192 3190
     
    
    3193 3191
     -- Changes the target only if we're compiling object code.  This is
    
    3194 3192
     -- used by -fasm and -fllvm, which switch from one to the other, but
    
    ... ... @@ -3707,6 +3705,11 @@ makeDynFlagsConsistent dflags
    3707 3705
             setGeneralFlag' Opt_ExternalInterpreter $
    
    3708 3706
             addWay' WayDyn dflags
    
    3709 3707
     
    
    3708
    + | LinkBinary <- ghcLink dflags
    
    3709
    + , gopt Opt_ByteCode dflags
    
    3710
    +    = loop (dflags { ghcLink = NoLink })
    
    3711
    +           "Byte-code linking does not currently support linking an executable, enabling -no-link"
    
    3712
    +
    
    3710 3713
      | LinkInMemory <- ghcLink dflags
    
    3711 3714
      , not (gopt Opt_ExternalInterpreter dflags)
    
    3712 3715
      , targetWays_ dflags /= hostFullWays
    

  • docs/users_guide/phases.rst
    ... ... @@ -860,6 +860,19 @@ Options affecting code generation
    860 860
         then any modules which are required to be compiled for Template Haskell evaluation
    
    861 861
         will generate byte-code rather than object code.
    
    862 862
     
    
    863
    +.. ghc-flag:: -fwrite-byte-code
    
    864
    +    :shortdesc: Write byte-code object files
    
    865
    +    :type: dynamic
    
    866
    +    :category: codegen
    
    867
    +
    
    868
    +    Write byte-code files (``.gbc``) when byte-code is generated.
    
    869
    +    These files can be used to avoid recompiling modules when using the byte-code
    
    870
    +    interpreter.
    
    871
    +
    
    872
    +    By default when using :ghc-flag:`-fbyte-code` no byte-code files are written.
    
    873
    +    This flag is implied by :ghc-flag:`-fbyte-code-and-object-code`.
    
    874
    +
    
    875
    +
    
    863 876
     
    
    864 877
     .. _options-linker:
    
    865 878
     
    

  • docs/users_guide/separate_compilation.rst
    ... ... @@ -423,6 +423,25 @@ Redirecting the compilation output(s)
    423 423
         Finally, the option ``-hcsuf`` ⟨suffix⟩ will change the ``.hc`` file
    
    424 424
         suffix for compiler-generated intermediate C files.
    
    425 425
     
    
    426
    +.. ghc-flag:: -gbcsuf ⟨suffix⟩
    
    427
    +    :shortdesc: set the suffix to use for bytecode files
    
    428
    +    :type: dynamic
    
    429
    +    :category:
    
    430
    +
    
    431
    +    The option ``-gbcsuf`` ⟨suffix⟩ will change the ``.gbc`` file
    
    432
    +    suffix for bytecode files to whatever you specify. This is useful
    
    433
    +    when you want to avoid conflicts between different bytecode versions
    
    434
    +    or when building with different flags.
    
    435
    +
    
    436
    +.. ghc-flag:: -gbcdir ⟨dir⟩
    
    437
    +    :shortdesc: set the directory for bytecode files
    
    438
    +    :type: dynamic
    
    439
    +    :category:
    
    440
    +
    
    441
    +    The option ``-gbcdir`` ⟨dir⟩ will change the directory where
    
    442
    +    bytecode files (``.gbc``) are placed. By default, bytecode files
    
    443
    +    are placed in the same directory as the source files.
    
    444
    +
    
    426 445
     .. _keeping-intermediates:
    
    427 446
     
    
    428 447
     Keeping Intermediate Files
    

  • ghc/Main.hs
    ... ... @@ -169,9 +169,9 @@ main' postLoadMode units dflags0 args flagWarnings = do
    169 169
       let dflt_backend = backend dflags0
    
    170 170
           (mode, bcknd, link)
    
    171 171
              = case postLoadMode of
    
    172
    -               DoInteractive   -> (CompManager, interpreterBackend,  LinkInMemory)
    
    173
    -               DoEval _        -> (CompManager, interpreterBackend,  LinkInMemory)
    
    174
    -               DoRun           -> (CompManager, interpreterBackend,  LinkInMemory)
    
    172
    +               DoInteractive   -> (CompManager, bytecodeBackend,  LinkInMemory)
    
    173
    +               DoEval _        -> (CompManager, bytecodeBackend,  LinkInMemory)
    
    174
    +               DoRun           -> (CompManager, bytecodeBackend,  LinkInMemory)
    
    175 175
                    DoMake          -> (CompManager, dflt_backend, LinkBinary)
    
    176 176
                    DoBackpack      -> (CompManager, dflt_backend, LinkBinary)
    
    177 177
                    DoMkDependHS    -> (MkDepend,    dflt_backend, LinkBinary)