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
0757831e
Commit
0757831e
authored
11 years ago
by
Simon Peyton Jones
Browse files
Options
Downloads
Patches
Plain Diff
Add Note [Placeholder PatSyn kinds] in TcBinds
This is just documentation for the fix to Trac #9161
parent
8a0aa198
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
compiler/typecheck/TcBinds.lhs
+33
-11
33 additions, 11 deletions
compiler/typecheck/TcBinds.lhs
compiler/typecheck/TcEnv.lhs
+3
-0
3 additions, 0 deletions
compiler/typecheck/TcEnv.lhs
with
36 additions
and
11 deletions
compiler/typecheck/TcBinds.lhs
+
33
−
11
View file @
0757831e
...
@@ -274,6 +274,30 @@ time by defaulting. No no no.
...
@@ -274,6 +274,30 @@ time by defaulting. No no no.
However [Oct 10] this is all handled automatically by the
However [Oct 10] this is all handled automatically by the
untouchable-range idea.
untouchable-range idea.
Note [Placeholder PatSyn kinds]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider this (Trac #9161)
{-# LANGUAGE PatternSynonyms, DataKinds #-}
pattern A = ()
b :: A
b = undefined
Here, the type signature for b mentions A. But A is a pattern
synonym, which is typechecked (for very good reasons; a view pattern
in the RHS may mention a value binding) as part of a group of
bindings. It is entirely resonable to reject this, but to do so
we need A to be in the kind environment when kind-checking the signature for B.
Hence the tcExtendKindEnv2 patsyn_placeholder_kinds, which adds a binding
A -> AGlobal (AConLike (PatSynCon _|_))
to the environment. Then TcHsType.tcTyVar will find A in the kind environment,
and will give a 'wrongThingErr' as a result. But the lookup of A won't fail.
The _|_ (= panic "fakePatSynCon") works because the wrongThingErr call, in
tcTyVar, doesn't look inside the TcTyThing.
\begin{code}
\begin{code}
tcValBinds :: TopLevelFlag
tcValBinds :: TopLevelFlag
-> [(RecFlag, LHsBinds Name)] -> [LSig Name]
-> [(RecFlag, LHsBinds Name)] -> [LSig Name]
...
@@ -281,12 +305,9 @@ tcValBinds :: TopLevelFlag
...
@@ -281,12 +305,9 @@ tcValBinds :: TopLevelFlag
-> TcM ([(RecFlag, LHsBinds TcId)], thing)
-> TcM ([(RecFlag, LHsBinds TcId)], thing)
tcValBinds top_lvl binds sigs thing_inside
tcValBinds top_lvl binds sigs thing_inside
= do { -- Add fake entries for pattern synonyms so that
= do { -- Typecheck the signature
-- precise error messages can be generated when
; (poly_ids, sig_fn) <- tcExtendKindEnv2 patsyn_placeholder_kinds $
-- trying to use a pattern synonym as a kind
-- See Note [Placeholder PatSyn kinds]
traceTc "Fake lifted patsyns:" (vcat (map ppr patsyns))
-- Typecheck the signature
; (poly_ids, sig_fn) <- tcExtendKindEnv2 [(patsyn, fakePatSynCon) | patsyn <- patsyns] $
tcTySigs sigs
tcTySigs sigs
; let prag_fn = mkPragFun sigs (foldr (unionBags . snd) emptyBag binds)
; let prag_fn = mkPragFun sigs (foldr (unionBags . snd) emptyBag binds)
...
@@ -298,11 +319,12 @@ tcValBinds top_lvl binds sigs thing_inside
...
@@ -298,11 +319,12 @@ tcValBinds top_lvl binds sigs thing_inside
tcBindGroups top_lvl sig_fn prag_fn
tcBindGroups top_lvl sig_fn prag_fn
binds thing_inside }
binds thing_inside }
where
where
patsyns = [ name
patsyn_placeholder_kinds -- See Note [Placeholder PatSyn kinds]
| (_, lbinds) <- binds
= [ (name, placeholder_patsyn_tything)
, L _ (PatSynBind{ patsyn_id = L _ name }) <- bagToList lbinds
| (_, lbinds) <- binds
]
, L _ (PatSynBind{ patsyn_id = L _ name }) <- bagToList lbinds ]
fakePatSynCon = AGlobal $ AConLike $ PatSynCon $ panic "fakePatSynCon"
placeholder_patsyn_tything
= AGlobal $ AConLike $ PatSynCon $ panic "fakePatSynCon"
------------------------
------------------------
tcBindGroups :: TopLevelFlag -> TcSigFun -> PragFun
tcBindGroups :: TopLevelFlag -> TcSigFun -> PragFun
...
...
This diff is collapsed.
Click to expand it.
compiler/typecheck/TcEnv.lhs
+
3
−
0
View file @
0757831e
...
@@ -874,6 +874,9 @@ notFound name
...
@@ -874,6 +874,9 @@ notFound name
}
}
wrongThingErr :: String -> TcTyThing -> Name -> TcM a
wrongThingErr :: String -> TcTyThing -> Name -> TcM a
-- It's important that this only calls pprTcTyThingCategory, which in
-- turn does not look at the details of the TcTyThing.
-- See Note [Placeholder PatSyn kinds] in TcBinds
wrongThingErr expected thing name
wrongThingErr expected thing name
= failWithTc (pprTcTyThingCategory thing <+> quotes (ppr name) <+>
= failWithTc (pprTcTyThingCategory thing <+> quotes (ppr name) <+>
ptext (sLit "used as a") <+> text expected)
ptext (sLit "used as a") <+> text expected)
...
...
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