-
diff --git a/compiler/basicTypes/BasicTypes.lhs b/compiler/basicTypes/BasicTypes.lhs
index c6226ca..f822ea8 100644
|
a
|
b
|
|
| 40 | 40 | compareFixity, |
| 41 | 41 | |
| 42 | 42 | IPName(..), ipNameName, mapIPName, |
| | 43 | HoleName(..), holeNameName, mapHoleName, |
| 43 | 44 | |
| 44 | 45 | RecFlag(..), isRec, isNonRec, boolToRecFlag, |
| 45 | 46 | |
| … |
… |
|
| 189 | 190 | |
| 190 | 191 | instance Outputable name => Outputable (IPName name) where |
| 191 | 192 | ppr (IPName n) = char '?' <> ppr n -- Ordinary implicit parameters |
| | 193 | |
| | 194 | |
| | 195 | newtype HoleName name = HoleName name -- _x |
| | 196 | deriving( Eq, Data, Typeable ) |
| | 197 | |
| | 198 | instance Ord a => Ord (HoleName a) where |
| | 199 | compare (HoleName a) (HoleName b) = compare a b |
| | 200 | |
| | 201 | instance Functor HoleName where |
| | 202 | fmap = mapHoleName |
| | 203 | |
| | 204 | holeNameName :: HoleName name -> name |
| | 205 | holeNameName (HoleName n) = n |
| | 206 | |
| | 207 | mapHoleName :: (a->b) -> HoleName a -> HoleName b |
| | 208 | mapHoleName f (HoleName n) = HoleName (f n) |
| | 209 | |
| | 210 | instance Outputable name => Outputable (HoleName name) where |
| | 211 | ppr (HoleName n) = text "_?" <> ppr n |
| | 212 | |
| 192 | 213 | \end{code} |
| 193 | 214 | |
| 194 | 215 | %************************************************************************ |
-
diff --git a/compiler/basicTypes/Unique.lhs b/compiler/basicTypes/Unique.lhs
index f99a50c..b81a5ad 100644
|
a
|
b
|
|
| 181 | 181 | |
| 182 | 182 | instance Uniquable n => Uniquable (IPName n) where |
| 183 | 183 | getUnique (IPName n) = getUnique n |
| | 184 | |
| | 185 | instance Uniquable n => Uniquable (HoleName n) where |
| | 186 | getUnique (HoleName n) = getUnique n |
| 184 | 187 | \end{code} |
| 185 | 188 | |
| 186 | 189 | |
-
diff --git a/compiler/deSugar/Coverage.lhs b/compiler/deSugar/Coverage.lhs
index 2d0ad23..9f4ee73 100644
|
a
|
b
|
|
| 540 | 540 | (addTickHsExpr e) -- explicitly no tick on inside |
| 541 | 541 | |
| 542 | 542 | addTickHsExpr e@(HsType _) = return e |
| | 543 | addTickHsExpr e@(HsHole _) = return e |
| 543 | 544 | |
| 544 | 545 | -- Others dhould never happen in expression content. |
| 545 | 546 | addTickHsExpr e = pprPanic "addTickHsExpr" (ppr e) |
-
diff --git a/compiler/deSugar/DsExpr.lhs b/compiler/deSugar/DsExpr.lhs
index d31c774..becb480 100644
|
a
|
b
|
|
| 231 | 231 | |
| 232 | 232 | dsExpr (HsApp fun arg) |
| 233 | 233 | = mkCoreAppDs <$> dsLExpr fun <*> dsLExpr arg |
| | 234 | |
| | 235 | dsExpr (HsHole nm) |
| | 236 | = return (Var $ holeNameName nm) |
| 234 | 237 | \end{code} |
| 235 | 238 | |
| 236 | 239 | Note [Desugaring vars] |
-
diff --git a/compiler/hsSyn/HsExpr.lhs b/compiler/hsSyn/HsExpr.lhs
index 08d1281..90b9f59 100644
|
a
|
b
|
|
| 290 | 290 | |
| 291 | 291 | | HsWrap HsWrapper -- TRANSLATION |
| 292 | 292 | (HsExpr id) |
| | 293 | | HsHole (HoleName id) |
| 293 | 294 | deriving (Data, Typeable) |
| 294 | 295 | |
| 295 | 296 | -- HsTupArg is used for tuple sections |
| … |
… |
|
| 545 | 546 | ppr_expr (HsArrForm op _ args) |
| 546 | 547 | = hang (ptext (sLit "(|") <> ppr_lexpr op) |
| 547 | 548 | 4 (sep (map (pprCmdArg.unLoc) args) <> ptext (sLit "|)")) |
| | 549 | ppr_expr (HsHole name) |
| | 550 | = ppr name |
| 548 | 551 | |
| 549 | 552 | pprCmdArg :: OutputableBndr id => HsCmdTop id -> SDoc |
| 550 | 553 | pprCmdArg (HsCmdTop cmd@(L _ (HsArrForm _ Nothing [])) _ _ _) |
-
diff --git a/compiler/iface/IfaceEnv.lhs b/compiler/iface/IfaceEnv.lhs
index 4c66a98..de43a89 100644
|
a
|
b
|
|
| 12 | 12 | newGlobalBinder, newImplicitBinder, |
| 13 | 13 | lookupIfaceTop, |
| 14 | 14 | lookupOrig, lookupOrigNameCache, extendNameCache, |
| 15 | | newIPName, newIfaceName, newIfaceNames, |
| | 15 | newIPName, newHoleName, newIfaceName, newIfaceNames, |
| 16 | 16 | extendIfaceIdEnv, extendIfaceTyVarEnv, |
| 17 | 17 | tcIfaceLclId, tcIfaceTyVar, lookupIfaceTyVar, |
| 18 | 18 | |
| … |
… |
|
| 42 | 42 | import SrcLoc |
| 43 | 43 | import BasicTypes |
| 44 | 44 | |
| | 45 | import TysPrim |
| | 46 | import TysWiredIn |
| | 47 | import Coercion |
| | 48 | |
| 45 | 49 | import Outputable |
| 46 | 50 | import Exception ( evaluate ) |
| 47 | 51 | |
| … |
… |
|
| 181 | 185 | newIPName ip = updNameCache $ flip allocateIPName ip |
| 182 | 186 | \end{code} |
| 183 | 187 | |
| | 188 | \begin{code} |
| | 189 | newHoleName :: FastString -> TcRnIf m n (HoleName Name) |
| | 190 | newHoleName name = updNameCache $ \name_cache -> case Map.lookup name $ nsHoles name_cache of |
| | 191 | Just name_hole -> (name_cache, name_hole) |
| | 192 | Nothing -> (new_ns, name_hole) |
| | 193 | where |
| | 194 | (us_here, us') = splitUniqSupply (nsUniqs name_cache) |
| | 195 | new_holecache = Map.insert name name_hole $ nsHoles name_cache |
| | 196 | tycon_u:datacon_u:dc_wrk_u:co_ax_u:_ = uniqsFromSupply us_here |
| | 197 | name_hole = mkHoleName name tycon_u datacon_u dc_wrk_u co_ax_u |
| | 198 | new_ns = name_cache { nsUniqs = us', nsHoles = new_holecache } |
| | 199 | |
| | 200 | \end{code} |
| | 201 | |
| 184 | 202 | %************************************************************************ |
| 185 | 203 | %* * |
| 186 | 204 | Name cache access |
| … |
… |
|
| 249 | 267 | initNameCache us names |
| 250 | 268 | = NameCache { nsUniqs = us, |
| 251 | 269 | nsNames = initOrigNames names, |
| 252 | | nsIPs = Map.empty } |
| | 270 | nsIPs = Map.empty, |
| | 271 | nsHoles = Map.empty } |
| 253 | 272 | |
| 254 | 273 | initOrigNames :: [Name] -> OrigNameCache |
| 255 | 274 | initOrigNames names = foldl extendOrigNameCache emptyModuleEnv names |
-
diff --git a/compiler/main/HscTypes.lhs b/compiler/main/HscTypes.lhs
index e55d78e..4974429 100644
|
a
|
b
|
|
| 1756 | 1756 | -- ^ Supply of uniques |
| 1757 | 1757 | nsNames :: OrigNameCache, |
| 1758 | 1758 | -- ^ Ensures that one original name gets one unique |
| 1759 | | nsIPs :: OrigIParamCache |
| | 1759 | nsIPs :: OrigIParamCache, |
| 1760 | 1760 | -- ^ Ensures that one implicit parameter name gets one unique |
| | 1761 | nsHoles :: OrigHoleCache |
| 1761 | 1762 | } |
| 1762 | 1763 | |
| 1763 | 1764 | -- | Per-module cache of original 'OccName's given 'Name's |
| … |
… |
|
| 1765 | 1766 | |
| 1766 | 1767 | -- | Module-local cache of implicit parameter 'OccName's given 'Name's |
| 1767 | 1768 | type OrigIParamCache = Map FastString (IPName Name) |
| | 1769 | |
| | 1770 | type OrigHoleCache = Map FastString (HoleName Name) |
| 1768 | 1771 | \end{code} |
| 1769 | 1772 | |
| 1770 | 1773 | |
-
diff --git a/compiler/main/InteractiveEval.hs b/compiler/main/InteractiveEval.hs
index 8cc94a3..fde4843 100644
|
a
|
b
|
|
| 927 | 927 | exprType :: GhcMonad m => String -> m Type |
| 928 | 928 | exprType expr = withSession $ \hsc_env -> do |
| 929 | 929 | ty <- liftIO $ hscTcExpr hsc_env expr |
| 930 | | return $ tidyType emptyTidyEnv ty |
| | 930 | return {-$ tidyType emptyTidyEnv-} ty |
| 931 | 931 | |
| 932 | 932 | -- ----------------------------------------------------------------------------- |
| 933 | 933 | -- Getting the kind of a type |
-
diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x
index 378a25c..4e6b29d 100644
|
a
|
b
|
|
| 344 | 344 | { token ITcubxparen } |
| 345 | 345 | } |
| 346 | 346 | |
| | 347 | <0> { |
| | 348 | \_\? @varid { skip_two_varid IThole } |
| | 349 | } |
| | 350 | |
| 347 | 351 | <0,option_prags> { |
| 348 | 352 | \( { special IToparen } |
| 349 | 353 | \) { special ITcparen } |
| … |
… |
|
| 544 | 548 | | ITprefixqconsym (FastString,FastString) |
| 545 | 549 | |
| 546 | 550 | | ITdupipvarid FastString -- GHC extension: implicit param: ?x |
| | 551 | | IThole FastString |
| 547 | 552 | |
| 548 | 553 | | ITchar Char |
| 549 | 554 | | ITstring FastString |
| … |
… |
|
| 729 | 734 | skip_one_varid f span buf len |
| 730 | 735 | = return (L span $! f (lexemeToFastString (stepOn buf) (len-1))) |
| 731 | 736 | |
| | 737 | skip_two_varid :: (FastString -> Token) -> Action |
| | 738 | skip_two_varid f span buf len |
| | 739 | = return (L span $! f (lexemeToFastString (stepOn $ stepOn buf) (len-2))) |
| | 740 | |
| 732 | 741 | strtoken :: (String -> Token) -> Action |
| 733 | 742 | strtoken f span buf len = |
| 734 | 743 | return (L span $! (f $! lexemeToString buf len)) |
-
diff --git a/compiler/parser/Parser.y.pp b/compiler/parser/Parser.y.pp
index fc6a950..81ca98a 100644
|
a
|
b
|
|
| 322 | 322 | PREFIXQCONSYM { L _ (ITprefixqconsym _) } |
| 323 | 323 | |
| 324 | 324 | IPDUPVARID { L _ (ITdupipvarid _) } -- GHC extension |
| | 325 | HOLEVARID { L _ (IThole _) } |
| 325 | 326 | |
| 326 | 327 | CHAR { L _ (ITchar _) } |
| 327 | 328 | STRING { L _ (ITstring _) } |
| … |
… |
|
| 1451 | 1452 | |
| 1452 | 1453 | aexp2 :: { LHsExpr RdrName } |
| 1453 | 1454 | : ipvar { L1 (HsIPVar $! unLoc $1) } |
| | 1455 | | hole { L1 (HsHole $! unLoc $1) } |
| 1454 | 1456 | | qcname { L1 (HsVar $! unLoc $1) } |
| 1455 | 1457 | | literal { L1 (HsLit $! unLoc $1) } |
| 1456 | 1458 | -- This will enable overloaded strings permanently. Normally the renamer turns HsString |
| … |
… |
|
| 1765 | 1767 | ipvar :: { Located (IPName RdrName) } |
| 1766 | 1768 | : IPDUPVARID { L1 (IPName (mkUnqual varName (getIPDUPVARID $1))) } |
| 1767 | 1769 | |
| | 1770 | hole :: { Located (HoleName RdrName) } |
| | 1771 | : HOLEVARID { L1 (HoleName (mkUnqual varName $ getHOLEVARID $1)) } |
| | 1772 | |
| 1768 | 1773 | ----------------------------------------------------------------------------- |
| 1769 | 1774 | -- Warnings and deprecations |
| 1770 | 1775 | |
| … |
… |
|
| 2082 | 2087 | getPREFIXQVARSYM (L _ (ITprefixqvarsym x)) = x |
| 2083 | 2088 | getPREFIXQCONSYM (L _ (ITprefixqconsym x)) = x |
| 2084 | 2089 | getIPDUPVARID (L _ (ITdupipvarid x)) = x |
| | 2090 | getHOLEVARID (L _ (IThole x)) = x |
| 2085 | 2091 | getCHAR (L _ (ITchar x)) = x |
| 2086 | 2092 | getSTRING (L _ (ITstring x)) = x |
| 2087 | 2093 | getINTEGER (L _ (ITinteger x)) = x |
-
diff --git a/compiler/prelude/TysWiredIn.lhs b/compiler/prelude/TysWiredIn.lhs
index 4b7f043..5718aaf 100644
|
a
|
b
|
|
| 73 | 73 | eqTyCon_RDR, eqTyCon, eqTyConName, eqBoxDataCon, |
| 74 | 74 | |
| 75 | 75 | -- * Implicit parameter predicates |
| 76 | | mkIPName |
| | 76 | mkIPName, |
| | 77 | |
| | 78 | mkHoleName |
| 77 | 79 | ) where |
| 78 | 80 | |
| 79 | 81 | #include "HsVersions.h" |
| … |
… |
|
| 95 | 97 | import TypeRep |
| 96 | 98 | import RdrName |
| 97 | 99 | import Name |
| 98 | | import BasicTypes ( TupleSort(..), tupleSortBoxity, IPName(..), |
| | 100 | import BasicTypes ( TupleSort(..), tupleSortBoxity, IPName(..), HoleName(..), |
| 99 | 101 | Arity, RecFlag(..), Boxity(..), HsBang(..) ) |
| 100 | 102 | import ForeignCall |
| 101 | 103 | import Unique ( incrUnique, mkTupleTyConUnique, |
| … |
… |
|
| 428 | 430 | co_ax_name = mkPrimTyConName ip co_ax_u tycon |
| 429 | 431 | \end{code} |
| 430 | 432 | |
| | 433 | \begin{code} |
| | 434 | mkHoleName :: FastString |
| | 435 | -> Unique -> Unique -> Unique -> Unique |
| | 436 | -> HoleName Name |
| | 437 | mkHoleName ip tycon_u datacon_u dc_wrk_u co_ax_u = name_hole |
| | 438 | where |
| | 439 | name_hole = HoleName tycon_name |
| | 440 | |
| | 441 | tycon_name = mkPrimTyConName ip tycon_u tycon |
| | 442 | tycon = mkAlgTyCon tycon_name |
| | 443 | (liftedTypeKind `mkArrowKind` constraintKind) |
| | 444 | [alphaTyVar] |
| | 445 | Nothing |
| | 446 | [] -- No stupid theta |
| | 447 | (NewTyCon { data_con = datacon, |
| | 448 | nt_rhs = mkTyVarTy alphaTyVar, |
| | 449 | nt_etad_rhs = ([alphaTyVar], mkTyVarTy alphaTyVar), |
| | 450 | nt_co = mkNewTypeCo co_ax_name tycon [alphaTyVar] (mkTyVarTy alphaTyVar) }) |
| | 451 | (HoleTyCon name_hole) |
| | 452 | NonRecursive |
| | 453 | False |
| | 454 | |
| | 455 | datacon_name = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "IPBox") datacon_u datacon |
| | 456 | datacon = pcDataCon' datacon_name dc_wrk_u [alphaTyVar] [mkTyVarTy alphaTyVar] tycon |
| | 457 | |
| | 458 | co_ax_name = mkPrimTyConName ip co_ax_u tycon |
| | 459 | \end{code} |
| | 460 | |
| 431 | 461 | %************************************************************************ |
| 432 | 462 | %* * |
| 433 | 463 | \subsection[TysWiredIn-boxed-prim]{The ``boxed primitive'' types (@Char@, @Int@, etc)} |
-
diff --git a/compiler/rename/RnExpr.lhs b/compiler/rename/RnExpr.lhs
index b884d4a..27d154b 100644
|
a
|
b
|
|
| 34 | 34 | import TcRnMonad |
| 35 | 35 | import TcEnv ( thRnBrack ) |
| 36 | 36 | import RnEnv |
| 37 | | import RnTypes |
| | 37 | import RnTypes |
| 38 | 38 | import RnPat |
| 39 | 39 | import DynFlags |
| 40 | 40 | import BasicTypes ( FixityDirection(..) ) |
| … |
… |
|
| 292 | 292 | rnExpr (PArrSeq _ seq) |
| 293 | 293 | = rnArithSeq seq `thenM` \ (new_seq, fvs) -> |
| 294 | 294 | return (PArrSeq noPostTcExpr new_seq, fvs) |
| | 295 | |
| | 296 | rnExpr (HsHole name) |
| | 297 | = do { name' <- rnHoleName name |
| | 298 | ; return (HsHole name', emptyFVs) |
| | 299 | } |
| 295 | 300 | \end{code} |
| 296 | 301 | |
| 297 | 302 | These three are pattern syntax appearing in expressions. |
-
diff --git a/compiler/rename/RnTypes.lhs b/compiler/rename/RnTypes.lhs
index 2c5a5a5..c954f8b 100644
|
a
|
b
|
|
| 12 | 12 | -- for details |
| 13 | 13 | |
| 14 | 14 | module RnTypes ( |
| 15 | | -- Type related stuff |
| 16 | | rnHsType, rnLHsType, rnLHsTypes, rnContext, |
| | 15 | -- Type related stuff |
| | 16 | rnHsType, rnLHsType, rnLHsTypes, rnContext, |
| 17 | 17 | rnHsKind, rnLHsKind, rnLHsMaybeKind, |
| 18 | | rnHsSigType, rnLHsInstType, rnConDeclFields, |
| 19 | | rnIPName, |
| | 18 | rnHsSigType, rnLHsInstType, rnConDeclFields, |
| | 19 | rnIPName, rnHoleName, |
| 20 | 20 | |
| 21 | 21 | -- Precence related stuff |
| 22 | 22 | mkOpAppRn, mkNegAppRn, mkOpFormRn, mkConOpPatRn, |
| … |
… |
|
| 40 | 40 | import RnHsDoc ( rnLHsDoc, rnMbLHsDoc ) |
| 41 | 41 | import RnEnv |
| 42 | 42 | import TcRnMonad |
| 43 | | import IfaceEnv ( newIPName ) |
| | 43 | import IfaceEnv ( newIPName, newHoleName ) |
| 44 | 44 | import RdrName |
| 45 | 45 | import PrelNames |
| 46 | 46 | import TysPrim ( funTyConName ) |
| … |
… |
|
| 50 | 50 | |
| 51 | 51 | import Util ( filterOut ) |
| 52 | 52 | import BasicTypes ( IPName(..), ipNameName, compareFixity, funTyFixity, negateFixity, |
| 53 | | Fixity(..), FixityDirection(..) ) |
| | 53 | Fixity(..), FixityDirection(..), HoleName(..), holeNameName ) |
| 54 | 54 | import Outputable |
| 55 | 55 | import FastString |
| 56 | 56 | import Control.Monad ( unless ) |
| … |
… |
|
| 480 | 480 | rnIPName n = newIPName (occNameFS (rdrNameOcc (ipNameName n))) |
| 481 | 481 | \end{code} |
| 482 | 482 | |
| | 483 | \begin{code} |
| | 484 | rnHoleName :: HoleName RdrName -> RnM (HoleName Name) |
| | 485 | rnHoleName n = newHoleName (occNameFS (rdrNameOcc (holeNameName n))) |
| | 486 | \end{code} |
| | 487 | |
| 483 | 488 | |
| 484 | 489 | %************************************************************************ |
| 485 | 490 | %* * |
-
diff --git a/compiler/typecheck/Inst.lhs b/compiler/typecheck/Inst.lhs
index ffaeac8..4f5a000 100644
|
a
|
b
|
|
| 518 | 518 | has_eq' (ClassPred cls _tys) = any has_eq (classSCTheta cls) |
| 519 | 519 | has_eq' (TuplePred ts) = any has_eq ts |
| 520 | 520 | has_eq' (IrredPred _) = True -- Might have equalities in it after reduction? |
| | 521 | has_eq' (HolePred {}) = False |
| 521 | 522 | |
| 522 | 523 | ---------------- Getting free tyvars ------------------------- |
| 523 | 524 | |
| … |
… |
|
| 528 | 529 | tyVarsOfCt (CIPCan { cc_ip_ty = ty }) = tyVarsOfType ty |
| 529 | 530 | tyVarsOfCt (CIrredEvCan { cc_ty = ty }) = tyVarsOfType ty |
| 530 | 531 | tyVarsOfCt (CNonCanonical { cc_flavor = fl }) = tyVarsOfType (ctFlavPred fl) |
| | 532 | tyVarsOfCt (CHoleCan { cc_hole_ty = ty }) = tyVarsOfType ty |
| 531 | 533 | |
| 532 | 534 | tyVarsOfCDict :: Ct -> TcTyVarSet |
| 533 | 535 | tyVarsOfCDict (CDictCan { cc_tyargs = tys }) = tyVarsOfTypes tys |
-
diff --git a/compiler/typecheck/TcCanonical.lhs b/compiler/typecheck/TcCanonical.lhs
index b24f76c..eb0a752 100644
|
a
|
b
|
|
| 13 | 13 | |
| 14 | 14 | #include "HsVersions.h" |
| 15 | 15 | |
| 16 | | import BasicTypes ( IPName ) |
| | 16 | import BasicTypes ( IPName, HoleName ) |
| 17 | 17 | import TcErrors |
| 18 | 18 | import TcRnTypes |
| 19 | 19 | import TcType |
| … |
… |
|
| 206 | 206 | , cc_depth = d |
| 207 | 207 | , cc_ty = xi }) |
| 208 | 208 | = canIrred d fl xi |
| 209 | | |
| | 209 | canonicalize (CHoleCan { cc_id = ev, cc_depth = d |
| | 210 | , cc_flavor = fl |
| | 211 | , cc_hole_nm = nm |
| | 212 | , cc_hole_ty = xi }) |
| | 213 | = canHole d fl nm xi |
| 210 | 214 | |
| 211 | 215 | canEvVar :: SubGoalDepth |
| 212 | 216 | -> CtFlavor |
| … |
… |
|
| 220 | 224 | IPPred nm ty -> canIP d fl nm ty |
| 221 | 225 | IrredPred ev_ty -> canIrred d fl ev_ty |
| 222 | 226 | TuplePred tys -> canTuple d fl tys |
| | 227 | HolePred name ty -> canHole d fl name ty |
| 223 | 228 | \end{code} |
| 224 | 229 | |
| 225 | 230 | |
| … |
… |
|
| 280 | 285 | class constraints for the same class MAY be equal, so they need to be |
| 281 | 286 | flattened in the first place to facilitate comparing them.) |
| 282 | 287 | |
| | 288 | \begin{code} |
| | 289 | canHole :: SubGoalDepth -- Depth |
| | 290 | -> CtFlavor |
| | 291 | -> HoleName Name -> Type -> TcS StopOrContinue |
| | 292 | canHole d fl nm ty |
| | 293 | = do { (xi,co) <- flatten d fl (mkHolePred nm ty) |
| | 294 | ; mb <- rewriteCtFlavor fl xi co |
| | 295 | ; case mb of |
| | 296 | Just new_fl -> let HolePred _ xi_in = classifyPredType xi |
| | 297 | in continueWith $ CHoleCan { cc_flavor = new_fl |
| | 298 | , cc_hole_nm = nm, cc_hole_ty = xi_in |
| | 299 | , cc_depth = d } |
| | 300 | Nothing -> return Stop } |
| | 301 | \end{code} |
| | 302 | |
| 283 | 303 | %************************************************************************ |
| 284 | 304 | %* * |
| 285 | 305 | %* Class Canonicalization |
-
diff --git a/compiler/typecheck/TcErrors.lhs b/compiler/typecheck/TcErrors.lhs
index 0fcd0d4..9bcb455 100644
|
a
|
b
|
|
| 71 | 71 | wanted <- zonkWC wanted |
| 72 | 72 | |
| 73 | 73 | ; env0 <- tcInitTidyEnv |
| 74 | | ; defer <- if runtimeCoercionErrors |
| 75 | | then do { ev <- newTcEvBinds |
| 76 | | ; return (Just ev) } |
| 77 | | else return Nothing |
| | 74 | ; defer <- newTcEvBinds -- if runtimeCoercionErrors |
| | 75 | -- then do { ev <- newTcEvBinds |
| | 76 | -- ; return (Just ev) } |
| | 77 | -- else return Nothing |
| 78 | 78 | |
| 79 | 79 | ; errs_so_far <- ifErrsM (return True) (return False) |
| 80 | 80 | ; let tidy_env = tidyFreeTyVars env0 free_tvs |
| … |
… |
|
| 83 | 83 | , cec_insol = errs_so_far |
| 84 | 84 | , cec_extra = empty |
| 85 | 85 | , cec_tidy = tidy_env |
| 86 | | , cec_defer = defer } |
| | 86 | , cec_defer = Just defer } |
| 87 | 87 | |
| 88 | 88 | ; traceTc "reportUnsolved" (ppr free_tvs $$ ppr wanted) |
| 89 | 89 | |
| 90 | 90 | ; reportWanteds err_ctxt wanted |
| 91 | 91 | |
| 92 | | ; case defer of |
| 93 | | Nothing -> return emptyBag |
| 94 | | Just ev -> getTcEvBinds ev } |
| | 92 | ; getTcEvBinds defer } |
| 95 | 93 | |
| 96 | 94 | -------------------------------------------- |
| 97 | 95 | -- Internal functions |
| … |
… |
|
| 144 | 142 | |
| 145 | 143 | reportTidyWanteds :: ReportErrCtxt -> Bag Ct -> Bag Ct -> Bag Implication -> TcM () |
| 146 | 144 | reportTidyWanteds ctxt insols flats implics |
| 147 | | | Just ev_binds_var <- cec_defer ctxt |
| 148 | | = do { -- Defer errors to runtime |
| 149 | | -- See Note [Deferring coercion errors to runtime] in TcSimplify |
| 150 | | mapBagM_ (deferToRuntime ev_binds_var ctxt mkFlatErr) |
| 151 | | (flats `unionBags` insols) |
| 152 | | ; mapBagM_ (reportImplic ctxt) implics } |
| 153 | | |
| 154 | | | otherwise |
| 155 | | = do { reportInsolsAndFlats ctxt insols flats |
| 156 | | ; mapBagM_ (reportImplic ctxt) implics } |
| | 145 | = do { |
| | 146 | ; let Just ev_binds_var = cec_defer ctxt |
| | 147 | ; runtimeCoercionErrors <- doptM Opt_DeferTypeErrors |
| | 148 | ; if runtimeCoercionErrors then |
| | 149 | do { -- Defer errors to runtime |
| | 150 | -- See Note [Deferring coercion errors to runtime] in TcSimplify |
| | 151 | mapBagM_ (deferToRuntime ev_binds_var ctxt mkFlatErr) |
| | 152 | (flats `unionBags` insols) |
| | 153 | ; mapBagM_ (reportImplic ctxt) implics |
| | 154 | } |
| | 155 | else |
| | 156 | do { |
| | 157 | ; traceTc "reportTidyWanteds" (ppr (filterBag (isHole) (flats `unionBags` insols))) |
| | 158 | ; mapBagM_ (deferToRuntime ev_binds_var ctxt mkFlatErr) |
| | 159 | (filterBag isHole (flats `unionBags` insols)) |
| | 160 | ; reportInsolsAndFlats ctxt (filterBag (not.isHole) insols) (filterBag (not.isHole) flats) |
| | 161 | ; mapBagM_ (reportImplic ctxt) implics |
| | 162 | } |
| | 163 | } |
| | 164 | where isHole ct = case classifyPredType (ctPred ct) of |
| | 165 | HolePred {} -> True |
| | 166 | _ -> False |
| 157 | 167 | |
| 158 | 168 | |
| 159 | 169 | deferToRuntime :: EvBindsVar -> ReportErrCtxt -> (ReportErrCtxt -> Ct -> TcM ErrMsg) |
| … |
… |
|
| 261 | 271 | IPPred {} -> mkIPErr ctxt [ct] |
| 262 | 272 | IrredPred {} -> mkIrredErr ctxt [ct] |
| 263 | 273 | EqPred {} -> mkEqErr1 ctxt ct |
| | 274 | HolePred {} -> mkHoleErr ctxt [ct] |
| 264 | 275 | TuplePred {} -> panic "mkFlat" |
| 265 | 276 | |
| 266 | 277 | reportAmbigErrs :: ReportErrCtxt -> Reporter |
| … |
… |
|
| 278 | 289 | reportFlatErrs ctxt cts |
| 279 | 290 | = tryReporters |
| 280 | 291 | [ ("Equalities", is_equality, groupErrs (mkEqErr ctxt)) ] |
| 281 | | (\cts -> do { let (dicts, ips, irreds) = go cts [] [] [] |
| | 292 | (\cts -> do { let (dicts, ips, irreds, holes) = go cts [] [] [] [] |
| 282 | 293 | ; groupErrs (mkIPErr ctxt) ips |
| 283 | 294 | ; groupErrs (mkIrredErr ctxt) irreds |
| | 295 | ; groupErrs (mkHoleErr ctxt) holes |
| 284 | 296 | ; groupErrs (mkDictErr ctxt) dicts }) |
| 285 | 297 | cts |
| 286 | 298 | where |
| 287 | 299 | is_equality _ (EqPred {}) = True |
| 288 | 300 | is_equality _ _ = False |
| 289 | 301 | |
| 290 | | go [] dicts ips irreds |
| 291 | | = (dicts, ips, irreds) |
| 292 | | go (ct:cts) dicts ips irreds |
| | 302 | go [] dicts ips irreds holes |
| | 303 | = (dicts, ips, irreds, holes) |
| | 304 | go (ct:cts) dicts ips irreds holes |
| 293 | 305 | = case classifyPredType (ctPred ct) of |
| 294 | | ClassPred {} -> go cts (ct:dicts) ips irreds |
| 295 | | IPPred {} -> go cts dicts (ct:ips) irreds |
| 296 | | IrredPred {} -> go cts dicts ips (ct:irreds) |
| | 306 | ClassPred {} -> go cts (ct:dicts) ips irreds holes |
| | 307 | IPPred {} -> go cts dicts (ct:ips) irreds holes |
| | 308 | IrredPred {} -> go cts dicts ips (ct:irreds) holes |
| | 309 | HolePred {} -> go cts dicts ips irreds (ct:holes) |
| 297 | 310 | _ -> panic "mkFlat" |
| 298 | 311 | -- TuplePreds should have been expanded away by the constraint |
| 299 | 312 | -- simplifier, so they shouldn't show up at this point |
| … |
… |
|
| 384 | 397 | msg = couldNotDeduce givens (map ctPred cts, orig) |
| 385 | 398 | \end{code} |
| 386 | 399 | |
| | 400 | \begin{code} |
| | 401 | mkHoleErr :: ReportErrCtxt -> [Ct] -> TcM ErrMsg |
| | 402 | mkHoleErr ctxt cts |
| | 403 | = mkErrorReport ctxt msg |
| | 404 | where |
| | 405 | (ct1:_) = cts |
| | 406 | orig = ctLocOrigin (ctWantedLoc ct1) |
| | 407 | preds = map ctPred cts |
| | 408 | msg = foundAHole preds |
| | 409 | |
| | 410 | foundAHole :: ThetaType -> SDoc |
| | 411 | foundAHole [TyConApp nm [ty]] = (text "Found hole _?") <> ppr nm <+> (text "with type") <+> ppr ty |
| | 412 | \end{code} |
| 387 | 413 | |
| 388 | 414 | %************************************************************************ |
| 389 | 415 | %* * |
-
diff --git a/compiler/typecheck/TcExpr.lhs b/compiler/typecheck/TcExpr.lhs
index 488e654..9cc7a0b 100644
|
a
|
b
|
|
| 63 | 63 | import Outputable |
| 64 | 64 | import FastString |
| 65 | 65 | import Control.Monad |
| | 66 | |
| | 67 | import TypeRep |
| | 68 | import qualified Data.Map as Map |
| 66 | 69 | \end{code} |
| 67 | 70 | |
| 68 | 71 | %************************************************************************ |
| … |
… |
|
| 90 | 93 | = do { traceTc "tcPolyExprNC" (ppr res_ty) |
| 91 | 94 | ; (gen_fn, expr') <- tcGen GenSigCtxt res_ty $ \ _ rho -> |
| 92 | 95 | tcMonoExprNC expr rho |
| | 96 | ; sk <- deeplySkolemise res_ty |
| 93 | 97 | ; return (mkLHsWrap gen_fn expr') } |
| 94 | 98 | |
| 95 | 99 | --------------- |
| … |
… |
|
| 214 | 218 | -- so it's not enabled yet. |
| 215 | 219 | -- Can't eliminate it altogether from the parser, because the |
| 216 | 220 | -- same parser parses *patterns*. |
| | 221 | tcExpr (HsHole name) res_ty |
| | 222 | = do { traceTc "tcExpr.HsHole" (ppr $ res_ty) |
| | 223 | ; let origin = OccurrenceOf $ holeNameName name |
| | 224 | ; ty <- newFlexiTyVarTy liftedTypeKind |
| | 225 | |
| | 226 | -- Emit the constraint |
| | 227 | ; var <- emitWanted origin (mkHolePred name ty) |
| | 228 | ; traceTc "tcExpr.HsHole: Creating new ty for hole" (ppr ty) |
| | 229 | |
| | 230 | ; tcWrapResult (HsHole $ HoleName var) ty res_ty } |
| 217 | 231 | \end{code} |
| 218 | 232 | |
| 219 | 233 | |
-
diff --git a/compiler/typecheck/TcHsSyn.lhs b/compiler/typecheck/TcHsSyn.lhs
index 75dedd0..2c82808 100644
|
a
|
b
|
|
| 701 | 701 | zonkExpr env1 expr `thenM` \ new_expr -> |
| 702 | 702 | return (HsWrap new_co_fn new_expr) |
| 703 | 703 | |
| | 704 | zonkExpr env h@(HsHole nm) |
| | 705 | = do { |
| | 706 | traceTc "zonkExpr.HsHole" (ppr h); |
| | 707 | return (HsHole nm) |
| | 708 | } |
| | 709 | |
| 704 | 710 | zonkExpr _ expr = pprPanic "zonkExpr" (ppr expr) |
| 705 | 711 | |
| 706 | 712 | zonkCmdTop :: ZonkEnv -> LHsCmdTop TcId -> TcM (LHsCmdTop Id) |
| … |
… |
|
| 1305 | 1311 | -- ty is actually a kind, zonk to AnyK |
| 1306 | 1312 | then anyKind |
| 1307 | 1313 | else anyTypeOfKind (defaultKind (tyVarKind tv)) |
| | 1314 | ; traceTc "zonkTypeZapping" (ppr tv) |
| 1308 | 1315 | ; writeMetaTyVar tv ty |
| 1309 | 1316 | ; return ty } |
| 1310 | 1317 | |
-
diff --git a/compiler/typecheck/TcInteract.lhs b/compiler/typecheck/TcInteract.lhs
index 01dcda8..8818fd5 100644
|
a
|
b
|
|
| 59 | 59 | import UniqFM |
| 60 | 60 | import FastString ( sLit ) |
| 61 | 61 | import DynFlags |
| | 62 | |
| | 63 | import Control.Monad |
| | 64 | import Type |
| 62 | 65 | \end{code} |
| 63 | 66 | ********************************************************************** |
| 64 | 67 | * * |
| … |
… |
|
| 375 | 378 | , inert_dicts = dictmap |
| 376 | 379 | , inert_ips = ipmap |
| 377 | 380 | , inert_funeqs = funeqmap |
| 378 | | , inert_irreds = irreds } |
| | 381 | , inert_irreds = irreds |
| | 382 | , inert_holes = holemap } |
| 379 | 383 | , inert_frozen = frozen }) |
| 380 | 384 | = ((kicked_out,eqmap), remaining) |
| 381 | 385 | where |
| 382 | 386 | rest_out = fro_out `andCts` dicts_out |
| 383 | | `andCts` ips_out `andCts` irs_out |
| | 387 | `andCts` ips_out `andCts` irs_out `andCts` holes_out |
| 384 | 388 | kicked_out = WorkList { wl_eqs = [] |
| 385 | 389 | , wl_funeqs = bagToList feqs_out |
| 386 | 390 | , wl_rest = bagToList rest_out } |
| … |
… |
|
| 391 | 395 | , inert_dicts = dicts_in |
| 392 | 396 | , inert_ips = ips_in |
| 393 | 397 | , inert_funeqs = feqs_in |
| 394 | | , inert_irreds = irs_in } |
| | 398 | , inert_irreds = irs_in |
| | 399 | , inert_holes = holes_in } |
| 395 | 400 | , inert_frozen = fro_in } |
| 396 | 401 | -- NB: Notice that don't rewrite |
| 397 | 402 | -- inert_solved, inert_flat_cache and inert_solved_funeqs |
| … |
… |
|
| 401 | 406 | tv = cc_tyvar ct |
| 402 | 407 | |
| 403 | 408 | (ips_out, ips_in) = partitionCCanMap rewritable ipmap |
| | 409 | (holes_out, holes_in) = partitionCCanMap rewritable holemap |
| 404 | 410 | |
| 405 | 411 | (feqs_out, feqs_in) = partCtFamHeadMap rewritable funeqmap |
| 406 | 412 | (dicts_out, dicts_in) = partitionCCanMap rewritable dictmap |
| … |
… |
|
| 657 | 663 | | IRInertConsumed { ir_fire :: String } |
| 658 | 664 | | IRKeepGoing { ir_fire :: String } |
| 659 | 665 | |
| | 666 | |
| | 667 | instance Outputable InteractResult where |
| | 668 | ppr (IRWorkItemConsumed str) = ptext (sLit "IRWorkItemConsumed ") <+> text str |
| | 669 | ppr (IRInertConsumed str) = ptext (sLit "IRInertConsumed ") <+> text str |
| | 670 | ppr (IRKeepGoing str) = ptext (sLit "IRKeepGoing ") <+> text str |
| | 671 | |
| 660 | 672 | irWorkItemConsumed :: String -> TcS InteractResult |
| 661 | 673 | irWorkItemConsumed str = return (IRWorkItemConsumed str) |
| 662 | 674 | |
| … |
… |
|
| 684 | 696 | ; foldlBagM interact_next (ContinueWith wi) rels } } |
| 685 | 697 | |
| 686 | 698 | where interact_next Stop atomic_inert |
| 687 | | = updInertSetTcS atomic_inert >> return Stop |
| | 699 | = trace "interact_next Stop" $ updInertSetTcS atomic_inert >> return Stop |
| 688 | 700 | interact_next (ContinueWith wi) atomic_inert |
| 689 | 701 | = do { ir <- doInteractWithInert atomic_inert wi |
| 690 | 702 | ; let mk_msg rule keep_doc |
| … |
… |
|
| 836 | 848 | | Wanted wl _ <- ifl = wl |
| 837 | 849 | | Derived wl _ <- ifl = wl |
| 838 | 850 | | otherwise = panic "Solve IP: no WantedLoc!" |
| | 851 | |
| | 852 | doInteractWithInert (CHoleCan id1 fl1 nm1 ty1 d1) workitem@(CHoleCan id2 fl2 nm2 ty2 d2) |
| | 853 | | nm1 == nm2 && isGivenOrSolved fl2 && isGivenOrSolved fl1 |
| | 854 | = irInertConsumed "Hole/Hole (override inert)" |
| | 855 | | nm1 == nm2 && ty1 `eqType` ty2 |
| | 856 | = solveOneFromTheOther "Hole/Hole" fl1 workitem |
| | 857 | |
| | 858 | | nm1 == nm2 |
| | 859 | = do { mb_eqv <- newWantedEvVar (mkEqPred ty2 ty1) |
| | 860 | -- co :: ty2 ~ ty1, see Note [Efficient orientation] |
| | 861 | ; cv <- case mb_eqv of |
| | 862 | Fresh eqv -> |
| | 863 | do { updWorkListTcS $ extendWorkListEq $ |
| | 864 | CNonCanonical { cc_flavor = Wanted new_wloc eqv |
| | 865 | , cc_depth = cc_depth workitem } |
| | 866 | ; return eqv } |
| | 867 | Cached eqv -> return eqv |
| | 868 | ; case fl2 of |
| | 869 | Wanted {} -> |
| | 870 | let hole_co = mkTcTyConAppCo (holeTyCon nm1) [mkTcCoVarCo cv] |
| | 871 | in do { setEvBind (ctId workitem) $ |
| | 872 | mkEvCast (flav_evar fl1) (mkTcSymCo hole_co) |
| | 873 | ; irWorkItemConsumed "Hole/Hole (solved by rewriting)" } |
| | 874 | _ -> pprPanic "Unexpected Hole constraint" (ppr workitem) } |
| | 875 | where new_wloc |
| | 876 | | Wanted wl _ <- fl2 = wl |
| | 877 | | Derived wl _ <- fl2 = wl |
| | 878 | | Wanted wl _ <- fl1 = wl |
| | 879 | | Derived wl _ <- fl1 = wl |
| | 880 | | otherwise = panic "Solve Hole: no WantedLoc!" |
| 839 | 881 | |
| 840 | 882 | |
| 841 | 883 | doInteractWithInert ii@(CFunEqCan { cc_flavor = fl1, cc_fun = tc1 |
-
diff --git a/compiler/typecheck/TcMType.lhs b/compiler/typecheck/TcMType.lhs
index a8460af..afb677b 100644
|
a
|
b
|
|
| 171 | 171 | predTypeOccName ty = case classifyPredType ty of |
| 172 | 172 | ClassPred cls _ -> mkDictOcc (getOccName cls) |
| 173 | 173 | IPPred ip _ -> mkVarOccFS (ipFastString ip) |
| | 174 | HolePred name _ -> mkVarOccFS (occNameFS $ nameOccName $ holeNameName name) |
| 174 | 175 | EqPred _ _ -> mkVarOccFS (fsLit "cobox") |
| 175 | 176 | TuplePred _ -> mkVarOccFS (fsLit "tup") |
| 176 | 177 | IrredPred _ -> mkVarOccFS (fsLit "irred") |
| … |
… |
|
| 1446 | 1447 | go (EqPred ty1 ty2) = grow (tyVarsOfType ty1 `unionVarSet` tyVarsOfType ty2) |
| 1447 | 1448 | go (TuplePred ts) = unionVarSets (map (go . classifyPredType) ts) |
| 1448 | 1449 | go (IrredPred ty) = grow (tyVarsOfType ty) |
| | 1450 | go (HolePred _ ty) = tyVarsOfType ty |
| 1449 | 1451 | \end{code} |
| 1450 | 1452 | |
| 1451 | 1453 | Note [Implicit parameters and ambiguity] |
-
diff --git a/compiler/typecheck/TcRnDriver.lhs b/compiler/typecheck/TcRnDriver.lhs
index 0128f18..5649619 100644
|
a
|
b
|
|
| 40 | 40 | import TcAnnotations |
| 41 | 41 | import TcBinds |
| 42 | 42 | import HeaderInfo ( mkPrelImports ) |
| 43 | | import TcType ( tidyTopType ) |
| | 43 | import TcType ( tidyTopType, tidyType ) |
| 44 | 44 | import TcDefaults |
| 45 | 45 | import TcEnv |
| 46 | 46 | import TcRules |
| … |
… |
|
| 100 | 100 | |
| 101 | 101 | import Control.Monad |
| 102 | 102 | |
| | 103 | import System.IO |
| | 104 | import TypeRep |
| | 105 | import qualified Data.Map as Map |
| | 106 | import TcType |
| | 107 | |
| 103 | 108 | #include "HsVersions.h" |
| 104 | 109 | \end{code} |
| 105 | 110 | |
| … |
… |
|
| 431 | 436 | simplifyTop lie ; |
| 432 | 437 | traceTc "Tc9" empty ; |
| 433 | 438 | |
| | 439 | traceRn (text "tcRnSrcDecls:" <+> (ppr lie)) ; |
| | 440 | |
| 434 | 441 | failIfErrsM ; -- Don't zonk if there have been errors |
| 435 | 442 | -- It's a waste of time; and we may get debug warnings |
| 436 | 443 | -- about strangely-typed TyCons! |
| … |
… |
|
| 463 | 470 | setGlobalTypeEnv tcg_env' final_type_env |
| 464 | 471 | } } |
| 465 | 472 | |
| | 473 | -- where |
| | 474 | |
| 466 | 475 | tc_rn_src_decls :: ModDetails |
| 467 | 476 | -> [LHsDecl RdrName] |
| 468 | 477 | -> TcM (TcGblEnv, TcLclEnv) |
| … |
… |
|
| 1431 | 1440 | -- it might have a rank-2 type (e.g. :t runST) |
| 1432 | 1441 | uniq <- newUnique ; |
| 1433 | 1442 | let { fresh_it = itName uniq (getLoc rdr_expr) } ; |
| 1434 | | ((_tc_expr, res_ty), lie) <- captureConstraints (tcInferRho rn_expr) ; |
| 1435 | | ((qtvs, dicts, _, _), lie_top) <- captureConstraints $ |
| | 1443 | ((_tc_expr, res_ty), lie) <- captureConstraints (tcInferRho rn_expr) ; |
| | 1444 | |
| | 1445 | |
| | 1446 | (g, l) <- getEnvs ; |
| | 1447 | |
| | 1448 | ((qtvs, dicts, _, _), lie_top) <- captureConstraints $ |
| 1436 | 1449 | {-# SCC "simplifyInfer" #-} |
| 1437 | 1450 | simplifyInfer True {- Free vars are closed -} |
| 1438 | 1451 | False {- No MR for now -} |
| 1439 | | [(fresh_it, res_ty)] |
| | 1452 | ([(fresh_it, res_ty)]) -- ++ (map (\(nm,(ty,_)) -> (holeNameName nm, ty)) $ Map.toList holes)) |
| 1440 | 1453 | lie ; |
| | 1454 | let { (holes, dicts') = splitEvs dicts [] [] } ; |
| | 1455 | |
| | 1456 | traceRn (text "tcRnExpr1:" <+> (ppr holes <+> ppr dicts')) ; |
| | 1457 | |
| 1441 | 1458 | _ <- simplifyInteractive lie_top ; -- Ignore the dicionary bindings |
| | 1459 | |
| | 1460 | traceRn (text "tcRnExpr2:" <+> (ppr lie_top)) ; |
| | 1461 | |
| | 1462 | let { all_expr_ty = mkForAllTys qtvs (mkPiTypes dicts' res_ty) } ; |
| | 1463 | result <- zonkTcType all_expr_ty ; |
| | 1464 | |
| 1442 | 1465 | |
| 1443 | | let { all_expr_ty = mkForAllTys qtvs (mkPiTypes dicts res_ty) } ; |
| 1444 | | zonkTcType all_expr_ty |
| | 1466 | zonked_holes <- zonkHoles $ map (apsnd (mkForAllTys qtvs) . apsnd (mkPiTypes dicts') . unwrapHole . varType) $ holes ; |
| | 1467 | |
| | 1468 | let { (env, tidied_holes) = apsnd (map (apsnd split)) $ foldr tidy (emptyTidyEnv, []) zonked_holes } ; |
| | 1469 | |
| | 1470 | liftIO $ putStrLn $ showSDoc ((ptext $ sLit "Found the following holes: ") |
| | 1471 | $+$ (vcat $ map (\(nm, ty) -> text "_?" <> ppr nm <+> colon <> colon <+> ppr ty) tidied_holes)); |
| | 1472 | |
| | 1473 | return $ snd $ tidyOpenType env result |
| 1445 | 1474 | } |
| | 1475 | where tidy (nm, ty) (env, tys) = let (env', ty') = tidyOpenType env ty |
| | 1476 | in (env', (nm, ty') : tys) |
| | 1477 | |
| | 1478 | split t = let (_, ctxt, ty') = tcSplitSigmaTy $ tidyTopType t |
| | 1479 | in mkPhiTy ctxt ty' |
| | 1480 | |
| | 1481 | splitEvs [] hls dcts = (hls, dcts) |
| | 1482 | splitEvs (evvar:xs) hls dcts = case classifyPredType $ varType evvar of |
| | 1483 | HolePred {} -> splitEvs xs (evvar:hls) dcts |
| | 1484 | _ -> splitEvs xs hls (evvar:dcts) |
| | 1485 | -- unwrap what was wrapped in mkHolePred |
| | 1486 | unwrapHole (TyConApp nm [ty]) = (nm, ty) |
| | 1487 | |
| | 1488 | -- zonk the holes, but keep the name |
| | 1489 | zonkHoles = mapM (\(nm, ty) -> liftM (\t -> (nm, t)) $ zonkTcType ty) |
| | 1490 | |
| | 1491 | apsnd f (a, b) = (a, f b) |
| | 1492 | |
| | 1493 | f (_, b) = let (Just (ATyCon tc)) = wiredInNameTyThing_maybe b |
| | 1494 | (Just (_, ty, _)) = trace ("unwrapNewTyCon_maybe" ++ (showSDoc $ ppr tc)) $ unwrapNewTyCon_maybe tc |
| | 1495 | in (b, ty) |
| 1446 | 1496 | |
| 1447 | 1497 | -------------------------- |
| 1448 | 1498 | tcRnImportDecls :: HscEnv |
-
diff --git a/compiler/typecheck/TcRnMonad.lhs b/compiler/typecheck/TcRnMonad.lhs
index 0d20be2..77c78b7 100644
|
a
|
b
|
|
| 53 | 53 | import Data.IORef |
| 54 | 54 | import qualified Data.Set as Set |
| 55 | 55 | import Control.Monad |
| | 56 | |
| | 57 | import qualified Data.Map as Map |
| 56 | 58 | \end{code} |
| 57 | 59 | |
| 58 | 60 | |
| … |
… |
|
| 86 | 88 | infer_var <- newIORef True ; |
| 87 | 89 | lie_var <- newIORef emptyWC ; |
| 88 | 90 | dfun_n_var <- newIORef emptyOccSet ; |
| | 91 | holes_var <- newIORef Map.empty ; |
| 89 | 92 | type_env_var <- case hsc_type_env_var hsc_env of { |
| 90 | 93 | Just (_mod, te_var) -> return te_var ; |
| 91 | 94 | Nothing -> newIORef emptyNameEnv } ; |
-
diff --git a/compiler/typecheck/TcRnTypes.lhs b/compiler/typecheck/TcRnTypes.lhs
index f480bab..c928fda 100644
|
a
|
b
|
|
| 54 | 54 | Xi, Ct(..), Cts, emptyCts, andCts, andManyCts, |
| 55 | 55 | singleCt, extendCts, isEmptyCts, isCTyEqCan, isCFunEqCan, |
| 56 | 56 | isCDictCan_Maybe, isCIPCan_Maybe, isCFunEqCan_Maybe, |
| | 57 | isCHoleCan_Maybe, isCHoleCan, |
| 57 | 58 | isCIrredEvCan, isCNonCanonical, isWantedCt, isDerivedCt, |
| 58 | 59 | isGivenCt, isGivenOrSolvedCt, |
| 59 | 60 | ctWantedLoc, |
| 60 | 61 | SubGoalDepth, mkNonCanonical, ctPred, ctFlavPred, ctId, ctFlavId, |
| 61 | 62 | |
| 62 | 63 | WantedConstraints(..), insolubleWC, emptyWC, isEmptyWC, |
| 63 | | andWC, addFlats, addImplics, mkFlatWC, |
| | 64 | andWC, unionsWC, addFlats, addImplics, mkFlatWC, |
| 64 | 65 | |
| 65 | 66 | Implication(..), |
| 66 | 67 | CtLoc(..), ctLocSpan, ctLocOrigin, setCtLocOrigin, |
| … |
… |
|
| 122 | 123 | |
| 123 | 124 | import Data.Set (Set) |
| 124 | 125 | |
| | 126 | import UniqSet |
| | 127 | import qualified Data.Map as Map |
| 125 | 128 | \end{code} |
| 126 | 129 | |
| 127 | 130 | |
| … |
… |
|
| 901 | 904 | cc_depth :: SubGoalDepth |
| 902 | 905 | } |
| 903 | 906 | |
| | 907 | | CHoleCan { |
| | 908 | cc_id :: EvVar, |
| | 909 | cc_flavor :: CtFlavor, |
| | 910 | cc_hole_nm :: HoleName Name, |
| | 911 | cc_hole_ty :: TcTauType, -- Not a Xi! See same not as above |
| | 912 | cc_depth :: SubGoalDepth -- See Note [WorkList] |
| | 913 | } |
| | 914 | |
| 904 | 915 | \end{code} |
| 905 | 916 | |
| 906 | 917 | \begin{code} |
| … |
… |
|
| 918 | 929 | ctPred (CIPCan { cc_ip_nm = nm, cc_ip_ty = xi }) |
| 919 | 930 | = mkIPPred nm xi |
| 920 | 931 | ctPred (CIrredEvCan { cc_ty = xi }) = xi |
| 921 | | |
| | 932 | ctPred (CHoleCan { cc_hole_nm = nm, cc_hole_ty = xi}) |
| | 933 | = mkHolePred nm xi |
| 922 | 934 | |
| 923 | 935 | ctId :: Ct -> EvVar |
| 924 | 936 | -- Precondition: not a derived! |
| 925 | 937 | ctId ct = ctFlavId (cc_flavor ct) |
| 926 | | |
| 927 | 938 | \end{code} |
| 928 | 939 | |
| 929 | 940 | |
| … |
… |
|
| 980 | 991 | isCNonCanonical :: Ct -> Bool |
| 981 | 992 | isCNonCanonical (CNonCanonical {}) = True |
| 982 | 993 | isCNonCanonical _ = False |
| | 994 | |
| | 995 | isCHoleCan :: Ct -> Bool |
| | 996 | isCHoleCan (CHoleCan {}) = True |
| | 997 | isCHoleCan _ = False |
| | 998 | |
| | 999 | isCHoleCan_Maybe :: Ct -> Maybe (HoleName Name) |
| | 1000 | isCHoleCan_Maybe (CHoleCan { cc_hole_nm = nm }) = Just nm |
| | 1001 | isCHoleCan_Maybe _ = Nothing |
| 983 | 1002 | \end{code} |
| 984 | 1003 | |
| 985 | 1004 | \begin{code} |
| … |
… |
|
| 993 | 1012 | CDictCan {} -> "CDictCan" |
| 994 | 1013 | CIPCan {} -> "CIPCan" |
| 995 | 1014 | CIrredEvCan {} -> "CIrredEvCan" |
| | 1015 | CHoleCan {} -> "CHoleCan" |
| 996 | 1016 | \end{code} |
| 997 | 1017 | |
| 998 | 1018 | \begin{code} |
| … |
… |
|
| 1059 | 1079 | , wc_impl = i1 `unionBags` i2 |
| 1060 | 1080 | , wc_insol = n1 `unionBags` n2 } |
| 1061 | 1081 | |
| | 1082 | unionsWC :: [WantedConstraints] -> WantedConstraints |
| | 1083 | unionsWC = foldr andWC emptyWC |
| | 1084 | |
| 1062 | 1085 | addFlats :: WantedConstraints -> Bag Ct -> WantedConstraints |
| 1063 | 1086 | addFlats wc cts |
| 1064 | 1087 | = wc { wc_flat = wc_flat wc `unionBags` cts } |
-
diff --git a/compiler/typecheck/TcSMonad.lhs b/compiler/typecheck/TcSMonad.lhs
index 33a049e..9696651 100644
|
a
|
b
|
|
| 285 | 285 | , cts_wanted :: UniqFM Cts } |
| 286 | 286 | -- Invariant: all Wanted |
| 287 | 287 | |
| | 288 | instance Outputable (CCanMap a) where |
| | 289 | ppr (CCanMap given derived wanted) = ptext (sLit "CCanMap") <+> (ppr given) <+> (ppr derived) <+> (ppr wanted) |
| | 290 | |
| 288 | 291 | cCanMapToBag :: CCanMap a -> Cts |
| 289 | 292 | cCanMapToBag cmap = foldUFM unionBags rest_wder (cts_given cmap) |
| 290 | 293 | where rest_wder = foldUFM unionBags rest_der (cts_wanted cmap) |
| … |
… |
|
| 355 | 358 | in (wntd `unionBags` derd, |
| 356 | 359 | cmap { cts_wanted = emptyUFM, cts_derived = emptyUFM }) |
| 357 | 360 | |
| 358 | | |
| 359 | 361 | -- Maps from PredTypes to Constraints |
| 360 | 362 | type CtTypeMap = TypeMap Ct |
| 361 | 363 | newtype CtPredMap = |
| … |
… |
|
| 421 | 423 | -- Family equations, index is the whole family head type. |
| 422 | 424 | , inert_irreds :: Cts |
| 423 | 425 | -- Irreducible predicates |
| | 426 | , inert_holes :: CCanMap (HoleName Name) |
| 424 | 427 | } |
| 425 | 428 | |
| 426 | 429 | |
| … |
… |
|
| 497 | 500 | , vcat (map ppr (Bag.bagToList $ |
| 498 | 501 | ctTypeMapCts (unCtFamHeadMap $ inert_funeqs ics))) |
| 499 | 502 | , vcat (map ppr (Bag.bagToList $ inert_irreds ics)) |
| | 503 | , vcat (map ppr (Bag.bagToList $ cCanMapToBag (inert_holes ics))) |
| 500 | 504 | ] |
| 501 | 505 | |
| 502 | 506 | instance Outputable InertSet where |
| … |
… |
|
| 515 | 519 | , inert_dicts = emptyCCanMap |
| 516 | 520 | , inert_ips = emptyCCanMap |
| 517 | 521 | , inert_funeqs = CtFamHeadMap emptyTM |
| 518 | | , inert_irreds = emptyCts } |
| | 522 | , inert_irreds = emptyCts |
| | 523 | , inert_holes = emptyCCanMap } |
| 519 | 524 | , inert_frozen = emptyCts |
| 520 | 525 | , inert_flat_cache = CtFamHeadMap emptyTM |
| 521 | 526 | , inert_solved = CtPredMap emptyTM |
| … |
… |
|
| 563 | 568 | |
| 564 | 569 | | Just x <- isCIPCan_Maybe item -- IP |
| 565 | 570 | = ics { inert_ips = updCCanMap (x,item) (inert_ips ics) } |
| | 571 | |
| | 572 | | Just x <- isCHoleCan_Maybe item |
| | 573 | = ics { inert_holes = updCCanMap (x,item) (inert_holes ics) } |
| 566 | 574 | |
| 567 | 575 | | isCIrredEvCan item -- Presently-irreducible evidence |
| 568 | 576 | = ics { inert_irreds = inert_irreds ics `Bag.snocBag` item } |
| … |
… |
|
| 639 | 647 | , inert_ips = ips |
| 640 | 648 | , inert_funeqs = funeqs |
| 641 | 649 | , inert_dicts = dicts |
| | 650 | , inert_holes = holes |
| 642 | 651 | } |
| 643 | 652 | , inert_frozen = frozen |
| 644 | 653 | , inert_solved = solved |
| … |
… |
|
| 651 | 660 | , inert_dicts = solved_dicts |
| 652 | 661 | , inert_ips = solved_ips |
| 653 | 662 | , inert_irreds = solved_irreds |
| 654 | | , inert_funeqs = solved_funeqs } |
| | 663 | , inert_funeqs = solved_funeqs |
| | 664 | , inert_holes = solved_holes } |
| 655 | 665 | , inert_frozen = emptyCts -- All out |
| 656 | 666 | |
| 657 | 667 | -- At some point, I used to flush all the solved, in |
| … |
… |
|
| 674 | 684 | (unsolved_funeqs, solved_funeqs) = |
| 675 | 685 | partCtFamHeadMap (not . isGivenOrSolved . cc_flavor) funeqs |
| 676 | 686 | |
| | 687 | (unsolved_holes, solved_holes) = extractUnsolvedCMap holes |
| | 688 | |
| 677 | 689 | unsolved = unsolved_eqs `unionBags` unsolved_irreds `unionBags` |
| 678 | 690 | unsolved_ips `unionBags` unsolved_dicts `unionBags` unsolved_funeqs |
| | 691 | `unionBags` unsolved_holes |
| 679 | 692 | |
| 680 | 693 | |
| 681 | 694 | |
| … |
… |
|
| 707 | 720 | extract_ics_relevants (CIPCan { cc_ip_nm = nm } ) ics = |
| 708 | 721 | let (cts, ips_map) = getRelevantCts nm (inert_ips ics) |
| 709 | 722 | in (cts, ics { inert_ips = ips_map }) |
| | 723 | extract_ics_relevants (CHoleCan { cc_hole_nm = nm } ) ics = |
| | 724 | let (cts, holes_map) = getRelevantCts nm (inert_holes ics) |
| | 725 | in (cts, ics { inert_holes = holes_map }) |
| 710 | 726 | extract_ics_relevants (CIrredEvCan { }) ics = |
| 711 | 727 | let cts = inert_irreds ics |
| 712 | 728 | in (cts, ics { inert_irreds = emptyCts }) |
-
diff --git a/compiler/typecheck/TcSimplify.lhs b/compiler/typecheck/TcSimplify.lhs
index 3c3c7f7..b8c7e4e 100644
|
a
|
b
|
|
| 294 | 294 | -- unless we are deferring errors to runtime |
| 295 | 295 | ; when (not runtimeCoercionErrors && insolubleWC simpl_results) $ |
| 296 | 296 | do { _ev_binds <- reportUnsolved False simpl_results |
| | 297 | ; traceTc "There is an insoluble constraint, failing already" empty |
| 297 | 298 | ; failM } |
| 298 | 299 | |
| 299 | 300 | -- Step 3 |
| … |
… |
|
| 471 | 472 | -> Bool -- True <=> quantify over this wanted |
| 472 | 473 | quantifyMe qtvs ct |
| 473 | 474 | | isIPPred pred = True -- Note [Inheriting implicit parameters] |
| | 475 | | isHolePred pred = True |
| 474 | 476 | | otherwise = tyVarsOfType pred `intersectsVarSet` qtvs |
| 475 | 477 | where |
| 476 | 478 | pred = ctPred ct |
-
diff --git a/compiler/typecheck/TcType.lhs b/compiler/typecheck/TcType.lhs
index fc08bad..bd6e504 100644
|
a
|
b
|
|
| 130 | 130 | mkTyVarTy, mkTyVarTys, mkTyConTy, |
| 131 | 131 | |
| 132 | 132 | isClassPred, isEqPred, isIPPred, |
| 133 | | mkClassPred, mkIPPred, |
| | 133 | mkClassPred, mkIPPred, isHolePred, |
| 134 | 134 | isDictLikeTy, |
| 135 | 135 | tcSplitDFunTy, tcSplitDFunHead, |
| 136 | 136 | mkEqPred, |
| … |
… |
|
| 307 | 307 | |
| 308 | 308 | | MetaTv MetaInfo (IORef MetaDetails) |
| 309 | 309 | |
| | 310 | instance Outputable TcTyVarDetails where |
| | 311 | ppr (SkolemTv b) = ptext (sLit "SkolemTv") <+> ppr b |
| | 312 | ppr RuntimeUnk = ptext (sLit "RuntimeUnk") |
| | 313 | ppr (FlatSkol ty) = ptext (sLit "FlatSkol") <+> ppr ty |
| | 314 | ppr (MetaTv info _) = ptext (sLit "MetaTv") <+> ppr info |
| | 315 | |
| 310 | 316 | vanillaSkolemTv, superSkolemTv :: TcTyVarDetails |
| 311 | 317 | -- See Note [Binding when looking up instances] in InstEnv |
| 312 | 318 | vanillaSkolemTv = SkolemTv False -- Might be instantiated |
| … |
… |
|
| 341 | 347 | -- UserTypeCtxt describes the origin of the polymorphic type |
| 342 | 348 | -- in the places where we need to an expression has that type |
| 343 | 349 | |
| | 350 | instance Outputable MetaInfo where |
| | 351 | ppr TauTv = ptext (sLit "TauTv") |
| | 352 | ppr SigTv = ptext (sLit "SigTv") |
| | 353 | ppr TcsTv = ptext (sLit "TcsTv") |
| | 354 | |
| 344 | 355 | data UserTypeCtxt |
| 345 | 356 | = FunSigCtxt Name -- Function type signature |
| 346 | 357 | -- Also used for types in SPECIALISE pragmas |
-
diff --git a/compiler/types/TyCon.lhs b/compiler/types/TyCon.lhs
index a0a69c6..991bf6e 100644
|
a
|
b
|
|
| 65 | 65 | tyConStupidTheta, |
| 66 | 66 | tyConArity, |
| 67 | 67 | tyConParent, |
| 68 | | tyConTuple_maybe, tyConClass_maybe, tyConIP_maybe, |
| | 68 | tyConTuple_maybe, tyConClass_maybe, tyConIP_maybe, tyConHole_maybe, |
| 69 | 69 | tyConFamInst_maybe, tyConFamInstSig_maybe, tyConFamilyCoercion_maybe, |
| 70 | 70 | synTyConDefn, synTyConRhs, synTyConType, |
| 71 | 71 | tyConExtName, -- External name for foreign types |
| … |
… |
|
| 551 | 551 | -- data R:TList a = ... |
| 552 | 552 | -- axiom co a :: T [a] ~ R:TList a |
| 553 | 553 | -- with R:TList's algTcParent = FamInstTyCon T [a] co |
| | 554 | | HoleTyCon (HoleName Name) |
| 554 | 555 | |
| 555 | 556 | instance Outputable TyConParent where |
| 556 | 557 | ppr NoParentTyCon = text "No parent" |
| … |
… |
|
| 566 | 567 | okParent tc_name (ClassTyCon cls) = tc_name == tyConName (classTyCon cls) |
| 567 | 568 | okParent tc_name (IPTyCon ip) = tc_name == ipTyConName ip |
| 568 | 569 | okParent _ (FamInstTyCon _ fam_tc tys) = tyConArity fam_tc == length tys |
| | 570 | okParent tc_name (HoleTyCon hole) = tc_name == holeNameName hole |
| 569 | 571 | |
| 570 | 572 | isNoParent :: TyConParent -> Bool |
| 571 | 573 | isNoParent NoParentTyCon = True |
| … |
… |
|
| 1410 | 1412 | tyConIP_maybe (AlgTyCon {algTcParent = IPTyCon ip}) = Just ip |
| 1411 | 1413 | tyConIP_maybe _ = Nothing |
| 1412 | 1414 | |
| | 1415 | tyConHole_maybe :: TyCon -> Maybe (HoleName Name) |
| | 1416 | tyConHole_maybe (AlgTyCon {algTcParent = HoleTyCon name}) = Just name |
| | 1417 | tyConHole_maybe _ = Nothing |
| | 1418 | |
| 1413 | 1419 | ---------------------------------------------------------------------------- |
| 1414 | 1420 | tyConParent :: TyCon -> TyConParent |
| 1415 | 1421 | tyConParent (AlgTyCon {algTcParent = parent}) = parent |
-
diff --git a/compiler/types/Type.lhs b/compiler/types/Type.lhs
index 89c460e..c1f6309 100644
|
a
|
b
|
|
| 53 | 53 | isDictLikeTy, |
| 54 | 54 | mkNakedEqPred, mkEqPred, mkPrimEqPred, |
| 55 | 55 | mkClassPred, |
| 56 | | mkIPPred, |
| | 56 | mkIPPred, mkHolePred, |
| 57 | 57 | noParenPred, isClassPred, isEqPred, isIPPred, |
| 58 | | |
| | 58 | isHolePred, |
| | 59 | |
| 59 | 60 | -- Deconstructing predicate types |
| 60 | 61 | PredTree(..), predTreePredType, classifyPredType, |
| 61 | 62 | getClassPredTys, getClassPredTys_maybe, |
| … |
… |
|
| 63 | 64 | getIPPredTy_maybe, |
| 64 | 65 | |
| 65 | 66 | -- ** Common type constructors |
| 66 | | funTyCon, |
| | 67 | funTyCon, holeTyCon, |
| 67 | 68 | |
| 68 | 69 | -- ** Predicates on types |
| 69 | 70 | isTypeVar, isKindVar, |
| … |
… |
|
| 158 | 159 | import TysPrim |
| 159 | 160 | import {-# SOURCE #-} TysWiredIn ( eqTyCon, mkBoxedTupleTy ) |
| 160 | 161 | import PrelNames ( eqTyConKey ) |
| | 162 | import Name |
| 161 | 163 | |
| 162 | 164 | -- others |
| 163 | 165 | import {-# SOURCE #-} IParam ( ipTyCon ) |
| 164 | 166 | import Unique ( Unique, hasKey ) |
| 165 | | import BasicTypes ( IPName(..) ) |
| | 167 | import BasicTypes ( IPName(..), HoleName(..), holeNameName ) |
| 166 | 168 | import Name ( Name ) |
| 167 | 169 | import NameSet |
| 168 | 170 | import StaticFlags |
| … |
… |
|
| 844 | 846 | isKindTy :: Type -> Bool |
| 845 | 847 | isKindTy = isSuperKind . typeKind |
| 846 | 848 | |
| 847 | | isClassPred, isEqPred, isIPPred :: PredType -> Bool |
| | 849 | isClassPred, isEqPred, isIPPred, isHolePred :: PredType -> Bool |
| 848 | 850 | isClassPred ty = case tyConAppTyCon_maybe ty of |
| 849 | 851 | Just tyCon | isClassTyCon tyCon -> True |
| 850 | 852 | _ -> False |
| … |
… |
|
| 854 | 856 | isIPPred ty = case tyConAppTyCon_maybe ty of |
| 855 | 857 | Just tyCon | Just _ <- tyConIP_maybe tyCon -> True |
| 856 | 858 | _ -> False |
| | 859 | isHolePred ty = case tyConAppTyCon_maybe ty of |
| | 860 | Just tycon | Just _ <- tyConHole_maybe tycon -> True |
| | 861 | _ -> False |
| 857 | 862 | \end{code} |
| 858 | 863 | |
| 859 | 864 | Make PredTypes |
| … |
… |
|
| 890 | 895 | mkIPPred ip ty = TyConApp (ipTyCon ip) [ty] |
| 891 | 896 | \end{code} |
| 892 | 897 | |
| | 898 | \begin{code} |
| | 899 | mkHolePred :: HoleName Name -> Type -> PredType |
| | 900 | mkHolePred name ty = TyConApp (holeTyCon name) [ty] |
| | 901 | |
| | 902 | holeTyCon :: HoleName Name -> TyCon |
| | 903 | holeTyCon name = case wiredInNameTyThing_maybe $ holeNameName name of |
| | 904 | Just (ATyCon tc) -> tc |
| | 905 | _ -> pprPanic "holeTyCon" (ppr name) |
| | 906 | \end{code} |
| | 907 | |
| 893 | 908 | --------------------- Dictionary types --------------------------------- |
| 894 | 909 | \begin{code} |
| 895 | 910 | mkClassPred :: Class -> [Type] -> PredType |
| … |
… |
|
| 945 | 960 | | IPPred (IPName Name) Type |
| 946 | 961 | | TuplePred [PredType] |
| 947 | 962 | | IrredPred PredType |
| | 963 | | HolePred (HoleName Name) Type |
| 948 | 964 | |
| 949 | 965 | predTreePredType :: PredTree -> PredType |
| 950 | 966 | predTreePredType (ClassPred clas tys) = mkClassPred clas tys |
| … |
… |
|
| 965 | 981 | -> IPPred ip ty |
| 966 | 982 | Just (tc, tys) | isTupleTyCon tc |
| 967 | 983 | -> TuplePred tys |
| | 984 | Just (tc, tys) | Just name <- tyConHole_maybe tc |
| | 985 | , let [ty] = tys |
| | 986 | -> HolePred name ty |
| 968 | 987 | _ -> IrredPred ev_ty |
| 969 | 988 | \end{code} |
| 970 | 989 | |