@@ -82,26 +82,71 @@ pub fn path_elt_to_str(pe: path_elt, itr: @ident_interner) -> ~str {
82
82
}
83
83
}
84
84
85
- pub fn impl_pretty_name ( trait_ref : & Option < trait_ref > ,
86
- ty : & Ty , default : Ident ) -> path_elt {
87
- let itr = get_ident_interner ( ) ;
88
- let ty_ident = match ty. node {
89
- ty_path( ref path, _, _) => path. segments . last ( ) . identifier ,
90
- _ => default
85
+ /// write a "pretty" version of `ty` to `out`. This is designed so
86
+ /// that symbols of `impl`'d methods give some hint of where they came
87
+ /// from, even if it's hard to read (previously they would all just be
88
+ /// listed as `__extensions__::method_name::hash`, with no indication
89
+ /// of the type).
90
+ // XXX: these dollar signs and the names in general are actually a
91
+ // relic of $ being one of the very few valid symbol names on
92
+ // unix. These kinds of details shouldn't be exposed way up here
93
+ // in the ast.
94
+ fn pretty_ty ( ty : & Ty , itr : @ident_interner , out : & mut ~str ) {
95
+ let ( prefix, subty) = match ty. node {
96
+ ty_uniq( ty) => ( "$UP$" , & * ty) ,
97
+ ty_box( mt { ty, .. } ) => ( "$SP$" , & * ty) ,
98
+ ty_ptr( mt { ty, mutbl } ) => ( if mutbl == MutMutable { "$RPmut$" } else { "$RP$" } ,
99
+ & * ty) ,
100
+ ty_rptr( _, mt { ty, mutbl } ) => ( if mutbl == MutMutable { "$BPmut$" } else { "$BP$" } ,
101
+ & * ty) ,
102
+
103
+ ty_vec( ty) => ( "$VEC$" , & * ty) ,
104
+ ty_fixed_length_vec( ty, _) => ( "$FIXEDVEC$" , & * ty) ,
105
+
106
+ // these can't be represented as <prefix><contained ty>, so
107
+ // need custom handling.
108
+ ty_nil => { out. push_str ( "$NIL$" ) ; return }
109
+ ty_path( ref path, _, _) => {
110
+ out. push_str ( itr. get ( path. segments . last ( ) . identifier . name ) ) ;
111
+ return
112
+ }
113
+ ty_tup( ref tys) => {
114
+ out. push_str ( format ! ( "$TUP_{}$" , tys. len( ) ) ) ;
115
+ for subty in tys. iter ( ) {
116
+ pretty_ty ( * subty, itr, out) ;
117
+ out. push_char ( '$' ) ;
118
+ }
119
+ return
120
+ }
121
+
122
+ // meh, better than nothing.
123
+ ty_bot => { out. push_str ( "$BOT$" ) ; return }
124
+ ty_closure( ..) => { out. push_str ( "$CLOSURE$" ) ; return }
125
+ ty_bare_fn( ..) => { out. push_str ( "$FN$" ) ; return }
126
+ ty_typeof( ..) => { out. push_str ( "$TYPEOF$" ) ; return }
127
+ ty_infer( ..) => { out. push_str ( "$INFER$" ) ; return }
128
+
91
129
} ;
130
+
131
+ out. push_str ( prefix) ;
132
+ pretty_ty ( subty, itr, out) ;
133
+ }
134
+
135
+ pub fn impl_pretty_name ( trait_ref : & Option < trait_ref > , ty : & Ty ) -> path_elt {
136
+ let itr = get_ident_interner ( ) ;
137
+
92
138
let hash = ( trait_ref, ty) . hash ( ) ;
139
+ let mut pretty;
93
140
match * trait_ref {
94
- None => path_pretty_name ( ty_ident , hash ) ,
141
+ None => pretty = ~"" ,
95
142
Some ( ref trait_ref) => {
96
- // XXX: this dollar sign is actually a relic of being one of the
97
- // very few valid symbol names on unix. These kinds of
98
- // details shouldn't be exposed way up here in the ast.
99
- let s = format ! ( "{}${}" ,
100
- itr. get( trait_ref. path. segments. last( ) . identifier. name) ,
101
- itr. get( ty_ident. name) ) ;
102
- path_pretty_name ( Ident :: new ( itr. gensym ( s) ) , hash)
143
+ pretty = itr. get ( trait_ref. path . segments . last ( ) . identifier . name ) . to_owned ( ) ;
144
+ pretty. push_char ( '$' ) ;
103
145
}
104
- }
146
+ } ;
147
+ pretty_ty ( ty, itr, & mut pretty) ;
148
+
149
+ path_pretty_name ( Ident :: new ( itr. gensym ( pretty) ) , hash)
105
150
}
106
151
107
152
#[ deriving( Clone ) ]
@@ -265,7 +310,7 @@ impl Visitor<()> for Ctx {
265
310
// Right now the ident on impls is __extensions__ which isn't
266
311
// very pretty when debugging, so attempt to select a better
267
312
// name to use.
268
- let elt = impl_pretty_name ( maybe_trait, ty, i . ident ) ;
313
+ let elt = impl_pretty_name ( maybe_trait, ty) ;
269
314
270
315
let impl_did = ast_util:: local_def ( i. id ) ;
271
316
for m in ms. iter ( ) {
0 commit comments