Skip to content

Commit

Permalink
auto merge of #4823 : pcwalton/rust/enum-variant-discriminants, r=gra…
Browse files Browse the repository at this point in the history
…ydon

r? @graydon
  • Loading branch information
bors committed Feb 7, 2013
2 parents fa69739 + 6d13c90 commit 82d7396
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 24 deletions.
21 changes: 0 additions & 21 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -813,27 +813,6 @@ pub fn get_discrim_val(cx: @crate_ctxt, span: span, enum_did: ast::def_id,
}
}

pub fn lookup_discriminant(ccx: @crate_ctxt, vid: ast::def_id) -> ValueRef {
unsafe {
let _icx = ccx.insn_ctxt("lookup_discriminant");
match ccx.discrims.find(&vid) {
None => {
// It's an external discriminant that we haven't seen yet.
assert (vid.crate != ast::local_crate);
let sym = csearch::get_symbol(ccx.sess.cstore, vid);
let gvar = str::as_c_str(sym, |buf| {
llvm::LLVMAddGlobal(ccx.llmod, ccx.int_type, buf)
});
lib::llvm::SetLinkage(gvar, lib::llvm::ExternalLinkage);
llvm::LLVMSetGlobalConstant(gvar, True);
ccx.discrims.insert(vid, gvar);
return gvar;
}
Some(llval) => return llval,
}
}
}

pub fn invoke(bcx: block, llfn: ValueRef, +llargs: ~[ValueRef]) -> block {
let _icx = bcx.insn_ctxt("invoke_");
if bcx.unreachable { return bcx; }
Expand Down
6 changes: 3 additions & 3 deletions src/librustc/middle/trans/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -696,15 +696,15 @@ fn trans_def_dps_unadjusted(bcx: block, ref_expr: @ast::expr,
return fn_data_to_datum(bcx, impl_did, fn_data, lldest);
}
ast::def_variant(tid, vid) => {
if ty::enum_variant_with_id(ccx.tcx, tid, vid).args.len() > 0u {
let variant_info = ty::enum_variant_with_id(ccx.tcx, tid, vid);
if variant_info.args.len() > 0u {
// N-ary variant.
let fn_data = callee::trans_fn_ref(bcx, vid, ref_expr.id);
return fn_data_to_datum(bcx, vid, fn_data, lldest);
} else {
// Nullary variant.
let lldiscrimptr = GEPi(bcx, lldest, [0u, 0u]);
let lldiscrim_gv = base::lookup_discriminant(ccx, vid);
let lldiscrim = Load(bcx, lldiscrim_gv);
let lldiscrim = C_int(bcx.ccx(), variant_info.disr_val);
Store(bcx, lldiscrim, lldiscrimptr);
return bcx;
}
Expand Down

0 comments on commit 82d7396

Please sign in to comment.