Commit 5df7a7ab authored by afarmer's avatar afarmer Committed by Ben Gamari
Browse files

Don't inline/apply other rules when simplifying a rule RHS.

HERMIT users depend on RULES to specify equational properties. 6.10.2
performed both inlining and simplification in both sides of the rules,
meaning they can't really be used for this. This breaks most HERMIT use
cases.  A separate commit already disabled this for the LHS of rules.
This does so for the RHS.

See Trac #10829 for nofib results.

Reviewed By: austin, bgamari, simonpj

Differential Revision: https://phabricator.haskell.org/D1246

GHC Trac Issues: #10829
parent 2f8f79bd
...@@ -14,7 +14,7 @@ module SimplUtils ( ...@@ -14,7 +14,7 @@ module SimplUtils (
preInlineUnconditionally, postInlineUnconditionally, preInlineUnconditionally, postInlineUnconditionally,
activeUnfolding, activeRule, activeUnfolding, activeRule,
getUnfoldingInRuleMatch, getUnfoldingInRuleMatch,
simplEnvForGHCi, updModeForStableUnfoldings, updModeForRuleLHS, simplEnvForGHCi, updModeForStableUnfoldings, updModeForRules,
-- The continuation type -- The continuation type
SimplCont(..), DupFlag(..), SimplCont(..), DupFlag(..),
...@@ -700,20 +700,25 @@ updModeForStableUnfoldings inline_rule_act current_mode ...@@ -700,20 +700,25 @@ updModeForStableUnfoldings inline_rule_act current_mode
phaseFromActivation (ActiveAfter n) = Phase n phaseFromActivation (ActiveAfter n) = Phase n
phaseFromActivation _ = InitialPhase phaseFromActivation _ = InitialPhase
updModeForRuleLHS :: SimplifierMode -> SimplifierMode updModeForRules :: SimplifierMode -> SimplifierMode
-- See Note [Simplifying RULE LHSs] -- See Note [Simplifying rules]
updModeForRuleLHS current_mode updModeForRules current_mode
= current_mode { sm_phase = InitialPhase = current_mode { sm_phase = InitialPhase
, sm_inline = False , sm_inline = False
, sm_rules = False , sm_rules = False
, sm_eta_expand = False } , sm_eta_expand = False }
{- Note [Simplifying RULE LHSs] {- Note [Simplifying rules]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When simplifying on the LHS of a rule, refrain from all inlining and When simplifying a rule, refrain from any inlining or applying of other RULES.
all RULES. Doing anything to the LHS is plain confusing, because it
means that what the rule matches is not what the user wrote. Doing anything to the LHS is plain confusing, because it means that what the
c.f. Trac #10595, and #10528. rule matches is not what the user wrote. c.f. Trac #10595, and #10528.
Moreover, inlining (or applying rules) on rule LHSs risks introducing
Ticks into the LHS, which makes matching trickier. Trac #10665, #10745.
Doing this to either side confounds tools like HERMIT, which seek to reason
about and apply the RULES as originally written. See Trac #10829.
Note [Inlining in gentle mode] Note [Inlining in gentle mode]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
......
...@@ -2966,13 +2966,11 @@ simplRules env mb_new_nm rules ...@@ -2966,13 +2966,11 @@ simplRules env mb_new_nm rules
= return rule = return rule
simpl_rule rule@(Rule { ru_bndrs = bndrs, ru_args = args simpl_rule rule@(Rule { ru_bndrs = bndrs, ru_args = args
, ru_fn = fn_name, ru_rhs = rhs , ru_fn = fn_name, ru_rhs = rhs })
, ru_act = act }) = do { (env', bndrs') <- simplBinders env bndrs
= do { (env, bndrs') <- simplBinders env bndrs ; let rule_env = updMode updModeForRules env'
; let lhs_env = updMode updModeForRuleLHS env ; args' <- mapM (simplExpr rule_env) args
rhs_env = updMode (updModeForStableUnfoldings act) env ; rhs' <- simplExpr rule_env rhs
; args' <- mapM (simplExpr lhs_env) args
; rhs' <- simplExpr rhs_env rhs
; return (rule { ru_bndrs = bndrs' ; return (rule { ru_bndrs = bndrs'
, ru_fn = mb_new_nm `orElse` fn_name , ru_fn = mb_new_nm `orElse` fn_name
, ru_args = args' , ru_args = args'
......
...@@ -4,7 +4,5 @@ ...@@ -4,7 +4,5 @@
forall ($dMyFunctor :: MyFunctor []) (irred :: Domain [] Int). forall ($dMyFunctor :: MyFunctor []) (irred :: Domain [] Int).
shared @ [] $dMyFunctor irred shared @ [] $dMyFunctor irred
= bar_$sshared = bar_$sshared
"SPEC/Foo myfmap @ []" [ALWAYS]
forall (tpl :: MyFunctor []). myfmap @ [] tpl = $cmyfmap
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment