@@ -78,125 +78,123 @@ fn type_of(cx: @crate_ctxt, t: ty::t) -> TypeRef {
78
78
// type than `option<myrec>`.
79
79
let t_norm = ty:: normalize_ty ( cx. tcx , t) ;
80
80
81
- let mut llty;
82
81
if t != t_norm {
83
- llty = type_of ( cx, t_norm) ;
82
+ let llty = type_of ( cx, t_norm) ;
84
83
cx. lltypes . insert ( t, llty) ;
85
- } else {
86
- llty = match ty:: get ( t) . struct {
87
- ty:: ty_nil | ty:: ty_bot => T_nil ( ) ,
88
- ty:: ty_bool => T_bool ( ) ,
89
- ty:: ty_int( t) => T_int_ty ( cx, t) ,
90
- ty:: ty_uint( t) => T_uint_ty ( cx, t) ,
91
- ty:: ty_float( t) => T_float_ty ( cx, t) ,
92
- ty:: ty_estr( ty:: vstore_uniq) => {
93
- T_unique_ptr ( T_unique ( cx, T_vec ( cx, T_i8 ( ) ) ) )
94
- }
95
- ty:: ty_enum( did, _) => {
96
- // Only create the named struct, but don't fill it in. We
97
- // fill it in *after* placing it into the type cache. This
98
- // avoids creating more than one copy of the enum when one
99
- // of the enum's variants refers to the enum itself.
100
-
101
- common:: T_named_struct ( llvm_type_name ( cx, t) )
102
- }
103
- ty:: ty_estr( ty:: vstore_box) => {
104
- T_box_ptr ( T_box ( cx, T_vec ( cx, T_i8 ( ) ) ) )
105
- }
106
- ty:: ty_evec( mt, ty:: vstore_box) => {
107
- T_box_ptr ( T_box ( cx, T_vec ( cx, type_of ( cx, mt. ty ) ) ) )
108
- }
109
- ty:: ty_box( mt) => T_box_ptr ( T_box ( cx, type_of ( cx, mt. ty ) ) ) ,
110
- ty:: ty_opaque_box => T_box_ptr ( T_box ( cx, T_i8 ( ) ) ) ,
111
- ty:: ty_uniq( mt) => T_unique_ptr ( T_unique ( cx, type_of ( cx, mt. ty ) ) ) ,
112
- ty:: ty_evec( mt, ty:: vstore_uniq) => {
113
- T_unique_ptr ( T_unique ( cx, T_vec ( cx, type_of ( cx, mt. ty ) ) ) )
114
- }
115
- ty:: ty_unboxed_vec( mt) => {
116
- T_vec ( cx, type_of ( cx, mt. ty ) )
117
- }
118
- ty:: ty_ptr( mt) => T_ptr ( type_of ( cx, mt. ty ) ) ,
119
- ty:: ty_rptr( _, mt) => T_ptr ( type_of ( cx, mt. ty ) ) ,
120
-
121
- ty:: ty_evec( mt, ty:: vstore_slice( _) ) => {
122
- T_struct ( ~[ T_ptr ( type_of ( cx, mt. ty ) ) ,
123
- T_uint_ty ( cx, ast:: ty_u) ] )
124
- }
125
-
126
- ty:: ty_estr( ty:: vstore_slice( _) ) => {
127
- T_struct ( ~[ T_ptr ( T_i8 ( ) ) ,
128
- T_uint_ty ( cx, ast:: ty_u) ] )
129
- }
130
-
131
- ty:: ty_estr( ty:: vstore_fixed( n) ) => {
132
- T_array ( T_i8 ( ) , n + 1 u /* +1 for trailing null */ )
133
- }
134
-
135
- ty:: ty_evec( mt, ty:: vstore_fixed( n) ) => {
136
- T_array ( type_of ( cx, mt. ty ) , n)
137
- }
84
+ return llty;
85
+ }
138
86
139
- ty:: ty_rec( fields) => {
140
- let mut tys: ~[ TypeRef ] = ~[ ] ;
141
- for vec:: each( fields) |f| {
142
- let mt_ty = f. mt . ty ;
143
- vec:: push ( tys, type_of ( cx, mt_ty) ) ;
144
- }
145
- T_struct ( tys)
146
- }
147
- ty:: ty_fn( _) => T_fn_pair ( cx, type_of_fn_from_ty ( cx, t) ) ,
148
- ty:: ty_trait( _, _) => T_opaque_trait ( cx) ,
149
- ty:: ty_type => T_ptr ( cx. tydesc_type ) ,
150
- ty:: ty_tup( elts) => {
151
- let mut tys = ~[ ] ;
152
- for vec:: each( elts) |elt| {
153
- vec:: push( tys, type_of( cx, elt) ) ;
154
- }
155
- T_struct ( tys)
156
- }
157
- ty:: ty_opaque_closure_ptr( _) => T_opaque_box_ptr ( cx) ,
158
- ty:: ty_class( * ) => {
159
- // Only create the named struct, but don't fill it in. We fill it
160
- // in *after* placing it into the type cache. This prevents
161
- // infinite recursion with recursive class types.
87
+ let llty = match ty:: get ( t) . struct {
88
+ ty:: ty_nil | ty:: ty_bot => T_nil ( ) ,
89
+ ty:: ty_bool => T_bool ( ) ,
90
+ ty:: ty_int( t) => T_int_ty ( cx, t) ,
91
+ ty:: ty_uint( t) => T_uint_ty ( cx, t) ,
92
+ ty:: ty_float( t) => T_float_ty ( cx, t) ,
93
+ ty:: ty_estr( ty:: vstore_uniq) => {
94
+ T_unique_ptr ( T_unique ( cx, T_vec ( cx, T_i8 ( ) ) ) )
95
+ }
96
+ ty:: ty_enum( did, _) => {
97
+ // Only create the named struct, but don't fill it in. We
98
+ // fill it in *after* placing it into the type cache. This
99
+ // avoids creating more than one copy of the enum when one
100
+ // of the enum's variants refers to the enum itself.
101
+
102
+ common:: T_named_struct ( llvm_type_name ( cx, t) )
103
+ }
104
+ ty:: ty_estr( ty:: vstore_box) => {
105
+ T_box_ptr ( T_box ( cx, T_vec ( cx, T_i8 ( ) ) ) )
106
+ }
107
+ ty:: ty_evec( mt, ty:: vstore_box) => {
108
+ T_box_ptr ( T_box ( cx, T_vec ( cx, type_of ( cx, mt. ty ) ) ) )
109
+ }
110
+ ty:: ty_box( mt) => T_box_ptr ( T_box ( cx, type_of ( cx, mt. ty ) ) ) ,
111
+ ty:: ty_opaque_box => T_box_ptr ( T_box ( cx, T_i8 ( ) ) ) ,
112
+ ty:: ty_uniq( mt) => T_unique_ptr ( T_unique ( cx, type_of ( cx, mt. ty ) ) ) ,
113
+ ty:: ty_evec( mt, ty:: vstore_uniq) => {
114
+ T_unique_ptr ( T_unique ( cx, T_vec ( cx, type_of ( cx, mt. ty ) ) ) )
115
+ }
116
+ ty:: ty_unboxed_vec( mt) => {
117
+ T_vec ( cx, type_of ( cx, mt. ty ) )
118
+ }
119
+ ty:: ty_ptr( mt) => T_ptr ( type_of ( cx, mt. ty ) ) ,
120
+ ty:: ty_rptr( _, mt) => T_ptr ( type_of ( cx, mt. ty ) ) ,
121
+
122
+ ty:: ty_evec( mt, ty:: vstore_slice( _) ) => {
123
+ T_struct ( ~[ T_ptr ( type_of ( cx, mt. ty ) ) ,
124
+ T_uint_ty ( cx, ast:: ty_u) ] )
125
+ }
126
+
127
+ ty:: ty_estr( ty:: vstore_slice( _) ) => {
128
+ T_struct ( ~[ T_ptr ( T_i8 ( ) ) ,
129
+ T_uint_ty ( cx, ast:: ty_u) ] )
130
+ }
131
+
132
+ ty:: ty_estr( ty:: vstore_fixed( n) ) => {
133
+ T_array ( T_i8 ( ) , n + 1 u /* +1 for trailing null */ )
134
+ }
135
+
136
+ ty:: ty_evec( mt, ty:: vstore_fixed( n) ) => {
137
+ T_array ( type_of ( cx, mt. ty ) , n)
138
+ }
139
+
140
+ ty:: ty_rec( fields) => {
141
+ let mut tys: ~[ TypeRef ] = ~[ ] ;
142
+ for vec:: each( fields) |f| {
143
+ let mt_ty = f. mt . ty ;
144
+ vec:: push ( tys, type_of ( cx, mt_ty) ) ;
145
+ }
146
+ T_struct ( tys)
147
+ }
148
+ ty:: ty_fn( _) => T_fn_pair ( cx, type_of_fn_from_ty ( cx, t) ) ,
149
+ ty:: ty_trait( _, _) => T_opaque_trait ( cx) ,
150
+ ty:: ty_type => T_ptr ( cx. tydesc_type ) ,
151
+ ty:: ty_tup( elts) => {
152
+ let mut tys = ~[ ] ;
153
+ for vec:: each( elts) |elt| {
154
+ vec:: push( tys, type_of( cx, elt) ) ;
155
+ }
156
+ T_struct ( tys)
157
+ }
158
+ ty:: ty_opaque_closure_ptr( _) => T_opaque_box_ptr ( cx) ,
159
+ ty:: ty_class( * ) => {
160
+ // Only create the named struct, but don't fill it in. We fill it
161
+ // in *after* placing it into the type cache. This prevents
162
+ // infinite recursion with recursive class types.
163
+
164
+ common:: T_named_struct ( llvm_type_name ( cx, t) )
165
+ }
166
+ ty:: ty_self => cx. tcx . sess . unimpl ( ~"type_of: ty_self") ,
167
+ ty:: ty_var( _) => cx. tcx . sess . bug ( ~"type_of with ty_var") ,
168
+ ty:: ty_param( * ) => cx. tcx . sess . bug ( ~"type_of with ty_param") ,
169
+ ty:: ty_var_integral( _) => {
170
+ cx. tcx . sess . bug ( ~"type_of shouldn' t see a ty_var_integral") ;
171
+ }
172
+ } ;
162
173
163
- common:: T_named_struct ( llvm_type_name ( cx, t) )
164
- }
165
- ty:: ty_self => cx. tcx . sess . unimpl ( ~"type_of: ty_self") ,
166
- ty:: ty_var( _) => cx. tcx . sess . bug ( ~"type_of with ty_var") ,
167
- ty:: ty_param( * ) => cx. tcx . sess . bug ( ~"type_of with ty_param") ,
168
- ty:: ty_var_integral( _) => {
169
- cx. tcx . sess . bug ( ~"type_of shouldn' t see a ty_var_integral") ;
170
- }
174
+ cx. lltypes. insert ( t, llty) ;
175
+
176
+ // If this was an enum or class, fill in the type now.
177
+ match ty:: get ( t) . struct {
178
+ ty:: ty_enum( did, _) => {
179
+ fill_type_of_enum ( cx, did, t, llty) ;
180
+ }
181
+ ty:: ty_class( did, ts) => {
182
+ // Only instance vars are record fields at runtime.
183
+ let fields = ty:: lookup_class_fields ( cx. tcx , did) ;
184
+ let mut tys = do vec:: map ( fields) |f| {
185
+ let t = ty:: lookup_field_type ( cx. tcx , did, f. id , ts) ;
186
+ type_of ( cx, t)
171
187
} ;
172
188
173
- cx. lltypes. insert ( t, llty) ;
174
-
175
- // If this was an enum or class, fill in the type now.
176
- match ty:: get ( t) . struct {
177
- ty:: ty_enum( did, _) => {
178
- fill_type_of_enum ( cx, did, t, llty) ;
179
- }
180
- ty:: ty_class( did, ts) => {
181
- // Only instance vars are record fields at runtime.
182
- let fields = ty:: lookup_class_fields ( cx. tcx , did) ;
183
- let mut tys = do vec:: map ( fields) |f| {
184
- let t = ty:: lookup_field_type ( cx. tcx , did, f. id , ts) ;
185
- type_of ( cx, t)
186
- } ;
187
-
188
- if ty:: ty_dtor ( cx. tcx , did) != none {
189
- // resource type
190
- tys = ~[ T_i8 ( ) , T_struct ( tys) ] ;
191
- }
192
-
193
- common:: set_struct_body ( llty, tys) ;
194
- }
195
- _ => {
196
- // Nothing more to do.
197
- }
189
+ if ty:: ty_dtor ( cx. tcx , did) != none {
190
+ // resource type
191
+ tys = ~[ T_i8 ( ) , T_struct ( tys) ] ;
198
192
}
199
- } ;
193
+
194
+ common:: set_struct_body ( llty, tys) ;
195
+ }
196
+ _ => ( )
197
+ }
200
198
201
199
return llty;
202
200
}
0 commit comments