2 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
8 thinAirIdNames, -- Names of non-wired-in Ids that may be used out of
9 setThinAirIds, -- thin air in any compilation. If they are not wired in
10 -- we must be sure to import them from some Prelude
11 -- interface file even if they are not overtly
12 -- mentioned. Subset of builtinNames.
13 -- Here are the thin-air Ids themselves
15 packStringForCId, unpackCStringId, unpackCString2Id,
16 unpackCStringAppendId, unpackCStringFoldrId,
24 #include "HsVersions.h"
26 import Var ( Id, varUnique )
27 import Name ( mkKnownKeyGlobal, varName )
28 import RdrName ( mkPreludeQual )
30 import UniqFM ( UniqFM, listToUFM, lookupWithDefaultUFM )
37 %************************************************************************
39 \subsection{Thin air entities}
41 %************************************************************************
43 These are Ids that we need to reference in various parts of the
44 system, and we'd like to pull them out of thin air rather than pass
45 them around. We'd also like to have all the IdInfo available for each
46 one: i.e. everything that gets pulled out of the interface file.
48 The solution is to generate this map of global Ids after the
49 typechecker, and assign it to a global variable. Any subsequent
50 pass may refer to the map to pull Ids out. Any invalid
51 (i.e. pre-typechecker) access to the map will result in a panic.
55 = map mkKnownKeyGlobal
57 -- Needed for converting literals to Integers (used in tidyCoreExpr)
58 (varQual pREL_NUM_Name SLIT("addr2Integer"), addr2IntegerIdKey)
61 , (varQual pREL_PACK_Name SLIT("packCString#"), packCStringIdKey)
62 , (varQual pREL_PACK_Name SLIT("unpackCString#"), unpackCStringIdKey)
63 , (varQual pREL_PACK_Name SLIT("unpackNBytes#"), unpackCString2IdKey)
64 , (varQual pREL_PACK_Name SLIT("unpackAppendCString#"), unpackCStringAppendIdKey)
65 , (varQual pREL_PACK_Name SLIT("unpackFoldrCString#"), unpackCStringFoldrIdKey)
67 -- Folds and builds; introduced by desugaring list comprehensions
68 , (varQual pREL_BASE_Name SLIT("foldr"), foldrIdKey)
69 , (varQual pREL_BASE_Name SLIT("build"), buildIdKey)
72 varQual = mkPreludeQual varName
77 noRepIntegerIds = [addr2IntegerId]
79 noRepStrIds = [unpackCString2Id, unpackCStringId]
81 addr2IntegerId = lookupThinAirId addr2IntegerIdKey
83 packStringForCId = lookupThinAirId packCStringIdKey
84 unpackCStringId = lookupThinAirId unpackCStringIdKey
85 unpackCString2Id = lookupThinAirId unpackCString2IdKey
86 unpackCStringAppendId = lookupThinAirId unpackCStringAppendIdKey
87 unpackCStringFoldrId = lookupThinAirId unpackCStringFoldrIdKey
89 foldrId = lookupThinAirId foldrIdKey
90 buildId = lookupThinAirId buildIdKey
94 thinAirIdMapRef :: IORef (UniqFM Id)
95 thinAirIdMapRef = unsafePerformIO (newIORef (panic "thinAirIdMap: still empty"))
97 setThinAirIds :: [Id] -> IO ()
98 setThinAirIds thin_air_ids
99 = writeIORef thinAirIdMapRef the_map
101 the_map = listToUFM [(varUnique id, id) | id <- thin_air_ids]
103 thinAirIdMap :: UniqFM Id
104 thinAirIdMap = unsafePerformIO (readIORef thinAirIdMapRef)
105 -- Read it just once, the first time someone tugs on thinAirIdMap
107 lookupThinAirId :: Unique -> Id
108 lookupThinAirId uniq = lookupWithDefaultUFM thinAirIdMap
109 (panic "lookupThinAirId: no mapping") uniq