Fix the problem with check-fast randomly failing

Trans has been assuming that tag node id's are unique across crates and they
are not so, depending on which way the wind is blowing, it would choose to use
a crate-local tag variant instead of the correct one from std.

No test case since I can't come up with a reliable one that compiles in a
reasonable amount of time.
This commit is contained in:
Brian Anderson 2011-10-20 15:26:26 -07:00
parent f8f1d950ef
commit 0714bb5f7d
3 changed files with 18 additions and 5 deletions

View file

@ -3026,7 +3026,7 @@ fn lval_static_fn(bcx: @block_ctxt, tpt: ty::ty_param_kinds_and_ty,
}
fn lookup_discriminant(lcx: @local_ctxt, vid: ast::def_id) -> ValueRef {
alt lcx.ccx.discrims.find(vid.node) {
alt lcx.ccx.discrims.find(vid) {
none. {
// It's an external discriminant that we haven't seen yet.
assert (vid.crate != ast::local_crate);
@ -3039,7 +3039,7 @@ fn lookup_discriminant(lcx: @local_ctxt, vid: ast::def_id) -> ValueRef {
llvm::LLVMSetLinkage(gvar,
lib::llvm::LLVMExternalLinkage as llvm::Linkage);
llvm::LLVMSetGlobalConstant(gvar, True);
lcx.ccx.discrims.insert(vid.node, gvar);
lcx.ccx.discrims.insert(vid, gvar);
ret gvar;
}
some(llval) { ret llval; }
@ -6086,7 +6086,8 @@ fn trans_constant(ccx: @crate_ctxt, it: @ast::item, &&pt: [str],
});
llvm::LLVMSetInitializer(discrim_gvar, C_int(i as int));
llvm::LLVMSetGlobalConstant(discrim_gvar, True);
ccx.discrims.insert(variant.node.id, discrim_gvar);
ccx.discrims.insert(
ast_util::local_def(variant.node.id), discrim_gvar);
ccx.discrim_symbols.insert(variant.node.id, s);
i += 1u;
}
@ -6288,7 +6289,7 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
mutable main_fn: none::<ValueRef>,
link_meta: link_meta,
tag_sizes: tag_sizes,
discrims: new_int_hash::<ValueRef>(),
discrims: ast_util::new_def_id_hash::<ValueRef>(),
discrim_symbols: new_int_hash::<str>(),
consts: new_int_hash::<ValueRef>(),
obj_methods: new_int_hash::<()>(),

View file

@ -102,7 +102,7 @@ type crate_ctxt =
mutable main_fn: option::t<ValueRef>,
link_meta: link::link_meta,
tag_sizes: hashmap<ty::t, uint>,
discrims: hashmap<ast::node_id, ValueRef>,
discrims: hashmap<ast::def_id, ValueRef>,
discrim_symbols: hashmap<ast::node_id, str>,
consts: hashmap<ast::node_id, ValueRef>,
obj_methods: hashmap<ast::node_id, ()>,

View file

@ -184,6 +184,18 @@ fn eq_ty(&&a: @ty, &&b: @ty) -> bool { ret std::box::ptr_eq(a, b); }
fn hash_ty(&&t: @ty) -> uint { ret t.span.lo << 16u + t.span.hi; }
fn hash_def_id(&&id: def_id) -> uint {
id.crate as uint << 16u + (id.node as uint)
}
fn eq_def_id(&&a: def_id, &&b: def_id) -> bool {
a == b
}
fn new_def_id_hash<@T>() -> std::map::hashmap<def_id, T> {
std::map::mk_hashmap(hash_def_id, eq_def_id)
}
fn block_from_expr(e: @expr) -> blk {
let blk_ = default_block([], option::some::<@expr>(e), e.id);
ret {node: blk_, span: e.span};