Skip to content

Commit

Permalink
Simplify trans/exprs.rs DefStatic considerably
Browse files Browse the repository at this point in the history
  • Loading branch information
nagisa committed Nov 10, 2015
1 parent 21deb18 commit f1342ff
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/librustc_trans/trans/common.rs
Expand Up @@ -1221,6 +1221,6 @@ pub fn get_static_val<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
if let Some(node_id) = ccx.tcx().map.as_local_node_id(did) {
base::get_item_val(ccx, node_id)
} else {
base::trans_external_path(ccx, did, ty)
base::get_extern_const(ccx, did, ty)
}
}
23 changes: 1 addition & 22 deletions src/librustc_trans/trans/expr.rs
Expand Up @@ -941,29 +941,8 @@ fn trans_def<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
DatumBlock::new(bcx, datum.to_expr_datum())
}
def::DefStatic(did, _) => {
// There are two things that may happen here:
// 1) If the static item is defined in this crate, it will be
// translated using `get_item_val`, and we return a pointer to
// the result.
// 2) If the static item is defined in another crate then we add
// (or reuse) a declaration of an external global, and return a
// pointer to that.
let const_ty = expr_ty(bcx, ref_expr);

// For external constants, we don't inline.
let val = if let Some(node_id) = bcx.tcx().map.as_local_node_id(did) {
// Case 1.

// The LLVM global has the type of its initializer,
// which may not be equal to the enum's type for
// non-C-like enums.
let val = base::get_item_val(bcx.ccx(), node_id);
let pty = type_of::type_of(bcx.ccx(), const_ty).ptr_to();
PointerCast(bcx, val, pty)
} else {
// Case 2.
base::get_extern_const(bcx.ccx(), did, const_ty)
};
let val = get_static_val(bcx.ccx(), did, const_ty);
let lval = Lvalue::new("expr::trans_def");
DatumBlock::new(bcx, Datum::new(val, const_ty, LvalueExpr(lval)))
}
Expand Down

0 comments on commit f1342ff

Please sign in to comment.