rustc_trans: access fields directly on CrateContext.

This commit is contained in:
Eduard-Mihai Burtescu
2018-01-05 06:58:34 +02:00
parent 7b3ac21427
commit 2931af62f0
31 changed files with 298 additions and 393 deletions
+3 -3
View File
@@ -649,9 +649,9 @@ pub struct FnType<'tcx> {
impl<'a, 'tcx> FnType<'tcx> {
pub fn of_instance(ccx: &CrateContext<'a, 'tcx>, instance: &ty::Instance<'tcx>)
-> Self {
let fn_ty = instance.ty(ccx.tcx());
let fn_ty = instance.ty(ccx.tcx);
let sig = ty_fn_sig(ccx, fn_ty);
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&sig);
let sig = ccx.tcx.erase_late_bound_regions_and_normalize(&sig);
FnType::new(ccx, sig, &[])
}
@@ -681,7 +681,7 @@ pub fn new_vtable(ccx: &CrateContext<'a, 'tcx>,
.unwrap_or_else(|| {
bug!("FnType::new_vtable: non-pointer self {:?}", self_arg)
}).ty;
let fat_ptr_ty = ccx.tcx().mk_mut_ptr(pointee);
let fat_ptr_ty = ccx.tcx.mk_mut_ptr(pointee);
self_arg.layout = ccx.layout_of(fat_ptr_ty).field(ccx, 0);
}
fn_ty.adjust_for_abi(ccx, sig.abi);
+3 -3
View File
@@ -109,13 +109,13 @@ pub fn trans_inline_asm<'a, 'tcx>(
// back to source locations. See #17552.
unsafe {
let key = "srcloc";
let kind = llvm::LLVMGetMDKindIDInContext(bcx.ccx.llcx(),
let kind = llvm::LLVMGetMDKindIDInContext(bcx.ccx.llcx,
key.as_ptr() as *const c_char, key.len() as c_uint);
let val: llvm::ValueRef = C_i32(bcx.ccx, ia.ctxt.outer().as_u32() as i32);
llvm::LLVMSetMetadata(r, kind,
llvm::LLVMMDNodeInContext(bcx.ccx.llcx(), &val, 1));
llvm::LLVMMDNodeInContext(bcx.ccx.llcx, &val, 1));
}
}
@@ -123,6 +123,6 @@ pub fn trans_global_asm<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
ga: &hir::GlobalAsm) {
let asm = CString::new(ga.asm.as_str().as_bytes()).unwrap();
unsafe {
llvm::LLVMRustAppendModuleInlineAsm(ccx.llmod(), asm.as_ptr());
llvm::LLVMRustAppendModuleInlineAsm(ccx.llmod, asm.as_ptr());
}
}
+2 -2
View File
@@ -103,7 +103,7 @@ pub fn set_probestack(ccx: &CrateContext, llfn: ValueRef) {
/// attributes.
pub fn from_fn_attrs(ccx: &CrateContext, llfn: ValueRef, id: DefId) {
use syntax::attr::*;
let attrs = ccx.tcx().get_attrs(id);
let attrs = ccx.tcx.get_attrs(id);
inline(llfn, find_inline_attr(Some(ccx.sess().diagnostic()), &attrs));
set_frame_pointer_elimination(ccx, llfn);
@@ -124,7 +124,7 @@ pub fn from_fn_attrs(ccx: &CrateContext, llfn: ValueRef, id: DefId) {
}
}
let target_features = ccx.tcx().target_features_enabled(id);
let target_features = ccx.tcx.target_features_enabled(id);
if !target_features.is_empty() {
let val = CString::new(target_features.join(",")).unwrap();
llvm::AddFunctionAttrStringValue(
+26 -26
View File
@@ -101,7 +101,7 @@ pub struct StatRecorder<'a, 'tcx: 'a> {
impl<'a, 'tcx> StatRecorder<'a, 'tcx> {
pub fn new(ccx: &'a CrateContext<'a, 'tcx>, name: String) -> StatRecorder<'a, 'tcx> {
let istart = ccx.stats().borrow().n_llvm_insns;
let istart = ccx.stats.borrow().n_llvm_insns;
StatRecorder {
ccx,
name: Some(name),
@@ -113,7 +113,7 @@ pub fn new(ccx: &'a CrateContext<'a, 'tcx>, name: String) -> StatRecorder<'a, 't
impl<'a, 'tcx> Drop for StatRecorder<'a, 'tcx> {
fn drop(&mut self) {
if self.ccx.sess().trans_stats() {
let mut stats = self.ccx.stats().borrow_mut();
let mut stats = self.ccx.stats.borrow_mut();
let iend = stats.n_llvm_insns;
stats.fn_stats.push((self.name.take().unwrap(), iend - self.istart));
stats.n_fns += 1;
@@ -194,7 +194,7 @@ pub fn unsized_info<'ccx, 'tcx>(ccx: &CrateContext<'ccx, 'tcx>,
target: Ty<'tcx>,
old_info: Option<ValueRef>)
-> ValueRef {
let (source, target) = ccx.tcx().struct_lockstep_tails(source, target);
let (source, target) = ccx.tcx.struct_lockstep_tails(source, target);
match (&source.sty, &target.sty) {
(&ty::TyArray(_, len), &ty::TySlice(_)) => {
C_usize(ccx, len.val.to_const_int().unwrap().to_u64().unwrap())
@@ -206,7 +206,7 @@ pub fn unsized_info<'ccx, 'tcx>(ccx: &CrateContext<'ccx, 'tcx>,
old_info.expect("unsized_info: missing old info for trait upcast")
}
(_, &ty::TyDynamic(ref data, ..)) => {
let vtable_ptr = ccx.layout_of(ccx.tcx().mk_mut_ptr(target))
let vtable_ptr = ccx.layout_of(ccx.tcx.mk_mut_ptr(target))
.field(ccx, abi::FAT_PTR_EXTRA);
consts::ptrcast(meth::get_vtable(ccx, source, data.principal()),
vtable_ptr.llvm_type(ccx))
@@ -421,7 +421,7 @@ pub fn call_memcpy(b: &Builder,
let memcpy = ccx.get_intrinsic(&key);
let src_ptr = b.pointercast(src, Type::i8p(ccx));
let dst_ptr = b.pointercast(dst, Type::i8p(ccx));
let size = b.intcast(n_bytes, ccx.isize_ty(), false);
let size = b.intcast(n_bytes, ccx.isize_ty, false);
let align = C_i32(ccx, align.abi() as i32);
let volatile = C_bool(ccx, false);
b.call(memcpy, &[dst_ptr, src_ptr, size, align, volatile], None);
@@ -458,7 +458,7 @@ pub fn call_memset<'a, 'tcx>(b: &Builder<'a, 'tcx>,
pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance<'tcx>) {
let _s = if ccx.sess().trans_stats() {
let mut instance_name = String::new();
DefPathBasedNames::new(ccx.tcx(), true, true)
DefPathBasedNames::new(ccx.tcx, true, true)
.push_def_path(instance.def_id(), &mut instance_name);
Some(StatRecorder::new(ccx, instance_name))
} else {
@@ -470,16 +470,16 @@ pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance
// release builds.
info!("trans_instance({})", instance);
let fn_ty = instance.ty(ccx.tcx());
let fn_ty = instance.ty(ccx.tcx);
let sig = common::ty_fn_sig(ccx, fn_ty);
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&sig);
let sig = ccx.tcx.erase_late_bound_regions_and_normalize(&sig);
let lldecl = match ccx.instances().borrow().get(&instance) {
let lldecl = match ccx.instances.borrow().get(&instance) {
Some(&val) => val,
None => bug!("Instance `{:?}` not already declared", instance)
};
ccx.stats().borrow_mut().n_closures += 1;
ccx.stats.borrow_mut().n_closures += 1;
// The `uwtable` attribute according to LLVM is:
//
@@ -502,7 +502,7 @@ pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance
attributes::emit_uwtable(lldecl, true);
}
let mir = ccx.tcx().instance_mir(instance.def);
let mir = ccx.tcx.instance_mir(instance.def);
mir::trans_mir(ccx, lldecl, &mir, instance, sig);
}
@@ -525,14 +525,14 @@ pub fn set_link_section(ccx: &CrateContext,
fn maybe_create_entry_wrapper(ccx: &CrateContext) {
let (main_def_id, span) = match *ccx.sess().entry_fn.borrow() {
Some((id, span)) => {
(ccx.tcx().hir.local_def_id(id), span)
(ccx.tcx.hir.local_def_id(id), span)
}
None => return,
};
let instance = Instance::mono(ccx.tcx(), main_def_id);
let instance = Instance::mono(ccx.tcx, main_def_id);
if !ccx.codegen_unit().contains_item(&MonoItem::Fn(instance)) {
if !ccx.codegen_unit.contains_item(&MonoItem::Fn(instance)) {
// We want to create the wrapper in the same codegen unit as Rust's main
// function.
return;
@@ -554,7 +554,7 @@ fn create_entry_fn<'ccx>(ccx: &'ccx CrateContext,
use_start_lang_item: bool) {
let llfty = Type::func(&[Type::c_int(ccx), Type::i8p(ccx).ptr_to()], &Type::c_int(ccx));
let main_ret_ty = ccx.tcx().fn_sig(rust_main_def_id).output();
let main_ret_ty = ccx.tcx.fn_sig(rust_main_def_id).output();
// Given that `main()` has no arguments,
// then its return type cannot have
// late-bound regions, since late-bound
@@ -582,12 +582,12 @@ fn create_entry_fn<'ccx>(ccx: &'ccx CrateContext,
// Params from native main() used as args for rust start function
let param_argc = get_param(llfn, 0);
let param_argv = get_param(llfn, 1);
let arg_argc = bld.intcast(param_argc, ccx.isize_ty(), true);
let arg_argc = bld.intcast(param_argc, ccx.isize_ty, true);
let arg_argv = param_argv;
let (start_fn, args) = if use_start_lang_item {
let start_def_id = ccx.tcx().require_lang_item(StartFnLangItem);
let start_fn = callee::resolve_and_get_fn(ccx, start_def_id, ccx.tcx().mk_substs(
let start_def_id = ccx.tcx.require_lang_item(StartFnLangItem);
let start_fn = callee::resolve_and_get_fn(ccx, start_def_id, ccx.tcx.mk_substs(
iter::once(Kind::from(main_ret_ty))));
(start_fn, vec![bld.pointercast(rust_main, Type::i8p(ccx).ptr_to()),
arg_argc, arg_argv])
@@ -1205,8 +1205,8 @@ fn module_translation<'a, 'tcx>(
// Instantiate translation items without filling out definitions yet...
let ccx = CrateContext::new(tcx, cgu, &llmod_id);
let module = {
let trans_items = ccx.codegen_unit()
.items_in_deterministic_order(ccx.tcx());
let trans_items = ccx.codegen_unit
.items_in_deterministic_order(ccx.tcx);
for &(trans_item, (linkage, visibility)) in &trans_items {
trans_item.predefine(&ccx, linkage, visibility);
}
@@ -1221,7 +1221,7 @@ fn module_translation<'a, 'tcx>(
maybe_create_entry_wrapper(&ccx);
// Run replace-all-uses-with for statics that need it
for &(old_g, new_g) in ccx.statics_to_rauw().borrow().iter() {
for &(old_g, new_g) in ccx.statics_to_rauw.borrow().iter() {
unsafe {
let bitcast = llvm::LLVMConstPointerCast(new_g, llvm::LLVMTypeOf(old_g));
llvm::LLVMReplaceAllUsesWith(old_g, bitcast);
@@ -1231,13 +1231,13 @@ fn module_translation<'a, 'tcx>(
// Create the llvm.used variable
// This variable has type [N x i8*] and is stored in the llvm.metadata section
if !ccx.used_statics().borrow().is_empty() {
if !ccx.used_statics.borrow().is_empty() {
let name = CString::new("llvm.used").unwrap();
let section = CString::new("llvm.metadata").unwrap();
let array = C_array(Type::i8(&ccx).ptr_to(), &*ccx.used_statics().borrow());
let array = C_array(Type::i8(&ccx).ptr_to(), &*ccx.used_statics.borrow());
unsafe {
let g = llvm::LLVMAddGlobal(ccx.llmod(),
let g = llvm::LLVMAddGlobal(ccx.llmod,
val_ty(array).to_ref(),
name.as_ptr());
llvm::LLVMSetInitializer(g, array);
@@ -1252,8 +1252,8 @@ fn module_translation<'a, 'tcx>(
}
let llvm_module = ModuleLlvm {
llcx: ccx.llcx(),
llmod: ccx.llmod(),
llcx: ccx.llcx,
llmod: ccx.llmod,
tm: create_target_machine(ccx.sess()),
};
+9 -9
View File
@@ -56,7 +56,7 @@ pub fn new_block<'b>(ccx: &'a CrateContext<'a, 'tcx>, llfn: ValueRef, name: &'b
let llbb = unsafe {
let name = CString::new(name).unwrap();
llvm::LLVMAppendBasicBlockInContext(
ccx.llcx(),
ccx.llcx,
llfn,
name.as_ptr()
)
@@ -68,7 +68,7 @@ pub fn new_block<'b>(ccx: &'a CrateContext<'a, 'tcx>, llfn: ValueRef, name: &'b
pub fn with_ccx(ccx: &'a CrateContext<'a, 'tcx>) -> Self {
// Create a fresh builder from the crate context.
let llbuilder = unsafe {
llvm::LLVMCreateBuilderInContext(ccx.llcx())
llvm::LLVMCreateBuilderInContext(ccx.llcx)
};
Builder {
llbuilder,
@@ -85,7 +85,7 @@ pub fn sess(&self) -> &Session {
}
pub fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> {
self.ccx.tcx()
self.ccx.tcx
}
pub fn llfn(&self) -> ValueRef {
@@ -102,10 +102,10 @@ pub fn llbb(&self) -> BasicBlockRef {
fn count_insn(&self, category: &str) {
if self.ccx.sess().trans_stats() {
self.ccx.stats().borrow_mut().n_llvm_insns += 1;
self.ccx.stats.borrow_mut().n_llvm_insns += 1;
}
if self.ccx.sess().count_llvm_insns() {
*self.ccx.stats()
*self.ccx.stats
.borrow_mut()
.llvm_insns
.entry(category.to_string())
@@ -558,7 +558,7 @@ pub fn range_metadata(&self, load: ValueRef, range: Range<u128>) {
];
llvm::LLVMSetMetadata(load, llvm::MD_range as c_uint,
llvm::LLVMMDNodeInContext(self.ccx.llcx(),
llvm::LLVMMDNodeInContext(self.ccx.llcx,
v.as_ptr(),
v.len() as c_uint));
}
@@ -567,7 +567,7 @@ pub fn range_metadata(&self, load: ValueRef, range: Range<u128>) {
pub fn nonnull_metadata(&self, load: ValueRef) {
unsafe {
llvm::LLVMSetMetadata(load, llvm::MD_nonnull as c_uint,
llvm::LLVMMDNodeInContext(self.ccx.llcx(), ptr::null(), 0));
llvm::LLVMMDNodeInContext(self.ccx.llcx, ptr::null(), 0));
}
}
@@ -621,7 +621,7 @@ pub fn nontemporal_store(&self, val: ValueRef, ptr: ValueRef) -> ValueRef {
//
// [1]: http://llvm.org/docs/LangRef.html#store-instruction
let one = C_i32(self.ccx, 1);
let node = llvm::LLVMMDNodeInContext(self.ccx.llcx(),
let node = llvm::LLVMMDNodeInContext(self.ccx.llcx,
&one,
1);
llvm::LLVMSetMetadata(insn,
@@ -1160,7 +1160,7 @@ pub fn add_incoming_to_phi(&self, phi: ValueRef, val: ValueRef, bb: BasicBlockRe
pub fn set_invariant_load(&self, load: ValueRef) {
unsafe {
llvm::LLVMSetMetadata(load, llvm::MD_invariant_load as c_uint,
llvm::LLVMMDNodeInContext(self.ccx.llcx(), ptr::null(), 0));
llvm::LLVMMDNodeInContext(self.ccx.llcx, ptr::null(), 0));
}
}
+2 -2
View File
@@ -20,12 +20,12 @@ fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
ret.extend_integer_width_to(32);
} else {
ret.make_indirect();
*offset += ccx.tcx().data_layout.pointer_size;
*offset += ccx.tcx.data_layout.pointer_size;
}
}
fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType, offset: &mut Size) {
let dl = &ccx.tcx().data_layout;
let dl = &ccx.tcx.data_layout;
let size = arg.layout.size;
let align = arg.layout.align.max(dl.i32_align).min(dl.i64_align);
+2 -2
View File
@@ -20,12 +20,12 @@ fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
ret.extend_integer_width_to(64);
} else {
ret.make_indirect();
*offset += ccx.tcx().data_layout.pointer_size;
*offset += ccx.tcx.data_layout.pointer_size;
}
}
fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType, offset: &mut Size) {
let dl = &ccx.tcx().data_layout;
let dl = &ccx.tcx.data_layout;
let size = arg.layout.size;
let align = arg.layout.align.max(dl.i32_align).min(dl.i64_align);
+2 -2
View File
@@ -20,12 +20,12 @@ fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
ret.extend_integer_width_to(32);
} else {
ret.make_indirect();
*offset += ccx.tcx().data_layout.pointer_size;
*offset += ccx.tcx.data_layout.pointer_size;
}
}
fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType, offset: &mut Size) {
let dl = &ccx.tcx().data_layout;
let dl = &ccx.tcx.data_layout;
let size = arg.layout.size;
let align = arg.layout.align.max(dl.i32_align).min(dl.i64_align);
+2 -2
View File
@@ -20,12 +20,12 @@ fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
ret.extend_integer_width_to(32);
} else {
ret.make_indirect();
*offset += ccx.tcx().data_layout.pointer_size;
*offset += ccx.tcx.data_layout.pointer_size;
}
}
fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType, offset: &mut Size) {
let dl = &ccx.tcx().data_layout;
let dl = &ccx.tcx.data_layout;
let size = arg.layout.size;
let align = arg.layout.align.max(dl.i32_align).min(dl.i64_align);
+8 -8
View File
@@ -40,7 +40,7 @@ pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
instance: Instance<'tcx>)
-> ValueRef
{
let tcx = ccx.tcx();
let tcx = ccx.tcx;
debug!("get_fn(instance={:?})", instance);
@@ -48,8 +48,8 @@ pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
assert!(!instance.substs.has_escaping_regions());
assert!(!instance.substs.has_param_types());
let fn_ty = instance.ty(ccx.tcx());
if let Some(&llfn) = ccx.instances().borrow().get(&instance) {
let fn_ty = instance.ty(ccx.tcx);
if let Some(&llfn) = ccx.instances.borrow().get(&instance) {
return llfn;
}
@@ -149,9 +149,9 @@ pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
unsafe {
llvm::LLVMRustSetLinkage(llfn, llvm::Linkage::ExternalLinkage);
if ccx.tcx().is_translated_function(instance_def_id) {
if ccx.tcx.is_translated_function(instance_def_id) {
if instance_def_id.is_local() {
if !ccx.tcx().is_exported_symbol(instance_def_id) {
if !ccx.tcx.is_exported_symbol(instance_def_id) {
llvm::LLVMRustSetVisibility(llfn, llvm::Visibility::Hidden);
}
} else {
@@ -160,7 +160,7 @@ pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
}
}
if ccx.use_dll_storage_attrs() &&
if ccx.use_dll_storage_attrs &&
tcx.is_dllimport_foreign_item(instance_def_id)
{
unsafe {
@@ -171,7 +171,7 @@ pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
llfn
};
ccx.instances().borrow_mut().insert(instance, llfn);
ccx.instances.borrow_mut().insert(instance, llfn);
llfn
}
@@ -184,7 +184,7 @@ pub fn resolve_and_get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
get_fn(
ccx,
ty::Instance::resolve(
ccx.tcx(),
ccx.tcx,
ty::ParamEnv::empty(traits::Reveal::All),
def_id,
substs
+11 -11
View File
@@ -175,7 +175,7 @@ pub fn C_usize(ccx: &CrateContext, i: u64) -> ValueRef {
assert!(i < (1<<bit_size));
}
C_uint(ccx.isize_ty(), i)
C_uint(ccx.isize_ty, i)
}
pub fn C_u8(ccx: &CrateContext, i: u8) -> ValueRef {
@@ -187,11 +187,11 @@ pub fn C_u8(ccx: &CrateContext, i: u8) -> ValueRef {
// our boxed-and-length-annotated strings.
pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> ValueRef {
unsafe {
if let Some(&llval) = cx.const_cstr_cache().borrow().get(&s) {
if let Some(&llval) = cx.const_cstr_cache.borrow().get(&s) {
return llval;
}
let sc = llvm::LLVMConstStringInContext(cx.llcx(),
let sc = llvm::LLVMConstStringInContext(cx.llcx,
s.as_ptr() as *const c_char,
s.len() as c_uint,
!null_terminated as Bool);
@@ -203,7 +203,7 @@ pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> Va
llvm::LLVMSetGlobalConstant(g, True);
llvm::LLVMRustSetLinkage(g, llvm::Linkage::InternalLinkage);
cx.const_cstr_cache().borrow_mut().insert(s, g);
cx.const_cstr_cache.borrow_mut().insert(s, g);
g
}
}
@@ -213,7 +213,7 @@ pub fn C_cstr(cx: &CrateContext, s: InternedString, null_terminated: bool) -> Va
pub fn C_str_slice(cx: &CrateContext, s: InternedString) -> ValueRef {
let len = s.len();
let cs = consts::ptrcast(C_cstr(cx, s, false),
cx.layout_of(cx.tcx().mk_str()).llvm_type(cx).ptr_to());
cx.layout_of(cx.tcx.mk_str()).llvm_type(cx).ptr_to());
C_fat_ptr(cx, cs, C_usize(cx, len as u64))
}
@@ -224,7 +224,7 @@ pub fn C_fat_ptr(cx: &CrateContext, ptr: ValueRef, meta: ValueRef) -> ValueRef {
}
pub fn C_struct(cx: &CrateContext, elts: &[ValueRef], packed: bool) -> ValueRef {
C_struct_in_context(cx.llcx(), elts, packed)
C_struct_in_context(cx.llcx, elts, packed)
}
pub fn C_struct_in_context(llcx: ContextRef, elts: &[ValueRef], packed: bool) -> ValueRef {
@@ -248,7 +248,7 @@ pub fn C_vector(elts: &[ValueRef]) -> ValueRef {
}
pub fn C_bytes(cx: &CrateContext, bytes: &[u8]) -> ValueRef {
C_bytes_in_context(cx.llcx(), bytes)
C_bytes_in_context(cx.llcx, bytes)
}
pub fn C_bytes_in_context(llcx: ContextRef, bytes: &[u8]) -> ValueRef {
@@ -389,9 +389,9 @@ pub fn ty_fn_sig<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
match ty.sty {
ty::TyFnDef(..) |
// Shims currently have type TyFnPtr. Not sure this should remain.
ty::TyFnPtr(_) => ty.fn_sig(ccx.tcx()),
ty::TyFnPtr(_) => ty.fn_sig(ccx.tcx),
ty::TyClosure(def_id, substs) => {
let tcx = ccx.tcx();
let tcx = ccx.tcx;
let sig = substs.closure_sig(def_id, tcx);
let env_ty = tcx.closure_env_ty(def_id, substs).unwrap();
@@ -404,8 +404,8 @@ pub fn ty_fn_sig<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
))
}
ty::TyGenerator(def_id, substs, _) => {
let tcx = ccx.tcx();
let sig = substs.generator_poly_sig(def_id, ccx.tcx());
let tcx = ccx.tcx;
let sig = substs.generator_poly_sig(def_id, ccx.tcx);
let env_region = ty::ReLateBound(ty::DebruijnIndex::new(1), ty::BrEnv);
let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty);
+26 -26
View File
@@ -85,7 +85,7 @@ pub fn addr_of(ccx: &CrateContext,
align: Align,
kind: &str)
-> ValueRef {
if let Some(&gv) = ccx.const_globals().borrow().get(&cv) {
if let Some(&gv) = ccx.const_globals.borrow().get(&cv) {
unsafe {
// Upgrade the alignment in cases where the same constant is used with different
// alignment requirements
@@ -100,27 +100,27 @@ pub fn addr_of(ccx: &CrateContext,
unsafe {
llvm::LLVMSetGlobalConstant(gv, True);
}
ccx.const_globals().borrow_mut().insert(cv, gv);
ccx.const_globals.borrow_mut().insert(cv, gv);
gv
}
pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
let instance = Instance::mono(ccx.tcx(), def_id);
if let Some(&g) = ccx.instances().borrow().get(&instance) {
let instance = Instance::mono(ccx.tcx, def_id);
if let Some(&g) = ccx.instances.borrow().get(&instance) {
return g;
}
let ty = instance.ty(ccx.tcx());
let g = if let Some(id) = ccx.tcx().hir.as_local_node_id(def_id) {
let ty = instance.ty(ccx.tcx);
let g = if let Some(id) = ccx.tcx.hir.as_local_node_id(def_id) {
let llty = ccx.layout_of(ty).llvm_type(ccx);
let (g, attrs) = match ccx.tcx().hir.get(id) {
let (g, attrs) = match ccx.tcx.hir.get(id) {
hir_map::NodeItem(&hir::Item {
ref attrs, span, node: hir::ItemStatic(..), ..
}) => {
let sym = MonoItem::Static(id).symbol_name(ccx.tcx());
let sym = MonoItem::Static(id).symbol_name(ccx.tcx);
let defined_in_current_codegen_unit = ccx.codegen_unit()
let defined_in_current_codegen_unit = ccx.codegen_unit
.items()
.contains_key(&MonoItem::Static(id));
assert!(!defined_in_current_codegen_unit);
@@ -131,7 +131,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
let g = declare::define_global(ccx, &sym[..], llty).unwrap();
if !ccx.tcx().is_exported_symbol(def_id) {
if !ccx.tcx.is_exported_symbol(def_id) {
unsafe {
llvm::LLVMRustSetVisibility(g, llvm::Visibility::Hidden);
}
@@ -143,7 +143,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
hir_map::NodeForeignItem(&hir::ForeignItem {
ref attrs, span, node: hir::ForeignItemStatic(..), ..
}) => {
let sym = ccx.tcx().symbol_name(instance);
let sym = ccx.tcx.symbol_name(instance);
let g = if let Some(name) =
attr::first_attr_value_str_by_name(&attrs, "linkage") {
// If this is a static with a linkage specified, then we need to handle
@@ -197,13 +197,13 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
for attr in attrs {
if attr.check_name("thread_local") {
llvm::set_thread_local_mode(g, ccx.tls_model());
llvm::set_thread_local_mode(g, ccx.tls_model);
}
}
g
} else {
let sym = ccx.tcx().symbol_name(instance);
let sym = ccx.tcx.symbol_name(instance);
// FIXME(nagisa): perhaps the map of externs could be offloaded to llvm somehow?
// FIXME(nagisa): investigate whether it can be changed into define_global
@@ -214,12 +214,12 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
// don't do this then linker errors can be generated where the linker
// complains that one object files has a thread local version of the
// symbol and another one doesn't.
for attr in ccx.tcx().get_attrs(def_id).iter() {
for attr in ccx.tcx.get_attrs(def_id).iter() {
if attr.check_name("thread_local") {
llvm::set_thread_local_mode(g, ccx.tls_model());
llvm::set_thread_local_mode(g, ccx.tls_model);
}
}
if ccx.use_dll_storage_attrs() && !ccx.tcx().is_foreign_item(def_id) {
if ccx.use_dll_storage_attrs && !ccx.tcx.is_foreign_item(def_id) {
// This item is external but not foreign, i.e. it originates from an external Rust
// crate. Since we don't know whether this crate will be linked dynamically or
// statically in the final application, we always mark such symbols as 'dllimport'.
@@ -232,15 +232,15 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
g
};
if ccx.use_dll_storage_attrs() && ccx.tcx().is_dllimport_foreign_item(def_id) {
if ccx.use_dll_storage_attrs && ccx.tcx.is_dllimport_foreign_item(def_id) {
// For foreign (native) libs we know the exact storage type to use.
unsafe {
llvm::LLVMSetDLLStorageClass(g, llvm::DLLStorageClass::DllImport);
}
}
ccx.instances().borrow_mut().insert(instance, g);
ccx.statics().borrow_mut().insert(g, def_id);
ccx.instances.borrow_mut().insert(instance, g);
ccx.statics.borrow_mut().insert(g, def_id);
g
}
@@ -250,7 +250,7 @@ pub fn trans_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
attrs: &[ast::Attribute])
-> Result<ValueRef, ConstEvalErr<'tcx>> {
unsafe {
let def_id = ccx.tcx().hir.local_def_id(id);
let def_id = ccx.tcx.hir.local_def_id(id);
let g = get_static(ccx, def_id);
let v = ::mir::trans_static_initializer(ccx, def_id)?;
@@ -265,8 +265,8 @@ pub fn trans_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
v
};
let instance = Instance::mono(ccx.tcx(), def_id);
let ty = instance.ty(ccx.tcx());
let instance = Instance::mono(ccx.tcx, def_id);
let ty = instance.ty(ccx.tcx);
let llty = ccx.layout_of(ty).llvm_type(ccx);
let g = if val_llty == llty {
g
@@ -282,7 +282,7 @@ pub fn trans_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
let visibility = llvm::LLVMRustGetVisibility(g);
let new_g = llvm::LLVMRustGetOrInsertGlobal(
ccx.llmod(), name_string.as_ptr(), val_llty.to_ref());
ccx.llmod, name_string.as_ptr(), val_llty.to_ref());
llvm::LLVMRustSetLinkage(new_g, linkage);
llvm::LLVMRustSetVisibility(new_g, visibility);
@@ -290,7 +290,7 @@ pub fn trans_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
// To avoid breaking any invariants, we leave around the old
// global for the moment; we'll replace all references to it
// with the new global later. (See base::trans_crate.)
ccx.statics_to_rauw().borrow_mut().push((g, new_g));
ccx.statics_to_rauw.borrow_mut().push((g, new_g));
new_g
};
set_global_alignment(ccx, g, ccx.align_of(ty));
@@ -307,7 +307,7 @@ pub fn trans_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
debuginfo::create_global_var_metadata(ccx, id, g);
if attr::contains_name(attrs, "thread_local") {
llvm::set_thread_local_mode(g, ccx.tls_model());
llvm::set_thread_local_mode(g, ccx.tls_model);
}
base::set_link_section(ccx, g, attrs);
@@ -315,7 +315,7 @@ pub fn trans_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
if attr::contains_name(attrs, "used") {
// This static will be stored in the llvm.used variable which is an array of i8*
let cast = llvm::LLVMConstPointerCast(g, Type::i8p(ccx).to_ref());
ccx.used_statics().borrow_mut().push(cast);
ccx.used_statics.borrow_mut().push(cast);
}
Ok(g)
+28 -123
View File
@@ -46,23 +46,23 @@
/// `ContextRef` so that several compilation units may be optimized in parallel.
/// All other LLVM data structures in the `CrateContext` are tied to that `ContextRef`.
pub struct CrateContext<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
check_overflow: bool,
use_dll_storage_attrs: bool,
tls_model: llvm::ThreadLocalMode,
pub tcx: TyCtxt<'a, 'tcx, 'tcx>,
pub check_overflow: bool,
pub use_dll_storage_attrs: bool,
pub tls_model: llvm::ThreadLocalMode,
llmod: ModuleRef,
llcx: ContextRef,
stats: RefCell<Stats>,
codegen_unit: Arc<CodegenUnit<'tcx>>,
pub llmod: ModuleRef,
pub llcx: ContextRef,
pub stats: RefCell<Stats>,
pub codegen_unit: Arc<CodegenUnit<'tcx>>,
/// Cache instances of monomorphic and polymorphic items
instances: RefCell<FxHashMap<Instance<'tcx>, ValueRef>>,
pub instances: RefCell<FxHashMap<Instance<'tcx>, ValueRef>>,
/// Cache generated vtables
vtables: RefCell<FxHashMap<(Ty<'tcx>,
pub vtables: RefCell<FxHashMap<(Ty<'tcx>,
Option<ty::PolyExistentialTraitRef<'tcx>>), ValueRef>>,
/// Cache of constant strings,
const_cstr_cache: RefCell<FxHashMap<InternedString, ValueRef>>,
pub const_cstr_cache: RefCell<FxHashMap<InternedString, ValueRef>>,
/// Reverse-direction for const ptrs cast from globals.
/// Key is a ValueRef holding a *T,
@@ -72,34 +72,34 @@ pub struct CrateContext<'a, 'tcx: 'a> {
/// when we ptrcast, and we have to ptrcast during translation
/// of a [T] const because we form a slice, a (*T,usize) pair, not
/// a pointer to an LLVM array type. Similar for trait objects.
const_unsized: RefCell<FxHashMap<ValueRef, ValueRef>>,
pub const_unsized: RefCell<FxHashMap<ValueRef, ValueRef>>,
/// Cache of emitted const globals (value -> global)
const_globals: RefCell<FxHashMap<ValueRef, ValueRef>>,
pub const_globals: RefCell<FxHashMap<ValueRef, ValueRef>>,
/// Mapping from static definitions to their DefId's.
statics: RefCell<FxHashMap<ValueRef, DefId>>,
pub statics: RefCell<FxHashMap<ValueRef, DefId>>,
/// List of globals for static variables which need to be passed to the
/// LLVM function ReplaceAllUsesWith (RAUW) when translation is complete.
/// (We have to make sure we don't invalidate any ValueRefs referring
/// to constants.)
statics_to_rauw: RefCell<Vec<(ValueRef, ValueRef)>>,
pub statics_to_rauw: RefCell<Vec<(ValueRef, ValueRef)>>,
/// Statics that will be placed in the llvm.used variable
/// See http://llvm.org/docs/LangRef.html#the-llvm-used-global-variable for details
used_statics: RefCell<Vec<ValueRef>>,
pub used_statics: RefCell<Vec<ValueRef>>,
lltypes: RefCell<FxHashMap<(Ty<'tcx>, Option<usize>), Type>>,
scalar_lltypes: RefCell<FxHashMap<Ty<'tcx>, Type>>,
pointee_infos: RefCell<FxHashMap<(Ty<'tcx>, Size), Option<PointeeInfo>>>,
isize_ty: Type,
pub lltypes: RefCell<FxHashMap<(Ty<'tcx>, Option<usize>), Type>>,
pub scalar_lltypes: RefCell<FxHashMap<Ty<'tcx>, Type>>,
pub pointee_infos: RefCell<FxHashMap<(Ty<'tcx>, Size), Option<PointeeInfo>>>,
pub isize_ty: Type,
dbg_cx: Option<debuginfo::CrateDebugContext<'tcx>>,
pub dbg_cx: Option<debuginfo::CrateDebugContext<'tcx>>,
eh_personality: Cell<Option<ValueRef>>,
eh_unwind_resume: Cell<Option<ValueRef>>,
rust_try_fn: Cell<Option<ValueRef>>,
pub rust_try_fn: Cell<Option<ValueRef>>,
intrinsics: RefCell<FxHashMap<&'static str, ValueRef>>,
@@ -319,16 +319,12 @@ pub fn into_stats(self) -> Stats {
}
impl<'b, 'tcx> CrateContext<'b, 'tcx> {
pub fn tcx(&self) -> TyCtxt<'b, 'tcx, 'tcx> {
self.tcx
}
pub fn sess<'a>(&'a self) -> &'a Session {
&self.tcx.sess
}
pub fn get_intrinsic(&self, key: &str) -> ValueRef {
if let Some(v) = self.intrinsics().borrow().get(key).cloned() {
if let Some(v) = self.intrinsics.borrow().get(key).cloned() {
return v;
}
match declare_intrinsic(self, key) {
@@ -337,97 +333,6 @@ pub fn get_intrinsic(&self, key: &str) -> ValueRef {
}
}
pub fn llmod(&self) -> ModuleRef {
self.llmod
}
pub fn llcx(&self) -> ContextRef {
self.llcx
}
pub fn codegen_unit(&self) -> &CodegenUnit<'tcx> {
&self.codegen_unit
}
pub fn instances<'a>(&'a self) -> &'a RefCell<FxHashMap<Instance<'tcx>, ValueRef>> {
&self.instances
}
pub fn vtables<'a>(&'a self)
-> &'a RefCell<FxHashMap<(Ty<'tcx>,
Option<ty::PolyExistentialTraitRef<'tcx>>), ValueRef>> {
&self.vtables
}
pub fn const_cstr_cache<'a>(&'a self) -> &'a RefCell<FxHashMap<InternedString, ValueRef>> {
&self.const_cstr_cache
}
pub fn const_unsized<'a>(&'a self) -> &'a RefCell<FxHashMap<ValueRef, ValueRef>> {
&self.const_unsized
}
pub fn const_globals<'a>(&'a self) -> &'a RefCell<FxHashMap<ValueRef, ValueRef>> {
&self.const_globals
}
pub fn statics<'a>(&'a self) -> &'a RefCell<FxHashMap<ValueRef, DefId>> {
&self.statics
}
pub fn statics_to_rauw<'a>(&'a self) -> &'a RefCell<Vec<(ValueRef, ValueRef)>> {
&self.statics_to_rauw
}
pub fn used_statics<'a>(&'a self) -> &'a RefCell<Vec<ValueRef>> {
&self.used_statics
}
pub fn lltypes<'a>(&'a self) -> &'a RefCell<FxHashMap<(Ty<'tcx>, Option<usize>), Type>> {
&self.lltypes
}
pub fn scalar_lltypes<'a>(&'a self) -> &'a RefCell<FxHashMap<Ty<'tcx>, Type>> {
&self.scalar_lltypes
}
pub fn pointee_infos<'a>(&'a self)
-> &'a RefCell<FxHashMap<(Ty<'tcx>, Size), Option<PointeeInfo>>> {
&self.pointee_infos
}
pub fn stats<'a>(&'a self) -> &'a RefCell<Stats> {
&self.stats
}
pub fn isize_ty(&self) -> Type {
self.isize_ty
}
pub fn dbg_cx<'a>(&'a self) -> &'a Option<debuginfo::CrateDebugContext<'tcx>> {
&self.dbg_cx
}
pub fn rust_try_fn<'a>(&'a self) -> &'a Cell<Option<ValueRef>> {
&self.rust_try_fn
}
fn intrinsics<'a>(&'a self) -> &'a RefCell<FxHashMap<&'static str, ValueRef>> {
&self.intrinsics
}
pub fn check_overflow(&self) -> bool {
self.check_overflow
}
pub fn use_dll_storage_attrs(&self) -> bool {
self.use_dll_storage_attrs
}
pub fn tls_model(&self) -> llvm::ThreadLocalMode {
self.tls_model
}
/// Generate a new symbol name with the given prefix. This symbol name must
/// only be used for definitions with `internal` or `private` linkage.
pub fn generate_local_symbol_name(&self, prefix: &str) -> String {
@@ -466,7 +371,7 @@ pub fn eh_personality(&self) -> ValueRef {
if let Some(llpersonality) = self.eh_personality.get() {
return llpersonality
}
let tcx = self.tcx();
let tcx = self.tcx;
let llfn = match tcx.lang_items().eh_personality() {
Some(def_id) if !base::wants_msvc_seh(self.sess()) => {
callee::resolve_and_get_fn(self, def_id, tcx.intern_substs(&[]))
@@ -494,7 +399,7 @@ pub fn eh_unwind_resume(&self) -> ValueRef {
return llfn;
}
let tcx = self.tcx();
let tcx = self.tcx;
assert!(self.sess().target.target.options.custom_unwind_resume);
if let Some(def_id) = tcx.lang_items().eh_unwind_resume() {
let llfn = callee::resolve_and_get_fn(self, def_id, tcx.intern_substs(&[]));
@@ -575,7 +480,7 @@ macro_rules! ifn {
if key == $name {
let f = declare::declare_cfn(ccx, $name, Type::func(&[], &$ret));
llvm::SetUnnamedAddr(f, false);
ccx.intrinsics().borrow_mut().insert($name, f.clone());
ccx.intrinsics.borrow_mut().insert($name, f.clone());
return Some(f);
}
);
@@ -583,7 +488,7 @@ macro_rules! ifn {
if key == $name {
let f = declare::declare_cfn(ccx, $name, Type::variadic_func(&[], &$ret));
llvm::SetUnnamedAddr(f, false);
ccx.intrinsics().borrow_mut().insert($name, f.clone());
ccx.intrinsics.borrow_mut().insert($name, f.clone());
return Some(f);
}
);
@@ -591,7 +496,7 @@ macro_rules! ifn {
if key == $name {
let f = declare::declare_cfn(ccx, $name, Type::func(&[$($arg),*], &$ret));
llvm::SetUnnamedAddr(f, false);
ccx.intrinsics().borrow_mut().insert($name, f.clone());
ccx.intrinsics.borrow_mut().insert($name, f.clone());
return Some(f);
}
);
+2 -2
View File
@@ -46,7 +46,7 @@ pub fn get_or_insert_gdb_debug_scripts_section_global(ccx: &CrateContext)
let section_var_name = &c_section_var_name[..c_section_var_name.len()-1];
let section_var = unsafe {
llvm::LLVMGetNamedGlobal(ccx.llmod(),
llvm::LLVMGetNamedGlobal(ccx.llmod,
c_section_var_name.as_ptr() as *const _)
};
@@ -79,7 +79,7 @@ pub fn get_or_insert_gdb_debug_scripts_section_global(ccx: &CrateContext)
pub fn needs_gdb_debug_scripts_section(ccx: &CrateContext) -> bool {
let omit_gdb_pretty_printer_section =
attr::contains_name(&ccx.tcx().hir.krate_attrs(),
attr::contains_name(&ccx.tcx.hir.krate_attrs(),
"omit_gdb_pretty_printer_section");
!omit_gdb_pretty_printer_section &&
+22 -22
View File
@@ -143,7 +143,7 @@ fn get_unique_type_id_of_type<'a>(&mut self, cx: &CrateContext<'a, 'tcx>,
// The hasher we are using to generate the UniqueTypeId. We want
// something that provides more than the 64 bits of the DefaultHasher.
let mut type_id_hasher = TypeIdHasher::<Fingerprint>::new(cx.tcx());
let mut type_id_hasher = TypeIdHasher::<Fingerprint>::new(cx.tcx);
type_id_hasher.visit_ty(type_);
let unique_type_id = type_id_hasher.finish().to_hex();
@@ -304,7 +304,7 @@ fn vec_slice_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
unique_type_id: UniqueTypeId,
span: Span)
-> MetadataCreationResult {
let data_ptr_type = cx.tcx().mk_imm_ptr(element_type);
let data_ptr_type = cx.tcx.mk_imm_ptr(element_type);
let data_ptr_metadata = type_metadata(cx, data_ptr_type, span);
@@ -313,7 +313,7 @@ fn vec_slice_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let slice_type_name = compute_debuginfo_type_name(cx, slice_ptr_type, true);
let (pointer_size, pointer_align) = cx.size_and_align_of(data_ptr_type);
let (usize_size, usize_align) = cx.size_and_align_of(cx.tcx().types.usize);
let (usize_size, usize_align) = cx.size_and_align_of(cx.tcx.types.usize);
let member_descriptions = [
MemberDescription {
@@ -326,7 +326,7 @@ fn vec_slice_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
},
MemberDescription {
name: "length".to_string(),
type_metadata: type_metadata(cx, cx.tcx().types.usize, span),
type_metadata: type_metadata(cx, cx.tcx.types.usize, span),
offset: pointer_size,
size: usize_size,
align: usize_align,
@@ -353,7 +353,7 @@ fn subroutine_type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
span: Span)
-> MetadataCreationResult
{
let signature = cx.tcx().erase_late_bound_regions_and_normalize(&signature);
let signature = cx.tcx.erase_late_bound_regions_and_normalize(&signature);
let mut signature_metadata: Vec<DIType> = Vec::with_capacity(signature.inputs().len() + 1);
@@ -415,7 +415,7 @@ fn trait_pointer_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let file_metadata = unknown_file_metadata(cx);
let layout = cx.layout_of(cx.tcx().mk_mut_ptr(trait_type));
let layout = cx.layout_of(cx.tcx.mk_mut_ptr(trait_type));
assert_eq!(abi::FAT_PTR_ADDR, 0);
assert_eq!(abi::FAT_PTR_EXTRA, 1);
@@ -426,7 +426,7 @@ fn trait_pointer_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
MemberDescription {
name: "pointer".to_string(),
type_metadata: type_metadata(cx,
cx.tcx().mk_mut_ptr(cx.tcx().types.u8),
cx.tcx.mk_mut_ptr(cx.tcx.types.u8),
syntax_pos::DUMMY_SP),
offset: layout.fields.offset(0),
size: data_ptr_field.size,
@@ -498,7 +498,7 @@ pub fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
Ok(vec_slice_metadata(cx, t, typ, unique_type_id, usage_site_span))
}
ty::TyStr => {
Ok(vec_slice_metadata(cx, t, cx.tcx().types.u8, unique_type_id, usage_site_span))
Ok(vec_slice_metadata(cx, t, cx.tcx.types.u8, unique_type_id, usage_site_span))
}
ty::TyDynamic(..) => {
Ok(MetadataCreationResult::new(
@@ -538,7 +538,7 @@ pub fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
fixed_vec_metadata(cx, unique_type_id, t, typ, usage_site_span)
}
ty::TyStr => {
fixed_vec_metadata(cx, unique_type_id, t, cx.tcx().types.i8, usage_site_span)
fixed_vec_metadata(cx, unique_type_id, t, cx.tcx.types.i8, usage_site_span)
}
ty::TyDynamic(..) => {
MetadataCreationResult::new(
@@ -566,7 +566,7 @@ pub fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
ty::TyFnDef(..) | ty::TyFnPtr(_) => {
let fn_metadata = subroutine_type_metadata(cx,
unique_type_id,
t.fn_sig(cx.tcx()),
t.fn_sig(cx.tcx),
usage_site_span).metadata;
match debug_context(cx).type_map
.borrow()
@@ -580,7 +580,7 @@ pub fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
}
ty::TyClosure(def_id, substs) => {
let upvar_tys : Vec<_> = substs.upvar_tys(def_id, cx.tcx()).collect();
let upvar_tys : Vec<_> = substs.upvar_tys(def_id, cx.tcx).collect();
prepare_tuple_metadata(cx,
t,
&upvar_tys,
@@ -588,8 +588,8 @@ pub fn type_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
usage_site_span).finalize(cx)
}
ty::TyGenerator(def_id, substs, _) => {
let upvar_tys : Vec<_> = substs.field_tys(def_id, cx.tcx()).map(|t| {
cx.tcx().fully_normalize_associated_types_in(&t)
let upvar_tys : Vec<_> = substs.field_tys(def_id, cx.tcx).map(|t| {
cx.tcx.fully_normalize_associated_types_in(&t)
}).collect();
prepare_tuple_metadata(cx,
t,
@@ -1368,7 +1368,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let file_metadata = unknown_file_metadata(cx);
let def = enum_type.ty_adt_def().unwrap();
let enumerators_metadata: Vec<DIDescriptor> = def.discriminants(cx.tcx())
let enumerators_metadata: Vec<DIDescriptor> = def.discriminants(cx.tcx)
.zip(&def.variants)
.map(|(discr, v)| {
let token = v.name.as_str();
@@ -1394,7 +1394,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let (discriminant_size, discriminant_align) =
(discr.size(cx), discr.align(cx));
let discriminant_base_type_metadata =
type_metadata(cx, discr.to_ty(cx.tcx()), syntax_pos::DUMMY_SP);
type_metadata(cx, discr.to_ty(cx.tcx), syntax_pos::DUMMY_SP);
let discriminant_name = get_enum_discriminant_name(cx, enum_def_id);
let name = CString::new(discriminant_name.as_bytes()).unwrap();
@@ -1473,7 +1473,7 @@ fn prepare_enum_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
fn get_enum_discriminant_name(cx: &CrateContext,
def_id: DefId)
-> InternedString {
cx.tcx().item_name(def_id)
cx.tcx.item_name(def_id)
}
}
@@ -1636,17 +1636,17 @@ fn create_union_stub<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
pub fn create_global_var_metadata(cx: &CrateContext,
node_id: ast::NodeId,
global: ValueRef) {
if cx.dbg_cx().is_none() {
if cx.dbg_cx.is_none() {
return;
}
let tcx = cx.tcx();
let tcx = cx.tcx;
let node_def_id = tcx.hir.local_def_id(node_id);
let no_mangle = attr::contains_name(&tcx.get_attrs(node_def_id), "no_mangle");
// We may want to remove the namespace scope if we're in an extern block, see:
// https://github.com/rust-lang/rust/pull/46457#issuecomment-351750952
let var_scope = get_namespace_for_item(cx, node_def_id);
let span = cx.tcx().def_span(node_def_id);
let span = cx.tcx.def_span(node_def_id);
let (file_metadata, line_number) = if span != syntax_pos::DUMMY_SP {
let loc = span_start(cx, span);
@@ -1656,7 +1656,7 @@ pub fn create_global_var_metadata(cx: &CrateContext,
};
let is_local_to_unit = is_node_local_to_unit(cx, node_id);
let variable_type = Instance::mono(cx.tcx(), node_def_id).ty(cx.tcx());
let variable_type = Instance::mono(cx.tcx, node_def_id).ty(cx.tcx);
let type_metadata = type_metadata(cx, variable_type, span);
let var_name = tcx.item_name(node_def_id).to_string();
let var_name = CString::new(var_name).unwrap();
@@ -1710,7 +1710,7 @@ pub fn extend_scope_to_file(ccx: &CrateContext,
pub fn create_vtable_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
ty: ty::Ty<'tcx>,
vtable: ValueRef) {
if cx.dbg_cx().is_none() {
if cx.dbg_cx.is_none() {
return;
}
@@ -1734,7 +1734,7 @@ pub fn create_vtable_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
unknown_file_metadata(cx),
UNKNOWN_LINE_NUMBER,
Size::from_bytes(0).bits(),
cx.tcx().data_layout.pointer_align.abi_bits() as u32,
cx.tcx.data_layout.pointer_align.abi_bits() as u32,
DIFlags::FlagArtificial,
ptr::null_mut(),
empty_array,
+19 -19
View File
@@ -151,7 +151,7 @@ pub enum VariableKind {
/// Create any deferred debug metadata nodes
pub fn finalize(cx: &CrateContext) {
if cx.dbg_cx().is_none() {
if cx.dbg_cx.is_none() {
return;
}
@@ -176,21 +176,21 @@ pub fn finalize(cx: &CrateContext) {
// Android has the same issue (#22398)
if cx.sess().target.target.options.is_like_osx ||
cx.sess().target.target.options.is_like_android {
llvm::LLVMRustAddModuleFlag(cx.llmod(),
llvm::LLVMRustAddModuleFlag(cx.llmod,
"Dwarf Version\0".as_ptr() as *const _,
2)
}
// Indicate that we want CodeView debug information on MSVC
if cx.sess().target.target.options.is_like_msvc {
llvm::LLVMRustAddModuleFlag(cx.llmod(),
llvm::LLVMRustAddModuleFlag(cx.llmod,
"CodeView\0".as_ptr() as *const _,
1)
}
// Prevent bitcode readers from deleting the debug info.
let ptr = "Debug Info Version\0".as_ptr();
llvm::LLVMRustAddModuleFlag(cx.llmod(), ptr as *const _,
llvm::LLVMRustAddModuleFlag(cx.llmod, ptr as *const _,
llvm::LLVMRustDebugMetadataVersion());
};
}
@@ -210,7 +210,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
return FunctionDebugContext::DebugInfoDisabled;
}
for attr in instance.def.attrs(cx.tcx()).iter() {
for attr in instance.def.attrs(cx.tcx).iter() {
if attr.check_name("no_debug") {
return FunctionDebugContext::FunctionWithoutDebugInfo;
}
@@ -235,15 +235,15 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
};
// Find the enclosing function, in case this is a closure.
let def_key = cx.tcx().def_key(def_id);
let def_key = cx.tcx.def_key(def_id);
let mut name = def_key.disambiguated_data.data.to_string();
let enclosing_fn_def_id = cx.tcx().closure_base_def_id(def_id);
let enclosing_fn_def_id = cx.tcx.closure_base_def_id(def_id);
// Get_template_parameters() will append a `<...>` clause to the function
// name if necessary.
let generics = cx.tcx().generics_of(enclosing_fn_def_id);
let substs = instance.substs.truncate_to(cx.tcx(), generics);
let generics = cx.tcx.generics_of(enclosing_fn_def_id);
let substs = instance.substs.truncate_to(cx.tcx, generics);
let template_parameters = get_template_parameters(cx,
&generics,
substs,
@@ -255,7 +255,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let scope_line = span_start(cx, span).line;
let local_id = cx.tcx().hir.as_local_node_id(instance.def_id());
let local_id = cx.tcx.hir.as_local_node_id(instance.def_id());
let is_local_to_unit = local_id.map_or(false, |id| is_node_local_to_unit(cx, id));
let function_name = CString::new(name).unwrap();
@@ -334,8 +334,8 @@ fn get_function_signature<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
signature.extend(inputs.iter().map(|&t| {
let t = match t.sty {
ty::TyArray(ct, _)
if (ct == cx.tcx().types.u8) || cx.layout_of(ct).is_zst() => {
cx.tcx().mk_imm_ptr(ct)
if (ct == cx.tcx.types.u8) || cx.layout_of(ct).is_zst() => {
cx.tcx.mk_imm_ptr(ct)
}
_ => t
};
@@ -375,7 +375,7 @@ fn get_template_parameters<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
name_to_append_suffix_to.push_str(",");
}
let actual_type = cx.tcx().fully_normalize_associated_types_in(&actual_type);
let actual_type = cx.tcx.fully_normalize_associated_types_in(&actual_type);
// Add actual type name to <...> clause of function name
let actual_type_name = compute_debuginfo_type_name(cx,
actual_type,
@@ -388,7 +388,7 @@ fn get_template_parameters<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let template_params: Vec<_> = if cx.sess().opts.debuginfo == FullDebugInfo {
let names = get_type_parameter_names(cx, generics);
substs.types().zip(names).map(|(ty, name)| {
let actual_type = cx.tcx().fully_normalize_associated_types_in(&ty);
let actual_type = cx.tcx.fully_normalize_associated_types_in(&ty);
let actual_type_metadata = type_metadata(cx, actual_type, syntax_pos::DUMMY_SP);
let name = CString::new(name.as_str().as_bytes()).unwrap();
unsafe {
@@ -411,7 +411,7 @@ fn get_template_parameters<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
fn get_type_parameter_names(cx: &CrateContext, generics: &ty::Generics) -> Vec<ast::Name> {
let mut names = generics.parent.map_or(vec![], |def_id| {
get_type_parameter_names(cx, cx.tcx().generics_of(def_id))
get_type_parameter_names(cx, cx.tcx.generics_of(def_id))
});
names.extend(generics.types.iter().map(|param| param.name));
names
@@ -423,10 +423,10 @@ fn get_containing_scope<'ccx, 'tcx>(cx: &CrateContext<'ccx, 'tcx>,
// First, let's see if this is a method within an inherent impl. Because
// if yes, we want to make the result subroutine DIE a child of the
// subroutine's self-type.
let self_type = cx.tcx().impl_of_method(instance.def_id()).and_then(|impl_def_id| {
let self_type = cx.tcx.impl_of_method(instance.def_id()).and_then(|impl_def_id| {
// If the method does *not* belong to a trait, proceed
if cx.tcx().trait_id_of_impl(impl_def_id).is_none() {
let impl_self_ty = cx.tcx().trans_impl_self_ty(impl_def_id, instance.substs);
if cx.tcx.trait_id_of_impl(impl_def_id).is_none() {
let impl_self_ty = cx.tcx.trans_impl_self_ty(impl_def_id, instance.substs);
// Only "class" methods are generally understood by LLVM,
// so avoid methods on other types (e.g. `<*mut T>::null`).
@@ -446,7 +446,7 @@ fn get_containing_scope<'ccx, 'tcx>(cx: &CrateContext<'ccx, 'tcx>,
self_type.unwrap_or_else(|| {
namespace::item_namespace(cx, DefId {
krate: instance.def_id().krate,
index: cx.tcx()
index: cx.tcx
.def_key(instance.def_id())
.parent
.expect("get_containing_scope: missing parent?")
+4 -4
View File
@@ -29,7 +29,7 @@ pub fn mangled_name_of_instance<'a, 'tcx>(
ccx: &CrateContext<'a, 'tcx>,
instance: Instance<'tcx>,
) -> ty::SymbolName {
let tcx = ccx.tcx();
let tcx = ccx.tcx;
tcx.symbol_name(instance)
}
@@ -37,7 +37,7 @@ pub fn mangled_name_of_item<'a, 'tcx>(
ccx: &CrateContext<'a, 'tcx>,
node_id: ast::NodeId,
) -> ty::SymbolName {
let tcx = ccx.tcx();
let tcx = ccx.tcx;
let node_def_id = tcx.hir.local_def_id(node_id);
let instance = Instance::mono(tcx, node_def_id);
tcx.symbol_name(instance)
@@ -48,7 +48,7 @@ pub fn item_namespace(ccx: &CrateContext, def_id: DefId) -> DIScope {
return scope;
}
let def_key = ccx.tcx().def_key(def_id);
let def_key = ccx.tcx.def_key(def_id);
let parent_scope = def_key.parent.map_or(ptr::null_mut(), |parent| {
item_namespace(ccx, DefId {
krate: def_id.krate,
@@ -57,7 +57,7 @@ pub fn item_namespace(ccx: &CrateContext, def_id: DefId) -> DIScope {
});
let namespace_name = match def_key.disambiguated_data.data {
DefPathData::CrateRoot => ccx.tcx().crate_name(def_id.krate).as_str(),
DefPathData::CrateRoot => ccx.tcx.crate_name(def_id.krate).as_str(),
data => data.as_interned_str()
};
+6 -6
View File
@@ -117,14 +117,14 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
},
ty::TyDynamic(ref trait_data, ..) => {
if let Some(principal) = trait_data.principal() {
let principal = cx.tcx().erase_late_bound_regions_and_normalize(
let principal = cx.tcx.erase_late_bound_regions_and_normalize(
&principal);
push_item_name(cx, principal.def_id, false, output);
push_type_params(cx, principal.substs, output);
}
},
ty::TyFnDef(..) | ty::TyFnPtr(_) => {
let sig = t.fn_sig(cx.tcx());
let sig = t.fn_sig(cx.tcx);
if sig.unsafety() == hir::Unsafety::Unsafe {
output.push_str("unsafe ");
}
@@ -138,7 +138,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
output.push_str("fn(");
let sig = cx.tcx().erase_late_bound_regions_and_normalize(&sig);
let sig = cx.tcx.erase_late_bound_regions_and_normalize(&sig);
if !sig.inputs().is_empty() {
for &parameter_type in sig.inputs() {
push_debuginfo_type_name(cx, parameter_type, true, output);
@@ -184,13 +184,13 @@ fn push_item_name(cx: &CrateContext,
qualified: bool,
output: &mut String) {
if qualified {
output.push_str(&cx.tcx().crate_name(def_id.krate).as_str());
for path_element in cx.tcx().def_path(def_id).data {
output.push_str(&cx.tcx.crate_name(def_id.krate).as_str());
for path_element in cx.tcx.def_path(def_id).data {
output.push_str("::");
output.push_str(&path_element.data.as_interned_str());
}
} else {
output.push_str(&cx.tcx().item_name(def_id));
output.push_str(&cx.tcx.item_name(def_id));
}
}
+5 -5
View File
@@ -33,8 +33,8 @@ pub fn is_node_local_to_unit(cx: &CrateContext, node_id: ast::NodeId) -> bool
// visible). It might better to use the `exported_items` set from
// `driver::CrateAnalysis` in the future, but (atm) this set is not
// available in the translation pass.
let def_id = cx.tcx().hir.local_def_id(node_id);
!cx.tcx().is_exported_symbol(def_id)
let def_id = cx.tcx.hir.local_def_id(node_id);
!cx.tcx.is_exported_symbol(def_id)
}
#[allow(non_snake_case)]
@@ -52,16 +52,16 @@ pub fn span_start(cx: &CrateContext, span: Span) -> syntax_pos::Loc {
#[inline]
pub fn debug_context<'a, 'tcx>(cx: &'a CrateContext<'a, 'tcx>)
-> &'a CrateDebugContext<'tcx> {
cx.dbg_cx().as_ref().unwrap()
cx.dbg_cx.as_ref().unwrap()
}
#[inline]
#[allow(non_snake_case)]
pub fn DIB(cx: &CrateContext) -> DIBuilderRef {
cx.dbg_cx().as_ref().unwrap().builder
cx.dbg_cx.as_ref().unwrap().builder
}
pub fn get_namespace_for_item(cx: &CrateContext, def_id: DefId) -> DIScope {
item_namespace(cx, cx.tcx().parent(def_id)
item_namespace(cx, cx.tcx.parent(def_id)
.expect("get_namespace_for_item: missing parent?"))
}
+9 -9
View File
@@ -45,7 +45,7 @@ pub fn declare_global(ccx: &CrateContext, name: &str, ty: Type) -> llvm::ValueRe
bug!("name {:?} contains an interior null byte", name)
});
unsafe {
llvm::LLVMRustGetOrInsertGlobal(ccx.llmod(), namebuf.as_ptr(), ty.to_ref())
llvm::LLVMRustGetOrInsertGlobal(ccx.llmod, namebuf.as_ptr(), ty.to_ref())
}
}
@@ -60,7 +60,7 @@ fn declare_raw_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv, ty:
bug!("name {:?} contains an interior null byte", name)
});
let llfn = unsafe {
llvm::LLVMRustGetOrInsertFunction(ccx.llmod(), namebuf.as_ptr(), ty.to_ref())
llvm::LLVMRustGetOrInsertFunction(ccx.llmod, namebuf.as_ptr(), ty.to_ref())
};
llvm::SetFunctionCallConv(llfn, callconv);
@@ -68,12 +68,12 @@ fn declare_raw_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv, ty:
// be merged.
llvm::SetUnnamedAddr(llfn, true);
if ccx.tcx().sess.opts.cg.no_redzone
.unwrap_or(ccx.tcx().sess.target.target.options.disable_redzone) {
if ccx.tcx.sess.opts.cg.no_redzone
.unwrap_or(ccx.tcx.sess.target.target.options.disable_redzone) {
llvm::Attribute::NoRedZone.apply_llfn(Function, llfn);
}
if let Some(ref sanitizer) = ccx.tcx().sess.opts.debugging_opts.sanitizer {
if let Some(ref sanitizer) = ccx.tcx.sess.opts.debugging_opts.sanitizer {
match *sanitizer {
Sanitizer::Address => {
llvm::Attribute::SanitizeAddress.apply_llfn(Function, llfn);
@@ -88,7 +88,7 @@ fn declare_raw_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv, ty:
}
}
match ccx.tcx().sess.opts.cg.opt_level.as_ref().map(String::as_ref) {
match ccx.tcx.sess.opts.cg.opt_level.as_ref().map(String::as_ref) {
Some("s") => {
llvm::Attribute::OptimizeForSize.apply_llfn(Function, llfn);
},
@@ -99,7 +99,7 @@ fn declare_raw_fn(ccx: &CrateContext, name: &str, callconv: llvm::CallConv, ty:
_ => {},
}
if ccx.tcx().sess.panic_strategy() != PanicStrategy::Unwind {
if ccx.tcx.sess.panic_strategy() != PanicStrategy::Unwind {
attributes::unwind(llfn, false);
}
@@ -127,7 +127,7 @@ pub fn declare_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, name: &str,
fn_type: Ty<'tcx>) -> ValueRef {
debug!("declare_rust_fn(name={:?}, fn_type={:?})", name, fn_type);
let sig = common::ty_fn_sig(ccx, fn_type);
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&sig);
let sig = ccx.tcx.erase_late_bound_regions_and_normalize(&sig);
debug!("declare_rust_fn (after region erasure) sig={:?}", sig);
let fty = FnType::new(ccx, sig, &[]);
@@ -197,7 +197,7 @@ pub fn get_declared_value(ccx: &CrateContext, name: &str) -> Option<ValueRef> {
let namebuf = CString::new(name).unwrap_or_else(|_|{
bug!("name {:?} contains an interior null byte", name)
});
let val = unsafe { llvm::LLVMRustGetNamedValue(ccx.llmod(), namebuf.as_ptr()) };
let val = unsafe { llvm::LLVMRustGetNamedValue(ccx.llmod, namebuf.as_ptr()) };
if val.is_null() {
debug!("get_declared_value: {:?} value is null", name);
None
+11 -11
View File
@@ -92,7 +92,7 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
llresult: ValueRef,
span: Span) {
let ccx = bcx.ccx;
let tcx = ccx.tcx();
let tcx = ccx.tcx;
let (def_id, substs) = match callee_ty.sty {
ty::TyFnDef(def_id, substs) => (def_id, substs),
@@ -176,7 +176,7 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
C_str_slice(ccx, ty_name)
}
"type_id" => {
C_u64(ccx, ccx.tcx().type_id_hash(substs.type_at(0)))
C_u64(ccx, ccx.tcx.type_id_hash(substs.type_at(0)))
}
"init" => {
let ty = substs.type_at(0);
@@ -399,11 +399,11 @@ pub fn trans_intrinsic_call<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
"align_offset" => {
// `ptr as usize`
let ptr_val = bcx.ptrtoint(args[0].immediate(), bcx.ccx.isize_ty());
let ptr_val = bcx.ptrtoint(args[0].immediate(), bcx.ccx.isize_ty);
// `ptr_val % align`
let align = args[1].immediate();
let offset = bcx.urem(ptr_val, align);
let zero = C_null(bcx.ccx.isize_ty());
let zero = C_null(bcx.ccx.isize_ty);
// `offset == 0`
let is_zero = bcx.icmp(llvm::IntPredicate::IntEQ, offset, zero);
// `if offset == 0 { 0 } else { align - offset }`
@@ -844,7 +844,7 @@ fn trans_msvc_try<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
let cs = catchswitch.catch_switch(None, None, 1);
catchswitch.add_handler(cs, catchpad.llbb());
let tcx = ccx.tcx();
let tcx = ccx.tcx;
let tydesc = match tcx.lang_items().msvc_try_filter() {
Some(did) => ::consts::get_static(ccx, did),
None => bug!("msvc_try_filter not defined"),
@@ -948,7 +948,7 @@ fn gen_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
output: Ty<'tcx>,
trans: &mut for<'b> FnMut(Builder<'b, 'tcx>))
-> ValueRef {
let rust_fn_ty = ccx.tcx().mk_fn_ptr(ty::Binder(ccx.tcx().mk_fn_sig(
let rust_fn_ty = ccx.tcx.mk_fn_ptr(ty::Binder(ccx.tcx.mk_fn_sig(
inputs.into_iter(),
output,
false,
@@ -968,12 +968,12 @@ fn gen_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
fn get_rust_try_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
trans: &mut for<'b> FnMut(Builder<'b, 'tcx>))
-> ValueRef {
if let Some(llfn) = ccx.rust_try_fn().get() {
if let Some(llfn) = ccx.rust_try_fn.get() {
return llfn;
}
// Define the type up front for the signature of the rust_try function.
let tcx = ccx.tcx();
let tcx = ccx.tcx;
let i8p = tcx.mk_mut_ptr(tcx.types.i8);
let fn_ty = tcx.mk_fn_ptr(ty::Binder(tcx.mk_fn_sig(
iter::once(i8p),
@@ -984,7 +984,7 @@ fn get_rust_try_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
)));
let output = tcx.types.i32;
let rust_try = gen_fn(ccx, "__rust_try", vec![fn_ty, i8p, i8p], output, trans);
ccx.rust_try_fn().set(Some(rust_try));
ccx.rust_try_fn.set(Some(rust_try));
return rust_try
}
@@ -1247,7 +1247,7 @@ fn int_type_width_signed(ty: Ty, ccx: &CrateContext) -> Option<(u64, bool)> {
match ty.sty {
ty::TyInt(t) => Some((match t {
ast::IntTy::Isize => {
match &ccx.tcx().sess.target.target.target_pointer_width[..] {
match &ccx.tcx.sess.target.target.target_pointer_width[..] {
"16" => 16,
"32" => 32,
"64" => 64,
@@ -1262,7 +1262,7 @@ fn int_type_width_signed(ty: Ty, ccx: &CrateContext) -> Option<(u64, bool)> {
}, true)),
ty::TyUint(t) => Some((match t {
ast::UintTy::Usize => {
match &ccx.tcx().sess.target.target.target_pointer_width[..] {
match &ccx.tcx.sess.target.target.target_pointer_width[..] {
"16" => 16,
"32" => 32,
"64" => 64,
+4 -4
View File
@@ -74,12 +74,12 @@ pub fn get_vtable<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
trait_ref: Option<ty::PolyExistentialTraitRef<'tcx>>)
-> ValueRef
{
let tcx = ccx.tcx();
let tcx = ccx.tcx;
debug!("get_vtable(ty={:?}, trait_ref={:?})", ty, trait_ref);
// Check the cache.
if let Some(&val) = ccx.vtables().borrow().get(&(ty, trait_ref)) {
if let Some(&val) = ccx.vtables.borrow().get(&(ty, trait_ref)) {
return val;
}
@@ -88,7 +88,7 @@ pub fn get_vtable<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
let (size, align) = ccx.size_and_align_of(ty);
let mut components: Vec<_> = [
callee::get_fn(ccx, monomorphize::resolve_drop_in_place(ccx.tcx(), ty)),
callee::get_fn(ccx, monomorphize::resolve_drop_in_place(ccx.tcx, ty)),
C_usize(ccx, size.bytes()),
C_usize(ccx, align.abi())
].iter().cloned().collect();
@@ -110,6 +110,6 @@ pub fn get_vtable<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
debuginfo::create_vtable_metadata(ccx, ty, vtable);
ccx.vtables().borrow_mut().insert((ty, trait_ref), vtable);
ccx.vtables.borrow_mut().insert((ty, trait_ref), vtable);
vtable
}
+6 -6
View File
@@ -117,7 +117,7 @@ fn visit_terminator_kind(&mut self,
}, ..
}),
ref args, ..
} if Some(def_id) == self.cx.ccx.tcx().lang_items().box_free_fn() => {
} if Some(def_id) == self.cx.ccx.tcx.lang_items().box_free_fn() => {
// box_free(x) shares with `drop x` the property that it
// is not guaranteed to be statically dominated by the
// definition of x, so x must always be in an alloca.
@@ -145,18 +145,18 @@ fn visit_place(&mut self,
_ => false
};
if is_consume {
let base_ty = proj.base.ty(self.cx.mir, ccx.tcx());
let base_ty = proj.base.ty(self.cx.mir, ccx.tcx);
let base_ty = self.cx.monomorphize(&base_ty);
// ZSTs don't require any actual memory access.
let elem_ty = base_ty.projection_ty(ccx.tcx(), &proj.elem).to_ty(ccx.tcx());
let elem_ty = base_ty.projection_ty(ccx.tcx, &proj.elem).to_ty(ccx.tcx);
let elem_ty = self.cx.monomorphize(&elem_ty);
if ccx.layout_of(elem_ty).is_zst() {
return;
}
if let mir::ProjectionElem::Field(..) = proj.elem {
let layout = ccx.layout_of(base_ty.to_ty(ccx.tcx()));
let layout = ccx.layout_of(base_ty.to_ty(ccx.tcx));
if layout.is_llvm_immediate() || layout.is_llvm_scalar_pair() {
// Recurse with the same context, instead of `Projection`,
// potentially stopping at non-operand projections,
@@ -200,8 +200,8 @@ fn visit_local(&mut self,
}
PlaceContext::Drop => {
let ty = mir::Place::Local(index).ty(self.cx.mir, self.cx.ccx.tcx());
let ty = self.cx.monomorphize(&ty.to_ty(self.cx.ccx.tcx()));
let ty = mir::Place::Local(index).ty(self.cx.mir, self.cx.ccx.tcx);
let ty = self.cx.monomorphize(&ty.to_ty(self.cx.ccx.tcx));
// Only need the place if we're actually dropping it.
if self.cx.ccx.type_needs_drop(ty) {
+8 -8
View File
@@ -267,7 +267,7 @@ fn trans_terminator(&mut self,
mir::TerminatorKind::Drop { ref location, target, unwind } => {
let ty = location.ty(self.mir, bcx.tcx()).to_ty(bcx.tcx());
let ty = self.monomorphize(&ty);
let drop_fn = monomorphize::resolve_drop_in_place(bcx.ccx.tcx(), ty);
let drop_fn = monomorphize::resolve_drop_in_place(bcx.ccx.tcx, ty);
if let ty::InstanceDef::DropGlue(_, None) = drop_fn.def {
// we don't actually need to drop anything.
@@ -280,7 +280,7 @@ fn trans_terminator(&mut self,
args = &args[..1 + place.has_extra() as usize];
let (drop_fn, fn_ty) = match ty.sty {
ty::TyDynamic(..) => {
let fn_ty = drop_fn.ty(bcx.ccx.tcx());
let fn_ty = drop_fn.ty(bcx.ccx.tcx);
let sig = common::ty_fn_sig(bcx.ccx, fn_ty);
let sig = bcx.tcx().erase_late_bound_regions_and_normalize(&sig);
let fn_ty = FnType::new_vtable(bcx.ccx, sig, &[]);
@@ -308,7 +308,7 @@ fn trans_terminator(&mut self,
// NOTE: Unlike binops, negation doesn't have its own
// checked operation, just a comparison with the minimum
// value, so we have to check for the assert message.
if !bcx.ccx.check_overflow() {
if !bcx.ccx.check_overflow {
use rustc_const_math::ConstMathErr::Overflow;
use rustc_const_math::Op::Neg;
@@ -440,7 +440,7 @@ fn trans_terminator(&mut self,
let (instance, mut llfn) = match callee.layout.ty.sty {
ty::TyFnDef(def_id, substs) => {
(Some(ty::Instance::resolve(bcx.ccx.tcx(),
(Some(ty::Instance::resolve(bcx.ccx.tcx,
ty::ParamEnv::empty(traits::Reveal::All),
def_id,
substs).unwrap()),
@@ -542,7 +542,7 @@ fn trans_terminator(&mut self,
}).collect();
let callee_ty = instance.as_ref().unwrap().ty(bcx.ccx.tcx());
let callee_ty = instance.as_ref().unwrap().ty(bcx.ccx.tcx);
trans_intrinsic_call(&bcx, callee_ty, &fn_ty, &args, dest,
terminator.source_info.span);
@@ -720,9 +720,9 @@ fn get_personality_slot(&mut self, bcx: &Builder<'a, 'tcx>) -> PlaceRef<'tcx> {
if let Some(slot) = self.personality_slot {
slot
} else {
let layout = ccx.layout_of(ccx.tcx().intern_tup(&[
ccx.tcx().mk_mut_ptr(ccx.tcx().types.u8),
ccx.tcx().types.i32
let layout = ccx.layout_of(ccx.tcx.intern_tup(&[
ccx.tcx.mk_mut_ptr(ccx.tcx.types.u8),
ccx.tcx.types.i32
], false));
let slot = PlaceRef::alloca(bcx, layout, "personalityslot");
self.personality_slot = Some(slot);
+15 -15
View File
@@ -63,7 +63,7 @@ pub fn new(llval: ValueRef, ty: Ty<'tcx>) -> Const<'tcx> {
}
pub fn from_constint(ccx: &CrateContext<'a, 'tcx>, ci: &ConstInt) -> Const<'tcx> {
let tcx = ccx.tcx();
let tcx = ccx.tcx;
let (llval, ty) = match *ci {
I8(v) => (C_int(Type::i8(ccx), v as i64), tcx.types.i8),
I16(v) => (C_int(Type::i16(ccx), v as i64), tcx.types.i16),
@@ -294,22 +294,22 @@ fn trans_def(ccx: &'a CrateContext<'a, 'tcx>,
substs: &'tcx Substs<'tcx>,
args: IndexVec<mir::Local, Result<Const<'tcx>, ConstEvalErr<'tcx>>>)
-> Result<Const<'tcx>, ConstEvalErr<'tcx>> {
let instance = ty::Instance::resolve(ccx.tcx(),
let instance = ty::Instance::resolve(ccx.tcx,
ty::ParamEnv::empty(traits::Reveal::All),
def_id,
substs).unwrap();
let mir = ccx.tcx().instance_mir(instance.def);
let mir = ccx.tcx.instance_mir(instance.def);
MirConstContext::new(ccx, &mir, instance.substs, args).trans()
}
fn monomorphize<T>(&self, value: &T) -> T
where T: TransNormalize<'tcx>
{
self.ccx.tcx().trans_apply_param_substs(self.substs, value)
self.ccx.tcx.trans_apply_param_substs(self.substs, value)
}
fn trans(&mut self) -> Result<Const<'tcx>, ConstEvalErr<'tcx>> {
let tcx = self.ccx.tcx();
let tcx = self.ccx.tcx;
let mut bb = mir::START_BLOCK;
// Make sure to evaluate all statemenets to
@@ -462,7 +462,7 @@ fn trans(&mut self) -> Result<Const<'tcx>, ConstEvalErr<'tcx>> {
}
fn is_binop_lang_item(&mut self, def_id: DefId) -> Option<(mir::BinOp, bool)> {
let tcx = self.ccx.tcx();
let tcx = self.ccx.tcx;
let items = tcx.lang_items();
let def_id = Some(def_id);
if items.i128_add_fn() == def_id { Some((mir::BinOp::Add, false)) }
@@ -505,7 +505,7 @@ fn store(&mut self,
fn const_place(&self, place: &mir::Place<'tcx>, span: Span)
-> Result<ConstPlace<'tcx>, ConstEvalErr<'tcx>> {
let tcx = self.ccx.tcx();
let tcx = self.ccx.tcx;
if let mir::Place::Local(index) = *place {
return self.locals[index].clone().unwrap_or_else(|| {
@@ -537,13 +537,13 @@ fn const_place(&self, place: &mir::Place<'tcx>, span: Span)
} else {
base.get_fat_ptr(self.ccx)
};
if self.ccx.statics().borrow().contains_key(&base) {
if self.ccx.statics.borrow().contains_key(&base) {
(Base::Static(base), extra)
} else if let ty::TyStr = projected_ty.sty {
(Base::Str(base), extra)
} else {
let v = base;
let v = self.ccx.const_unsized().borrow().get(&v).map_or(v, |&v| v);
let v = self.ccx.const_unsized.borrow().get(&v).map_or(v, |&v| v);
let mut val = unsafe { llvm::LLVMGetInitializer(v) };
if val.is_null() {
span_bug!(span, "dereference of non-constant pointer `{:?}`",
@@ -653,7 +653,7 @@ fn const_array(&self, array_ty: Ty<'tcx>, fields: &[ValueRef])
fn const_rvalue(&self, rvalue: &mir::Rvalue<'tcx>,
dest_ty: Ty<'tcx>, span: Span)
-> Result<Const<'tcx>, ConstEvalErr<'tcx>> {
let tcx = self.ccx.tcx();
let tcx = self.ccx.tcx;
debug!("const_rvalue({:?}: {:?} @ {:?})", rvalue, dest_ty, span);
let val = match *rvalue {
mir::Rvalue::Use(ref operand) => self.const_operand(operand, span)?,
@@ -763,7 +763,7 @@ fn const_rvalue(&self, rvalue: &mir::Rvalue<'tcx>,
unsized_ty, old_info);
if old_info.is_none() {
let prev_const = self.ccx.const_unsized().borrow_mut()
let prev_const = self.ccx.const_unsized.borrow_mut()
.insert(base, operand.llval);
assert!(prev_const.is_none() || prev_const == Some(operand.llval));
}
@@ -813,7 +813,7 @@ fn const_rvalue(&self, rvalue: &mir::Rvalue<'tcx>,
(CastTy::Int(_), CastTy::Ptr(_)) => {
let s = signed as llvm::Bool;
let usize_llval = llvm::LLVMConstIntCast(llval,
self.ccx.isize_ty().to_ref(), s);
self.ccx.isize_ty.to_ref(), s);
llvm::LLVMConstIntToPtr(usize_llval, ll_t_out.to_ref())
}
(CastTy::Ptr(_), CastTy::Int(_)) |
@@ -860,7 +860,7 @@ fn const_rvalue(&self, rvalue: &mir::Rvalue<'tcx>,
let align = if self.ccx.type_is_sized(ty) {
self.ccx.align_of(ty)
} else {
self.ccx.tcx().data_layout.pointer_align
self.ccx.tcx.data_layout.pointer_align
};
if bk == mir::BorrowKind::Mut {
consts::addr_of_mut(self.ccx, llval, align, "ref_mut")
@@ -1090,7 +1090,7 @@ unsafe fn cast_const_float_to_int(ccx: &CrateContext,
};
if cast_result.status.contains(Status::INVALID_OP) {
let err = ConstEvalErr { span: span, kind: ErrKind::CannotCast };
err.report(ccx.tcx(), span, "expression");
err.report(ccx.tcx, span, "expression");
}
C_uint_big(int_ty, cast_result.value)
}
@@ -1224,7 +1224,7 @@ fn trans_const_adt<'a, 'tcx>(
layout::Variants::Tagged { .. } => {
let discr = match *kind {
mir::AggregateKind::Adt(adt_def, _, _, _) => {
adt_def.discriminant_for_variant(ccx.tcx(), variant_index)
adt_def.discriminant_for_variant(ccx.tcx, variant_index)
.to_u128_unchecked() as u64
},
_ => 0,
+1 -1
View File
@@ -106,7 +106,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
pub fn monomorphize<T>(&self, value: &T) -> T
where T: TransNormalize<'tcx>
{
self.ccx.tcx().trans_apply_param_substs(self.param_substs, value)
self.ccx.tcx.trans_apply_param_substs(self.param_substs, value)
}
pub fn set_debug_loc(&mut self, bcx: &Builder, source_info: mir::SourceInfo) {
+2 -2
View File
@@ -407,7 +407,7 @@ pub fn trans_place(&mut self,
debug!("trans_place(place={:?})", place);
let ccx = bcx.ccx;
let tcx = ccx.tcx();
let tcx = ccx.tcx;
if let mir::Place::Local(index) = *place {
match self.locals[index] {
@@ -492,7 +492,7 @@ pub fn trans_place(&mut self,
}
pub fn monomorphized_place_ty(&self, place: &mir::Place<'tcx>) -> Ty<'tcx> {
let tcx = self.ccx.tcx();
let tcx = self.ccx.tcx;
let place_ty = place.ty(self.mir, tcx);
self.monomorphize(&place_ty.to_ty(tcx))
}
+7 -7
View File
@@ -207,7 +207,7 @@ pub fn trans_rvalue_operand(&mut self,
match operand.layout.ty.sty {
ty::TyClosure(def_id, substs) => {
let instance = monomorphize::resolve_closure(
bcx.ccx.tcx(), def_id, substs, ty::ClosureKind::FnOnce);
bcx.ccx.tcx, def_id, substs, ty::ClosureKind::FnOnce);
OperandValue::Immediate(callee::get_fn(bcx.ccx, instance))
}
_ => {
@@ -314,7 +314,7 @@ pub fn trans_rvalue_operand(&mut self,
(CastTy::FnPtr, CastTy::Int(_)) =>
bcx.ptrtoint(llval, ll_t_out),
(CastTy::Int(_), CastTy::Ptr(_)) => {
let usize_llval = bcx.intcast(llval, bcx.ccx.isize_ty(), signed);
let usize_llval = bcx.intcast(llval, bcx.ccx.isize_ty, signed);
bcx.inttoptr(usize_llval, ll_t_out)
}
(CastTy::Int(_), CastTy::Float) =>
@@ -348,8 +348,8 @@ pub fn trans_rvalue_operand(&mut self,
};
(bcx, OperandRef {
val,
layout: self.ccx.layout_of(self.ccx.tcx().mk_ref(
self.ccx.tcx().types.re_erased,
layout: self.ccx.layout_of(self.ccx.tcx.mk_ref(
self.ccx.tcx.types.re_erased,
ty::TypeAndMut { ty, mutbl: bk.to_mutbl_lossy() }
)),
})
@@ -477,7 +477,7 @@ pub fn trans_rvalue_operand(&mut self,
mir::Rvalue::Aggregate(..) => {
// According to `rvalue_creates_operand`, only ZST
// aggregate rvalues are allowed to be operands.
let ty = rvalue.ty(self.mir, self.ccx.tcx());
let ty = rvalue.ty(self.mir, self.ccx.tcx);
(bcx, OperandRef::new_zst(self.ccx,
self.ccx.layout_of(self.monomorphize(&ty))))
}
@@ -636,7 +636,7 @@ pub fn trans_scalar_checked_binop(&mut self,
// with #[rustc_inherit_overflow_checks] and inlined from
// another crate (mostly core::num generic/#[inline] fns),
// while the current crate doesn't use overflow checks.
if !bcx.ccx.check_overflow() {
if !bcx.ccx.check_overflow {
let val = self.trans_scalar_binop(bcx, op, lhs, rhs, input_ty);
return OperandValue::Pair(val, C_bool(bcx.ccx, false));
}
@@ -697,7 +697,7 @@ pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>) -> bool {
true,
mir::Rvalue::Repeat(..) |
mir::Rvalue::Aggregate(..) => {
let ty = rvalue.ty(self.mir, self.ccx.tcx());
let ty = rvalue.ty(self.mir, self.ccx.tcx);
let ty = self.monomorphize(&ty);
self.ccx.layout_of(ty).is_zst()
}
+23 -23
View File
@@ -40,13 +40,13 @@
pub trait MonoItemExt<'a, 'tcx>: fmt::Debug + BaseMonoItemExt<'a, 'tcx> {
fn define(&self, ccx: &CrateContext<'a, 'tcx>) {
debug!("BEGIN IMPLEMENTING '{} ({})' in cgu {}",
self.to_string(ccx.tcx()),
self.to_string(ccx.tcx),
self.to_raw_string(),
ccx.codegen_unit().name());
ccx.codegen_unit.name());
match *self.as_mono_item() {
MonoItem::Static(node_id) => {
let tcx = ccx.tcx();
let tcx = ccx.tcx;
let item = tcx.hir.expect_item(node_id);
if let hir::ItemStatic(_, m, _) = item.node {
match consts::trans_static(&ccx, m, item.id, &item.attrs) {
@@ -60,7 +60,7 @@ fn define(&self, ccx: &CrateContext<'a, 'tcx>) {
}
}
MonoItem::GlobalAsm(node_id) => {
let item = ccx.tcx().hir.expect_item(node_id);
let item = ccx.tcx.hir.expect_item(node_id);
if let hir::ItemGlobalAsm(ref ga) = item.node {
asm::trans_global_asm(ccx, ga);
} else {
@@ -73,9 +73,9 @@ fn define(&self, ccx: &CrateContext<'a, 'tcx>) {
}
debug!("END IMPLEMENTING '{} ({})' in cgu {}",
self.to_string(ccx.tcx()),
self.to_string(ccx.tcx),
self.to_raw_string(),
ccx.codegen_unit().name());
ccx.codegen_unit.name());
}
fn predefine(&self,
@@ -83,11 +83,11 @@ fn predefine(&self,
linkage: Linkage,
visibility: Visibility) {
debug!("BEGIN PREDEFINING '{} ({})' in cgu {}",
self.to_string(ccx.tcx()),
self.to_string(ccx.tcx),
self.to_raw_string(),
ccx.codegen_unit().name());
ccx.codegen_unit.name());
let symbol_name = self.symbol_name(ccx.tcx());
let symbol_name = self.symbol_name(ccx.tcx);
debug!("symbol {}", &symbol_name);
@@ -102,9 +102,9 @@ fn predefine(&self,
}
debug!("END PREDEFINING '{} ({})' in cgu {}",
self.to_string(ccx.tcx()),
self.to_string(ccx.tcx),
self.to_raw_string(),
ccx.codegen_unit().name());
ccx.codegen_unit.name());
}
fn local_span(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> Option<Span> {
@@ -143,13 +143,13 @@ fn predefine_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
linkage: Linkage,
visibility: Visibility,
symbol_name: &str) {
let def_id = ccx.tcx().hir.local_def_id(node_id);
let instance = Instance::mono(ccx.tcx(), def_id);
let ty = instance.ty(ccx.tcx());
let def_id = ccx.tcx.hir.local_def_id(node_id);
let instance = Instance::mono(ccx.tcx, def_id);
let ty = instance.ty(ccx.tcx);
let llty = ccx.layout_of(ty).llvm_type(ccx);
let g = declare::define_global(ccx, symbol_name, llty).unwrap_or_else(|| {
ccx.sess().span_fatal(ccx.tcx().hir.span(node_id),
ccx.sess().span_fatal(ccx.tcx.hir.span(node_id),
&format!("symbol `{}` is already defined", symbol_name))
});
@@ -158,8 +158,8 @@ fn predefine_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
llvm::LLVMRustSetVisibility(g, base::visibility_to_llvm(visibility));
}
ccx.instances().borrow_mut().insert(instance, g);
ccx.statics().borrow_mut().insert(g, def_id);
ccx.instances.borrow_mut().insert(instance, g);
ccx.statics.borrow_mut().insert(g, def_id);
}
fn predefine_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
@@ -170,14 +170,14 @@ fn predefine_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
assert!(!instance.substs.needs_infer() &&
!instance.substs.has_param_types());
let mono_ty = instance.ty(ccx.tcx());
let attrs = instance.def.attrs(ccx.tcx());
let mono_ty = instance.ty(ccx.tcx);
let attrs = instance.def.attrs(ccx.tcx);
let lldecl = declare::declare_fn(ccx, symbol_name, mono_ty);
unsafe { llvm::LLVMRustSetLinkage(lldecl, base::linkage_to_llvm(linkage)) };
base::set_link_section(ccx, lldecl, &attrs);
if linkage == Linkage::LinkOnceODR ||
linkage == Linkage::WeakODR {
llvm::SetUniqueComdat(ccx.llmod(), lldecl);
llvm::SetUniqueComdat(ccx.llmod, lldecl);
}
// If we're compiling the compiler-builtins crate, e.g. the equivalent of
@@ -185,7 +185,7 @@ fn predefine_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
// visibility as we're going to link this object all over the place but
// don't want the symbols to get exported.
if linkage != Linkage::Internal && linkage != Linkage::Private &&
attr::contains_name(ccx.tcx().hir.krate_attrs(), "compiler_builtins") {
attr::contains_name(ccx.tcx.hir.krate_attrs(), "compiler_builtins") {
unsafe {
llvm::LLVMRustSetVisibility(lldecl, llvm::Visibility::Hidden);
}
@@ -196,10 +196,10 @@ fn predefine_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
}
debug!("predefine_fn: mono_ty = {:?} instance = {:?}", mono_ty, instance);
if instance.def.is_inline(ccx.tcx()) {
if instance.def.is_inline(ccx.tcx) {
attributes::inline(lldecl, attributes::InlineAttr::Hint);
}
attributes::from_fn_attrs(ccx, lldecl, instance.def.def_id());
ccx.instances().borrow_mut().insert(instance, lldecl);
ccx.instances.borrow_mut().insert(instance, lldecl);
}
+18 -18
View File
@@ -63,19 +63,19 @@ pub fn to_ref_slice(slice: &[Type]) -> &[TypeRef] {
}
pub fn void(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMVoidTypeInContext(ccx.llcx()))
ty!(llvm::LLVMVoidTypeInContext(ccx.llcx))
}
pub fn metadata(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMRustMetadataTypeInContext(ccx.llcx()))
ty!(llvm::LLVMRustMetadataTypeInContext(ccx.llcx))
}
pub fn i1(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMInt1TypeInContext(ccx.llcx()))
ty!(llvm::LLVMInt1TypeInContext(ccx.llcx))
}
pub fn i8(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMInt8TypeInContext(ccx.llcx()))
ty!(llvm::LLVMInt8TypeInContext(ccx.llcx))
}
pub fn i8_llcx(llcx: ContextRef) -> Type {
@@ -83,32 +83,32 @@ pub fn i8_llcx(llcx: ContextRef) -> Type {
}
pub fn i16(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMInt16TypeInContext(ccx.llcx()))
ty!(llvm::LLVMInt16TypeInContext(ccx.llcx))
}
pub fn i32(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMInt32TypeInContext(ccx.llcx()))
ty!(llvm::LLVMInt32TypeInContext(ccx.llcx))
}
pub fn i64(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMInt64TypeInContext(ccx.llcx()))
ty!(llvm::LLVMInt64TypeInContext(ccx.llcx))
}
pub fn i128(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMIntTypeInContext(ccx.llcx(), 128))
ty!(llvm::LLVMIntTypeInContext(ccx.llcx, 128))
}
// Creates an integer type with the given number of bits, e.g. i24
pub fn ix(ccx: &CrateContext, num_bits: u64) -> Type {
ty!(llvm::LLVMIntTypeInContext(ccx.llcx(), num_bits as c_uint))
ty!(llvm::LLVMIntTypeInContext(ccx.llcx, num_bits as c_uint))
}
pub fn f32(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMFloatTypeInContext(ccx.llcx()))
ty!(llvm::LLVMFloatTypeInContext(ccx.llcx))
}
pub fn f64(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMDoubleTypeInContext(ccx.llcx()))
ty!(llvm::LLVMDoubleTypeInContext(ccx.llcx))
}
pub fn bool(ccx: &CrateContext) -> Type {
@@ -128,7 +128,7 @@ pub fn i8p_llcx(llcx: ContextRef) -> Type {
}
pub fn isize(ccx: &CrateContext) -> Type {
match &ccx.tcx().sess.target.target.target_pointer_width[..] {
match &ccx.tcx.sess.target.target.target_pointer_width[..] {
"16" => Type::i16(ccx),
"32" => Type::i32(ccx),
"64" => Type::i64(ccx),
@@ -137,7 +137,7 @@ pub fn isize(ccx: &CrateContext) -> Type {
}
pub fn c_int(ccx: &CrateContext) -> Type {
match &ccx.tcx().sess.target.target.target_c_int_width[..] {
match &ccx.tcx.sess.target.target.target_c_int_width[..] {
"16" => Type::i16(ccx),
"32" => Type::i32(ccx),
"64" => Type::i64(ccx),
@@ -147,7 +147,7 @@ pub fn c_int(ccx: &CrateContext) -> Type {
pub fn int_from_ty(ccx: &CrateContext, t: ast::IntTy) -> Type {
match t {
ast::IntTy::Isize => ccx.isize_ty(),
ast::IntTy::Isize => ccx.isize_ty,
ast::IntTy::I8 => Type::i8(ccx),
ast::IntTy::I16 => Type::i16(ccx),
ast::IntTy::I32 => Type::i32(ccx),
@@ -158,7 +158,7 @@ pub fn int_from_ty(ccx: &CrateContext, t: ast::IntTy) -> Type {
pub fn uint_from_ty(ccx: &CrateContext, t: ast::UintTy) -> Type {
match t {
ast::UintTy::Usize => ccx.isize_ty(),
ast::UintTy::Usize => ccx.isize_ty,
ast::UintTy::U8 => Type::i8(ccx),
ast::UintTy::U16 => Type::i16(ccx),
ast::UintTy::U32 => Type::i32(ccx),
@@ -188,14 +188,14 @@ pub fn variadic_func(args: &[Type], ret: &Type) -> Type {
pub fn struct_(ccx: &CrateContext, els: &[Type], packed: bool) -> Type {
let els: &[TypeRef] = Type::to_ref_slice(els);
ty!(llvm::LLVMStructTypeInContext(ccx.llcx(), els.as_ptr(),
ty!(llvm::LLVMStructTypeInContext(ccx.llcx, els.as_ptr(),
els.len() as c_uint,
packed as Bool))
}
pub fn named_struct(ccx: &CrateContext, name: &str) -> Type {
let name = CString::new(name).unwrap();
ty!(llvm::LLVMStructCreateNamed(ccx.llcx(), name.as_ptr()))
ty!(llvm::LLVMStructCreateNamed(ccx.llcx, name.as_ptr()))
}
@@ -295,6 +295,6 @@ pub fn padding_filler(ccx: &CrateContext, size: Size, align: Align) -> Type {
}
pub fn x86_mmx(ccx: &CrateContext) -> Type {
ty!(llvm::LLVMX86MMXTypeInContext(ccx.llcx()))
ty!(llvm::LLVMX86MMXTypeInContext(ccx.llcx))
}
}
+12 -12
View File
@@ -61,7 +61,7 @@ fn uncached_llvm_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
ty::TyForeign(..) |
ty::TyStr => {
let mut name = String::with_capacity(32);
let printer = DefPathBasedNames::new(ccx.tcx(), true, true);
let printer = DefPathBasedNames::new(ccx.tcx, true, true);
printer.push_type_name(layout.ty, &mut name);
match (&layout.ty.sty, &layout.variants) {
(&ty::TyAdt(def, _), &layout::Variants::Single { index }) => {
@@ -244,7 +244,7 @@ fn llvm_type<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> Type {
if let layout::Abi::Scalar(ref scalar) = self.abi {
// Use a different cache for scalars because pointers to DSTs
// can be either fat or thin (data pointers of fat pointers).
if let Some(&llty) = ccx.scalar_lltypes().borrow().get(&self.ty) {
if let Some(&llty) = ccx.scalar_lltypes.borrow().get(&self.ty) {
return llty;
}
let llty = match self.ty.sty {
@@ -256,12 +256,12 @@ fn llvm_type<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> Type {
ccx.layout_of(self.ty.boxed_ty()).llvm_type(ccx).ptr_to()
}
ty::TyFnPtr(sig) => {
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&sig);
let sig = ccx.tcx.erase_late_bound_regions_and_normalize(&sig);
FnType::new(ccx, sig, &[]).llvm_type(ccx).ptr_to()
}
_ => self.scalar_llvm_type_at(ccx, scalar, Size::from_bytes(0))
};
ccx.scalar_lltypes().borrow_mut().insert(self.ty, llty);
ccx.scalar_lltypes.borrow_mut().insert(self.ty, llty);
return llty;
}
@@ -271,7 +271,7 @@ fn llvm_type<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> Type {
layout::Variants::Single { index } => Some(index),
_ => None
};
if let Some(&llty) = ccx.lltypes().borrow().get(&(self.ty, variant_index)) {
if let Some(&llty) = ccx.lltypes.borrow().get(&(self.ty, variant_index)) {
return llty;
}
@@ -281,7 +281,7 @@ fn llvm_type<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> Type {
// Make sure lifetimes are erased, to avoid generating distinct LLVM
// types for Rust types that only differ in the choice of lifetimes.
let normal_ty = ccx.tcx().erase_regions(&self.ty);
let normal_ty = ccx.tcx.erase_regions(&self.ty);
let mut defer = None;
let llty = if self.ty != normal_ty {
@@ -295,7 +295,7 @@ fn llvm_type<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> Type {
};
debug!("--> mapped {:#?} to llty={:?}", self, llty);
ccx.lltypes().borrow_mut().insert((self.ty, variant_index), llty);
ccx.lltypes.borrow_mut().insert((self.ty, variant_index), llty);
if let Some((mut llty, layout)) = defer {
let (llfields, packed) = struct_llfields(ccx, layout);
@@ -342,7 +342,7 @@ fn scalar_pair_element_llvm_type<'a>(&self, ccx: &CrateContext<'a, 'tcx>,
return self.field(ccx, index).llvm_type(ccx);
}
ty::TyAdt(def, _) if def.is_box() => {
let ptr_ty = ccx.tcx().mk_mut_ptr(self.ty.boxed_ty());
let ptr_ty = ccx.tcx.mk_mut_ptr(self.ty.boxed_ty());
return ccx.layout_of(ptr_ty).scalar_pair_element_llvm_type(ccx, index);
}
_ => {}
@@ -398,7 +398,7 @@ fn llvm_field_index(&self, index: usize) -> u64 {
fn pointee_info_at<'a>(&self, ccx: &CrateContext<'a, 'tcx>, offset: Size)
-> Option<PointeeInfo> {
if let Some(&pointee) = ccx.pointee_infos().borrow().get(&(self.ty, offset)) {
if let Some(&pointee) = ccx.pointee_infos.borrow().get(&(self.ty, offset)) {
return pointee;
}
@@ -423,8 +423,8 @@ fn pointee_info_at<'a>(&self, ccx: &CrateContext<'a, 'tcx>, offset: Size)
PointerKind::Shared
},
hir::MutMutable => {
if ccx.tcx().sess.opts.debugging_opts.mutable_noalias ||
ccx.tcx().sess.panic_strategy() == PanicStrategy::Abort {
if ccx.tcx.sess.opts.debugging_opts.mutable_noalias ||
ccx.tcx.sess.panic_strategy() == PanicStrategy::Abort {
PointerKind::UniqueBorrowed
} else {
PointerKind::Shared
@@ -495,7 +495,7 @@ fn pointee_info_at<'a>(&self, ccx: &CrateContext<'a, 'tcx>, offset: Size)
}
}
ccx.pointee_infos().borrow_mut().insert((self.ty, offset), result);
ccx.pointee_infos.borrow_mut().insert((self.ty, offset), result);
result
}
}