Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Open sidebar
Alex D
GHC
Commits
22f218b7
Commit
22f218b7
authored
Oct 02, 2020
by
Krzysztof Gogolewski
Committed by
Marge Bot
Oct 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Linear types: fix quantification in GADTs (#18790)
parent
ea59fd4d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
9 deletions
+30
-9
compiler/GHC/Rename/HsType.hs
compiler/GHC/Rename/HsType.hs
+6
-2
compiler/GHC/Rename/Module.hs
compiler/GHC/Rename/Module.hs
+3
-1
testsuite/tests/linear/should_compile/MultConstructor.hs
testsuite/tests/linear/should_compile/MultConstructor.hs
+21
-6
No files found.
compiler/GHC/Rename/HsType.hs
View file @
22f218b7
...
...
@@ -31,6 +31,7 @@ module GHC.Rename.HsType (
extractHsTyRdrTyVars
,
extractHsTyRdrTyVarsKindVars
,
extractHsTysRdrTyVars
,
extractRdrKindSigVars
,
extractDataDefnKindVars
,
extractHsTvBndrs
,
extractHsTyArgRdrKiTyVars
,
extractHsScaledTysRdrTyVars
,
forAllOrNothing
,
nubL
)
where
...
...
@@ -1748,6 +1749,9 @@ extractHsTyArgRdrKiTyVars args
extractHsTyRdrTyVars
::
LHsType
GhcPs
->
FreeKiTyVars
extractHsTyRdrTyVars
ty
=
extract_lty
ty
[]
extractHsScaledTysRdrTyVars
::
[
HsScaled
GhcPs
(
LHsType
GhcPs
)]
->
FreeKiTyVars
->
FreeKiTyVars
extractHsScaledTysRdrTyVars
args
acc
=
foldr
(
\
(
HsScaled
m
ty
)
->
extract_lty
ty
.
extract_hs_arrow
m
)
acc
args
-- | Extracts the free type/kind variables from the kind signature of a HsType.
-- This is used to implicitly quantify over @k@ in @type T = Nothing :: Maybe k@.
-- The left-to-right order of variables is preserved.
...
...
@@ -1764,8 +1768,8 @@ extractHsTyRdrTyVarsKindVars (L _ ty) =
-- | Extracts free type and kind variables from types in a list.
-- When the same name occurs multiple times in the types, all occurrences
-- are returned.
extractHsTysRdrTyVars
::
[
LHsType
GhcPs
]
->
FreeKiTyVars
extractHsTysRdrTyVars
tys
=
extract_ltys
tys
[]
extractHsTysRdrTyVars
::
[
LHsType
GhcPs
]
->
FreeKiTyVars
->
FreeKiTyVars
extractHsTysRdrTyVars
tys
=
extract_ltys
tys
-- Returns the free kind variables of any explicitly-kinded binders, returning
-- variable occurrences in left-to-right order.
...
...
compiler/GHC/Rename/Module.hs
View file @
22f218b7
...
...
@@ -2213,7 +2213,9 @@ rnConDecl decl@(ConDeclGADT { con_names = names
-- See #14808.
;
implicit_bndrs
<-
forAllOrNothing
explicit_forall
$
extractHsTvBndrs
explicit_tkvs
$
extractHsTysRdrTyVars
(
theta
++
map
hsScaledThing
arg_tys
++
[
res_ty
])
$
extractHsTysRdrTyVars
theta
$
extractHsScaledTysRdrTyVars
arg_tys
$
extractHsTysRdrTyVars
[
res_ty
]
[]
;
let
ctxt
=
ConDeclCtx
new_names
...
...
testsuite/tests/linear/should_compile/MultConstructor.hs
View file @
22f218b7
{-# LANGUAGE GADT
Syntax
, DataKinds, LinearTypes, KindSignatures, ExplicitForAll #-}
{-# LANGUAGE GADT
s
, DataKinds, LinearTypes, KindSignatures, ExplicitForAll
, TypeApplications
#-}
module
MultConstructor
where
import
GHC.Types
...
...
@@ -6,8 +6,23 @@ import GHC.Types
data
T
p
a
where
MkT
::
a
%
p
->
T
p
a
{-
this currently fails
g :: forall (b :: Type). T 'Many b %1 -> (b,b)
g (MkT x) = (x,x)
-}
data
Existential
a
where
-- #18790
MkE
::
a
%
p
->
Existential
a
f1
::
forall
(
a
::
Type
)
.
T
'Many
a
%
1
->
(
a
,
a
)
f1
(
MkT
x
)
=
(
x
,
x
)
f2
::
forall
(
a
::
Type
)
m
.
T
'Many
a
%
1
->
T
m
a
f2
(
MkT
x
)
=
MkT
x
f3
::
forall
(
a
::
Type
)
.
a
%
1
->
T
'One
a
f3
=
MkT
g1
::
forall
(
a
::
Type
)
.
a
%
1
->
Existential
a
g1
x
=
MkE
x
g2
::
forall
(
a
::
Type
)
.
Existential
a
->
a
g2
(
MkE
x
)
=
x
vta
::
Int
%
1
->
Existential
Int
vta
x
=
MkE
@
Int
@
'One
x
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