-use arena::{TypedArena, DroplessArena};
+use arena::{DroplessArena, TypedArena};
+use smallvec::SmallVec;
+use std::cell::RefCell;
+use std::marker::PhantomData;
use std::mem;
use std::ptr;
use std::slice;
-use std::cell::RefCell;
-use std::marker::PhantomData;
-use smallvec::SmallVec;
/// This declares a list of types which can be allocated by `Arena`.
///
[] generics: rustc::ty::Generics,
[] trait_def: rustc::ty::TraitDef,
[] adt_def: rustc::ty::AdtDef,
- [] steal_mir: rustc::ty::steal::Steal<rustc::mir::BodyCache<$tcx>>,
- [] mir: rustc::mir::BodyCache<$tcx>,
+ [] steal_mir: rustc::ty::steal::Steal<rustc::mir::BodyAndCache<$tcx>>,
+ [] mir: rustc::mir::BodyAndCache<$tcx>,
[] steal_promoted: rustc::ty::steal::Steal<
rustc_index::vec::IndexVec<
rustc::mir::Promoted,
- rustc::mir::BodyCache<$tcx>
+ rustc::mir::BodyAndCache<$tcx>
>
>,
[] promoted: rustc_index::vec::IndexVec<
rustc::mir::Promoted,
- rustc::mir::BodyCache<$tcx>
+ rustc::mir::BodyAndCache<$tcx>
>,
[] tables: rustc::ty::TypeckTables<$tcx>,
[] const_allocs: rustc::mir::interpret::Allocation,
rustc::hir::def_id::CrateNum
>
>,
- [few] hir_forest: rustc::hir::map::Forest,
[few] diagnostic_items: rustc_data_structures::fx::FxHashMap<
syntax::symbol::Symbol,
rustc::hir::def_id::DefId,
[few] crate_variances: rustc::ty::CrateVariancesMap<'tcx>,
[few] inferred_outlives_crate: rustc::ty::CratePredicatesMap<'tcx>,
[] upvars: rustc_data_structures::fx::FxIndexMap<rustc::hir::HirId, rustc::hir::Upvar>,
+
+ // HIR types
+ [few] hir_forest: rustc::hir::map::Forest<$tcx>,
+ [] attribute: syntax::ast::Attribute,
+ [few] global_asm: rustc::hir::GlobalAsm,
+ [] fn_decl: rustc::hir::FnDecl,
+ [] foreign_item: rustc::hir::ForeignItem<$tcx>,
+ [] impl_item_ref: rustc::hir::ImplItemRef,
+ [few] macro_def: rustc::hir::MacroDef<$tcx>,
+ [] param: rustc::hir::Param,
+ [] path: rustc::hir::Path,
+ [] struct_field: rustc::hir::StructField<$tcx>,
+ [] trait_item_ref: rustc::hir::TraitItemRef,
+ [] ty: rustc::hir::Ty,
+ [] variant: rustc::hir::Variant<$tcx>,
], $tcx);
)
}
#[inline]
pub fn alloc_slice<T: Copy>(&self, value: &[T]) -> &mut [T] {
if value.len() == 0 {
- return &mut []
+ return &mut [];
}
self.dropless.alloc_slice(value)
}
- pub fn alloc_from_iter<
- T: ArenaAllocatable,
- I: IntoIterator<Item = T>
- >(
+ pub fn alloc_from_iter<T: ArenaAllocatable, I: IntoIterator<Item = T>>(
&'a self,
- iter: I
+ iter: I,
) -> &'a mut [T] {
if !mem::needs_drop::<T>() {
return self.dropless.alloc_from_iter(iter);
impl Drop for DropType {
fn drop(&mut self) {
- unsafe {
- (self.drop_fn)(self.obj)
- }
+ unsafe { (self.drop_fn)(self.obj) }
}
}
impl DropArena {
#[inline]
unsafe fn alloc<T>(&self, object: T) -> &mut T {
- let mem = self.arena.alloc_raw(
- mem::size_of::<T>(),
- mem::align_of::<T>()
- ) as *mut _ as *mut T;
+ let mem =
+ self.arena.alloc_raw(mem::size_of::<T>(), mem::align_of::<T>()) as *mut _ as *mut T;
// Write into uninitialized memory.
ptr::write(mem, object);
let result = &mut *mem;
// Record the destructor after doing the allocation as that may panic
// and would cause `object`'s destuctor to run twice if it was recorded before
- self.destructors.borrow_mut().push(DropType {
- drop_fn: drop_for_type::<T>,
- obj: result as *mut T as *mut u8,
- });
+ self.destructors
+ .borrow_mut()
+ .push(DropType { drop_fn: drop_for_type::<T>, obj: result as *mut T as *mut u8 });
result
}
}
let len = vec.len();
- let start_ptr = self.arena.alloc_raw(
- len.checked_mul(mem::size_of::<T>()).unwrap(),
- mem::align_of::<T>()
- ) as *mut _ as *mut T;
+ let start_ptr = self
+ .arena
+ .alloc_raw(len.checked_mul(mem::size_of::<T>()).unwrap(), mem::align_of::<T>())
+ as *mut _ as *mut T;
let mut destructors = self.destructors.borrow_mut();
// Reserve space for the destructors so we can't panic while adding them