Skip to content

Commit 17459d0

Browse files
committed
rustc: Purge of HashMap, fixing segfaulting cases
Various FIXME comments added around to denote copies which when removed cause the compiler to segfault at some point before stage2. None of these copies should even be necessary.
1 parent 6f812fe commit 17459d0

17 files changed

+83
-61
lines changed

src/librustc/metadata/tyencode.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ pub fn enc_ty(w: @io::Writer, cx: @ctxt, t: ty::t) {
6161
match cx.abbrevs {
6262
ac_no_abbrevs => {
6363
let result_str = match cx.tcx.short_names_cache.find(&t) {
64-
Some(s) => /*bad*/copy *s,
64+
Some(&s) => /*bad*/copy *s,
6565
None => {
6666
let s = do io::with_str_writer |wr| {
6767
enc_sty(wr, cx, /*bad*/copy ty::get(t).sty);

src/librustc/middle/astencode.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,9 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
856856
do ebml_w.tag(c::tag_table_node_type_subst) {
857857
ebml_w.id(id);
858858
do ebml_w.tag(c::tag_table_val) {
859-
ebml_w.emit_tys(ecx, /*bad*/copy *tys)
859+
// FIXME(#5562): removing this copy causes a segfault
860+
// before stage2
861+
ebml_w.emit_tys(ecx, /*bad*/copy **tys)
860862
}
861863
}
862864
}
@@ -922,7 +924,7 @@ fn encode_side_tables_for_id(ecx: @e::EncodeContext,
922924
}
923925
}
924926
925-
for maps.method_map.find(&id).each |mme| {
927+
for maps.method_map.find(&id).each |&mme| {
926928
do ebml_w.tag(c::tag_table_method_map) {
927929
ebml_w.id(id);
928930
do ebml_w.tag(c::tag_table_val) {

src/librustc/middle/const_eval.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ use middle;
1717

1818
use core::float;
1919
use core::vec;
20-
use std::oldmap::HashMap;
2120
use syntax::{ast, ast_map, ast_util, visit};
2221
use syntax::ast::*;
2322

@@ -194,7 +193,7 @@ pub fn lookup_const_by_id(tcx: ty::ctxt,
194193
mutbl_map: @mut LinearSet::new(),
195194
root_map: @mut LinearMap::new(),
196195
last_use_map: @mut LinearMap::new(),
197-
method_map: HashMap(),
196+
method_map: @mut LinearMap::new(),
198197
vtable_map: @mut LinearMap::new(),
199198
write_guard_map: @mut LinearSet::new(),
200199
moves_map: @mut LinearSet::new(),

src/librustc/middle/kind.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,8 @@ pub fn check_expr(e: @expr, cx: Context, v: visit::vt<Context>) {
274274
_ => e.id
275275
};
276276
for cx.tcx.node_type_substs.find(&type_parameter_id).each |ts| {
277+
// FIXME(#5562): removing this copy causes a segfault before stage2
278+
let ts = /*bad*/ copy **ts;
277279
let bounds = match e.node {
278280
expr_path(_) => {
279281
let did = ast_util::def_id_of_def(*cx.tcx.def_map.get(&e.id));
@@ -289,15 +291,15 @@ pub fn check_expr(e: @expr, cx: Context, v: visit::vt<Context>) {
289291
~"non path/method call expr has type substs??")
290292
}
291293
};
292-
if vec::len(*ts) != vec::len(*bounds) {
294+
if ts.len() != bounds.len() {
293295
// Fail earlier to make debugging easier
294296
fail!(fmt!("internal error: in kind::check_expr, length \
295297
mismatch between actual and declared bounds: actual = \
296298
%s (%u tys), declared = %? (%u tys)",
297-
tys_to_str(cx.tcx, *ts), ts.len(),
298-
*bounds, (*bounds).len()));
299+
tys_to_str(cx.tcx, ts), ts.len(),
300+
*bounds, bounds.len()));
299301
}
300-
for vec::each2(*ts, *bounds) |ty, bound| {
302+
for vec::each2(ts, *bounds) |ty, bound| {
301303
check_bounds(cx, type_parameter_id, e.span, *ty, *bound)
302304
}
303305
}
@@ -335,9 +337,11 @@ fn check_ty(aty: @Ty, cx: Context, v: visit::vt<Context>) {
335337
match aty.node {
336338
ty_path(_, id) => {
337339
for cx.tcx.node_type_substs.find(&id).each |ts| {
340+
// FIXME(#5562): removing this copy causes a segfault before stage2
341+
let ts = /*bad*/ copy **ts;
338342
let did = ast_util::def_id_of_def(*cx.tcx.def_map.get(&id));
339343
let bounds = ty::lookup_item_type(cx.tcx, did).bounds;
340-
for vec::each2(*ts, *bounds) |ty, bound| {
344+
for vec::each2(ts, *bounds) |ty, bound| {
341345
check_bounds(cx, aty.id, aty.span, *ty, *bound)
342346
}
343347
}

src/librustc/middle/trans/base.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ use core::int;
7272
use core::io;
7373
use core::libc::{c_uint, c_ulonglong};
7474
use core::uint;
75-
use std::oldmap::HashMap;
76-
use std::{oldmap, time, list};
75+
use std::{time, list};
7776
use syntax::ast::ident;
7877
use syntax::ast_map::{path, path_elt_to_str, path_mod, path_name};
7978
use syntax::ast_util::{def_id_of_def, local_def, path_to_ident};
@@ -170,16 +169,22 @@ pub fn get_extern_fn(externs: ExternMap,
170169
name: @str,
171170
cc: lib::llvm::CallConv,
172171
ty: TypeRef) -> ValueRef {
173-
if externs.contains_key(&name) { return externs.get(&name); }
172+
match externs.find(&name) {
173+
Some(n) => return copy *n,
174+
None => ()
175+
}
174176
let f = decl_fn(llmod, name, cc, ty);
175177
externs.insert(name, f);
176178
return f;
177179
}
178180

179181
pub fn get_extern_const(externs: ExternMap, llmod: ModuleRef,
180182
name: @str, ty: TypeRef) -> ValueRef {
183+
match externs.find(&name) {
184+
Some(n) => return copy *n,
185+
None => ()
186+
}
181187
unsafe {
182-
if externs.contains_key(&name) { return externs.get(&name); }
183188
let c = str::as_c_str(name, |buf| {
184189
llvm::LLVMAddGlobal(llmod, ty, buf)
185190
});
@@ -3061,7 +3066,7 @@ pub fn trans_crate(sess: session::Session,
30613066
llmod: llmod,
30623067
td: td,
30633068
tn: tn,
3064-
externs: HashMap(),
3069+
externs: @mut LinearMap::new(),
30653070
intrinsics: intrinsics,
30663071
item_vals: @mut LinearMap::new(),
30673072
exp_map2: emap2,
@@ -3082,8 +3087,8 @@ pub fn trans_crate(sess: session::Session,
30823087
const_globals: @mut LinearMap::new(),
30833088
const_values: @mut LinearMap::new(),
30843089
module_data: @mut LinearMap::new(),
3085-
lltypes: ty::new_ty_hash(),
3086-
llsizingtypes: ty::new_ty_hash(),
3090+
lltypes: @mut LinearMap::new(),
3091+
llsizingtypes: @mut LinearMap::new(),
30873092
adt_reprs: @mut LinearMap::new(),
30883093
names: new_namegen(sess.parse_sess.interner),
30893094
next_addrspace: new_addrspace_gen(),

src/librustc/middle/trans/callee.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,12 @@ pub fn trans(bcx: block, expr: @ast::expr) -> Callee {
8282
}
8383
ast::expr_field(base, _, _) => {
8484
match bcx.ccx().maps.method_map.find(&expr.id) {
85-
Some(ref origin) => { // An impl method
85+
Some(origin) => { // An impl method
86+
// FIXME(#5562): removing this copy causes a segfault
87+
// before stage2
88+
let origin = /*bad*/ copy *origin;
8689
return meth::trans_method_callee(bcx, expr.id,
87-
base, (*origin));
90+
base, origin);
8891
}
8992
None => {} // not a method, just a field
9093
}
@@ -343,11 +346,14 @@ pub fn trans_method_call(in_cx: block,
343346
expr_ty(in_cx, call_ex),
344347
|cx| {
345348
match cx.ccx().maps.method_map.find(&call_ex.id) {
346-
Some(ref origin) => {
349+
Some(origin) => {
350+
// FIXME(#5562): removing this copy causes a segfault
351+
// before stage2
352+
let origin = /*bad*/ copy *origin;
347353
meth::trans_method_callee(cx,
348354
call_ex.callee_id,
349355
rcvr,
350-
(*origin))
356+
origin)
351357
}
352358
None => {
353359
cx.tcx().sess.span_bug(call_ex.span,

src/librustc/middle/trans/common.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ use core::str;
5252
use core::to_bytes;
5353
use core::vec::raw::to_ptr;
5454
use core::vec;
55-
use std::oldmap::{HashMap, Set};
5655
use syntax::ast::ident;
5756
use syntax::ast_map::{path, path_elt};
5857
use syntax::codemap::span;
@@ -156,7 +155,7 @@ pub fn BuilderRef_res(B: BuilderRef) -> BuilderRef_res {
156155
}
157156
}
158157

159-
pub type ExternMap = HashMap<@str, ValueRef>;
158+
pub type ExternMap = @mut LinearMap<@str, ValueRef>;
160159

161160
// Crate context. Every crate we compile has one of these.
162161
pub struct CrateContext {
@@ -203,8 +202,8 @@ pub struct CrateContext {
203202
// Cache of emitted const values
204203
const_values: @mut LinearMap<ast::node_id, ValueRef>,
205204
module_data: @mut LinearMap<~str, ValueRef>,
206-
lltypes: HashMap<ty::t, TypeRef>,
207-
llsizingtypes: HashMap<ty::t, TypeRef>,
205+
lltypes: @mut LinearMap<ty::t, TypeRef>,
206+
llsizingtypes: @mut LinearMap<ty::t, TypeRef>,
208207
adt_reprs: @mut LinearMap<ty::t, @adt::Repr>,
209208
names: namegen,
210209
next_addrspace: addrspace_gen,

src/librustc/middle/trans/expr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1647,7 +1647,7 @@ fn trans_overloaded_op(bcx: block,
16471647
dest: Dest,
16481648
+autoref_arg: AutorefArg) -> block
16491649
{
1650-
let origin = bcx.ccx().maps.method_map.get(&expr.id);
1650+
let origin = *bcx.ccx().maps.method_map.get(&expr.id);
16511651
let fty = node_id_type(bcx, expr.callee_id);
16521652
return callee::trans_call_inner(
16531653
bcx, expr.info(), fty,

src/librustc/middle/trans/glue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ pub fn make_visit_glue(bcx: block, v: ValueRef, t: ty::t) {
402402
let mut bcx = bcx;
403403
let ty_visitor_name = special_idents::ty_visitor;
404404
fail_unless!(bcx.ccx().tcx.intrinsic_defs.contains_key(&ty_visitor_name));
405-
let (trait_id, ty) = bcx.ccx().tcx.intrinsic_defs.get(&ty_visitor_name);
405+
let (trait_id, ty) = *bcx.ccx().tcx.intrinsic_defs.get(&ty_visitor_name);
406406
let v = PointerCast(bcx, v, T_ptr(type_of::type_of(bcx.ccx(), ty)));
407407
bcx = reflect::emit_calls_to_trait_visit_ty(bcx, t, v, trait_id);
408408
build_return(bcx);

src/librustc/middle/trans/reachable.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ fn traverse_inline_body(cx: ctx, body: &blk) {
193193
}
194194
expr_field(_, _, _) => {
195195
match cx.method_map.find(&e.id) {
196-
Some(typeck::method_map_entry {
196+
Some(&typeck::method_map_entry {
197197
origin: typeck::method_static(did),
198198
_
199199
}) => {
@@ -204,7 +204,7 @@ fn traverse_inline_body(cx: ctx, body: &blk) {
204204
}
205205
expr_method_call(*) => {
206206
match cx.method_map.find(&e.id) {
207-
Some(typeck::method_map_entry {
207+
Some(&typeck::method_map_entry {
208208
origin: typeck::method_static(did),
209209
_
210210
}) => {

src/librustc/middle/trans/reflect.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ pub fn emit_calls_to_trait_visit_ty(bcx: block,
337337
use syntax::parse::token::special_idents::tydesc;
338338
let final = sub_block(bcx, ~"final");
339339
fail_unless!(bcx.ccx().tcx.intrinsic_defs.contains_key(&tydesc));
340-
let (_, tydesc_ty) = bcx.ccx().tcx.intrinsic_defs.get(&tydesc);
340+
let (_, tydesc_ty) = *bcx.ccx().tcx.intrinsic_defs.get(&tydesc);
341341
let tydesc_ty = type_of(bcx.ccx(), tydesc_ty);
342342
let mut r = Reflector {
343343
visitor_val: visitor_val,

src/librustc/middle/trans/type_of.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,10 @@ pub fn type_of_non_gc_box(cx: @CrateContext, t: ty::t) -> TypeRef {
101101
// behavior.
102102

103103
pub fn sizing_type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
104-
if cx.llsizingtypes.contains_key(&t) {
105-
return cx.llsizingtypes.get(&t);
104+
match cx.llsizingtypes.find(&t) {
105+
// FIXME(#5562): removing this copy causes a segfault in stage1 core
106+
Some(t) => return /*bad*/ copy *t,
107+
None => ()
106108
}
107109

108110
let llsizingty = match ty::get(t).sty {
@@ -161,7 +163,11 @@ pub fn type_of(cx: @CrateContext, t: ty::t) -> TypeRef {
161163
debug!("type_of %?: %?", t, ty::get(t));
162164

163165
// Check the cache.
164-
if cx.lltypes.contains_key(&t) { return cx.lltypes.get(&t); }
166+
match cx.lltypes.find(&t) {
167+
// FIXME(#5562): removing this copy causes a segfault in stage1 core
168+
Some(t) => return /*bad*/ copy *t,
169+
None => ()
170+
}
165171

166172
// Replace any typedef'd types with their equivalent non-typedef
167173
// type. This ensures that all LLVM nominal types that contain

src/librustc/middle/trans/type_use.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,11 @@ pub fn mark_for_method_call(cx: Context, e_id: node_id, callee_id: node_id) {
250250
match mth.origin {
251251
typeck::method_static(did) => {
252252
for cx.ccx.tcx.node_type_substs.find(&callee_id).each |ts| {
253+
// FIXME(#5562): removing this copy causes a segfault
254+
// before stage2
255+
let ts = /*bad*/ copy **ts;
253256
let type_uses = type_uses_for(cx.ccx, did, ts.len());
254-
for vec::each2(type_uses, *ts) |uses, subst| {
257+
for vec::each2(type_uses, ts) |uses, subst| {
255258
type_needs(cx, *uses, *subst)
256259
}
257260
}
@@ -296,9 +299,11 @@ pub fn mark_for_expr(cx: Context, e: @expr) {
296299
}
297300
expr_path(_) => {
298301
for cx.ccx.tcx.node_type_substs.find(&e.id).each |ts| {
302+
// FIXME(#5562): removing this copy causes a segfault before stage2
303+
let ts = copy **ts;
299304
let id = ast_util::def_id_of_def(*cx.ccx.tcx.def_map.get(&e.id));
300305
let uses_for_ts = type_uses_for(cx.ccx, id, ts.len());
301-
for vec::each2(uses_for_ts, *ts) |uses, subst| {
306+
for vec::each2(uses_for_ts, ts) |uses, subst| {
302307
type_needs(cx, *uses, *subst)
303308
}
304309
}

0 commit comments

Comments
 (0)