[Git][ghc/ghc][wip/jade/ast] notes updated

Hassan Al-Awwadi (@hassan.awwadi) gitlab at gitlab.haskell.org
Tue Oct 1 14:16:34 UTC 2024



Hassan Al-Awwadi pushed to branch wip/jade/ast at Glasgow Haskell Compiler / GHC


Commits:
e6cc1d4d by Hassan Al-Awwadi at 2024-10-01T16:16:01+02:00
notes updated

- - - - -


1 changed file:

- compiler/GHC/Hs/Type.hs


Changes:

=====================================
compiler/GHC/Hs/Type.hs
=====================================
@@ -1088,32 +1088,47 @@ also forbids them in types involved with `deriving`:
 *                                                                      *
 ************************************************************************
 
-Note [Lifecycle of a FieldOcc]
+Note [Lifecycle of an UpdFieldOcc]
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-A field occurrence (FieldOcc) has a slightly special lifecycle because field
-occurrences may be deemed /ambiguous/ during renaming. Ambiguous field
-occurrences can only be resolved during typechecking (since we do type-directed
-disambiguation). To accommodate the fact that we may be unable to produce a
-`Name` for a `FieldOcc` during renaming, `FieldOcc` is extended with
-`AmbiguousFieldOcc` during renaming. Here's the life cycle:
-
-* The `FieldOcc` constructor of the `FieldOcc` type always refers to an
-  unambiguous field occurrence. We parse field occurrences into `FieldOcc`.
-
-* During renaming, a FieldOcc may be ambiguous and only be resolvable
-  during typechecking. To construct an /ambiguous/ `FieldOcc GhcRn`, we use the
-  extension point for constructors, which is instanced with `AmbiguousFieldOcc`:
-
-    (XFieldOcc . Ambiguous) :: FieldOcc GhcRn
-
-* During typechecking, all ambiguous field occurrences must be resolved. We
-  statically guarantee this by making it impossible to construct a `FieldOcc
-  GhcTc` with an ambiguous name:
-
-    type instance XXFieldOcc GhcTc = DataConCantHappen
-
-Note that throughout this lifecycle, we preserve the `RdrName` the user
-originally wrote in the extension point during renaming and typechecking.
+When we have an update to a field occurrence (UpdFieldOcc) of the form
+rec{ label = value }, its possible that what label refers to is ambiguous,
+aka: that there are multiple record types with label as a field. In this case
+we can't go from a RdrName in the GhcPs stage to a Name in the GhcRn stage,
+because we have multiple Names we could choose from. Once we typecheck, we
+also do type-directed disambiguation, so at that stage we can go directly from
+a Name to an Id, modulo the disambiguation succeeding.
+
+To account for this the UpdFieldOcc occurrence has an instantiation for its
+XXUpdFieldOcc type family: AmbiguousFieldOcc. AmbiguousFieldOcc just stores
+the RdrName directly, whereas the FieldOcc (GhcPass p) field will go from
+RdrName to Name to Id as the stage shifts. Note that FieldOcc also stores
+the RdrName throughout its lifecycle, for exact printing purpose, after the
+Parse stage this RdrName just shifts from the foLabel field to the foExt field.
+
+Summarised the lifecycle of a FieldOcc is like this:
+* GhcPs: FieldOcc noExtField RdrName
+* GhcRn: FieldOcc RdrName    Name
+* GhcTc: FieldOcc RdrName    Id
+
+With its extra constructor `XFieldOcc currently being unused and disabled by
+instantiation XXFieldOcc (GhcPass p) = DataConCantHappen. In most cases just
+having this FieldOcc datatype is enough, but as mentioned the UpdFieldOcc case
+requires a case for ambiguity.
+
+The lifecycle of an UpdFieldOcc is as follows
+* GhcPs:
+  * UpdFieldOcc noExtField (FieldOcc GhcPs)
+  * XUpdFieldOcc DataConCantHappen
+* GhcRn:
+  * UpdFieldOcc noExtField (FieldOCc GhcRn)
+  * XUpdFieldOcc AmbiguousFieldOcc
+* GhcTc:
+  * UpdFieldOcc noExtField (FieldOCc GhcRn)
+  * XUpdFieldOcc DataConCantHappen
+
+so using DataConCantHappen we statically guarantee that when we go to a
+UpdFieldOcc GhcRn to UpdFieldOcc GhcTc we either succesfully disambiguate or
+error when we can't.
 -}
 
 -- | Ambiguous Field Occurrence
@@ -1124,7 +1139,8 @@ originally wrote in the extension point during renaming and typechecking.
 -- originally wrote, and store the selector function after the typechecker (for
 -- ambiguous occurrences).
 --
--- Unambiguous field occurrences should be stored in the proper FieldOcc datacon of FieldOcc.
+-- Unambiguous field occurrences should be stored in the proper
+-- UpdFieldOcc datacon of UpdFieldOcc.
 --
 -- See Note [HsRecField and HsRecUpdField] in "GHC.Hs.Pat".
 -- See Note [Located RdrNames] in "GHC.Hs.Expr".



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e6cc1d4d231d81b46cdc77206e1a753f5fa6717f

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/e6cc1d4d231d81b46cdc77206e1a753f5fa6717f
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/20241001/11e829cd/attachment-0001.html>


More information about the ghc-commits mailing list