@@ -247,8 +247,9 @@ enum mode { m_collect, m_check, m_check_tyvar(@fn_ctxt), }
247
247
// internal notion of a type. `getter` is a function that returns the type
248
248
// corresponding to a definition ID:
249
249
fn ast_ty_to_ty ( tcx : ty:: ctxt , mode : mode , & & ast_ty: @ast:: ty ) -> ty:: t {
250
- fn getter ( tcx : ty:: ctxt , mode : mode , id : ast:: def_id )
251
- -> ty:: ty_param_bounds_and_ty {
250
+ fn getter ( tcx : ty:: ctxt , _use_site : ast:: node_id , mode : mode ,
251
+ id : ast:: def_id ) -> ty:: ty_param_bounds_and_ty {
252
+ // FIXME (pcwalton): Doesn't work with region inference.
252
253
alt mode {
253
254
m_check | m_check_tyvar ( _) { ty:: lookup_item_type ( tcx, id) }
254
255
m_collect {
@@ -269,23 +270,14 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
269
270
}
270
271
}
271
272
}
272
- alt tcx. ast_ty_to_ty_cache . find ( ast_ty) {
273
- some ( ty:: atttce_resolved ( ty) ) { ret ty; }
274
- some ( ty:: atttce_unresolved) {
275
- tcx. sess . span_fatal ( ast_ty. span , "illegal recursive type. \
276
- insert a enum in the cycle, \
277
- if this is desired)") ;
278
- }
279
- some ( ty:: atttce_has_regions) | none { /* go on */ }
280
- }
281
-
282
- tcx. ast_ty_to_ty_cache . insert ( ast_ty, ty:: atttce_unresolved) ;
283
- fn ast_mt_to_mt ( tcx : ty:: ctxt , mode : mode , mt : ast:: mt ) -> ty:: mt {
284
- ret { ty : ast_ty_to_ty ( tcx, mode, mt. ty ) , mutbl : mt. mutbl } ;
273
+ fn ast_mt_to_mt ( tcx : ty:: ctxt , use_site : ast:: node_id , mode : mode ,
274
+ mt : ast:: mt ) -> ty:: mt {
275
+ ret { ty : do_ast_ty_to_ty ( tcx, use_site, mode, mt. ty ) ,
276
+ mutbl : mt. mutbl } ;
285
277
}
286
- fn instantiate ( tcx : ty:: ctxt , sp : span , mode : mode ,
287
- id : ast:: def_id , args : [ @ast:: ty ] ) -> ty:: t {
288
- let ty_param_bounds_and_ty = getter ( tcx, mode, id) ;
278
+ fn instantiate ( tcx : ty:: ctxt , use_site : ast :: node_id , sp : span ,
279
+ mode : mode , id : ast:: def_id , args : [ @ast:: ty ] ) -> ty:: t {
280
+ let ty_param_bounds_and_ty = getter ( tcx, use_site , mode, id) ;
289
281
if vec:: len ( * ty_param_bounds_and_ty. bounds ) == 0 u {
290
282
ret ty_param_bounds_and_ty. ty ;
291
283
}
@@ -297,142 +289,167 @@ fn ast_ty_to_ty(tcx: ty::ctxt, mode: mode, &&ast_ty: @ast::ty) -> ty::t {
297
289
polymorphic type") ;
298
290
}
299
291
for ast_ty: @ast:: ty in args {
300
- param_bindings += [ ast_ty_to_ty ( tcx, mode, ast_ty) ] ;
292
+ param_bindings += [ do_ast_ty_to_ty ( tcx, use_site , mode, ast_ty) ] ;
301
293
}
302
294
let typ =
303
295
ty:: substitute_type_params ( tcx, param_bindings,
304
296
ty_param_bounds_and_ty. ty ) ;
305
297
ret typ;
306
298
}
307
- let typ = alt ast_ty. node {
308
- ast:: ty_nil { ty : : mk_nil ( tcx) }
309
- ast:: ty_bot { ty : : mk_bot ( tcx) }
310
- ast:: ty_box ( mt) {
311
- ty:: mk_box ( tcx, ast_mt_to_mt ( tcx, mode, mt) )
312
- }
313
- ast:: ty_uniq ( mt) {
314
- ty:: mk_uniq ( tcx, ast_mt_to_mt ( tcx, mode, mt) )
315
- }
316
- ast:: ty_vec ( mt) {
317
- ty:: mk_vec ( tcx, ast_mt_to_mt ( tcx, mode, mt) )
318
- }
319
- ast:: ty_ptr ( mt) {
320
- ty:: mk_ptr ( tcx, ast_mt_to_mt ( tcx, mode, mt) )
321
- }
322
- ast:: ty_rptr ( region, mt) {
323
- let region = alt region. node {
324
- ast:: re_inferred | ast:: re_self {
325
- tcx. region_map . ast_type_to_inferred_region . get ( ast_ty. id )
326
- }
327
- ast:: re_named ( _) {
328
- tcx. region_map . ast_type_to_region . get ( region. id )
329
- }
330
- } ;
331
- ty:: mk_rptr ( tcx, region, ast_mt_to_mt ( tcx, mode, mt) )
332
- }
333
- ast:: ty_tup ( fields) {
334
- let flds = vec:: map ( fields, bind ast_ty_to_ty ( tcx, mode, _) ) ;
335
- ty:: mk_tup ( tcx, flds)
336
- }
337
- ast:: ty_rec ( fields) {
338
- let flds: [ field ] = [ ] ;
339
- for f: ast:: ty_field in fields {
340
- let tm = ast_mt_to_mt ( tcx, mode, f. node . mt ) ;
341
- flds += [ { ident: f. node . ident , mt: tm} ] ;
342
- }
343
- ty:: mk_rec ( tcx, flds)
344
- }
345
- ast:: ty_fn ( proto, decl) {
346
- ty:: mk_fn ( tcx, ty_of_fn_decl ( tcx, mode, proto, decl) )
347
- }
348
- ast:: ty_path ( path, id) {
349
- let a_def = alt tcx. def_map . find ( id) {
350
- none { tcx. sess . span_fatal ( ast_ty. span , #fmt ( "unbound path %s" ,
351
- path_to_str ( path) ) ) ; }
352
- some ( d) { d } } ;
353
- alt a_def {
354
- ast : : def_ty ( id) {
355
- instantiate ( tcx, ast_ty. span , mode, id, path. node . types )
356
- }
357
- ast:: def_prim_ty ( nty) {
358
- alt nty {
359
- ast : : ty_bool { ty : : mk_bool ( tcx) }
360
- ast:: ty_int ( it) { ty:: mk_mach_int ( tcx, it) }
361
- ast:: ty_uint ( uit) { ty:: mk_mach_uint ( tcx, uit) }
362
- ast:: ty_float ( ft) { ty:: mk_mach_float ( tcx, ft) }
363
- ast:: ty_str { ty : : mk_str ( tcx) }
364
- }
299
+ fn do_ast_ty_to_ty ( tcx : ty:: ctxt , use_site : ast:: node_id , mode : mode ,
300
+ & & ast_ty: @ast:: ty ) -> ty:: t {
301
+ alt tcx. ast_ty_to_ty_cache . find ( ast_ty) {
302
+ some ( ty:: atttce_resolved ( ty) ) { ret ty; }
303
+ some ( ty:: atttce_unresolved) {
304
+ tcx. sess . span_fatal ( ast_ty. span , "illegal recursive type. \
305
+ insert a enum in the cycle, \
306
+ if this is desired)") ;
307
+ }
308
+ some ( ty:: atttce_has_regions) | none { /* go on */ }
309
+ }
310
+
311
+ tcx. ast_ty_to_ty_cache . insert ( ast_ty, ty:: atttce_unresolved) ;
312
+ let typ = alt ast_ty. node {
313
+ ast:: ty_nil { ty : : mk_nil ( tcx) }
314
+ ast:: ty_bot { ty : : mk_bot ( tcx) }
315
+ ast:: ty_box ( mt) {
316
+ ty:: mk_box ( tcx, ast_mt_to_mt ( tcx, use_site, mode, mt) )
365
317
}
366
- ast:: def_ty_param ( id, n) {
367
- if vec:: len ( path. node . types ) > 0 u {
368
- tcx. sess . span_err ( ast_ty. span , "provided type parameters to \
369
- a type parameter") ;
318
+ ast:: ty_uniq ( mt) {
319
+ ty:: mk_uniq ( tcx, ast_mt_to_mt ( tcx, use_site, mode, mt) )
320
+ }
321
+ ast:: ty_vec ( mt) {
322
+ ty:: mk_vec ( tcx, ast_mt_to_mt ( tcx, use_site, mode, mt) )
323
+ }
324
+ ast:: ty_ptr ( mt) {
325
+ ty:: mk_ptr ( tcx, ast_mt_to_mt ( tcx, use_site, mode, mt) )
326
+ }
327
+ ast:: ty_rptr ( region, mt) {
328
+ let region = alt region. node {
329
+ ast:: re_inferred | ast:: re_self {
330
+ tcx. region_map . ast_type_to_inferred_region . get ( ast_ty. id )
331
+ }
332
+ ast:: re_named ( _) {
333
+ tcx. region_map . ast_type_to_region . get ( region. id )
334
+ }
335
+ } ;
336
+ ty:: mk_rptr ( tcx, region, ast_mt_to_mt ( tcx, use_site, mode, mt) )
337
+ }
338
+ ast:: ty_tup ( fields) {
339
+ let flds = vec:: map ( fields,
340
+ bind do_ast_ty_to_ty ( tcx, use_site, mode, _) ) ;
341
+ ty:: mk_tup ( tcx, flds)
342
+ }
343
+ ast:: ty_rec ( fields) {
344
+ let flds: [ field ] = [ ] ;
345
+ for f: ast:: ty_field in fields {
346
+ let tm = ast_mt_to_mt ( tcx, use_site, mode, f. node . mt ) ;
347
+ flds += [ { ident: f. node . ident , mt: tm} ] ;
370
348
}
371
- ty:: mk_param ( tcx, n, id)
372
- }
373
- ast:: def_self ( self_id) {
374
- alt check tcx. items . get ( self_id) {
375
- ast_map:: node_item ( @{ node: ast:: item_iface ( tps, _) , _} , _) {
376
- if vec:: len ( tps) != vec:: len ( path. node . types ) {
377
- tcx. sess . span_err ( ast_ty. span , "incorrect number of type \
378
- parameter to self type") ;
349
+ ty:: mk_rec ( tcx, flds)
350
+ }
351
+ ast:: ty_fn ( proto, decl) {
352
+ ty:: mk_fn ( tcx, ty_of_fn_decl ( tcx, mode, proto, decl) )
353
+ }
354
+ ast:: ty_path ( path, id) {
355
+ let a_def = alt tcx. def_map . find ( id) {
356
+ none { tcx. sess . span_fatal ( ast_ty. span , #fmt ( "unbound path %s" ,
357
+ path_to_str ( path) ) ) ; }
358
+ some ( d) { d } } ;
359
+ alt a_def {
360
+ ast : : def_ty ( id) {
361
+ instantiate ( tcx, use_site, ast_ty. span , mode, id,
362
+ path. node . types )
363
+ }
364
+ ast:: def_prim_ty ( nty) {
365
+ alt nty {
366
+ ast : : ty_bool { ty : : mk_bool ( tcx) }
367
+ ast:: ty_int ( it) { ty:: mk_mach_int ( tcx, it) }
368
+ ast:: ty_uint ( uit) { ty:: mk_mach_uint ( tcx, uit) }
369
+ ast:: ty_float ( ft) { ty:: mk_mach_float ( tcx, ft) }
370
+ ast:: ty_str { ty : : mk_str ( tcx) }
379
371
}
380
- ty:: mk_self ( tcx, vec:: map ( path. node . types , { |ast_ty|
381
- ast_ty_to_ty ( tcx, mode, ast_ty)
382
- } ) )
383
372
}
384
- }
385
- }
386
- ast:: def_class ( class_id) {
387
- alt tcx. items . find ( class_id. node ) {
388
- some ( ast_map:: node_item (
389
- @{ node: ast:: item_class ( tps, _, _) , _} , _) ) {
390
- if vec:: len ( tps) != vec:: len ( path. node . types ) {
373
+ ast:: def_ty_param ( id, n) {
374
+ if vec:: len ( path. node . types ) > 0 u {
375
+ tcx. sess . span_err ( ast_ty. span , "provided type parameters \
376
+ to a type parameter") ;
377
+ }
378
+ ty:: mk_param ( tcx, n, id)
379
+ }
380
+ ast:: def_self ( self_id) {
381
+ alt check tcx. items . get ( self_id) {
382
+ ast_map:: node_item ( @{ node: ast:: item_iface ( tps, _) , _} , _) {
383
+ if vec:: len ( tps) != vec:: len ( path. node . types ) {
391
384
tcx. sess . span_err ( ast_ty. span , "incorrect number of \
392
- type parameters to object type") ;
385
+ type parameters to \
386
+ self type") ;
387
+ }
388
+ ty:: mk_self ( tcx, vec:: map ( path. node . types , { |ast_ty|
389
+ do_ast_ty_to_ty ( tcx, use_site, mode, ast_ty)
390
+ } ) )
391
+ }
392
+ }
393
+ }
394
+ ast:: def_class ( class_id) {
395
+ alt tcx. items . find ( class_id. node ) {
396
+ some ( ast_map:: node_item (
397
+ @{ node: ast:: item_class ( tps, _, _) , _} , _) ) {
398
+ if vec:: len ( tps) != vec:: len ( path. node . types ) {
399
+ tcx. sess . span_err ( ast_ty. span , "incorrect number \
400
+ of type parameters to object type") ;
401
+ }
402
+ ty:: mk_class ( tcx, class_id,
403
+ vec:: map ( path. node . types , { |ast_ty|
404
+ do_ast_ty_to_ty ( tcx,
405
+ use_site,
406
+ mode,
407
+ ast_ty)
408
+ } ) )
393
409
}
394
- ty:: mk_class ( tcx, class_id, vec:: map ( path. node . types ,
395
- { |ast_ty| ast_ty_to_ty ( tcx, mode, ast_ty) } ) )
396
- }
397
- _ {
398
- tcx. sess . span_bug ( ast_ty. span , "class id is unbound \
399
- in items") ;
400
- }
410
+ _ {
411
+ tcx. sess . span_bug ( ast_ty. span , "class id is unbound \
412
+ in items") ;
413
+ }
414
+ }
401
415
}
416
+ _ {
417
+ tcx. sess . span_fatal ( ast_ty. span ,
418
+ "found type name used as a variable" ) ;
419
+ }
420
+ }
402
421
}
403
- _ {
404
- tcx. sess . span_fatal ( ast_ty. span ,
405
- "found type name used as a variable" ) ;
422
+ ast:: ty_constr( t, cs) {
423
+ let out_cs = [ ] ;
424
+ for constr: @ast:: ty_constr in cs {
425
+ out_cs += [ ty:: ast_constr_to_constr ( tcx, constr) ] ;
426
+ }
427
+ ty:: mk_constr ( tcx, do_ast_ty_to_ty ( tcx, use_site, mode, t) ,
428
+ out_cs)
429
+ }
430
+ ast:: ty_infer {
431
+ alt mode {
432
+ m_check_tyvar( fcx) { ret next_ty_var ( fcx) ; }
433
+ _ { tcx. sess . span_bug ( ast_ty. span ,
434
+ "found `ty_infer` in unexpected place" ) ; }
435
+ }
406
436
}
437
+ ast:: ty_mac ( _) {
438
+ tcx. sess . span_bug ( ast_ty. span ,
439
+ "found `ty_mac` in unexpected place" ) ;
440
+ }
441
+ } ;
442
+
443
+ if ty:: type_has_rptrs ( typ) {
444
+ tcx. ast_ty_to_ty_cache . insert ( ast_ty, ty:: atttce_has_regions) ;
445
+ } else {
446
+ tcx. ast_ty_to_ty_cache . insert ( ast_ty, ty:: atttce_resolved ( typ) ) ;
407
447
}
408
- }
409
- ast:: ty_constr( t, cs) {
410
- let out_cs = [ ] ;
411
- for constr: @ast:: ty_constr in cs {
412
- out_cs += [ ty:: ast_constr_to_constr ( tcx, constr) ] ;
413
- }
414
- ty:: mk_constr ( tcx, ast_ty_to_ty ( tcx, mode, t) , out_cs)
415
- }
416
- ast:: ty_infer {
417
- alt mode {
418
- m_check_tyvar( fcx) { ret next_ty_var ( fcx) ; }
419
- _ { tcx. sess . span_bug ( ast_ty. span ,
420
- "found `ty_infer` in unexpected place" ) ; }
421
- }
422
- }
423
- ast:: ty_mac ( _) {
424
- tcx. sess . span_bug ( ast_ty. span ,
425
- "found `ty_mac` in unexpected place" ) ;
426
- }
427
- } ;
428
448
429
- if ty:: type_has_rptrs ( typ) {
430
- tcx. ast_ty_to_ty_cache . insert ( ast_ty, ty:: atttce_has_regions) ;
431
- } else {
432
- tcx. ast_ty_to_ty_cache . insert ( ast_ty, ty:: atttce_resolved ( typ) ) ;
449
+ ret typ;
433
450
}
434
451
435
- ret typ ;
452
+ ret do_ast_ty_to_ty ( tcx , ast_ty . id , mode , ast_ty ) ;
436
453
}
437
454
438
455
fn ty_of_item ( tcx : ty:: ctxt , mode : mode , it : @ast:: item )
0 commit comments