1. 17 Nov, 2015 2 commits
  2. 16 Nov, 2015 2 commits
    • Alan Zimmerman's avatar
      ApiAnnotations : ITopenExpQuote needs SourceText · ee914828
      Alan Zimmerman authored
      Summary:
      In the lexer, ITopenExpQuote can be recognised for '[e|' or '[|'.
      
      The token definition needs to capture the original SourceText, and pass
      it through to ExpBr, which also needs a SrcText field.
      
      It is easier to simply add a flag  to the token identifying the variant
      and to generate a different AnnKeywordId based on this.
      
      Test Plan: ./validate
      
      Reviewers: mpickering, bgamari, austin
      
      Reviewed By: bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D1479
      
      GHC Trac Issues: #10276
      ee914828
    • Alan Zimmerman's avatar
      ApiAnnotations: Add SourceText for unicode tokens · fe95463b
      Alan Zimmerman authored
      Summary:
      At the moment there is no way to tell if a given token used its unicode
      variant or its normal one, except to look at the length of the token.
      
      This fails for the unicode '*'.
      
      Expose the original source text for unicode variants so that API
      Annotations can capture them specifically.
      
      Test Plan: ./validate
      
      Reviewers: mpickering, austin, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D1473
      
      GHC Trac Issues: #11018
      fe95463b
  3. 17 Oct, 2015 1 commit
    • Herbert Valerio Riedel's avatar
      Make Monad/Applicative instances MRP-friendly · e8ed2136
      Herbert Valerio Riedel authored
      This patch refactors pure/(*>) and return/(>>) in MRP-friendly way, i.e.
      such that the explicit definitions for `return` and `(>>)` match the
      MRP-style default-implementation, i.e.
      
        return = pure
      
      and
      
        (>>) = (*>)
      
      This way, e.g. all `return = pure` definitions can easily be grepped and
      removed in GHC 8.1;
      
      Test Plan: Harbormaster
      
      Reviewers: goldfire, alanz, bgamari, quchen, austin
      
      Reviewed By: quchen, austin
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D1312
      e8ed2136
  4. 15 Oct, 2015 1 commit
  5. 30 Sep, 2015 1 commit
    • thomie's avatar
      Lexer: delete dead code for binary character literals · 2eddcd9b
      thomie authored
      The Haskell 2010 report chapter 2.6 (Characters and String Literals)
      says:
      
        "Numeric escapes such as \137 are used to designate the character with
        decimal representation 137; octal (e.g. \o137) and hexadecimal (e.g.
        \x37) representations are also allowed."
      
      Commit 1c0b5fdc added syntax for writing
      character literals using binary notation (e.g. '\b100100'). But this
      code can never be reached, because '\b' already represents "backspace".
      
      Turn on -fwarn-overlapping-patterns to catch such bugs in the future.
      
      Reviewed by: hvr
      
      Differential Revision: https://phabricator.haskell.org/D1291
      2eddcd9b
  6. 23 Jul, 2015 1 commit
  7. 07 Jul, 2015 2 commits
  8. 06 Jul, 2015 1 commit
  9. 04 Jul, 2015 4 commits
  10. 03 Jul, 2015 1 commit
  11. 16 Jun, 2015 1 commit
    • Ben Gamari's avatar
      Lexer: Suggest adding 'let' on unexpected '=' token · 1ff7f09b
      Ben Gamari authored
      Summary:
      I've heard numerous fledgling Haskeller's complain about the behavior of
      ghci regarding bindings. While most REPLs accept bindings of the form
      `x = 42`, GHCi is implicitly a `do` block, meaning that the user must
      know to use a `let` to introduce a binding.
      
      Here we suggest to the user that they may need a `let` and give them a
      small example in the event that we find an unexpected `=` token.
      
      Reviewers: austin
      
      Reviewed By: austin
      
      Subscribers: thomie, bgamari
      
      Differential Revision: https://phabricator.haskell.org/D980
      1ff7f09b
  12. 14 Apr, 2015 1 commit
  13. 02 Apr, 2015 1 commit
  14. 19 Jan, 2015 1 commit
    • Alan Zimmerman's avatar
      API Annotations documentation update, parsing issue, add example test · 851ed721
      Alan Zimmerman authored
      Summary:
      Add a reference note to each AnnKeywordId haddock comment so GHC
      developers will have an idea why they are there.
      
      Add a new test to ghc-api/annotations to serve as a template for other
      GHC developers when they need to update the parser. It provides output
      which checks that each SrcSpan that an annotation is attached to
      actually appears in the `ParsedSource`, and lists the individual
      annotations. The idea is that a developer writes a version of this
      which parses a sample file using whatever syntax is changed in
      Parser.y, and can then check that all the annotations come through.
      
      Depends on D538
      
      Test Plan: ./validate
      
      Reviewers: simonpj, hvr, austin
      
      Reviewed By: austin
      
      Subscribers: thomie, jstolarek
      
      Differential Revision: https://phabricator.haskell.org/D620
      851ed721
  15. 16 Jan, 2015 1 commit
    • Alan Zimmerman's avatar
      API Annotations tweaks. · 11881ec6
      Alan Zimmerman authored
      Summary:
      HsTyLit now has SourceText
      
      Update documentation of HsSyn to reflect which annotations are attached to which element.
      
      Ensure that the parser always keeps HsSCC and HsTickPragma values, to
      be ignored in the desugar phase if not needed
      
      Bringing in SourceText for pragmas
      
      Add Location in NPlusKPat
      
      Add Location in FunDep
      
      Make RecCon payload Located
      
      Explicitly add AnnVal to RdrName where it is compound
      
      Add Location in IPBind
      
      Add Location to name in IEThingAbs
      
      Add Maybe (Located id,Bool) to Match to track fun_id,infix
        This includes converting Match into a record and adding a note about why
        the fun_id needs to be replicated in the Match.
      
      Add Location in KindedTyVar
      
      Sort out semi-colons for parsing
      
        - import statements
        - stmts
        - decls
        - decls_cls
        - decls_inst
      
      This updates the haddock submodule.
      
      Test Plan: ./validate
      
      Reviewers: hvr, austin, goldfire, simonpj
      
      Reviewed By: simonpj
      
      Subscribers: thomie, carter
      
      Differential Revision: https://phabricator.haskell.org/D538
      11881ec6
  16. 10 Dec, 2014 1 commit
  17. 21 Nov, 2014 3 commits
    • Alan Zimmerman's avatar
      Capture original source for literals · c0ad5bc0
      Alan Zimmerman authored
      Summary:
      Make HsLit and OverLitVal have original source strings, for source to
      source conversions using the GHC API
      
      This is part of the ongoing AST Annotations work, as captured in
      https://ghc.haskell.org/trac/ghc/wiki/GhcAstAnnotations and
      https://ghc.haskell.org/trac/ghc/ticket/9628#comment:28
      
      The motivations for the literals is as follows
      
      ```lang=haskell
      x,y :: Int
      x = 0003
      y = 0x04
      
      s :: String
      s = "\x20"
      
      c :: Char
      c = '\x20'
      
      d :: Double
      d = 0.00
      
      blah = x
        where
          charH = '\x41'#
          intH = 0004#
          wordH = 005##
          floatH = 3.20#
          doubleH = 04.16##
          x = 1
      ```
      
      Test Plan: ./sh validate
      
      Reviewers: simonpj, austin
      
      Reviewed By: simonpj, austin
      
      Subscribers: thomie, goldfire, carter, simonmar
      
      Differential Revision: https://phabricator.haskell.org/D412
      
      GHC Trac Issues: #9628
      c0ad5bc0
    • Alan Zimmerman's avatar
      Add API Annotations · 803fc5db
      Alan Zimmerman authored
      Summary:
      The final design and discussion is captured at
      https://ghc.haskell.org/trac/ghc/wiki/GhcAstAnnotations
      
      This is a proof of concept implementation of a completely
      separate annotation structure, populated in the parser,and tied to the
      AST by means of a virtual "node-key" comprising the surrounding
      SrcSpan and a value derived from the specific constructor used for the
      node.
      
      The key parts of the design are the following.
      
      == The Annotations ==
      
      In `hsSyn/ApiAnnotation.hs`
      
      ```lang=haskell
      type ApiAnns = (Map.Map ApiAnnKey SrcSpan, Map.Map SrcSpan [Located Token])
      
      type ApiAnnKey = (SrcSpan,AnnKeywordId)
      
      -- ---------------------------------------------------------------------
      
      -- | Retrieve an annotation based on the @SrcSpan@ of the annotated AST
      -- element, and the known type of the annotation.
      getAnnotation :: ApiAnns -> SrcSpan -> AnnKeywordId -> Maybe SrcSpan
      getAnnotation (anns,_) span ann = Map.lookup (span,ann) anns
      
      -- |Retrieve the comments allocated to the current @SrcSpan@
      getAnnotationComments :: ApiAnns -> SrcSpan -> [Located Token]
      getAnnotationComments (_,anns) span =
        case Map.lookup span anns of
          Just cs -> cs
          Nothing -> []
      
      -- | Note: in general the names of these are taken from the
      -- corresponding token, unless otherwise noted
      data AnnKeywordId
               = AnnAs
               | AnnBang
               | AnnClass
               | AnnClose -- ^ } or ] or ) or #) etc
               | AnnComma
               | AnnDarrow
               | AnnData
               | AnnDcolon
               ....
      ```
      
      == Capturing in the lexer/parser ==
      
      The annotations are captured in the lexer / parser by extending PState to include a field
      
      In `parser/Lexer.x`
      
      ```lang=haskell
      data PState = PState {
              ....
              annotations :: [(ApiAnnKey,SrcSpan)]
              -- Annotations giving the locations of 'noise' tokens in the
              -- source, so that users of the GHC API can do source to
              -- source conversions.
           }
      ```
      
      The lexer exposes a helper function to add an annotation
      
      ```lang=haskell
      addAnnotation :: SrcSpan -> Ann -> SrcSpan -> P ()
      addAnnotation l a v = P $ \s -> POk s {
        annotations = ((AK l a), v) : annotations s
        } ()
      
      ```
      
      The parser also has some helper functions of the form
      
      ```lang=haskell
      type MaybeAnn = Maybe (SrcSpan -> P ())
      
      gl = getLoc
      gj x = Just (gl x)
      
      ams :: Located a -> [MaybeAnn] -> P (Located a)
      ams a@(L l _) bs = (mapM_ (\a -> a l) $ catMaybes bs) >> return a
      ```
      
      This allows annotations to be captured in the parser by means of
      
      ```
      ctypedoc :: { LHsType RdrName }
              : 'forall' tv_bndrs '.' ctypedoc {% hintExplicitForall (getLoc $1) >>
                                                  ams (LL $ mkExplicitHsForAllTy $2 (noLoc []) $4)
                                                      [mj AnnForall $1,mj AnnDot $3] }
              | context '=>' ctypedoc         {% ams (LL $ mkQualifiedHsForAllTy   $1 $3)
                                                     [mj AnnDarrow $2] }
              | ipvar '::' type               {% ams (LL (HsIParamTy (unLoc $1) $3))
                                                     [mj AnnDcolon $2] }
              | typedoc                       { $1 }
      ```
      
      == Parse result ==
      
      ```lang-haskell
      data HsParsedModule = HsParsedModule {
          hpm_module    :: Located (HsModule RdrName),
          hpm_src_files :: [FilePath],
             -- ^ extra source files (e.g. from #includes).  The lexer collects
             -- these from '# <file> <line>' pragmas, which the C preprocessor
             -- leaves behind.  These files and their timestamps are stored in
             -- the .hi file, so that we can force recompilation if any of
             -- them change (#3589)
          hpm_annotations :: ApiAnns
        }
      
      -- | The result of successful parsing.
      data ParsedModule =
        ParsedModule { pm_mod_summary   :: ModSummary
                     , pm_parsed_source :: ParsedSource
                     , pm_extra_src_files :: [FilePath]
                     , pm_annotations :: ApiAnns }
      ```
      
      This diff depends on D426
      
      Test Plan: sh ./validate
      
      Reviewers: austin, simonpj, Mikolaj
      
      Reviewed By: simonpj, Mikolaj
      
      Subscribers: Mikolaj, goldfire, thomie, carter
      
      Differential Revision: https://phabricator.haskell.org/D438
      
      GHC Trac Issues: #9628
      803fc5db
    • eir@cis.upenn.edu's avatar
      Fix #7484, checking for good binder names in Convert. · da2fca9e
      eir@cis.upenn.edu authored
      This commit also refactors a bunch of lexeme-oriented code into
      a new module Lexeme, and includes a submodule update for haddock.
      da2fca9e
  18. 20 Nov, 2014 1 commit
  19. 07 Nov, 2014 1 commit
    • rodlogic's avatar
      small parser/lexer cleanup · 37d64a51
      rodlogic authored
      Summary:
      The last three '#define ...' macros were removed from Parser.y.pp and this file was renamed to Parser.y.
      This basically got rid of a CPP step in the build.
      
      Also converted two modules in compiler/parser/ from .lhs to .hs.
      
      Test Plan: Does it build? Yes, I performed a full build here and things are looking good.
      
      Reviewers: austin
      
      Reviewed By: austin
      
      Subscribers: adamse, thomie, carter, simonmar
      
      Differential Revision: https://phabricator.haskell.org/D411
      37d64a51
  20. 26 Sep, 2014 1 commit
  21. 09 Sep, 2014 1 commit
    • Austin Seipp's avatar
      Make Applicative a superclass of Monad · d94de872
      Austin Seipp authored
      Summary:
      This includes pretty much all the changes needed to make `Applicative`
      a superclass of `Monad` finally. There's mostly reshuffling in the
      interests of avoid orphans and boot files, but luckily we can resolve
      all of them, pretty much. The only catch was that
      Alternative/MonadPlus also had to go into Prelude to avoid this.
      
      As a result, we must update the hsc2hs and haddock submodules.
      Signed-off-by: default avatarAustin Seipp <austin@well-typed.com>
      
      Test Plan: Build things, they might not explode horribly.
      
      Reviewers: hvr, simonmar
      
      Subscribers: simonmar
      
      Differential Revision: https://phabricator.haskell.org/D13
      d94de872
  22. 01 Sep, 2014 1 commit
    • thomie's avatar
      Make Lexer.x more like the 2010 report · 64c9898f
      thomie authored
      Summary:
      I tried reading the lexer and the 2010 report side-by-side. Althought I didn't
      quite finish, here are some small discrepancies that I found.
      
      This revision may be low priority for reviewers, but having these commits just
      in my local repository does no good either.
      
      Changes:
      * $nl was defined, but not used anywhere
      * formfeed is a newline character
      * add \: to $ascsymbol
        For simplification reason, the colon (':') was added to the character
        set $ascsymbol in the 2010 report. Here we make the same change.
      * introduce the macros `qvarid`, `qconid`, `qvarsym` and `qconsym`
      * foreign is a Haskell keyword
      * add/update comments
      
      Test Plan: Harbormaster (is awesome)
      
      Reviewers: simonmar, hvr, austin
      
      Reviewed By: austin
      
      Subscribers: hvr, simonmar, ezyang, carter
      
      Differential Revision: https://phabricator.haskell.org/D180
      64c9898f
  23. 27 Jul, 2014 1 commit
    • Iavor S. Diatchki's avatar
      Implement OVERLAPPING and OVERLAPPABLE pragmas (see #9242) · 97f499b5
      Iavor S. Diatchki authored
      This also removes the short-lived NO_OVERLAP pragama, and renames
      OVERLAP to OVERLAPS.
      
      An instance may be annotated with one of 4 pragams, to control its
      interaction with other overlapping instances:
      
        * OVERLAPPABLE:
          this instance is ignored if a more specific candidate exists
      
        * OVERLAPPING:
          this instance is preferred over more general candidates
      
        * OVERLAPS:
          both OVERLAPPING and OVERLAPPABLE (i.e., the previous GHC behavior).
          When compiling with -XOverlappingInstances, all instance are OVERLAPS.
      
        * INCOHERENT:
          same as before (see manual for details).
          When compiling with -XIncoherentInstances, all instances are INCOHERENT.
      97f499b5
  24. 21 Jul, 2014 1 commit
    • Edward Z. Yang's avatar
      Rename PackageId to PackageKey, distinguishing it from Cabal's PackageId. · 4bebab25
      Edward Z. Yang authored
      Summary:
      Previously, both Cabal and GHC defined the type PackageId, and we expected
      them to be roughly equivalent (but represented differently).  This refactoring
      separates these two notions.
      
      A package ID is a user-visible identifier; it's the thing you write in a
      Cabal file, e.g. containers-0.9.  The components of this ID are semantically
      meaningful, and decompose into a package name and a package vrsion.
      
      A package key is an opaque identifier used by GHC to generate linking symbols.
      Presently, it just consists of a package name and a package version, but
      pursuant to #9265 we are planning to extend it to record other information.
      Within a single executable, it uniquely identifies a package.  It is *not* an
      InstalledPackageId, as the choice of a package key affects the ABI of a package
      (whereas an InstalledPackageId is computed after compilation.)  Cabal computes
      a package key for the package and passes it to GHC using -package-name (now
      *extremely* misnamed).
      
      As an added bonus, we don't have to worry about shadowing anymore.
      
      As a follow on, we should introduce -current-package-key having the same role as
      -package-name, and deprecate the old flag.  This commit is just renaming.
      
      The haddock submodule needed to be updated.
      Signed-off-by: default avatarEdward Z. Yang <ezyang@cs.stanford.edu>
      
      Test Plan: validate
      
      Reviewers: simonpj, simonmar, hvr, austin
      
      Subscribers: simonmar, relrod, carter
      
      Differential Revision: https://phabricator.haskell.org/D79
      
      Conflicts:
      	compiler/main/HscTypes.lhs
      	compiler/main/Packages.lhs
      	utils/haddock
      4bebab25
  25. 30 Jun, 2014 1 commit
    • Iavor S. Diatchki's avatar
      Overlapable pragmas for individual instances (#9242) · 6290eead
      Iavor S. Diatchki authored
      Programmers may provide a pragma immediately after the `instance` keyword
      to control the overlap/incoherence behavior for individual instances.
      For example:
      
          instance {-# OVERLAP #-} C a where ...
      
      I chose this notation, rather than the other two outlined in the ticket
      for these reasons:
      
         1. Having the pragma after the type looks odd, I think.
         2. Having the pragma after there `where` does not work for
             stand-alone derived instances
      
      I have implemented 3 pragams:
      
         1. NO_OVERLAP
         2. OVERLAP
         3. INCOHERENT
      
      These correspond directly to the internal modes currently supported by
      GHC.  If a pragma is specified, it will be used no matter what flags are
      turned on.   For example, putting `NO_OVERLAP` on an instance will mark
      it as non-overlapping, even if `OVERLAPPIN_INSTANCES` is turned on for the
      module.
      6290eead
  26. 27 Jun, 2014 2 commits
    • Herbert Valerio Riedel's avatar
      Add -XBinaryLiterals language extension (re #9224) · 1c0b5fdc
      Herbert Valerio Riedel authored
      Haskell2010 supports
      
      - base-10 (prefix-less),
      - base-8 (via `0[oO]`-prefix), and
      - base-16 (via `0[xX]`-prefix) integer literals.
      
      This commit adds syntax support for base-2 integer literals via the new `0[bB]`
      prefix. The use of a `0b` prefix for indicating binary literals is known
      from popular programming languages such as C++14, Perl, Python, Ruby, and Java.
      
      This syntax extension is disabled by default and can be enabled via the
      new `{-# LANGUAGE BinaryLiterals #-}` pragma and/or the new `-XBinaryLiterals`
      
      This new extensions requires to upgrade the `ExtsBitmap` type from
      `Word` to `Word64` as this adds a 33th flag which is not guaranteed to
      fit into a `Word`.
      Signed-off-by: Herbert Valerio Riedel's avatarHerbert Valerio Riedel <hvr@gnu.org>
      
      Differential Revision: https://phabricator.haskell.org/D22
      1c0b5fdc
    • Herbert Valerio Riedel's avatar
      Refactor extension-bitmap in Lexer · b80d5739
      Herbert Valerio Riedel authored
      This introduces an Enum type `ExtBits` for the currently used 32 flags
      and introduces a type-synonym `ExtsBitmap` for representing a set over
      `ExtBits`. While at it, the current `Int` was replaced by `Word` to
      have the compiler catch any missed use-sites.
      
      This will make it easy to swap the `Word`-representation of `ExtsBitmap`
      by something different, such as e.g. a `Word64`
      
      Test Plan: successful validate
      
      Differential Revision: https://phabricator.haskell.org/D23
      b80d5739
  27. 20 Jan, 2014 1 commit
    • cactus's avatar
      Implement pattern synonyms · 4f8369bf
      cactus authored
      This patch implements Pattern Synonyms (enabled by -XPatternSynonyms),
      allowing y ou to assign names to a pattern and abstract over it.
      
      The rundown is this:
      
        * Named patterns are introduced by the new 'pattern' keyword, and can
          be either *unidirectional* or *bidirectional*. A unidirectional
          pattern is, in the simplest sense, simply an 'alias' for a pattern,
          where the LHS may mention variables to occur in the RHS. A
          bidirectional pattern synonym occurs when a pattern may also be used
          in expression context.
      
        * Unidirectional patterns are declared like thus:
      
              pattern P x <- x:_
      
          The synonym 'P' may only occur in a pattern context:
      
              foo :: [Int] -> Maybe Int
              foo (P x) = Just x
              foo _     = Nothing
      
        * Bidirectional patterns are declared like thus:
      
              pattern P x y = [x, y]
      
          Here, P may not only occur as a pattern, but also as an expression
          when given values for 'x' and 'y', i.e.
      
              bar :: Int -> [Int]
              bar x = P x 10
      
        * Patterns can't yet have their own type signatures; signatures are inferred.
      
        * Pattern synonyms may not be recursive, c.f. type synonyms.
      
        * Pattern synonyms are also exported/imported using the 'pattern'
          keyword in an import/export decl, i.e.
      
              module Foo (pattern Bar) where ...
      
          Note that pattern synonyms share the namespace of constructors, so
          this disambiguation is required as a there may also be a 'Bar'
          type in scope as well as the 'Bar' pattern.
      
        * The semantics of a pattern synonym differ slightly from a typical
          pattern: when using a synonym, the pattern itself is matched,
          followed by all the arguments. This means that the strictness
          differs slightly:
      
              pattern P x y <- [x, y]
      
              f (P True True) = True
              f _             = False
      
              g [True, True] = True
              g _            = False
      
          In the example, while `g (False:undefined)` evaluates to False,
          `f (False:undefined)` results in undefined as both `x` and `y`
          arguments are matched to `True`.
      
      For more information, see the wiki:
      
          https://ghc.haskell.org/trac/ghc/wiki/PatternSynonyms
          https://ghc.haskell.org/trac/ghc/wiki/PatternSynonyms/ImplementationReviewed-by: Simon Peyton Jones's avatarSimon Peyton Jones <simonpj@microsoft.com>
      Signed-off-by: default avatarAustin Seipp <austin@well-typed.com>
      4f8369bf
  28. 05 Dec, 2013 2 commits
  29. 01 Nov, 2013 1 commit
  30. 17 Oct, 2013 1 commit