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
71e28fd2
Commit
71e28fd2
authored
27 years ago
by
Simon Peyton Jones
Browse files
Options
Downloads
Patches
Plain Diff
[project @ 1998-02-23 23:12:38 by simonpj]
A bit more specialise code
parent
a89cd8f7
Loading
Loading
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ghc/compiler/specialise/Specialise.lhs
+41
-19
41 additions, 19 deletions
ghc/compiler/specialise/Specialise.lhs
with
41 additions
and
19 deletions
ghc/compiler/specialise/Specialise.lhs
+
41
−
19
View file @
71e28fd2
...
...
@@ -736,7 +736,7 @@ We do, however, generate polymorphic, but not overloaded, specialisations:
f :: Eq a => [a] -> b -> b -> b
{#- SPECIALISE f :: [Int] -> b -> b -> b #-}
T
he invariant is this:
Hence, t
he invariant is this:
*** no specialised version is overloaded ***
...
...
@@ -819,11 +819,15 @@ specExpr (Case scrut alts)
---------------- Finally, let is the interesting case --------------------
specExpr (Let (NonRec bndr rhs) body)
= specExpr body `thenSM` \ (body', body_uds) ->
= -- Deal with the body
specExpr body `thenSM` \ (body', body_uds) ->
-- Deal with the RHS, specialising it according
-- to the calls found in the body
specDefn (calls body_uds) (bndr,rhs) `thenSM` \ ((bndr',rhs'), spec_defns, spec_uds) ->
let
all_uds = rhs_uds `plusUDs` body_uds
all_uds =
deleteCalls (
rhs_uds `plusUDs` body_uds
) bndr'
in
if bndr `elementOfIdSet` free_dicts body_uds then
-- This is a dictionary binding; we must pick it up
...
...
@@ -831,7 +835,7 @@ specExpr (Let (NonRec bndr rhs) body)
ASSERT( null spec_defns )
returnSM (body', addDictBind all_uds bndr' rhs')
else if isSpecPragmaId bnd then
else if isSpecPragmaId bnd
r
then
-- SpecPragmaIds are there solely to generate specialisations
-- Just drop the whole binding
ASSERT( null spec_defns )
...
...
@@ -841,7 +845,7 @@ specExpr (Let (NonRec bndr rhs) body)
-- An ordinary binding, so glue it all together
returnSM (
Let (NonRec bndr' rhs') (mkLets spec_defns body'),
deleteCalls
all_uds
bndr'
all_uds
)
specDefn :: CallDetails -- Info on how it is used in its scope
...
...
@@ -857,8 +861,11 @@ specDefn calls (fn, rhs)
| n_tyvars == length rhs_tyvars -- Rhs of fn's defn has right number of big lambdas
&& n_dicts <= length rhs_bndrs -- and enough dict args
&& not (null calls_for_me) -- And there are some calls to specialise
= specExpr body `thenSM` \ (body', body_uds) ->
mapSM (specCall body_uds) calls_for_me `thenSM` \ stuff ->
= -- Specialise the body of the function
specExpr body `thenSM` \ (body', body_uds) ->
-- Make a specialised version for each call in calls_for_me
mapSM (spec_call body_uds) calls_for_me `thenSM` \ stuff ->
let
(spec_defns, spec_uds, spec_env_stuff) = unzip3 stuff
...
...
@@ -867,7 +874,9 @@ specDefn calls (fn, rhs)
fn' = addIdSpecialisations fn spec_env_stuff
in
returnSM ((fn',rhs'), spec_defns, rhs_uds `plusUDs` plusUDList spec_uds)
returnSM ((fn',rhs'),
spec_defns,
rhs_uds `plusUDs` plusUDList spec_uds)
| otherwise -- No calls or RHS doesn't fit our preconceptions
= specExpr rhs `thenSM` \ (rhs', rhs_uds) ->
...
...
@@ -890,37 +899,50 @@ specDefn calls (fn, rhs)
-- Specialise to one particular call pattern
spec_call :: UsageDetails -- From the original body
-> ([Maybe Type], [DictVar]) -- Call instance
-> ((Id, CoreExpr), -- Specialised definition
UsageDetails, -- Usage details from specialised body
([Type], CoreExpr)) -- Info for the Id's SpecEnv
spec_call body_uds (call_ts, call_ds)
= ASSERT( length call_ts == n_tyvars && length call_ds == n_dicts )
--
The c
alls are only recorded for properly-saturated applications
--
C
alls are only recorded for properly-saturated applications
-- Supppose the call is for f [Just t1, Nothing, Just t3, Nothing] [d1, d2]
-- Construct the new binding
-- f1 = /\ b d -> (..body of f..) t1 b t3 d d1 d2
-- and the type of this binder
let
spec_tys = zipNothings call_ts tyvars
spec_rhs = mkTyLam tyvars (mkGenApp rhs (map TyArg spec_tys ++ map VarArg call_ds))
spec_ty = mkForAllTys tyvars (applyTys (idType f) spec_tys)
spec_tyvars = [tyvar | (tyvar, Nothing) <- tyvars `zip` call_tys]
spec_tys = zipWith mk_spec_ty call_ts tyvars
spec_rhs = mkTyLam spec_tyvars $
mkGenApp rhs (map TyArg spec_tys ++ map VarArg call_ds)
spec_id_ty = mkForAllTys spec_tyvars (applyTys (idType f) spec_tys)
mk_spec_ty (Just ty) _ = ty
mk_spec_ty Nothing tyvar = mkTyVarTy tyvar
in
newIdSM f spec_ty `thenSM` \ spec_f ->
newIdSM f spec_
id_
ty `thenSM` \ spec_f ->
-- Construct the stuff for f's spec env
-- [t1,b,t3,d] |-> \d1 d2 -> f1 b d
let
spec_env_rhs = mkValLam call_ds $
mkTyApp (Var spec_f) $
map mkTyVarTy tyvars
spec_env_rhs = mkValLam call_ds $
mkTyApp (Var spec_f) $
map mkTyVarTy spec_tyvars
spec_env_info = (spec_tys, spec_env_rhs)
in
-- Specialise the UDs from f's RHS
specUDs (zipEqual
defn_tv
s call_ts)
(zipEqual rhs_dicts call_ds)
specUDs (zipEqual
rhs_tyvar
s call_ts)
(zipEqual rhs_dicts
call_ds)
body_uds `thenSM` \ spec_uds ->
returnSM ((spec_f, spec_rhs),
spec_uds,
(spec_tys,
spec_env_
rhs)
spec_env_
info
)
\end{code}
...
...
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