diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/GHC/Core/DataCon.hs | 4 | ||||
-rw-r--r-- | compiler/GHC/Core/Multiplicity.hs | 6 | ||||
-rw-r--r-- | compiler/GHC/Core/Opt/Arity.hs | 2 | ||||
-rw-r--r-- | compiler/GHC/Core/Opt/Monad.hs | 2 | ||||
-rw-r--r-- | compiler/GHC/Core/Opt/Simplify.hs | 2 | ||||
-rw-r--r-- | compiler/GHC/Core/Opt/Simplify/Env.hs | 4 | ||||
-rw-r--r-- | compiler/GHC/Core/SimpleOpt.hs | 2 | ||||
-rw-r--r-- | compiler/GHC/Hs/Decls.hs | 2 | ||||
-rw-r--r-- | compiler/GHC/Hs/Type.hs | 4 | ||||
-rw-r--r-- | compiler/GHC/Parser.y | 21 | ||||
-rw-r--r-- | compiler/GHC/Parser/Annotation.hs | 4 | ||||
-rw-r--r-- | compiler/GHC/Parser/Lexer.x | 8 | ||||
-rw-r--r-- | compiler/GHC/Parser/PostProcess.hs | 7 | ||||
-rw-r--r-- | compiler/GHC/Types/Id/Make.hs | 6 | ||||
-rw-r--r-- | compiler/GHC/Utils/Outputable.hs | 2 |
15 files changed, 42 insertions, 34 deletions
diff --git a/compiler/GHC/Core/DataCon.hs b/compiler/GHC/Core/DataCon.hs index 04570f9af7..87e6bf10c9 100644 --- a/compiler/GHC/Core/DataCon.hs +++ b/compiler/GHC/Core/DataCon.hs @@ -1321,7 +1321,7 @@ dataConStupidTheta dc = dcStupidTheta dc Note [Displaying linear fields] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ A constructor with a linear field can be written either as -MkT :: a #-> T a (with -XLinearTypes) +MkT :: a %1 -> T a (with -XLinearTypes) or MkT :: a -> T a (with -XNoLinearTypes) @@ -1330,7 +1330,7 @@ They differ in how linear fields are handled. 1. dataConWrapperType: The type of the wrapper in Core. -For example, dataConWrapperType for Maybe is a #-> Just a. +For example, dataConWrapperType for Maybe is a %1 -> Just a. 2. dataConNonlinearType: The type of the constructor, with linear arrows replaced by unrestricted ones. diff --git a/compiler/GHC/Core/Multiplicity.hs b/compiler/GHC/Core/Multiplicity.hs index 8c3ad88fc2..73535a3e15 100644 --- a/compiler/GHC/Core/Multiplicity.hs +++ b/compiler/GHC/Core/Multiplicity.hs @@ -216,7 +216,7 @@ That is, in We have - Just :: a #-> Just a + Just :: a %1 -> Just a The goal is to maximise reuse of types between linear code and traditional code. This is argued at length in the proposal and the article (links in Note @@ -232,7 +232,7 @@ backwards compatibility. Consider We have map :: (a -> b) -> f a -> f b - Just :: a #-> Just a + Just :: a %1 -> Just a Types don't match, we should get a type error. But this is legal Haskell 98 code! Bad! Bad! Bad! @@ -242,7 +242,7 @@ polymorphism. Instead, we generalise the type of Just, when used as term: - Just :: forall {p}. a #p-> Just a + Just :: forall {p}. a %p-> Just a This is solely a concern for higher-order code like this: when called fully applied linear constructors are more general than constructors with unrestricted diff --git a/compiler/GHC/Core/Opt/Arity.hs b/compiler/GHC/Core/Opt/Arity.hs index 2471470814..1526be01ca 100644 --- a/compiler/GHC/Core/Opt/Arity.hs +++ b/compiler/GHC/Core/Opt/Arity.hs @@ -1490,7 +1490,7 @@ pushCoValArg co -- We can't push the coercion in the case where co_mult isn't reflexivity: -- it could be an unsafe axiom, and losing this information could yield -- ill-typed terms. For instance (fun x ::(1) Int -> (fun _ -> () |> co) x) - -- with co :: (Int -> ()) ~ (Int #-> ()), would reduce to (fun x ::(1) Int + -- with co :: (Int -> ()) ~ (Int %1 -> ()), would reduce to (fun x ::(1) Int -- -> (fun _ ::(Many) Int -> ()) x) which is ill-typed -- If co :: (tyL1 -> tyL2) ~ (tyR1 -> tyR2) diff --git a/compiler/GHC/Core/Opt/Monad.hs b/compiler/GHC/Core/Opt/Monad.hs index 070ea11cc2..e7298fef54 100644 --- a/compiler/GHC/Core/Opt/Monad.hs +++ b/compiler/GHC/Core/Opt/Monad.hs @@ -412,7 +412,7 @@ EtaExpansion: fail = \void. (\s. (e |> g) s) |> sym g where g :: IO () ~ S -> (S,()) --> Next iteration of simplify fail1 = \void. \s. (e |> g) s - fail = fail1 |> Void#->sym g + fail = fail1 |> Void# -> sym g And now inline 'fail' CaseMerge: diff --git a/compiler/GHC/Core/Opt/Simplify.hs b/compiler/GHC/Core/Opt/Simplify.hs index 6c207766bd..96d9cfc61e 100644 --- a/compiler/GHC/Core/Opt/Simplify.hs +++ b/compiler/GHC/Core/Opt/Simplify.hs @@ -2640,7 +2640,7 @@ rebuildCase env scrut case_bndr alts cont -- -- As an illustration, consider the following -- case[Many] case[1] of { C x -> C x } of { C x -> (x, x) } - -- Where C :: A #-> T is linear + -- Where C :: A %1 -> T is linear -- If we were to produce a case[1], like the inner case, we would get -- case[1] of { C x -> (x, x) } -- Which is ill-typed with respect to linearity. So it needs to be a diff --git a/compiler/GHC/Core/Opt/Simplify/Env.hs b/compiler/GHC/Core/Opt/Simplify/Env.hs index 7049e3e578..7d53a2db2b 100644 --- a/compiler/GHC/Core/Opt/Simplify/Env.hs +++ b/compiler/GHC/Core/Opt/Simplify/Env.hs @@ -953,7 +953,7 @@ adjustJoinPointType mult new_res_ty join_id ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Consider a join point which is linear in its variable, in some context E: -E[join j :: a #-> a +E[join j :: a %1 -> a j x = x in case v of A -> j 'x' @@ -961,7 +961,7 @@ E[join j :: a #-> a The simplifier changes to: -join j :: a #-> a +join j :: a %1 -> a j x = E[x] in case v of A -> j 'x' diff --git a/compiler/GHC/Core/SimpleOpt.hs b/compiler/GHC/Core/SimpleOpt.hs index 67f08cdd23..d066535e30 100644 --- a/compiler/GHC/Core/SimpleOpt.hs +++ b/compiler/GHC/Core/SimpleOpt.hs @@ -1342,5 +1342,3 @@ exprIsLambda_maybe (in_scope_set, id_unf) e exprIsLambda_maybe _ _e = -- pprTrace "exprIsLambda_maybe:Fail" (vcat [ppr _e]) Nothing - - diff --git a/compiler/GHC/Hs/Decls.hs b/compiler/GHC/Hs/Decls.hs index 1eeb42d73e..c0b8baa435 100644 --- a/compiler/GHC/Hs/Decls.hs +++ b/compiler/GHC/Hs/Decls.hs @@ -1538,7 +1538,7 @@ types of a GADT constructor, since there are some non-obvious details involved. While splitting the argument types of a record GADT constructor is easy (they are stored in an HsRecTy), splitting the arguments of a prefix GADT constructor is trickier. The basic idea is that we must split along the outermost function -arrows ((->) and (#->)) in the type, which GHC.Hs.Type.splitHsFunType +arrows ((->) and (%1 ->)) in the type, which GHC.Hs.Type.splitHsFunType accomplishes. But what about type operators? Consider: C :: a :*: b -> a :*: b -> a :+: b diff --git a/compiler/GHC/Hs/Type.hs b/compiler/GHC/Hs/Type.hs index c2da3857d4..818fe75475 100644 --- a/compiler/GHC/Hs/Type.hs +++ b/compiler/GHC/Hs/Type.hs @@ -936,9 +936,9 @@ data HsArrow pass = HsUnrestrictedArrow -- ^ a -> b | HsLinearArrow - -- ^ a #-> b + -- ^ a %1 -> b | HsExplicitMult (LHsType pass) - -- ^ a # m -> b (very much including `a # Many -> b`! This is how the + -- ^ a %m -> b (very much including `a %Many -> b`! This is how the -- programmer wrote it). It is stored as an `HsType` so as to preserve the -- syntax as written in the program. diff --git a/compiler/GHC/Parser.y b/compiler/GHC/Parser.y index efd8831418..12f5b8be3b 100644 --- a/compiler/GHC/Parser.y +++ b/compiler/GHC/Parser.y @@ -280,7 +280,7 @@ Context: context -> btype . type -> btype . type -> btype . '->' ctype - type -> btype . '#->' ctype + type -> btype . '->.' ctype Example: a :: Maybe Integer -> Bool @@ -636,7 +636,7 @@ are the most common patterns, rewritten as regular expressions for clarity: '|' { L _ ITvbar } '<-' { L _ (ITlarrow _) } '->' { L _ (ITrarrow _) } - '#->' { L _ (ITlolly _) } + '->.' { L _ ITlolly } TIGHT_INFIX_AT { L _ ITat } '=>' { L _ (ITdarrow _) } '-' { L _ ITminus } @@ -650,6 +650,7 @@ are the most common patterns, rewritten as regular expressions for clarity: '>>-' { L _ (ITRarrowtail _) } -- for arrow notation '.' { L _ ITdot } PREFIX_AT { L _ ITtypeApp } + PREFIX_PERCENT { L _ ITpercent } -- for linear types '{' { L _ ITocurly } -- special symbols '}' { L _ ITccurly } @@ -2062,12 +2063,16 @@ type :: { LHsType GhcPs } >> ams (sLL $1 $> $ HsFunTy noExtField HsUnrestrictedArrow $1 $3) [mu AnnRarrow $2] } - | btype '#->' ctype {% hintLinear (getLoc $2) >> - ams (sLL $1 $> $ HsFunTy noExtField HsLinearArrow $1 $3) - [mu AnnLolly $2] } + | btype mult '->' ctype {% hintLinear (getLoc $2) >> + ams (sLL $1 $> $ HsFunTy noExtField (unLoc $2) $1 $4) + [mu AnnRarrow $3] } -mult :: { LHsType GhcPs } - : btype { $1 } + | btype '->.' ctype {% hintLinear (getLoc $2) >> + ams (sLL $1 $> $ HsFunTy noExtField HsLinearArrow $1 $3) + [mu AnnLollyU $2] } + +mult :: { Located (HsArrow GhcPs) } + : PREFIX_PERCENT atype { sLL $1 $> (mkMultTy $2) } btype :: { LHsType GhcPs } : infixtype {% runPV $1 } @@ -3823,7 +3828,7 @@ isUnicode (L _ (ITcparenbar iu)) = iu == UnicodeSyntax isUnicode (L _ (ITopenExpQuote _ iu)) = iu == UnicodeSyntax isUnicode (L _ (ITcloseQuote iu)) = iu == UnicodeSyntax isUnicode (L _ (ITstar iu)) = iu == UnicodeSyntax -isUnicode (L _ (ITlolly iu)) = iu == UnicodeSyntax +isUnicode (L _ ITlolly) = True isUnicode _ = False hasE :: Located Token -> Bool diff --git a/compiler/GHC/Parser/Annotation.hs b/compiler/GHC/Parser/Annotation.hs index 0db029ba02..f6fbe47fe6 100644 --- a/compiler/GHC/Parser/Annotation.hs +++ b/compiler/GHC/Parser/Annotation.hs @@ -259,8 +259,7 @@ data AnnKeywordId | AnnLarrow -- ^ '<-' | AnnLarrowU -- ^ '<-', unicode variant | AnnLet - | AnnLolly -- ^ '#->' - | AnnLollyU -- ^ '#->', unicode variant + | AnnLollyU -- ^ The '⊸' unicode arrow | AnnMdo | AnnMinus -- ^ '-' | AnnModule @@ -364,7 +363,6 @@ unicodeAnn AnnOpenB = AnnOpenBU unicodeAnn AnnCloseB = AnnCloseBU unicodeAnn AnnOpenEQ = AnnOpenEQU unicodeAnn AnnCloseQ = AnnCloseQU -unicodeAnn AnnLolly = AnnLollyU unicodeAnn ann = ann diff --git a/compiler/GHC/Parser/Lexer.x b/compiler/GHC/Parser/Lexer.x index c346df1d0d..ad93226112 100644 --- a/compiler/GHC/Parser/Lexer.x +++ b/compiler/GHC/Parser/Lexer.x @@ -768,14 +768,15 @@ data Token | ITvbar | ITlarrow IsUnicodeSyntax | ITrarrow IsUnicodeSyntax - | ITlolly IsUnicodeSyntax | ITdarrow IsUnicodeSyntax + | ITlolly -- The (⊸) arrow (for LinearTypes) | ITminus -- See Note [Minus tokens] | ITprefixminus -- See Note [Minus tokens] | ITbang -- Prefix (!) only, e.g. f !x = rhs | ITtilde -- Prefix (~) only, e.g. f ~x = rhs | ITat -- Tight infix (@) only, e.g. f x@pat = rhs | ITtypeApp -- Prefix (@) only, e.g. f @t + | ITpercent -- Prefix (%) only, e.g. a %1 -> b | ITstar IsUnicodeSyntax | ITdot @@ -1024,8 +1025,7 @@ reservedSymsFM = listToUFM $ ,("→", ITrarrow UnicodeSyntax, UnicodeSyntax, 0 ) ,("←", ITlarrow UnicodeSyntax, UnicodeSyntax, 0 ) - ,("#->", ITlolly NormalSyntax, NormalSyntax, 0) - ,("⊸", ITlolly UnicodeSyntax, UnicodeSyntax, 0) + ,("⊸", ITlolly, UnicodeSyntax, 0) ,("⤙", ITlarrowtail UnicodeSyntax, UnicodeSyntax, xbit ArrowsBit) ,("⤚", ITrarrowtail UnicodeSyntax, UnicodeSyntax, xbit ArrowsBit) @@ -1577,6 +1577,8 @@ varsym_prefix :: Action varsym_prefix = sym $ \exts s -> if | s == fsLit "@" -- regardless of TypeApplications for better error messages -> return ITtypeApp + | LinearTypesBit `xtest` exts, s == fsLit "%" + -> return ITpercent | ThQuotesBit `xtest` exts, s == fsLit "$" -> return ITdollar | ThQuotesBit `xtest` exts, s == fsLit "$$" diff --git a/compiler/GHC/Parser/PostProcess.hs b/compiler/GHC/Parser/PostProcess.hs index 9014c9f159..ee95880bba 100644 --- a/compiler/GHC/Parser/PostProcess.hs +++ b/compiler/GHC/Parser/PostProcess.hs @@ -70,6 +70,7 @@ module GHC.Parser.PostProcess ( addFatalError, hintBangPat, mkBangTy, UnpackednessPragma(..), + mkMultTy, -- Help with processing exports ImpExpSubSpec(..), @@ -661,7 +662,7 @@ mkConDeclH98 name mb_forall mb_cxt args -- -- * If -XLinearTypes is not enabled, the function arrows in a prefix GADT -- constructor are always interpreted as linear. If -XLinearTypes is enabled, --- we faithfully record whether -> or #-> was used. +-- we faithfully record whether -> or %1 -> was used. mkGadtDecl :: [Located RdrName] -> LHsType GhcPs -> P (ConDecl GhcPs) @@ -2875,6 +2876,10 @@ mkLHsOpTy x op y = let loc = getLoc x `combineSrcSpans` getLoc op `combineSrcSpans` getLoc y in L loc (mkHsOpTy x op y) +mkMultTy :: LHsType GhcPs -> HsArrow GhcPs +mkMultTy (L _ (HsTyLit _ (HsNumTy _ 1))) = HsLinearArrow +mkMultTy t = HsExplicitMult t + ----------------------------------------------------------------------------- -- Token symbols diff --git a/compiler/GHC/Types/Id/Make.hs b/compiler/GHC/Types/Id/Make.hs index fa445ea25f..63a7d5a02a 100644 --- a/compiler/GHC/Types/Id/Make.hs +++ b/compiler/GHC/Types/Id/Make.hs @@ -398,11 +398,11 @@ Projections of records can't be linear: If we had - a :: Foo #-> A + a :: Foo %1 -> A We could write - bad :: A #-> B #-> A + bad :: A %1 -> B %1 -> A bad x y = a (MkFoo { a=x, b=y }) There is an exception: if `b` (more generally all the fields besides `a`) is @@ -411,7 +411,7 @@ linear projection has as simple definition. data Bar = MkBar { c :: C, d # Many :: D } - c :: Bar #-> C + c :: Bar %1 -> C c MkBar{ c=x, d=_} = x The `# Many` syntax, for records, does not exist yet. But there is one important diff --git a/compiler/GHC/Utils/Outputable.hs b/compiler/GHC/Utils/Outputable.hs index 5c337fd5b4..6dd5b88fbb 100644 --- a/compiler/GHC/Utils/Outputable.hs +++ b/compiler/GHC/Utils/Outputable.hs @@ -654,7 +654,7 @@ lparen, rparen, lbrack, rbrack, lbrace, rbrace, blankLine :: SDoc blankLine = docToSDoc $ Pretty.text "" dcolon = unicodeSyntax (char '∷') (docToSDoc $ Pretty.text "::") arrow = unicodeSyntax (char '→') (docToSDoc $ Pretty.text "->") -lollipop = unicodeSyntax (char '⊸') (docToSDoc $ Pretty.text "#->") +lollipop = unicodeSyntax (char '⊸') (docToSDoc $ Pretty.text "%1 ->") larrow = unicodeSyntax (char '←') (docToSDoc $ Pretty.text "<-") darrow = unicodeSyntax (char '⇒') (docToSDoc $ Pretty.text "=>") arrowt = unicodeSyntax (char '⤚') (docToSDoc $ Pretty.text ">-") |