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
9ca5c88e
Commit
9ca5c88e
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
Use foldTyCo for coVarsOfType
parent
0e59afd6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
32 deletions
+57
-32
compiler/types/TyCoFVs.hs
compiler/types/TyCoFVs.hs
+57
-32
No files found.
compiler/types/TyCoFVs.hs
View file @
9ca5c88e
...
...
@@ -334,6 +334,63 @@ shallowTcvFolder = TyCoFolder { tcf_tyvar = do_tcv, tcf_covar = do_tcv
do_hole
_
_
=
mempty
-- Ignore coercion holes
{- *********************************************************************
* *
Free coercion variables
* *
********************************************************************* -}
{- Note [Finding free coercion varibles]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here we are only interested in the free /coercion/ variables.
We can achieve this through a slightly differnet TyCo folder.
Notice that we look deeply, into kinds.
See #14880.
-}
coVarsOfType
::
Type
->
CoVarSet
coVarsOfTypes
::
[
Type
]
->
CoVarSet
coVarsOfCo
::
Coercion
->
CoVarSet
coVarsOfCos
::
[
Coercion
]
->
CoVarSet
coVarsOfType
ty
=
runTyCoVars
(
deep_cv_ty
ty
)
coVarsOfTypes
tys
=
runTyCoVars
(
deep_cv_tys
tys
)
coVarsOfCo
co
=
runTyCoVars
(
deep_cv_co
co
)
coVarsOfCos
cos
=
runTyCoVars
(
deep_cv_cos
cos
)
deep_cv_ty
::
Type
->
Endo
CoVarSet
deep_cv_tys
::
[
Type
]
->
Endo
CoVarSet
deep_cv_co
::
Coercion
->
Endo
CoVarSet
deep_cv_cos
::
[
Coercion
]
->
Endo
CoVarSet
(
deep_cv_ty
,
deep_cv_tys
,
deep_cv_co
,
deep_cv_cos
)
=
foldTyCo
deepCoVarFolder
emptyVarSet
deepCoVarFolder
::
TyCoFolder
TyCoVarSet
(
Endo
CoVarSet
)
deepCoVarFolder
=
TyCoFolder
{
tcf_tyvar
=
do_tyvar
,
tcf_covar
=
do_covar
,
tcf_hole
=
do_hole
,
tcf_tycobinder
=
do_bndr
}
where
do_tyvar
_
_
=
mempty
-- This do_tyvar means we won't see any CoVars in this
-- TyVar's kind. This may be wrong; but it's the way it's
-- always been. And its awkward to change, because
-- the tyvar won't end up in the accumulator, so
-- we'd look repeatedly. Blargh.
do_covar
is
v
=
Endo
do_it
where
do_it
acc
|
v
`
elemVarSet
`
is
=
acc
|
v
`
elemVarSet
`
acc
=
acc
|
otherwise
=
appEndo
(
deep_cv_ty
(
varType
v
))
$
acc
`
extendVarSet
`
v
do_bndr
is
tcv
_
=
extendVarSet
is
tcv
do_hole
is
hole
=
do_covar
is
(
coHoleCoVar
hole
)
-- See Note [CoercionHoles and coercion free variables]
-- in TyCoRep
{- *********************************************************************
* *
Closing over kinds
...
...
@@ -556,38 +613,6 @@ tyCoFVsOfCos [] fv_cand in_scope acc = emptyFV fv_cand in_scope acc
tyCoFVsOfCos
(
co
:
cos
)
fv_cand
in_scope
acc
=
(
tyCoFVsOfCo
co
`
unionFV
`
tyCoFVsOfCos
cos
)
fv_cand
in_scope
acc
------------- Extracting the CoVars of a type or coercion -----------
{- Note [CoVarsOfX and the InterestingVarFun]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The coVarsOfType, coVarsOfTypes, coVarsOfCo, and coVarsOfCos functions are
implemented in terms of the respective FV equivalents (tyCoFVsOf...), rather
than the VarSet-based flavors (tyCoVarsOf...), despite the performance
considerations outlined in Note [Free variables of types].
This is because FV includes the InterestingVarFun, which is useful here,
because we can cleverly use it to restrict our calculations to CoVars - this
is what getCoVarSet achieves.
See #14880.
-}
getCoVarSet
::
FV
->
CoVarSet
getCoVarSet
fv
=
snd
(
fv
isCoVar
emptyVarSet
(
[]
,
emptyVarSet
))
coVarsOfType
::
Type
->
CoVarSet
coVarsOfType
ty
=
getCoVarSet
(
tyCoFVsOfType
ty
)
coVarsOfTypes
::
[
Type
]
->
TyCoVarSet
coVarsOfTypes
tys
=
getCoVarSet
(
tyCoFVsOfTypes
tys
)
coVarsOfCo
::
Coercion
->
CoVarSet
coVarsOfCo
co
=
getCoVarSet
(
tyCoFVsOfCo
co
)
coVarsOfCos
::
[
Coercion
]
->
CoVarSet
coVarsOfCos
cos
=
getCoVarSet
(
tyCoFVsOfCos
cos
)
----- Whether a covar is /Almost Devoid/ in a type or coercion ----
-- | Given a covar and a coercion, returns True if covar is almost devoid in
...
...
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