@@ -764,6 +764,24 @@ fn type_of_arg(@crate_ctxt cx, &ty.arg arg) -> TypeRef {
764
764
ret typ;
765
765
}
766
766
767
+ fn type_of_ty_params_opt_and_ty ( @crate_ctxt ccx , ty. ty_params_opt_and_ty tpt )
768
+ -> TypeRef {
769
+ alt ( tpt. _1 . struct ) {
770
+ case ( ty. ty_fn ( ?proto, ?inputs, ?output) ) {
771
+ auto ty_params = option. get [ vec[ ast. def_id ] ] ( tpt. _0 ) ;
772
+ auto ty_param_count = _vec. len [ ast. def_id ] ( ty_params) ;
773
+ auto llfnty = type_of_fn ( ccx, proto, inputs, output,
774
+ ty_param_count) ;
775
+ ret T_fn_pair ( ccx. tn , llfnty) ;
776
+ }
777
+ case ( _) {
778
+ // fall through
779
+ }
780
+ }
781
+ ret type_of( ccx, tpt. _1 ) ;
782
+ }
783
+
784
+
767
785
// Name sanitation. LLVM will happily accept identifiers with weird names, but
768
786
// gas doesn't!
769
787
@@ -3570,14 +3588,30 @@ fn lval_val(@block_ctxt cx, ValueRef val) -> lval_result {
3570
3588
llobj=none[ ValueRef ] ) ;
3571
3589
}
3572
3590
3591
+ fn trans_external_path( @block_ctxt cx, ast. def_id did,
3592
+ ty. ty_params_opt_and_ty tpt) -> lval_result {
3593
+ auto ccx = cx. fcx. ccx;
3594
+ auto name = creader. get_symbol( ccx. sess, did) ;
3595
+ auto v = get_extern_const( ccx. externs, ccx. llmod,
3596
+ name, type_of_ty_params_opt_and_ty( ccx, tpt) ) ;
3597
+ ret lval_val( cx, v) ;
3598
+ }
3599
+
3573
3600
fn lval_generic_fn( @block_ctxt cx,
3574
3601
ty. ty_params_and_ty tpt,
3575
3602
ast. def_id fn_id,
3576
3603
& ast. ann ann)
3577
- -> lval_result {
3578
-
3579
- check ( cx. fcx. ccx. fn_pairs. contains_key( fn_id) ) ;
3580
- auto lv = lval_val( cx, cx. fcx. ccx. fn_pairs. get( fn_id) ) ;
3604
+ -> lval_result {
3605
+ auto lv;
3606
+ if ( cx. fcx. ccx. sess. get_targ_crate_num( ) == fn_id. _0) {
3607
+ // Internal reference.
3608
+ check ( cx. fcx. ccx. fn_pairs. contains_key( fn_id) ) ;
3609
+ lv = lval_val( cx, cx. fcx. ccx. fn_pairs. get( fn_id) ) ;
3610
+ } else {
3611
+ // External reference.
3612
+ auto tpot = tup( some[ vec[ ast. def_id] ] ( tpt. _0) , tpt. _1) ;
3613
+ lv = trans_external_path( cx, fn_id, tpot) ;
3614
+ }
3581
3615
3582
3616
auto monoty;
3583
3617
auto tys;
@@ -3609,22 +3643,10 @@ fn lval_generic_fn(@block_ctxt cx,
3609
3643
ret lv;
3610
3644
}
3611
3645
3612
- fn trans_external_path( @block_ctxt cx, & ast. path p,
3613
- ast. def def, ast. ann a) -> lval_result {
3614
- // FIXME: This isn't generic-safe.
3615
- auto ccx = cx. fcx. ccx;
3616
- auto ty = node_ann_type( ccx, a) ;
3617
- auto name = creader. get_symbol( ccx. sess, ast. def_id_of_def( def) ) ;
3618
- auto v = get_extern_const( ccx. externs, ccx. llmod,
3619
- name, type_of( ccx, ty) ) ;
3620
- ret lval_mem( cx, v) ;
3621
- }
3622
-
3623
3646
fn trans_path( @block_ctxt cx, & ast. path p, & option. t[ ast. def] dopt,
3624
3647
& ast. ann ann) -> lval_result {
3625
3648
alt ( dopt) {
3626
3649
case ( some[ ast. def] ( ?def) ) {
3627
-
3628
3650
alt ( def) {
3629
3651
case ( ast. def_arg( ?did) ) {
3630
3652
alt ( cx. fcx. llargs. find( did) ) {
@@ -3657,13 +3679,11 @@ fn trans_path(@block_ctxt cx, &ast.path p, &option.t[ast.def] dopt,
3657
3679
ret lval_mem( cx, cx. fcx. llobjfields. get( did) ) ;
3658
3680
}
3659
3681
case ( ast. def_fn( ?did) ) {
3660
- check ( cx. fcx. ccx. items. contains_key( did) ) ;
3661
3682
auto tyt = ty. lookup_generic_item_type( cx. fcx. ccx. sess,
3662
3683
cx. fcx. ccx. type_cache, did) ;
3663
3684
ret lval_generic_fn( cx, tyt, did, ann) ;
3664
3685
}
3665
3686
case ( ast. def_obj( ?did) ) {
3666
- check ( cx. fcx. ccx. items. contains_key( did) ) ;
3667
3687
auto tyt = ty. lookup_generic_item_type( cx. fcx. ccx. sess,
3668
3688
cx. fcx. ccx. type_cache, did) ;
3669
3689
ret lval_generic_fn( cx, tyt, did, ann) ;
@@ -3717,7 +3737,6 @@ fn trans_path(@block_ctxt cx, &ast.path p, &option.t[ast.def] dopt,
3717
3737
ret lval_mem( cx, cx. fcx. ccx. consts. get( did) ) ;
3718
3738
}
3719
3739
case ( ast. def_native_fn( ?did) ) {
3720
- check ( cx. fcx. ccx. native_items. contains_key( did) ) ;
3721
3740
auto tyt = ty. lookup_generic_item_type( cx. fcx. ccx. sess,
3722
3741
cx. fcx. ccx. type_cache, did) ;
3723
3742
ret lval_generic_fn( cx, tyt, did, ann) ;
0 commit comments