diff options
-rw-r--r-- | compiler/typecheck/TcRnDriver.hs | 12 | ||||
-rw-r--r-- | compiler/typecheck/TcTyDecls.hs | 6 | ||||
-rw-r--r-- | docs/users_guide/7.12.1-notes.xml | 13 | ||||
-rw-r--r-- | docs/users_guide/separate_compilation.xml | 2 | ||||
-rw-r--r-- | testsuite/tests/rename/should_fail/rnfail055.stderr | 41 | ||||
-rw-r--r-- | testsuite/tests/roles/should_compile/T9204b.hs | 5 | ||||
-rw-r--r-- | testsuite/tests/roles/should_compile/T9204b.hs-boot | 3 | ||||
-rw-r--r-- | testsuite/tests/roles/should_compile/T9204b2.hs | 3 | ||||
-rw-r--r-- | testsuite/tests/roles/should_compile/all.T | 1 | ||||
-rw-r--r-- | testsuite/tests/roles/should_fail/Roles12.stderr | 5 | ||||
-rw-r--r-- | testsuite/tests/roles/should_fail/T9204.stderr | 5 | ||||
-rw-r--r-- | testsuite/tests/typecheck/should_fail/tcfail220.stderr | 10 |
12 files changed, 68 insertions, 38 deletions
diff --git a/compiler/typecheck/TcRnDriver.hs b/compiler/typecheck/TcRnDriver.hs index 60a6860066..f75ca64c25 100644 --- a/compiler/typecheck/TcRnDriver.hs +++ b/compiler/typecheck/TcRnDriver.hs @@ -460,7 +460,7 @@ tcRnImports hsc_env import_decls ************************************************************************ -} -tcRnSrcDecls :: ModDetails +tcRnSrcDecls :: ModDetails -> Maybe (Located [LIE RdrName]) -- Exports -> [LHsDecl RdrName] -- Declarations -> TcM TcGblEnv @@ -736,7 +736,7 @@ checkHiBootIface' :: [ClsInst] -> TypeEnv -> [AvailInfo] -- Variant which doesn't require a full TcGblEnv; you could get the -- local components from another ModDetails. -- --- We return a list of "impedence-matching" bindings for the dfuns +-- We return a list of "impedence-matching" bindings for the dfuns -- defined in the hs-boot file, such as -- $fxEqT = $fEqT -- We need these because the module and hi-boot file might differ in @@ -996,9 +996,9 @@ checkBootTyCon tc1 tc2 where roles1 = tyConRoles tc1 roles2 = tyConRoles tc2 - roles_msg = text "The roles do not match." <+> - (text "Roles default to" <+> - quotes (text "representational") <+> text "in boot files") + roles_msg = text "The roles do not match." $$ + (text "Roles on abstract types default to" <+> + quotes (text "representational") <+> text "in boot files.") eqAlgRhs tc (AbstractTyCon dis1) rhs2 | dis1 = check (isDistinctAlgRhs rhs2) --Check compatibility @@ -1921,7 +1921,7 @@ getModuleInterface hsc_env mod = runTcInteractive hsc_env $ loadModuleInterface (ptext (sLit "getModuleInterface")) mod -tcRnLookupRdrName :: HscEnv -> Located RdrName +tcRnLookupRdrName :: HscEnv -> Located RdrName -> IO (Messages, Maybe [Name]) -- ^ Find all the Names that this RdrName could mean, in GHCi tcRnLookupRdrName hsc_env (L loc rdr_name) diff --git a/compiler/typecheck/TcTyDecls.hs b/compiler/typecheck/TcTyDecls.hs index 94442901a9..d279ff5ebc 100644 --- a/compiler/typecheck/TcTyDecls.hs +++ b/compiler/typecheck/TcTyDecls.hs @@ -684,9 +684,9 @@ initialRoleEnv1 is_boot annots_env tc zipWith orElse role_annots (repeat default_role) default_role - | isClassTyCon tc = Nominal - | is_boot = Representational - | otherwise = Phantom + | isClassTyCon tc = Nominal + | is_boot && isAbstractTyCon tc = Representational + | otherwise = Phantom irGroup :: RoleEnv -> [TyCon] -> RoleEnv irGroup env tcs diff --git a/docs/users_guide/7.12.1-notes.xml b/docs/users_guide/7.12.1-notes.xml index 5bdf96d9e1..4dbb0b20cd 100644 --- a/docs/users_guide/7.12.1-notes.xml +++ b/docs/users_guide/7.12.1-notes.xml @@ -59,7 +59,18 @@ See the release notes for base for a description of the <literal>CallStack</literal> type. </para> - </listitem> + </listitem> + <listitem> + <para> + To conform to the common case, the default role assigned to parameters + of datatypes declared in <literal>hs-boot</literal> files is + <literal>representational</literal>. However, if the constructor(s) + for the datatype are given, it makes sense to do normal role inference. + This is now implemented, effectively making the default role for + non-abstract datatypes in <literal>hs-boot</literal> files to be + <literal>phantom</literal>, like it is in regular Haskell code. + </para> + </listitem> </itemizedlist> </sect3> diff --git a/docs/users_guide/separate_compilation.xml b/docs/users_guide/separate_compilation.xml index 07cf76c6c7..f6b2cba0ce 100644 --- a/docs/users_guide/separate_compilation.xml +++ b/docs/users_guide/separate_compilation.xml @@ -878,7 +878,7 @@ methods entirely; but you must either omit them all or put them all in. </para></listitem> <listitem><para> You can include instance declarations just as in Haskell; but omit the "where" part. </para></listitem> -<listitem><para>The default role for class and datatype parameters is now representational. To get another role, use a role annotation. (See <xref linkend="roles"/>.)</para></listitem> +<listitem><para>The default role for abstract datatype parameters is now representational. (An abstract datatype is one with no constructors listed.) To get another role, use a role annotation. (See <xref linkend="roles"/>.)</para></listitem> </itemizedlist> </para> </sect2> diff --git a/testsuite/tests/rename/should_fail/rnfail055.stderr b/testsuite/tests/rename/should_fail/rnfail055.stderr index 05cec42788..4611e867ec 100644 --- a/testsuite/tests/rename/should_fail/rnfail055.stderr +++ b/testsuite/tests/rename/should_fail/rnfail055.stderr @@ -1,55 +1,57 @@ -RnFail055.hs:1:73: Warning: +RnFail055.hs:1:73: warning: -XDatatypeContexts is deprecated: It was widely considered a misfeature, and has been removed from the Haskell language. -RnFail055.hs-boot:1:73: Warning: +RnFail055.hs-boot:1:73: warning: -XDatatypeContexts is deprecated: It was widely considered a misfeature, and has been removed from the Haskell language. -RnFail055.hs-boot:4:1: +RnFail055.hs-boot:4:1: error: Identifier ‘f1’ has conflicting definitions in the module and its hs-boot file Main module: f1 :: Int -> Float Boot file: f1 :: Float -> Int The two types are different -RnFail055.hs-boot:6:1: +RnFail055.hs-boot:6:1: error: Type constructor ‘S1’ has conflicting definitions in the module and its hs-boot file Main module: type S1 a b = (a, b) Boot file: type S1 a b c = (a, b) The types have different kinds -RnFail055.hs-boot:8:1: +RnFail055.hs-boot:8:1: error: Type constructor ‘S2’ has conflicting definitions in the module and its hs-boot file Main module: type S2 a b = forall a1. (a1, b) Boot file: type S2 a b = forall b1. (a, b1) - The roles do not match. Roles default to ‘representational’ in boot files + The roles do not match. + Roles on abstract types default to ‘representational’ in boot files. -RnFail055.hs-boot:12:1: +RnFail055.hs-boot:12:1: error: Type constructor ‘T1’ has conflicting definitions in the module and its hs-boot file Main module: data T1 a b = T1 [b] [a] Boot file: data T1 a b = T1 [a] [b] The constructors do not match: The types for ‘T1’ differ -RnFail055.hs-boot:14:1: +RnFail055.hs-boot:14:1: error: Type constructor ‘T2’ has conflicting definitions in the module and its hs-boot file Main module: type role T2 representational nominal data Eq b => T2 a b = T2 a - Boot file: type role T2 nominal representational + Boot file: type role T2 nominal phantom data Eq a => T2 a b = T2 a - The roles do not match. Roles default to ‘representational’ in boot files + The roles do not match. + Roles on abstract types default to ‘representational’ in boot files. The datatype contexts do not match -RnFail055.hs-boot:16:11: +RnFail055.hs-boot:16:11: error: ‘T3’ is exported by the hs-boot file, but not exported by the module -RnFail055.hs-boot:17:12: +RnFail055.hs-boot:17:12: error: ‘T3'’ is exported by the hs-boot file, but not exported by the module -RnFail055.hs-boot:21:1: +RnFail055.hs-boot:21:1: error: Type constructor ‘T5’ has conflicting definitions in the module and its hs-boot file Main module: data T5 a = T5 {field5 :: a} @@ -57,7 +59,7 @@ RnFail055.hs-boot:21:1: The constructors do not match: The record label lists for ‘T5’ differ -RnFail055.hs-boot:23:1: +RnFail055.hs-boot:23:1: error: Type constructor ‘T6’ has conflicting definitions in the module and its hs-boot file Main module: data T6 = T6 Int @@ -65,20 +67,21 @@ RnFail055.hs-boot:23:1: The constructors do not match: The strictness annotations for ‘T6’ differ -RnFail055.hs-boot:25:1: +RnFail055.hs-boot:25:1: error: Type constructor ‘T7’ has conflicting definitions in the module and its hs-boot file Main module: type role T7 phantom data T7 a where T7 :: a1 -> T7 a Boot file: data T7 a = T7 a - The roles do not match. Roles default to ‘representational’ in boot files + The roles do not match. + Roles on abstract types default to ‘representational’ in boot files. The constructors do not match: The types for ‘T7’ differ -RnFail055.hs-boot:27:22: +RnFail055.hs-boot:27:22: error: ‘RnFail055.m1’ is exported by the hs-boot file, but not exported by the module -RnFail055.hs-boot:28:1: +RnFail055.hs-boot:28:1: error: Class ‘C2’ has conflicting definitions in the module and its hs-boot file Main module: class C2 a b where @@ -88,7 +91,7 @@ RnFail055.hs-boot:28:1: m2 :: a -> b The methods do not match: There are different numbers of methods -RnFail055.hs-boot:29:1: +RnFail055.hs-boot:29:1: error: Class ‘C3’ has conflicting definitions in the module and its hs-boot file Main module: class (Eq a, Ord a) => C3 a diff --git a/testsuite/tests/roles/should_compile/T9204b.hs b/testsuite/tests/roles/should_compile/T9204b.hs new file mode 100644 index 0000000000..d3c974f10c --- /dev/null +++ b/testsuite/tests/roles/should_compile/T9204b.hs @@ -0,0 +1,5 @@ +module T9204b where + +import T9204b2 + +data P a = P diff --git a/testsuite/tests/roles/should_compile/T9204b.hs-boot b/testsuite/tests/roles/should_compile/T9204b.hs-boot new file mode 100644 index 0000000000..fab2a86168 --- /dev/null +++ b/testsuite/tests/roles/should_compile/T9204b.hs-boot @@ -0,0 +1,3 @@ +module T9204b where + +data P a = P diff --git a/testsuite/tests/roles/should_compile/T9204b2.hs b/testsuite/tests/roles/should_compile/T9204b2.hs new file mode 100644 index 0000000000..607192254b --- /dev/null +++ b/testsuite/tests/roles/should_compile/T9204b2.hs @@ -0,0 +1,3 @@ +module T9204b2 where + +import {-# SOURCE #-} T9204b diff --git a/testsuite/tests/roles/should_compile/all.T b/testsuite/tests/roles/should_compile/all.T index 2e0d8ea01c..b740d8ad3e 100644 --- a/testsuite/tests/roles/should_compile/all.T +++ b/testsuite/tests/roles/should_compile/all.T @@ -6,3 +6,4 @@ test('Roles13', only_ways('normal'), compile, ['-ddump-simpl -dsuppress-uniques' test('Roles14', only_ways('normal'), compile, ['-ddump-tc']) test('T8958', [normalise_fun(normalise_errmsg), only_ways('normal')], compile, ['-ddump-tc -dsuppress-uniques']) test('T10263', normal, compile, ['']) +test('T9204b', extra_clean(['T9204b.o-boot', 'T9204b.hi-boot', 'T9204b2.hi', 'T9204b2.o']), multimod_compile, ['T9204b', '-v0']) diff --git a/testsuite/tests/roles/should_fail/Roles12.stderr b/testsuite/tests/roles/should_fail/Roles12.stderr index 874ddca1d3..7dff7f97ec 100644 --- a/testsuite/tests/roles/should_fail/Roles12.stderr +++ b/testsuite/tests/roles/should_fail/Roles12.stderr @@ -1,8 +1,9 @@ -Roles12.hs:5:1: +Roles12.hs:5:1: error: Type constructor ‘T’ has conflicting definitions in the module and its hs-boot file Main module: type role T phantom data T a Boot file: abstract T a - The roles do not match. Roles default to ‘representational’ in boot files + The roles do not match. + Roles on abstract types default to ‘representational’ in boot files. diff --git a/testsuite/tests/roles/should_fail/T9204.stderr b/testsuite/tests/roles/should_fail/T9204.stderr index 9936839284..721e74e74b 100644 --- a/testsuite/tests/roles/should_fail/T9204.stderr +++ b/testsuite/tests/roles/should_fail/T9204.stderr @@ -1,8 +1,9 @@ -T9204.hs:6:1: +T9204.hs:6:1: error: Type constructor ‘D’ has conflicting definitions in the module and its hs-boot file Main module: type role D phantom data D a Boot file: abstract D a - The roles do not match. Roles default to ‘representational’ in boot files + The roles do not match. + Roles on abstract types default to ‘representational’ in boot files. diff --git a/testsuite/tests/typecheck/should_fail/tcfail220.stderr b/testsuite/tests/typecheck/should_fail/tcfail220.stderr index dcb6fbc2e4..6a4e87382d 100644 --- a/testsuite/tests/typecheck/should_fail/tcfail220.stderr +++ b/testsuite/tests/typecheck/should_fail/tcfail220.stderr @@ -1,15 +1,17 @@ [1 of 1] Compiling ShouldFail[sig of Prelude] ( tcfail220.hsig, nothing ) -tcfail220.hsig:4:1: +tcfail220.hsig:4:1: error: Type constructor ‘Bool’ has conflicting definitions in the module and its hsig file Main module: data Bool = False | True - Hsig file: data Bool a b c d = False + Hsig file: type role Bool phantom phantom phantom phantom + data Bool a b c d = False The types have different kinds -tcfail220.hsig:5:1: +tcfail220.hsig:5:1: error: Type constructor ‘Maybe’ has conflicting definitions in the module and its hsig file Main module: data Maybe a = Nothing | Just a - Hsig file: data Maybe a b = Nothing + Hsig file: type role Maybe phantom phantom + data Maybe a b = Nothing The types have different kinds |