Simon Peyton Jones pushed to branch wip/spj-reinstallable-base at Glasgow Haskell Compiler / GHC
Commits:
-
0f713406
by Simon Peyton Jones at 2026-03-25T00:05:18+00:00
21 changed files:
- compiler/GHC/Builtin/Names.hs
- compiler/GHC/HsToCore/Monad.hs
- compiler/GHC/Iface/Errors/Ppr.hs
- compiler/GHC/Iface/Errors/Types.hs
- compiler/GHC/Iface/Load.hs
- compiler/GHC/Rename/Env.hs
- compiler/GHC/Rename/Expr.hs
- compiler/GHC/Rename/Lit.hs
- compiler/GHC/Rename/Names.hs
- compiler/GHC/Rename/Pat.hs
- compiler/GHC/Tc/Utils/Env.hs
- compiler/GHC/Types/Error/Codes.hs
- compiler/GHC/Types/Name.hs
- libraries/ghc-internal/src/GHC/Internal/Arr.hs
- libraries/ghc-internal/src/GHC/Internal/Data/STRef.hs
- libraries/ghc-internal/src/GHC/Internal/Data/Type/Ord.hs
- libraries/ghc-internal/src/GHC/Internal/Event/IntVar.hs
- libraries/ghc-internal/src/GHC/Internal/Event/Unique.hs
- libraries/ghc-internal/src/GHC/Internal/Float/RealFracMethods.hs
- libraries/ghc-internal/src/GHC/Internal/Num.hs
- libraries/ghc-internal/src/GHC/Internal/ST.hs
Changes:
| ... | ... | @@ -127,7 +127,6 @@ import GHC.Types.SrcLoc |
| 127 | 127 | import GHC.Builtin.Uniques
|
| 128 | 128 | import GHC.Builtin.Names.TH( thKnownKeyTable )
|
| 129 | 129 | |
| 130 | -import GHC.Utils.Outputable
|
|
| 131 | 130 | import GHC.Utils.Panic
|
| 132 | 131 | import GHC.Utils.Misc( HasDebugCallStack )
|
| 133 | 132 | |
| ... | ... | @@ -204,13 +203,6 @@ knownKeyOccName std_uniq |
| 204 | 203 | Just occ -> occ
|
| 205 | 204 | Nothing -> pprPanic "knownKeyOccName" (pprKnownKey std_uniq)
|
| 206 | 205 | |
| 207 | -pprKnownKey :: KnownKeyNameKey -> SDoc
|
|
| 208 | --- Show it in both base64 and decimal, for debugging
|
|
| 209 | -pprKnownKey uniq
|
|
| 210 | - = ppr uniq <+> braces (text (show tag) <+> ppr u)
|
|
| 211 | - where
|
|
| 212 | - (tag, u) = unpkUnique uniq
|
|
| 213 | - |
|
| 214 | 206 | basicKnownKeyTable :: [(OccName, KnownKeyNameKey)]
|
| 215 | 207 | basicKnownKeyTable
|
| 216 | 208 | = [ (mkTcOcc "Rational", rationalTyConKey)
|
| ... | ... | @@ -2280,7 +2272,7 @@ enumFromThenToClassOpKey = mkPreludeMiscIdUnique 166 |
| 2280 | 2272 | eqClassOpKey = mkPreludeMiscIdUnique 167
|
| 2281 | 2273 | geClassOpKey = mkPreludeMiscIdUnique 168
|
| 2282 | 2274 | negateClassOpKey = mkPreludeMiscIdUnique 169
|
| 2283 | -bindMClassOpKey = mkPreludeMiscIdUnique 171 -- (>>=)
|
|
| 2275 | +bindMClassOpKey = mkPreludeMiscIdUnique 171 -- (>>=) 02L
|
|
| 2284 | 2276 | thenMClassOpKey = mkPreludeMiscIdUnique 172 -- (>>)
|
| 2285 | 2277 | fmapClassOpKey = mkPreludeMiscIdUnique 173
|
| 2286 | 2278 | returnMClassOpKey = mkPreludeMiscIdUnique 174
|
| ... | ... | @@ -567,7 +567,8 @@ dsLookupKnownKey :: KnownKeyNameKey -> DsM TyThing |
| 567 | 567 | dsLookupKnownKey uniq
|
| 568 | 568 | = do { rebindable_path <- goptM Opt_RebindableKnownKeyNames
|
| 569 | 569 | ; mb_rdr_env <- if rebindable_path
|
| 570 | - then KKNS_InScope <$> dsGetGlobalRdrEnv
|
|
| 570 | + then do { rdr_env <- dsGetGlobalRdrEnv
|
|
| 571 | + ; return (KKNS_InScope rdr_env) }
|
|
| 571 | 572 | else return KKNS_FromModule
|
| 572 | 573 | ; dsToIfL $
|
| 573 | 574 | do { mb_res <- lookupKnownKeyThing mb_rdr_env uniq
|
| ... | ... | @@ -60,10 +60,11 @@ interfaceErrorHints :: IfaceMessage -> [GhcHint] |
| 60 | 60 | interfaceErrorHints = \ case
|
| 61 | 61 | Can'tFindInterface err _looking_for ->
|
| 62 | 62 | missingInterfaceErrorHints err
|
| 63 | - Can'tFindNameInInterface {} ->
|
|
| 64 | - noHints
|
|
| 65 | - CircularImport {} ->
|
|
| 66 | - noHints
|
|
| 63 | + Can'tFindNameInInterface {} -> noHints
|
|
| 64 | + CircularImport {} -> noHints
|
|
| 65 | + MissingKnownKey1 {} -> noHints
|
|
| 66 | + MissingKnownKey2 {} -> noHints
|
|
| 67 | + KnownKeyScopeError {} -> noHints
|
|
| 67 | 68 | |
| 68 | 69 | missingInterfaceErrorHints :: MissingInterfaceError -> [GhcHint]
|
| 69 | 70 | missingInterfaceErrorHints = \case
|
| ... | ... | @@ -85,8 +86,10 @@ interfaceErrorReason (Can'tFindInterface err _) |
| 85 | 86 | = missingInterfaceErrorReason err
|
| 86 | 87 | interfaceErrorReason (Can'tFindNameInInterface {})
|
| 87 | 88 | = ErrorWithoutFlag
|
| 88 | -interfaceErrorReason (CircularImport {})
|
|
| 89 | - = ErrorWithoutFlag
|
|
| 89 | +interfaceErrorReason (CircularImport {}) = ErrorWithoutFlag
|
|
| 90 | +interfaceErrorReason (MissingKnownKey1 {}) = ErrorWithoutFlag
|
|
| 91 | +interfaceErrorReason (MissingKnownKey2 {}) = ErrorWithoutFlag
|
|
| 92 | +interfaceErrorReason (KnownKeyScopeError {}) = ErrorWithoutFlag
|
|
| 90 | 93 | |
| 91 | 94 | missingInterfaceErrorReason :: MissingInterfaceError -> DiagnosticReason
|
| 92 | 95 | missingInterfaceErrorReason = \ case
|
| ... | ... | @@ -290,6 +293,18 @@ interfaceErrorDiagnostic opts = \ case |
| 290 | 293 | CircularImport mod ->
|
| 291 | 294 | text "Circular imports: module" <+> quotes (ppr mod)
|
| 292 | 295 | <+> text "depends on itself"
|
| 296 | + MissingKnownKey1 key -> hang (text "Could not find known key" <+> quotes (pprKnownKey key))
|
|
| 297 | + 2 (text "in the exports of GHC.KnownKeys")
|
|
| 298 | + MissingKnownKey2 key -> hang (text "Could not find known key" <+> quotes (pprKnownKey key))
|
|
| 299 | + 2 (text "in the static known-key table")
|
|
| 300 | + KnownKeyScopeError _key occ gres
|
|
| 301 | + | null gres
|
|
| 302 | + -> hang (text "Could not find known-key entity" <+> quotes (ppr occ))
|
|
| 303 | + 2 (vcat [ text "in the top-level global environment"
|
|
| 304 | + , text "Consider importing it" ])
|
|
| 305 | + | otherwise
|
|
| 306 | + -> hang (text "Known-key entity" <+> quotes (ppr occ))
|
|
| 307 | + 2 (text "is ambiguous in the top-level global environment")
|
|
| 293 | 308 | |
| 294 | 309 | lookingForHerald :: InterfaceLookingFor -> SDoc
|
| 295 | 310 | lookingForHerald looking_for =
|
| ... | ... | @@ -16,7 +16,9 @@ module GHC.Iface.Errors.Types ( |
| 16 | 16 | |
| 17 | 17 | import GHC.Prelude
|
| 18 | 18 | |
| 19 | -import GHC.Types.Name (Name)
|
|
| 19 | +import GHC.Types.Name (Name, KnownKeyNameKey)
|
|
| 20 | +import GHC.Types.Name.Occurrence (OccName)
|
|
| 21 | +import GHC.Types.Name.Reader (GlobalRdrElt)
|
|
| 20 | 22 | import GHC.Types.TyThing (TyThing)
|
| 21 | 23 | import GHC.Unit.Types (Module, InstalledModule, UnitId, Unit)
|
| 22 | 24 | import GHC.Unit.State (UnitState, ModuleSuggestion, ModuleOrigin, UnusableUnit, UnitInfo)
|
| ... | ... | @@ -43,10 +45,24 @@ data IfaceMessage |
| 43 | 45 | = Can'tFindInterface
|
| 44 | 46 | MissingInterfaceError
|
| 45 | 47 | InterfaceLookingFor
|
| 48 | + |
|
| 46 | 49 | | Can'tFindNameInInterface
|
| 47 | 50 | Name
|
| 48 | 51 | [TyThing] -- possibly relevant TyThings
|
| 52 | + |
|
| 49 | 53 | | CircularImport !Module
|
| 54 | + |
|
| 55 | + | MissingKnownKey1 KnownKeyNameKey
|
|
| 56 | + -- We looked up a known-key, but it wasn't in the
|
|
| 57 | + -- known-key map that came from importing GHC.KnownKeyNames
|
|
| 58 | + |
|
| 59 | + | MissingKnownKey2 KnownKeyNameKey
|
|
| 60 | + -- We looked up a known-key, but it wasn't in
|
|
| 61 | + -- the `knownKeyTable` of all known keys
|
|
| 62 | + |
|
| 63 | + | KnownKeyScopeError KnownKeyNameKey OccName [GlobalRdrElt]
|
|
| 64 | + -- We looked up a known-key in the GlobalRdrEnv,
|
|
| 65 | + -- but did not find a unique hit
|
|
| 50 | 66 | deriving Generic
|
| 51 | 67 | |
| 52 | 68 | data MissingInterfaceError
|
| ... | ... | @@ -157,43 +157,35 @@ lookupKnownKeyThing :: HasDebugCallStack |
| 157 | 157 | => KnownKeyNameSource -> KnownKeyNameKey
|
| 158 | 158 | -> IfM lcl (MaybeErr IfaceMessage TyThing)
|
| 159 | 159 | lookupKnownKeyThing mb_gbl_rdr_env key
|
| 160 | - = do { name <- lookupKnownKeyName mb_gbl_rdr_env key
|
|
| 161 | - ; lookupGlobalName name }
|
|
| 160 | + = do { mb_name <- lookupKnownKeyName mb_gbl_rdr_env key
|
|
| 161 | + ; case mb_name of
|
|
| 162 | + Failed err -> return (Failed err)
|
|
| 163 | + Succeeded name -> lookupGlobalName name }
|
|
| 162 | 164 | |
| 163 | 165 | lookupKnownKeyName :: HasDebugCallStack
|
| 164 | 166 | => KnownKeyNameSource -> KnownKeyNameKey
|
| 165 | - -> IfM lcl Name
|
|
| 167 | + -> IfM lcl (MaybeErr IfaceMessage Name)
|
|
| 166 | 168 | lookupKnownKeyName KKNS_FromModule uniq
|
| 167 | 169 | = do { known_key_name_map :: UniqFM KnownKeyNameKey Name <- loadKnownKeyOccMap
|
| 168 | - ; let name = lookupUFM known_key_name_map uniq
|
|
| 169 | - `orElse` pprPanic "lookupKnownKeyThing 1"
|
|
| 170 | - (vcat [ text "unique:" <+> ppr uniq
|
|
| 171 | - , text "occ-map" <+> ppr known_key_name_map ])
|
|
| 172 | - ; traceIf $ hang (text "lookupKnownKeyThing ImplicitKnownKeyNames")
|
|
| 173 | - 2 (ppr name <+> ppr uniq)
|
|
| 174 | - ; return name }
|
|
| 170 | + ; case lookupUFM known_key_name_map uniq of
|
|
| 171 | + Just name -> return (Succeeded name)
|
|
| 172 | + Nothing -> return (Failed (MissingKnownKey1 uniq)) }
|
|
| 175 | 173 | |
| 176 | 174 | lookupKnownKeyName (KKNS_InScope gbl_rdr_env) uniq
|
| 177 | 175 | -- Just gbl_rdr_env: we have -frebindable-known-key-names on, and
|
| 178 | 176 | -- here is the top-level GlobalRdrEnv
|
| 179 | 177 | -- Look up the known-key OccName in the GlobalRdrEnv
|
| 180 | 178 | -- If we get a unique hit, use it; if not, panic.
|
| 181 | - | let occ :: OccName
|
|
| 182 | - occ = lookupUFM knownKeyUniqMap uniq
|
|
| 183 | - `orElse` pprPanic "lookupKnownKeyThing: missing key"
|
|
| 184 | - (vcat [ text "unique:" <+> ppr uniq
|
|
| 185 | - , text "uniq-map:" <+> ppr knownKeyUniqMap ])
|
|
| 179 | + | Just (occ :: OccName) <- lookupUFM knownKeyUniqMap uniq
|
|
| 186 | 180 | = case lookupGRE gbl_rdr_env (LookupOccName occ SameNameSpace) of
|
| 187 | 181 | [gre] -> do { let name = greName gre
|
| 188 | --- ; addUsedGRE NoDeprecationWarnings gre
|
|
| 189 | --- -- addUseGRE: don't complain about unused imports
|
|
| 190 | --- -- of known-key names when -frebindable-known-key-names
|
|
| 191 | 182 | ; traceIf $ hang (text "lookupKnownKeyThing NoImplicitKnownKeyNames")
|
| 192 | 183 | 2 (ppr name <+> ppr uniq)
|
| 193 | - ; return name }
|
|
| 194 | - [] -> pprPanic "lookupKnownKeyName: known-key name is not in scope" (ppr occ)
|
|
| 195 | - gres -> pprPanic "lookupKnownKeyName: known-key name is ambiguously in scope" (ppr gres)
|
|
| 196 | - where
|
|
| 184 | + ; return (Succeeded name) }
|
|
| 185 | + gres -> return (Failed (KnownKeyScopeError uniq occ gres))
|
|
| 186 | + |
|
| 187 | + | otherwise
|
|
| 188 | + = return (Failed (MissingKnownKey2 uniq))
|
|
| 197 | 189 | |
| 198 | 190 | loadKnownKeyOccMap :: IfM lcl KnownKeyNameMap
|
| 199 | 191 | loadKnownKeyOccMap
|
| ... | ... | @@ -44,9 +44,7 @@ module GHC.Rename.Env ( |
| 44 | 44 | lookupSyntax, lookupSyntaxExpr,
|
| 45 | 45 | lookupSyntaxName,
|
| 46 | 46 | lookupIfThenElse,
|
| 47 | - |
|
| 48 | - -- QualifiedDo
|
|
| 49 | - lookupQualifiedDo, lookupQualifiedDoName, lookupNameWithQualifier,
|
|
| 47 | + lookupNameWithQualifier,
|
|
| 50 | 48 | |
| 51 | 49 | -- Constructing usage information
|
| 52 | 50 | DeprecationWarnings(..),
|
| ... | ... | @@ -104,7 +102,6 @@ import GHC.Types.CompleteMatch |
| 104 | 102 | import GHC.Types.PkgQual
|
| 105 | 103 | import GHC.Types.GREInfo
|
| 106 | 104 | |
| 107 | -import Control.Arrow ( first )
|
|
| 108 | 105 | import Control.Monad
|
| 109 | 106 | import Data.Either ( partitionEithers )
|
| 110 | 107 | import Data.Function ( on )
|
| ... | ... | @@ -2404,39 +2401,19 @@ lookupSyntax std_uniq |
| 2404 | 2401 | = do { (expr, fvs) <- lookupSyntaxExpr std_uniq
|
| 2405 | 2402 | ; return (SyntaxExprRn expr, fvs) }
|
| 2406 | 2403 | |
| 2407 | -{-
|
|
| 2408 | -Note [QualifiedDo]
|
|
| 2409 | -~~~~~~~~~~~~~~~~~~
|
|
| 2410 | -QualifiedDo is implemented using the same placeholders for operation names in
|
|
| 2411 | -the AST that were devised for RebindableSyntax. Whenever the renamer checks
|
|
| 2412 | -which names to use for do syntax, it first checks if the do block is qualified
|
|
| 2413 | -(e.g. M.do { stmts }), in which case it searches for qualified names. If the
|
|
| 2414 | -qualified names are not in scope, an error is produced. If the do block is not
|
|
| 2415 | -qualified, the renamer does the usual search of the names which considers
|
|
| 2416 | -whether RebindableSyntax is enabled or not. Dealing with QualifiedDo is driven
|
|
| 2417 | -by the Opt_QualifiedDo dynamic flag.
|
|
| 2418 | --}
|
|
| 2419 | - |
|
| 2420 | --- Lookup operations for a qualified do. If the context is not a qualified
|
|
| 2421 | --- do, then use lookupSyntaxExpr. See Note [QualifiedDo].
|
|
| 2422 | -lookupQualifiedDo :: HsStmtContext fn -> KnownKeyNameKey -> RnM (SyntaxExpr GhcRn, FreeVars)
|
|
| 2423 | -lookupQualifiedDo ctxt std_name
|
|
| 2424 | - = first mkRnSyntaxExpr <$> lookupQualifiedDoName ctxt std_name
|
|
| 2425 | - |
|
| 2426 | -lookupNameWithQualifier :: KnownKeyNameKey -> ModuleName -> RnM (Name, FreeVars)
|
|
| 2427 | -lookupNameWithQualifier std_uniq modName
|
|
| 2404 | +lookupNameWithQualifier :: ModuleName -> KnownKeyNameKey -> RnM (Name, FreeVars)
|
|
| 2405 | +lookupNameWithQualifier modName std_uniq
|
|
| 2428 | 2406 | = do { qname <- lookupOccRnNone $
|
| 2429 | 2407 | mkRdrQual modName (knownKeyOccName std_uniq)
|
| 2430 | 2408 | ; return (qname, unitFV qname) }
|
| 2431 | 2409 | |
| 2432 | --- See Note [QualifiedDo].
|
|
| 2433 | -lookupQualifiedDoName :: HsStmtContext fn -> KnownKeyNameKey -> RnM (Name, FreeVars)
|
|
| 2434 | -lookupQualifiedDoName ctxt std_uniq
|
|
| 2435 | - = case qualifiedDoModuleName_maybe ctxt of
|
|
| 2436 | - Nothing -> lookupSyntaxName std_uniq
|
|
| 2437 | - Just modName -> lookupNameWithQualifier std_uniq modName
|
|
| 2438 | 2410 | |
| 2439 | ---------------------------------------------------------------------------------
|
|
| 2411 | +{- *********************************************************************
|
|
| 2412 | +* *
|
|
| 2413 | + Irrefutability
|
|
| 2414 | +* *
|
|
| 2415 | +********************************************************************* -}
|
|
| 2416 | + |
|
| 2440 | 2417 | -- Helper functions for 'isIrrefutableHsPat'.
|
| 2441 | 2418 | --
|
| 2442 | 2419 | -- (Defined here to avoid import cycles.)
|
| ... | ... | @@ -2498,4 +2475,3 @@ in_single_complete_match con_nm = go |
| 2498 | 2475 | | otherwise
|
| 2499 | 2476 | = go comps
|
| 2500 | 2477 | |
| 2501 | --------------------------------------------------------------------------------- |
| ... | ... | @@ -1266,8 +1266,7 @@ rnStmt ctxt rnBody (L loc (LastStmt _ (L lb body) noret _)) thing_inside |
| 1266 | 1266 | |
| 1267 | 1267 | rnStmt ctxt rnBody (L loc (BodyStmt _ (L lb body) _ _)) thing_inside
|
| 1268 | 1268 | = do { (body', fv_expr) <- rnBody body
|
| 1269 | - ; (then_op, fvs1) <- pprTrace "rnStmt" (ppr loc $$ ppr ctxt) $
|
|
| 1270 | - lookupQualifiedDoStmtName ctxt thenMClassOpKey
|
|
| 1269 | + ; (then_op, fvs1) <- lookupQualifiedDoStmtName ctxt thenMClassOpKey
|
|
| 1271 | 1270 | |
| 1272 | 1271 | ; (guard_op, fvs2) <- if isComprehensionContext ctxt
|
| 1273 | 1272 | then lookupQualifiedDoStmtName ctxt guardMIdKey
|
| ... | ... | @@ -1418,6 +1417,44 @@ rnParallelStmts ctxt return_op segs thing_inside |
| 1418 | 1417 | |
| 1419 | 1418 | dupErr vs = addErr $ TcRnListComprehensionDuplicateBinding (NE.head vs)
|
| 1420 | 1419 | |
| 1420 | +{- Note [Renaming parallel Stmts]
|
|
| 1421 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 1422 | +Renaming parallel statements is painful. Given, say
|
|
| 1423 | + [ a+c | a <- as, bs <- bss
|
|
| 1424 | + | c <- bs, a <- ds ]
|
|
| 1425 | +Note that
|
|
| 1426 | + (a) In order to report "Defined but not used" about 'bs', we must
|
|
| 1427 | + rename each group of Stmts with a thing_inside whose FreeVars
|
|
| 1428 | + include at least {a,c}
|
|
| 1429 | + |
|
| 1430 | + (b) We want to report that 'a' is illegally bound in both branches
|
|
| 1431 | + |
|
| 1432 | + (c) The 'bs' in the second group must obviously not be captured by
|
|
| 1433 | + the binding in the first group
|
|
| 1434 | + |
|
| 1435 | +To satisfy (a) we nest the segments.
|
|
| 1436 | +To satisfy (b) we check for duplicates just before thing_inside.
|
|
| 1437 | +To satisfy (c) we reset the LocalRdrEnv each time.
|
|
| 1438 | +-}
|
|
| 1439 | + |
|
| 1440 | +{- *********************************************************************
|
|
| 1441 | +* *
|
|
| 1442 | + Lookups for known-key names
|
|
| 1443 | +* *
|
|
| 1444 | +********************************************************************* -}
|
|
| 1445 | + |
|
| 1446 | +{- Note [QualifiedDo]
|
|
| 1447 | +~~~~~~~~~~~~~~~~~~~~~
|
|
| 1448 | +QualifiedDo is implemented using the same placeholders for operation names in
|
|
| 1449 | +the AST that were devised for RebindableSyntax. Whenever the renamer checks
|
|
| 1450 | +which names to use for do syntax, it first checks if the do block is qualified
|
|
| 1451 | +(e.g. M.do { stmts }), in which case it searches for qualified names. If the
|
|
| 1452 | +qualified names are not in scope, an error is produced. If the do block is not
|
|
| 1453 | +qualified, the renamer does the usual search of the names which considers
|
|
| 1454 | +whether RebindableSyntax is enabled or not. Dealing with QualifiedDo is driven
|
|
| 1455 | +by the Opt_QualifiedDo dynamic flag.
|
|
| 1456 | +-}
|
|
| 1457 | + |
|
| 1421 | 1458 | lookupQualifiedDoStmtName :: HasDebugCallStack => HsStmtContextRn
|
| 1422 | 1459 | -> KnownKeyNameKey -> RnM (SyntaxExpr GhcRn, FreeVars)
|
| 1423 | 1460 | lookupQualifiedDoStmtName ctxt n
|
| ... | ... | @@ -1435,13 +1472,19 @@ lookupQualifiedDoStmtName ctxt n |
| 1435 | 1472 | lookupQualifiedDoStmtNameE :: HasDebugCallStack => HsStmtContextRn
|
| 1436 | 1473 | -> KnownKeyNameKey -> RnM (HsExpr GhcRn, FreeVars)
|
| 1437 | 1474 | lookupQualifiedDoStmtNameE ctxt key
|
| 1438 | - -- Respect QualifiedDo
|
|
| 1439 | - | Just mod_name <- qualifiedDoModuleName_maybe ctxt
|
|
| 1440 | - = do { (nm, fvs) <- lookupNameWithQualifier key mod_name
|
|
| 1475 | + = do { (nm, fvs) <- lookupQualifiedDoStmtNameN ctxt key
|
|
| 1441 | 1476 | ; return (genHsVar nm, fvs) }
|
| 1442 | 1477 | |
| 1478 | +lookupQualifiedDoStmtNameN :: HasDebugCallStack => HsStmtContextRn
|
|
| 1479 | + -> KnownKeyNameKey -> RnM (Name, FreeVars)
|
|
| 1480 | +lookupQualifiedDoStmtNameN ctxt key
|
|
| 1481 | + -- Respect QualifiedDo; see Note [QualifiedDo]
|
|
| 1482 | + | Just mod_name <- qualifiedDoModuleName_maybe ctxt
|
|
| 1483 | + = do { (nm, fvs) <- lookupNameWithQualifier mod_name key
|
|
| 1484 | + ; return (nm, fvs) }
|
|
| 1485 | + |
|
| 1443 | 1486 | | otherwise -- Respect -XRebindableSyntax
|
| 1444 | - = lookupSyntaxExpr key
|
|
| 1487 | + = lookupSyntaxName key
|
|
| 1445 | 1488 | |
| 1446 | 1489 | -- | Is this a context where we respect RebindableSyntax?
|
| 1447 | 1490 | -- but ListComp are never rebindable
|
| ... | ... | @@ -1463,25 +1506,6 @@ rebindableDoStmtContext flavour = case flavour of |
| 1463 | 1506 | GhciStmtCtxt -> True -- I suppose?
|
| 1464 | 1507 | |
| 1465 | 1508 | {-
|
| 1466 | -Note [Renaming parallel Stmts]
|
|
| 1467 | -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 1468 | -Renaming parallel statements is painful. Given, say
|
|
| 1469 | - [ a+c | a <- as, bs <- bss
|
|
| 1470 | - | c <- bs, a <- ds ]
|
|
| 1471 | -Note that
|
|
| 1472 | - (a) In order to report "Defined but not used" about 'bs', we must
|
|
| 1473 | - rename each group of Stmts with a thing_inside whose FreeVars
|
|
| 1474 | - include at least {a,c}
|
|
| 1475 | - |
|
| 1476 | - (b) We want to report that 'a' is illegally bound in both branches
|
|
| 1477 | - |
|
| 1478 | - (c) The 'bs' in the second group must obviously not be captured by
|
|
| 1479 | - the binding in the first group
|
|
| 1480 | - |
|
| 1481 | -To satisfy (a) we nest the segments.
|
|
| 1482 | -To satisfy (b) we check for duplicates just before thing_inside.
|
|
| 1483 | -To satisfy (c) we reset the LocalRdrEnv each time.
|
|
| 1484 | - |
|
| 1485 | 1509 | ************************************************************************
|
| 1486 | 1510 | * *
|
| 1487 | 1511 | \subsubsection{mdo expressions}
|
| ... | ... | @@ -1612,19 +1636,19 @@ rn_rec_stmt :: AnnoBody body => |
| 1612 | 1636 | -- Turns each stmt into a singleton Stmt
|
| 1613 | 1637 | rn_rec_stmt ctxt rnBody _ (L loc (LastStmt _ (L lb body) noret _), _)
|
| 1614 | 1638 | = do { (body', fv_expr) <- rnBody body
|
| 1615 | - ; (ret_op, fvs1) <- lookupQualifiedDo ctxt returnMClassOpKey
|
|
| 1639 | + ; (ret_op, fvs1) <- lookupQualifiedDoStmtName ctxt returnMClassOpKey
|
|
| 1616 | 1640 | ; return [(emptyNameSet, fv_expr `plusFV` fvs1, emptyNameSet,
|
| 1617 | 1641 | L loc (LastStmt noExtField (L lb body') noret ret_op))] }
|
| 1618 | 1642 | |
| 1619 | 1643 | rn_rec_stmt ctxt rnBody _ (L loc (BodyStmt _ (L lb body) _ _), _)
|
| 1620 | 1644 | = do { (body', fvs) <- rnBody body
|
| 1621 | - ; (then_op, fvs1) <- lookupQualifiedDo ctxt thenMClassOpKey
|
|
| 1645 | + ; (then_op, fvs1) <- lookupQualifiedDoStmtName ctxt thenMClassOpKey
|
|
| 1622 | 1646 | ; return [(emptyNameSet, fvs `plusFV` fvs1, emptyNameSet,
|
| 1623 | 1647 | L loc (BodyStmt noExtField (L lb body') then_op noSyntaxExpr))] }
|
| 1624 | 1648 | |
| 1625 | 1649 | rn_rec_stmt ctxt rnBody _ (L loc (BindStmt _ pat' (L lb body)), fv_pat)
|
| 1626 | 1650 | = do { (body', fv_expr) <- rnBody body
|
| 1627 | - ; (bind_op, fvs1) <- lookupQualifiedDo ctxt bindMClassOpKey
|
|
| 1651 | + ; (bind_op, fvs1) <- lookupQualifiedDoStmtName ctxt bindMClassOpKey
|
|
| 1628 | 1652 | |
| 1629 | 1653 | ; (fail_op, fvs2) <- getMonadFailOp ctxt
|
| 1630 | 1654 | |
| ... | ... | @@ -2032,8 +2056,8 @@ rearrangeForApplicativeDo _ [] = return ([], emptyNameSet) |
| 2032 | 2056 | -- If the do-block contains a single @return@ statement, change it to
|
| 2033 | 2057 | -- @pure@ if ApplicativeDo is turned on. See Note [ApplicativeDo].
|
| 2034 | 2058 | rearrangeForApplicativeDo ctxt [(one,_)] = do
|
| 2035 | - (return_name, _) <- lookupQualifiedDoName (HsDoStmt ctxt) returnMClassOpKey
|
|
| 2036 | - (pure_name, _) <- lookupQualifiedDoName (HsDoStmt ctxt) pureAClassOpKey
|
|
| 2059 | + (return_name, _) <- lookupQualifiedDoStmtNameN (HsDoStmt ctxt) returnMClassOpKey
|
|
| 2060 | + (pure_name, _) <- lookupQualifiedDoStmtNameN (HsDoStmt ctxt) pureAClassOpKey
|
|
| 2037 | 2061 | let monad_names = MonadNames { return_name = return_name
|
| 2038 | 2062 | , pure_name = pure_name }
|
| 2039 | 2063 | return $ case needJoin monad_names [one] (Just pure_name) of
|
| ... | ... | @@ -2044,8 +2068,8 @@ rearrangeForApplicativeDo ctxt stmts0 = do |
| 2044 | 2068 | let stmt_tree | optimal_ado = mkStmtTreeOptimal stmts
|
| 2045 | 2069 | | otherwise = mkStmtTreeHeuristic stmts
|
| 2046 | 2070 | traceRn "rearrangeForADo" (ppr stmt_tree)
|
| 2047 | - (return_name, _) <- lookupQualifiedDoName (HsDoStmt ctxt) returnMClassOpKey
|
|
| 2048 | - (pure_name, _) <- lookupQualifiedDoName (HsDoStmt ctxt) pureAClassOpKey
|
|
| 2071 | + (return_name, _) <- lookupQualifiedDoStmtNameN (HsDoStmt ctxt) returnMClassOpKey
|
|
| 2072 | + (pure_name, _) <- lookupQualifiedDoStmtNameN (HsDoStmt ctxt) pureAClassOpKey
|
|
| 2049 | 2073 | let monad_names = MonadNames { return_name = return_name
|
| 2050 | 2074 | , pure_name = pure_name }
|
| 2051 | 2075 | stmtTreeToStmts monad_names ctxt stmt_tree [last] last_fvs
|
| ... | ... | @@ -2199,7 +2223,7 @@ stmtTreeToStmts monad_names ctxt (StmtTreeOne (L _ (BodyStmt _ rhs _ _),_)) |
| 2199 | 2223 | }] False tail'
|
| 2200 | 2224 | stmtTreeToStmts monad_names ctxt (StmtTreeOne (let_stmt@(L _ LetStmt{}),_))
|
| 2201 | 2225 | tail _tail_fvs = do
|
| 2202 | - (pure_name, _) <- lookupQualifiedDoName (HsDoStmt ctxt) pureAClassOpKey
|
|
| 2226 | + (pure_name, _) <- lookupQualifiedDoStmtNameN (HsDoStmt ctxt) pureAClassOpKey
|
|
| 2203 | 2227 | return $ case needJoin monad_names tail (Just pure_name) of
|
| 2204 | 2228 | (False, tail') -> (let_stmt : tail', emptyNameSet)
|
| 2205 | 2229 | (True, _) -> (let_stmt : tail, emptyNameSet)
|
| ... | ... | @@ -2258,7 +2282,7 @@ stmtTreeToStmts monad_names ctxt (StmtTreeApplicative trees) tail tail_fvs = do |
| 2258 | 2282 | | otherwise -> do
|
| 2259 | 2283 | -- Need 'pureAClassOpKey' and not 'returnMClassOpKey' here, so that it requires
|
| 2260 | 2284 | -- 'Applicative' and not 'Monad' whenever possible (until #20540 is fixed).
|
| 2261 | - (pure_name, _) <- lookupQualifiedDoName (HsDoStmt ctxt) pureAClassOpKey
|
|
| 2285 | + (pure_name, _) <- lookupQualifiedDoStmtNameN (HsDoStmt ctxt) pureAClassOpKey
|
|
| 2262 | 2286 | let expr = HsApp noExtField (noLocA (genHsVar pure_name)) tup
|
| 2263 | 2287 | return (expr, emptyFVs)
|
| 2264 | 2288 | return ( ApplicativeArgMany
|
| ... | ... | @@ -2784,7 +2808,7 @@ using fromString: |
| 2784 | 2808 | Nothing -> M.fail (fromString "Pattern match error")
|
| 2785 | 2809 | |
| 2786 | 2810 | -}
|
| 2787 | -getMonadFailOp :: HsStmtContext fn -> RnM (FailOperator GhcRn, FreeVars) -- Syntax expr fail op
|
|
| 2811 | +getMonadFailOp :: HsStmtContextRn -> RnM (FailOperator GhcRn, FreeVars) -- Syntax expr fail op
|
|
| 2788 | 2812 | getMonadFailOp ctxt
|
| 2789 | 2813 | = do { xOverloadedStrings <- fmap (xopt LangExt.OverloadedStrings) getDynFlags
|
| 2790 | 2814 | ; xRebindableSyntax <- fmap (xopt LangExt.RebindableSyntax) getDynFlags
|
| ... | ... | @@ -2796,7 +2820,7 @@ getMonadFailOp ctxt |
| 2796 | 2820 | |
| 2797 | 2821 | reallyGetMonadFailOp rebindableSyntax overloadedStrings
|
| 2798 | 2822 | | (isQualifiedDo || rebindableSyntax) && overloadedStrings = do
|
| 2799 | - (failName, failFvs) <- lookupQualifiedDoName ctxt failMClassOpKey
|
|
| 2823 | + (failName, failFvs) <- lookupQualifiedDoStmtNameN ctxt failMClassOpKey
|
|
| 2800 | 2824 | (fromStringExpr, fromStringFvs) <- lookupSyntaxExpr fromStringClassOpKey
|
| 2801 | 2825 | let arg_lit = mkVarOccFS (fsLit "arg")
|
| 2802 | 2826 | arg_name <- newSysName arg_lit
|
| ... | ... | @@ -2809,7 +2833,7 @@ getMonadFailOp ctxt |
| 2809 | 2833 | let failAfterFromStringSynExpr :: SyntaxExpr GhcRn =
|
| 2810 | 2834 | mkSyntaxExpr failAfterFromStringExpr
|
| 2811 | 2835 | return (failAfterFromStringSynExpr, failFvs `plusFV` fromStringFvs)
|
| 2812 | - | otherwise = lookupQualifiedDo ctxt failMClassOpKey
|
|
| 2836 | + | otherwise = lookupQualifiedDoStmtName ctxt failMClassOpKey
|
|
| 2813 | 2837 | |
| 2814 | 2838 | |
| 2815 | 2839 | {- *********************************************************************
|
| ... | ... | @@ -18,7 +18,7 @@ rnQualLit QualLit{..} = do |
| 18 | 18 | case ql_val of
|
| 19 | 19 | -- See Note [Implementation of QualifiedStrings]
|
| 20 | 20 | HsQualString st s -> (fromStringClassOpKey, HsString st s)
|
| 21 | - (funName, fvs) <- lookupNameWithQualifier funNameBase ql_mod
|
|
| 21 | + (funName, fvs) <- lookupNameWithQualifier ql_mod funNameBase
|
|
| 22 | 22 | let lit = QualLit{ql_ext = L noAnn funName, ..}
|
| 23 | 23 | let expr = genHsApps funName [genLHsLit hsLit]
|
| 24 | 24 | pure ((lit, expr), fvs) |
| ... | ... | @@ -1982,7 +1982,10 @@ findImportUsage rebindable_known_key_names imports used_gres |
| 1982 | 1982 | |
| 1983 | 1983 | unused_decl :: LImportDecl GhcRn -> ImportDeclUsage
|
| 1984 | 1984 | unused_decl decl@(L _ (ImportDecl { ideclImportList = imps }))
|
| 1985 | - = (decl, used_gres, unused_names, unused_wcs)
|
|
| 1985 | + = -- pprTrace "unused_decl" (vcat [ ppr decl
|
|
| 1986 | + -- , text "used" <+> ppr used_gres
|
|
| 1987 | + -- , text "unused" <+> ppr unused_names ]) $
|
|
| 1988 | + (decl, used_gres, unused_names, unused_wcs)
|
|
| 1986 | 1989 | where
|
| 1987 | 1990 | used_gres = lookupImportMap decl import_usage
|
| 1988 | 1991 | |
| ... | ... | @@ -2021,6 +2024,7 @@ findImportUsage rebindable_known_key_names imports used_gres |
| 2021 | 2024 | (flds, flds_used) = lookupFsEnv acc_fs fs `orElse` (emptyNameSet, Any False)
|
| 2022 | 2025 | acc_fs' = extendFsEnv acc_fs fs (extendNameSet flds n, Any used S.<> flds_used)
|
| 2023 | 2026 | in UnusedNames acc_ns acc_wcs acc_fs'
|
| 2027 | + |
|
| 2024 | 2028 | | used
|
| 2025 | 2029 | = acc
|
| 2026 | 2030 |
| ... | ... | @@ -68,7 +68,6 @@ import GHC.Types.SourceText |
| 68 | 68 | import GHC.Data.FastString ( uniqCompareFS )
|
| 69 | 69 | import GHC.Data.List.SetOps( removeDups )
|
| 70 | 70 | |
| 71 | -import GHC.Utils.Outputable
|
|
| 72 | 71 | import GHC.Utils.Misc
|
| 73 | 72 | import GHC.Utils.Panic.Plain
|
| 74 | 73 | import GHC.Types.SrcLoc
|
| ... | ... | @@ -511,13 +511,17 @@ getKnownKeySource :: TcRn KnownKeyNameSource |
| 511 | 511 | getKnownKeySource
|
| 512 | 512 | = do { rebindable_path <- goptM Opt_RebindableKnownKeyNames
|
| 513 | 513 | ; if rebindable_path
|
| 514 | - then KKNS_InScope <$> getGlobalRdrEnv
|
|
| 514 | + then do { rdr_env <- getGlobalRdrEnv
|
|
| 515 | + ; return (KKNS_InScope rdr_env) }
|
|
| 515 | 516 | else return KKNS_FromModule }
|
| 516 | 517 | |
| 517 | 518 | rnLookupKnownKeyName :: HasDebugCallStack => KnownKeyNameKey -> RnM Name
|
| 518 | 519 | rnLookupKnownKeyName uniq
|
| 519 | 520 | = do { kk_source <- getKnownKeySource
|
| 520 | - ; initIfaceTcRn (lookupKnownKeyName kk_source uniq) }
|
|
| 521 | + ; mb_res <- initIfaceTcRn (lookupKnownKeyName kk_source uniq)
|
|
| 522 | + ; case mb_res of
|
|
| 523 | + Failed err -> failWithTc (TcRnInterfaceError err)
|
|
| 524 | + Succeeded name -> return name }
|
|
| 521 | 525 | |
| 522 | 526 | rnLookupKnownKeyRdr :: HasDebugCallStack => KnownKeyNameKey -> RnM RdrName
|
| 523 | 527 | rnLookupKnownKeyRdr uniq
|
| ... | ... | @@ -885,6 +885,9 @@ type family GhcDiagnosticCode c = n | n -> c where |
| 885 | 885 | GhcDiagnosticCode "CircularImport" = 75429
|
| 886 | 886 | GhcDiagnosticCode "HiModuleNameMismatchWarn" = 53693
|
| 887 | 887 | GhcDiagnosticCode "ExceptionOccurred" = 47808
|
| 888 | + GhcDiagnosticCode "MissingKnownKey1" = 74926
|
|
| 889 | + GhcDiagnosticCode "MissingKnownKey2" = 71344
|
|
| 890 | + GhcDiagnosticCode "KnownKeyScopeError" = 99040
|
|
| 888 | 891 | |
| 889 | 892 | -- Out of scope errors
|
| 890 | 893 | GhcDiagnosticCode "NotInScope" = 76037
|
| ... | ... | @@ -41,7 +41,7 @@ module GHC.Types.Name ( |
| 41 | 41 | -- * The main types
|
| 42 | 42 | Name, -- Abstract
|
| 43 | 43 | BuiltInSyntax(..),
|
| 44 | - KnownKeyNameKey, KnownKeyNameMap, hasKnownKey,
|
|
| 44 | + KnownKeyNameKey, KnownKeyNameMap, hasKnownKey, pprKnownKey,
|
|
| 45 | 45 | |
| 46 | 46 | -- ** Creating 'Name's
|
| 47 | 47 | mkSystemName, mkSystemNameAt,
|
| ... | ... | @@ -441,6 +441,12 @@ mk_known_key_name :: NameSpace -> Module -> FastString -> KnownKeyNameKey -> Nam |
| 441 | 441 | mk_known_key_name space modu str unique
|
| 442 | 442 | = mkExternalName unique modu (mkOccNameFS space str) noSrcSpan
|
| 443 | 443 | |
| 444 | +pprKnownKey :: KnownKeyNameKey -> SDoc
|
|
| 445 | +-- Show it in both base64 and decimal, for debugging
|
|
| 446 | +pprKnownKey uniq
|
|
| 447 | + = ppr uniq <+> braces (text (show tag) <+> ppr u)
|
|
| 448 | + where
|
|
| 449 | + (tag, u) = unpkUnique uniq
|
|
| 444 | 450 | |
| 445 | 451 | |
| 446 | 452 | {- *********************************************************************
|
| ... | ... | @@ -63,6 +63,8 @@ import GHC.Internal.Prim.PtrEq (sameMutableArray#) |
| 63 | 63 | import GHC.Internal.Show
|
| 64 | 64 | import GHC.Internal.Types (Bool, Int(..), Ordering(..), isTrue#)
|
| 65 | 65 | |
| 66 | +import GHC.Internal.Base( (>>=) ) -- For known-key names
|
|
| 67 | + |
|
| 66 | 68 | infixl 9 !, //
|
| 67 | 69 | |
| 68 | 70 | default ()
|
| ... | ... | @@ -28,6 +28,7 @@ import GHC.Internal.Base ((.), (=<<)) |
| 28 | 28 | import GHC.Internal.Prim (seq)
|
| 29 | 29 | import GHC.Internal.ST
|
| 30 | 30 | import GHC.Internal.STRef
|
| 31 | +import GHC.Internal.Base( Monad(..) ) -- Used for known-key names
|
|
| 31 | 32 | |
| 32 | 33 | -- $setup
|
| 33 | 34 | -- >>> import Prelude
|
| ... | ... | @@ -41,6 +41,8 @@ import GHC.Internal.TypeLits.Internal |
| 41 | 41 | import GHC.Internal.TypeNats.Internal
|
| 42 | 42 | import GHC.Internal.Types (Bool(..), Char, Ordering(..), type (~))
|
| 43 | 43 | |
| 44 | +import GHC.Internal.Classes ( (==) ) -- For known-key names in deriving(Eq)
|
|
| 45 | + |
|
| 44 | 46 | -- | 'Compare' branches on the kind of its arguments to either compare by
|
| 45 | 47 | -- 'Symbol' or 'Nat'.
|
| 46 | 48 | --
|
| ... | ... | @@ -9,13 +9,16 @@ module GHC.Internal.Event.IntVar |
| 9 | 9 | , writeIntVar
|
| 10 | 10 | ) where
|
| 11 | 11 | |
| 12 | -import GHC.Internal.Base (return, ($))
|
|
| 12 | +import GHC.Internal.Base ( ($) )
|
|
| 13 | 13 | import GHC.Internal.Bits
|
| 14 | 14 | import GHC.Internal.Prim (
|
| 15 | 15 | MutableByteArray#, RealWorld, newByteArray#, readIntArray#, writeIntArray#,
|
| 16 | 16 | )
|
| 17 | 17 | import GHC.Internal.Types (Int(..), IO(..))
|
| 18 | 18 | |
| 19 | +import GHC.Internal.Num( fromInteger ) -- For known-key names
|
|
| 20 | +import GHC.Internal.Base( Monad(..) ) -- For known-key names
|
|
| 21 | + |
|
| 19 | 22 | data IntVar = IntVar (MutableByteArray# RealWorld)
|
| 20 | 23 | |
| 21 | 24 | newIntVar :: Int -> IO IntVar
|
| ... | ... | @@ -19,6 +19,8 @@ import GHC.Internal.Prim ( |
| 19 | 19 | )
|
| 20 | 20 | import GHC.Internal.Types(Int(..), IO(..))
|
| 21 | 21 | |
| 22 | +import GHC.Internal.Num( fromInteger ) -- For known-key names
|
|
| 23 | + |
|
| 22 | 24 | #include "MachDeps.h"
|
| 23 | 25 | |
| 24 | 26 | data UniqueSource = US (MutableByteArray# RealWorld)
|
| ... | ... | @@ -73,6 +73,8 @@ import GHC.Internal.Prim ( |
| 73 | 73 | )
|
| 74 | 74 | import GHC.Internal.Types (Double(..), Float(..), Int(..), isTrue#)
|
| 75 | 75 | |
| 76 | +import GHC.Internal.Num( fromInteger, negate ) -- For known-key names
|
|
| 77 | + |
|
| 76 | 78 | #if WORD_SIZE_IN_BITS < 64
|
| 77 | 79 | |
| 78 | 80 | import GHC.Internal.Prim (
|
| ... | ... | @@ -48,6 +48,8 @@ import GHC.Internal.Prim ( |
| 48 | 48 | )
|
| 49 | 49 | import GHC.Internal.Types (Int(..), Word(..))
|
| 50 | 50 | |
| 51 | +import GHC.Internal.Classes ( (==) ) -- Needed for know-key names
|
|
| 52 | + |
|
| 51 | 53 | infixl 7 *
|
| 52 | 54 | infixl 6 +, -
|
| 53 | 55 |
| ... | ... | @@ -32,6 +32,8 @@ import GHC.Internal.Magic (runRW#) |
| 32 | 32 | import GHC.Internal.Prim (State#, noDuplicate#)
|
| 33 | 33 | import GHC.Internal.Show
|
| 34 | 34 | |
| 35 | +import GHC.Internal.Num( fromInteger ) -- For known-key names
|
|
| 36 | + |
|
| 35 | 37 | default ()
|
| 36 | 38 | |
| 37 | 39 | -- The 'ST' monad proper. By default the monad is strict;
|