Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
GHC
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gesh
GHC
Commits
f2137787
Commit
f2137787
authored
27 years ago
by
sof
Browse files
Options
Downloads
Patches
Plain Diff
[project @ 1997-06-05 20:14:14 by sof]
fixed eta-reduction code;removed mkIdentityAlts
parent
ffa8eebf
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ghc/compiler/simplCore/SimplUtils.lhs
+22
-77
22 additions, 77 deletions
ghc/compiler/simplCore/SimplUtils.lhs
with
22 additions
and
77 deletions
ghc/compiler/simplCore/SimplUtils.lhs
+
22
−
77
View file @
f2137787
...
...
@@ -14,15 +14,15 @@ module SimplUtils (
etaExpandCount,
mkIdentityAlts,
simplIdWantsToBeINLINEd,
singleConstructorType, typeOkForCase
) where
IMP_Ubiq(){-uitous-}
#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ <= 201
IMPORT_DELOOPER(SmplLoop) -- paranoia checking
#endif
import BinderInfo
import CmdLineOpts ( opt_DoEtaReduction, SimplifierSwitch(..) )
...
...
@@ -38,13 +38,14 @@ import PrelVals ( augmentId, buildId )
import PrimOp ( primOpIsCheap )
import SimplEnv
import SimplMonad
import Type ( tyVarsOfType, mkForAllTys, mkTyVarTys, isPrimType,
import Type ( tyVarsOfType, mkForAllTys, mkTyVarTys, isPrimType,
getTyVar_maybe,
maybeAppDataTyConExpandingDicts, SYN_IE(Type)
)
import TyCon ( isDataTyCon )
import TysWiredIn ( realWorldStateTy )
import TyVar ( elementOfTyVarSet,
GenTyVar{-instance Eq-} )
import Util ( isIn, panic )
import Util ( isIn, panic
, assertPanic
)
\end{code}
...
...
@@ -269,21 +270,27 @@ etaCoreExpr expr@(Lam bndr body)
other -> expr -- Can't eliminate it, so do nothing at all
where
eta_match (ValBinder v) (VarArg v') = v == v'
eta_match (TyBinder tv) (TyArg ty) = tv `elementOfTyVarSet` tyVarsOfType ty
eta_match (TyBinder tv) (TyArg ty) = case getTyVar_maybe ty of
Nothing -> False
Just tv' -> tv == tv'
eta_match bndr arg = False
residual_ok :: CoreExpr -> Bool -- Checks for type application
-- and function not one of the
-- bound vars
(VarArg v) `mentions` (ValBinder v') = v == v'
(TyArg ty) `mentions` (TyBinder tv) = tv `elementOfTyVarSet` tyVarsOfType ty
bndr `mentions` arg = False
residual_ok (Var v)
= not (
eta_match bndr (VarArg v)
)
= not (
VarArg v `mentions` bndr
)
residual_ok (App fun arg)
|
eta_match
bndr
arg
= False
| otherwise = residual_ok fun
|
arg `mentions`
bndr = False
| otherwise
= residual_ok fun
residual_ok (Coerce coercion ty body)
|
eta_match bndr (TyArg ty)
= False
| otherwise
= residual_ok body
|
TyArg ty `mentions` bndr
= False
| otherwise = residual_ok body
residual_ok other = False -- Safe answer
-- This last clause may seem conservative, but consider:
...
...
@@ -417,68 +424,6 @@ manifestlyCheap other_expr -- look for manifest partial application
\end{code}
Let to case
~~~~~~~~~~~
Given a type generate the case alternatives
C a b -> C a b
if there's one constructor, or
x -> x
if there's many, or if it's a primitive type.
\begin{code}
mkIdentityAlts
:: Type -- type of RHS
-> DemandInfo -- Appropriate demand info
-> SmplM InAlts -- result
mkIdentityAlts rhs_ty demand_info
= case (maybeAppDataTyConExpandingDicts rhs_ty) of
Just (tycon, ty_args, [data_con]) -> -- algebraic type suitable for unpacking
let
inst_con_arg_tys = dataConArgTys data_con ty_args
in
newIds inst_con_arg_tys `thenSmpl` \ new_bindees ->
let
new_binders = [ (b, bad_occ_info) | b <- new_bindees ]
in
returnSmpl (
AlgAlts
[(data_con, new_binders, mkCon data_con [] ty_args (map VarArg new_bindees))]
NoDefault
)
_ -> panic "mkIdentityAlts" -- Should never happen; only called for single-constructor types
where
bad_occ_info = ManyOcc 0 -- Non-committal!
{- SHOULD NEVER HAPPEN
| isPrimType rhs_ty
= newId rhs_ty `thenSmpl` \ binder ->
let
binder_w_info = binder `addIdDemandInfo` demand_info
-- It's occasionally really worth adding the right demand info. Consider
-- let x = E in B
-- where x is sure to be demanded in B
-- We will transform to:
-- case E of x -> B
-- Now suppose that E simplifies to just y; we get
-- case y of x -> B
-- Because x is sure to be demanded, we can eliminate the case
-- even if pedantic-bottoms is on; but we need to have the right
-- demand-info on the default branch of the case. That's what
-- we are doing here.
in
returnSmpl (PrimAlts [] (BindDefault (binder, bad_occ_info) (Var binder)))
-}
\end{code}
\begin{code}
simplIdWantsToBeINLINEd :: Id -> SimplEnv -> Bool
...
...
@@ -515,15 +460,15 @@ idMinArity id = case getIdArity id of
singleConstructorType :: Type -> Bool
singleConstructorType ty
= case (maybeAppDataTyConExpandingDicts ty) of
Just (tycon, ty_args, [con]) -> True
other -> False
Just (tycon, ty_args, [con])
| isDataTyCon tycon
-> True
other
-> False
typeOkForCase :: Type -> Bool
typeOkForCase ty
= case (maybeAppDataTyConExpandingDicts ty) of
Nothing
-> False
Just (tycon, ty_args,
[]) -> Fals
e
Just (tycon, ty_args, non_null_data_cons) -> Tru
e
Just (tycon, ty_args, [])
-> False
Just (tycon, ty_args,
non_null_data_cons) | isDataTyCon tycon -> Tru
e
other -> Fals
e
-- Null data cons => type is abstract, which code gen can't
-- currently handle. (ToDo: when return-in-heap is universal we
-- don't need to worry about this.)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment