Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
GHC
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
4,326
Issues
4,326
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
390
Merge Requests
390
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Glasgow Haskell Compiler
GHC
Commits
0e59afd6
Commit
0e59afd6
authored
Jan 16, 2020
by
Simon Peyton Jones
Committed by
Ben Gamari
Feb 06, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify closeOverKinds
parent
01a1f4fb
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
29 additions
and
23 deletions
+29
-23
compiler/types/TyCoFVs.hs
compiler/types/TyCoFVs.hs
+12
-5
compiler/types/Type.hs
compiler/types/Type.hs
+1
-1
compiler/utils/FV.hs
compiler/utils/FV.hs
+16
-17
No files found.
compiler/types/TyCoFVs.hs
View file @
0e59afd6
...
...
@@ -36,7 +36,7 @@ module TyCoFVs
tyCoVarsOfTypesWellScoped
,
-- * Closing over kinds
closeOverKindsDSet
,
closeOverKinds
FV
,
closeOverKinds
List
,
closeOverKindsDSet
,
closeOverKindsList
,
closeOverKinds
,
)
where
...
...
@@ -54,7 +54,6 @@ import Var
import
FV
import
UniqFM
import
UniqSet
(
nonDetEltsUniqSet
)
import
VarSet
import
VarEnv
import
Util
...
...
@@ -343,10 +342,18 @@ shallowTcvFolder = TyCoFolder { tcf_tyvar = do_tcv, tcf_covar = do_tcv
------------- Closing over kinds -----------------
closeOverKinds
::
TyVarSet
->
TyVarSet
closeOverKinds
::
TyCoVarSet
->
TyCoVarSet
-- For each element of the input set,
-- add the deep free variables of its kind
closeOverKinds
vs
=
nonDetFoldVarSet
do_one
vs
vs
where
do_one
v
acc
=
appEndo
(
deep_ty
(
varType
v
))
acc
{- --------------- Alternative version 1 (using FV) ------------
closeOverKinds = fvVarSet . closeOverKindsFV . nonDetEltsUniqSet
-}
{- ---------------- Alternative version
1 (preferred)
-------------
{- ---------------- Alternative version
2
-------------
-- | Add the kind variables free in the kinds of the tyvars in the given set.
-- Returns a non-deterministic set.
...
...
@@ -368,7 +375,7 @@ closeOverKinds vs
-}
{- ---------------- Alternative version -------------
{- ---------------- Alternative version
3
-------------
-- | Add the kind variables free in the kinds of the tyvars in the given set.
-- Returns a non-deterministic set.
closeOverKinds :: TyVarSet -> TyVarSet
...
...
compiler/types/Type.hs
View file @
0e59afd6
...
...
@@ -149,7 +149,7 @@ module Type (
typeSize
,
occCheckExpand
,
-- ** Closing over kinds
closeOverKindsDSet
,
closeOverKinds
FV
,
closeOverKinds
List
,
closeOverKindsDSet
,
closeOverKindsList
,
closeOverKinds
,
-- * Well-scoped lists of variables
...
...
compiler/utils/FV.hs
View file @
0e59afd6
...
...
@@ -12,7 +12,7 @@ module FV (
FV
,
InterestingVarFun
,
-- * Running the computations
fvVarList
VarSet
,
fvVarList
,
fvVarSet
,
fvDVarSet
,
fvVarList
,
fvVarSet
,
fvDVarSet
,
-- ** Manipulating those computations
unitFV
,
...
...
@@ -46,22 +46,21 @@ type InterestingVarFun = Var -> Bool
-- Merging costs O(n+m) for UniqFM and for UniqDFM there's an additional log
-- factor. It's cheaper to incrementally add to a list and use a set to check
-- for duplicates.
type
FV
=
InterestingVarFun
-- Used for filtering sets as we build them
->
VarSet
-- Locally bound variables
->
([
Var
],
VarSet
)
-- List to preserve ordering and set to check for membership,
-- so that the list doesn't have duplicates
-- For explanation of why using `VarSet` is not deterministic see
-- Note [Deterministic UniqFM] in UniqDFM.
->
([
Var
],
VarSet
)
type
FV
=
InterestingVarFun
-- Used for filtering sets as we build them
->
VarSet
-- Locally bound variables
->
VarAcc
-- Accumulator
->
VarAcc
type
VarAcc
=
([
Var
],
VarSet
)
-- List to preserve ordering and set to check for membership,
-- so that the list doesn't have duplicates
-- For explanation of why using `VarSet` is not deterministic see
-- Note [Deterministic UniqFM] in UniqDFM.
-- Note [FV naming conventions]
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- To get the performance and determinism that FV provides, FV computations
-- need to built up from smaller FV computations and then evaluated with
-- one of `fvVarList`, `fvDVarSet`
, `fvVarListVarSet`.
That means the functions
-- one of `fvVarList`, `fvDVarSet` That means the functions
-- returning FV need to be exported.
--
-- The conventions are:
...
...
@@ -84,26 +83,26 @@ type FV = InterestingVarFun
-- | Run a free variable computation, returning a list of distinct free
-- variables in deterministic order and a non-deterministic set containing
-- those variables.
fvVar
ListVarSet
::
FV
->
([
Var
],
VarSet
)
fvVar
ListVarSet
fv
=
fv
(
const
True
)
emptyVarSet
(
[]
,
emptyVarSet
)
fvVar
Acc
::
FV
->
([
Var
],
VarSet
)
fvVar
Acc
fv
=
fv
(
const
True
)
emptyVarSet
(
[]
,
emptyVarSet
)
-- | Run a free variable computation, returning a list of distinct free
-- variables in deterministic order.
fvVarList
::
FV
->
[
Var
]
fvVarList
=
fst
.
fvVar
ListVarSet
fvVarList
=
fst
.
fvVar
Acc
-- | Run a free variable computation, returning a deterministic set of free
-- variables. Note that this is just a wrapper around the version that
-- returns a deterministic list. If you need a list you should use
-- `fvVarList`.
fvDVarSet
::
FV
->
DVarSet
fvDVarSet
=
mkDVarSet
.
f
st
.
fvVarListVarSe
t
fvDVarSet
=
mkDVarSet
.
f
vVarLis
t
-- | Run a free variable computation, returning a non-deterministic set of
-- free variables. Don't use if the set will be later converted to a list
-- and the order of that list will impact the generated code.
fvVarSet
::
FV
->
VarSet
fvVarSet
=
snd
.
fvVar
ListVarSet
fvVarSet
=
snd
.
fvVar
Acc
-- Note [FV eta expansion]
-- ~~~~~~~~~~~~~~~~~~~~~~~
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment