From: simonpj@microsoft.com Date: Fri, 4 May 2007 12:24:05 +0000 (+0000) Subject: Make -frewrite-rules into a dynamic flag; off for -O0 X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=commitdiff_plain;h=5943ce90c9c9d4319eec3cfe1fb3315f018e1c45 Make -frewrite-rules into a dynamic flag; off for -O0 Argubly rewrite rules should not fire with -O0, and it turns out that when compiling GHC.Base with -O0 we get a crash if the rewrite rules do fire (see Note [Scoping for Builtin rules] in PrelRules). So unless someone yells, rewrite rules are off with -O0. The new (now dynamic) flag is -frewrite rules (with -fno-rewrite-rules to disable) The old (static) flag -frules-off is gone. --- diff --git a/compiler/deSugar/DsListComp.lhs b/compiler/deSugar/DsListComp.lhs index 6a25a75..ccc1a7b 100644 --- a/compiler/deSugar/DsListComp.lhs +++ b/compiler/deSugar/DsListComp.lhs @@ -50,7 +50,7 @@ dsListComp lquals body elt_ty let quals = map unLoc lquals in - if opt_RulesOff || dopt Opt_IgnoreInterfacePragmas dflags + if not (dopt Opt_RewriteRules dflags) || dopt Opt_IgnoreInterfacePragmas dflags -- Either rules are switched off, or we are ignoring what there are; -- Either way foldr/build won't happen, so use the more efficient -- Wadler-style desugaring diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs index 7022964..046e2b2 100644 --- a/compiler/main/DynFlags.hs +++ b/compiler/main/DynFlags.hs @@ -192,6 +192,7 @@ data DynFlag | Opt_CaseMerge | Opt_UnboxStrictFields | Opt_DictsCheap + | Opt_RewriteRules -- misc opts | Opt_Cpp @@ -560,12 +561,16 @@ optLevelFlags :: [([Int], DynFlag)] optLevelFlags = [ ([0], Opt_IgnoreInterfacePragmas) , ([0], Opt_OmitInterfacePragmas) + , ([1,2], Opt_IgnoreAsserts) + , ([1,2], Opt_RewriteRules) -- Off for -O0; see Note [Scoping for Builtin rules] + -- in PrelRules , ([1,2], Opt_DoEtaReduction) , ([1,2], Opt_CaseMerge) , ([1,2], Opt_Strictness) , ([1,2], Opt_CSE) , ([1,2], Opt_FullLaziness) + , ([2], Opt_LiberateCase) , ([2], Opt_SpecConstr) @@ -1067,7 +1072,8 @@ fFlags = [ ( "asm-mangling", Opt_DoAsmMangling ), ( "print-bind-result", Opt_PrintBindResult ), ( "force-recomp", Opt_ForceRecomp ), - ( "hpc-no-auto", Opt_Hpc_No_Auto ) + ( "hpc-no-auto", Opt_Hpc_No_Auto ), + ( "rewrite-rules", Opt_RewriteRules ) ] diff --git a/compiler/main/StaticFlags.hs b/compiler/main/StaticFlags.hs index fbdcb68..2a8c4dc 100644 --- a/compiler/main/StaticFlags.hs +++ b/compiler/main/StaticFlags.hs @@ -42,7 +42,6 @@ module StaticFlags ( opt_NoMethodSharing, opt_NoStateHack, opt_CprOff, - opt_RulesOff, opt_SimplNoPreInlining, opt_SimplExcessPrecision, opt_MaxWorkerArgs, @@ -296,7 +295,6 @@ opt_Flatten = lookUp FSLIT("-fflatten") opt_NoStateHack = lookUp FSLIT("-fno-state-hack") opt_NoMethodSharing = lookUp FSLIT("-fno-method-sharing") opt_CprOff = lookUp FSLIT("-fcpr-off") -opt_RulesOff = lookUp FSLIT("-frules-off") -- Switch off CPR analysis in the new demand analyser opt_MaxWorkerArgs = lookup_def_int "-fmax-worker-args" (10::Int) @@ -369,7 +367,6 @@ isStaticFlag f = "static", "funregisterised", "fext-core", - "frules-off", "fcpr-off", "ferror-spans", "fPIC" diff --git a/compiler/prelude/PrelRules.lhs b/compiler/prelude/PrelRules.lhs index 69901d3..165d008 100644 --- a/compiler/prelude/PrelRules.lhs +++ b/compiler/prelude/PrelRules.lhs @@ -44,9 +44,7 @@ import Name ( Name, nameOccName ) import Outputable import FastString import StaticFlags ( opt_SimplExcessPrecision ) - -import Data.Bits as Bits ( Bits(..), shiftL, shiftR ) - -- shiftL and shiftR were not always methods of Bits +import Data.Bits as Bits import Data.Word ( Word ) \end{code} @@ -447,6 +445,33 @@ dataToTagRule other = Nothing %* * %************************************************************************ +Note [Scoping for Builtin rules] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +When compiling a (base-package) module that defines one of the +functions mentioned in the RHS of a built-in rule, there's a danger +that we'll see + + f = ...(eq String x).... + + ....and lower down... + + eqString = ... + +Then a rewrite would give + + f = ...(eqString x)... + ....and lower down... + eqString = ... + +and lo, eqString is not in scope. This only really matters when we get to code +generation. With -O we do a GlomBinds step that does a new SCC analysis on the whole +set of bindings, which sorts out the dependency. Without -O we don't do any rule +rewriting so again we are fine. + +(This whole thing doesn't show up for non-built-in rules because their dependencies +are explicit.) + + \begin{code} builtinRules :: [CoreRule] -- Rules for non-primops that can't be expressed using a RULE pragma diff --git a/compiler/simplCore/SimplUtils.lhs b/compiler/simplCore/SimplUtils.lhs index 2e9c83d..3b304c6 100644 --- a/compiler/simplCore/SimplUtils.lhs +++ b/compiler/simplCore/SimplUtils.lhs @@ -774,10 +774,11 @@ activeInline env id where prag = idInlinePragma id -activeRule :: SimplEnv -> Maybe (Activation -> Bool) +activeRule :: DynFlags -> SimplEnv -> Maybe (Activation -> Bool) -- Nothing => No rules at all -activeRule env - | opt_RulesOff = Nothing +activeRule dflags env + | not (dopt Opt_RewriteRules dflags) + = Nothing -- Rewriting is off | otherwise = case getMode env of SimplGently -> Just isAlwaysActive diff --git a/compiler/simplCore/Simplify.lhs b/compiler/simplCore/Simplify.lhs index f27dcab..aab8925 100644 --- a/compiler/simplCore/Simplify.lhs +++ b/compiler/simplCore/Simplify.lhs @@ -967,7 +967,7 @@ completeCall env var cont -- So it's up to the programmer: rules can cause divergence ; let in_scope = getInScope env rules = getRules env - maybe_rule = case activeRule env of + maybe_rule = case activeRule dflags env of Nothing -> Nothing -- No rules apply Just act_fn -> lookupRule act_fn in_scope rules var args diff --git a/docs/users_guide/flags.xml b/docs/users_guide/flags.xml index 2f14127..b2c398d 100644 --- a/docs/users_guide/flags.xml +++ b/docs/users_guide/flags.xml @@ -928,7 +928,7 @@ - Enable case-merging + Enable case-merging. Implied by . dynamic @@ -942,7 +942,7 @@ - Enable eta-reduction + Enable eta-reduction. Implied by . dynamic @@ -962,14 +962,6 @@ - - Switch off all rewrite rules (including rules - generated by automatic specialisation of overloaded functions) - static - - - - Ignore assertions in the source dynamic @@ -984,13 +976,6 @@ - - Tweak the liberate-case optimisation (default: 10) - static - - - - Don't generate interface pragmas dynamic @@ -1021,31 +1006,54 @@ - - Turn off common sub-expression + + Turn on common sub-expression elimination. Implied by . dynamic - - + -fno-cse - - Turn off full laziness (floating bindings outwards). + + Turn on full laziness (floating bindings outwards). Implied by . dynamic - -ffull-laziness + -fno-full-laziness - - Turn off pre-inlining - static - - + + Switch on all rewrite rules (including rules + generated by automatic specialisation of overloaded functions). + Implied by . + dynamic + - - Turn off strictness analysis + + Turn on strictness analysis. Implied by . dynamic - - + -fno-strictness + + + + + Turn on the SpecConstr transformation. Implied by . + dynamic + -fno-spec-constr + + + + + Turn on the liberate-case transformation. Implied by . + dynamic + -fno-liberate-case + + + + + Tweak the liberate-case optimisation (default: 10) + static + @@ -1089,6 +1097,13 @@ static + + + + Turn off pre-inlining + static + - +