@@ -164,7 +164,6 @@ pub fn trans_method_callee(bcx: @mut Block,
164
164
llfn : callee_fn. llfn ,
165
165
llself : val,
166
166
temp_cleanup : temp_cleanups. head_opt ( ) . map_move ( |v| * v) ,
167
- self_ty : node_id_type ( bcx, this. id ) ,
168
167
self_mode : mentry. self_mode ,
169
168
} )
170
169
}
@@ -187,13 +186,11 @@ pub fn trans_method_callee(bcx: @mut Block,
187
186
}
188
187
}
189
188
190
- typeck:: method_trait( _, off, store ) => {
189
+ typeck:: method_trait( _, off) => {
191
190
trans_trait_callee ( bcx,
192
191
callee_id,
193
192
off,
194
- this,
195
- store,
196
- mentry. explicit_self )
193
+ this)
197
194
}
198
195
}
199
196
}
@@ -341,7 +338,6 @@ pub fn trans_monomorphized_callee(bcx: @mut Block,
341
338
llfn : llfn_val,
342
339
llself : llself_val,
343
340
temp_cleanup : temp_cleanups. head_opt ( ) . map_move ( |v| * v) ,
344
- self_ty : node_id_type ( bcx, base. id ) ,
345
341
self_mode : mentry. self_mode ,
346
342
} )
347
343
}
@@ -406,142 +402,78 @@ pub fn combine_impl_and_methods_tps(bcx: @mut Block,
406
402
pub fn trans_trait_callee ( bcx : @mut Block ,
407
403
callee_id : ast:: NodeId ,
408
404
n_method : uint ,
409
- self_expr : @ast:: expr ,
410
- store : ty:: TraitStore ,
411
- explicit_self : ast:: explicit_self_ )
405
+ self_expr : @ast:: expr )
412
406
-> Callee {
413
- // !
414
- //
415
- // Create a method callee where the method is coming from a trait
416
- // instance (e.g., @Trait type). In this case, we must pull the
417
- // fn pointer out of the vtable that is packaged up with the
418
- // @/~/&Trait instance. @/~/&Traits are represented as a pair, so we
419
- // first evaluate the self expression (expected a by-ref result) and then
420
- // extract the self data and vtable out of the pair.
407
+ /* !
408
+ * Create a method callee where the method is coming from a trait
409
+ * object (e.g., @Trait type). In this case, we must pull the fn
410
+ * pointer out of the vtable that is packaged up with the object.
411
+ * Objects are represented as a pair, so we first evaluate the self
412
+ * expression and then extract the self data and vtable out of the
413
+ * pair.
414
+ */
421
415
422
416
let _icx = push_ctxt ( "impl::trans_trait_callee" ) ;
423
417
let mut bcx = bcx;
424
- let self_datum = unpack_datum ! ( bcx,
425
- expr:: trans_to_datum( bcx, self_expr) ) ;
426
- let llpair = self_datum. to_ref_llval ( bcx) ;
427
-
428
- let llpair = match explicit_self {
429
- ast:: sty_region( * ) => Load ( bcx, llpair) ,
430
- ast:: sty_static | ast:: sty_value |
431
- ast:: sty_box( _) | ast:: sty_uniq => llpair
432
- } ;
418
+
419
+ let self_ty = expr_ty_adjusted ( bcx, self_expr) ;
420
+ let self_scratch = scratch_datum ( bcx, self_ty, "__trait_callee" , false ) ;
421
+ bcx = expr:: trans_into ( bcx, self_expr, expr:: SaveIn ( self_scratch. val ) ) ;
422
+
423
+ // Arrange a temporary cleanup for the object in case something
424
+ // should go wrong before the method is actually *invoked*.
425
+ self_scratch. add_clean ( bcx) ;
433
426
434
427
let callee_ty = node_id_type ( bcx, callee_id) ;
435
428
trans_trait_callee_from_llval ( bcx,
436
429
callee_ty,
437
430
n_method,
438
- llpair,
439
- store,
440
- explicit_self)
431
+ self_scratch. val ,
432
+ Some ( self_scratch. val ) )
441
433
}
442
434
443
435
pub fn trans_trait_callee_from_llval ( bcx : @mut Block ,
444
436
callee_ty : ty:: t ,
445
437
n_method : uint ,
446
438
llpair : ValueRef ,
447
- store : ty:: TraitStore ,
448
- explicit_self : ast:: explicit_self_ )
439
+ temp_cleanup : Option < ValueRef > )
449
440
-> Callee {
450
- // !
451
- //
452
- // Same as `trans_trait_callee()` above, except that it is given
453
- // a by-ref pointer to the @Trait pair.
441
+ /* !
442
+ * Same as `trans_trait_callee()` above, except that it is given
443
+ * a by-ref pointer to the object pair.
444
+ */
454
445
455
446
let _icx = push_ctxt ( "impl::trans_trait_callee" ) ;
456
447
let ccx = bcx. ccx ( ) ;
457
448
458
- // Load the vtable from the @Trait pair
459
- debug ! ( "(translating trait callee) loading vtable from pair %s" ,
460
- bcx. val_to_str( llpair) ) ;
461
- let llvtable = Load ( bcx,
462
- PointerCast ( bcx,
463
- GEPi ( bcx, llpair,
464
- [ 0 u, abi:: trt_field_vtable] ) ,
465
- Type :: vtable ( ) . ptr_to ( ) . ptr_to ( ) ) ) ;
466
-
467
- // Load the box from the @Trait pair and GEP over the box header if
468
- // necessary:
469
- let mut llself;
449
+ // Load the data pointer from the object.
470
450
debug ! ( "(translating trait callee) loading second index from pair" ) ;
471
451
let llboxptr = GEPi ( bcx, llpair, [ 0 u, abi:: trt_field_box] ) ;
472
452
let llbox = Load ( bcx, llboxptr) ;
473
-
474
- // Munge `llself` appropriately for the type of `self` in the method.
475
- match explicit_self {
476
- ast:: sty_static => {
477
- bcx. tcx ( ) . sess . bug ( "shouldn't see static method here" ) ;
478
- }
479
- ast:: sty_value => {
480
- bcx. tcx ( ) . sess . bug ( "methods with by-value self should not be \
481
- called on objects") ;
482
- }
483
- ast:: sty_region( * ) => {
484
- match store {
485
- ty:: UniqTraitStore
486
- if !ty:: type_contents ( bcx. tcx ( ) , callee_ty) . contains_managed ( ) => {
487
- llself = llbox;
488
- }
489
- ty:: BoxTraitStore |
490
- ty:: UniqTraitStore => {
491
- llself = GEPi ( bcx, llbox, [ 0 u, abi:: box_field_body] ) ;
492
- }
493
- ty:: RegionTraitStore ( _) => {
494
- llself = llbox;
495
- }
496
- }
497
- }
498
- ast:: sty_box( _) => {
499
- // Bump the reference count on the box.
500
- debug ! ( "(translating trait callee) callee type is `%s`" ,
501
- bcx. ty_to_str( callee_ty) ) ;
502
- glue:: incr_refcnt_of_boxed ( bcx, llbox) ;
503
-
504
- // Pass a pointer to the box.
505
- match store {
506
- ty:: BoxTraitStore => llself = llbox,
507
- _ => bcx. tcx ( ) . sess . bug ( "@self receiver with non-@Trait" )
508
- }
509
- }
510
- ast:: sty_uniq => {
511
- // Pass the unique pointer.
512
- match store {
513
- ty:: UniqTraitStore => llself = llbox,
514
- _ => bcx. tcx ( ) . sess . bug ( "~self receiver with non-~Trait" )
515
- }
516
-
517
- zero_mem ( bcx, llboxptr, ty:: mk_opaque_box ( bcx. tcx ( ) ) ) ;
518
- }
519
- }
520
-
521
- llself = PointerCast ( bcx, llself, Type :: opaque_box ( ccx) . ptr_to ( ) ) ;
522
- let scratch = scratch_datum ( bcx, ty:: mk_opaque_box ( bcx. tcx ( ) ) ,
523
- "__trait_callee" , false ) ;
524
- Store ( bcx, llself, scratch. val ) ;
525
- scratch. add_clean ( bcx) ;
453
+ let llself = PointerCast ( bcx, llbox, Type :: opaque_box ( ccx) . ptr_to ( ) ) ;
526
454
527
455
// Load the function from the vtable and cast it to the expected type.
528
456
debug ! ( "(translating trait callee) loading method" ) ;
529
457
let llcallee_ty = type_of_fn_from_ty ( ccx, callee_ty) ;
530
-
531
- // Plus one in order to skip past the type descriptor.
458
+ let llvtable = Load ( bcx,
459
+ PointerCast ( bcx,
460
+ GEPi ( bcx, llpair,
461
+ [ 0 u, abi:: trt_field_vtable] ) ,
462
+ Type :: vtable ( ) . ptr_to ( ) . ptr_to ( ) ) ) ;
532
463
let mptr = Load ( bcx, GEPi ( bcx, llvtable, [ 0 u, n_method + 1 ] ) ) ;
533
-
534
464
let mptr = PointerCast ( bcx, mptr, llcallee_ty. ptr_to ( ) ) ;
535
465
536
466
return Callee {
537
467
bcx : bcx,
538
468
data : Method ( MethodData {
539
469
llfn : mptr,
540
- llself : scratch. to_value_llval ( bcx) ,
541
- temp_cleanup : Some ( scratch. val ) ,
542
- self_ty : scratch. ty ,
470
+ llself : llself,
471
+ temp_cleanup : temp_cleanup,
472
+
473
+ // We know that the func declaration is &self, ~self,
474
+ // or @self, and such functions are always by-copy
475
+ // (right now, at least).
543
476
self_mode : ty:: ByCopy ,
544
- /* XXX: Some(llbox) */
545
477
} )
546
478
} ;
547
479
}
0 commit comments