789abe48c09d5958e6544d1f4f73f0680bf41e63
[ghc-hetmet.git] / compiler / coreSyn / MkCore.lhs
1 \begin{code}
2 -- | Handy functions for creating much Core syntax
3 module MkCore (
4         -- * Constructing normal syntax
5         mkCoreLet, mkCoreLets,
6         mkCoreApp, mkCoreApps, mkCoreConApps,
7         mkCoreLams, mkWildCase, mkWildBinder, mkIfThenElse,
8         
9         -- * Constructing boxed literals
10         mkWordExpr, mkWordExprWord,
11         mkIntExpr, mkIntExprInt,
12         mkIntegerExpr,
13         mkFloatExpr, mkDoubleExpr,
14         mkCharExpr, mkStringExpr, mkStringExprFS,
15         
16         -- * Constructing general big tuples
17         -- $big_tuples
18         mkChunkified,
19         
20         -- * Constructing small tuples
21         mkCoreVarTup, mkCoreVarTupTy,
22         mkCoreTup, mkCoreTupTy,
23         
24         -- * Constructing big tuples
25         mkBigCoreVarTup, mkBigCoreVarTupTy,
26         mkBigCoreTup, mkBigCoreTupTy,
27         
28         -- * Deconstructing small tuples
29         mkSmallTupleSelector, mkSmallTupleCase,
30         
31         -- * Deconstructing big tuples
32         mkTupleSelector, mkTupleCase,
33         
34         -- * Constructing list expressions
35         mkNilExpr, mkConsExpr, mkListExpr, 
36         mkFoldrExpr, mkBuildExpr
37     ) where
38
39 #include "HsVersions.h"
40
41 import Id
42 import Var      ( setTyVarUnique )
43
44 import CoreSyn
45 import CoreUtils        ( exprType, needsCaseBinding, bindNonRec )
46 import Literal
47 import HscTypes
48
49 import TysWiredIn
50 import PrelNames
51
52 import Type
53 import TysPrim          ( alphaTyVar )
54 import DataCon          ( DataCon, dataConWorkId )
55
56 import FastString
57 import UniqSupply
58 import Unique           ( mkBuiltinUnique )
59 import BasicTypes
60 import Util             ( notNull, zipEqual )
61 import Panic
62 import Constants
63
64 import Data.Char        ( ord )
65 import Data.Word
66
67 infixl 4 `mkCoreApp`, `mkCoreApps`
68 \end{code}
69
70 %************************************************************************
71 %*                                                                      *
72 \subsection{Basic CoreSyn construction}
73 %*                                                                      *
74 %************************************************************************
75
76 \begin{code}
77 -- | Bind a binding group over an expression, using a @let@ or @case@ as
78 -- appropriate (see "CoreSyn#let_app_invariant")
79 mkCoreLet :: CoreBind -> CoreExpr -> CoreExpr
80 mkCoreLet (NonRec bndr rhs) body        -- See Note [CoreSyn let/app invariant]
81   | needsCaseBinding (idType bndr) rhs
82   = Case rhs bndr (exprType body) [(DEFAULT,[],body)]
83 mkCoreLet bind body
84   = Let bind body
85
86 -- | Bind a list of binding groups over an expression. The leftmost binding
87 -- group becomes the outermost group in the resulting expression
88 mkCoreLets :: [CoreBind] -> CoreExpr -> CoreExpr
89 mkCoreLets binds body = foldr mkCoreLet body binds
90
91 -- | Construct an expression which represents the application of one expression
92 -- to the other
93 mkCoreApp :: CoreExpr -> CoreExpr -> CoreExpr
94 -- Check the invariant that the arg of an App is ok-for-speculation if unlifted
95 -- See CoreSyn Note [CoreSyn let/app invariant]
96 mkCoreApp fun (Type ty) = App fun (Type ty)
97 mkCoreApp fun arg       = mk_val_app fun arg arg_ty res_ty
98                       where
99                         (arg_ty, res_ty) = splitFunTy (exprType fun)
100
101 -- | Construct an expression which represents the application of a number of
102 -- expressions to another. The leftmost expression in the list is applied first
103 mkCoreApps :: CoreExpr -> [CoreExpr] -> CoreExpr
104 -- Slightly more efficient version of (foldl mkCoreApp)
105 mkCoreApps fun args
106   = go fun (exprType fun) args
107   where
108     go fun _      []               = fun
109     go fun fun_ty (Type ty : args) = go (App fun (Type ty)) (applyTy fun_ty ty) args
110     go fun fun_ty (arg     : args) = go (mk_val_app fun arg arg_ty res_ty) res_ty args
111                                    where
112                                      (arg_ty, res_ty) = splitFunTy fun_ty
113
114 -- | Construct an expression which represents the application of a number of
115 -- expressions to that of a data constructor expression. The leftmost expression
116 -- in the list is applied first
117 mkCoreConApps :: DataCon -> [CoreExpr] -> CoreExpr
118 mkCoreConApps con args = mkCoreApps (Var (dataConWorkId con)) args
119
120 -----------
121 mk_val_app :: CoreExpr -> CoreExpr -> Type -> Type -> CoreExpr
122 mk_val_app fun arg arg_ty _        -- See Note [CoreSyn let/app invariant]
123   | not (needsCaseBinding arg_ty arg)
124   = App fun arg                -- The vastly common case
125
126 mk_val_app fun arg arg_ty res_ty
127   = Case arg arg_id res_ty [(DEFAULT,[],App fun (Var arg_id))]
128   where
129     arg_id = mkWildBinder arg_ty    
130         -- Lots of shadowing, but it doesn't matter,
131         -- because 'fun ' should not have a free wild-id
132         --
133         -- This is Dangerous.  But this is the only place we play this 
134         -- game, mk_val_app returns an expression that does not have
135         -- have a free wild-id.  So the only thing that can go wrong
136         -- is if you take apart this case expression, and pass a 
137         -- fragmet of it as the fun part of a 'mk_val_app'.
138
139
140 -- | Make a /wildcard binder/. This is typically used when you need a binder 
141 -- that you expect to use only at a *binding* site.  Do not use it at
142 -- occurrence sites because it has a single, fixed unique, and it's very
143 -- easy to get into difficulties with shadowing.  That's why it is used so little.
144 mkWildBinder :: Type -> Id
145 mkWildBinder ty = mkSysLocal (fsLit "wild") (mkBuiltinUnique 1) ty
146
147 mkWildCase :: CoreExpr -> Type -> Type -> [CoreAlt] -> CoreExpr
148 -- Make a case expression whose case binder is unused
149 -- The alts should not have any occurrences of WildId
150 mkWildCase scrut scrut_ty res_ty alts 
151   = Case scrut (mkWildBinder scrut_ty) res_ty alts
152
153 mkIfThenElse :: CoreExpr -> CoreExpr -> CoreExpr -> CoreExpr
154 mkIfThenElse guard then_expr else_expr
155 -- Not going to be refining, so okay to take the type of the "then" clause
156   = mkWildCase guard boolTy (exprType then_expr) 
157          [ (DataAlt falseDataCon, [], else_expr),       -- Increasing order of tag!
158            (DataAlt trueDataCon,  [], then_expr) ]
159 \end{code}
160
161 The functions from this point don't really do anything cleverer than
162 their counterparts in CoreSyn, but they are here for consistency
163
164 \begin{code}
165 -- | Create a lambda where the given expression has a number of variables
166 -- bound over it. The leftmost binder is that bound by the outermost
167 -- lambda in the result
168 mkCoreLams :: [CoreBndr] -> CoreExpr -> CoreExpr
169 mkCoreLams = mkLams
170 \end{code}
171
172 %************************************************************************
173 %*                                                                      *
174 \subsection{Making literals}
175 %*                                                                      *
176 %************************************************************************
177
178 \begin{code}
179 -- | Create a 'CoreExpr' which will evaluate to the given @Int@
180 mkIntExpr      :: Integer    -> CoreExpr            -- Result = I# i :: Int
181 mkIntExpr  i = mkConApp intDataCon  [mkIntLit i]
182
183 -- | Create a 'CoreExpr' which will evaluate to the given @Int@
184 mkIntExprInt   :: Int        -> CoreExpr            -- Result = I# i :: Int
185 mkIntExprInt  i = mkConApp intDataCon  [mkIntLitInt i]
186
187 -- | Create a 'CoreExpr' which will evaluate to the a @Word@ with the given value
188 mkWordExpr     :: Integer    -> CoreExpr
189 mkWordExpr w = mkConApp wordDataCon [mkWordLit w]
190
191 -- | Create a 'CoreExpr' which will evaluate to the given @Word@
192 mkWordExprWord :: Word       -> CoreExpr
193 mkWordExprWord w = mkConApp wordDataCon [mkWordLitWord w]
194
195 -- | Create a 'CoreExpr' which will evaluate to the given @Integer@
196 mkIntegerExpr  :: MonadThings m => Integer    -> m CoreExpr  -- Result :: Integer
197 mkIntegerExpr i
198   | inIntRange i        -- Small enough, so start from an Int
199     = do integer_id <- lookupId smallIntegerName
200          return (mkSmallIntegerLit integer_id i)
201
202 -- Special case for integral literals with a large magnitude:
203 -- They are transformed into an expression involving only smaller
204 -- integral literals. This improves constant folding.
205
206   | otherwise = do       -- Big, so start from a string
207       plus_id <- lookupId plusIntegerName
208       times_id <- lookupId timesIntegerName
209       integer_id <- lookupId smallIntegerName
210       let
211            lit i = mkSmallIntegerLit integer_id i
212            plus a b  = Var plus_id  `App` a `App` b
213            times a b = Var times_id `App` a `App` b
214
215            -- Transform i into (x1 + (x2 + (x3 + (...) * b) * b) * b) with abs xi <= b
216            horner :: Integer -> Integer -> CoreExpr
217            horner b i | abs q <= 1 = if r == 0 || r == i 
218                                      then lit i 
219                                      else lit r `plus` lit (i-r)
220                       | r == 0     =               horner b q `times` lit b
221                       | otherwise  = lit r `plus` (horner b q `times` lit b)
222                       where
223                         (q,r) = i `quotRem` b
224
225       return (horner tARGET_MAX_INT i)
226   where
227     mkSmallIntegerLit :: Id -> Integer -> CoreExpr
228     mkSmallIntegerLit small_integer i = mkApps (Var small_integer) [mkIntLit i]
229
230
231 -- | Create a 'CoreExpr' which will evaluate to the given @Float@
232 mkFloatExpr :: Float -> CoreExpr
233 mkFloatExpr f = mkConApp floatDataCon [mkFloatLitFloat f]
234
235 -- | Create a 'CoreExpr' which will evaluate to the given @Double@
236 mkDoubleExpr :: Double -> CoreExpr
237 mkDoubleExpr d = mkConApp doubleDataCon [mkDoubleLitDouble d]
238
239
240 -- | Create a 'CoreExpr' which will evaluate to the given @Char@
241 mkCharExpr     :: Char             -> CoreExpr      -- Result = C# c :: Int
242 mkCharExpr c = mkConApp charDataCon [mkCharLit c]
243
244 -- | Create a 'CoreExpr' which will evaluate to the given @String@
245 mkStringExpr   :: MonadThings m => String     -> m CoreExpr  -- Result :: String
246 -- | Create a 'CoreExpr' which will evaluate to a string morally equivalent to the given @FastString@
247 mkStringExprFS :: MonadThings m => FastString -> m CoreExpr  -- Result :: String
248
249 mkStringExpr str = mkStringExprFS (mkFastString str)
250
251 mkStringExprFS str
252   | nullFS str
253   = return (mkNilExpr charTy)
254
255   | lengthFS str == 1
256   = do let the_char = mkCharExpr (headFS str)
257        return (mkConsExpr charTy the_char (mkNilExpr charTy))
258
259   | all safeChar chars
260   = do unpack_id <- lookupId unpackCStringName
261        return (App (Var unpack_id) (Lit (MachStr str)))
262
263   | otherwise
264   = do unpack_id <- lookupId unpackCStringUtf8Name
265        return (App (Var unpack_id) (Lit (MachStr str)))
266
267   where
268     chars = unpackFS str
269     safeChar c = ord c >= 1 && ord c <= 0x7F
270 \end{code}
271
272 %************************************************************************
273 %*                                                                      *
274 \subsection{Tuple constructors}
275 %*                                                                      *
276 %************************************************************************
277
278 \begin{code}
279
280 -- $big_tuples
281 -- #big_tuples#
282 --
283 -- GHCs built in tuples can only go up to 'mAX_TUPLE_SIZE' in arity, but
284 -- we might concievably want to build such a massive tuple as part of the
285 -- output of a desugaring stage (notably that for list comprehensions).
286 --
287 -- We call tuples above this size \"big tuples\", and emulate them by
288 -- creating and pattern matching on >nested< tuples that are expressible
289 -- by GHC.
290 --
291 -- Nesting policy: it's better to have a 2-tuple of 10-tuples (3 objects)
292 -- than a 10-tuple of 2-tuples (11 objects), so we want the leaves of any
293 -- construction to be big.
294 --
295 -- If you just use the 'mkBigCoreTup', 'mkBigCoreVarTupTy', 'mkTupleSelector'
296 -- and 'mkTupleCase' functions to do all your work with tuples you should be
297 -- fine, and not have to worry about the arity limitation at all.
298
299 -- | Lifts a \"small\" constructor into a \"big\" constructor by recursive decompositon
300 mkChunkified :: ([a] -> a)      -- ^ \"Small\" constructor function, of maximum input arity 'mAX_TUPLE_SIZE'
301              -> [a]             -- ^ Possible \"big\" list of things to construct from
302              -> a               -- ^ Constructed thing made possible by recursive decomposition
303 mkChunkified small_tuple as = mk_big_tuple (chunkify as)
304   where
305         -- Each sub-list is short enough to fit in a tuple
306     mk_big_tuple [as] = small_tuple as
307     mk_big_tuple as_s = mk_big_tuple (chunkify (map small_tuple as_s))
308
309 chunkify :: [a] -> [[a]]
310 -- ^ Split a list into lists that are small enough to have a corresponding
311 -- tuple arity. The sub-lists of the result all have length <= 'mAX_TUPLE_SIZE'
312 -- But there may be more than 'mAX_TUPLE_SIZE' sub-lists
313 chunkify xs
314   | n_xs <= mAX_TUPLE_SIZE = [xs] 
315   | otherwise              = split xs
316   where
317     n_xs     = length xs
318     split [] = []
319     split xs = take mAX_TUPLE_SIZE xs : split (drop mAX_TUPLE_SIZE xs)
320     
321 \end{code}
322
323 Creating tuples and their types for Core expressions 
324
325 @mkBigCoreVarTup@ builds a tuple; the inverse to @mkTupleSelector@.  
326
327 * If it has only one element, it is the identity function.
328
329 * If there are more elements than a big tuple can have, it nests 
330   the tuples.  
331
332 \begin{code}
333
334 -- | Build a small tuple holding the specified variables
335 mkCoreVarTup :: [Id] -> CoreExpr
336 mkCoreVarTup ids = mkCoreTup (map Var ids)
337
338 -- | Bulid the type of a small tuple that holds the specified variables
339 mkCoreVarTupTy :: [Id] -> Type
340 mkCoreVarTupTy ids = mkCoreTupTy (map idType ids)
341
342 -- | Build a small tuple holding the specified expressions
343 mkCoreTup :: [CoreExpr] -> CoreExpr
344 mkCoreTup []  = Var unitDataConId
345 mkCoreTup [c] = c
346 mkCoreTup cs  = mkConApp (tupleCon Boxed (length cs))
347                          (map (Type . exprType) cs ++ cs)
348
349 -- | Build the type of a small tuple that holds the specified type of thing
350 mkCoreTupTy :: [Type] -> Type
351 mkCoreTupTy tys  = mkTupleTy Boxed tys
352
353 -- | Build a big tuple holding the specified variables
354 mkBigCoreVarTup :: [Id] -> CoreExpr
355 mkBigCoreVarTup ids = mkBigCoreTup (map Var ids)
356
357 -- | Build the type of a big tuple that holds the specified variables
358 mkBigCoreVarTupTy :: [Id] -> Type
359 mkBigCoreVarTupTy ids = mkBigCoreTupTy (map idType ids)
360
361 -- | Build a big tuple holding the specified expressions
362 mkBigCoreTup :: [CoreExpr] -> CoreExpr
363 mkBigCoreTup = mkChunkified mkCoreTup
364
365 -- | Build the type of a big tuple that holds the specified type of thing
366 mkBigCoreTupTy :: [Type] -> Type
367 mkBigCoreTupTy = mkChunkified mkCoreTupTy
368 \end{code}
369
370 %************************************************************************
371 %*                                                                      *
372 \subsection{Tuple destructors}
373 %*                                                                      *
374 %************************************************************************
375
376 \begin{code}
377 -- | Builds a selector which scrutises the given
378 -- expression and extracts the one name from the list given.
379 -- If you want the no-shadowing rule to apply, the caller
380 -- is responsible for making sure that none of these names
381 -- are in scope.
382 --
383 -- If there is just one 'Id' in the tuple, then the selector is
384 -- just the identity.
385 --
386 -- If necessary, we pattern match on a \"big\" tuple.
387 mkTupleSelector :: [Id]         -- ^ The 'Id's to pattern match the tuple against
388                 -> Id           -- ^ The 'Id' to select
389                 -> Id           -- ^ A variable of the same type as the scrutinee
390                 -> CoreExpr     -- ^ Scrutinee
391                 -> CoreExpr     -- ^ Selector expression
392
393 -- mkTupleSelector [a,b,c,d] b v e
394 --          = case e of v { 
395 --                (p,q) -> case p of p {
396 --                           (a,b) -> b }}
397 -- We use 'tpl' vars for the p,q, since shadowing does not matter.
398 --
399 -- In fact, it's more convenient to generate it innermost first, getting
400 --
401 --        case (case e of v 
402 --                (p,q) -> p) of p
403 --          (a,b) -> b
404 mkTupleSelector vars the_var scrut_var scrut
405   = mk_tup_sel (chunkify vars) the_var
406   where
407     mk_tup_sel [vars] the_var = mkSmallTupleSelector vars the_var scrut_var scrut
408     mk_tup_sel vars_s the_var = mkSmallTupleSelector group the_var tpl_v $
409                                 mk_tup_sel (chunkify tpl_vs) tpl_v
410         where
411           tpl_tys = [mkCoreTupTy (map idType gp) | gp <- vars_s]
412           tpl_vs  = mkTemplateLocals tpl_tys
413           [(tpl_v, group)] = [(tpl,gp) | (tpl,gp) <- zipEqual "mkTupleSelector" tpl_vs vars_s,
414                                          the_var `elem` gp ]
415 \end{code}
416
417 \begin{code}
418 -- | Like 'mkTupleSelector' but for tuples that are guaranteed
419 -- never to be \"big\".
420 --
421 -- > mkSmallTupleSelector [x] x v e = [| e |]
422 -- > mkSmallTupleSelector [x,y,z] x v e = [| case e of v { (x,y,z) -> x } |]
423 mkSmallTupleSelector :: [Id]        -- The tuple args
424           -> Id         -- The selected one
425           -> Id         -- A variable of the same type as the scrutinee
426           -> CoreExpr        -- Scrutinee
427           -> CoreExpr
428 mkSmallTupleSelector [var] should_be_the_same_var _ scrut
429   = ASSERT(var == should_be_the_same_var)
430     scrut
431 mkSmallTupleSelector vars the_var scrut_var scrut
432   = ASSERT( notNull vars )
433     Case scrut scrut_var (idType the_var)
434          [(DataAlt (tupleCon Boxed (length vars)), vars, Var the_var)]
435 \end{code}
436
437 \begin{code}
438 -- | A generalization of 'mkTupleSelector', allowing the body
439 -- of the case to be an arbitrary expression.
440 --
441 -- To avoid shadowing, we use uniques to invent new variables.
442 --
443 -- If necessary we pattern match on a \"big\" tuple.
444 mkTupleCase :: UniqSupply       -- ^ For inventing names of intermediate variables
445             -> [Id]             -- ^ The tuple identifiers to pattern match on
446             -> CoreExpr         -- ^ Body of the case
447             -> Id               -- ^ A variable of the same type as the scrutinee
448             -> CoreExpr         -- ^ Scrutinee
449             -> CoreExpr
450 -- ToDo: eliminate cases where none of the variables are needed.
451 --
452 --         mkTupleCase uniqs [a,b,c,d] body v e
453 --           = case e of v { (p,q) ->
454 --             case p of p { (a,b) ->
455 --             case q of q { (c,d) ->
456 --             body }}}
457 mkTupleCase uniqs vars body scrut_var scrut
458   = mk_tuple_case uniqs (chunkify vars) body
459   where
460     -- This is the case where don't need any nesting
461     mk_tuple_case _ [vars] body
462       = mkSmallTupleCase vars body scrut_var scrut
463       
464     -- This is the case where we must make nest tuples at least once
465     mk_tuple_case us vars_s body
466       = let (us', vars', body') = foldr one_tuple_case (us, [], body) vars_s
467             in mk_tuple_case us' (chunkify vars') body'
468     
469     one_tuple_case chunk_vars (us, vs, body)
470       = let (us1, us2) = splitUniqSupply us
471             scrut_var = mkSysLocal (fsLit "ds") (uniqFromSupply us1)
472               (mkCoreTupTy (map idType chunk_vars))
473             body' = mkSmallTupleCase chunk_vars body scrut_var (Var scrut_var)
474         in (us2, scrut_var:vs, body')
475 \end{code}
476
477 \begin{code}
478 -- | As 'mkTupleCase', but for a tuple that is small enough to be guaranteed
479 -- not to need nesting.
480 mkSmallTupleCase
481         :: [Id]         -- ^ The tuple args
482         -> CoreExpr     -- ^ Body of the case
483         -> Id           -- ^ A variable of the same type as the scrutinee
484         -> CoreExpr     -- ^ Scrutinee
485         -> CoreExpr
486
487 mkSmallTupleCase [var] body _scrut_var scrut
488   = bindNonRec var scrut body
489 mkSmallTupleCase vars body scrut_var scrut
490 -- One branch no refinement?
491   = Case scrut scrut_var (exprType body) [(DataAlt (tupleCon Boxed (length vars)), vars, body)]
492 \end{code}
493
494 %************************************************************************
495 %*                                                                      *
496 \subsection{Common list manipulation expressions}
497 %*                                                                      *
498 %************************************************************************
499
500 Call the constructor Ids when building explicit lists, so that they
501 interact well with rules.
502
503 \begin{code}
504 -- | Makes a list @[]@ for lists of the specified type
505 mkNilExpr :: Type -> CoreExpr
506 mkNilExpr ty = mkConApp nilDataCon [Type ty]
507
508 -- | Makes a list @(:)@ for lists of the specified type
509 mkConsExpr :: Type -> CoreExpr -> CoreExpr -> CoreExpr
510 mkConsExpr ty hd tl = mkConApp consDataCon [Type ty, hd, tl]
511
512 -- | Make a list containing the given expressions, where the list has the given type
513 mkListExpr :: Type -> [CoreExpr] -> CoreExpr
514 mkListExpr ty xs = foldr (mkConsExpr ty) (mkNilExpr ty) xs
515
516 -- | Make a fully applied 'foldr' expression
517 mkFoldrExpr :: MonadThings m
518             => Type             -- ^ Element type of the list
519             -> Type             -- ^ Fold result type
520             -> CoreExpr         -- ^ "Cons" function expression for the fold
521             -> CoreExpr         -- ^ "Nil" expression for the fold
522             -> CoreExpr         -- ^ List expression being folded acress
523             -> m CoreExpr
524 mkFoldrExpr elt_ty result_ty c n list = do
525     foldr_id <- lookupId foldrName
526     return (Var foldr_id `App` Type elt_ty 
527            `App` Type result_ty
528            `App` c
529            `App` n
530            `App` list)
531
532 -- | Make a 'build' expression applied to a locally-bound worker function
533 mkBuildExpr :: (MonadThings m, MonadUnique m)
534             => Type                                     -- ^ Type of list elements to be built
535             -> ((Id, Type) -> (Id, Type) -> m CoreExpr) -- ^ Function that, given information about the 'Id's
536                                                         -- of the binders for the build worker function, returns
537                                                         -- the body of that worker
538             -> m CoreExpr
539 mkBuildExpr elt_ty mk_build_inside = do
540     [n_tyvar] <- newTyVars [alphaTyVar]
541     let n_ty = mkTyVarTy n_tyvar
542         c_ty = mkFunTys [elt_ty, n_ty] n_ty
543     [c, n] <- sequence [mkSysLocalM (fsLit "c") c_ty, mkSysLocalM (fsLit "n") n_ty]
544     
545     build_inside <- mk_build_inside (c, c_ty) (n, n_ty)
546     
547     build_id <- lookupId buildName
548     return $ Var build_id `App` Type elt_ty `App` mkLams [n_tyvar, c, n] build_inside
549   where
550     newTyVars tyvar_tmpls = do
551       uniqs <- getUniquesM
552       return (zipWith setTyVarUnique tyvar_tmpls uniqs)
553 \end{code}