1. 01 Nov, 2015 1 commit
  2. 25 Oct, 2015 1 commit
    • Alan Zimmerman's avatar
      Provide a utility to check API Annotations · 43751b24
      Alan Zimmerman authored
      It is difficult for GHC developers to know if they have broken the API
      Annotations.
      
      This patch provides a utility that can be used as a test to show up
      errors in the API Annotations.
      
      It is based on the current tests for ghc-api/annotations which can parse
      a file using the just-built GHC API, and check that no annotations are
      disconnected from the ParsedSource in the output.
      
      In addition, it should be able to dump the annotations to a file, so a
      new feature developer can check that all changes to the parser do
      provide annotations.
      
      Trac ticket: #10917
      
      Test Plan: ./validate
      
      Reviewers: hvr, thomie, austin, bgamari
      
      Reviewed By: bgamari
      
      Differential Revision: https://phabricator.haskell.org/D1368
      
      GHC Trac Issues: #10917
      43751b24
  3. 06 Aug, 2015 1 commit
    • Ben Gamari's avatar
      Ensure DynFlags are consistent · eca9a1a1
      Ben Gamari authored
      While we have always had makeDynFlagsConsistent to enforce a variety of
      consistency invariants on DynFlags, it hasn't been widely used.
      GHC.Main, for instance, ignored it entirely. This leads to issues like
      Trac #10549, where an OPTIONS_GHC pragma introduced an inconsistency,
      leading to a perplexing crash later in compilation.
      
      Here I add consistency checks in GHC.Main.set{Session,Program}DynFlags,
      closing this hole.
      
      Fixes #10549.
      
      Test Plan: Validate with T10549
      
      Reviewers: austin
      
      Subscribers: thomie
      
      Differential Revision: https://phabricator.haskell.org/D1128
      
      GHC Trac Issues: #10549
      eca9a1a1
  4. 02 Aug, 2015 1 commit
    • Alan Zimmerman's avatar
      Replace (SourceText,FastString) with StringLiteral data type · 15dd7007
      Alan Zimmerman authored
      Summary:
      Phab:D907 introduced SourceText for a number of data types, by replacing
      FastString with (SourceText,FastString). Since this has an Outputable
      instance, no warnings are generated when ppr is called on it, but
      unexpected output is generated. See Phab:D1096 for an example of this.
      
      Replace the (SourceText,FastString) tuples with a new data type,
      ```lang=hs
      data StringLiteral = StringLiteral SourceText FastString
      ```
      
      Update haddock submodule accordingly
      
      Test Plan: ./validate
      
      Reviewers: hvr, austin, rwbarton, trofi, bgamari
      
      Reviewed By: trofi, bgamari
      
      Subscribers: thomie, trofi, rwbarton, mpickering
      
      Differential Revision: https://phabricator.haskell.org/D1101
      
      GHC Trac Issues: #10692
      15dd7007
  5. 26 Jun, 2015 1 commit
  6. 18 Jun, 2015 1 commit
    • Alan Zimmerman's avatar
      Parser: commas_tup_tail duplicate SrcSpan on "Missing" value · 72b21c39
      Alan Zimmerman authored
      Summary:
      Parsing
      
          {-# LANGUAGE TupleSections #-}
      
          baz = (1, "hello", 6.5,,) 'a' (Just ())
      
      Results in the following AST fragment
      
          (L tests/examples/Tuple.hs:3:7-25
             (ExplicitTuple
                [ L tests/examples/Tuple.hs:3:8
                    (Present
                       (L tests/examples/Tuple.hs:3:8
                          (HsOverLit
                             (OverLit
                                (HsIntegral [ '1' ] 1)
                                PlaceHolder
                                (HsLit
                                   (HsString
                                      []
                                      {abstract:FastString}))
                                PlaceHolder))))
                , L tests/examples/Tuple.hs:3:11-17
                    (Present
                       (L tests/examples/Tuple.hs:3:11-17
                          (HsLit
                             (HsString
                                [ '"'
                                , 'h'
                                , 'e'
                                , 'l'
                                , 'l'
                                , 'o'
                                , '"'
                                ]
                                {abstract:FastString}))))
                , L tests/examples/Tuple.hs:3:20-22
                    (Present
                       (L tests/examples/Tuple.hs:3:20-22
                          (HsOverLit
                             (OverLit
                                (HsFractional
                                   (FL
                                      [ '6' , '.' , '5' ]
                                      (:% 13 2)))
                                PlaceHolder
                                (HsLit
                                   (HsString
                                      []
                                      {abstract:FastString}))
                                PlaceHolder))))
                , L tests/examples/Tuple.hs:3:24
                    (Missing PlaceHolder)
                , L tests/examples/Tuple.hs:3:24
                    (Missing PlaceHolder)
                ]
      
      The final `Missing PlaceHolder` has a duplicated `SrcSpan`
      
      Test Plan: ./validate
      
      Reviewers: austin, hvr, bgamari
      
      Reviewed By: bgamari
      
      Subscribers: thomie, bgamari, mpickering
      
      Differential Revision: https://phabricator.haskell.org/D995
      
      GHC Trac Issues: #10537
      72b21c39
  7. 12 Jun, 2015 1 commit
    • Simon Marlow's avatar
      Add parseExpr and compileParsedExpr and use them in GHC API and GHCi · d20031d4
      Simon Marlow authored
      Summary:
      This commit brings following changes and fixes:
      
       * Implement parseExpr and compileParsedExpr;
       * Fix compileExpr and dynCompilerExpr, which returned `()` for empty expr;
       * Fix :def and :cmd, which didn't work if `IO` or `String` is not in scope;
       * Use GHCiMonad instead IO in :def and :cmd;
       * Clean PrelInfo: delete dead comment and duplicate entries, add assertion.
      
      See new tests for more details.
      
      Test Plan: ./validate
      
      Reviewers: austin, dterei, simonmar
      
      Reviewed By: simonmar
      
      Subscribers: thomie, bgamari
      
      Differential Revision: https://phabricator.haskell.org/D974
      
      GHC Trac Issues: #10508
      d20031d4
  8. 02 Jun, 2015 1 commit
    • Austin Seipp's avatar
      compiler: make sure we reject -O + HscInterpreted · 091944e3
      Austin Seipp authored
      When using GHCi, we explicitly reject optimization, because the
      compilers optimization passes can introduce unboxed tuples, which the
      interpreter is not able to handle. But this goes the other way too: using
      GHCi on optimized code may cause the optimizer to float out breakpoints
      that the interpreter introduces. This manifests itself in weird ways,
      particularly if you as an API client use custom DynFlags to introduce
      optimization in combination with HscInterpreted.
      
      It turns out we weren't checking for consistent DynFlag settings when
      doing `setSessionDynFlags`, as #10052 showed. While the main driver
      handled it in `DynFlags` via `parseDynamicFlags`, we didn't check this
      elsewhere.
      
      This does a little refactoring to split out some of the common code, and
      immunizes the various `DynFlags` utilities in the `GHC` module from this
      particular bug. We should probably be checking other general invariants
      too.
      
      This fixes #10052
      
      , and adds some notes about the behavior in `GHC` and
      `FloatOut`
      
      As a bonus, expose `warningMsg` from `ErrUtils` as a helper since it
      didn't exist (somehow).
      Signed-off-by: default avatarAustin Seipp <austin@well-typed.com>
      
      Reviewed By: edsko
      
      Differential Revision: https://phabricator.haskell.org/D727
      
      GHC Trac Issues: #10052
      091944e3
  9. 01 Jun, 2015 2 commits
    • Alan Zimmerman's avatar
      ApiAnnotations : strings in warnings do not return SourceText · e6191d1c
      Alan Zimmerman authored
      Summary:
      The strings used in a WARNING pragma are captured via
      
          strings :: { Located ([AddAnn],[Located FastString]) }
              : STRING { sL1 $1 ([],[L (gl $1) (getSTRING $1)]) }
          ..
      
      The STRING token has a method getSTRINGs that returns the original
      source text for a string.
      
      A warning of the form
      
          {-# WARNING Logic
                    , mkSolver
                    , mkSimpleSolver
                    , mkSolverForLogic
                    , solverSetParams
                    , solverPush
                    , solverPop
                    , solverReset
                    , solverGetNumScopes
                    , solverAssertCnstr
                    , solverAssertAndTrack
                    , solverCheck
                    , solverCheckAndGetModel
                    , solverGetReasonUnknown
                    "New Z3 API support is still incomplete and fragile: \
                    \you may experience segmentation faults!"
            #-}
      
      returns the concatenated warning string rather than the original source.
      
      This...
      e6191d1c
    • Alan Zimmerman's avatar
      ApiAnnotations : rationalise tests · e00910b0
      Alan Zimmerman authored
      Summary:
      At the moment the API Annotations tests have a driver that has been
      copy/pasted multiple times.
      
      Compile it once, and run it for each test case.
      
      Test Plan: ./validate
      
      Reviewers: hvr, austin
      
      Reviewed By: austin
      
      Subscribers: bgamari, thomie
      
      Differential Revision: https://phabricator.haskell.org/D913
      
      GHC Trac Issues: #10452
      e00910b0
  10. 27 May, 2015 1 commit
    • Alan Zimmerman's avatar
      ApiAnnotations tweaks · c5911479
      Alan Zimmerman authored
      Summary:
      A collection of minor updates for the API Annotations.
      
      1. The annotations for the implicity parameter is disconnected in the
         following
      
          type MPI = ?mpi_secret :: MPISecret
      
      2. In the following, the annotation for one of the commas is disconeected.
      
          mkPoli = mkBila . map ((,,(),,()) <$> P.base <*> P.pos <*> P.form)
      
      3. In the following, the annotation for the parens becomes disconnected
      
          data MaybeDefault v where
              SetTo :: forall v . ( Eq v, Show v ) => !v -> MaybeDefault v
              SetTo4 :: forall v a. (( Eq v, Show v ) => v -> MaybeDefault v
                                                      -> a -> MaybeDefault [a])
      
      Test Plan: ./validate
      
      Reviewers: hvr, austin
      
      Reviewed By: austin
      
      Subscribers: bgamari, thomie, mpickering
      
      Differential Revision: https://phabricator.haskell.org/D901
      
      GHC Trac Issues: #10399
      c5911479
  11. 21 May, 2015 3 commits
  12. 19 May, 2015 2 commits
    • Austin Seipp's avatar
      Revert "compiler: make sure we reject -O + HscInterpreted" (again) · edb8dc5c
      Austin Seipp authored
      Apparently my machine likes this commit, but Harbormaster does not?
      
      This reverts commit b199536b.
      edb8dc5c
    • Austin Seipp's avatar
      compiler: make sure we reject -O + HscInterpreted · b199536b
      Austin Seipp authored
      When using GHCi, we explicitly reject optimization, because the
      compilers optimization passes can introduce unboxed tuples, which the
      interpreter is not able to handle. But this goes the other way too: using
      GHCi on optimized code may cause the optimizer to float out breakpoints
      that the interpreter introduces. This manifests itself in weird ways,
      particularly if you as an API client use custom DynFlags to introduce
      optimization in combination with HscInterpreted.
      
      It turns out we weren't checking for consistent DynFlag settings when
      doing `setSessionDynFlags`, as #10052 showed. While the main driver
      handled it in `DynFlags` via `parseDynamicFlags`, we didn't check this
      elsewhere.
      
      This does a little refactoring to split out some of the common code, and
      immunizes the various `DynFlags` utilities in the `GHC` module from this
      particular bug. We should probably be checking other general invariants
      too.
      
      This fixes #10052
      
      , and adds some notes about the behavior in `GHC` and
      `FloatOut`
      
      As a bonus, expose `warningMsg` from `ErrUtils` as a helper since it
      didn't exist (somehow).
      Signed-off-by: default avatarAustin Seipp <austin@well-typed.com>
      
      Reviewed By: edsko
      
      Differential Revision: https://phabricator.haskell.org/D727
      
      GHC Trac Issues: #10052
      b199536b
  13. 13 May, 2015 1 commit
    • Austin Seipp's avatar
      Revert D727 · 8764a7e8
      Austin Seipp authored
      This caused print007 to fail, so I guess I botched this more than I
      thought. This is a combination of reverting:
      
        "Fix build breakage from 9736c042", commit f35d621d.
        "compiler: make sure we reject -O + HscInterpreted", commit 9736c042.
      8764a7e8
  14. 12 May, 2015 2 commits
  15. 11 May, 2015 7 commits
    • Alan Zimmerman's avatar
      ApiAnnotations : PatBind gives wrong SrcSpan for the pattern. · ecc3d6be
      Alan Zimmerman authored
      Summary:
      The production for decl_no_th starts
      
          decl_no_th :: { Located (OrdList (LHsDecl RdrName)) }
                  : sigdecl               { $1 }
      
                  | '!' aexp rhs  {% do { let { e = sLL $1 $> (SectionR (sL1 $1 (HsVar bang_RDR)) $2) };
                                          pat <- checkPattern empty e;
          ...
      
      The e value should be just the pattern, excluding the rhs, but the span
      created includes the rhs.
      
      Test Plan: ./validate
      
      Reviewers: hvr, austin
      
      Reviewed By: austin
      
      Subscribers: bgamari, thomie, mpickering
      
      Differential Revision: https://phabricator.haskell.org/D873
      
      GHC Trac Issues: #10358
      ecc3d6be
    • Alan Zimmerman's avatar
      ApiAnnotations : pquals production adds AnnVbar in the wrong place · fe38195e
      Alan Zimmerman authored
      Summary:
      The Parser.y production for pquals is
      
          pquals :: { Located [[LStmt RdrName (LHsExpr RdrName)]] }
              : squals '|' pquals
                               {% addAnnotation (gl $ last $ unLoc $1) AnnVbar (gl $2) >>
                                  return (sLL $1 $> (reverse (unLoc $1) : unLoc $3)) }
              | squals         { L (getLoc $1) [reverse (unLoc $1)] }
      
      The squals are returned in reverse order, so the AnnVbar should be
      attached to the head of the list, not the last.
      
      Test Plan: ./validate
      
      Reviewers: hvr, austin
      
      Reviewed By: austin
      
      Subscribers: thomie, mpickering
      
      Differential Revision: https://phabricator.haskell.org/D869
      
      GHC Trac Issues: #10357
      fe38195e
    • Alan Zimmerman's avatar
      ApiAnnotations : BooleanFormula construction discards original · 24707d72
      Alan Zimmerman authored
      Summary:
      The MINIMAL pragma is captured in the parser using a BooleanFormula.
      
      The constructors (mkBool,mkAnd,mkOr) are smart and try to minimise the
      boolean formula as it is constructed.
      
      This discards the original information, making round tripping
      impossible.
      
      Note: there is another version which provides a more API Annotations
      friendly version of the MINIMAL pragma, but this requires changes to
      haddock, which will cause problems for 7.10.2.
      
      See https://github.com/alanz/ghc/tree/wip/10287
      
      Test Plan: ./validate
      
      Reviewers: hvr, austin
      
      Reviewed By: austin
      
      Subscribers: bgamari, Fuuzetsu, thomie, mpickering
      
      Differential Revision: https://phabricator.haskell.org/D837
      
      GHC Trac Issues: #10287
      24707d72
    • Austin Seipp's avatar
      compiler: make sure we reject -O + HscInterpreted · 9736c042
      Austin Seipp authored
      When using GHCi, we explicitly reject optimization, because the
      compilers optimization passes can introduce unboxed tuples, which the
      interpreter is not able to handle. But this goes the other way too: using
      GHCi on optimized code may cause the optimizer to float out breakpoints
      that the interpreter introduces. This manifests itself in weird ways,
      particularly if you as an API client use custom DynFlags to introduce
      optimization in combination with HscInterpreted.
      
      It turns out we weren't checking for consistent DynFlag settings when
      doing `setSessionDynFlags`, as #10052 showed. While the main driver
      handled it in `DynFlags` via `parseDynamicFlags`, we didn't check this
      elsewhere.
      
      This does a little refactoring to split out some of the common code, and
      immunizes the various `DynFlags` utilities in the `GHC` module from this
      particular bug. We should probably be checking other general invariants
      too.
      
      This fixes #10052
      
      , and adds some notes about the behavior in `GHC` and
      `FloatOut`
      
      As a bonus, expose `warningMsg` from `ErrUtils` as a helper since it
      didn't exist (somehow).
      Signed-off-by: default avatarAustin Seipp <austin@well-typed.com>
      
      Reviewed By: edsko
      
      Differential Revision: https://phabricator.haskell.org/D727
      
      GHC Trac Issues: #10052
      9736c042
    • Simon Marlow's avatar
      More accurate allocation stats for :set +s · cf7573b8
      Simon Marlow authored
      The point of this commit is to make the memory allocation statistic
      from :set +s in GHCi a lot more accurate.  Currently it uses the total
      allocation figure calculated by the RTS, which is only updated during
      GC, so can be wrong by an arbitrary amount.  The fix is to the the
      per-thread allocation counter that was introduced for allocation
      limits.
      
      This required changes to the GHC API, because we now have to return
      the allocation value from each evaluation.  Rather than just change
      the API, I introduced a new API and deprecated the old one.  The new
      one is simpler and more extensible, so hopefully we won't need to make
      this transition in the future.  See GHC.hs for details.
      cf7573b8
    • Alan Zimmerman's avatar
      ApiAnnotations : mkGadtDecl discards annotations for HsFunTy · e4032b19
      Alan Zimmerman authored
      Summary:
      When mkGadtDecl is presented wih a HsFunTy it discards the SrcSpan, thus
      disconnecting any annotations on the HsFunTy.
      
      ```
      mkGadtDecl names (L ls (HsForAllTy imp Nothing qvars cxt tau))
        = return $ mk_gadt_con names
        where
          (details, res_ty)           -- See Note [Sorting out the result type]
            = case tau of
                L _ (HsFunTy (L l (HsRecTy flds)) res_ty)
                                                  -> (RecCon (L l flds), res_ty)
                _other                                    -> (PrefixCon [], tau)
      ...
      ```
      
      This can be triggered by the following
      
      ```
      {-# LANGUAGE GADTs #-}
      module GADTRecords2 (H1(..)) where
      
      -- | h1
      data H1 a b where
        C3 :: (Num a) => { field :: a -- ^ hello docs
                         } -> H1 Int Int
      ```
      
      Test Plan: ./validate
      
      Reviewers: hvr, austin
      
      Reviewed By: austin
      
      Subscribers: bgamari, thomie, mpickering
      
      Differential Revision: https://phabricator.haskell.org/D848
      
      GHC Trac Issues: #10309
      e4032b19
    • Alan Zimmerman's avatar
      Api Annotations: RdrHsSyn.mkAtDefault causes annotations to be disconnected. · 811b72ad
      Alan Zimmerman authored
      Summary:
      The code for mkAtDefault is as follows.
      
          mkATDefault (L loc (TyFamInstDecl { tfid_eqn = L _ e }))
                | TyFamEqn { tfe_tycon = tc, tfe_pats = pats, tfe_rhs = rhs } <- e
                = do { tvs <- checkTyVars (ptext (sLit "default")) equalsDots tc (hswb_cts pats)
                     ; return (L loc (TyFamEqn { tfe_tycon = tc
                                               , tfe_pats = tvs
                                               , tfe_rhs = rhs })) }
      
      An associated type in a class of the form
      
          type FoldableConstraint t x = ()
      
      has an AnnEqual attached to the location in tfid_eqn. Since the location
      is discarded, this annotation is then disconnected from the AST.
      
      Test Plan: ./validate
      
      Reviewers: hvr, austin
      
      Reviewed By: austin
      
      Subscribers: bgamari, thomie, mpickering
      
      Differential Revision: https://phabricator.haskell.org/D842
      
      GHC Trac Issues: #10307
      811b72ad
  16. 08 May, 2015 2 commits
  17. 07 May, 2015 1 commit
    • Alan Zimmerman's avatar
      ApiAnnotations : RdrHsSyn.isFunLhs discards parentheses · 5bde9f7c
      Alan Zimmerman authored
      Summary:
      The RdrHsSyn.isFunLhs function has the following
      
        isFunLhs e = go e []
         where
           go (L loc (HsVar f)) es
                | not (isRdrDataCon f)   = return (Just (L loc f, False, es))
           go (L _ (HsApp f e)) es       = go f (e:es)
           go (L _ (HsPar e))   es@(_:_) = go e es
      
      The treatment of HsPar means that any parentheses around an infix function will be discarded.
      
      e.g.
      
        (f =*= g) sa i = f (toF sa i) =^= g (toG sa i)
      
      will lose the ( before f and the closing one after g
      
      Test Plan: ./validate
      
      Reviewers: hvr, austin
      
      Reviewed By: austin
      
      Subscribers: bgamari, thomie
      
      Differential Revision: https://phabricator.haskell.org/D832
      
      GHC Trac Issues: #10269
      5bde9f7c
  18. 06 May, 2015 5 commits
    • Austin Seipp's avatar
      Revert "API Annotations : add Locations in hsSyn were layout occurs" · 97d320f5
      Austin Seipp authored
      This reverts commit fb54b2c1.
      
      As Alan pointed out, this will make cherry picking a lot harder until
      7.10.2, so lets back it out until after the release.
      97d320f5
    • Austin Seipp's avatar
      Revert "ApiAnnotations : Nested forall loses forall annotation" · f34c0728
      Austin Seipp authored
      This reverts commit 81030ede.
      
      Alan is abandoning this approach in favor of D836.
      f34c0728
    • Alan Zimmerman's avatar
      ApiAnnotations : Nested forall loses forall annotation · 81030ede
      Alan Zimmerman authored
      When parsing
      
          {-# LANGUAGE ScopedTypeVariables #-}
      
          extremumNewton :: forall tag. forall tag1.
                             tag -> tag1 -> Int
          extremumNewton = undefined
      
      The parser attaches an AnnForall to the second forall, which appears as
      a nested HsForAllTy.
      
      Somewhere this nesting is flattened, and the tyvarbndrs are collapsed
      into a single HsForAllTy. In this process the second AnnForAll loses its
      anchor in the AST.
      
      Reviewed By: austin
      
      Differential Revision: https://phabricator.haskell.org/D833
      
      GHC Trac Issues: #10278
      81030ede
    • Alan Zimmerman's avatar
      ApiAnnotations : quoted type variables missing leading quote · 15aafc7f
      Alan Zimmerman authored
      The HsOpTy can be constructed for a promoted type operator, in which case it has the following form
      
              | btype SIMPLEQUOTE qconop type     { sLL $1 $> $ mkHsOpTy $1 $3 $4 }
              | btype SIMPLEQUOTE varop  type     { sLL $1 $> $ mkHsOpTy $1 $3 $4 }
      
      The SIMPLEQUOTE does not get an annotation, so cannot be reproduced via the API Annotations.
      
      Also, in
      
      splice_exp :: { LHsExpr RdrName }
              : TH_ID_SPLICE          { sL1 $1 $ mkHsSpliceE
                                              (sL1 $1 $ HsVar (mkUnqual varName
                                                              (getTH_ID_SPLICE $1))) }
              | '$(' exp ')'          {% ams (sLL $1 $> $ mkHsSpliceE $2) [mo $1,mc $3] }
              | TH_ID_TY_SPLICE       { sL1 $1 $ mkHsSpliceTE
                                              (sL1 $1 $ HsVar (mkUnqual varName
                                                           (getTH_ID_TY_SPLICE $1))) }
              | '$$(' exp ')'         {% ams (sLL $1 $> $ mkHsSpliceTE $2) [mo $1,mc $3] }
      
      the TH_ID_SPLICE and TH_ID_TY_SPLICE positions are lost.
      
      Reviewed By: austin
      
      Differential Revision: https://phabricator.haskell.org/D825
      
      GHC Trac Issues: #10268
      15aafc7f
    • Alan Zimmerman's avatar
      API Annotations : add Locations in hsSyn were layout occurs · fb54b2c1
      Alan Zimmerman authored
      At the moment ghc-exactprint, which uses the GHC API Annotations to
      provide a framework for roundtripping Haskell source code with optional
      AST edits, has to implement a horrible workaround to manage the points
      where layout needs to be captured.
      
      These are
      
          MatchGroup
          HsDo
          HsCmdDo
          HsLet
          LetStmt
          HsCmdLet
          GRHSs
      
      To provide a more natural representation, the contents subject to layout
      rules need to be wrapped in a SrcSpan.
      
      This commit does this.
      
      Trac ticket #10250
      
      Reviewed By: austin
      
      Differential Revision: https://phabricator.haskell.org/D815
      
      GHC Trac Issues: #10250
      fb54b2c1
  19. 14 Apr, 2015 5 commits
  20. 07 Apr, 2015 1 commit