Andreas Klebinger pushed to branch wip/andreask/enable_ghci_opt at Glasgow Haskell Compiler / GHC

Commits:

11 changed files:

Changes:

  • changelog.d/T25955.md
    1
    +section: ghci
    
    2
    +issues: #25955
    
    3
    +mrs: !15773
    
    4
    +synopsis:
    
    5
    +  Allow optimizations for GHCi by default.
    
    6
    +description:
    
    7
    +  GHCi used to force -O0 because it had no support for certain features
    
    8
    +  introduced during optimization of programs. E.g. unboxed tuples.
    
    9
    +  We believe all of those have been addressed now so we can allow -O to take effect
    
    10
    +  when targeting the bytecode backend/GHCi.
    
    11
    +
    
    12
    +  However there might still be bugs when using -O and the interpreter.
    
    13
    +  And the simplifier is heavily tuned for targeting the non-bytecode backends
    
    14
    +  so performance improvements are not a given.
    
    15
    +
    
    16
    +  The old behaviour can be restored by passing `-funoptimized-core-for-interpreter`
    
    17
    +  to GHC/ghci.
    
    18
    +

  • compiler/GHC/Driver/Backend.hs
    ... ... @@ -20,9 +20,6 @@ especially the driver. Examples include the following:
    20 20
      * Property `backendValidityOfCImport` says whether the back end can
    
    21 21
        import foreign C functions.
    
    22 22
     
    
    23
    - * Property `backendForcesOptimization0` says whether the back end can
    
    24
    -   be used with optimization levels higher than `-O0`.
    
    25
    -
    
    26 23
      * Property `backendCDefs` tells the compiler driver, "if you're using
    
    27 24
        this back end, then these are the command-line flags you should add
    
    28 25
        to any invocation of the C compiler."
    
    ... ... @@ -88,7 +85,6 @@ module GHC.Driver.Backend
    88 85
        , backendGeneratesHc
    
    89 86
        , backendSptIsDynamic
    
    90 87
        , backendSupportsBreakpoints
    
    91
    -   , backendForcesOptimization0
    
    92 88
        , backendNeedsFullWays
    
    93 89
        , backendSupportsHpc
    
    94 90
        , backendSupportsCImport
    
    ... ... @@ -680,17 +676,6 @@ backendSupportsBreakpoints = \case
    680 676
       Named Bytecode -> True
    
    681 677
       Named NoBackend   -> False
    
    682 678
     
    
    683
    --- | If this flag is set, then the driver forces the
    
    684
    --- optimization level to 0, issuing a warning message if
    
    685
    --- the command line requested a higher optimization level.
    
    686
    -backendForcesOptimization0 :: Backend -> Bool
    
    687
    -backendForcesOptimization0 (Named NCG)         = False
    
    688
    -backendForcesOptimization0 (Named LLVM)        = False
    
    689
    -backendForcesOptimization0 (Named ViaC)        = False
    
    690
    -backendForcesOptimization0 (Named JavaScript)  = False
    
    691
    -backendForcesOptimization0 (Named Bytecode) = True
    
    692
    -backendForcesOptimization0 (Named NoBackend)   = False
    
    693
    -
    
    694 679
     -- | I don't understand exactly how this works.  But if
    
    695 680
     -- this flag is set *and* another condition is met, then
    
    696 681
     -- @ghc/Main.hs@ will alter the `DynFlags` so that all the
    

  • compiler/GHC/Driver/DynFlags.hs
    ... ... @@ -1229,7 +1229,6 @@ defaultFlags settings
    1229 1229
           Opt_CompactUnwind,
    
    1230 1230
           Opt_ShowErrorContext,
    
    1231 1231
           Opt_SuppressStgReps,
    
    1232
    -      Opt_UnoptimizedCoreForInterpreter,
    
    1233 1232
           Opt_SpecialiseIncoherents,
    
    1234 1233
           Opt_WriteSelfRecompInfo
    
    1235 1234
         ]
    

  • compiler/GHC/Driver/Session.hs
    ... ... @@ -3819,15 +3819,6 @@ makeDynFlagsConsistent dflags
    3819 3819
         = loop (gopt_set dflags Opt_PIC)
    
    3820 3820
                "Enabling -fPIC as it is always on for this platform"
    
    3821 3821
     
    
    3822
    - | backendForcesOptimization0 (backend dflags)
    
    3823
    - , gopt Opt_UnoptimizedCoreForInterpreter dflags
    
    3824
    - , let (dflags', changed) = updOptLevelChanged 0 dflags
    
    3825
    - , changed
    
    3826
    -    = loop dflags' $
    
    3827
    -      "Ignoring optimization flags since they are experimental for the " ++
    
    3828
    -      backendDescription (backend dflags) ++
    
    3829
    -      ". Pass -fno-unoptimized-core-for-interpreter to enable this feature."
    
    3830
    -
    
    3831 3822
      | LinkInMemory <- ghcLink dflags
    
    3832 3823
      , not (gopt Opt_ExternalInterpreter dflags)
    
    3833 3824
      , hostIsProfiled
    

  • docs/users_guide/debugging.rst
    ... ... @@ -1252,19 +1252,18 @@ Other
    1252 1252
         :type: dynamic
    
    1253 1253
     
    
    1254 1254
         :since: 9.8.1
    
    1255
    -    :default: enabled
    
    1255
    +    :default: disabled
    
    1256 1256
     
    
    1257
    -    At the moment, ghci disables optimizations, because not all passes
    
    1258
    -    are compatible with the interpreter.
    
    1259
    -    This option can be used to override this check, e.g.
    
    1260
    -    ``ghci -O2 -fno-unoptimized-core-for-interpreter``.
    
    1261
    -    It is not recommended for normal use and can cause a compiler panic.
    
    1257
    +    At the moment, optimizations are used with the interpreter are on by default.
    
    1258
    +    In case this causes errors or compatibility issues this option can be used to override
    
    1259
    +    the behaviour, e.g.
    
    1260
    +    ``ghci -O2 -funoptimized-core-for-interpreter``.
    
    1262 1261
     
    
    1263 1262
         Note that this has an effect on the debugger interface: With optimizations
    
    1264 1263
         in play, free variables in breakpoints may now be substituted with complex
    
    1265
    -    expressions.
    
    1266
    -    Those cannot be stored in breakpoints, so any free variable that refers to
    
    1267
    -    optimized code will not be inspectable when this flag is enabled.
    
    1264
    +    expressions. This means disabling optimizations can improve the debugging experience.
    
    1265
    +    As otherwise those variables cannot be stored in breakpoints, so any free variable that refers to
    
    1266
    +    optimized code will not be inspectable when this flag is disabled.
    
    1268 1267
     
    
    1269 1268
     .. ghc-flag:: -fadd-bco-name
    
    1270 1269
         :shortdesc: Add ``BCO_NAME`` instructions in generated bytecode.
    

  • docs/users_guide/extending_ghc.rst
    ... ... @@ -1750,10 +1750,10 @@ decision-making code depends on the code’s form.
    1750 1750
     -  If your decision-making is driven by an equality or inequality
    
    1751 1751
        predicate, an equivalent predicate may already be defined in module
    
    1752 1752
        ``GHC.Driver.Backend``. For example, if your client wants to be
    
    1753
    -   sure that optimization levels above ``-O0`` are permitted, it might
    
    1754
    -   have originally compared ``backend /= Interpreter``. But now there is
    
    1753
    +   sure that breakpoints are supported, it might
    
    1754
    +   have originally compared ``backend == Interpreter``. But now there is
    
    1755 1755
        a predicate for that: it is
    
    1756
    -   ``not (backendForcesOptimization0 backend)``.
    
    1756
    +   ``backendSupportsBreakpoints backend``.
    
    1757 1757
     
    
    1758 1758
        If the predicate you want is not already defined, you will have to
    
    1759 1759
        fall back on the more general strategy defined below.
    

  • docs/users_guide/ghci.rst
    ... ... @@ -3678,7 +3678,7 @@ The interpreter can't load modules with foreign export declarations!
    3678 3678
         Unfortunately not. We haven't implemented it yet. Please compile any
    
    3679 3679
         offending modules by hand before loading them into GHCi.
    
    3680 3680
     
    
    3681
    -:ghc-flag:`-O` is ineffective in GHCi!
    
    3681
    +:ghc-flag:`-O` is experimental in GHCi!
    
    3682 3682
     
    
    3683 3683
         .. index::
    
    3684 3684
            single: optimization; and GHCi
    
    ... ... @@ -3686,11 +3686,12 @@ The interpreter can't load modules with foreign export declarations!
    3686 3686
         Before GHC 9.8, optimizations were considered too unstable to be used with
    
    3687 3687
         the bytecode interpreter.
    
    3688 3688
         This restriction has been lifted, but is still regarded as experimental and
    
    3689
    -    guarded by :ghc-flag:`-funoptimized-core-for-interpreter`, which is enabled
    
    3690
    -    by default.
    
    3691
    -    In order to use optimizations, run: ::
    
    3689
    +    guarded by :ghc-flag:`-funoptimized-core-for-interpreter`. Starting with
    
    3690
    +    10.0 it is enabled by default.
    
    3692 3691
     
    
    3693
    -      ghci -fno-unoptimized-core-for-interpreter -O
    
    3692
    +    If this causes issue you can disable it by using: ::
    
    3693
    +
    
    3694
    +      ghci -funoptimized-core-for-interpreter -O
    
    3694 3695
     
    
    3695 3696
     Concurrent threads don't carry on running when GHCi is waiting for input.
    
    3696 3697
         This should work, as long as your GHCi was built with the
    

  • testsuite/tests/ghc-api/T10052/T10052.stderr deleted
    1
    -
    
    2
    -when making flags consistent: warning: [GHC-74335] [-Winconsistent-flags]
    
    3
    -    Ignoring optimization flags since they are experimental for the byte-code interpreter. Pass -fno-unoptimized-core-for-interpreter to enable this feature.

  • testsuite/tests/ghci/prog-mhu002/prog-mhu002c.stdout
    ... ... @@ -11,7 +11,6 @@ other dynamic, non-language, flag settings:
    11 11
       -fignore-hpc-changes
    
    12 12
       -fno-ghci-history
    
    13 13
       -fimplicit-import-qualified
    
    14
    -  -fno-unoptimized-core-for-interpreter
    
    15 14
       -fshow-warning-groups
    
    16 15
       -fprefer-byte-code
    
    17 16
       -fbreak-points
    
    ... ... @@ -30,7 +29,6 @@ other dynamic, non-language, flag settings:
    30 29
       -fignore-hpc-changes
    
    31 30
       -fno-ghci-history
    
    32 31
       -fimplicit-import-qualified
    
    33
    -  -fno-unoptimized-core-for-interpreter
    
    34 32
       -fshow-warning-groups
    
    35 33
       -fprefer-byte-code
    
    36 34
       -fbreak-points
    
    ... ... @@ -47,7 +45,6 @@ other dynamic, non-language, flag settings:
    47 45
       -fignore-hpc-changes
    
    48 46
       -fno-ghci-history
    
    49 47
       -fimplicit-import-qualified
    
    50
    -  -fno-unoptimized-core-for-interpreter
    
    51 48
       -fshow-warning-groups
    
    52 49
       -fprefer-byte-code
    
    53 50
       -fbreak-points
    
    ... ... @@ -64,7 +61,6 @@ other dynamic, non-language, flag settings:
    64 61
       -fignore-hpc-changes
    
    65 62
       -fno-ghci-history
    
    66 63
       -fimplicit-import-qualified
    
    67
    -  -fno-unoptimized-core-for-interpreter
    
    68 64
       -fshow-warning-groups
    
    69 65
       -fprefer-byte-code
    
    70 66
       -fbreak-points
    
    ... ... @@ -81,7 +77,6 @@ other dynamic, non-language, flag settings:
    81 77
       -fignore-hpc-changes
    
    82 78
       -fno-ghci-history
    
    83 79
       -fimplicit-import-qualified
    
    84
    -  -fno-unoptimized-core-for-interpreter
    
    85 80
       -fshow-warning-groups
    
    86 81
       -fprefer-byte-code
    
    87 82
       -fbreak-points
    

  • testsuite/tests/ghci/should_fail/T10549.stderr deleted
    1
    -
    
    2
    -when making flags consistent: warning: [GHC-74335] [-Winconsistent-flags (in -Wdefault)]
    
    3
    -    Ignoring optimization flags since they are experimental for the byte-code interpreter. Pass -fno-unoptimized-core-for-interpreter to enable this feature.

  • testsuite/tests/th/T8333.stderr deleted
    1
    -
    
    2
    -when making flags consistent: warning: [GHC-74335] [-Winconsistent-flags (in -Wdefault)]
    
    3
    -    Ignoring optimization flags since they are experimental for the byte-code interpreter. Pass -fno-unoptimized-core-for-interpreter to enable this feature.