Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • ghc/ghc
  • bgamari/ghc
  • syd/ghc
  • ggreif/ghc
  • watashi/ghc
  • RolandSenn/ghc
  • mpickering/ghc
  • DavidEichmann/ghc
  • carter/ghc
  • harpocrates/ghc
  • ethercrow/ghc
  • mijicd/ghc
  • adamse/ghc
  • alexbiehl/ghc
  • gridaphobe/ghc
  • trofi/ghc
  • supersven/ghc
  • ppk/ghc
  • ulysses4ever/ghc
  • AndreasK/ghc
  • ghuntley/ghc
  • shayne-fletcher-da/ghc
  • fgaz/ghc
  • yav/ghc
  • osa1/ghc
  • mbbx6spp/ghc
  • JulianLeviston/ghc
  • reactormonk/ghc
  • rae/ghc
  • takenobu-hs/ghc
  • michalt/ghc
  • andrewthad/ghc
  • hsyl20/ghc
  • scottgw/ghc
  • sjakobi/ghc
  • angerman/ghc
  • RyanGlScott/ghc
  • hvr/ghc
  • howtonotwin/ghc
  • chessai/ghc
  • m-renaud/ghc
  • brprice/ghc
  • stevehartdata/ghc
  • sighingnow/ghc
  • kgardas/ghc
  • ckoparkar/ghc
  • alp/ghc
  • smaeul/ghc
  • kakkun61/ghc
  • sykloid/ghc
  • newhoggy/ghc
  • toonn/ghc
  • nineonine/ghc
  • Phyx/ghc
  • ezyang/ghc
  • tweag/ghc
  • langston/ghc
  • ndmitchell/ghc
  • rockbmb/ghc
  • artempyanykh/ghc
  • mniip/ghc
  • mynguyenbmc/ghc
  • alexfmpe/ghc
  • crockeea/ghc
  • nh2/ghc
  • vaibhavsagar/ghc
  • phadej/ghc
  • Haskell-mouse/ghc
  • lolotp/ghc
  • spacekitteh/ghc
  • michaelpj/ghc
  • mgsloan/ghc
  • HPCohen/ghc
  • tmobile/ghc
  • radrow/ghc
  • simonmar/ghc
  • _deepfire/ghc
  • Ericson2314/ghc
  • leitao/ghc
  • fumieval/ghc
  • trac-isovector/ghc
  • cblp/ghc
  • xich/ghc
  • ciil/ghc
  • erthalion/ghc
  • xldenis/ghc
  • autotaker/ghc
  • haskell-wasm/ghc
  • kcsongor/ghc
  • agander/ghc
  • Baranowski/ghc
  • trac-dredozubov/ghc
  • 23Skidoo/ghc
  • iustin/ghc
  • ningning/ghc
  • josefs/ghc
  • kabuhr/ghc
  • gallais/ghc
  • dten/ghc
  • expipiplus1/ghc
  • Pluralia/ghc
  • rohanjr/ghc
  • intricate/ghc
  • kirelagin/ghc
  • Javran/ghc
  • DanielG/ghc
  • trac-mizunashi_mana/ghc
  • pparkkin/ghc
  • bollu/ghc
  • ntc2/ghc
  • jaspervdj/ghc
  • JoshMeredith/ghc
  • wz1000/ghc
  • zkourouma/ghc
  • code5hot/ghc
  • jdprice/ghc
  • tdammers/ghc
  • J-mie6/ghc
  • trac-lantti/ghc
  • ch1bo/ghc
  • cgohla/ghc
  • lucamolteni/ghc
  • acairncross/ghc
  • amerocu/ghc
  • chreekat/ghc
  • txsmith/ghc
  • trupill/ghc
  • typetetris/ghc
  • sergv/ghc
  • fryguybob/ghc
  • erikd/ghc
  • trac-roland/ghc
  • setupminimal/ghc
  • Friede80/ghc
  • SkyWriter/ghc
  • xplorld/ghc
  • abrar/ghc
  • obsidiansystems/ghc
  • Icelandjack/ghc
  • adinapoli/ghc
  • trac-matthewbauer/ghc
  • heatsink/ghc
  • dwijnand/ghc
  • Cmdv/ghc
  • alinab/ghc
  • pepeiborra/ghc
  • fommil/ghc
  • luochen1990/ghc
  • rlupton20/ghc
  • applePrincess/ghc
  • lehins/ghc
  • ronmrdechai/ghc
  • leeadam/ghc
  • harendra/ghc
  • mightymosquito1991/ghc
  • trac-gershomb/ghc
  • lucajulian/ghc
  • Rizary/ghc
  • VictorCMiraldo/ghc
  • jamesbrock/ghc
  • andrewdmeier/ghc
  • luke/ghc
  • pranaysashank/ghc
  • cocreature/ghc
  • hithroc/ghc
  • obreitwi/ghc
  • slrtbtfs/ghc
  • kaol/ghc
  • yairchu/ghc
  • Mathemagician98/ghc
  • trac-taylorfausak/ghc
  • leungbk/ghc
  • MichaWiedenmann/ghc
  • chris-martin/ghc
  • TDecki/ghc
  • adithyaov/ghc
  • trac-gelisam/ghc
  • Lysxia/ghc
  • complyue/ghc
  • bwignall/ghc
  • sternmull/ghc
  • sonika/ghc
  • leif/ghc
  • broadwaylamb/ghc
  • myszon/ghc
  • danbroooks/ghc
  • Mechachleopteryx/ghc
  • zardyh/ghc
  • trac-vdukhovni/ghc
  • OmarKhaledAbdo/ghc
  • arrowd/ghc
  • Bodigrim/ghc
  • matheus23/ghc
  • cardenaso11/ghc
  • trac-Athas/ghc
  • mb720/ghc
  • DylanZA/ghc
  • liff/ghc
  • typedrat/ghc
  • trac-claude/ghc
  • jbm/ghc
  • Gertjan423/ghc
  • PHO/ghc
  • JKTKops/ghc
  • kockahonza/ghc
  • msakai/ghc
  • Sir4ur0n/ghc
  • barambani/ghc
  • vishnu.c/ghc
  • dcoutts/ghc
  • trac-runeks/ghc
  • trac-MaxGabriel/ghc
  • lexi.lambda/ghc
  • strake/ghc
  • spavikevik/ghc
  • JakobBruenker/ghc
  • rmanne/ghc
  • gdziadkiewicz/ghc
  • ani/ghc
  • iliastsi/ghc
  • smunix/ghc
  • judah/ghc
  • blackgnezdo/ghc
  • emilypi/ghc
  • trac-bpfoley/ghc
  • muesli4/ghc
  • trac-gkaracha/ghc
  • Kleidukos/ghc
  • nek0/ghc
  • TristanCacqueray/ghc
  • dwulive/ghc
  • mbakke/ghc
  • arybczak/ghc
  • Yang123321/ghc
  • maksbotan/ghc
  • QuietMisdreavus/ghc
  • trac-olshanskydr/ghc
  • emekoi/ghc
  • samuela/ghc
  • josephcsible/ghc
  • dramforever/ghc
  • lpsmith/ghc
  • DenisFrezzato/ghc
  • michivi/ghc
  • jneira/ghc
  • jeffhappily/ghc
  • Ivan-Yudin/ghc
  • nakaji-dayo/ghc
  • gdevanla/ghc
  • galen/ghc
  • fendor/ghc
  • yaitskov/ghc
  • rcythr/ghc
  • awpr/ghc
  • jeremyschlatter/ghc
  • Aver1y/ghc
  • mitchellvitez/ghc
  • merijn/ghc
  • tomjaguarpaw1/ghc
  • trac-NoidedSuper/ghc
  • erewok/ghc
  • trac-junji.hashimoto/ghc
  • adamwespiser/ghc
  • bjaress/ghc
  • jhrcek/ghc
  • leonschoorl/ghc
  • lukasz-golebiewski/ghc
  • sheaf/ghc
  • last-g/ghc
  • carassius1014/ghc
  • eschwartz/ghc
  • dwincort/ghc
  • felixwiemuth/ghc
  • TimWSpence/ghc
  • marcusmonteirodesouza/ghc
  • WJWH/ghc
  • vtols/ghc
  • theobat/ghc
  • BinderDavid/ghc
  • ckoparkar0/ghc
  • alexander-kjeldaas/ghc
  • dme2/ghc
  • philderbeast/ghc
  • aaronallen8455/ghc
  • rayshih/ghc
  • benkard/ghc
  • mpardalos/ghc
  • saidelman/ghc
  • leiftw/ghc
  • ca333/ghc
  • bwroga/ghc
  • nmichael44/ghc
  • trac-crobbins/ghc
  • felixonmars/ghc
  • adityagupta1089/ghc
  • hgsipiere/ghc
  • treeowl/ghc
  • alexpeits/ghc
  • CraigFe/ghc
  • dnlkrgr/ghc
  • kerckhove_ts/ghc
  • cptwunderlich/ghc
  • eiais/ghc
  • hahohihu/ghc
  • sanchayan/ghc
  • lemmih/ghc
  • sehqlr/ghc
  • trac-dbeacham/ghc
  • luite/ghc
  • trac-f-a/ghc
  • vados/ghc
  • luntain/ghc
  • fatho/ghc
  • alexbiehl-gc/ghc
  • dcbdan/ghc
  • tvh/ghc
  • liam-ly/ghc
  • timbobbarnes/ghc
  • GovanifY/ghc
  • shanth2600/ghc
  • gliboc/ghc
  • duog/ghc
  • moxonsghost/ghc
  • zander/ghc
  • masaeedu/ghc
  • georgefst/ghc
  • guibou/ghc
  • nicuveo/ghc
  • mdebruijne/ghc
  • stjordanis/ghc
  • emiflake/ghc
  • wygulmage/ghc
  • frasertweedale/ghc
  • coot/ghc
  • aratamizuki/ghc
  • tsandstr/ghc
  • mrBliss/ghc
  • Anton-Latukha/ghc
  • tadfisher/ghc
  • vapourismo/ghc
  • Sorokin-Anton/ghc
  • basile-henry/ghc
  • trac-mightybyte/ghc
  • AbsoluteNikola/ghc
  • cobrien99/ghc
  • songzh/ghc
  • blamario/ghc
  • aj4ayushjain/ghc
  • trac-utdemir/ghc
  • tangcl/ghc
  • hdgarrood/ghc
  • maerwald/ghc
  • arjun/ghc
  • ratherforky/ghc
  • haskieLambda/ghc
  • EmilGedda/ghc
  • Bogicevic/ghc
  • eddiejessup/ghc
  • kozross/ghc
  • AlistairB/ghc
  • 3Rafal/ghc
  • christiaanb/ghc
  • trac-bit/ghc
  • matsumonkie/ghc
  • trac-parsonsmatt/ghc
  • chisui/ghc
  • jaro/ghc
  • trac-kmiyazato/ghc
  • davidsd/ghc
  • Tritlo/ghc
  • I-B-3/ghc
  • lykahb/ghc
  • AriFordsham/ghc
  • turion1/ghc
  • berberman/ghc
  • christiantakle/ghc
  • zyklotomic/ghc
  • trac-ocramz/ghc
  • CSEdd/ghc
  • doyougnu/ghc
  • mmhat/ghc
  • why-not-try-calmer/ghc
  • plutotulp/ghc
  • kjekac/ghc
  • Manvi07/ghc
  • teo/ghc
  • cactus/ghc
  • CarrieMY/ghc
  • abel/ghc
  • yihming/ghc
  • tsakki/ghc
  • jessicah/ghc
  • oliverbunting/ghc
  • meld/ghc
  • friedbrice/ghc
  • Joald/ghc
  • abarbu/ghc
  • DigitalBrains1/ghc
  • sterni/ghc
  • alexDarcy/ghc
  • hexchain/ghc
  • minimario/ghc
  • zliu41/ghc
  • tommd/ghc
  • jazcarate/ghc
  • peterbecich/ghc
  • alirezaghey/ghc
  • solomon/ghc
  • mikael.urankar/ghc
  • davjam/ghc
  • int-index/ghc
  • MorrowM/ghc
  • nrnrnr/ghc
  • Sonfamm/ghc-test-only
  • afzt1/ghc
  • nguyenhaibinh-tpc/ghc
  • trac-lierdakil/ghc
  • MichaWiedenmann1/ghc
  • jmorag/ghc
  • Ziharrk/ghc
  • trac-MitchellSalad/ghc
  • juampe/ghc
  • jwaldmann/ghc
  • snowleopard/ghc
  • juhp/ghc
  • normalcoder/ghc
  • ksqsf/ghc
  • trac-jberryman/ghc
  • roberth/ghc
  • 1ntEgr8/ghc
  • epworth/ghc
  • MrAdityaAlok/ghc
  • JunmingZhao42/ghc
  • jappeace/ghc
  • trac-Gabriel439/ghc
  • alt-romes/ghc
  • HugoPeters1024/ghc
  • 10ne1/ghc-fork
  • agentultra/ghc
  • Garfield1002/ghc
  • ChickenProp/ghc
  • clyring/ghc
  • MaxHearnden/ghc
  • jumper149/ghc
  • vem/ghc
  • ketzacoatl/ghc
  • Rosuavio/ghc
  • jackohughes/ghc
  • p4l1ly/ghc
  • konsumlamm/ghc
  • shlevy/ghc
  • torsten.schmits/ghc
  • andremarianiello/ghc
  • amesgen/ghc
  • googleson78/ghc
  • InfiniteVerma/ghc
  • uhbif19/ghc
  • yiyunliu/ghc
  • raehik/ghc
  • mrkun/ghc
  • telser/ghc
  • 1Jajen1/ghc
  • slotThe/ghc
  • WinstonHartnett/ghc
  • mpilgrem/ghc
  • dreamsmasher/ghc
  • schuelermine/ghc
  • trac-Viwor/ghc
  • undergroundquizscene/ghc
  • evertedsphere/ghc
  • coltenwebb/ghc
  • oberblastmeister/ghc
  • agrue/ghc
  • lf-/ghc
  • zacwood9/ghc
  • steshaw/ghc
  • high-cloud/ghc
  • SkamDart/ghc
  • PiDelport/ghc
  • maoif/ghc
  • RossPaterson/ghc
  • CharlesTaylor7/ghc
  • ribosomerocker/ghc
  • trac-ramirez7/ghc
  • daig/ghc
  • NicolasT/ghc
  • FinleyMcIlwaine/ghc
  • lawtonnichols/ghc
  • jmtd/ghc
  • ozkutuk/ghc
  • wildsebastian/ghc
  • nikshalark/ghc
  • lrzlin/ghc
  • tobias/ghc
  • fw/ghc
  • hawkinsw/ghc
  • type-dance/ghc
  • rui314/ghc
  • ocharles/ghc
  • wavewave/ghc
  • TheKK/ghc
  • nomeata/ghc
  • trac-csabahruska/ghc
  • jonathanjameswatson/ghc
  • L-as/ghc
  • Axman6/ghc
  • barracuda156/ghc
  • trac-jship/ghc
  • jake-87/ghc
  • meooow/ghc
  • rebeccat/ghc
  • hamana55/ghc
  • Enigmage/ghc
  • kokobd/ghc
  • agevelt/ghc
  • gshen42/ghc
  • chrismwendt/ghc
  • MangoIV/ghc
  • teto/ghc
  • Sookr1/ghc
  • trac-thomasjm/ghc
  • barci2/ghc-dev
  • trac-m4dc4p/ghc
  • dixonary/ghc
  • breakerzirconia/ghc
  • alexsio27444/ghc
  • glocq/ghc
  • sourabhxyz/ghc
  • ryantrinkle/ghc
  • Jade/ghc
  • scedfaliako/ghc
  • martijnbastiaan/ghc
  • trac-george.colpitts/ghc
  • ammarbinfaisal/ghc
  • mimi.vx/ghc
  • lortabac/ghc
  • trac-zyla/ghc
  • benbellick/ghc
  • aadaa-fgtaa/ghc
  • jvanbruegge/ghc
  • archbung/ghc
  • gilmi/ghc
  • mfonism/ghc
  • alex-mckenna/ghc
  • Ei30metry/ghc
  • DiegoDiverio/ghc
  • jorgecunhamendes/ghc
  • liesnikov/ghc
  • akrmn/ghc
  • trac-simplifierticks/ghc
  • jacco/ghc
  • rhendric/ghc
  • damhiya/ghc
  • ryndubei/ghc
  • DaveBarton/ghc
  • trac-Profpatsch/ghc
  • GZGavinZhao/ghc
  • ncfavier/ghc
  • jameshaydon/ghc
  • ajccosta/ghc
  • dschrempf/ghc
  • cydparser/ghc
  • LinuxUserGD/ghc
  • elodielander/ghc
  • facundominguez/ghc
  • psilospore/ghc
  • lachrimae/ghc
  • dylan-thinnes/ghc-type-errors-plugin
  • hamishmack/ghc
  • Leary/ghc
  • lzszt/ghc
  • lyokha/ghc
  • trac-glaubitz/ghc
  • Rewbert/ghc
  • andreabedini/ghc
  • Jasagredo/ghc
  • sol/ghc
  • OlegAlexander/ghc
  • trac-sthibaul/ghc
  • avdv/ghc
  • Wendaolee/ghc
  • ur4t/ghc
  • daylily/ghc
  • boltzmannrain/ghc
  • mmzk1526/ghc
  • trac-fizzixnerd/ghc
  • soulomoon/ghc
  • rwmjones/ghc
  • j14i/ghc
  • tracsis/ghc
  • gesh/ghc
  • flip101/ghc
  • eldritch-cookie/ghc
  • LemonjamesD/ghc
  • pgujjula/ghc
  • skeuchel/ghc
  • noteed/ghc
  • Torrekie/ghc
  • jlwoodwa/ghc
  • ayanamists/ghc
  • husong998/ghc
  • trac-edmundnoble/ghc
  • josephf/ghc
  • contrun/ghc
  • baulig/ghc
  • edsko/ghc
  • mzschr/ghc-issue-24732
  • ulidtko/ghc
  • Arsen/ghc
  • trac-sjoerd_visscher/ghc
  • crumbtoo/ghc
  • L0neGamer/ghc
  • DrewFenwick/ghc
  • benz0li/ghc
  • MaciejWas/ghc
  • jordanrule/ghc
  • trac-qqwy/ghc
  • LiamGoodacre/ghc
  • isomorpheme/ghc
  • trac-danidiaz/ghc
  • Kariim/ghc
  • MTaimoorZaeem/ghc
  • hololeap/ghc
  • ticat-fp/ghc
  • meritamen/ghc
  • criskell/ghc
  • trac-kraai/ghc
  • aergus/ghc
  • jdral/ghc
  • SamB/ghc
  • Tristian/ghc
  • ywgrit/ghc
  • KatsuPatrick/ghc
  • OsePedro/ghc
  • mpscholten/ghc
  • fp/ghc
  • zaquest/ghc
  • fangyi-zhou/ghc
  • augyg/ghc
  • rkirkman/ghc
  • gulin.serge/ghc-windows-aarch64-bootstrap
  • iris/ghc
  • kwxm/ghc
  • maralorn/ghc
  • rafl/ghc
645 results
Show changes
Commits on Source (2)
  • Simon Peyton Jones's avatar
    Make simplifyInfer generalise only over simple class constraints · 0ac2073a
    Simon Peyton Jones authored
    So we never infer
       f :: Eq (Tree a) => blah
    when there isn't an instance for Eq (Tree a).
    
    This fixes Trac #6022.
    
    It does represent a change in behaviour: certain (bizarre) programs
    will be rejected that were previously accepted. Specifically, if you
    have
    
       module A where
       f x = ...somethign needing (C T)...
    
       moudule B where
       import A
       instance C T
       test = f True
    
    Here the (C T) instance is provided "later".  But this is wierd; it
    would be better to give a type signature for f
       f :: C T => Bool -> Bool
    and then you'd be fine.
    0ac2073a
  • Simon Peyton Jones's avatar
    Simplify simplifyInfer quite a lot · ff500354
    Simon Peyton Jones authored
    Work in progress, on branch
    ff500354
...@@ -1212,7 +1212,7 @@ check_pred_ty' dflags ctxt (ClassPred cls tys) ...@@ -1212,7 +1212,7 @@ check_pred_ty' dflags ctxt (ClassPred cls tys)
-- Check the form of the argument types -- Check the form of the argument types
; mapM_ checkValidMonoType tys ; mapM_ checkValidMonoType tys
; checkTc (check_class_pred_tys dflags ctxt tys) ; checkTc (check_class_pred_tys dflags ctxt cls tys)
(predTyVarErr (mkClassPred cls tys) $$ how_to_allow) (predTyVarErr (mkClassPred cls tys) $$ how_to_allow)
} }
where where
...@@ -1285,16 +1285,15 @@ check_pred_ty' dflags ctxt (IrredPred pred) ...@@ -1285,16 +1285,15 @@ check_pred_ty' dflags ctxt (IrredPred pred)
(predIrredBadCtxtErr pred) (predIrredBadCtxtErr pred)
------------------------- -------------------------
check_class_pred_tys :: DynFlags -> UserTypeCtxt -> [KindOrType] -> Bool check_class_pred_tys :: DynFlags -> UserTypeCtxt -> Class -> [KindOrType] -> Bool
check_class_pred_tys dflags ctxt kts check_class_pred_tys dflags ctxt cls kts
= case ctxt of = case ctxt of
SpecInstCtxt -> True -- {-# SPECIALISE instance Eq (T Int) #-} is fine SpecInstCtxt -> True -- {-# SPECIALISE instance Eq (T Int) #-} is fine
InstDeclCtxt -> flexible_contexts || undecidable_ok || all tcIsTyVarTy tys InstDeclCtxt -> flexible_contexts || undecidable_ok || isTyVarClassApp cls kts
-- Further checks on head and theta in -- Further checks on head and theta in
-- checkInstTermination -- checkInstTermination
_ -> flexible_contexts || all tyvar_head tys _ -> flexible_contexts || isTyVarHeadClassApp cls kts
where where
(_, tys) = span isKind kts -- see Note [Kind polymorphic type classes]
flexible_contexts = xopt Opt_FlexibleContexts dflags flexible_contexts = xopt Opt_FlexibleContexts dflags
undecidable_ok = xopt Opt_UndecidableInstances dflags undecidable_ok = xopt Opt_UndecidableInstances dflags
...@@ -1309,7 +1308,6 @@ class C f where ...@@ -1309,7 +1308,6 @@ class C f where
MultiParam: MultiParam:
~~~~~~~~~~~ ~~~~~~~~~~~
instance C Maybe where instance C Maybe where
empty = Nothing empty = Nothing
...@@ -1318,7 +1316,6 @@ type class. ...@@ -1318,7 +1316,6 @@ type class.
Flexible: Flexible:
~~~~~~~~~ ~~~~~~~~~
data D a = D data D a = D
-- D :: forall k. k -> * -- D :: forall k. k -> *
...@@ -1329,15 +1326,6 @@ The dictionary gets type [C * (D *)]. IA0_TODO it should be ...@@ -1329,15 +1326,6 @@ The dictionary gets type [C * (D *)]. IA0_TODO it should be
generalized actually. generalized actually.
-} -}
-------------------------
tyvar_head :: Type -> Bool
tyvar_head ty -- Haskell 98 allows predicates of form
| tcIsTyVarTy ty = True -- C (a ty1 .. tyn)
| otherwise -- where a is a type variable
= case tcSplitAppTy_maybe ty of
Just (ty, _) -> tyvar_head ty
Nothing -> False
\end{code} \end{code}
Check for ambiguity Check for ambiguity
...@@ -1504,10 +1492,14 @@ checkValidInstHead :: UserTypeCtxt -> Class -> [Type] -> TcM () ...@@ -1504,10 +1492,14 @@ checkValidInstHead :: UserTypeCtxt -> Class -> [Type] -> TcM ()
checkValidInstHead ctxt clas cls_args checkValidInstHead ctxt clas cls_args
= do { dflags <- getDynFlags = do { dflags <- getDynFlags
-- Check language restrictions; ; let ty_args = classTyArgs clas cls_args
-- but not for SPECIALISE isntance pragmas -- class C f where { empty :: f a }
; let ty_args = dropWhile isKind cls_args -- instance C Maybe where ...
; unless spec_inst_prag $ -- So C :: forall k. k -> Constraint
-- The dictionary gets type [C * Maybe] which is ok even if it's
-- not a MultiParam type class.
; unless spec_inst_prag $ -- Not for SPECIALISE instance pragmas
do { checkTc (xopt Opt_TypeSynonymInstances dflags || do { checkTc (xopt Opt_TypeSynonymInstances dflags ||
all tcInstHeadTyNotSynonym ty_args) all tcInstHeadTyNotSynonym ty_args)
(instTypeErr pp_pred head_type_synonym_msg) (instTypeErr pp_pred head_type_synonym_msg)
......
\begin{code} \begin{code}
{-# OPTIONS -fno-warn-tabs #-} {-# OPTIONS -fno-warn-tabs -Wwarn #-}
-- The above warning supression flag is a temporary kludge. -- The above warning supression flag is a temporary kludge.
-- While working on this module you are encouraged to remove it and -- While working on this module you are encouraged to remove it and
-- detab the module (please do the detabbing in a separate patch). See -- detab the module (please do the detabbing in a separate patch). See
...@@ -20,9 +20,10 @@ import TcMType ...@@ -20,9 +20,10 @@ import TcMType
import TcType import TcType
import TcSMonad import TcSMonad
import TcInteract import TcInteract
import InstEnv ( lookupInstEnv )
import Inst import Inst
import Unify ( niFixTvSubst, niSubstTvSet ) import Unify ( niFixTvSubst, niSubstTvSet )
import Type ( classifyPredType, PredTree(..) ) import Type ( classifyPredType, getClassPredTys, getClassPredTys_maybe, PredTree(..) )
import Var import Var
import VarSet import VarSet
import VarEnv import VarEnv
...@@ -37,11 +38,11 @@ import PrelNames ...@@ -37,11 +38,11 @@ import PrelNames
import Class ( classKey ) import Class ( classKey )
import BasicTypes ( RuleName ) import BasicTypes ( RuleName )
import Control.Monad ( when ) import Control.Monad ( when )
import Data.List ( partition )
import Outputable import Outputable
import FastString import FastString
import TrieMap () -- DV: for now import TrieMap () -- DV: for now
import DynFlags import DynFlags
\end{code} \end{code}
...@@ -235,7 +236,7 @@ simplifyInfer :: Bool ...@@ -235,7 +236,7 @@ simplifyInfer :: Bool
-- so the results type is not as general as -- so the results type is not as general as
-- it could be -- it could be
TcEvBinds) -- ... binding these evidence variables TcEvBinds) -- ... binding these evidence variables
simplifyInfer _top_lvl apply_mr name_taus wanteds simplifyInfer top_lvl apply_mr name_taus wanteds
| isEmptyWC wanteds | isEmptyWC wanteds
= do { gbl_tvs <- tcGetGlobalTyVars -- Already zonked = do { gbl_tvs <- tcGetGlobalTyVars -- Already zonked
; zonked_taus <- zonkTcTypes (map snd name_taus) ; zonked_taus <- zonkTcTypes (map snd name_taus)
...@@ -256,11 +257,72 @@ simplifyInfer _top_lvl apply_mr name_taus wanteds ...@@ -256,11 +257,72 @@ simplifyInfer _top_lvl apply_mr name_taus wanteds
, ptext (sLit "taus =") <+> ppr (map snd name_taus) , ptext (sLit "taus =") <+> ppr (map snd name_taus)
, ptext (sLit "tau_tvs (zonked) =") <+> ppr zonked_tau_tvs , ptext (sLit "tau_tvs (zonked) =") <+> ppr zonked_tau_tvs
, ptext (sLit "gbl_tvs =") <+> ppr gbl_tvs , ptext (sLit "gbl_tvs =") <+> ppr gbl_tvs
, ptext (sLit "closed =") <+> ppr _top_lvl , ptext (sLit "closed =") <+> ppr top_lvl
, ptext (sLit "apply_mr =") <+> ppr apply_mr , ptext (sLit "apply_mr =") <+> ppr apply_mr
, ptext (sLit "wanted =") <+> ppr zonked_wanteds , ptext (sLit "wanted =") <+> ppr zonked_wanteds
] ]
-- Step 2
-- Now simplify the possibly-bound constraints
; let ctxt = SimplInfer (ppr (map fst name_taus))
; (simpl_results, _binds)
<- runTcS ctxt NoUntouchables emptyInert emptyWorkList $
simplifyWithApprox zonked_wanteds
-- Step 3
-- Split again simplified_perhaps_bound, because some unifications
-- may have happened, and emit the free constraints.
; gbl_tvs <- tcGetGlobalTyVars
; zonked_tau_tvs <- zonkTyVarsAndFV zonked_tau_tvs
; zonked_results <- zonkWC simpl_results
; (quantifiable_preds, rest_wc) <- quantifiablePreds apply_mr zonked_results
; let full_gbl_tvs = gbl_tvs `unionVarSet` tyVarsOfWC rest_wc
init_tvs = zonked_tau_tvs `minusVarSet` full_gbl_tvs
qtvs = growPreds1 full_gbl_tvs quantifiable_preds init_tvs
minimal_flat_preds = filter (quantifyMe qtvs) quantifiable_preds
-- Monomorphism restriction bites if the natural polymorphsim
-- (tau_tvs - gbl_tvs) is not the same as the actual polymorphism
mr_bites = not ((zonked_tau_tvs `minusVarSet` gbl_tvs) `subVarSet` qtvs)
; let skol_info = InferSkol [ (name, mkSigmaTy [] minimal_flat_preds ty)
| (name, ty) <- name_taus ]
-- Don't add the quantified variables here, because
-- they are also bound in ic_skols and we want them to be
-- tidied uniformly
; qtvs_to_return <- zonkQuantifiedTyVars (varSetElems qtvs)
; minimal_bound_ev_vars <- mapM TcMType.newEvVar minimal_flat_preds
; ev_binds_var <- newTcEvBinds
; lcl_env <- getLclTypeEnv
; gloc <- getCtLoc skol_info
; let implic = Implic { ic_untch = NoUntouchables
, ic_env = lcl_env
, ic_skols = qtvs_to_return
, ic_given = minimal_bound_ev_vars
, ic_wanted = wanteds
, ic_insol = False
, ic_binds = ev_binds_var
, ic_loc = gloc }
; emitImplication implic
; traceTc "} simplifyInfer/produced residual implication for quantification" $
vcat [ ptext (sLit "implic =") <+> ppr implic
-- ic_skols, ic_given give rest of result
, ptext (sLit "qtvs =") <+> ppr qtvs
, ptext (sLit "qtvs_to_return =") <+> ppr qtvs_to_return
, ptext (sLit "init_tvs =") <+> ppr init_tvs
, ptext (sLit "full_gbl_tvs =") <+> ppr full_gbl_tvs
, ptext (sLit "rest_wc =") <+> ppr rest_wc
, ptext (sLit "spb =") <+> ppr quantifiable_preds
, ptext (sLit "bound =") <+> ppr minimal_flat_preds ]
; return ( qtvs_to_return, minimal_bound_ev_vars
, mr_bites, TcEvBinds ev_binds_var) }
------------
{-
-- Step 1 -- Step 1
-- Make a guess at the quantified type variables -- Make a guess at the quantified type variables
-- Then split the constraints on the baisis of those tyvars -- Then split the constraints on the baisis of those tyvars
...@@ -324,22 +386,22 @@ simplifyInfer _top_lvl apply_mr name_taus wanteds ...@@ -324,22 +386,22 @@ simplifyInfer _top_lvl apply_mr name_taus wanteds
else do else do
-- Step 4, zonk quantified variables -- Step 4, zonk quantified variables
{ let minimal_flat_preds = mkMinimalBySCs $ { qtvs_to_return <- zonkQuantifiedTyVars (varSetElems qtvs)
map ctPred $ bagToList bound
skol_info = InferSkol [ (name, mkSigmaTy [] minimal_flat_preds ty) -- Step 5
-- Minimize `bound' and emit an implication
; minimal_flat_preds <- predsToQuantify bound
}
; let skol_info = InferSkol [ (name, mkSigmaTy [] minimal_flat_preds ty)
| (name, ty) <- name_taus ] | (name, ty) <- name_taus ]
-- Don't add the quantified variables here, because -- Don't add the quantified variables here, because
-- they are also bound in ic_skols and we want them to be -- they are also bound in ic_skols and we want them to be
-- tidied uniformly -- tidied uniformly
; qtvs_to_return <- zonkQuantifiedTyVars (varSetElems qtvs)
-- Step 5
-- Minimize `bound' and emit an implication
; minimal_bound_ev_vars <- mapM TcMType.newEvVar minimal_flat_preds ; minimal_bound_ev_vars <- mapM TcMType.newEvVar minimal_flat_preds
; ev_binds_var <- newTcEvBinds ; ev_binds_var <- newTcEvBinds
; mapBagM_ (\(EvBind evar etrm) -> addTcEvBind ev_binds_var evar etrm) ; mapBagM_ (\(EvBind evar etrm) -> addTcEvBind ev_binds_var evar etrm)
tc_binds tc_binds
; lcl_env <- getLclTypeEnv ; lcl_env <- getLclTypeEnv
; gloc <- getCtLoc skol_info ; gloc <- getCtLoc skol_info
; let implic = Implic { ic_untch = NoUntouchables ; let implic = Implic { ic_untch = NoUntouchables
...@@ -362,12 +424,34 @@ simplifyInfer _top_lvl apply_mr name_taus wanteds ...@@ -362,12 +424,34 @@ simplifyInfer _top_lvl apply_mr name_taus wanteds
; return ( qtvs_to_return, minimal_bound_ev_vars ; return ( qtvs_to_return, minimal_bound_ev_vars
, mr_bites, TcEvBinds ev_binds_var) } } , mr_bites, TcEvBinds ev_binds_var) } }
\end{code} -}
quantifiablePreds :: Bool -> WantedConstraints -> TcM ([PredType], WantedConstraints)
-- From a bunch of (non-insoluble) flat constraints, pick the ones to generalise
-- an inferred type over. In particular:
-- * Omit superclasses: (Eq a, Ord a) ---> Ord a
-- * Reject non-tyvar clases: (Eq a, Show (Tree b)) --> Eq a
quantifiablePreds apply_mr wc
| apply_mr
= return ([], wc)
| otherwise
= do { inst_envs <- tcGetInstEnvs
; let (quant_flats, non_quant_flats) = partitionBag quantifiable (wc_flat wc)
quantifiable ct
| Just (cls, tys) <- getClassPredTys_maybe (ctPred ct)
= isTyVarClassApp cls tys
|| case lookupInstEnv inst_envs cls tys of
([], [], _) -> False
(_, _, _) -> True
| otherwise
= True
; return (map ctPred (bagToList quant_flats), wc { wc_flat = non_quant_flats }) }
\end{code}
Note [Minimize by Superclasses] Note [Minimize by Superclasses]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
When we quantify over a constraint, in simplifyInfer we need to When we quantify over a constraint, in simplifyInfer we need to
quantify over a constraint that is minimal in some sense: For quantify over a constraint that is minimal in some sense: For
instance, if the final wanted constraint is (Eq alpha, Ord alpha), instance, if the final wanted constraint is (Eq alpha, Ord alpha),
...@@ -466,15 +550,20 @@ growPreds gbl_tvs get_pred items tvs ...@@ -466,15 +550,20 @@ growPreds gbl_tvs get_pred items tvs
extend item tvs = tvs `unionVarSet` extend item tvs = tvs `unionVarSet`
(growPredTyVars (get_pred item) tvs `minusVarSet` gbl_tvs) (growPredTyVars (get_pred item) tvs `minusVarSet` gbl_tvs)
growPreds1 :: TyVarSet -> [PredType] -> TyVarSet -> TyVarSet
growPreds1 gbl_tvs items tvs
= foldr extend tvs items
where
extend item tvs = tvs `unionVarSet`
(growPredTyVars item tvs `minusVarSet` gbl_tvs)
-------------------- --------------------
quantifyMe :: TyVarSet -- Quantifying over these quantifyMe :: TyVarSet -- Quantifying over these
-> Ct -> PredType
-> Bool -- True <=> quantify over this wanted -> Bool -- True <=> quantify over this wanted
quantifyMe qtvs ct quantifyMe qtvs pred
| isIPPred pred = True -- Note [Inheriting implicit parameters] | isIPPred pred = True -- Note [Inheriting implicit parameters]
| otherwise = tyVarsOfType pred `intersectsVarSet` qtvs | otherwise = tyVarsOfType pred `intersectsVarSet` qtvs
where
pred = ctPred ct
\end{code} \end{code}
Note [Avoid unecessary constraint simplification] Note [Avoid unecessary constraint simplification]
......
...@@ -65,8 +65,9 @@ module TcType ( ...@@ -65,8 +65,9 @@ module TcType (
isIntegerTy, isBoolTy, isUnitTy, isCharTy, isIntegerTy, isBoolTy, isUnitTy, isCharTy,
isTauTy, isTauTyCon, tcIsTyVarTy, tcIsForAllTy, isTauTy, isTauTyCon, tcIsTyVarTy, tcIsForAllTy,
isSynFamilyTyConApp, isSynFamilyTyConApp,
isPredTy, isTyVarClassPred, isPredTy,
shallowPredTypePredTree, isTyVarClassPred, isTyVarClassApp, isTyVarHeadClassPred, isTyVarHeadClassApp,
classTyArgs, shallowPredTypePredTree,
--------------------------------- ---------------------------------
-- Misc type manipulators -- Misc type manipulators
...@@ -1102,8 +1103,33 @@ shallowPredTypePredTree ev_ty ...@@ -1102,8 +1103,33 @@ shallowPredTypePredTree ev_ty
isTyVarClassPred :: PredType -> Bool isTyVarClassPred :: PredType -> Bool
isTyVarClassPred ty = case getClassPredTys_maybe ty of isTyVarClassPred ty = case getClassPredTys_maybe ty of
Just (_, tys) -> all isTyVarTy tys Just (cls, tks) -> isTyVarClassApp cls tks
_ -> False _ -> False
isTyVarClassApp :: Class -> [KindOrType] -> Bool
isTyVarClassApp cls tks
= all tcIsTyVarTy (classTyArgs cls tks)
isTyVarHeadClassPred :: PredType -> Bool
isTyVarHeadClassPred ty = case getClassPredTys_maybe ty of
Just (cls, tks) -> isTyVarHeadClassApp cls tks
_ -> False
isTyVarHeadClassApp :: Class -> [KindOrType] -> Bool
isTyVarHeadClassApp cls tks
= all hasTyVarHead (classTyArgs cls tks)
classTyArgs :: Class -> [KindOrType] -> [Type]
-- Drop the initial kind arguments of a class
classTyArgs cls kts = drop (count isKindVar (classTyVars cls)) kts
hasTyVarHead :: Type -> Bool
hasTyVarHead ty -- Haskell 98 allows predicates of form
| tcIsTyVarTy ty = True -- C (a ty1 .. tyn)
| otherwise -- where a is a type variable
= case tcSplitAppTy_maybe ty of
Just (ty, _) -> hasTyVarHead ty
Nothing -> False
evVarPred_maybe :: EvVar -> Maybe PredType evVarPred_maybe :: EvVar -> Maybe PredType
evVarPred_maybe v = if isPredTy ty then Just ty else Nothing evVarPred_maybe v = if isPredTy ty then Just ty else Nothing
......