-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use explicit namespace specifiers when promoting/singling fixity decl…
…arations During promotion, we now give promoted fixity declarations the `type` namespace, and during singling, we now give singled fixity declarations the `type` namespace (if it is a singled class declaration) or the `data` namesapce (for all other singled names). Doing so makes our intentions clearer, and it also future-proofs the code against planned GHC changes discussed in [GHC proposal 65](https://github.com/ghc-proposals/ghc-proposals/blob/8443acc903437cef1a7fbb56de79b6dce77b1a09/proposals/0065-type-infix.rst#migration-plan), where specifier-less fixity declarations (e.g., `infixl 4 %%%`) will become an error if they refer to both a term-level and type-level `%%%` name. We now also take namespace specifiers into account when promoting fixity declarations. This is because `Wrinkle 1: When not to promote/single fixity declarations` in `Note [singletons-th and fixity declarations]` describes a special case where we must avoid promoting fixity declarations for infix names, but this workaround only needs to be used if the fixity declaration lacks an explicit namespace specifier. If it _does_ have an explicit namespace specifier (e.g., `infixl 4 data %%%`), then we can promote it (e.g., to `infixl 4 type %%%`) without fear of name clashes. Fixes #582.
- Loading branch information
1 parent
0f4bfc3
commit 2b4f955
Showing
10 changed files
with
276 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
151 changes: 151 additions & 0 deletions
151
singletons-base/tests/compile-and-dump/Singletons/T582.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
Singletons/T582.hs:(0,0)-(0,0): Splicing declarations | ||
singletons | ||
[d| infixl 4 !!! | ||
infixl 4 %%% | ||
infixl 4 `Bar` | ||
infixl 4 `foo` | ||
|
||
foo :: a -> a -> a | ||
x `foo` _ = x | ||
(%%%) :: a -> a -> a | ||
x %%% _ = x | ||
|
||
type Bar :: a -> a -> a | ||
type (!!!) :: a -> a -> a | ||
|
||
type x `Bar` y = x | ||
type x !!! y = x |] | ||
======> | ||
infixl 4 `foo` | ||
foo :: a -> a -> a | ||
foo x _ = x | ||
infixl 4 `Bar` | ||
type Bar :: a -> a -> a | ||
type Bar x y = x | ||
infixl 4 %%% | ||
(%%%) :: a -> a -> a | ||
(%%%) x _ = x | ||
infixl 4 !!! | ||
type (!!!) :: a -> a -> a | ||
type (!!!) x y = x | ||
type BarSym0 :: (~>) a ((~>) a a) | ||
data BarSym0 :: (~>) a ((~>) a a) | ||
where | ||
BarSym0KindInference :: SameKind (Apply BarSym0 arg) (BarSym1 arg) => | ||
BarSym0 a0123456789876543210 | ||
type instance Apply BarSym0 a0123456789876543210 = BarSym1 a0123456789876543210 | ||
instance SuppressUnusedWarnings BarSym0 where | ||
suppressUnusedWarnings = snd ((,) BarSym0KindInference ()) | ||
infixl 4 `BarSym0` | ||
type BarSym1 :: a -> (~>) a a | ||
data BarSym1 (a0123456789876543210 :: a) :: (~>) a a | ||
where | ||
BarSym1KindInference :: SameKind (Apply (BarSym1 a0123456789876543210) arg) (BarSym2 a0123456789876543210 arg) => | ||
BarSym1 a0123456789876543210 a0123456789876543210 | ||
type instance Apply (BarSym1 a0123456789876543210) a0123456789876543210 = Bar a0123456789876543210 a0123456789876543210 | ||
instance SuppressUnusedWarnings (BarSym1 a0123456789876543210) where | ||
suppressUnusedWarnings = snd ((,) BarSym1KindInference ()) | ||
infixl 4 `BarSym1` | ||
type BarSym2 :: a -> a -> a | ||
type family BarSym2 @a (a0123456789876543210 :: a) (a0123456789876543210 :: a) :: a where | ||
BarSym2 a0123456789876543210 a0123456789876543210 = Bar a0123456789876543210 a0123456789876543210 | ||
infixl 4 `BarSym2` | ||
type (!!!@#@$) :: (~>) a ((~>) a a) | ||
data (!!!@#@$) :: (~>) a ((~>) a a) | ||
where | ||
(:!!!@#@$###) :: SameKind (Apply (!!!@#@$) arg) ((!!!@#@$$) arg) => | ||
(!!!@#@$) a0123456789876543210 | ||
type instance Apply (!!!@#@$) a0123456789876543210 = (!!!@#@$$) a0123456789876543210 | ||
instance SuppressUnusedWarnings (!!!@#@$) where | ||
suppressUnusedWarnings = snd ((,) (:!!!@#@$###) ()) | ||
infixl 4 !!!@#@$ | ||
type (!!!@#@$$) :: a -> (~>) a a | ||
data (!!!@#@$$) (a0123456789876543210 :: a) :: (~>) a a | ||
where | ||
(:!!!@#@$$###) :: SameKind (Apply ((!!!@#@$$) a0123456789876543210) arg) ((!!!@#@$$$) a0123456789876543210 arg) => | ||
(!!!@#@$$) a0123456789876543210 a0123456789876543210 | ||
type instance Apply ((!!!@#@$$) a0123456789876543210) a0123456789876543210 = (!!!) a0123456789876543210 a0123456789876543210 | ||
instance SuppressUnusedWarnings ((!!!@#@$$) a0123456789876543210) where | ||
suppressUnusedWarnings = snd ((,) (:!!!@#@$$###) ()) | ||
infixl 4 !!!@#@$$ | ||
type (!!!@#@$$$) :: a -> a -> a | ||
type family (!!!@#@$$$) @a (a0123456789876543210 :: a) (a0123456789876543210 :: a) :: a where | ||
(!!!@#@$$$) a0123456789876543210 a0123456789876543210 = (!!!) a0123456789876543210 a0123456789876543210 | ||
infixl 4 !!!@#@$$$ | ||
type (%%%@#@$) :: (~>) a ((~>) a a) | ||
data (%%%@#@$) :: (~>) a ((~>) a a) | ||
where | ||
(:%%%@#@$###) :: SameKind (Apply (%%%@#@$) arg) ((%%%@#@$$) arg) => | ||
(%%%@#@$) a0123456789876543210 | ||
type instance Apply (%%%@#@$) a0123456789876543210 = (%%%@#@$$) a0123456789876543210 | ||
instance SuppressUnusedWarnings (%%%@#@$) where | ||
suppressUnusedWarnings = snd ((,) (:%%%@#@$###) ()) | ||
infixl 4 %%%@#@$ | ||
type (%%%@#@$$) :: a -> (~>) a a | ||
data (%%%@#@$$) (a0123456789876543210 :: a) :: (~>) a a | ||
where | ||
(:%%%@#@$$###) :: SameKind (Apply ((%%%@#@$$) a0123456789876543210) arg) ((%%%@#@$$$) a0123456789876543210 arg) => | ||
(%%%@#@$$) a0123456789876543210 a0123456789876543210 | ||
type instance Apply ((%%%@#@$$) a0123456789876543210) a0123456789876543210 = (%%%) a0123456789876543210 a0123456789876543210 | ||
instance SuppressUnusedWarnings ((%%%@#@$$) a0123456789876543210) where | ||
suppressUnusedWarnings = snd ((,) (:%%%@#@$$###) ()) | ||
infixl 4 %%%@#@$$ | ||
type (%%%@#@$$$) :: a -> a -> a | ||
type family (%%%@#@$$$) @a (a0123456789876543210 :: a) (a0123456789876543210 :: a) :: a where | ||
(%%%@#@$$$) a0123456789876543210 a0123456789876543210 = (%%%) a0123456789876543210 a0123456789876543210 | ||
infixl 4 %%%@#@$$$ | ||
type FooSym0 :: (~>) a ((~>) a a) | ||
data FooSym0 :: (~>) a ((~>) a a) | ||
where | ||
FooSym0KindInference :: SameKind (Apply FooSym0 arg) (FooSym1 arg) => | ||
FooSym0 a0123456789876543210 | ||
type instance Apply FooSym0 a0123456789876543210 = FooSym1 a0123456789876543210 | ||
instance SuppressUnusedWarnings FooSym0 where | ||
suppressUnusedWarnings = snd ((,) FooSym0KindInference ()) | ||
infixl 4 `FooSym0` | ||
type FooSym1 :: a -> (~>) a a | ||
data FooSym1 (a0123456789876543210 :: a) :: (~>) a a | ||
where | ||
FooSym1KindInference :: SameKind (Apply (FooSym1 a0123456789876543210) arg) (FooSym2 a0123456789876543210 arg) => | ||
FooSym1 a0123456789876543210 a0123456789876543210 | ||
type instance Apply (FooSym1 a0123456789876543210) a0123456789876543210 = Foo a0123456789876543210 a0123456789876543210 | ||
instance SuppressUnusedWarnings (FooSym1 a0123456789876543210) where | ||
suppressUnusedWarnings = snd ((,) FooSym1KindInference ()) | ||
infixl 4 `FooSym1` | ||
type FooSym2 :: a -> a -> a | ||
type family FooSym2 @a (a0123456789876543210 :: a) (a0123456789876543210 :: a) :: a where | ||
FooSym2 a0123456789876543210 a0123456789876543210 = Foo a0123456789876543210 a0123456789876543210 | ||
infixl 4 `FooSym2` | ||
type (%%%) :: a -> a -> a | ||
type family (%%%) @a (a :: a) (a :: a) :: a where | ||
(%%%) x _ = x | ||
type Foo :: a -> a -> a | ||
type family Foo @a (a :: a) (a :: a) :: a where | ||
Foo x _ = x | ||
infixl 4 %%% | ||
infixl 4 `Foo` | ||
infixl 4 %%%% | ||
infixl 4 `sFoo` | ||
(%%%%) :: | ||
(forall (t :: a) (t :: a). | ||
Sing t | ||
-> Sing t -> Sing (Apply (Apply (%%%@#@$) t) t :: a) :: Type) | ||
sFoo :: | ||
(forall (t :: a) (t :: a). | ||
Sing t -> Sing t -> Sing (Apply (Apply FooSym0 t) t :: a) :: Type) | ||
(%%%%) (sX :: Sing x) _ = sX | ||
sFoo (sX :: Sing x) _ = sX | ||
instance SingI ((%%%@#@$) :: (~>) a ((~>) a a)) where | ||
sing = singFun2 @(%%%@#@$) (%%%%) | ||
instance SingI d => SingI ((%%%@#@$$) (d :: a) :: (~>) a a) where | ||
sing = singFun1 @((%%%@#@$$) (d :: a)) ((%%%%) (sing @d)) | ||
instance SingI1 ((%%%@#@$$) :: a -> (~>) a a) where | ||
liftSing (s :: Sing (d :: a)) | ||
= singFun1 @((%%%@#@$$) (d :: a)) ((%%%%) s) | ||
instance SingI (FooSym0 :: (~>) a ((~>) a a)) where | ||
sing = singFun2 @FooSym0 sFoo | ||
instance SingI d => SingI (FooSym1 (d :: a) :: (~>) a a) where | ||
sing = singFun1 @(FooSym1 (d :: a)) (sFoo (sing @d)) | ||
instance SingI1 (FooSym1 :: a -> (~>) a a) where | ||
liftSing (s :: Sing (d :: a)) | ||
= singFun1 @(FooSym1 (d :: a)) (sFoo s) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module T582 where | ||
|
||
import Data.Singletons.TH | ||
|
||
$(singletons [d| | ||
infixl 4 data `foo` | ||
foo :: a -> a -> a | ||
x `foo` _ = x | ||
|
||
infixl 4 type `Bar` | ||
type Bar :: a -> a -> a | ||
type x `Bar` y = x | ||
|
||
infixl 4 data %%% | ||
(%%%) :: a -> a -> a | ||
x %%% _ = x | ||
|
||
infixl 4 type !!! | ||
type (!!!) :: a -> a -> a | ||
type x !!! y = x | ||
|]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.