[Git][ghc/ghc][wip/fabu/T25014-mistakenly-accepted-parent] Apply 12 suggestion(s) to 2 file(s)
Fabricio Nascimento (@fabu)
gitlab at gitlab.haskell.org
Mon Jul 29 10:23:48 UTC 2024
Fabricio Nascimento pushed to branch wip/fabu/T25014-mistakenly-accepted-parent at Glasgow Haskell Compiler / GHC
Commits:
d6590865 by Fabricio Nascimento at 2024-07-29T10:23:44+00:00
Apply 12 suggestion(s) to 2 file(s)
Co-authored-by: sheaf <sam.derbyshire at gmail.com>
- - - - -
2 changed files:
- compiler/GHC/Rename/Env.hs
- compiler/GHC/Tc/Gen/Export.hs
Changes:
=====================================
compiler/GHC/Rename/Env.hs
=====================================
@@ -691,7 +691,7 @@ parent than it was declared, for example PatternSynonyms (see [Typing Pattern
Synonym Exports]).
Another difference is in the presence of ambiguous names. Because we are strict
-on the parent, we won't report a name clash in the example bellow (see #24452),
+on the parent, we won't report a name clash in the example below (see #24452),
as it would lead to a confusing error.
module Ambiguous where
@@ -734,7 +734,6 @@ lookupInstanceDeclarationSubBndr warn_if_deprec parent doc rdr_name =
return $ Left (UnknownSubordinate doc)
AmbiguousOccurrence _ ->
return $ Left (UnknownSubordinate doc)
-{-# INLINEABLE lookupInstanceDeclarationSubBndr #-}
-- For details, see Note [Renaming children on export lists]
lookupChildExportListSubBndr :: DeprecationWarnings
@@ -760,7 +759,6 @@ lookupChildExportListSubBndr warn_if_deprec parent rdr_name lookup_method = do
success_found_child warn_if_deprec g = do
addUsedGRE warn_if_deprec g
return $ FoundChild g
-{-# INLINEABLE lookupChildExportListSubBndr #-}
{- Note [Picking and disambiguating children candidates]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -781,7 +779,7 @@ parent matches can cause #25014.
import Ambig2 (T(MkT))
Even when we don't find matching parents, we need to consider matching names
-without a parent, for example for pattern synonyms bellow.
+without a parent, for example for pattern synonyms below.
module M (Maybe (Empty)) where
class Empty a where
@@ -813,16 +811,17 @@ pick_matching_gres parent rdr_name lookup_method = do
traceTc "pick_matching_gres original_gres:" (ppr original_gres)
return (picked_gres, original_gres)
where
+ See Note [Renaming child GREs] for what's happening here
pick_gres :: [GlobalRdrElt] -> DisambigInfo
pick_gres gres
- | length matching_parent_gres == 1 =
- MatchingParentOccurrence (head matching_parent_gres)
+ | [gre] <- matching_parent_gres =
+ MatchingParentOccurrence gre
| length no_parent_gres == 1 =
NoParentOccurrence (head no_parent_gres)
| null no_parent_gres && null matching_parent_gres =
NoOccurrence
- | not $ null matching_parent_gres =
- AmbiguousOccurrence (NE.fromList matching_parent_gres)
+ | gre:gres <- matching_parent_gres =
+ AmbiguousOccurrence (gre NE.:| gres)
| otherwise =
-- no_parent_gres won't be empty due to the conditions above
AmbiguousOccurrence (NE.fromList no_parent_gres)
@@ -853,7 +852,7 @@ When GHC does not find a matching name on GREs after disambiguation
`Not in scope: ...` (NoOccurence). In some cases we can offer a better error
by looking at the original GRE matches before disambiguation and attempt to
surface problems that could have caused ghc to not being able to find the
-correct identifier.
+correct identifier. This is what error_no_occurrence_after_disambiguation does.
1. For example where the name exists for a different parent.
@@ -907,10 +906,10 @@ error_incorrect_parent parent gres = return $ IncorrectParent parent (NE.head gr
{- Note [Disambiguating GREs by parent]
-
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Names can occur on GRE with or without Parent. When renaming an identifier
for example the `foo` on export `A (foo)` on the export list of the program
-bellow, we have the following types of matches:
+below, we have the following types of matches:
{-# LANGUAGE DuplicateRecordFields #-}
module Matches (A (foo, Pat, bar)) where
=====================================
compiler/GHC/Tc/Gen/Export.hs
=====================================
@@ -691,7 +691,7 @@ in a children export list under a parent.
pattern Px{x} <- Point x _
-To makes matter more complicate.
+To makes matter more complicated:
1. Some type constructors are parsed as variables (-.->) for example.
2. All data constructors are parsed as type constructors
3. When there is ambiguity, we default type constructors to data
@@ -700,10 +700,12 @@ constructors.
4. Pattern synonyms are very flexible in which parents they can be exported with
(see [Typing Pattern Synonym Exports]).
-The strategy for renaming, is to first establish all the possible namespaces
-that an identifier might be in, then for each namespace in turn,
-tries to find the correct identifier there returning the
-first positive result or the first terminating error.
+We proceed in two steps:
+
+ 1. We look up GREs, handling the possible NameSpaces to look up in.
+ See Note [Configurable GRE lookup priority].
+ 2. We refine by using the GRE parent information.
+ See Note [Renaming child GREs].
For more details see
[Renaming the LHS on type class Instances],
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d6590865e8ef662c029393a9b2ab5412576877d9
--
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/d6590865e8ef662c029393a9b2ab5412576877d9
You're receiving this email because of your account on gitlab.haskell.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240729/ca721aaf/attachment-0001.html>
More information about the ghc-commits
mailing list