summaryrefslogtreecommitdiff
path: root/compiler/GHC/Parser.y
Commit message (Collapse)AuthorAgeFilesLines
* Fix parsing & printing of unboxed sumssheaf2022-01-111-7/+12
| | | | | | | | | | | | | | | | | The pretty-printing of partially applied unboxed sums was incorrect, as we incorrectly dropped the first half of the arguments, even for a partial application such as (# | #) @IntRep @DoubleRep Int# which lead to the nonsensical (# DoubleRep | Int# #). This patch also allows users to write unboxed sum type constructors such as (# | #) :: TYPE r1 -> TYPE r2 -> TYPE (SumRep '[r1,r2]). Fixes #20858 and #20859.
* Fix typosKrzysztof Gogolewski2021-12-251-1/+1
|
* Fix panic trying to -ddump-parsed-ast for implicit fixityAlan Zimmerman2021-12-221-7/+15
| | | | | | | | | | | | | | A declaration such as infixr ++++ is supplied with an implicit fixity of 9 in the parser, but uses an invalid SrcSpan to capture this. Use of this span triggers a panic. Fix the problem by not recording an exact print annotation for the non-existent fixity source. Closes #20846
* More permissive parsing of higher-rank type IPssheaf2021-12-071-1/+1
| | | | | | | | | | | | | | | | | The parser now accepts implicit parameters with higher-rank types, such as `foo :: (?ip :: forall a. a -> a) => ...` Before this patch, we instead insisted on parentheses like so: `foo :: (?ip :: (forall a. a -> a)) => ...` The rest of the logic surrounding implicit parameters is unchanged; in particular, even with ImpredicativeTypes, this idiom is not likely to be very useful. Fixes #20654
* Allow keywords which can be used as variables to be used with ↵Matthew Pickering2021-11-261-1/+1
| | | | | | | | | | | | | OverloadedDotSyntax There are quite a few keywords which are allowed to be used as variables. Such as "as", "dependency" etc. These weren't accepted by OverloadedDotSyntax. The fix is pretty simple, use the varid production rather than raw VARID. Fixes #20723
* Use 'NonEmpty' for the fields in an 'HsProjection' (#20389)Zubin Duggal2021-11-201-4/+6
| | | | | | | | | | | | T12545 is very inconsistently affected by this change for some reason. There is a decrease in allocations on most configurations, but an increase on validate-x86_64-linux-deb9-unreg-hadrian. Accepting it as it seems unrelated to this patch. Metric Decrease: T12545 Metric Increase: T12545
* Remove unused module import syntax from .bkp modeMatthew Pickering2021-11-201-8/+2
| | | | | | | | | | | | | | | .bkp mode had this unused feature where you could write module A and it would go looking for A.hs on the file system and use that rather than provide the definition inline. This isn't use anywhere in the testsuite and the code to find the module A looks dubious. Therefore to reduce .bkp complexity I propose to remove it. Fixes #20701
* EPA: Get rid of bare SrcSpan's in the ParsedSourceAlan Zimmerman2021-11-021-57/+61
| | | | | | | | | | | | | The ghc-exactPrint library has had to re-introduce the relatavise phase. This is needed if you change the length of an identifier and want the layout to be preserved afterwards. It is not possible to relatavise a bare SrcSpan, so introduce `SrcAnn NoEpAnns` for them instead. Updates haddock submodule.
* HsToken for let/in (#19623)Vladislav Zavialov2021-11-021-2/+1
| | | | One more step towards the new design of EPA.
* EPA: Use LocatedA for ModuleNameAlan Zimmerman2021-10-241-17/+17
| | | | | This allows us to use an Anchor with a DeltaPos in it when exact printing.
* Refactor package importsSylvain Henry2021-10-221-3/+4
| | | | | | | | | Use an (Raw)PkgQual datatype instead of `Maybe FastString` to represent package imports. Factorize the code that renames RawPkgQual into PkgQual in function `rnPkgQual`. Renaming consists in checking if the FastString is the magic "this" keyword, the home-unit unit-id or something else. Bump haddock submodule
* EPA: Preserve semicolon order in annotationsAlan Zimmerman2021-10-141-20/+20
| | | | | | | | | Ensure the AddSemiAnn items appear in increasing order, so that if they are converted to delta format they are still in the correct order. Prior to this the exact printer sorted by Span, which is meaningless for EpaDelta locations.
* Bespoke TokenLocation data typeVladislav Zavialov2021-10-041-2/+2
| | | | | | | | | | | | The EpaAnnCO we were using contained an Anchor instead of EpaLocation, making it harder to work with. At the same time, using EpaLocation by itself isn't possible either, as we may have tokens without location information. Hence the new data type: data TokenLocation = NoTokenLoc | TokenLoc !EpaLocation
* EPA: correctly capture comments between 'where' and bindsAlan Zimmerman2021-09-171-11/+17
| | | | | | | | | | | | In the following foo = x where -- do stuff doStuff = do stuff The "-- do stuff" comment is captured in the HsValBinds. Closes #20297
* EPA: order of semicolons and comments for top-level decls is wrongAlan Zimmerman2021-09-061-6/+11
| | | | | | | | | | A comment followed by a semicolon at the top level resulted in the preceding comments being attached to the following declaration. Capture the comments as belonging to the declaration preceding the semicolon instead. Closes #20258
* Modify InlineSpec data constructor (helps fix #18138)Alina Banerjee2021-08-111-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The inl_inline field of the InlinePragma record is modified to store pragma source text by adding a data constructor of type SourceText. This can help in tracking the actual text of pragma names. Add/modify functions, modify type instance for InlineSpec type Modify parser, lexer to handle InlineSpec constructors containing SourceText Modify functions with InlineSpec type Extract pragma source from InlineSpec for SpecSig, InlineSig types Modify cvtInline function to add SourceText to InlineSpec type Extract name for InlineSig, SpecSig from pragma, SpectInstSig from source (fixes #18138) Extract pragma name for SpecPrag pragma, SpecSig signature Add Haddock annotation for inlinePragmaName function Add Haddock annotations for using helper functions in hsSigDoc Remove redundant ppr in pragma name for SpecSig, InlineSig; update comment Rename test to T18138 for misplaced SPECIALIZE pragma testcase
* HsUniToken and HsToken for HsArrow (#19623)Vladislav Zavialov2021-06-161-14/+13
| | | | | | Another step towards a simpler design for exact printing. Updates the haddock submodule.
* Change representation of HsGetField and HsProjectionShayne Fletcher2021-05-271-14/+14
| | | | | Another change in a series improving record syntax in the AST. The key change in this commit is the renaming of `HsFieldLabel` to `DotFieldOcc`.
* Support new parser types in GHCAlfredo Di Napoli2021-05-261-12/+18
| | | | | | | | | | | | | | This commit converts the lexers and all the parser machinery to use the new parser types and diagnostics infrastructure. Furthermore, it cleans up the way the parser code was emitting hints. As a result of this systematic approach, the test output of the `InfixAppPatErr` and `T984` tests have been changed. Previously they would emit a `SuggestMissingDo` hint, but this was not at all helpful in resolving the error, and it was even confusing by just looking at the original program that triggered the errors. Update haddock submodule
* HsToken for HsPar, ParPat, HsCmdPar (#19523)Vladislav Zavialov2021-05-231-1/+4
| | | | This patch is a first step towards a simpler design for exact printing.
* Introduce Strict.Maybe, Strict.Pair (#19156)Vladislav Zavialov2021-05-231-5/+7
| | | | | | | | | | | | | This patch fixes a space leak related to the use of Maybe in RealSrcSpan by introducing a strict variant of Maybe. In addition to that, it also introduces a strict pair and uses the newly introduced strict data types in a few other places (e.g. the lexer/parser state) to reduce allocations. Includes a regression test.
* Remove Maybe from Context in HsQualTyAlan Zimmerman2021-05-211-1/+1
| | | | | | Updates haddock submodule Closes #19845
* EPA: Fix explicit specificity and unicode linear arrow annotationsAlan Zimmerman2021-05-211-3/+6
| | | | | Closes #19839 Closes #19840
* Extensible Hints for diagnostic messagesAlfredo Di Napoli2021-05-201-0/+1
| | | | | | | | | | | | | | | | | | This commit extends the GHC diagnostic hierarchy with a `GhcHint` type, modelling helpful suggestions emitted by GHC which can be used to deal with a particular warning or error. As a direct consequence of this, the `Diagnostic` typeclass has been extended with a `diagnosticHints` method, which returns a `[GhcHint]`. This means that now we can clearly separate out the printing of the diagnostic message with the suggested fixes. This is done by extending the `printMessages` function in `GHC.Driver.Errors`. On top of that, the old `PsHint` type has been superseded by the new `GhcHint` type, which de-duplicates some hints in favour of a general `SuggestExtension` constructor that takes a `GHC.LanguageExtensions.Extension`.
* Changes to HsRecField'Shayne Fletcher2021-05-191-2/+2
|
* EPA: Fix incorrect SrcSpan for FamDeclAlan Zimmerman2021-05-121-1/+1
| | | | | | | The SrcSpan for a type family declaration did not include the family equations. Closes #19821
* EPA: record annotations for braces in LetStmtAlan Zimmerman2021-05-111-3/+1
| | | | Closes #19814
* EPA: Use custom AnnsIf structure for HsIf and HsCmdIfAlan Zimmerman2021-05-111-7/+12
| | | | | | | This clearly identifies the presence and location of optional semicolons in an if statement. Closes #19813
* EPA: properly capture leading semicolons in statement listsAlan Zimmerman2021-05-091-5/+5
| | | | | | | | | | | | | | For the fragment blah = do { ; print "a" ; print "b" } capture the leading semicolon before 'print "a"' in 'al_rest' in AnnList instead of in 'al_trailing'. Closes #19798
* fix #19736Daniel Rogozin2021-04-271-4/+4
|
* EPA: cleanups after the mergeAlan Zimmerman2021-04-191-48/+48
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Remove EpaAnn type synonym, rename EpaAnn' to EpaAnn. Closes #19705 Updates haddock submodule -- Change data EpaAnchor = AR RealSrcSpan | AD DeltaPos To instead be data EpaAnchor = AnchorReal RealSrcSpan | AnchorDelta DeltaPos Closes #19699 -- Change data DeltaPos = DP { deltaLine :: !Int, deltaColumn :: !Int } To instead be data DeltaPos = SameLine { deltaColumn :: !Int } | DifferentLine { deltaLine :: !Int, startColumn :: !Int } Closes #19698 -- Also some clean-ups of unused parts of check-exact.
* EPA : Rename AnnComment to EpaCommentAlan Zimmerman2021-03-311-2/+2
| | | | Follow-up from !2418, see #19579
* EPA : rename AnnAnchor to EpaAnchorAlan Zimmerman2021-03-311-14/+14
| | | | Follow-up from !2418, see #19579
* EPA : rename 'api annotations' to 'exact print annotations'Alan Zimmerman2021-03-311-1/+1
| | | | | | In comments, and notes. Follow-up from !2418, see #19579
* EPA : Rename ApiAnn to EPAnnAlan Zimmerman2021-03-311-162/+162
| | | | | | Follow-up from !2418, see #19579 Updates haddock submodule
* EPA : Rename AddApiAnn to AddEpAnnAlan Zimmerman2021-03-311-61/+61
| | | | | | | As port of the process of migrating naming from API Annotations to exact print annotations (EPA) Follow-up from !2418, see #19579
* EPA : Remove ApiAnn from ParsedModuleGHC GitLab CI2021-03-251-0/+2
| | | | | All the comments are now captured in the AST, there is no need for a side-channel structure for them.
* GHC Exactprint main commitAlan Zimmerman2021-03-201-1220/+1418
| | | | | | | | Metric Increase: T10370 parsing001 Updates haddock submodule
* Fix record dot precedence (#19521)Vladislav Zavialov2021-03-151-15/+6
| | | | | By moving the handling of TIGHT_INFIX_PROJ to the correct place, we can remove the isGetField hack and fix a bug at the same time.
* Implement record dot syntaxwip/joachim/bump-haddockShayne Fletcher2021-03-061-12/+83
|
* Wrap LHsContext in Maybe in the GHC ASTAlan Zimmerman2021-03-011-1/+1
| | | | | | | If the context is missing it is captured as Nothing, rather than putting a noLoc in the ParsedSource. Updates haddock submodule
* Improve handling of overloaded labels, literals, lists etcwip/T19154Simon Peyton Jones2021-02-191-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When implementing Quick Look I'd failed to remember that overloaded labels, like #foo, should be treated as a "head", so that they can be instantiated with Visible Type Application. This caused #19154. A very similar ticket covers overloaded literals: #19167. This patch fixes both problems, but (annoyingly, albeit temporarily) in two different ways. Overloaded labels I dealt with overloaded labels by buying fully into the Rebindable Syntax approach described in GHC.Hs.Expr Note [Rebindable syntax and HsExpansion]. There is a good overview in GHC.Rename.Expr Note [Handling overloaded and rebindable constructs]. That module contains much of the payload for this patch. Specifically: * Overloaded labels are expanded in the renamer, fixing #19154. See Note [Overloaded labels] in GHC.Rename.Expr. * Left and right sections used to have special code paths in the typechecker and desugarer. Now we just expand them in the renamer. This is harder than it sounds. See GHC.Rename.Expr Note [Left and right sections]. * Infix operator applications are expanded in the typechecker, specifically in GHC.Tc.Gen.App.splitHsApps. See Note [Desugar OpApp in the typechecker] in that module * ExplicitLists are expanded in the renamer, when (and only when) OverloadedLists is on. * HsIf is expanded in the renamer when (and only when) RebindableSyntax is on. Reason: the coverage checker treats HsIf specially. Maybe we could instead expand it unconditionally, and fix up the coverage checker, but I did not attempt that. Overloaded literals Overloaded literals, like numbers (3, 4.2) and strings with OverloadedStrings, were not working correctly with explicit type applications (see #19167). Ideally I'd also expand them in the renamer, like the stuff above, but I drew back on that because they can occur in HsPat as well, and I did not want to to do the HsExpanded thing for patterns. But they *can* now be the "head" of an application in the typechecker, and hence something like ("foo" @T) works now. See GHC.Tc.Gen.Head.tcInferOverLit. It's also done a bit more elegantly, rather than by constructing a new HsExpr and re-invoking the typechecker. There is some refactoring around tcShortCutLit. Ultimately there is more to do here, following the Rebindable Syntax story. There are a lot of knock-on effects: * HsOverLabel and ExplicitList no longer need funny (Maybe SyntaxExpr) fields to support rebindable syntax -- good! * HsOverLabel, OpApp, SectionL, SectionR all become impossible in the output of the typecheker, GhcTc; so we set their extension fields to Void. See GHC.Hs.Expr Note [Constructor cannot occur] * Template Haskell quotes for HsExpanded is a bit tricky. See Note [Quotation and rebindable syntax] in GHC.HsToCore.Quote. * In GHC.HsToCore.Match.viewLExprEq, which groups equal HsExprs for the purpose of pattern-match overlap checking, I found that dictionary evidence for the same type could have two different names. Easily fixed by comparing types not names. * I did quite a bit of annoying fiddling around in GHC.Tc.Gen.Head and GHC.Tc.Gen.App to get error message locations and contexts right, esp in splitHsApps, and the HsExprArg type. Tiresome and not very illuminating. But at least the tricky, higher order, Rebuilder function is gone. * Some refactoring in GHC.Tc.Utils.Monad around contexts and locations for rebindable syntax. * Incidentally fixes #19346, because we now print renamed, rather than typechecked, syntax in error mesages about applications. The commit removes the vestigial module GHC.Builtin.RebindableNames, and thus triggers a 2.4% metric decrease for test MultiLayerModules (#19293). Metric Decrease: MultiLayerModules T12545
* Parse symbolic names in ANN type correctly with otyconRyan Scott2021-02-161-1/+7
| | | | | | | | | | | | | | | | | This adds a new `otycon` production to the parser that allows for type constructor names that are either alphanumeric (`tycon`) or symbolic (`tyconsym`), where the latter must be parenthesized appropriately. `otycon` is much like the existing `oqtycon` production, except that it does not permit qualified names. The parser now uses `otycon` to parse type constructor names in `ANN type` declarations, which fixes #19374. To make sure that all of this works, I added three test cases: * `should_compile/T19374a`: the original test case from #19374 * `should_fail/T19374b`: a test that makes sure that an `ANN` with a qualified name fails to parse * `should_fail/T19374c`: a test that makes sure that an `ANN type` with a qualified name fails to parse
* The Char kind (#11342)Daniel Rogozin2021-02-061-0/+2
| | | | | | | | | | | | | | | | | | | | | | Co-authored-by: Rinat Stryungis <rinat.stryungis@serokell.io> Implement GHC Proposal #387 * Parse char literals 'x' at the type level * New built-in type families CmpChar, ConsSymbol, UnconsSymbol * New KnownChar class (cf. KnownSymbol and KnownNat) * New SomeChar type (cf. SomeSymbol and SomeNat) * CharTyLit support in template-haskell Updated submodules: binary, haddock. Metric Decrease: T5205 haddock.base Metric Increase: Naperian T13035
* INLINE pragma for patterns (#12178)Cale Gibbard2020-12-311-2/+24
| | | | | Allow INLINE and NOINLINE pragmas to be used for patterns. Those are applied to both the builder and matcher (where applicable).
* Refactor renamer datastructuresAdam Gundry2020-12-241-3/+3
| | | | | | | | | | | | | | | This patch significantly refactors key renamer datastructures (primarily Avail and GlobalRdrElt) in order to treat DuplicateRecordFields in a more robust way. In particular it allows the extension to be used with pattern synonyms (fixes where mangled record selector names could be printed instead of field labels (e.g. with -Wpartial-fields or hole fits, see new tests). The key idea is the introduction of a new type GreName for names that may represent either normal entities or field labels. This is then used in GlobalRdrElt and AvailInfo, in place of the old way of representing fields using FldParent (yuck) and an extra list in AvailTC. Updates the haddock submodule.
* Rename parser Error and Warning typesAlfredo Di Napoli2020-12-181-9/+9
| | | | | | | | | This commit renames parser's Error and Warning types (and their constructors) to have a 'Ps' prefix, so that this would play nicely when more errors and warnings for other phases of the pipeline will be added. This will make more explicit which is the particular type of error and warning we are dealing with, and will be more informative for users to see in the generated Haddock.
* Implement type applications in patternsCale Gibbard2020-12-141-1/+1
| | | | | The haddock submodule is also updated so that it understands the changes to patterns.
* Fix bad span calculations of post qualified importsShayne Fletcher2020-12-051-8/+15
|
* Replace HsImplicitBndrs with HsOuterTyVarBndrsRyan Scott2020-11-061-35/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This refactors the GHC AST to remove `HsImplicitBndrs` and replace it with `HsOuterTyVarBndrs`, a type which records whether the outermost quantification in a type is explicit (i.e., with an outermost, invisible `forall`) or implicit. As a result of this refactoring, it is now evident in the AST where the `forall`-or-nothing rule applies: it's all the places that use `HsOuterTyVarBndrs`. See the revamped `Note [forall-or-nothing rule]` in `GHC.Hs.Type` (previously in `GHC.Rename.HsType`). Moreover, the places where `ScopedTypeVariables` brings lexically scoped type variables into scope are a subset of the places that adhere to the `forall`-or-nothing rule, so this also makes places that interact with `ScopedTypeVariables` easier to find. See the revamped `Note [Lexically scoped type variables]` in `GHC.Hs.Type` (previously in `GHC.Tc.Gen.Sig`). `HsOuterTyVarBndrs` are used in type signatures (see `HsOuterSigTyVarBndrs`) and type family equations (see `HsOuterFamEqnTyVarBndrs`). The main difference between the former and the latter is that the former cares about specificity but the latter does not. There are a number of knock-on consequences: * There is now a dedicated `HsSigType` type, which is the combination of `HsOuterSigTyVarBndrs` and `HsType`. `LHsSigType` is now an alias for an `XRec` of `HsSigType`. * Working out the details led us to a substantial refactoring of the handling of explicit (user-written) and implicit type-variable bindings in `GHC.Tc.Gen.HsType`. Instead of a confusing family of higher order functions, we now have a local data type, `SkolemInfo`, that controls how these binders are kind-checked. It remains very fiddly, not fully satisfying. But it's better than it was. Fixes #16762. Bumps the Haddock submodule. Co-authored-by: Simon Peyton Jones <simonpj@microsoft.com> Co-authored-by: Richard Eisenberg <rae@richarde.dev> Co-authored-by: Zubin Duggal <zubin@cmi.ac.in>