summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Eisenberg <eir@cis.upenn.edu>2014-04-05 13:56:00 -0400
committerRichard Eisenberg <eir@cis.upenn.edu>2014-04-05 17:25:45 -0400
commitd468cd376ffc02cf9f4755275a316be914c482be (patch)
tree3ae0b3da074be5aab808d13658bb3b0d52bde3ae
parente81d110e7ddd381e53c3af4fbd261d29edd16725 (diff)
downloadhaskell-d468cd376ffc02cf9f4755275a316be914c482be.tar.gz
Fix #8958.
We now do role inference on stupid datatype contexts, allowing a lightweight role annotation syntax.
-rw-r--r--compiler/typecheck/TcTyClsDecls.lhs3
-rw-r--r--compiler/typecheck/TcTyDecls.lhs4
-rw-r--r--testsuite/tests/ghci/scripts/ghci031.stdout4
-rw-r--r--testsuite/tests/rename/should_fail/rnfail055.stderr5
-rw-r--r--testsuite/tests/roles/should_compile/T8958.hs13
-rw-r--r--testsuite/tests/roles/should_compile/T8958.stderr49
-rw-r--r--testsuite/tests/roles/should_compile/all.T1
7 files changed, 74 insertions, 5 deletions
diff --git a/compiler/typecheck/TcTyClsDecls.lhs b/compiler/typecheck/TcTyClsDecls.lhs
index d0f7814abf..3a589a9ce1 100644
--- a/compiler/typecheck/TcTyClsDecls.lhs
+++ b/compiler/typecheck/TcTyClsDecls.lhs
@@ -780,7 +780,8 @@ tcDataDefn rec_info tc_name tvs kind
= do { extra_tvs <- tcDataKindSig kind
; let final_tvs = tvs ++ extra_tvs
roles = rti_roles rec_info tc_name
- ; stupid_theta <- tcHsContext ctxt
+ ; stupid_tc_theta <- tcHsContext ctxt
+ ; stupid_theta <- zonkTcTypeToTypes emptyZonkEnv stupid_tc_theta
; kind_signatures <- xoptM Opt_KindSignatures
; is_boot <- tcIsHsBoot -- Are we compiling an hs-boot file?
diff --git a/compiler/typecheck/TcTyDecls.lhs b/compiler/typecheck/TcTyDecls.lhs
index a75618b75e..ed9a5b7661 100644
--- a/compiler/typecheck/TcTyDecls.lhs
+++ b/compiler/typecheck/TcTyDecls.lhs
@@ -709,6 +709,8 @@ irTyCon tc
; unless (all (== Nominal) old_roles) $ -- also catches data families,
-- which don't want or need role inference
do { whenIsJust (tyConClass_maybe tc) (irClass tc_name)
+ ; addRoleInferenceInfo tc_name (tyConTyVars tc) $
+ mapM_ (irType emptyVarSet) (tyConStupidTheta tc) -- See #8958
; mapM_ (irDataCon tc_name) (visibleDataCons $ algTyConRhs tc) }}
| Just (SynonymTyCon ty) <- synTyConRhs_maybe tc
@@ -778,7 +780,7 @@ lookupRoles tc
Just roles -> return roles
Nothing -> return $ tyConRoles tc }
--- tries to update a role; won't even update a role "downwards"
+-- tries to update a role; won't ever update a role "downwards"
updateRole :: Role -> TyVar -> RoleM ()
updateRole role tv
= do { var_ns <- getVarNs
diff --git a/testsuite/tests/ghci/scripts/ghci031.stdout b/testsuite/tests/ghci/scripts/ghci031.stdout
index d90cc7aa00..796433e1b7 100644
--- a/testsuite/tests/ghci/scripts/ghci031.stdout
+++ b/testsuite/tests/ghci/scripts/ghci031.stdout
@@ -1 +1,3 @@
-data Eq a => D a = C a -- Defined at ghci031.hs:7:1
+type role D nominal
+data Eq a => D a = C a
+ -- Defined at ghci031.hs:7:1
diff --git a/testsuite/tests/rename/should_fail/rnfail055.stderr b/testsuite/tests/rename/should_fail/rnfail055.stderr
index ed17c5c5e6..99ed2d6f12 100644
--- a/testsuite/tests/rename/should_fail/rnfail055.stderr
+++ b/testsuite/tests/rename/should_fail/rnfail055.stderr
@@ -32,9 +32,10 @@ RnFail055.hs-boot:12:1:
RnFail055.hs-boot:14:1:
Type constructor ‘T2’ has conflicting definitions in the module
and its hs-boot file
- Main module: type role T2 representational phantom
+ Main module: type role T2 representational nominal
data Eq b => T2 a b = T2 a
- Boot file: data Eq a => T2 a b = T2 a
+ Boot file: type role T2 nominal representational
+ data Eq a => T2 a b = T2 a
RnFail055.hs-boot:16:11:
T3 is exported by the hs-boot file, but not exported by the module
diff --git a/testsuite/tests/roles/should_compile/T8958.hs b/testsuite/tests/roles/should_compile/T8958.hs
new file mode 100644
index 0000000000..b3c2910e2e
--- /dev/null
+++ b/testsuite/tests/roles/should_compile/T8958.hs
@@ -0,0 +1,13 @@
+{-# LANGUAGE RoleAnnotations, DatatypeContexts, IncoherentInstances,
+ FlexibleInstances #-}
+
+module T8958 where
+
+class Nominal a
+instance Nominal a
+
+class Representational a
+instance Representational a
+type role Representational representational
+
+newtype (Nominal k, Representational v) => Map k v = MkMap [(k,v)]
diff --git a/testsuite/tests/roles/should_compile/T8958.stderr b/testsuite/tests/roles/should_compile/T8958.stderr
new file mode 100644
index 0000000000..e40865fc64
--- /dev/null
+++ b/testsuite/tests/roles/should_compile/T8958.stderr
@@ -0,0 +1,49 @@
+
+T8958.hs:1:31: Warning:
+ -XDatatypeContexts is deprecated: It was widely considered a misfeature, and has been removed from the Haskell language.
+TYPE SIGNATURES
+TYPE CONSTRUCTORS
+ Map :: * -> * -> *
+ newtype (Nominal k, Representational v) => Map k v
+ No C type associated
+ Roles: [nominal, representational]
+ RecFlag NonRecursive, Promotable
+ = MkMap :: [(k, v)] -> Map k v Stricts: _
+ FamilyInstance: none
+ Nominal :: * -> Constraint
+ class Nominal a
+ Roles: [nominal]
+ RecFlag NonRecursive
+ Representational :: * -> Constraint
+ class Representational a
+ Roles: [representational]
+ RecFlag NonRecursive
+COERCION AXIOMS
+ axiom T8958.NTCo:Map :: Map k v = [(k, v)]
+INSTANCES
+ instance [incoherent] Representational a
+ -- Defined at T8958.hs:10:10
+ instance [incoherent] Nominal a -- Defined at T8958.hs:7:10
+Dependent modules: []
+Dependent packages: [base, ghc-prim, integer-gmp]
+
+==================== Typechecker ====================
+AbsBinds [a] []
+ {Exports: [T8958.$fRepresentationala <= $dRepresentational_aJ6
+ <>]
+ Exported types: T8958.$fRepresentationala [InlPrag=[ALWAYS] CONLIKE]
+ :: forall a. Representational a
+ [LclIdX[DFunId],
+ Str=DmdType,
+ Unf=DFun: \ (@ a) -> T8958.D:Representational TYPE a]
+ Binds: $dRepresentational_aJ6 = T8958.D:Representational}
+AbsBinds [a] []
+ {Exports: [T8958.$fNominala <= $dNominal_aJ7
+ <>]
+ Exported types: T8958.$fNominala [InlPrag=[ALWAYS] CONLIKE]
+ :: forall a. Nominal a
+ [LclIdX[DFunId],
+ Str=DmdType,
+ Unf=DFun: \ (@ a) -> T8958.D:Nominal TYPE a]
+ Binds: $dNominal_aJ7 = T8958.D:Nominal}
+
diff --git a/testsuite/tests/roles/should_compile/all.T b/testsuite/tests/roles/should_compile/all.T
index f77e61f55d..4555b0f84e 100644
--- a/testsuite/tests/roles/should_compile/all.T
+++ b/testsuite/tests/roles/should_compile/all.T
@@ -5,3 +5,4 @@ test('Roles4', only_ways('normal'), compile, ['-ddump-tc'])
test('Roles13', only_ways('normal'), compile, ['-ddump-simpl -dsuppress-uniques'])
test('Roles14', only_ways('normal'), compile, ['-ddump-tc'])
test('RolesIArray', only_ways('normal'), compile, [''])
+test('T8958', only_ways('normal'), compile, ['-ddump-tc'])