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
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
gershomb
GHC
Commits
c1c9cf50
Commit
c1c9cf50
authored
11 years ago
by
Richard Eisenberg
Browse files
Options
Downloads
Patches
Plain Diff
Change default roles for classes to be *nominal*.
parent
ff3904d9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
compiler/typecheck/TcTyDecls.lhs
+15
-12
15 additions, 12 deletions
compiler/typecheck/TcTyDecls.lhs
with
15 additions
and
12 deletions
compiler/typecheck/TcTyDecls.lhs
+
15
−
12
View file @
c1c9cf50
...
...
@@ -557,27 +557,27 @@ emptyRoleAnnots = emptyNameEnv
Note [Role inference]
~~~~~~~~~~~~~~~~~~~~~
The role inference algorithm
uses class, datatype, and synonym definitions
to infer the roles on the
parameters. Although these roles are stored in the
tycons, we can perform this
algorithm on the built tycons, as long as we
don't peek at an as-yet-unknown
roles field! Ah, the magic of laziness.
The role inference algorithm
datatype definitions to infer the roles on the
parameters. Although these roles are stored in the
tycons, we can perform this
algorithm on the built tycons, as long as we
don't peek at an as-yet-unknown
roles field! Ah, the magic of laziness.
First, we choose appropriate initial roles. For families
, roles (including
initial roles) are N. For
all other
types, we start with the role in the
First, we choose appropriate initial roles. For families
and classes, roles
(including
initial roles) are N. For
data
types, we start with the role in the
role annotation (if any), or otherwise use Phantom. This is done in
initialRoleEnv1.
The function irGroup then propagates role information until it reaches a
fixpoint, preferring N over
R,
P and R over P. To aid in this, we have a
monad
RoleM, which is a combination reader and state monad. In its state are
the
current RoleEnv, which gets updated by role propagation, and an update
bit,
which we use to know whether or not we've reached the fixpoint. The
fixpoint, preferring N over
(R or
P
)
and R over P. To aid in this, we have a
monad
RoleM, which is a combination reader and state monad. In its state are
the
current RoleEnv, which gets updated by role propagation, and an update
bit,
which we use to know whether or not we've reached the fixpoint. The
environment of RoleM contains the tycon whose parameters we are inferring, and
a VarEnv from parameters to their positions, so we can update the RoleEnv.
Between tycons, this reader information is missing; it is added by
addRoleInferenceInfo.
There are two kinds of tycons to consider: algebraic ones (
in
cluding classes)
There are two kinds of tycons to consider: algebraic ones (
ex
cluding classes)
and type synonyms. (Remember, families don't participate -- all their parameters
are N.) An algebraic tycon processes each of its datacons, in turn. Note that
a datacon's universally quantified parameters might be different from the parent
...
...
@@ -687,7 +687,10 @@ initialRoleEnv1 is_boot annots_env tc
default_roles = map (const Nominal) kvs ++
zipWith orElse role_annots (repeat default_role)
default_role = if is_boot then Representational else Phantom
default_role
| isClassTyCon tc = Nominal
| is_boot = Representational
| otherwise = Phantom
irGroup :: RoleEnv -> [TyCon] -> RoleEnv
irGroup env tcs
...
...
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