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
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
Alexander Kaznacheev
GHC
Commits
5e86ea50
Commit
5e86ea50
authored
11 years ago
by
Joachim Breitner
Browse files
Options
Downloads
Patches
Plain Diff
TcDeriv: s/isomorphism/coercible
in comments and function names, to use less names for the same thing.
parent
fac831fd
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
compiler/typecheck/TcDeriv.lhs
+19
-19
19 additions, 19 deletions
compiler/typecheck/TcDeriv.lhs
with
19 additions
and
19 deletions
compiler/typecheck/TcDeriv.lhs
+
19
−
19
View file @
5e86ea50
...
@@ -274,9 +274,9 @@ clause. The last arg is the new instance type.
...
@@ -274,9 +274,9 @@ clause. The last arg is the new instance type.
We must pass the superclasses; the newtype might be an instance
We must pass the superclasses; the newtype might be an instance
of them in a different way than the representation type
of them in a different way than the representation type
E.g. newtype Foo a = Foo a deriving( Show, Num, Eq )
E.g. newtype Foo a = Foo a deriving( Show, Num, Eq )
Then the Show instance is not done via
isomorphism
; it shows
Then the Show instance is not done via
Coercible
; it shows
Foo 3 as "Foo 3"
Foo 3 as "Foo 3"
The Num instance is derived via
isomorphism
, but the Show superclass
The Num instance is derived via
Coercible
, but the Show superclass
dictionary must the Show instance for Foo, *not* the Show dictionary
dictionary must the Show instance for Foo, *not* the Show dictionary
gotten from the Num dictionary. So we must build a whole new dictionary
gotten from the Num dictionary. So we must build a whole new dictionary
not just use the Num one. The instance we want is something like:
not just use the Num one. The instance we want is something like:
...
@@ -977,7 +977,7 @@ mkPolyKindedTypeableEqn orig tvs cls tycon tc_args mtheta
...
@@ -977,7 +977,7 @@ mkPolyKindedTypeableEqn orig tvs cls tycon tc_args mtheta
= ptext (sLit "Derived Typeable instance must be of form")
= ptext (sLit "Derived Typeable instance must be of form")
<+> parens (ptext (sLit "Typeable") <+> ppr tycon)
<+> parens (ptext (sLit "Typeable") <+> ppr tycon)
----------------------
inferConstraints :: Class -> [TcType]
inferConstraints :: Class -> [TcType]
-> TyCon -> [TcType]
-> TyCon -> [TcType]
-> TcM ThetaType
-> TcM ThetaType
...
@@ -1327,23 +1327,23 @@ checkFlag flag (dflags, _, _)
...
@@ -1327,23 +1327,23 @@ checkFlag flag (dflags, _, _)
[s] -> s
[s] -> s
other -> pprPanic "checkFlag" (ppr other)
other -> pprPanic "checkFlag" (ppr other)
std_class_via_
iso
:: Class -> Bool
std_class_via_
coercible
:: Class -> Bool
-- These standard classes can be derived for a newtype
-- These standard classes can be derived for a newtype
-- using the
isomorphism
trick *even if no -XGeneralizedNewtypeDeriving
-- using the
coercible
trick *even if no -XGeneralizedNewtypeDeriving
-- because giving so gives the same results as generating the boilerplate
-- because giving so gives the same results as generating the boilerplate
std_class_via_
iso
clas
std_class_via_
coercible
clas
= classKey clas `elem` [eqClassKey, ordClassKey, ixClassKey, boundedClassKey]
= classKey clas `elem` [eqClassKey, ordClassKey, ixClassKey, boundedClassKey]
-- Not Read/Show because they respect the type
-- Not Read/Show because they respect the type
-- Not Enum, because newtypes are never in Enum
-- Not Enum, because newtypes are never in Enum
non_
iso
_class :: Class -> Bool
non_
coercible
_class :: Class -> Bool
-- *Never* derive Read, Show, Typeable, Data, Generic, Generic1 by
isomorphism
,
-- *Never* derive Read, Show, Typeable, Data, Generic, Generic1 by
Coercible
,
-- even with -XGeneralizedNewtypeDeriving
-- even with -XGeneralizedNewtypeDeriving
-- Also, avoid Traversable, as the
iso
-derived instance and the "normal"-derived
-- Also, avoid Traversable, as the
Coercible
-derived instance and the "normal"-derived
-- instance behave differently if there's a non-lawful Applicative out there.
-- instance behave differently if there's a non-lawful Applicative out there.
-- Besides, with roles,
iso
-deriving Traversable is ill-roled.
-- Besides, with roles,
Coercible
-deriving Traversable is ill-roled.
non_
iso
_class cls
non_
coercible
_class cls
= classKey cls `elem` ([ readClassKey, showClassKey, dataClassKey
= classKey cls `elem` ([ readClassKey, showClassKey, dataClassKey
, genClassKey, gen1ClassKey, typeableClassKey
, genClassKey, gen1ClassKey, typeableClassKey
, traversableClassKey ]
, traversableClassKey ]
...
@@ -1402,7 +1402,7 @@ mkNewTypeEqn :: CtOrigin -> DynFlags -> [Var] -> Class
...
@@ -1402,7 +1402,7 @@ mkNewTypeEqn :: CtOrigin -> DynFlags -> [Var] -> Class
mkNewTypeEqn orig dflags tvs
mkNewTypeEqn orig dflags tvs
cls cls_tys tycon tc_args rep_tycon rep_tc_args mtheta
cls cls_tys tycon tc_args rep_tycon rep_tc_args mtheta
-- Want: instance (...) => cls (cls_tys ++ [tycon tc_args]) where ...
-- Want: instance (...) => cls (cls_tys ++ [tycon tc_args]) where ...
| might_derive_via_
isomorphism
&& (newtype_deriving || std_class_via_
iso
cls)
| might_derive_via_
coercible
&& (newtype_deriving || std_class_via_
coercible
cls)
= do { traceTc "newtype deriving:" (ppr tycon <+> ppr rep_tys <+> ppr all_preds)
= do { traceTc "newtype deriving:" (ppr tycon <+> ppr rep_tys <+> ppr all_preds)
; dfun_name <- new_dfun_name cls tycon
; dfun_name <- new_dfun_name cls tycon
; loc <- getSrcSpanM
; loc <- getSrcSpanM
...
@@ -1419,12 +1419,12 @@ mkNewTypeEqn orig dflags tvs
...
@@ -1419,12 +1419,12 @@ mkNewTypeEqn orig dflags tvs
= case checkSideConditions dflags mtheta cls cls_tys rep_tycon rep_tc_args of
= case checkSideConditions dflags mtheta cls cls_tys rep_tycon rep_tc_args of
CanDerive -> go_for_it -- Use the standard H98 method
CanDerive -> go_for_it -- Use the standard H98 method
DerivableClassError msg -- Error with standard class
DerivableClassError msg -- Error with standard class
| might_derive_via_
isomorphism
-> bale_out (msg $$ suggest_nd)
| might_derive_via_
coercible
-> bale_out (msg $$ suggest_nd)
| otherwise
-> bale_out msg
| otherwise -> bale_out msg
NonDerivableClass -- Must use newtype deriving
NonDerivableClass -- Must use newtype deriving
| newtype_deriving
-> bale_out cant_derive_err -- Too hard, even with newtype deriving
| newtype_deriving -> bale_out cant_derive_err -- Too hard, even with newtype deriving
| might_derive_via_
isomorphism
-> bale_out (non_std $$ suggest_nd) -- Try newtype deriving!
| might_derive_via_
coercible
-> bale_out (non_std $$ suggest_nd) -- Try newtype deriving!
| otherwise
-> bale_out non_std
| otherwise -> bale_out non_std
where
where
newtype_deriving = xopt Opt_GeneralizedNewtypeDeriving dflags
newtype_deriving = xopt Opt_GeneralizedNewtypeDeriving dflags
go_for_it = mk_data_eqn orig tvs cls tycon tc_args rep_tycon rep_tc_args mtheta
go_for_it = mk_data_eqn orig tvs cls tycon tc_args rep_tycon rep_tc_args mtheta
...
@@ -1509,8 +1509,8 @@ mkNewTypeEqn orig dflags tvs
...
@@ -1509,8 +1509,8 @@ mkNewTypeEqn orig dflags tvs
-- Figuring out whether we can only do this newtype-deriving thing
-- Figuring out whether we can only do this newtype-deriving thing
-- See Note [Determining whether newtype-deriving is appropriate]
-- See Note [Determining whether newtype-deriving is appropriate]
might_derive_via_
isomorphism
might_derive_via_
coercible
= not (non_
iso
_class cls)
= not (non_
coercible
_class cls)
&& arity_ok
&& arity_ok
&& eta_ok
&& eta_ok
&& ats_ok
&& ats_ok
...
...
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