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
| Opt_CaseMerge
| Opt_UnboxStrictFields
| Opt_DictsCheap
+ | Opt_RewriteRules
-- misc opts
| Opt_Cpp
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)
( "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 )
]
opt_NoMethodSharing,
opt_NoStateHack,
opt_CprOff,
- opt_RulesOff,
opt_SimplNoPreInlining,
opt_SimplExcessPrecision,
opt_MaxWorkerArgs,
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)
"static",
"funregisterised",
"fext-core",
- "frules-off",
"fcpr-off",
"ferror-spans",
"fPIC"
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}
%* *
%************************************************************************
+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
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
-- 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
<tbody>
<row>
<entry><option>-fcase-merge</option></entry>
- <entry>Enable case-merging</entry>
+ <entry>Enable case-merging. Implied by <option>-O</option>.</entry>
<entry>dynamic</entry>
<entry><option>-fno-case-merge</option></entry>
</row>
<row>
<entry><option>-fdo-eta-reduction</option></entry>
- <entry>Enable eta-reduction</entry>
+ <entry>Enable eta-reduction. Implied by <option>-O</option>.</entry>
<entry>dynamic</entry>
<entry><option>-fno-do-eta-reduction</option></entry>
</row>
</row>
<row>
- <entry><option>-frules-off</option></entry>
- <entry>Switch off all rewrite rules (including rules
- generated by automatic specialisation of overloaded functions)</entry>
- <entry>static</entry>
- <entry><option>-frules-off</option></entry>
- </row>
-
- <row>
<entry><option>-fignore-asserts</option></entry>
<entry>Ignore assertions in the source</entry>
<entry>dynamic</entry>
</row>
<row>
- <entry><option>-fliberate-case-threshold</option></entry>
- <entry>Tweak the liberate-case optimisation (default: 10)</entry>
- <entry>static</entry>
- <entry><option>-fno-liberate-case-threshold</option></entry>
- </row>
-
- <row>
<entry><option>-fomit-interface-pragmas</option></entry>
<entry>Don't generate interface pragmas</entry>
<entry>dynamic</entry>
</row>
<row>
- <entry><option>-fno-cse</option></entry>
- <entry>Turn off common sub-expression</entry>
+ <entry><option>-fcse</option></entry>
+ <entry>Turn on common sub-expression elimination. Implied by <option>-O</option>.</entry>
<entry>dynamic</entry>
- <entry>-</entry>
+ <entry>-fno-cse</entry>
</row>
<row>
- <entry><option>-fno-full-laziness</option></entry>
- <entry>Turn off full laziness (floating bindings outwards).</entry>
+ <entry><option>-ffull-laziness</option></entry>
+ <entry>Turn on full laziness (floating bindings outwards). Implied by <option>-O</option>.</entry>
<entry>dynamic</entry>
- <entry>-ffull-laziness</entry>
+ <entry>-fno-full-laziness</entry>
</row>
<row>
- <entry><option>-fno-pre-inlining</option></entry>
- <entry>Turn off pre-inlining</entry>
- <entry>static</entry>
- <entry>-</entry>
+ <entry><option>-frewrite-rules</option></entry>
+ <entry>Switch on all rewrite rules (including rules
+ generated by automatic specialisation of overloaded functions).
+ Implied by <option>-O</option>. </entry>
+ <entry>dynamic</entry>
+ <entry><option>-fno-rewrite-rules</option></entry>
</row>
<row>
- <entry><option>-fno-strictness</option></entry>
- <entry>Turn off strictness analysis</entry>
+ <entry><option>-fstrictness</option></entry>
+ <entry>Turn on strictness analysis. Implied by <option>-O</option>.</entry>
<entry>dynamic</entry>
- <entry>-</entry>
+ <entry>-fno-strictness</entry>
+ </row>
+
+ <row>
+ <entry><option>-fspec-constr</option></entry>
+ <entry>Turn on the SpecConstr transformation. Implied by <option>-O2</option>.</entry>
+ <entry>dynamic</entry>
+ <entry>-fno-spec-constr</entry>
+ </row>
+
+ <row>
+ <entry><option>-fliberate-case</option></entry>
+ <entry>Turn on the liberate-case transformation. Implied by <option>-O2</option>.</entry>
+ <entry>dynamic</entry>
+ <entry>-fno-liberate-case</entry>
+ </row>
+
+ <row>
+ <entry><option>-fliberate-case-threshold</option></entry>
+ <entry>Tweak the liberate-case optimisation (default: 10)</entry>
+ <entry>static</entry>
+ <entry><option>-fno-liberate-case-threshold</option></entry>
</row>
<row>
<entry>static</entry>
<entry><option>-fno-unfolding-use-threshold</option></entry>
</row>
+
+ <row>
+ <entry><option>-fno-pre-inlining</option></entry>
+ <entry>Turn off pre-inlining</entry>
+ <entry>static</entry>
+ <entry>-</entry>
+ </row>
</tbody>
</tgroup>
</informaltable>