Refactor wild card renaming
authorThomas Winant <thomas.winant@cs.kuleuven.be>
Tue, 9 Jun 2015 04:45:48 +0000 (23:45 -0500)
committerAustin Seipp <austin@well-typed.com>
Tue, 9 Jun 2015 05:10:21 +0000 (00:10 -0500)
commit058af6c90a0e8d122f2d1339b6b4fd0b5ec83d05
tree948f6dd1823c4f3c4b7cc9d79b689e51ab40ea87
parent7944a68f0a91033f50c5d0c56e923948bba30be1
Refactor wild card renaming

Summary:
Refactor wild card error reporting

* Merge `HsWildcardTy` and `HsNamedWildcardTy` into one constructor
  `HsWildCardTy` with as field the new type `HsWildCardInfo`, which has two
  constructors: `AnonWildCard` and `NamedWildCard`.

* All partial type checks are removed from `RdrHsSyn.hs` and are now done
  during renaming in order to report better error messages. When wild cards
  are allowed in a type, the new function `rnLHsTypeWithWildCards` (or
  `rnHsSigTypeWithWildCards`) should be used. This will bring the named wild
  cards into scope before renaming them. When this is not done, renaming will
  trigger "Unexpected wild card..." errors.

  Unfortunately, this has to be done separately for anonymous wild cards
  because they are given a fresh name during renaming, so they will not cause
  an out-of-scope error. They are handled in `tc_hs_type`, as a special case
  of a lookup that fails.

  The previous opt-out approach is replaced with an opt-in approach. No more
  panics because of forgotten checks!

* `[t| _ |]` isn't caught by the above two checks, so it is currently handled
  by a special case. The error message (generated in the `DsM` monad) doesn't
  provide as much context information as the other cases.

* Instead of three (!) functions that walk `HsType`, there is now only one
  pure function called `collectWildCards`.

* Alternative approach: catch all unwanted wild cards in `rnHsTyKi` by looking
  at the `HsDocContext`. This will reduce the number of places to catch
  unwanted wild cards form three to one, and make the error messages more
  uniform, albeit less informative, as the error context for renaming is not
  as informative as the one for type checking. A new constructor of
  `HsDocContext` will be required for pattern synonyms signatures.

  Small problem: currently type-class type signatures can't be distinguished
  from type signatures using the `HsDocContext`.

This requires an update to the Haddock submodule.

Test Plan: validate

Reviewers: goldfire, simonpj, austin

Reviewed By: simonpj

Subscribers: bgamari, thomie, goldfire

Differential Revision: https://phabricator.haskell.org/D613

GHC Trac Issues: #10098
49 files changed:
compiler/deSugar/DsMeta.hs
compiler/hsSyn/HsTypes.hs
compiler/hsSyn/PlaceHolder.hs
compiler/parser/Parser.y
compiler/parser/RdrHsSyn.hs
compiler/rename/RnBinds.hs
compiler/rename/RnExpr.hs
compiler/rename/RnTypes.hs
compiler/typecheck/TcEnv.hs
compiler/typecheck/TcHsType.hs
compiler/typecheck/TcRnDriver.hs
compiler/typecheck/TcRnMonad.hs
testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardNotLast.stderr
testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardTwice.hs [new file with mode: 0644]
testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardTwice.stderr [new file with mode: 0644]
testsuite/tests/partial-sigs/should_fail/NamedExtraConstraintsWildcard.stderr
testsuite/tests/partial-sigs/should_fail/NamedWildcardsNotInMonotype.stderr
testsuite/tests/partial-sigs/should_fail/NestedExtraConstraintsWildcard.stderr
testsuite/tests/partial-sigs/should_fail/NestedNamedExtraConstraintsWildcard.stderr
testsuite/tests/partial-sigs/should_fail/PartialClassMethodSignature.hs
testsuite/tests/partial-sigs/should_fail/PartialClassMethodSignature.stderr
testsuite/tests/partial-sigs/should_fail/PartialClassMethodSignature2.hs [new file with mode: 0644]
testsuite/tests/partial-sigs/should_fail/PartialClassMethodSignature2.stderr [new file with mode: 0644]
testsuite/tests/partial-sigs/should_fail/UnnamedConstraintWildcard1.stderr
testsuite/tests/partial-sigs/should_fail/UnnamedConstraintWildcard2.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInADT1.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInADT2.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInADT3.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInADTContext1.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInADTContext2.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInDefault.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInDefaultSignature.hs
testsuite/tests/partial-sigs/should_fail/WildcardInDefaultSignature.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInDeriving.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInForeignExport.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInForeignImport.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInGADT1.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInGADT2.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInInstanceHead.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInInstanceSig.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInNewtype.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInPatSynSig.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInStandaloneDeriving.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInTypeBrackets.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInTypeFamilyInstanceLHS.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInTypeFamilyInstanceRHS.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInTypeSynonymRHS.stderr
testsuite/tests/partial-sigs/should_fail/all.T
utils/haddock