Refactor treatment of wildcards
authorSimon Peyton Jones <simonpj@microsoft.com>
Tue, 1 Dec 2015 16:38:23 +0000 (17:38 +0100)
committerBen Gamari <ben@smart-cactus.org>
Tue, 1 Dec 2015 17:45:23 +0000 (18:45 +0100)
commit1e041b7382b6aa329e4ad9625439f811e0f27232
tree91f4418553a1e6df072f56f43b5697d40c985b5f
parentb432e2f39c095d8acbb0cfcc63bd08436c7a3e49
Refactor treatment of wildcards

This patch began as a modest refactoring of HsType and friends, to
clarify and tidy up exactly where quantification takes place in types.
Although initially driven by making the implementation of wildcards more
tidy (and fixing a number of bugs), I gradually got drawn into a pretty
big process, which I've been doing on and off for quite a long time.

There is one compiler performance regression as a result of all
this, in perf/compiler/T3064.  I still need to look into that.

* The principal driving change is described in Note [HsType binders]
  in HsType.  Well worth reading!

* Those data type changes drive almost everything else.  In particular
  we now statically know where

       (a) implicit quantification only (LHsSigType),
           e.g. in instance declaratios and SPECIALISE signatures

       (b) implicit quantification and wildcards (LHsSigWcType)
           can appear, e.g. in function type signatures

* As part of this change, HsForAllTy is (a) simplified (no wildcards)
  and (b) split into HsForAllTy and HsQualTy.  The two contructors
  appear when and only when the correponding user-level construct
  appears.  Again see Note [HsType binders].

  HsExplicitFlag disappears altogether.

* Other simplifications

     - ExprWithTySig no longer needs an ExprWithTySigOut variant

     - TypeSig no longer needs a PostRn name [name] field
       for wildcards

     - PatSynSig records a LHsSigType rather than the decomposed
       pieces

     - The mysterious 'GenericSig' is now 'ClassOpSig'

* Renamed LHsTyVarBndrs to LHsQTyVars

* There are some uninteresting knock-on changes in Haddock,
  because of the HsSyn changes

I also did a bunch of loosely-related changes:

* We already had type synonyms CoercionN/CoercionR for nominal and
  representational coercions.  I've added similar treatment for

      TcCoercionN/TcCoercionR

      mkWpCastN/mkWpCastN

  All just type synonyms but jolly useful.

* I record-ised ForeignImport and ForeignExport

* I improved the (poor) fix to Trac #10896, by making
  TcTyClsDecls.checkValidTyCl recover from errors, but adding a
  harmless, abstract TyCon to the envt if so.

* I did some significant refactoring in RnEnv.lookupSubBndrOcc,
  for reasons that I have (embarrassingly) now totally forgotten.
  It had to do with something to do with import and export

Updates haddock submodule.
319 files changed:
compiler/basicTypes/RdrName.hs
compiler/deSugar/Coverage.hs
compiler/deSugar/DsArrows.hs
compiler/deSugar/DsBinds.hs
compiler/deSugar/DsExpr.hs
compiler/deSugar/DsForeign.hs
compiler/deSugar/DsMeta.hs
compiler/ghc.mk
compiler/hsSyn/Convert.hs
compiler/hsSyn/HsBinds.hs
compiler/hsSyn/HsDecls.hs
compiler/hsSyn/HsExpr.hs
compiler/hsSyn/HsPat.hs
compiler/hsSyn/HsSyn.hs
compiler/hsSyn/HsTypes.hs
compiler/hsSyn/HsUtils.hs
compiler/iface/IfaceSyn.hs
compiler/main/HscStats.hs
compiler/main/HscTypes.hs
compiler/parser/Lexer.x
compiler/parser/Parser.y
compiler/parser/RdrHsSyn.hs
compiler/prelude/PrelNames.hs
compiler/rename/RnBinds.hs
compiler/rename/RnEnv.hs
compiler/rename/RnExpr.hs
compiler/rename/RnNames.hs
compiler/rename/RnPat.hs
compiler/rename/RnSource.hs
compiler/rename/RnSplice.hs
compiler/rename/RnTypes.hs
compiler/typecheck/TcArrows.hs
compiler/typecheck/TcBinds.hs
compiler/typecheck/TcClassDcl.hs
compiler/typecheck/TcDefaults.hs
compiler/typecheck/TcDeriv.hs
compiler/typecheck/TcEnv.hs
compiler/typecheck/TcErrors.hs
compiler/typecheck/TcEvidence.hs
compiler/typecheck/TcExpr.hs
compiler/typecheck/TcForeign.hs
compiler/typecheck/TcGenDeriv.hs
compiler/typecheck/TcHsSyn.hs
compiler/typecheck/TcHsType.hs
compiler/typecheck/TcInstDcls.hs
compiler/typecheck/TcMType.hs
compiler/typecheck/TcMatches.hs
compiler/typecheck/TcPat.hs
compiler/typecheck/TcPatSyn.hs
compiler/typecheck/TcPatSyn.hs-boot
compiler/typecheck/TcRnDriver.hs
compiler/typecheck/TcRnMonad.hs
compiler/typecheck/TcRnTypes.hs
compiler/typecheck/TcRules.hs
compiler/typecheck/TcSMonad.hs
compiler/typecheck/TcSimplify.hs
compiler/typecheck/TcSplice.hs
compiler/typecheck/TcTyClsDecls.hs
compiler/typecheck/TcTyDecls.hs
compiler/typecheck/TcType.hs
compiler/typecheck/TcTypeable.hs
compiler/typecheck/TcUnify.hs
compiler/typecheck/TcValidity.hs
compiler/types/Coercion.hs
compiler/types/InstEnv.hs
compiler/utils/Util.hs
ghc/InteractiveUI.hs
libraries/base/Data/Monoid.hs
testsuite/tests/ado/ado005.stderr
testsuite/tests/arrows/should_fail/T5380.stderr
testsuite/tests/deriving/should_fail/T5287.stderr
testsuite/tests/gadt/T3169.stderr
testsuite/tests/gadt/T7558.stderr
testsuite/tests/gadt/rw.stderr
testsuite/tests/ghc-api/annotations/all.T
testsuite/tests/ghc-api/landmines/landmines.stdout
testsuite/tests/ghci/scripts/Defer02.stderr
testsuite/tests/ghci/scripts/T10248.stderr
testsuite/tests/ghci/scripts/T7873.stdout
testsuite/tests/ghci/scripts/ghci050.stderr
testsuite/tests/indexed-types/should_compile/PushedInAsGivens.stderr
testsuite/tests/indexed-types/should_compile/Records.hs
testsuite/tests/indexed-types/should_compile/Simple14.stderr
testsuite/tests/indexed-types/should_compile/T3208b.stderr
testsuite/tests/indexed-types/should_fail/BadSock.hs
testsuite/tests/indexed-types/should_fail/GADTwrong1.stderr
testsuite/tests/indexed-types/should_fail/NoMatchErr.stderr
testsuite/tests/indexed-types/should_fail/Overlap6.stderr
testsuite/tests/indexed-types/should_fail/SimpleFail15.stderr
testsuite/tests/indexed-types/should_fail/SimpleFail16.stderr
testsuite/tests/indexed-types/should_fail/SimpleFail5a.stderr
testsuite/tests/indexed-types/should_fail/T1897b.stderr
testsuite/tests/indexed-types/should_fail/T1900.stderr
testsuite/tests/indexed-types/should_fail/T2693.stderr
testsuite/tests/indexed-types/should_fail/T3330a.stderr
testsuite/tests/indexed-types/should_fail/T3440.stderr
testsuite/tests/indexed-types/should_fail/T4093a.stderr
testsuite/tests/indexed-types/should_fail/T4093b.stderr
testsuite/tests/indexed-types/should_fail/T4174.stderr
testsuite/tests/indexed-types/should_fail/T4272.stderr
testsuite/tests/indexed-types/should_fail/T7194.stderr
testsuite/tests/indexed-types/should_fail/T9036.stderr
testsuite/tests/indexed-types/should_fail/T9171.stderr
testsuite/tests/indexed-types/should_fail/T9433.stderr
testsuite/tests/indexed-types/should_fail/T9662.stderr
testsuite/tests/module/mod98.stderr
testsuite/tests/monadfail/MonadFailErrors.stderr
testsuite/tests/monadfail/MonadFailWarnings.stderr
testsuite/tests/overloadedrecflds/should_fail/overloadedlabelsfail01.stderr
testsuite/tests/parser/should_fail/NoPatternSynonyms.stderr
testsuite/tests/parser/should_fail/T3811.stderr
testsuite/tests/parser/should_fail/T7848.stderr
testsuite/tests/parser/should_fail/readFail031.stderr
testsuite/tests/partial-sigs/should_compile/Defaulting2MROn.stderr
testsuite/tests/partial-sigs/should_compile/ExprSigLocal.hs [new file with mode: 0644]
testsuite/tests/partial-sigs/should_compile/ExprSigLocal.stderr [new file with mode: 0644]
testsuite/tests/partial-sigs/should_compile/ExtraConstraints3.stderr
testsuite/tests/partial-sigs/should_compile/SomethingShowable.hs
testsuite/tests/partial-sigs/should_compile/SomethingShowable.stderr
testsuite/tests/partial-sigs/should_compile/SplicesUsed.stderr
testsuite/tests/partial-sigs/should_compile/T10403.hs
testsuite/tests/partial-sigs/should_compile/T10403.stderr
testsuite/tests/partial-sigs/should_compile/T10438.stderr
testsuite/tests/partial-sigs/should_compile/T10519.stderr
testsuite/tests/partial-sigs/should_compile/WarningWildcardInstantiations.stderr
testsuite/tests/partial-sigs/should_compile/all.T
testsuite/tests/partial-sigs/should_fail/Defaulting1MROff.hs
testsuite/tests/partial-sigs/should_fail/Defaulting1MROff.stderr
testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardInExpressionSignature.stderr
testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardInPatternSignature.stderr
testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardInTypeSplice2.hs
testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardInTypeSplice2.stderr
testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardInTypeSpliceUsed.stderr
testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardNotEnabled.stderr
testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardNotLast.stderr
testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardNotPresent.stderr
testsuite/tests/partial-sigs/should_fail/ExtraConstraintsWildcardTwice.stderr
testsuite/tests/partial-sigs/should_fail/InstantiatedNamedWildcardsInConstraints.stderr
testsuite/tests/partial-sigs/should_fail/NamedExtraConstraintsWildcard.stderr
testsuite/tests/partial-sigs/should_fail/NamedWildcardInDataFamilyInstanceLHS.stderr
testsuite/tests/partial-sigs/should_fail/NamedWildcardInTypeFamilyInstanceLHS.stderr
testsuite/tests/partial-sigs/should_fail/NamedWildcardInTypeSplice.stderr
testsuite/tests/partial-sigs/should_fail/NamedWildcardsEnabled.stderr
testsuite/tests/partial-sigs/should_fail/NamedWildcardsNotEnabled.stderr
testsuite/tests/partial-sigs/should_fail/NamedWildcardsNotInMonotype.hs
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.stderr
testsuite/tests/partial-sigs/should_fail/PartialClassMethodSignature2.stderr
testsuite/tests/partial-sigs/should_fail/PartialTypeSignaturesDisabled.stderr
testsuite/tests/partial-sigs/should_fail/T10045.stderr
testsuite/tests/partial-sigs/should_fail/T10615.stderr
testsuite/tests/partial-sigs/should_fail/T10999.hs
testsuite/tests/partial-sigs/should_fail/T10999.stderr
testsuite/tests/partial-sigs/should_fail/TidyClash.stderr
testsuite/tests/partial-sigs/should_fail/Trac10045.hs [deleted file]
testsuite/tests/partial-sigs/should_fail/Trac10045.stderr [deleted file]
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.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/WildcardInTypeFamilyInstanceRHS.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInTypeSynonymRHS.stderr
testsuite/tests/partial-sigs/should_fail/WildcardInstantiations.stderr
testsuite/tests/partial-sigs/should_fail/all.T
testsuite/tests/patsyn/should_fail/T9161-1.stderr
testsuite/tests/patsyn/should_fail/T9161-2.stderr
testsuite/tests/perf/compiler/T5837.stderr
testsuite/tests/perf/compiler/all.T
testsuite/tests/polykinds/PolyKinds02.stderr
testsuite/tests/polykinds/T10503.stderr
testsuite/tests/polykinds/T10516.stderr
testsuite/tests/polykinds/T6021.stderr
testsuite/tests/polykinds/T6068.hs
testsuite/tests/polykinds/T7224.stderr
testsuite/tests/polykinds/T7230.stderr
testsuite/tests/polykinds/T7278.stderr
testsuite/tests/polykinds/T7328.stderr
testsuite/tests/polykinds/T7438.stderr
testsuite/tests/polykinds/T9222.stderr
testsuite/tests/rename/should_compile/T4426.hs
testsuite/tests/rename/should_compile/T4426.stderr
testsuite/tests/rename/should_compile/T5331.stderr
testsuite/tests/rename/should_compile/all.T
testsuite/tests/rename/should_fail/T2901.stderr
testsuite/tests/rename/should_fail/T5372.hs
testsuite/tests/rename/should_fail/T5372.stderr
testsuite/tests/rename/should_fail/rnfail026.stderr
testsuite/tests/roles/should_fail/RolesIArray.stderr
testsuite/tests/simplCore/should_compile/T8848.stderr
testsuite/tests/simplCore/should_compile/T8848a.stderr
testsuite/tests/simplCore/should_compile/rule2.stderr
testsuite/tests/th/T10267.stderr
testsuite/tests/th/T3177a.stderr
testsuite/tests/th/T8625.stdout
testsuite/tests/th/TH_pragma.stderr
testsuite/tests/typecheck/should_compile/FD1.stderr
testsuite/tests/typecheck/should_compile/FD2.stderr
testsuite/tests/typecheck/should_compile/FD3.stderr
testsuite/tests/typecheck/should_compile/T10632.stderr
testsuite/tests/typecheck/should_compile/T7220a.stderr
testsuite/tests/typecheck/should_compile/T9834.stderr
testsuite/tests/typecheck/should_compile/T9939.stderr
testsuite/tests/typecheck/should_compile/tc141.stderr
testsuite/tests/typecheck/should_compile/tc166.hs
testsuite/tests/typecheck/should_compile/tc168.stderr
testsuite/tests/typecheck/should_compile/tc182.hs
testsuite/tests/typecheck/should_compile/tc244.hs
testsuite/tests/typecheck/should_fail/ContextStack2.stderr
testsuite/tests/typecheck/should_fail/CustomTypeErrors02.stderr
testsuite/tests/typecheck/should_fail/CustomTypeErrors03.stderr
testsuite/tests/typecheck/should_fail/FDsFromGivens.stderr
testsuite/tests/typecheck/should_fail/FailDueToGivenOverlapping.stderr
testsuite/tests/typecheck/should_fail/IPFail.stderr
testsuite/tests/typecheck/should_fail/T10285.stderr
testsuite/tests/typecheck/should_fail/T10351.stderr
testsuite/tests/typecheck/should_fail/T10534.stderr
testsuite/tests/typecheck/should_fail/T10715.stderr
testsuite/tests/typecheck/should_fail/T11112.stderr
testsuite/tests/typecheck/should_fail/T1897a.stderr
testsuite/tests/typecheck/should_fail/T1899.stderr
testsuite/tests/typecheck/should_fail/T2538.stderr
testsuite/tests/typecheck/should_fail/T2714.stderr
testsuite/tests/typecheck/should_fail/T3102.stderr
testsuite/tests/typecheck/should_fail/T3540.stderr
testsuite/tests/typecheck/should_fail/T4875.stderr
testsuite/tests/typecheck/should_fail/T5236.stderr
testsuite/tests/typecheck/should_fail/T5300.stderr
testsuite/tests/typecheck/should_fail/T5957.stderr
testsuite/tests/typecheck/should_fail/T6022.stderr
testsuite/tests/typecheck/should_fail/T7279.stderr
testsuite/tests/typecheck/should_fail/T7410.stderr
testsuite/tests/typecheck/should_fail/T7453.stderr
testsuite/tests/typecheck/should_fail/T7609.stderr
testsuite/tests/typecheck/should_fail/T7645.stderr
testsuite/tests/typecheck/should_fail/T7696.stderr
testsuite/tests/typecheck/should_fail/T7697.stderr
testsuite/tests/typecheck/should_fail/T7748a.stderr
testsuite/tests/typecheck/should_fail/T7778.stderr
testsuite/tests/typecheck/should_fail/T7809.stderr
testsuite/tests/typecheck/should_fail/T7869.stderr
testsuite/tests/typecheck/should_fail/T8030.stderr
testsuite/tests/typecheck/should_fail/T8034.stderr
testsuite/tests/typecheck/should_fail/T8142.stderr
testsuite/tests/typecheck/should_fail/T8392a.stderr
testsuite/tests/typecheck/should_fail/T8450.stderr
testsuite/tests/typecheck/should_fail/T8603.stderr
testsuite/tests/typecheck/should_fail/T8806.stderr
testsuite/tests/typecheck/should_fail/T8883.stderr
testsuite/tests/typecheck/should_fail/T9196.stderr
testsuite/tests/typecheck/should_fail/T9201.stderr
testsuite/tests/typecheck/should_fail/mc19.stderr
testsuite/tests/typecheck/should_fail/mc21.stderr
testsuite/tests/typecheck/should_fail/mc22.stderr
testsuite/tests/typecheck/should_fail/tcfail032.stderr
testsuite/tests/typecheck/should_fail/tcfail034.stderr
testsuite/tests/typecheck/should_fail/tcfail057.stderr
testsuite/tests/typecheck/should_fail/tcfail058.stderr
testsuite/tests/typecheck/should_fail/tcfail063.stderr
testsuite/tests/typecheck/should_fail/tcfail065.stderr
testsuite/tests/typecheck/should_fail/tcfail067.stderr
testsuite/tests/typecheck/should_fail/tcfail068.stderr
testsuite/tests/typecheck/should_fail/tcfail072.stderr
testsuite/tests/typecheck/should_fail/tcfail076.stderr
testsuite/tests/typecheck/should_fail/tcfail078.stderr
testsuite/tests/typecheck/should_fail/tcfail080.stderr
testsuite/tests/typecheck/should_fail/tcfail097.stderr
testsuite/tests/typecheck/should_fail/tcfail098.stderr
testsuite/tests/typecheck/should_fail/tcfail101.stderr
testsuite/tests/typecheck/should_fail/tcfail102.stderr
testsuite/tests/typecheck/should_fail/tcfail103.stderr
testsuite/tests/typecheck/should_fail/tcfail107.stderr
testsuite/tests/typecheck/should_fail/tcfail110.stderr
testsuite/tests/typecheck/should_fail/tcfail113.stderr
testsuite/tests/typecheck/should_fail/tcfail116.stderr
testsuite/tests/typecheck/should_fail/tcfail127.stderr
testsuite/tests/typecheck/should_fail/tcfail131.stderr
testsuite/tests/typecheck/should_fail/tcfail134.stderr
testsuite/tests/typecheck/should_fail/tcfail135.stderr
testsuite/tests/typecheck/should_fail/tcfail142.stderr
testsuite/tests/typecheck/should_fail/tcfail153.stderr
testsuite/tests/typecheck/should_fail/tcfail158.stderr
testsuite/tests/typecheck/should_fail/tcfail160.stderr
testsuite/tests/typecheck/should_fail/tcfail161.stderr
testsuite/tests/typecheck/should_fail/tcfail174.stderr
testsuite/tests/typecheck/should_fail/tcfail175.stderr
testsuite/tests/typecheck/should_fail/tcfail179.stderr
testsuite/tests/typecheck/should_fail/tcfail181.stderr
testsuite/tests/typecheck/should_fail/tcfail191.stderr
testsuite/tests/typecheck/should_fail/tcfail193.stderr
testsuite/tests/typecheck/should_fail/tcfail196.stderr
testsuite/tests/typecheck/should_fail/tcfail197.stderr
testsuite/tests/typecheck/should_fail/tcfail201.stderr
testsuite/tests/typecheck/should_fail/tcfail206.stderr
testsuite/tests/typecheck/should_fail/tcfail208.stderr
testsuite/tests/typecheck/should_fail/tcfail209a.stderr
testsuite/tests/typecheck/should_fail/tcfail212.stderr
testsuite/tests/typecheck/should_fail/tcfail215.stderr
testsuite/tests/typecheck/should_run/Defer01.hs
testsuite/tests/typecheck/should_run/T7861.stderr
testsuite/tests/typecheck/should_run/tcrun008.hs
testsuite/tests/wcompat-warnings/WCompatWarningsOn.stderr
utils/haddock