@@ -26,18 +26,21 @@ use syntax::attr;
26
26
pub fn maybe_instantiate_inline ( ccx : @mut CrateContext , fn_id : ast:: DefId )
27
27
-> ast:: DefId {
28
28
let _icx = push_ctxt ( "maybe_instantiate_inline" ) ;
29
- match ccx. external . find ( & fn_id) {
30
- Some ( & Some ( node_id) ) => {
31
- // Already inline
32
- debug ! ( "maybe_instantiate_inline({}): already inline as node id {}" ,
33
- ty:: item_path_str( ccx. tcx, fn_id) , node_id) ;
34
- return local_def ( node_id) ;
35
- }
36
- Some ( & None ) => {
37
- return fn_id; // Not inlinable
38
- }
39
- None => {
40
- // Not seen yet
29
+ {
30
+ let external = ccx. external . borrow ( ) ;
31
+ match external. get ( ) . find ( & fn_id) {
32
+ Some ( & Some ( node_id) ) => {
33
+ // Already inline
34
+ debug ! ( "maybe_instantiate_inline({}): already inline as node id {}" ,
35
+ ty:: item_path_str( ccx. tcx, fn_id) , node_id) ;
36
+ return local_def ( node_id) ;
37
+ }
38
+ Some ( & None ) => {
39
+ return fn_id; // Not inlinable
40
+ }
41
+ None => {
42
+ // Not seen yet
43
+ }
41
44
}
42
45
}
43
46
@@ -49,12 +52,18 @@ pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::DefId)
49
52
} ) ;
50
53
return match csearch_result {
51
54
csearch:: not_found => {
52
- ccx. external . insert ( fn_id, None ) ;
55
+ let mut external = ccx. external . borrow_mut ( ) ;
56
+ external. get ( ) . insert ( fn_id, None ) ;
53
57
fn_id
54
58
}
55
59
csearch:: found( ast:: ii_item( item) ) => {
56
- ccx. external . insert ( fn_id, Some ( item. id ) ) ;
57
- ccx. external_srcs . insert ( item. id , fn_id) ;
60
+ {
61
+ let mut external = ccx. external . borrow_mut ( ) ;
62
+ let mut external_srcs = ccx. external_srcs . borrow_mut ( ) ;
63
+ external. get ( ) . insert ( fn_id, Some ( item. id ) ) ;
64
+ external_srcs. get ( ) . insert ( item. id , fn_id) ;
65
+ }
66
+
58
67
ccx. stats . n_inlines += 1 ;
59
68
trans_item ( ccx, item) ;
60
69
@@ -82,28 +91,39 @@ pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::DefId)
82
91
local_def ( item. id )
83
92
}
84
93
csearch:: found( ast:: ii_foreign( item) ) => {
85
- ccx. external . insert ( fn_id, Some ( item. id ) ) ;
86
- ccx. external_srcs . insert ( item. id , fn_id) ;
87
- local_def ( item. id )
94
+ {
95
+ let mut external = ccx. external . borrow_mut ( ) ;
96
+ let mut external_srcs = ccx. external_srcs . borrow_mut ( ) ;
97
+ external. get ( ) . insert ( fn_id, Some ( item. id ) ) ;
98
+ external_srcs. get ( ) . insert ( item. id , fn_id) ;
99
+ }
100
+ local_def ( item. id )
88
101
}
89
102
csearch:: found_parent( parent_id, ast:: ii_item( item) ) => {
90
- ccx. external . insert ( parent_id, Some ( item. id ) ) ;
91
- ccx. external_srcs . insert ( item. id , parent_id) ;
103
+ {
104
+ let mut external = ccx. external . borrow_mut ( ) ;
105
+ let mut external_srcs = ccx. external_srcs . borrow_mut ( ) ;
106
+ external. get ( ) . insert ( parent_id, Some ( item. id ) ) ;
107
+ external_srcs. get ( ) . insert ( item. id , parent_id) ;
108
+ }
109
+
92
110
let mut my_id = 0 ;
93
111
match item. node {
94
112
ast:: item_enum( _, _) => {
95
113
let vs_here = ty:: enum_variants ( ccx. tcx , local_def ( item. id ) ) ;
96
114
let vs_there = ty:: enum_variants ( ccx. tcx , parent_id) ;
97
115
for ( here, there) in vs_here. iter ( ) . zip ( vs_there. iter ( ) ) {
98
116
if there. id == fn_id { my_id = here. id . node ; }
99
- ccx. external . insert ( there. id , Some ( here. id . node ) ) ;
117
+ let mut external = ccx. external . borrow_mut ( ) ;
118
+ external. get ( ) . insert ( there. id , Some ( here. id . node ) ) ;
100
119
}
101
120
}
102
121
ast:: item_struct( ref struct_def, _) => {
103
122
match struct_def. ctor_id {
104
123
None => { }
105
124
Some ( ctor_id) => {
106
- let _ = ccx. external . insert ( fn_id, Some ( ctor_id) ) ;
125
+ let mut external = ccx. external . borrow_mut ( ) ;
126
+ let _ = external. get ( ) . insert ( fn_id, Some ( ctor_id) ) ;
107
127
my_id = ctor_id;
108
128
}
109
129
}
@@ -119,9 +139,14 @@ pub fn maybe_instantiate_inline(ccx: @mut CrateContext, fn_id: ast::DefId)
119
139
with a non-item parent") ;
120
140
}
121
141
csearch:: found( ast:: ii_method( impl_did, is_provided, mth) ) => {
142
+ {
143
+ let mut external = ccx. external . borrow_mut ( ) ;
144
+ let mut external_srcs = ccx. external_srcs . borrow_mut ( ) ;
145
+ external. get ( ) . insert ( fn_id, Some ( mth. id ) ) ;
146
+ external_srcs. get ( ) . insert ( mth. id , fn_id) ;
147
+ }
148
+
122
149
ccx. stats . n_inlines += 1 ;
123
- ccx. external . insert ( fn_id, Some ( mth. id ) ) ;
124
- ccx. external_srcs . insert ( mth. id , fn_id) ;
125
150
// If this is a default method, we can't look up the
126
151
// impl type. But we aren't going to translate anyways, so don't.
127
152
if is_provided { return local_def ( mth. id ) ; }
0 commit comments