Commit 5926b6ed authored by Ryan Scott's avatar Ryan Scott Committed by Ben Gamari

Don't expose (~#), (~R#), (~P#) from GHC.Prim

Currently, the primitive `(~#)`, `(~R#)`, and `(~P#)` type
constructors are wired in to be exported from `GHC.Prim`. This has
some unfortunate consequences, however. It turns out that `(~#)` is
actually a legal infix identifier, so users can make use of unboxed
equalities in strange ways in user code (see #15209). The other two,
`(~R#)` and `(~P#)`, can't be used in source code, but they can be
observed with GHCi's `:browse` command, which is somewhat unnerving.

The fix for both of these problems is simple: just don't wire them
to be exported from `GHC.Prim`.

Test Plan: make test TEST="T12023 T15209"

Reviewers: bgamari, dfeuer

Reviewed By: bgamari, dfeuer

Subscribers: rwbarton, thomie, carter, dfeuer

GHC Trac Issues: #12023, #15209

Differential Revision: https://phabricator.haskell.org/D4801
parent 04e29fc6
......@@ -252,7 +252,7 @@ ghcPrimExports
= map (avail . idName) ghcPrimIds ++
map (avail . idName . primOpId) allThePrimOps ++
[ AvailTC n [n] []
| tc <- funTyCon : primTyCons, let n = tyConName tc ]
| tc <- funTyCon : exposedPrimTyCons, let n = tyConName tc ]
{-
************************************************************************
......
......@@ -30,7 +30,7 @@ module TysPrim(
tYPE, primRepToRuntimeRep,
funTyCon, funTyConName,
primTyCons,
unexposedPrimTyCons, exposedPrimTyCons, primTyCons,
charPrimTyCon, charPrimTy, charPrimTyConName,
intPrimTyCon, intPrimTy, intPrimTyConName,
......@@ -118,7 +118,22 @@ import Data.Char
-}
primTyCons :: [TyCon]
primTyCons
primTyCons = unexposedPrimTyCons ++ exposedPrimTyCons
-- | Primitive 'TyCon's that are defined in "GHC.Prim" but not exposed.
-- It's important to keep these separate as we don't want users to be able to
-- write them (see Trac #15209) or see them in GHCi's @:browse@ output
-- (see Trac #12023).
unexposedPrimTyCons :: [TyCon]
unexposedPrimTyCons
= [ eqPrimTyCon
, eqReprPrimTyCon
, eqPhantPrimTyCon
]
-- | Primitive 'TyCon's that are defined in, and exported from, "GHC.Prim".
exposedPrimTyCons :: [TyCon]
exposedPrimTyCons
= [ addrPrimTyCon
, arrayPrimTyCon
, byteArrayPrimTyCon
......@@ -150,9 +165,6 @@ primTyCons
, wordPrimTyCon
, word32PrimTyCon
, word64PrimTyCon
, eqPrimTyCon
, eqReprPrimTyCon
, eqPhantPrimTyCon
, tYPETyCon
......
......@@ -61,3 +61,8 @@ T11389:
# (without -v0)
'$(TEST_HC)' $(filter-out -v0,$(TEST_HC_OPTS_INTERACTIVE)) \
-ghci-script T11389.script < /dev/null | grep 'configuration'
.PHONY: T12023
T12023:
-'$(TEST_HC)' $(TEST_HC_OPTS_INTERACTIVE) \
-ghci-script T12023.script < /dev/null | grep -c -E '(~#|~R#|~P#)'
......@@ -239,6 +239,8 @@ test('T12007', normal, ghci_script, ['T12007.script'])
test('T11975', normal, ghci_script, ['T11975.script'])
test('T10963', normal, ghci_script, ['T10963.script'])
test('T11721', normal, ghci_script, ['T11721.script'])
test('T12023', normal, run_command,
['$MAKE -s --no-print-directory T12023'])
test('T12520', normal, ghci_script, ['T12520.script'])
test('T12091', [extra_run_opts('-fobject-code')], ghci_script,
['T12091.script'])
......
{-# LANGUAGE GADTs, TypeOperators #-}
module T15209 where
import GHC.Prim
foo :: a ~# Int -> ()
foo = ()
T15209.hs:6:8: error: Not in scope: type constructor or class ‘~#’
......@@ -110,6 +110,7 @@ test('T13450', normal, compile_fail, [''])
test('T13450TH', normal, compile_fail, [''])
test('T14588', normal, compile_fail, [''])
test('T14740', normal, compile_fail, [''])
test('T15209', normal, compile_fail, [''])
test('NoNumericUnderscores0', normal, compile_fail, [''])
test('NoNumericUnderscores1', normal, compile_fail, [''])
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment