Id.lhs 55.6 KB
Newer Older
1
%
2
% (c) The GRASP/AQUA Project, Glasgow University, 1992-1996
3 4 5 6 7 8
%
\section[Id]{@Ids@: Value and constructor identifiers}

\begin{code}
#include "HsVersions.h"

9 10 11
module Id {- (
	GenId, Id(..),		-- Abstract
	StrictnessMark(..),	-- An enumaration
12 13 14 15 16 17
	ConTag(..), DictVar(..), DictFun(..), DataCon(..),

	-- CONSTRUCTION
	mkSysLocal, mkUserLocal,
	mkSpecPragmaId,
	mkSpecId, mkSameSpecCon,
18
	selectIdInfoForSpecId,
19
	mkTemplateLocals,
20
	mkImported,
21 22
	mkDataCon, mkTupleCon,
	mkIdWithNewUniq,
23 24
	mkMethodSelId, mkSuperDictSelId, mkDefaultMethodId,
	mkConstMethodId, getConstMethodId,
25 26

	updateIdType,
27
	mkId, mkDictFunId, mkInstId,
28 29 30 31
	mkWorkerId,
	localiseId,

	-- DESTRUCTION
32 33 34
	idType,
	getIdInfo, replaceIdInfo,
	getPragmaInfo,
35
	idPrimRep, getInstIdModule,
36
	getMentionedTyConsAndClassesFromId,
37

38
	dataConTag, dataConStrictMarks,
39
	dataConSig, dataConRawArgTys, dataConArgTys,
40 41 42 43
	dataConTyCon, dataConArity,
	dataConFieldLabels,

	recordSelectorFieldLabel,
44 45

	-- PREDICATES
46
	isDataCon, isTupleCon,
47
	isNullaryDataCon,
48 49 50 51 52
	isSpecId_maybe, isSpecPragmaId_maybe,
	toplevelishId, externallyVisibleId,
	isTopLevId, isWorkerId, isWrapperId,
	isImportedId, isSysLocalId,
	isBottomingId,
53 54 55 56
	isMethodSelId, isDefaultMethodId_maybe, isSuperDictSelId_maybe,
	isDictFunId,
--???	isInstId_maybe,
	isConstMethodId_maybe,
57 58 59 60 61 62 63 64 65 66 67 68
	cmpId_withSpecDataCon,
	myWrapperMaybe,
	whatsMentionedInId,
	unfoldingUnfriendlyId,	-- ToDo: rm, eventually
	idWantsToBeINLINEd,
--	dataConMentionsNonPreludeTyCon,

	-- SUBSTITUTION
	applySubstToId, applyTypeEnvToId,
-- not exported:	apply_to_Id, -- please don't use this, generally

	-- UNFOLDING, ARITY, UPDATE, AND STRICTNESS STUFF (etc)
69
	getIdArity, addIdArity,
70 71 72
	getIdDemandInfo, addIdDemandInfo,
	getIdSpecialisation, addIdSpecialisation,
	getIdStrictness, addIdStrictness,
73
	getIdUnfolding, addIdUnfolding,
74 75 76 77 78 79 80 81 82 83 84
	getIdUpdateInfo, addIdUpdateInfo,
	getIdArgUsageInfo, addIdArgUsageInfo,
	getIdFBTypeInfo, addIdFBTypeInfo,
	-- don't export the types, lest OptIdInfo be dragged in!

	-- MISCELLANEOUS
	unlocaliseId,
	fIRST_TAG,
	showId,
	pprIdInUnfolding,

85 86
	nmbrId,

87 88 89 90 91 92
	-- "Environments" keyed off of Ids, and sets of Ids
	IdEnv(..),
	lookupIdEnv, lookupNoFailIdEnv, nullIdEnv, unitIdEnv, mkIdEnv,
	growIdEnv, growIdEnvList, isNullIdEnv, addOneToIdEnv,
	delOneFromIdEnv, delManyFromIdEnv, modifyIdEnv, combineIdEnvs,
	rngIdEnv, mapIdEnv,
93

94 95 96
	-- and to make the interface self-sufficient...
	GenIdSet(..), IdSet(..)
    )-} where
97

98 99 100
IMP_Ubiq()
IMPORT_DELOOPER(IdLoop)   -- for paranoia checking
IMPORT_DELOOPER(TyLoop)   -- for paranoia checking
101 102

import Bag
103
import Class		( classOpString, Class(..), GenClass, ClassOp(..), GenClassOp )
104
import CStrings		( identToC, cSEP )
105 106
import IdInfo
import Maybes		( maybeToBool )
107
import Name		( appendRdr, nameUnique, mkLocalName, isLocalName,
108
			  isLocallyDefinedName,
109
			  mkTupleDataConName, mkCompoundName, mkCompoundName2,
110 111 112
			  isLexSym, isLexSpecialSym,
			  isLocallyDefined, changeUnique,
			  getOccName, origName, moduleOf,
113 114
			  isExported, ExportFlag(..),
			  RdrName(..), Name
115
			)
116
import FieldLabel	( fieldLabelName, FieldLabel(..){-instances-} )
117
import PragmaInfo	( PragmaInfo(..) )
118
import PprEnv		-- ( NmbrM(..), NmbrEnv(..) )
119
import PprType		( getTypeString, typeMaybeString, specMaybeTysSuffix,
120
			  nmbrType, nmbrTyVar,
121 122
			  GenType, GenTyVar
			)
123 124 125
import PprStyle
import Pretty
import SrcLoc		( mkBuiltinSrcLoc )
126
import TyCon		( TyCon, mkTupleTyCon, tyConDataCons )
127 128
import Type		( mkSigmaTy, mkTyVarTys, mkFunTys, mkDictTy,
			  applyTyCon, isPrimType, instantiateTy,
129
			  tyVarsOfType, applyTypeEnvToTy, typePrimRep,
130 131
			  GenType, ThetaType(..), TauType(..), Type(..)
			)
132
import TyVar		( alphaTyVars, isEmptyTyVarSet, TyVarEnv(..) )
133
import UniqFM
134
import UniqSet		-- practically all of it
135 136
import Unique		( getBuiltinUniques, pprUnique, showUnique,
			  incrUnique,
137 138
			  Unique{-instance Ord3-}
			)
139
import Util		( mapAccumL, nOfThem, zipEqual,
140 141
			  panic, panic#, pprPanic, assertPanic
			)
142 143 144 145 146 147
\end{code}

Here are the @Id@ and @IdDetails@ datatypes; also see the notes that
follow.

Every @Id@ has a @Unique@, to uniquify it and for fast comparison, a
148
@Type@, and an @IdInfo@ (non-essential info about it, e.g.,
149 150 151 152 153 154
strictness).  The essential info about different kinds of @Ids@ is
in its @IdDetails@.

ToDo: possibly cache other stuff in the single-constructor @Id@ type.

\begin{code}
155 156
data GenId ty = Id
	Unique		-- Key for fast comparison
157
	Name
158 159 160 161 162 163 164 165 166
	ty		-- Id's type; used all the time;
	IdDetails	-- Stuff about individual kinds of Ids.
	PragmaInfo	-- Properties of this Id requested by programmer
			-- eg specialise-me, inline-me
	IdInfo		-- Properties of this Id deduced by compiler
				   
type Id = GenId Type

data StrictnessMark = MarkedStrict | NotMarkedStrict
167 168 169 170 171

data IdDetails

  ---------------- Local values

172 173
  = LocalId	Bool		-- Local name; mentioned by the user
				-- True <=> no free type vars
174

175 176
  | SysLocalId	Bool	        -- Local name; made up by the compiler
				-- as for LocalId
177

178
  | SpecPragmaId 		-- Local name; introduced by the compiler
179 180
		 (Maybe Id)	-- for explicit specid in pragma
		 Bool		-- as for LocalId
181 182 183

  ---------------- Global values

184
  | ImportedId			-- Global name (Imported or Implicit); Id imported from an interface
185

186
  | TopLevId			-- Global name (LocalDef); Top-level in the orig source pgm
187 188 189 190 191 192 193
				-- (not moved there by transformations).

	-- a TopLevId's type may contain free type variables, if
	-- the monomorphism restriction applies.

  ---------------- Data constructors

194
  | DataConId	ConTag
195
		[StrictnessMark] -- Strict args; length = arity
196
		[FieldLabel]	-- Field labels for this constructor
197

198 199 200 201
		[TyVar] [(Class,Type)] [Type] TyCon
				-- the type is:
				-- forall tyvars . theta_ty =>
				--    unitype_1 -> ... -> unitype_n -> tycon tyvars
202

203
  | TupleConId	Int		-- Its arity
204

205
  | RecordSelId FieldLabel
206

207 208 209 210 211 212
  ---------------- Things to do with overloading

  | SuperDictSelId		-- Selector for superclass dictionary
		Class		-- The class (input dict)
		Class		-- The superclass (result dict)

213
  | MethodSelId	Class		-- An overloaded class operation, with
214 215 216 217 218
				-- a fully polymorphic type.  Its code
				-- just selects a method from the
				-- dictionary.  The class.
		ClassOp		-- The operation

219
	-- NB: The IdInfo for a MethodSelId has all the info about its
220 221 222 223
	-- related "constant method Ids", which are just
	-- specialisations of this general one.

  | DefaultMethodId		-- Default method for a particular class op
224
		Class		-- same class, <blah-blah> info as MethodSelId
225 226 227 228
		ClassOp		-- (surprise, surprise)
		Bool		-- True <=> I *know* this default method Id
				-- is a generated one that just says
				-- `error "No default method for <op>"'.
229 230 231 232 233 234 235 236 237

				-- see below
  | DictFunId	Class		-- A DictFun is uniquely identified
		Type		-- by its class and type; this type has free type vars,
				-- whose identity is irrelevant.  Eg Class = Eq
				--				     Type  = Tree a
				-- The "a" is irrelevant.  As it is too painful to
				-- actually do comparisons that way, we kindly supply
				-- a Unique for that purpose.
238
		Module		-- module where instance came from
239 240 241 242 243 244 245

				-- see below
  | ConstMethodId		-- A method which depends only on the type of the
				-- instance, and not on any further dictionaries etc.
		Class		-- Uniquely identified by:
		Type		-- (class, type, classop) triple
		ClassOp
246
		Module		-- module where instance came from
247

248
  | InstId			-- An instance of a dictionary, class operation,
249
				-- or overloaded value (Local name)
250
		Bool		-- as for LocalId
251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267

  | SpecId			-- A specialisation of another Id
		Id		-- Id of which this is a specialisation
		[Maybe Type]	-- Types at which it is specialised;
				-- A "Nothing" says this type ain't relevant.
		Bool		-- True <=> no free type vars; it's not enough
				-- to know about the unspec version, because
				-- we may specialise to a type w/ free tyvars
				-- (i.e., in one of the "Maybe Type" dudes).

  | WorkerId			-- A "worker" for some other Id
		Id		-- Id for which this is a worker

type ConTag	= Int
type DictVar	= Id
type DictFun	= Id
type DataCon	= Id
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
\end{code}

DictFunIds are generated from instance decls.
\begin{verbatim}
	class Foo a where
	  op :: a -> a -> Bool

	instance Foo a => Foo [a] where
	  op = ...
\end{verbatim}
generates the dict fun id decl
\begin{verbatim}
	dfun.Foo.[*] = \d -> ...
\end{verbatim}
The dfun id is uniquely named by the (class, type) pair.  Notice, it
isn't a (class,tycon) pair any more, because we may get manually or
automatically generated specialisations of the instance decl:
\begin{verbatim}
	instance Foo [Int] where
	  op = ...
\end{verbatim}
generates
\begin{verbatim}
291
	dfun.Foo.[Int] = ...
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
\end{verbatim}
The type variables in the name are irrelevant; we print them as stars.


Constant method ids are generated from instance decls where
there is no context; that is, no dictionaries are needed to
construct the method.  Example
\begin{verbatim}
	instance Foo Int where
	  op = ...
\end{verbatim}
Then we get a constant method
\begin{verbatim}
	Foo.op.Int = ...
\end{verbatim}

It is possible, albeit unusual, to have a constant method
for an instance decl which has type vars:
\begin{verbatim}
	instance Foo [a] where
	  op []     ys = True
	  op (x:xs) ys = False
\end{verbatim}
We get the constant method
\begin{verbatim}
	Foo.op.[*] = ...
\end{verbatim}
So a constant method is identified by a class/op/type triple.
The type variables in the type are irrelevant.


For Ids whose names must be known/deducible in other modules, we have
to conjure up their worker's names (and their worker's worker's
names... etc) in a known systematic way.

327

328 329 330 331 332 333 334 335 336
%************************************************************************
%*									*
\subsection[Id-documentation]{Documentation}
%*									*
%************************************************************************

[A BIT DATED [WDP]]

The @Id@ datatype describes {\em values}.  The basic things we want to
337
know: (1)~a value's {\em type} (@idType@ is a very common
338 339 340 341 342 343 344 345
operation in the compiler); and (2)~what ``flavour'' of value it might
be---for example, it can be terribly useful to know that a value is a
class method.

\begin{description}
%----------------------------------------------------------------------
\item[@DataConId@:] For the data constructors declared by a @data@
declaration.  Their type is kept in {\em two} forms---as a regular
346
@Type@ (in the usual place), and also in its constituent pieces (in
347 348 349 350 351 352 353 354 355 356 357 358 359 360
the ``details''). We are frequently interested in those pieces.

%----------------------------------------------------------------------
\item[@TupleConId@:] This is just a special shorthand for @DataCons@ for
the infinite family of tuples.

%----------------------------------------------------------------------
\item[@ImportedId@:] These are values defined outside this module.
{\em Everything} we want to know about them must be stored here (or in
their @IdInfo@).

%----------------------------------------------------------------------
\item[@TopLevId@:] These are values defined at the top-level in this
module; i.e., those which {\em might} be exported (hence, a
361
@Name@).  It does {\em not} include those which are moved to the
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376
top-level through program transformations.

We also guarantee that @TopLevIds@ will {\em stay} at top-level.
Theoretically, they could be floated inwards, but there's no known
advantage in doing so.	This way, we can keep them with the same
@Unique@ throughout (no cloning), and, in general, we don't have to be
so paranoid about them.

In particular, we had the following problem generating an interface:
We have to ``stitch together'' info (1)~from the typechecker-produced
global-values list (GVE) and (2)~from the STG code [which @Ids@ have
what arities].	If the @Uniques@ on the @TopLevIds@ can {\em change}
between (1) and (2), you're sunk!

%----------------------------------------------------------------------
377
\item[@MethodSelId@:] A selector from a dictionary; it may select either
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
a method or a dictionary for one of the class's superclasses.

%----------------------------------------------------------------------
\item[@DictFunId@:]

@mkDictFunId [a,b..] theta C T@ is the function derived from the
instance declaration

	instance theta => C (T a b ..) where
		...

It builds function @Id@ which maps dictionaries for theta,
to a dictionary for C (T a b ..).

*Note* that with the ``Mark Jones optimisation'', the theta may
include dictionaries for the immediate superclasses of C at the type
(T a b ..).

%----------------------------------------------------------------------
\item[@InstId@:]

%----------------------------------------------------------------------
\item[@SpecId@:]

%----------------------------------------------------------------------
\item[@WorkerId@:]

%----------------------------------------------------------------------
\item[@LocalId@:] A purely-local value, e.g., a function argument,
something defined in a @where@ clauses, ... --- but which appears in
the original program text.

%----------------------------------------------------------------------
\item[@SysLocalId@:] Same as a @LocalId@, except does {\em not} appear in
the original program text; these are introduced by the compiler in
doing its thing.

%----------------------------------------------------------------------
\item[@SpecPragmaId@:] Introduced by the compiler to record
Specialisation pragmas. It is dead code which MUST NOT be removed
before specialisation.
\end{description}

Further remarks:
\begin{enumerate}
%----------------------------------------------------------------------
\item

@DataCons@ @TupleCons@, @Importeds@, @TopLevIds@, @SuperDictSelIds@,
427
@MethodSelIds@, @DictFunIds@, and @DefaultMethodIds@ have the following
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
properties:
\begin{itemize}
\item
They have no free type variables, so if you are making a
type-variable substitution you don't need to look inside them.
\item
They are constants, so they are not free variables.  (When the STG
machine makes a closure, it puts all the free variables in the
closure; the above are not required.)
\end{itemize}
Note that @InstIds@, @Locals@ and @SysLocals@ {\em may} have the above
properties, but they may not.
\end{enumerate}

%************************************************************************
%*									*
\subsection[Id-general-funs]{General @Id@-related functions}
%*									*
%************************************************************************

\begin{code}
449
unsafeGenId2Id :: GenId ty -> Id
450
unsafeGenId2Id (Id u n ty d p i) = Id u n (panic "unsafeGenId2Id:ty") d p i
451 452 453

isDataCon id = is_data (unsafeGenId2Id id)
 where
454 455 456
  is_data (Id _ _ _ (DataConId _ _ _ _ _ _ _) _ _) = True
  is_data (Id _ _ _ (TupleConId _) _ _)		   = True
  is_data (Id _ _ _ (SpecId unspec _ _) _ _)	   = is_data unspec
457
  is_data other					   = False
458 459 460 461


isTupleCon id = is_tuple (unsafeGenId2Id id)
 where
462 463
  is_tuple (Id _ _ _ (TupleConId _) _ _)	 = True
  is_tuple (Id _ _ _ (SpecId unspec _ _) _ _)	 = is_tuple unspec
464 465 466
  is_tuple other				 = False

{-LATER:
467
isSpecId_maybe (Id _ _ _ (SpecId unspec ty_maybes _) _ _)
468 469 470 471 472
  = ASSERT(not (maybeToBool (isSpecId_maybe unspec)))
    Just (unspec, ty_maybes)
isSpecId_maybe other_id
  = Nothing

473
isSpecPragmaId_maybe (Id _ _ _ (SpecPragmaId specid _) _ _)
474
  = Just specid
475 476
isSpecPragmaId_maybe other_id
  = Nothing
477
-}
478 479
\end{code}

480 481 482 483
@toplevelishId@ tells whether an @Id@ {\em may} be defined in a nested
@let(rec)@ (returns @False@), or whether it is {\em sure} to be
defined at top level (returns @True@). This is used to decide whether
the @Id@ is a candidate free variable. NB: you are only {\em sure}
484 485 486
about something if it returns @True@!

\begin{code}
487 488
toplevelishId	  :: Id -> Bool
idHasNoFreeTyVars :: Id -> Bool
489

490
toplevelishId (Id _ _ _ details _ _)
491 492
  = chk details
  where
493 494
    chk (DataConId _ _ _ _ _ _ _)   = True
    chk (TupleConId _)    	    = True
495
    chk (RecordSelId _)   	    = True
496 497
    chk ImportedId	    	    = True
    chk TopLevId	    	    = True	-- NB: see notes
498 499 500
    chk (SuperDictSelId _ _)	    = True
    chk (MethodSelId _ _)	    = True
    chk (DefaultMethodId _ _ _)     = True
501 502
    chk (DictFunId     _ _ _)	    = True
    chk (ConstMethodId _ _ _ _)     = True
503 504 505
    chk (SpecId unspec _ _)	    = toplevelishId unspec
				    -- depends what the unspecialised thing is
    chk (WorkerId unwrkr)	    = toplevelishId unwrkr
506 507 508 509
    chk (InstId	      _)	    = False	-- these are local
    chk (LocalId      _)	    = False
    chk (SysLocalId   _)	    = False
    chk (SpecPragmaId _ _)	    = False
510

511
idHasNoFreeTyVars (Id _ _ _ details _ info)
512 513
  = chk details
  where
514 515
    chk (DataConId _ _ _ _ _ _ _) = True
    chk (TupleConId _)    	  = True
516
    chk (RecordSelId _)   	  = True
517 518
    chk ImportedId	    	  = True
    chk TopLevId	    	  = True
519
    chk (SuperDictSelId _ _)	  = True
520
    chk (MethodSelId _ _)	  = True
521
    chk (DefaultMethodId _ _ _)   = True
522 523
    chk (DictFunId     _ _ _)	  = True
    chk (ConstMethodId _ _ _ _)   = True
524
    chk (WorkerId unwrkr)	  = idHasNoFreeTyVars unwrkr
525
    chk (SpecId _     _   no_free_tvs) = no_free_tvs
526 527 528 529
    chk (InstId         no_free_tvs) = no_free_tvs
    chk (LocalId        no_free_tvs) = no_free_tvs
    chk (SysLocalId     no_free_tvs) = no_free_tvs
    chk (SpecPragmaId _ no_free_tvs) = no_free_tvs
530 531 532
\end{code}

\begin{code}
533 534
isTopLevId (Id _ _ _ TopLevId _ _) = True
isTopLevId other		   = False
535

536 537
isImportedId (Id _ _ _ ImportedId _ _) = True
isImportedId other		       = False
538

539
isBottomingId (Id _ _ _ _ _ info) = bottomIsGuaranteed (getInfo info)
540

541
isSysLocalId (Id _ _ _ (SysLocalId _) _ _) = True
542 543
isSysLocalId other			   = False

544
isSpecPragmaId (Id _ _ _ (SpecPragmaId _ _) _ _) = True
545 546
isSpecPragmaId other			         = False

547 548
isMethodSelId (Id _ _ _ (MethodSelId _ _) _ _) = True
isMethodSelId _				       = False
549

550 551
isDefaultMethodId (Id _ _ _ (DefaultMethodId _ _ _) _ _) = True
isDefaultMethodId other				         = False
552

553
isDefaultMethodId_maybe (Id _ _ _ (DefaultMethodId cls clsop err) _ _)
554 555 556
  = Just (cls, clsop, err)
isDefaultMethodId_maybe other = Nothing

557
isDictFunId (Id _ _ _ (DictFunId _ _ _) _ _) = True
558 559
isDictFunId other		    	     = False

560
isConstMethodId (Id _ _ _ (ConstMethodId _ _ _ _) _ _) = True
561 562
isConstMethodId other		    		       = False

563
isConstMethodId_maybe (Id _ _ _ (ConstMethodId cls ty clsop _) _ _)
564 565 566
  = Just (cls, ty, clsop)
isConstMethodId_maybe other = Nothing

567
isSuperDictSelId_maybe (Id _ _ _ (SuperDictSelId c sc) _ _) = Just (c, sc)
568 569
isSuperDictSelId_maybe other_id				  = Nothing

570
isWorkerId (Id _ _ _ (WorkerId _) _ _) = True
571 572 573
isWorkerId other		     = False

{-LATER:
574
isWrapperId id = workerExists (getIdStrictness id)
575
-}
576 577 578
\end{code}

\begin{code}
579
{-LATER:
580 581 582 583
pprIdInUnfolding :: IdSet -> Id -> Pretty

pprIdInUnfolding in_scopes v
  = let
584
	v_ty = idType v
585 586 587
    in
    -- local vars first:
    if v `elementOfUniqSet` in_scopes then
588
	pprUnique (idUnique v)
589 590 591 592 593

    -- ubiquitous Ids with special syntax:
    else if v == nilDataCon then
	ppPStr SLIT("_NIL_")
    else if isTupleCon v then
594
	ppBeside (ppPStr SLIT("_TUP_")) (ppInt (dataConArity v))
595 596 597 598

    -- ones to think about:
    else
	let
599
	    (Id _ _ _ v_details _ _) = v
600 601 602
	in
    	case v_details of
	    -- these ones must have been exported by their original module
603
	  ImportedId   -> pp_full_name
604 605

	    -- these ones' exportedness checked later...
606 607
	  TopLevId  -> pp_full_name
	  DataConId _ _ _ _ _ _ _ -> pp_full_name
608

609
	  RecordSelId lbl -> ppr sty lbl
610 611 612 613

	    -- class-ish things: class already recorded as "mentioned"
	  SuperDictSelId c sc
	    -> ppCat [ppPStr SLIT("_SDSEL_"), pp_class c, pp_class sc]
614
	  MethodSelId c o
615 616 617 618 619 620
	    -> ppCat [ppPStr SLIT("_METH_"), pp_class c, pp_class_op o]
	  DefaultMethodId c o _
	    -> ppCat [ppPStr SLIT("_DEFM_"), pp_class c, pp_class_op o]

	    -- instance-ish things: should we try to figure out
	    -- *exactly* which extra instances have to be exported? (ToDo)
621
	  DictFunId  c t _
622
	    -> ppCat [ppPStr SLIT("_DFUN_"), pp_class c, pp_type t]
623
	  ConstMethodId c t o _
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
	    -> ppCat [ppPStr SLIT("_CONSTM_"), pp_class c, pp_class_op o, pp_type t]

	  -- specialisations and workers
	  SpecId unspec ty_maybes _
	    -> let
		  pp = pprIdInUnfolding in_scopes unspec
	       in
	       ppCat [ppPStr SLIT("_SPEC_"), pp, ppLbrack,
			ppIntersperse pp'SP{-'-} (map pp_ty_maybe ty_maybes),
			ppRbrack]

	  WorkerId unwrkr
	    -> let
		  pp = pprIdInUnfolding in_scopes unwrkr
	       in
	       ppBeside (ppPStr SLIT("_WRKR_ ")) pp

	  -- anything else? we're nae interested
	  other_id -> panic "pprIdInUnfolding:mystery Id"
  where
    ppr_Unfolding = PprUnfolding (panic "Id:ppr_Unfolding")

    pp_full_name
      = let
648
	    (OrigName m_str n_str) = origName "Id:ppr_Unfolding" v
649 650

	    pp_n =
651
	      if isLexSym n_str && not (isLexSpecialSym n_str) then
652 653 654 655
		  ppBesides [ppLparen, ppPStr n_str, ppRparen]
	      else
		  ppPStr n_str
	in
656
	if isPreludeDefined v then
657 658 659 660 661 662
	    pp_n
	else
	    ppCat [ppPStr SLIT("_ORIG_"), ppPStr m_str, pp_n]

    pp_class :: Class -> Pretty
    pp_class_op :: ClassOp -> Pretty
663 664
    pp_type :: Type -> Pretty
    pp_ty_maybe :: Maybe Type -> Pretty
665 666 667 668 669 670 671 672

    pp_class    clas = ppr ppr_Unfolding clas
    pp_class_op op   = ppr ppr_Unfolding op

    pp_type t = ppBesides [ppLparen, ppr ppr_Unfolding t, ppRparen]

    pp_ty_maybe Nothing  = ppPStr SLIT("_N_")
    pp_ty_maybe (Just t) = pp_type t
673
-}
674 675 676 677 678 679 680 681
\end{code}

@whatsMentionedInId@ ferrets out the types/classes/instances on which
this @Id@ depends.  If this Id is to appear in an interface, then
those entities had Jolly Well be in scope.  Someone else up the
call-tree decides that.

\begin{code}
682
{-LATER:
683 684 685 686 687 688 689
whatsMentionedInId
	:: IdSet			    -- Ids known to be in scope
	-> Id				    -- Id being processed
	-> (Bag Id, Bag TyCon, Bag Class)   -- mentioned Ids/TyCons/etc.

whatsMentionedInId in_scopes v
  = let
690
	v_ty = idType v
691 692

    	(tycons, clss)
693
	  = getMentionedTyConsAndClassesFromType v_ty
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708

	result0 id_bag = (id_bag, tycons, clss)

	result1 ids tcs cs
	  = (ids `unionBags` unitBag v,	-- we add v to "mentioned"...
	     tcs `unionBags` tycons,
	     cs  `unionBags` clss)
    in
    -- local vars first:
    if v `elementOfUniqSet` in_scopes then
	result0 emptyBag    -- v not added to "mentioned"

    -- ones to think about:
    else
	let
709
	    (Id _ _ _ v_details _ _) = v
710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
	in
    	case v_details of
	  -- specialisations and workers
	  SpecId unspec ty_maybes _
	    -> let
		  (ids2, tcs2, cs2) = whatsMentionedInId in_scopes unspec
	       in
	       result1 ids2 tcs2 cs2

	  WorkerId unwrkr
	    -> let
		  (ids2, tcs2, cs2) = whatsMentionedInId in_scopes unwrkr
	       in
	       result1 ids2 tcs2 cs2

	  anything_else -> result0 (unitBag v) -- v is  added to "mentioned"
726
-}
727 728 729 730
\end{code}

Tell them who my wrapper function is.
\begin{code}
731
{-LATER:
732 733
myWrapperMaybe :: Id -> Maybe Id

734
myWrapperMaybe (Id _ _ _ (WorkerId my_wrapper) _ _) = Just my_wrapper
735 736
myWrapperMaybe other_id			    	  = Nothing
-}
737 738 739 740 741 742 743 744
\end{code}

\begin{code}
unfoldingUnfriendlyId	-- return True iff it is definitely a bad
	:: Id		-- idea to export an unfolding that
	-> Bool		-- mentions this Id.  Reason: it cannot
			-- possibly be seen in another module.

745 746 747
unfoldingUnfriendlyId id = panic "Id.unfoldingUnfriendlyId"
{-LATER:

748 749 750 751
unfoldingUnfriendlyId id
  | not (externallyVisibleId id) -- that settles that...
  = True

752
unfoldingUnfriendlyId (Id _ _ _ (WorkerId wrapper) _ _)
753 754 755 756 757 758 759 760
  = class_thing wrapper
  where
    -- "class thing": If we're going to use this worker Id in
    -- an interface, we *have* to be able to untangle the wrapper's
    -- strictness when reading it back in.  At the moment, this
    -- is not always possible: in precisely those cases where
    -- we pass tcGenPragmas a "Nothing" for its "ty_maybe".

761 762 763
    class_thing (Id _ _ _ (SuperDictSelId _ _) _ _)    = True
    class_thing (Id _ _ _ (MethodSelId _ _) _ _)  	   = True
    class_thing (Id _ _ _ (DefaultMethodId _ _ _) _ _) = True
764 765
    class_thing other				   = False

766
unfoldingUnfriendlyId (Id _ _ _ (SpecId d@(Id _ _ _ dfun@(DictFunId _ t _)) _ _) _ _)
767 768 769 770
    -- a SPEC of a DictFunId can end up w/ gratuitous
    -- TyVar(Templates) in the i/face; only a problem
    -- if -fshow-pragma-name-errs; but we can do without the pain.
    -- A HACK in any case (WDP 94/05/02)
771
  = naughty_DictFunId dfun
772

773
unfoldingUnfriendlyId d@(Id _ _ _ dfun@(DictFunId _ t _) _ _)
774
  = naughty_DictFunId dfun -- similar deal...
775 776 777 778 779 780

unfoldingUnfriendlyId other_id   = False -- is friendly in all other cases

naughty_DictFunId :: IdDetails -> Bool
    -- True <=> has a TyVar(Template) in the "type" part of its "name"

781 782
naughty_DictFunId (DictFunId _ _ _) = panic "False" -- came from outside; must be OK
naughty_DictFunId (DictFunId _ ty _)
783
  = not (isGroundTy ty)
784
-}
785 786 787 788 789 790 791 792 793 794 795 796 797
\end{code}

@externallyVisibleId@: is it true that another module might be
able to ``see'' this Id?

We need the @toplevelishId@ check as well as @isExported@ for when we
compile instance declarations in the prelude.  @DictFunIds@ are
``exported'' if either their class or tycon is exported, but, in
compiling the prelude, the compiler may not recognise that as true.

\begin{code}
externallyVisibleId :: Id -> Bool

798
externallyVisibleId id@(Id _ _ _ details _ _)
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814
  = if isLocallyDefined id then
	toplevelishId id && isExported id && not (weird_datacon details)
    else
	not (weird_tuplecon details)
	-- if visible here, it must be visible elsewhere, too.
  where
    -- If it's a DataCon, it's not enough to know it (meaning
    -- its TyCon) is exported; we need to know that it might
    -- be visible outside.  Consider:
    --
    --	data Foo a = Mumble | BigFoo a WeirdLocalType
    --
    -- We can't tell the outside world *anything* about Foo, because
    -- of WeirdLocalType; but we need to know this when asked if
    -- "Mumble" is externally visible...

815
{- LATER: if at all:
816
    weird_datacon (DataConId _ _ _ _ _ _ tycon)
817
      = maybeToBool (maybePurelyLocalTyCon tycon)
818
-}
819 820
    weird_datacon not_a_datacon_therefore_not_weird = False

821
    weird_tuplecon (TupleConId arity)
822 823 824 825 826 827 828
      = arity > 32 -- sigh || isBigTupleTyCon tycon -- generated *purely* for local use
    weird_tuplecon _ = False
\end{code}

\begin{code}
idWantsToBeINLINEd :: Id -> Bool

829 830
idWantsToBeINLINEd (Id _ _ _ _ IWantToBeINLINEd _) = True
idWantsToBeINLINEd _				   = False
831 832 833 834 835 836
\end{code}

For @unlocaliseId@: See the brief commentary in
\tr{simplStg/SimplStg.lhs}.

\begin{code}
837
{-LATER:
838 839
unlocaliseId :: FAST_STRING{-modulename-} -> Id -> Maybe Id

840 841
unlocaliseId mod (Id u fn ty info TopLevId)
  = Just (Id u (unlocaliseFullName fn) ty info TopLevId)
842

843
unlocaliseId mod (Id u sn ty info (LocalId no_ftvs))
844 845 846 847
  = --false?: ASSERT(no_ftvs)
    let
	full_name = unlocaliseShortName mod u sn
    in
848
    Just (Id u full_name ty info TopLevId)
849

850
unlocaliseId mod (Id u sn ty info (SysLocalId no_ftvs))
851 852 853 854
  = --false?: on PreludeGlaST: ASSERT(no_ftvs)
    let
	full_name = unlocaliseShortName mod u sn
    in
855
    Just (Id u full_name ty info TopLevId)
856

857
unlocaliseId mod (Id u n ty info (SpecId unspec ty_maybes no_ftvs))
858 859
  = case unlocalise_parent mod u unspec of
      Nothing -> Nothing
860
      Just xx -> Just (Id u n ty info (SpecId xx ty_maybes no_ftvs))
861

862
unlocaliseId mod (Id u n ty info (WorkerId unwrkr))
863 864
  = case unlocalise_parent mod u unwrkr of
      Nothing -> Nothing
865
      Just xx -> Just (Id u n ty info (WorkerId xx))
866

867 868
unlocaliseId mod (Id u name ty info (InstId no_ftvs))
  = Just (Id u full_name ty info TopLevId)
869 870 871
	-- type might be wrong, but it hardly matters
	-- at this stage (just before printing C)  ToDo
  where
872
    name = nameOf (origName "Id.unlocaliseId" name)
873
    full_name = mkFullName mod name InventedInThisModule ExportAll mkGeneratedSrcLoc
874 875 876 877 878 879 880

unlocaliseId mod other_id = Nothing

--------------------
-- we have to be Very Careful for workers/specs of
-- local functions!

881
unlocalise_parent mod uniq (Id _ sn ty info (LocalId no_ftvs))
882 883 884 885
  = --false?: ASSERT(no_ftvs)
    let
	full_name = unlocaliseShortName mod uniq sn
    in
886
    Just (Id uniq full_name ty info TopLevId)
887

888
unlocalise_parent mod uniq (Id _ sn ty info (SysLocalId no_ftvs))
889 890 891 892
  = --false?: ASSERT(no_ftvs)
    let
	full_name = unlocaliseShortName mod uniq sn
    in
893
    Just (Id uniq full_name ty info TopLevId)
894 895 896

unlocalise_parent mod uniq other_id = unlocaliseId mod other_id
  -- we're OK otherwise
897
-}
898 899 900 901 902 903 904 905 906 907
\end{code}

CLAIM (not ASSERTed) for @applyTypeEnvToId@ and @applySubstToId@:
`Top-levelish Ids'' cannot have any free type variables, so applying
the type-env cannot have any effect.  (NB: checked in CoreLint?)

The special casing is in @applyTypeEnvToId@, not @apply_to_Id@, as the
former ``should be'' the usual crunch point.

\begin{code}
908 909
type TypeEnv = TyVarEnv Type

910 911
applyTypeEnvToId :: TypeEnv -> Id -> Id

912
applyTypeEnvToId type_env id@(Id _ _ ty _ _ _)
913 914 915 916 917 918 919 920 921
  | idHasNoFreeTyVars id
  = id
  | otherwise
  = apply_to_Id ( \ ty ->
	applyTypeEnvToTy type_env ty
    ) id
\end{code}

\begin{code}
922
apply_to_Id :: (Type -> Type) -> Id -> Id
923

924
apply_to_Id ty_fn (Id u n ty details prag info)
925 926 927
  = let
	new_ty = ty_fn ty
    in
928
    Id u n new_ty (apply_to_details details) prag (apply_to_IdInfo ty_fn info)
929 930 931 932 933 934
  where
    apply_to_details (SpecId unspec ty_maybes no_ftvs)
      = let
	    new_unspec = apply_to_Id ty_fn unspec
	    new_maybes = map apply_to_maybe ty_maybes
	in
935 936
	SpecId new_unspec new_maybes (no_free_tvs ty)
	-- ToDo: gratuitous recalc no_ftvs???? (also InstId)
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
      where
	apply_to_maybe Nothing   = Nothing
	apply_to_maybe (Just ty) = Just (ty_fn ty)

    apply_to_details (WorkerId unwrkr)
      = let
	    new_unwrkr = apply_to_Id ty_fn unwrkr
	in
	WorkerId new_unwrkr

    apply_to_details other = other
\end{code}

Sadly, I don't think the one using the magic typechecker substitution
can be done with @apply_to_Id@.  Here we go....

Strictness is very important here.  We can't leave behind thunks
with pointers to the substitution: it {\em must} be single-threaded.

\begin{code}
957
{-LATER:
958 959
applySubstToId :: Subst -> Id -> (Subst, Id)

960
applySubstToId subst id@(Id u n ty info details)
961 962 963 964 965 966
  -- *cannot* have a "idHasNoFreeTyVars" get-out clause
  -- because, in the typechecker, we are still
  -- *concocting* the types.
  = case (applySubstToTy     subst ty)		of { (s2, new_ty)      ->
    case (applySubstToIdInfo s2    info)	of { (s3, new_info)    ->
    case (apply_to_details   s3 new_ty details) of { (s4, new_details) ->
967
    (s4, Id u n new_ty new_info new_details) }}}
968
  where
969
    apply_to_details subst _ (InstId inst no_ftvs)
970
      = case (applySubstToInst subst inst) of { (s2, new_inst) ->
971
	(s2, InstId new_inst no_ftvs{-ToDo:right???-}) }
972 973 974

    apply_to_details subst new_ty (SpecId unspec ty_maybes _)
      = case (applySubstToId subst unspec)  	     of { (s2, new_unspec) ->
975
	case (mapAccumL apply_to_maybe s2 ty_maybes) of { (s3, new_maybes) ->
976 977 978 979 980 981 982 983 984 985
	(s3, SpecId new_unspec new_maybes (no_free_tvs new_ty)) }}
	-- NB: recalc no_ftvs (I think it's necessary (?) WDP 95/04)
      where
	apply_to_maybe subst Nothing   = (subst, Nothing)
	apply_to_maybe subst (Just ty)
	  = case (applySubstToTy subst ty) of { (s2, new_ty) ->
	    (s2, Just new_ty) }

    apply_to_details subst _ (WorkerId unwrkr)
      = case (applySubstToId subst unwrkr) of { (s2, new_unwrkr) ->
986
	(s2, WorkerId new_unwrkr) }
987 988

    apply_to_details subst _ other = (subst, other)
989
-}
990 991 992 993 994 995 996 997 998
\end{code}

%************************************************************************
%*									*
\subsection[Id-type-funs]{Type-related @Id@ functions}
%*									*
%************************************************************************

\begin{code}
999 1000
idType :: GenId ty -> ty

1001
idType (Id _ _ ty _ _ _) = ty
1002 1003 1004
\end{code}

\begin{code}
1005
{-LATER:
1006 1007 1008
getMentionedTyConsAndClassesFromId :: Id -> (Bag TyCon, Bag Class)

getMentionedTyConsAndClassesFromId id
1009 1010
 = getMentionedTyConsAndClassesFromType (idType id)
-}
1011 1012 1013
\end{code}

\begin{code}
1014
idPrimRep i = typePrimRep (idType i)
1015 1016
\end{code}

1017
\begin{code}
1018
{-LATER:
1019 1020
getInstIdModule (Id _ _ _ (DictFunId _ _ mod)) = mod
getInstIdModule (Id _ _ _ (ConstMethodId _ _ _ mod)) = mod
1021
getInstIdModule other = panic "Id:getInstIdModule"
1022 1023 1024 1025 1026 1027 1028 1029 1030 1031
-}
\end{code}

%************************************************************************
%*									*
\subsection[Id-overloading]{Functions related to overloading}
%*									*
%************************************************************************

\begin{code}
1032
mkSuperDictSelId u c sc ty info
1033
  = mk_classy_id (SuperDictSelId c sc) SLIT("sdsel") (Left (origName "mkSuperDictSelId" sc)) u c ty info
1034

1035
mkMethodSelId u rec_c op ty info
1036
  = mk_classy_id (MethodSelId rec_c op) SLIT("meth") (Right (classOpString op)) u rec_c ty info
1037

1038
mkDefaultMethodId u rec_c op gen ty info
1039 1040 1041 1042
  = mk_classy_id (DefaultMethodId rec_c op gen) SLIT("defm") (Right (classOpString op)) u rec_c ty info

mk_classy_id details str op_str u rec_c ty info
  = Id u n ty details NoPragmaInfo info
1043
  where
1044
    cname = getName rec_c -- we get other info out of here
1045 1046
    cname_orig = origName "mk_classy_id" cname
    cmod = moduleOf cname_orig
1047

1048
    n = mkCompoundName u cmod str [Left cname_orig, op_str] cname
1049 1050 1051 1052

mkDictFunId u c ity full_ty from_here locn mod info
  = Id u n full_ty (DictFunId c ity mod) NoPragmaInfo info
  where
1053
    n = mkCompoundName2 u mod SLIT("dfun") (Left (origName "mkDictFunId" c) : map Right (getTypeString ity)) from_here locn
1054 1055 1056 1057

mkConstMethodId	u c op ity full_ty from_here locn mod info
  = Id u n full_ty (ConstMethodId c ity op mod) NoPragmaInfo info
  where
1058
    n = mkCompoundName2 u mod SLIT("const") (Left (origName "mkConstMethodId" c) : Right (classOpString op) : map Right (getTypeString ity)) from_here locn
1059 1060 1061 1062 1063

mkWorkerId u unwrkr ty info
  = Id u n ty (WorkerId unwrkr) NoPragmaInfo info
  where
    unwrkr_name = getName unwrkr
1064 1065
    unwrkr_orig = trace "mkWorkerId:origName:" $ origName "mkWorkerId" unwrkr_name
    umod = moduleOf unwrkr_orig
1066

1067
    n = mkCompoundName u umod SLIT("wrk") [Left unwrkr_orig] unwrkr_name
1068 1069

mkInstId u ty name = Id u (changeUnique name u) ty (InstId (no_free_tvs ty)) NoPragmaInfo noIdInfo
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079

{-LATER:
getConstMethodId clas op ty
  = -- constant-method info is hidden in the IdInfo of
    -- the class-op id (as mentioned up above).
    let
	sel_id = getMethodSelId clas op
    in
    case (lookupConstMethodId (getIdSpecialisation sel_id) ty) of
      Just xx -> xx
1080 1081
      Nothing -> pprError "ERROR: getConstMethodId:" (ppAboves [
	ppCat [ppr PprDebug ty, ppr PprDebug ops, ppr PprDebug op_ids,
1082 1083 1084 1085
	       ppr PprDebug sel_id],
	ppStr "(This can arise if an interface pragma refers to an instance",
	ppStr "but there is no imported interface which *defines* that instance.",
	ppStr "The info above, however ugly, should indicate what else you need to import."
1086
	])
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096
-}
\end{code}

%************************************************************************
%*									*
\subsection[local-funs]{@LocalId@-related functions}
%*									*
%************************************************************************

\begin{code}
1097
mkImported  n ty info = Id (nameUnique n) n ty ImportedId NoPragmaInfo info
1098

1099 1100
{-LATER:
updateIdType :: Id -> Type -> Id
1101
updateIdType (Id u n _ info details) ty = Id u n ty info details
1102
-}
1103 1104 1105
\end{code}

\begin{code}
1106 1107 1108 1109
type MyTy a b = GenType (GenTyVar a) b
type MyId a b = GenId (MyTy a b)

no_free_tvs ty = isEmptyTyVarSet (tyVarsOfType ty)
1110 1111 1112

-- SysLocal: for an Id being created by the compiler out of thin air...
-- UserLocal: an Id with a name the user might recognize...
1113
mkSysLocal, mkUserLocal :: FAST_STRING -> Unique -> MyTy a b -> SrcLoc -> MyId a b
1114 1115

mkSysLocal str uniq ty loc
1116
  = Id uniq (mkLocalName uniq str True{-emph uniq-} loc) ty (SysLocalId (no_free_tvs ty)) NoPragmaInfo noIdInfo
1117 1118

mkUserLocal str uniq ty loc
1119
  = Id uniq (mkLocalName uniq str False{-emph name-} loc) ty (LocalId (no_free_tvs ty)) NoPragmaInfo noIdInfo
1120 1121

-- mkUserId builds a local or top-level Id, depending on the name given
1122
mkUserId :: Name -> MyTy a b -> PragmaInfo -> MyId a b
1123 1124
mkUserId name ty pragma_info
  | isLocalName name
1125
  = Id (nameUnique name) name ty (LocalId (no_free_tvs ty)) pragma_info noIdInfo
1126
  | otherwise
1127 1128 1129
  = Id (nameUnique name) name ty 
	(if isLocallyDefinedName name then TopLevId else ImportedId)
	pragma_info noIdInfo
1130 1131 1132 1133 1134
\end{code}


\begin{code}
{-LATER:
1135

1136
-- for a SpecPragmaId being created by the compiler out of thin air...
1137 1138
mkSpecPragmaId :: FAST_STRING -> Unique -> Type -> Maybe Id -> SrcLoc -> Id
mkSpecPragmaId str uniq ty specid loc
1139
  = Id uniq (mkShortName str loc) ty noIdInfo (SpecPragmaId specid (no_free_tvs ty))
1140

1141
-- for new SpecId
1142 1143
mkSpecId u unspec ty_maybes ty info
  = ASSERT(not (maybeToBool (isSpecId_maybe unspec)))
1144
    Id u n ty info (SpecId unspec ty_maybes (no_free_tvs ty))
1145 1146 1147 1148

-- Specialised version of constructor: only used in STG and code generation
-- Note: The specialsied Id has the same unique as the unspeced Id

1149
mkSameSpecCon ty_maybes unspec@(Id u n ty info details)
1150 1151
  = ASSERT(isDataCon unspec)
    ASSERT(not (maybeToBool (isSpecId_maybe unspec)))
1152
    Id u n new_ty info (SpecId unspec ty_maybes (no_free_tvs new_ty))
1153 1154 1155 1156
  where
    new_ty = specialiseTy ty ty_maybes 0

localiseId :: Id -> Id
1157 1158
localiseId id@(Id u n ty info details)
  = Id u (mkShortName name loc) ty info (LocalId (no_free_tvs ty))
1159
  where
1160
    name = getOccName id
1161
    loc  = getSrcLoc id
1162
-}
1163 1164 1165

mkIdWithNewUniq :: Id -> Unique -> Id

1166 1167
mkIdWithNewUniq (Id _ n ty details prag info) u
  = Id u (changeUnique n u) ty details prag info
1168 1169 1170 1171 1172 1173
\end{code}

Make some local @Ids@ for a template @CoreExpr@.  These have bogus
@Uniques@, but that's OK because the templates are supposed to be
instantiated before use.
\begin{code}
1174
mkTemplateLocals :: [Type] -> [Id]
1175
mkTemplateLocals tys
1176
  = zipWith (\ u -> \ ty -> mkSysLocal SLIT("tpl") u ty mkBuiltinSrcLoc)
1177 1178 1179 1180 1181
	    (getBuiltinUniques (length tys))
	    tys
\end{code}

\begin{code}
1182 1183
getIdInfo     :: GenId ty -> IdInfo
getPragmaInfo :: GenId ty -> PragmaInfo
1184

1185 1186
getIdInfo     (Id _ _ _ _ _ info) = info
getPragmaInfo (Id _ _ _ _ info _) = info
1187

1188
{-LATER:
1189 1190
replaceIdInfo :: Id -> IdInfo -> Id

1191
replaceIdInfo (Id u n ty _ details) info = Id u n ty info details