1
1
import front. ast ;
2
2
import front. ast . ann ;
3
3
import front. ast . mutability ;
4
+ import front. creader ;
4
5
import middle. fold ;
5
6
import driver. session ;
6
7
import util. common ;
@@ -404,6 +405,12 @@ fn actual_type(@ty.t t, @ast.item item) -> @ty.t {
404
405
// ast_ty_to_ty.
405
406
fn ast_ty_to_ty_crate( @crate_ctxt ccx, & @ast. ty ast_ty) -> @ty. t {
406
407
fn getter( @crate_ctxt ccx, ast. def_id id) -> ty_and_params {
408
+
409
+ if ( id. _0 != ccx. sess. get_targ_crate_num( ) ) {
410
+ // This is a type we need to load in from the crate reader.
411
+ ret creader. get_type( ccx. sess, id) ;
412
+ }
413
+
407
414
check ( ccx. item_items. contains_key( id) ) ;
408
415
check ( ccx. item_types. contains_key( id) ) ;
409
416
auto it = ccx. item_items. get( id) ;
@@ -500,21 +507,29 @@ fn ty_of_native_fn_decl(@ty_item_table id_to_ty_item,
500
507
fn collect_item_types( session. session sess, @ast. crate crate)
501
508
-> tup( @ast. crate , @ty_table, @ty_item_table, @ty_param_table) {
502
509
503
- fn getter( @ty_item_table id_to_ty_item,
510
+ fn getter( session. session sess,
511
+ @ty_item_table id_to_ty_item,
504
512
@ty_table item_to_ty,
505
513
ast. def_id id) -> ty_and_params {
514
+
515
+ if ( id. _0 != sess. get_targ_crate_num( ) ) {
516
+ // This is a type we need to load in from the crate reader.
517
+ ret creader. get_type( sess, id) ;
518
+ }
519
+
506
520
check ( id_to_ty_item. contains_key( id) ) ;
521
+
507
522
auto it = id_to_ty_item. get( id) ;
508
523
auto ty;
509
524
auto params;
510
525
alt ( it) {
511
526
case ( any_item_rust( ?item) ) {
512
- ty = ty_of_item( id_to_ty_item, item_to_ty, item) ;
527
+ ty = ty_of_item( sess , id_to_ty_item, item_to_ty, item) ;
513
528
ty = actual_type( ty, item) ;
514
529
params = ty_params_of_item( item) ;
515
530
}
516
531
case ( any_item_native( ?native_item, ?abi) ) {
517
- ty = ty_of_native_item( id_to_ty_item, item_to_ty,
532
+ ty = ty_of_native_item( sess , id_to_ty_item, item_to_ty,
518
533
native_item, abi) ;
519
534
params = ty_params_of_native_item( native_item) ;
520
535
}
@@ -523,30 +538,33 @@ fn collect_item_types(session.session sess, @ast.crate crate)
523
538
ret rec( params = params, ty = ty) ;
524
539
}
525
540
526
- fn ty_of_arg( @ty_item_table id_to_ty_item,
541
+ fn ty_of_arg( session. session sess,
542
+ @ty_item_table id_to_ty_item,
527
543
@ty_table item_to_ty,
528
544
& ast. arg a) -> arg {
529
- auto f = bind getter( id_to_ty_item, item_to_ty, _) ;
545
+ auto f = bind getter( sess , id_to_ty_item, item_to_ty, _) ;
530
546
ret rec( mode=a. mode, ty=ast_ty_to_ty( f, a. ty) ) ;
531
547
}
532
548
533
- fn ty_of_method( @ty_item_table id_to_ty_item,
549
+ fn ty_of_method( session. session sess,
550
+ @ty_item_table id_to_ty_item,
534
551
@ty_table item_to_ty,
535
552
& @ast. method m) -> method {
536
- auto get = bind getter( id_to_ty_item, item_to_ty, _) ;
553
+ auto get = bind getter( sess , id_to_ty_item, item_to_ty, _) ;
537
554
auto convert = bind ast_ty_to_ty( get, _) ;
538
- auto f = bind ty_of_arg( id_to_ty_item, item_to_ty, _) ;
555
+ auto f = bind ty_of_arg( sess , id_to_ty_item, item_to_ty, _) ;
539
556
auto inputs = _vec. map[ ast. arg, arg] ( f, m. node. meth. decl. inputs) ;
540
557
auto output = convert( m. node. meth. decl. output) ;
541
558
ret rec( proto=m. node. meth. proto, ident=m. node. ident,
542
559
inputs=inputs, output=output) ;
543
560
}
544
561
545
- fn ty_of_obj( @ty_item_table id_to_ty_item,
562
+ fn ty_of_obj( session. session sess,
563
+ @ty_item_table id_to_ty_item,
546
564
@ty_table item_to_ty,
547
565
& ast. ident id,
548
566
& ast. _obj obj_info) -> @ty. t {
549
- auto f = bind ty_of_method( id_to_ty_item, item_to_ty, _) ;
567
+ auto f = bind ty_of_method( sess , id_to_ty_item, item_to_ty, _) ;
550
568
auto methods =
551
569
_vec. map[ @ast. method, method] ( f, obj_info. methods) ;
552
570
@@ -555,26 +573,29 @@ fn collect_item_types(session.session sess, @ast.crate crate)
555
573
ret t_obj;
556
574
}
557
575
558
- fn ty_of_obj_ctor( @ty_item_table id_to_ty_item,
576
+ fn ty_of_obj_ctor( session. session sess,
577
+ @ty_item_table id_to_ty_item,
559
578
@ty_table item_to_ty,
560
579
& ast. ident id,
561
580
& ast. _obj obj_info) -> @ty. t {
562
- auto t_obj = ty_of_obj( id_to_ty_item, item_to_ty, id, obj_info) ;
581
+ auto t_obj = ty_of_obj( sess, id_to_ty_item, item_to_ty,
582
+ id, obj_info) ;
563
583
let vec[ arg] t_inputs = vec( ) ;
564
584
for ( ast. obj_field f in obj_info. fields) {
565
- auto g = bind getter( id_to_ty_item, item_to_ty, _) ;
585
+ auto g = bind getter( sess , id_to_ty_item, item_to_ty, _) ;
566
586
auto t_field = ast_ty_to_ty( g, f. ty) ;
567
587
_vec. push[ arg] ( t_inputs, rec( mode=ast. alias, ty=t_field) ) ;
568
588
}
569
589
auto t_fn = plain_ty( ty. ty_fn( ast. proto_fn, t_inputs, t_obj) ) ;
570
590
ret t_fn;
571
591
}
572
592
573
- fn ty_of_item( @ty_item_table id_to_ty_item,
593
+ fn ty_of_item( session. session sess,
594
+ @ty_item_table id_to_ty_item,
574
595
@ty_table item_to_ty,
575
596
@ast. item it) -> @ty. t {
576
597
577
- auto get = bind getter( id_to_ty_item, item_to_ty, _) ;
598
+ auto get = bind getter( sess , id_to_ty_item, item_to_ty, _) ;
578
599
auto convert = bind ast_ty_to_ty( get, _) ;
579
600
580
601
alt ( it. node) {
@@ -584,14 +605,15 @@ fn collect_item_types(session.session sess, @ast.crate crate)
584
605
}
585
606
586
607
case ( ast. item_fn( ?ident, ?fn_info, _, ?def_id, _) ) {
587
- auto f = bind ty_of_arg( id_to_ty_item, item_to_ty, _) ;
588
- ret ty_of_fn_decl( id_to_ty_item, item_to_ty, convert, f ,
589
- fn_info. decl, fn_info. proto, def_id) ;
608
+ auto f = bind ty_of_arg( sess , id_to_ty_item, item_to_ty, _) ;
609
+ ret ty_of_fn_decl( id_to_ty_item, item_to_ty, convert,
610
+ f , fn_info. decl, fn_info. proto, def_id) ;
590
611
}
591
612
592
613
case ( ast. item_obj( ?ident, ?obj_info, _, ?def_id, _) ) {
593
614
// TODO: handle ty-params
594
- auto t_ctor = ty_of_obj_ctor( id_to_ty_item,
615
+ auto t_ctor = ty_of_obj_ctor( sess,
616
+ id_to_ty_item,
595
617
item_to_ty,
596
618
ident,
597
619
obj_info) ;
@@ -628,18 +650,19 @@ fn collect_item_types(session.session sess, @ast.crate crate)
628
650
}
629
651
}
630
652
631
- fn ty_of_native_item( @ty_item_table id_to_ty_item,
653
+ fn ty_of_native_item( session. session sess,
654
+ @ty_item_table id_to_ty_item,
632
655
@ty_table item_to_ty,
633
656
@ast. native_item it,
634
657
ast. native_abi abi) -> @ty. t {
635
658
alt ( it. node) {
636
659
case ( ast. native_item_fn( ?ident, ?lname, ?fn_decl,
637
660
?params, ?def_id, _) ) {
638
- auto get = bind getter( id_to_ty_item, item_to_ty, _) ;
661
+ auto get = bind getter( sess , id_to_ty_item, item_to_ty, _) ;
639
662
auto convert = bind ast_ty_to_ty( get, _) ;
640
- auto f = bind ty_of_arg( id_to_ty_item, item_to_ty, _) ;
641
- ret ty_of_native_fn_decl( id_to_ty_item, item_to_ty, convert ,
642
- f, fn_decl, abi, def_id) ;
663
+ auto f = bind ty_of_arg( sess , id_to_ty_item, item_to_ty, _) ;
664
+ ret ty_of_native_fn_decl( id_to_ty_item, item_to_ty,
665
+ convert , f, fn_decl, abi, def_id) ;
643
666
}
644
667
case ( ast. native_item_ty( _, ?def_id) ) {
645
668
if ( item_to_ty. contains_key( def_id) ) {
@@ -653,7 +676,8 @@ fn collect_item_types(session.session sess, @ast.crate crate)
653
676
}
654
677
}
655
678
656
- fn get_tag_variant_types( @ty_item_table id_to_ty_item,
679
+ fn get_tag_variant_types( session. session sess,
680
+ @ty_item_table id_to_ty_item,
657
681
@ty_table item_to_ty,
658
682
& ast. def_id tag_id,
659
683
& vec[ ast. variant] variants,
@@ -676,7 +700,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
676
700
} else {
677
701
// As above, tell ast_ty_to_ty() that trans_ty_item_to_ty()
678
702
// should be called to resolve named types.
679
- auto f = bind getter( id_to_ty_item, item_to_ty, _) ;
703
+ auto f = bind getter( sess , id_to_ty_item, item_to_ty, _) ;
680
704
681
705
let vec[ arg] args = vec( ) ;
682
706
for ( ast. variant_arg va in variant. args) {
@@ -778,14 +802,14 @@ fn collect_item_types(session.session sess, @ast.crate crate)
778
802
case ( _) {
779
803
// This call populates the ty_table with the converted type of
780
804
// the item in passing; we don't need to do anything else.
781
- ty_of_item( e. id_to_ty_item, e. item_to_ty, i) ;
805
+ ty_of_item( e. sess , e . id_to_ty_item, e. item_to_ty, i) ;
782
806
}
783
807
}
784
808
ret @rec( abi=abi with * e) ;
785
809
}
786
810
787
811
fn convert_native( & @env e, @ast. native_item i) -> @env {
788
- ty_of_native_item( e. id_to_ty_item, e. item_to_ty, i, e. abi) ;
812
+ ty_of_native_item( e. sess , e . id_to_ty_item, e. item_to_ty, i, e. abi) ;
789
813
ret e;
790
814
}
791
815
@@ -872,7 +896,7 @@ fn collect_item_types(session.session sess, @ast.crate crate)
872
896
m = @rec( node=m_ with * meth) ;
873
897
_vec. push[ @ast. method] ( methods, m) ;
874
898
}
875
- auto g = bind getter( e. id_to_ty_item, e. item_to_ty, _) ;
899
+ auto g = bind getter( e. sess , e . id_to_ty_item, e. item_to_ty, _) ;
876
900
for ( ast. obj_field fld in ob. fields) {
877
901
let @ty. t fty = ast_ty_to_ty( g, fld. ty) ;
878
902
let ast. obj_field f = rec(
@@ -908,7 +932,8 @@ fn collect_item_types(session.session sess, @ast.crate crate)
908
932
ast. def_id id) -> @ast. item {
909
933
collect_ty_params( e, id, ty_params) ;
910
934
911
- auto variants_t = get_tag_variant_types( e. id_to_ty_item,
935
+ auto variants_t = get_tag_variant_types( e. sess,
936
+ e. id_to_ty_item,
912
937
e. item_to_ty,
913
938
id,
914
939
variants,
0 commit comments