@@ -7231,15 +7231,16 @@ fn trans_obj(@local_ctxt cx, &span sp, &ast::_obj ob, ast::def_id oid,
7231
7231
typarams_ty,
7232
7232
fields_ty] ) ;
7233
7233
7234
- // Hand this thing we've constructed off to trans_malloc_boxed, which
7235
- // makes space for the refcount.
7234
+ // Hand this type we've synthesized off to trans_malloc_boxed, which
7235
+ // allocates a box, including space for a refcount.
7236
7236
auto box = trans_malloc_boxed( bcx, body_ty) ;
7237
7237
bcx = box. bcx;
7238
7238
7239
- // And mk_imm_box throws a refcount into the type we're synthesizing:
7240
- // [rc, [tydesc_ty, [typaram, ...], [field, ...]]]
7239
+ // mk_imm_box throws a refcount into the type we're synthesizing, so
7240
+ // that it looks like: [rc, [tydesc_ty, [typaram, ...], [field, ...]]]
7241
7241
let ty:: t boxed_body_ty = ty:: mk_imm_box( ccx. tcx, body_ty) ;
7242
7242
7243
+ // Grab onto the refcount and body parts of the box we allocated.
7243
7244
auto rc = GEP_tup_like ( bcx, boxed_body_ty, box. val,
7244
7245
[ 0 ,
7245
7246
abi:: box_rc_field_refcnt] ) ;
@@ -7253,6 +7254,12 @@ fn trans_obj(@local_ctxt cx, &span sp, &ast::_obj ob, ast::def_id oid,
7253
7254
7254
7255
// Put together a tydesc for the body, so that the object can later be
7255
7256
// freed by calling through its tydesc.
7257
+
7258
+ // Every object (not just those with type parameters) needs to have a
7259
+ // tydesc to describe its body, since all objects have unknown type to
7260
+ // the user of the object. So the tydesc is needed to keep track of
7261
+ // the types of the object's fields, so that the fields can be freed
7262
+ // later.
7256
7263
auto body_tydesc =
7257
7264
GEP_tup_like ( bcx, body_ty, body. val,
7258
7265
[ 0 , abi:: obj_body_elt_tydesc] ) ;
@@ -7263,17 +7270,16 @@ fn trans_obj(@local_ctxt cx, &span sp, &ast::_obj ob, ast::def_id oid,
7263
7270
lazily_emit_tydesc_glue( bcx, abi:: tydesc_field_drop_glue, ti) ;
7264
7271
lazily_emit_tydesc_glue( bcx, abi:: tydesc_field_free_glue, ti) ;
7265
7272
7266
- auto dtor = C_null ( T_ptr ( T_glue_fn ( ccx. tn) ) ) ;
7267
- alt ( ob. dtor) {
7268
- case ( some( ?d) ) {
7269
- dtor = trans_dtor( cx, llself_ty, self_ty, ty_params, d) ;
7270
- }
7271
- case ( none) { }
7272
- }
7273
-
7274
7273
bcx = body_td. bcx;
7275
7274
bcx. build. Store ( body_td. val, body_tydesc. val) ;
7276
7275
7276
+ // Copy the object's type parameters and fields into the space we
7277
+ // allocated for the object body. (This is something like saving the
7278
+ // lexical environment of a function in its closure: the "captured
7279
+ // typarams" are any type parameters that are passed to the object
7280
+ // constructor and are then available to the object's methods.
7281
+ // Likewise for the object's fields.)
7282
+
7277
7283
// Copy typarams into captured typarams.
7278
7284
auto body_typarams =
7279
7285
GEP_tup_like ( bcx, body_ty, body. val,
0 commit comments