@@ -90,7 +90,6 @@ state type crate_ctxt = rec(session.session sess,
90
90
ValueRef crate_ptr,
91
91
hashmap[ str, ValueRef ] externs,
92
92
hashmap[ str, ValueRef ] intrinsics,
93
- hashmap[ str, ValueRef ] item_names,
94
93
hashmap[ ast. def_id , ValueRef ] item_ids,
95
94
hashmap[ ast. def_id , @ast. item ] items,
96
95
hashmap[ ast. def_id ,
@@ -108,7 +107,8 @@ state type crate_ctxt = rec(session.session sess,
108
107
vec[ ast. obj_field ] obj_fields,
109
108
@glue_fns glues,
110
109
namegen names,
111
- str path) ;
110
+ vec[ str] path,
111
+ std. sha1 . sha1 sha) ;
112
112
113
113
state type fn_ctxt = rec ( ValueRef llfn,
114
114
ValueRef lltaskptr ,
@@ -156,6 +156,30 @@ fn sep() -> str {
156
156
ret "_" ;
157
157
}
158
158
159
+ fn extend_path ( @crate_ctxt cx , str name ) -> @crate_ctxt {
160
+ ret @rec( path = cx. path + vec ( name) with * cx) ;
161
+ }
162
+
163
+ fn path_name ( vec[ str] path ) -> str {
164
+ ret _str. connect ( path, sep ( ) ) ;
165
+ }
166
+
167
+
168
+ fn mangle_name_by_type ( @crate_ctxt cx , @ty. t t ) -> str {
169
+ cx. sha . reset ( ) ;
170
+ auto f = metadata. def_to_str ;
171
+ cx. sha . input_str ( metadata. ty_str ( t, f) ) ;
172
+ ret sep( ) + "rust" + sep ( )
173
+ + cx. sha . result_str ( ) + sep ( )
174
+ + path_name ( cx. path ) ;
175
+ }
176
+
177
+ fn mangle_name_by_seq ( @crate_ctxt cx , str flav ) -> str {
178
+ ret sep ( ) + "rust" + sep ( )
179
+ + cx. names . next ( flav) + sep ( )
180
+ + path_name ( cx. path ) ;
181
+ }
182
+
159
183
fn res ( @block_ctxt bcx , ValueRef val) -> result {
160
184
ret rec ( mutable bcx = bcx,
161
185
mutable val = val) ;
@@ -1549,7 +1573,8 @@ fn define_tydesc(@crate_ctxt cx, @ty.t t, vec[ast.def_id] typaram_defs) {
1549
1573
fn declare_generic_glue( @crate_ctxt cx, @ty. t t, str name) -> ValueRef {
1550
1574
auto llfnty = T_glue_fn ( cx. tn) ;
1551
1575
1552
- auto fn_name = cx. names. next( "_rust_" + name) + sep( ) + ty. ty_to_str( t) ;
1576
+ auto gcx = @rec( path=vec( "glue", name) with * cx) ;
1577
+ auto fn_name = mangle_name_by_type( gcx, t) ;
1553
1578
fn_name = sanitize( fn_name) ;
1554
1579
auto llfn = decl_fastcall_fn( cx. llmod, fn_name, llfnty) ;
1555
1580
llvm. LLVMSetLinkage ( llfn, lib. llvm. LLVMPrivateLinkage as llvm. Linkage ) ;
@@ -3193,9 +3218,7 @@ fn trans_for_each(@block_ctxt cx,
3193
3218
3194
3219
// Step 2: Declare foreach body function.
3195
3220
3196
- let str s =
3197
- cx. fcx. ccx. names. next( "_rust_foreach")
3198
- + sep( ) + cx. fcx. ccx. path;
3221
+ let str s = mangle_name_by_seq( cx. fcx. ccx, "foreach") ;
3199
3222
3200
3223
// The 'env' arg entering the body function is a fake env member (as in
3201
3224
// the env-part of the normal rust calling convention) that actually
@@ -3788,7 +3811,7 @@ fn trans_bind_thunk(@crate_ctxt cx,
3788
3811
// Construct a thunk-call with signature incoming_fty, and that copies
3789
3812
// args forward into a call to outgoing_fty.
3790
3813
3791
- let str s = cx . names . next ( "_rust_thunk" ) + sep ( ) + cx . path ;
3814
+ let str s = mangle_name_by_seq ( cx , "thunk" ) ;
3792
3815
let TypeRef llthunk_ty = get_pair_fn_ty( type_of( cx, incoming_fty) ) ;
3793
3816
let ValueRef llthunk = decl_fastcall_fn( cx. llmod, s, llthunk_ty) ;
3794
3817
@@ -5327,7 +5350,6 @@ fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid,
5327
5350
& vec[ ast. ty_param] ty_params, & ast. ann ann) {
5328
5351
5329
5352
auto llfndecl = cx. item_ids. get( fid) ;
5330
- cx. item_names. insert( cx. path, llfndecl) ;
5331
5353
5332
5354
auto fcx = new_fn_ctxt( cx, llfndecl) ;
5333
5355
create_llargs_for_fn_args( fcx, f. proto,
@@ -5378,22 +5400,21 @@ fn trans_vtbl(@crate_ctxt cx, TypeRef self_ty,
5378
5400
}
5379
5401
}
5380
5402
5381
- let @crate_ctxt mcx = @rec( path=cx. path + sep( ) + m. node. ident
5382
- with * cx) ;
5383
-
5384
- let str s = cx. names. next( "_rust_method") + sep( ) + mcx. path;
5403
+ let @crate_ctxt mcx = extend_path( cx, m. node. ident) ;
5404
+ let str s = mangle_name_by_seq( mcx, "method") ;
5385
5405
let ValueRef llfn = decl_fastcall_fn( cx. llmod, s, llfnty) ;
5386
5406
cx. item_ids. insert( m. node. id, llfn) ;
5387
5407
cx. item_symbols. insert( m. node. id, s) ;
5388
5408
5409
+
5389
5410
trans_fn( mcx, m. node. meth, m. node. id, some[ TypeRef ] ( self_ty) ,
5390
5411
ty_params, m. node. ann) ;
5391
5412
methods += vec( llfn) ;
5392
5413
}
5393
5414
auto vtbl = C_struct ( methods) ;
5394
- auto gvar = llvm . LLVMAddGlobal ( cx. llmod ,
5395
- val_ty( vtbl) ,
5396
- _str. buf( "_rust_vtbl" + sep ( ) + cx . path ) ) ;
5415
+ auto vtbl_name = mangle_name_by_seq ( cx, "vtbl" ) ;
5416
+ auto gvar = llvm . LLVMAddGlobal ( cx . llmod , val_ty( vtbl) ,
5417
+ _str. buf( vtbl_name ) ) ;
5397
5418
llvm. LLVMSetInitializer ( gvar, vtbl) ;
5398
5419
llvm. LLVMSetGlobalConstant ( gvar, True ) ;
5399
5420
llvm. LLVMSetLinkage ( gvar, lib. llvm. LLVMPrivateLinkage
@@ -5405,7 +5426,6 @@ fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
5405
5426
& vec[ ast. ty_param] ty_params, & ast. ann ann) {
5406
5427
5407
5428
auto llctor_decl = cx. item_ids. get( oid) ;
5408
- cx. item_names. insert( cx. path, llctor_decl) ;
5409
5429
5410
5430
// Translate obj ctor args to function arguments.
5411
5431
let vec[ ast. arg] fn_args = vec( ) ;
@@ -5628,29 +5648,29 @@ fn trans_const(@crate_ctxt cx, @ast.expr e,
5628
5648
fn trans_item( @crate_ctxt cx, & ast. item item) {
5629
5649
alt ( item. node) {
5630
5650
case ( ast. item_fn( ?name, ?f, ?tps, ?fid, ?ann) ) {
5631
- auto sub_cx = @rec ( path=cx . path + sep ( ) + name with * cx ) ;
5651
+ auto sub_cx = extend_path ( cx , name) ;
5632
5652
trans_fn( sub_cx, f, fid, none[ TypeRef ] , tps, ann) ;
5633
5653
}
5634
5654
case ( ast. item_obj( ?name, ?ob, ?tps, ?oid, ?ann) ) {
5635
- auto sub_cx = @rec( path=cx . path + sep ( ) + name ,
5636
- obj_typarams=tps ,
5637
- obj_fields=ob . fields with * cx ) ;
5655
+ auto sub_cx = @rec( obj_typarams=tps ,
5656
+ obj_fields=ob . fields with
5657
+ * extend_path ( cx , name ) ) ;
5638
5658
trans_obj( sub_cx, ob, oid, tps, ann) ;
5639
5659
}
5640
5660
case ( ast. item_mod( ?name, ?m, _) ) {
5641
- auto sub_cx = @rec ( path=cx . path + sep ( ) + name with * cx ) ;
5661
+ auto sub_cx = extend_path ( cx , name) ;
5642
5662
trans_mod( sub_cx, m) ;
5643
5663
}
5644
5664
case ( ast. item_tag( ?name, ?variants, ?tps, ?tag_id) ) {
5645
- auto sub_cx = @rec ( path=cx . path + sep ( ) + name with * cx ) ;
5665
+ auto sub_cx = extend_path ( cx , name) ;
5646
5666
auto i = 0 ;
5647
5667
for ( ast. variant variant in variants) {
5648
5668
trans_tag_variant( sub_cx, tag_id, variant, i, tps) ;
5649
5669
i += 1 ;
5650
5670
}
5651
5671
}
5652
5672
case ( ast. item_const( ?name, _, ?expr, ?cid, ?ann) ) {
5653
- auto sub_cx = @rec ( path=cx . path + sep ( ) + name with * cx ) ;
5673
+ auto sub_cx = extend_path ( cx , name) ;
5654
5674
trans_const( sub_cx, expr, cid, ann) ;
5655
5675
}
5656
5676
case ( _) { /* fall through */ }
@@ -5672,8 +5692,7 @@ fn get_pair_fn_ty(TypeRef llpairty) -> TypeRef {
5672
5692
}
5673
5693
5674
5694
fn decl_fn_and_pair ( @crate_ctxt cx ,
5675
- str kind ,
5676
- str name ,
5695
+ str flav ,
5677
5696
vec[ ast. ty_param] ty_params ,
5678
5697
& ast. ann ann ,
5679
5698
ast. def_id id ) {
@@ -5693,11 +5712,11 @@ fn decl_fn_and_pair(@crate_ctxt cx,
5693
5712
}
5694
5713
5695
5714
// Declare the function itself.
5696
- let str s = cx . names . next ( "_rust_" + kind ) + sep ( ) + name ;
5715
+ let str s = mangle_name_by_seq ( cx , flav ) ;
5697
5716
let ValueRef llfn = decl_fastcall_fn ( cx. llmod , s, llfty) ;
5698
5717
5699
5718
// Declare the global constant pair that points to it.
5700
- let str ps = cx . names . next ( "_rust_" + kind + "_pair" ) + sep ( ) + name ;
5719
+ let str ps = mangle_name_by_type ( cx , node_ann_type ( cx , ann ) ) ;
5701
5720
5702
5721
register_fn_pair ( cx, ps, llpairty, llfn, id) ;
5703
5722
}
@@ -5756,14 +5775,14 @@ fn decl_native_fn_and_pair(@crate_ctxt cx,
5756
5775
5757
5776
// Declare the wrapper.
5758
5777
auto wrapper_type = native_fn_wrapper_type ( cx, num_ty_param, ann) ;
5759
- let str s = cx . names . next ( "_rust_wrapper" ) + sep ( ) + name ;
5778
+ let str s = mangle_name_by_seq ( cx , "wrapper" ) ;
5760
5779
let ValueRef wrapper_fn = decl_fastcall_fn ( cx. llmod , s, wrapper_type) ;
5761
5780
llvm. LLVMSetLinkage ( wrapper_fn, lib. llvm . LLVMPrivateLinkage
5762
5781
as llvm . Linkage ) ;
5763
5782
5764
5783
// Declare the global constant pair that points to it.
5765
5784
auto wrapper_pair_type = T_fn_pair ( cx. tn , wrapper_type) ;
5766
- let str ps = cx . names . next ( "_rust_wrapper_pair" ) + sep ( ) + name ;
5785
+ let str ps = mangle_name_by_type ( cx , node_ann_type ( cx , ann ) ) ;
5767
5786
5768
5787
register_fn_pair ( cx, ps, wrapper_pair_type, wrapper_fn, id) ;
5769
5788
@@ -5827,8 +5846,33 @@ fn collect_native_item(&@crate_ctxt cx, @ast.native_item i) -> @crate_ctxt {
5827
5846
ret cx;
5828
5847
}
5829
5848
5830
- fn collect_item( & @crate_ctxt cx, @ast. item i) -> @crate_ctxt {
5849
+ fn item_name( @ast. item i) -> str {
5850
+ alt ( i. node) {
5851
+ case ( ast. item_mod( ?name, _, _) ) {
5852
+ ret name;
5853
+ }
5854
+ case ( ast. item_tag( ?name, _, _, _) ) {
5855
+ ret name;
5856
+ }
5857
+ case ( ast. item_const( ?name, _, _, _, _) ) {
5858
+ ret name;
5859
+ }
5860
+ case ( ast. item_fn( ?name, _, _, _, _) ) {
5861
+ ret name;
5862
+ }
5863
+ case ( ast. item_native_mod( ?name, _, _) ) {
5864
+ ret name;
5865
+ }
5866
+ case ( ast. item_ty( ?name, _, _, _, _) ) {
5867
+ ret name;
5868
+ }
5869
+ case ( ast. item_obj( ?name, _, _, _, _) ) {
5870
+ ret name;
5871
+ }
5872
+ }
5873
+ }
5831
5874
5875
+ fn collect_item( & @crate_ctxt cx, @ast. item i) -> @crate_ctxt {
5832
5876
alt ( i. node) {
5833
5877
case ( ast. item_const( ?name, _, _, ?cid, ?ann) ) {
5834
5878
auto typ = node_ann_type( cx, ann) ;
@@ -5844,35 +5888,36 @@ fn collect_item(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
5844
5888
cx. items. insert( mid, i) ;
5845
5889
}
5846
5890
5847
- case ( ast. item_tag( _ , ?variants, ?tps, ?tag_id) ) {
5891
+ case ( ast. item_tag( ?name , ?variants, ?tps, ?tag_id) ) {
5848
5892
cx. items. insert( tag_id, i) ;
5849
5893
}
5850
-
5851
5894
case ( _) { /* fall through */ }
5852
5895
}
5853
- ret cx ;
5896
+ ret extend_path ( cx , item_name ( i ) ) ;
5854
5897
}
5855
5898
5856
5899
fn collect_item_pass2( & @crate_ctxt cx, @ast. item i) -> @crate_ctxt {
5857
5900
alt ( i. node) {
5858
5901
case ( ast. item_fn( ?name, ?f, ?tps, ?fid, ?ann) ) {
5859
5902
cx. items. insert( fid, i) ;
5860
5903
if ( ! cx. obj_methods. contains_key( fid) ) {
5861
- decl_fn_and_pair( cx, "fn ", name, tps, ann, fid) ;
5904
+ decl_fn_and_pair( extend_path( cx, name) , "fn ",
5905
+ tps, ann, fid) ;
5862
5906
}
5863
5907
}
5864
5908
5865
5909
case ( ast. item_obj( ?name, ?ob, ?tps, ?oid, ?ann) ) {
5866
5910
cx. items. insert( oid, i) ;
5867
- decl_fn_and_pair( cx, "obj_ctor" , name, tps, ann, oid) ;
5911
+ decl_fn_and_pair( extend_path( cx, name) , "obj_ctor" ,
5912
+ tps, ann, oid) ;
5868
5913
for ( @ast. method m in ob. methods) {
5869
5914
cx. obj_methods. insert( m. node. id, ( ) ) ;
5870
5915
}
5871
5916
}
5872
5917
5873
5918
case ( _) { /* fall through */ }
5874
5919
}
5875
- ret cx ;
5920
+ ret extend_path ( cx , item_name ( i ) ) ;
5876
5921
}
5877
5922
5878
5923
@@ -5904,7 +5949,7 @@ fn collect_tag_ctor(&@crate_ctxt cx, @ast.item i) -> @crate_ctxt {
5904
5949
case ( ast. item_tag( _, ?variants, ?tps, _) ) {
5905
5950
for ( ast. variant variant in variants) {
5906
5951
if ( _vec. len [ ast. variant_arg ] ( variant. args ) != 0 u) {
5907
- decl_fn_and_pair ( cx, "tag" , variant. name ,
5952
+ decl_fn_and_pair ( extend_path ( cx, variant. name ) , "tag" ,
5908
5953
tps, variant. ann , variant. id ) ;
5909
5954
}
5910
5955
}
@@ -5963,7 +6008,8 @@ fn trans_constant(&@crate_ctxt cx, @ast.item it) -> @crate_ctxt {
5963
6008
// with consts.
5964
6009
auto v = C_int ( 1 ) ;
5965
6010
cx. item_ids . insert ( cid, v) ;
5966
- auto s = cx. names . next ( "_rust_const" ) + sep ( ) + name;
6011
+ auto s = mangle_name_by_type ( extend_path ( cx, name) ,
6012
+ node_ann_type ( cx, ann) ) ;
5967
6013
cx. item_symbols . insert ( cid, s) ;
5968
6014
}
5969
6015
@@ -6064,10 +6110,10 @@ fn find_main_fn(@crate_ctxt cx) -> ValueRef {
6064
6110
auto e = sep ( ) + "main" ;
6065
6111
let ValueRef v = C_nil ( ) ;
6066
6112
let uint n = 0 u;
6067
- for each ( @tup( str , ValueRef ) i in cx. item_names . items ( ) ) {
6068
- if ( _str. ends_with ( i. _0 , e) ) {
6113
+ for each ( @tup( ast . def_id , str ) i in cx. item_symbols . items ( ) ) {
6114
+ if ( _str. ends_with ( i. _1 , e) ) {
6069
6115
n += 1 u;
6070
- v = i . _1 ;
6116
+ v = cx . item_ids . get ( i . _0 ) ;
6071
6117
}
6072
6118
}
6073
6119
alt ( n) {
@@ -6534,14 +6580,14 @@ fn trans_crate(session.session sess, @ast.crate crate, str output,
6534
6580
let vec[ ast. ty_param ] obj_typarams = vec ( ) ;
6535
6581
let vec[ ast. obj_field ] obj_fields = vec ( ) ;
6536
6582
6583
+ let vec[ str] pth = vec ( ) ;
6537
6584
auto cx = @rec ( sess = sess,
6538
6585
llmod = llmod,
6539
6586
td = td,
6540
6587
tn = tn,
6541
6588
crate_ptr = crate_ptr,
6542
6589
externs = new_str_hash[ ValueRef ] ( ) ,
6543
6590
intrinsics = intrinsics,
6544
- item_names = new_str_hash[ ValueRef ] ( ) ,
6545
6591
item_ids = new_def_hash[ ValueRef ] ( ) ,
6546
6592
items = new_def_hash[ @ast. item ] ( ) ,
6547
6593
native_items = new_def_hash[ @ast. native_item ] ( ) ,
@@ -6557,7 +6603,8 @@ fn trans_crate(session.session sess, @ast.crate crate, str output,
6557
6603
obj_fields = obj_fields,
6558
6604
glues = glues,
6559
6605
names = namegen ( 0 ) ,
6560
- path = "_rust" ) ;
6606
+ path = pth,
6607
+ sha = std. sha1 . mk_sha1 ( ) ) ;
6561
6608
6562
6609
create_typedefs ( cx) ;
6563
6610
0 commit comments