@@ -889,6 +889,48 @@ fn field_of_tydesc(@block_ctxt cx, @ty.t t, int field) -> ValueRef {
889
889
ret cx. build . GEP ( tydesc, vec ( C_int ( 0 ) , C_int ( field) ) ) ;
890
890
}
891
891
892
+ // Given a type containing ty params, build a vector containing a ValueRef for
893
+ // each of the ty params it uses (from the current frame), as well as a vec
894
+ // containing a def_id for each such param. This is used solely for
895
+ // constructing derived tydescs.
896
+ fn linearize_ty_params ( @block_ctxt cx , @ty. t t )
897
+ -> tup ( vec[ ast. def_id ] , vec[ ValueRef ] ) {
898
+ let vec[ ValueRef ] param_vals = vec ( ) ;
899
+ let vec[ ast. def_id ] param_defs = vec ( ) ;
900
+ type rr = rec ( @block_ctxt cx ,
901
+ mutable vec[ ValueRef ] vals ,
902
+ mutable vec[ ast. def_id] defs ) ;
903
+
904
+ state obj folder ( @rr r) {
905
+ fn fold_simple_ty ( @ty. t t ) -> @ty. t {
906
+ alt ( t. struct ) {
907
+ case ( ty. ty_param ( ?pid) ) {
908
+ let bool seen = false ;
909
+ for ( ast. def_id d in r. defs) {
910
+ if ( d == pid) {
911
+ seen = true ;
912
+ }
913
+ }
914
+ if ( !seen) {
915
+ r. vals += cx. fcx . lltydescs . get ( pid) ;
916
+ r. defs += pid;
917
+ }
918
+ }
919
+ }
920
+ ret t;
921
+ }
922
+ }
923
+
924
+
925
+ auto x = @rec ( cx = cx,
926
+ mutable vals = param_vals,
927
+ mutable defs = param_defs) ;
928
+
929
+ ty. fold_ty ( folder ( x) , t) ;
930
+
931
+ ret tup( x. defs , x. vals ) ;
932
+ }
933
+
892
934
fn get_tydesc ( & @block_ctxt cx , @ty. t t ) -> ValueRef {
893
935
// Is the supplied type a type param? If so, return the passed-in tydesc.
894
936
alt ( ty. type_param ( t) ) {
@@ -897,9 +939,10 @@ fn get_tydesc(&@block_ctxt cx, @ty.t t) -> ValueRef {
897
939
}
898
940
899
941
// Does it contain a type param? If so, generate a derived tydesc.
942
+ let uint n_params = ty. count_ty_params ( t) ;
900
943
if ( ty. count_ty_params ( t) > 0 u) {
901
- log "TODO: trans.get_tydesc(): generate a derived type descriptor" ;
902
- fail ;
944
+ auto tys = linearize_ty_params ( cx , t ) ;
945
+ cx . fcx . ccx . sess . unimpl ( "derived type descriptors" ) ;
903
946
}
904
947
905
948
// Otherwise, generate a tydesc if necessary, and return it.
0 commit comments