... | @@ -13,7 +13,7 @@ We now propose the following changes to the TH API in order to track these chang |
... | @@ -13,7 +13,7 @@ We now propose the following changes to the TH API in order to track these chang |
|
- [\#10279](https://gitlab.haskell.org//ghc/ghc/issues/10279): breakage caused by faking package keys
|
|
- [\#10279](https://gitlab.haskell.org//ghc/ghc/issues/10279): breakage caused by faking package keys
|
|
- [ Similar lens bug](https://github.com/ekmett/lens/issues/496)
|
|
- [ Similar lens bug](https://github.com/ekmett/lens/issues/496)
|
|
|
|
|
|
## Rename PkgName to PkgKey
|
|
## Rename PkgName to UnitId
|
|
|
|
|
|
|
|
|
|
Currently, a TH `NameG` contains a `PkgName`, defined as:
|
|
Currently, a TH `NameG` contains a `PkgName`, defined as:
|
... | @@ -23,12 +23,12 @@ newtype PkgName = PkgName String |
... | @@ -23,12 +23,12 @@ newtype PkgName = PkgName String |
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
This is badly misleading, even in the old world order, since these needed version numbers as well (except for wired-in packages, which are always just a bare package name). We propose that this be renamed to `PkgKey`:
|
|
This is badly misleading, even in the old world order, since these needed version numbers as well (except for wired-in packages, which are always just a bare package name). We propose that this be renamed to `UnitId`:
|
|
|
|
|
|
```wiki
|
|
```wiki
|
|
newtype PkgKey = PkgKey String
|
|
newtype UnitId = UnitId String
|
|
mkPackageKey :: String -> PackageKey
|
|
mkUnitId :: String -> UnitId
|
|
mkPackageKey = PkgKey
|
|
mkUnitId = UnitId
|
|
```
|
|
```
|
|
|
|
|
|
**Variation 1.** Keep the old `PkgName` type and constructor around for backwards compatibility. One reason **not** to do this is that the change from package name to package key was a semantic change, meaning that people who were faking keys by concatenating a name with a version had their code break. (On the other hand, by the end of the 7.10 cycle most people probably will be using the old name correctly.)
|
|
**Variation 1.** Keep the old `PkgName` type and constructor around for backwards compatibility. One reason **not** to do this is that the change from package name to package key was a semantic change, meaning that people who were faking keys by concatenating a name with a version had their code break. (On the other hand, by the end of the 7.10 cycle most people probably will be using the old name correctly.)
|
... | @@ -36,29 +36,29 @@ mkPackageKey = PkgKey |
... | @@ -36,29 +36,29 @@ mkPackageKey = PkgKey |
|
|
|
|
|
Here is the GitHub search for uses of `NameG`, which usually indicates a package key is being manipulated directly: [ https://github.com/search?l=haskell&q=NameG&type=Code&utf8=%E2%9C%93](https://github.com/search?l=haskell&q=NameG&type=Code&utf8=%E2%9C%93)
|
|
Here is the GitHub search for uses of `NameG`, which usually indicates a package key is being manipulated directly: [ https://github.com/search?l=haskell&q=NameG&type=Code&utf8=%E2%9C%93](https://github.com/search?l=haskell&q=NameG&type=Code&utf8=%E2%9C%93)
|
|
|
|
|
|
## Querying about packages
|
|
## Querying about units
|
|
|
|
|
|
|
|
|
|
Package keys are somewhat hard to synthesize, so we also offer an API for querying the package database of the GHC which is compiling your code for information about packages. So, we introduce a new abstract data type:
|
|
Unit IDs are somewhat hard to synthesize, so we also offer an API for querying the package database of the GHC which is compiling your code for information about packages. So, we introduce a new abstract data type:
|
|
|
|
|
|
```wiki
|
|
```wiki
|
|
data Package
|
|
data Unit
|
|
packageKey :: Package -> PkgKey
|
|
unitId :: Unit -> UnitId
|
|
packageVersionString :: Package -> String
|
|
unitVersionString :: Unit -> String
|
|
packageName :: Package -> String
|
|
unitPackageName :: Unit -> String
|
|
|
|
|
|
packageDependencies :: Package -> Q [Package]
|
|
unitDependencies :: Unit -> Q [Unit]
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
and some functions for getting packages:
|
|
and some functions for getting packages:
|
|
|
|
|
|
```wiki
|
|
```wiki
|
|
searchPackage :: String -- Package name
|
|
searchUnit :: String -- Package name
|
|
-> String -- Version
|
|
-> String -- Version
|
|
-> Q [Package]
|
|
-> Q [Unit]
|
|
|
|
|
|
reifyPackage :: PkgKey -> Q Package
|
|
reifyUnit :: UnitId -> Q Unit
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
... | @@ -81,18 +81,18 @@ Commonly, a user wants to get the package key of the current package. Following |
... | @@ -81,18 +81,18 @@ Commonly, a user wants to get the package key of the current package. Following |
|
We'll also add a function for accessing the module package key:
|
|
We'll also add a function for accessing the module package key:
|
|
|
|
|
|
```wiki
|
|
```wiki
|
|
modulePackageKey :: Module -> PkgKey
|
|
moduleUnitId :: Module -> UnitId
|
|
```
|
|
```
|
|
|
|
|
|
|
|
|
|
And a convenience function for accessing the current module:
|
|
And a convenience function for accessing the current module:
|
|
|
|
|
|
```wiki
|
|
```wiki
|
|
thisPackageKey :: Q PkgKey
|
|
thisUnitId :: Q UnitId
|
|
thisPackageKey = fmap (modulePackageKey . mi_this_mod) qReifyModule
|
|
thisUnitId = fmap (moduleUnitId . mi_this_mod) qReifyModule
|
|
|
|
|
|
thisPackage :: Q Package
|
|
thisPackage :: Q Unit
|
|
thisPackage = reifyPackage =<< thisPackageKey
|
|
thisPackage = reifyUnit =<< thisUnitId
|
|
```
|
|
```
|
|
|
|
|
|
**Variation 1.** The current package and module is accessible from `qLocation`. Should the types in the record that `qLocation` returns change? |
|
**Variation 1.** The current package and module is accessible from `qLocation`. Should the types in the record that `qLocation` returns change? |