1
Fork 0

librustc_trans: use #[deriving(Copy)]

This commit is contained in:
Jorge Aparicio 2014-12-14 23:14:38 -05:00
parent 463475b7fa
commit 5e2bca9e86
20 changed files with 43 additions and 109 deletions

View file

@ -33,7 +33,7 @@ use std::sync::{Arc, Mutex};
use std::thread;
use libc::{c_uint, c_int, c_void};
#[deriving(Clone, PartialEq, PartialOrd, Ord, Eq)]
#[deriving(Clone, Copy, PartialEq, PartialOrd, Ord, Eq)]
pub enum OutputType {
OutputTypeBitcode,
OutputTypeAssembly,
@ -42,8 +42,6 @@ pub enum OutputType {
OutputTypeExe,
}
impl Copy for OutputType {}
pub fn llvm_err(handler: &diagnostic::Handler, msg: String) -> ! {
unsafe {
let cstr = llvm::LLVMRustGetLastError();

View file

@ -61,6 +61,7 @@ macro_rules! svec {
})
}
#[deriving(Copy)]
pub enum Row {
Variable,
Enum,
@ -87,8 +88,6 @@ pub enum Row {
FnRef,
}
impl Copy for Row {}
impl<'a> FmtStrs<'a> {
pub fn new(rec: Box<Recorder>, span: SpanUtils<'a>, krate: String) -> FmtStrs<'a> {
FmtStrs {

View file

@ -228,11 +228,9 @@ use syntax::codemap::Span;
use syntax::fold::Folder;
use syntax::ptr::P;
#[deriving(Show)]
#[deriving(Copy, Show)]
struct ConstantExpr<'a>(&'a ast::Expr);
impl<'a> Copy for ConstantExpr<'a> {}
impl<'a> ConstantExpr<'a> {
fn eq(self, other: ConstantExpr<'a>, tcx: &ty::ctxt) -> bool {
let ConstantExpr(expr) = self;
@ -301,7 +299,7 @@ impl<'a, 'tcx> Opt<'a, 'tcx> {
}
}
#[deriving(PartialEq)]
#[deriving(Copy, PartialEq)]
pub enum BranchKind {
NoBranch,
Single,
@ -310,23 +308,19 @@ pub enum BranchKind {
CompareSliceLength
}
impl Copy for BranchKind {}
pub enum OptResult<'blk, 'tcx: 'blk> {
SingleResult(Result<'blk, 'tcx>),
RangeResult(Result<'blk, 'tcx>, Result<'blk, 'tcx>),
LowerBound(Result<'blk, 'tcx>)
}
#[deriving(Clone)]
#[deriving(Clone, Copy)]
pub enum TransBindingMode {
TrByCopy(/* llbinding */ ValueRef),
TrByMove,
TrByRef,
}
impl Copy for TransBindingMode {}
/// Information about a pattern binding:
/// - `llmatch` is a pointer to a stack slot. The stack slot contains a
/// pointer into the value being matched. Hence, llmatch has type `T**`
@ -334,7 +328,7 @@ impl Copy for TransBindingMode {}
/// - `trmode` is the trans binding mode
/// - `id` is the node id of the binding
/// - `ty` is the Rust type of the binding
#[deriving(Clone)]
#[deriving(Clone, Copy)]
pub struct BindingInfo<'tcx> {
pub llmatch: ValueRef,
pub trmode: TransBindingMode,
@ -343,8 +337,6 @@ pub struct BindingInfo<'tcx> {
pub ty: Ty<'tcx>,
}
impl<'tcx> Copy for BindingInfo<'tcx> {}
type BindingsMap<'tcx> = FnvHashMap<Ident, BindingInfo<'tcx>>;
struct ArmData<'p, 'blk, 'tcx: 'blk> {

View file

@ -281,14 +281,12 @@ struct Case<'tcx> {
}
#[deriving(Eq, PartialEq, Show)]
#[deriving(Copy, Eq, PartialEq, Show)]
pub enum PointerField {
ThinPointer(uint),
FatPointer(uint)
}
impl Copy for PointerField {}
impl<'tcx> Case<'tcx> {
fn is_zerolen<'a>(&self, cx: &CrateContext<'a, 'tcx>, scapegoat: Ty<'tcx>)
-> bool {

View file

@ -565,10 +565,9 @@ pub fn maybe_name_value(cx: &CrateContext, v: ValueRef, s: &str) {
// Used only for creating scalar comparison glue.
#[deriving(Copy)]
pub enum scalar_type { nil_type, signed_int, unsigned_int, floating_point, }
impl Copy for scalar_type {}
pub fn compare_scalar_types<'blk, 'tcx>(cx: Block<'blk, 'tcx>,
lhs: ValueRef,
rhs: ValueRef,
@ -1792,14 +1791,12 @@ pub fn build_return_block<'blk, 'tcx>(fcx: &FunctionContext<'blk, 'tcx>,
}
}
#[deriving(Clone, Eq, PartialEq)]
#[deriving(Clone, Copy, Eq, PartialEq)]
pub enum IsUnboxedClosureFlag {
NotUnboxedClosure,
IsUnboxedClosure,
}
impl Copy for IsUnboxedClosureFlag {}
// trans_closure: Builds an LLVM function out of a source function.
// If the function closes over its environment a closure will be
// returned.
@ -2194,6 +2191,7 @@ pub fn llvm_linkage_by_name(name: &str) -> Option<Linkage> {
/// Enum describing the origin of an LLVM `Value`, for linkage purposes.
#[deriving(Copy)]
pub enum ValueOrigin {
/// The LLVM `Value` is in this context because the corresponding item was
/// assigned to the current compilation unit.
@ -2204,8 +2202,6 @@ pub enum ValueOrigin {
InlinedCopy,
}
impl Copy for ValueOrigin {}
/// Set the appropriate linkage for an LLVM `ValueRef` (function or global).
/// If the `llval` is the direct translation of a specific Rust item, `id`
/// should be set to the `NodeId` of that item. (This mapping should be

View file

@ -13,10 +13,9 @@ use llvm::{BasicBlockRef};
use trans::value::{Users, Value};
use std::iter::{Filter, Map};
#[deriving(Copy)]
pub struct BasicBlock(pub BasicBlockRef);
impl Copy for BasicBlock {}
pub type Preds = Map<
Value,
BasicBlock,

View file

@ -20,7 +20,7 @@ use trans::cabi_arm;
use trans::cabi_mips;
use trans::type_::Type;
#[deriving(Clone, PartialEq)]
#[deriving(Clone, Copy, PartialEq)]
pub enum ArgKind {
/// Pass the argument directly using the normal converted
/// LLVM type or by coercing to another specified type
@ -31,13 +31,11 @@ pub enum ArgKind {
Ignore,
}
impl Copy for ArgKind {}
/// Information about how a specific C type
/// should be passed to or returned from a function
///
/// This is borrowed from clang's ABIInfo.h
#[deriving(Clone)]
#[deriving(Clone, Copy)]
pub struct ArgType {
pub kind: ArgKind,
/// Original LLVM type
@ -50,8 +48,6 @@ pub struct ArgType {
pub attr: option::Option<Attribute>
}
impl Copy for ArgType {}
impl ArgType {
pub fn direct(ty: Type, cast: option::Option<Type>,
pad: option::Option<Type>,

View file

@ -24,7 +24,7 @@ use trans::type_::Type;
use std::cmp;
#[deriving(Clone, PartialEq)]
#[deriving(Clone, Copy, PartialEq)]
enum RegClass {
NoClass,
Int,
@ -40,8 +40,6 @@ enum RegClass {
Memory
}
impl Copy for RegClass {}
trait TypeMethods {
fn is_reg_ty(&self) -> bool;
}

View file

@ -57,13 +57,12 @@ use syntax::ast;
use syntax::ast_map;
use syntax::ptr::P;
#[deriving(Copy)]
pub struct MethodData {
pub llfn: ValueRef,
pub llself: ValueRef,
}
impl Copy for MethodData {}
pub enum CalleeData<'tcx> {
Closure(Datum<'tcx, Lvalue>),
@ -1049,13 +1048,12 @@ pub fn trans_args<'a, 'blk, 'tcx>(cx: Block<'blk, 'tcx>,
bcx
}
#[deriving(Copy)]
pub enum AutorefArg {
DontAutorefArg,
DoAutorefArg(ast::NodeId)
}
impl Copy for AutorefArg {}
pub fn trans_arg_datum<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
formal_arg_ty: Ty<'tcx>,
arg_datum: Datum<'tcx, Expr>,

View file

@ -50,13 +50,11 @@ pub struct CleanupScope<'blk, 'tcx: 'blk> {
cached_landing_pad: Option<BasicBlockRef>,
}
#[deriving(Show)]
#[deriving(Copy, Show)]
pub struct CustomScopeIndex {
index: uint
}
impl Copy for CustomScopeIndex {}
pub const EXIT_BREAK: uint = 0;
pub const EXIT_LOOP: uint = 1;
pub const EXIT_MAX: uint = 2;
@ -83,22 +81,19 @@ impl<'blk, 'tcx: 'blk> fmt::Show for CleanupScopeKind<'blk, 'tcx> {
}
}
#[deriving(PartialEq, Show)]
#[deriving(Copy, PartialEq, Show)]
pub enum EarlyExitLabel {
UnwindExit,
ReturnExit,
LoopExit(ast::NodeId, uint)
}
impl Copy for EarlyExitLabel {}
#[deriving(Copy)]
pub struct CachedEarlyExit {
label: EarlyExitLabel,
cleanup_block: BasicBlockRef,
}
impl Copy for CachedEarlyExit {}
pub trait Cleanup<'tcx> {
fn must_unwind(&self) -> bool;
fn clean_on_unwind(&self) -> bool;
@ -111,14 +106,12 @@ pub trait Cleanup<'tcx> {
pub type CleanupObj<'tcx> = Box<Cleanup<'tcx>+'tcx>;
#[deriving(Show)]
#[deriving(Copy, Show)]
pub enum ScopeId {
AstScope(ast::NodeId),
CustomScope(CustomScopeIndex)
}
impl Copy for ScopeId {}
impl<'blk, 'tcx> CleanupMethods<'blk, 'tcx> for FunctionContext<'blk, 'tcx> {
/// Invoked when we start to trans the code contained within a new cleanup scope.
fn push_ast_cleanup_scope(&self, debug_loc: NodeInfo) {
@ -876,6 +869,7 @@ impl EarlyExitLabel {
///////////////////////////////////////////////////////////////////////////
// Cleanup types
#[deriving(Copy)]
pub struct DropValue<'tcx> {
is_immediate: bool,
must_unwind: bool,
@ -884,8 +878,6 @@ pub struct DropValue<'tcx> {
zero: bool
}
impl<'tcx> Copy for DropValue<'tcx> {}
impl<'tcx> Cleanup<'tcx> for DropValue<'tcx> {
fn must_unwind(&self) -> bool {
self.must_unwind
@ -915,21 +907,18 @@ impl<'tcx> Cleanup<'tcx> for DropValue<'tcx> {
}
}
#[deriving(Show)]
#[deriving(Copy, Show)]
pub enum Heap {
HeapExchange
}
impl Copy for Heap {}
#[deriving(Copy)]
pub struct FreeValue<'tcx> {
ptr: ValueRef,
heap: Heap,
content_ty: Ty<'tcx>
}
impl<'tcx> Copy for FreeValue<'tcx> {}
impl<'tcx> Cleanup<'tcx> for FreeValue<'tcx> {
fn must_unwind(&self) -> bool {
true
@ -957,6 +946,7 @@ impl<'tcx> Cleanup<'tcx> for FreeValue<'tcx> {
}
}
#[deriving(Copy)]
pub struct FreeSlice {
ptr: ValueRef,
size: ValueRef,
@ -964,8 +954,6 @@ pub struct FreeSlice {
heap: Heap,
}
impl Copy for FreeSlice {}
impl<'tcx> Cleanup<'tcx> for FreeSlice {
fn must_unwind(&self) -> bool {
true
@ -993,12 +981,11 @@ impl<'tcx> Cleanup<'tcx> for FreeSlice {
}
}
#[deriving(Copy)]
pub struct LifetimeEnd {
ptr: ValueRef,
}
impl Copy for LifetimeEnd {}
impl<'tcx> Cleanup<'tcx> for LifetimeEnd {
fn must_unwind(&self) -> bool {
false

View file

@ -102,13 +102,12 @@ use syntax::ast_util;
//
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#[deriving(Copy)]
pub struct EnvValue<'tcx> {
action: ast::CaptureClause,
datum: Datum<'tcx, Lvalue>
}
impl<'tcx> Copy for EnvValue<'tcx> {}
impl<'tcx> EnvValue<'tcx> {
pub fn to_string<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> String {
format!("{}({})", self.action, self.datum.to_string(ccx))

View file

@ -119,6 +119,7 @@ pub fn gensym_name(name: &str) -> PathElem {
PathName(token::gensym(format!("{}:{}", name, num).as_slice()))
}
#[deriving(Copy)]
pub struct tydesc_info<'tcx> {
pub ty: Ty<'tcx>,
pub tydesc: ValueRef,
@ -127,8 +128,6 @@ pub struct tydesc_info<'tcx> {
pub name: ValueRef,
}
impl<'tcx> Copy for tydesc_info<'tcx> {}
/*
* A note on nomenclature of linking: "extern", "foreign", and "upcall".
*
@ -155,13 +154,12 @@ impl<'tcx> Copy for tydesc_info<'tcx> {}
*
*/
#[deriving(Copy)]
pub struct NodeInfo {
pub id: ast::NodeId,
pub span: Span,
}
impl Copy for NodeInfo {}
pub fn expr_info(expr: &ast::Expr) -> NodeInfo {
NodeInfo { id: expr.id, span: expr.span }
}
@ -863,7 +861,7 @@ pub fn fulfill_obligation<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
}
// Key used to lookup values supplied for type parameters in an expr.
#[deriving(PartialEq, Show)]
#[deriving(Copy, PartialEq, Show)]
pub enum ExprOrMethodCall {
// Type parameters for a path like `None::<int>`
ExprId(ast::NodeId),
@ -872,8 +870,6 @@ pub enum ExprOrMethodCall {
MethodCall(ty::MethodCall)
}
impl Copy for ExprOrMethodCall {}
pub fn node_id_substs<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
node: ExprOrMethodCall)
-> subst::Substs<'tcx> {

View file

@ -33,7 +33,7 @@ use syntax::ast;
/// describes where the value is stored, what Rust type the value has,
/// whether it is addressed by reference, and so forth. Please refer
/// the section on datums in `doc.rs` for more details.
#[deriving(Clone)]
#[deriving(Clone, Copy)]
pub struct Datum<'tcx, K> {
/// The llvm value. This is either a pointer to the Rust value or
/// the value itself, depending on `kind` below.
@ -46,8 +46,6 @@ pub struct Datum<'tcx, K> {
pub kind: K,
}
impl<'tcx,K:Copy> Copy for Datum<'tcx,K> {}
pub struct DatumBlock<'blk, 'tcx: 'blk, K> {
pub bcx: Block<'blk, 'tcx>,
pub datum: Datum<'tcx, K>,
@ -65,11 +63,9 @@ pub enum Expr {
LvalueExpr,
}
#[deriving(Clone, Show)]
#[deriving(Clone, Copy, Show)]
pub struct Lvalue;
impl Copy for Lvalue {}
#[deriving(Show)]
pub struct Rvalue {
pub mode: RvalueMode
@ -86,7 +82,7 @@ impl Drop for Rvalue {
fn drop(&mut self) { }
}
#[deriving(PartialEq, Eq, Hash, Show)]
#[deriving(Copy, PartialEq, Eq, Hash, Show)]
pub enum RvalueMode {
/// `val` is a pointer to the actual value (and thus has type *T)
ByRef,
@ -95,8 +91,6 @@ pub enum RvalueMode {
ByValue,
}
impl Copy for RvalueMode {}
pub fn immediate_rvalue<'tcx>(val: ValueRef, ty: Ty<'tcx>) -> Datum<'tcx, Rvalue> {
return Datum::new(val, ty, Rvalue::new(ByValue));
}

View file

@ -248,11 +248,9 @@ static FLAGS_NONE: c_uint = 0;
// Public Interface of debuginfo module
//=-----------------------------------------------------------------------------
#[deriving(Show, Hash, Eq, PartialEq, Clone)]
#[deriving(Copy, Show, Hash, Eq, PartialEq, Clone)]
struct UniqueTypeId(ast::Name);
impl Copy for UniqueTypeId {}
// The TypeMap is where the CrateDebugContext holds the type metadata nodes
// created so far. The metadata nodes are indexed by UniqueTypeId, and, for
// faster lookup, also by Ty. The TypeMap is responsible for creating
@ -2320,14 +2318,13 @@ impl<'tcx> VariantMemberDescriptionFactory<'tcx> {
}
}
#[deriving(Copy)]
enum EnumDiscriminantInfo {
RegularDiscriminant(DIType),
OptimizedDiscriminant(adt::PointerField),
NoDiscriminant
}
impl Copy for EnumDiscriminantInfo {}
// Returns a tuple of (1) type_metadata_stub of the variant, (2) the llvm_type
// of the variant, and (3) a MemberDescriptionFactory for producing the
// descriptions of the fields of the variant. This is a rudimentary version of a
@ -3047,14 +3044,12 @@ impl MetadataCreationResult {
}
}
#[deriving(PartialEq)]
#[deriving(Copy, PartialEq)]
enum DebugLocation {
KnownLocation { scope: DIScope, line: uint, col: uint },
UnknownLocation
}
impl Copy for DebugLocation {}
impl DebugLocation {
fn new(scope: DIScope, line: uint, col: uint) -> DebugLocation {
KnownLocation {

View file

@ -73,14 +73,12 @@ use std::rc::Rc;
// These are passed around by the code generating functions to track the
// destination of a computation's value.
#[deriving(PartialEq)]
#[deriving(Copy, PartialEq)]
pub enum Dest {
SaveIn(ValueRef),
Ignore,
}
impl Copy for Dest {}
impl Dest {
pub fn to_string(&self, ccx: &CrateContext) -> String {
match *self {
@ -1889,7 +1887,7 @@ fn float_cast(bcx: Block,
} else { llsrc };
}
#[deriving(PartialEq, Show)]
#[deriving(Copy, PartialEq, Show)]
pub enum cast_kind {
cast_pointer,
cast_integral,
@ -1898,8 +1896,6 @@ pub enum cast_kind {
cast_other,
}
impl Copy for cast_kind {}
pub fn cast_type_kind<'tcx>(tcx: &ty::ctxt<'tcx>, t: Ty<'tcx>) -> cast_kind {
match t.sty {
ty::ty_char => cast_integral,

View file

@ -54,13 +54,12 @@ mod basic_block;
mod llrepr;
mod cleanup;
#[deriving(Copy)]
pub struct ModuleTranslation {
pub llcx: ContextRef,
pub llmod: ModuleRef,
}
impl Copy for ModuleTranslation {}
pub struct CrateTranslation {
pub modules: Vec<ModuleTranslation>,
pub metadata_module: ModuleTranslation,

View file

@ -89,6 +89,7 @@ pub fn make_drop_glue_unboxed<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
})
}
#[deriving(Copy)]
pub struct VecTypes<'tcx> {
pub unit_ty: Ty<'tcx>,
pub llunit_ty: Type,
@ -96,8 +97,6 @@ pub struct VecTypes<'tcx> {
pub llunit_alloc_size: u64
}
impl<'tcx> Copy for VecTypes<'tcx> {}
impl<'tcx> VecTypes<'tcx> {
pub fn to_string<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> String {
format!("VecTypes {{unit_ty={}, llunit_ty={}, \

View file

@ -25,14 +25,12 @@ use std::cell::RefCell;
use libc::c_uint;
#[deriving(Clone, PartialEq, Show)]
#[deriving(Clone, Copy, PartialEq, Show)]
#[repr(C)]
pub struct Type {
rf: TypeRef
}
impl Copy for Type {}
macro_rules! ty {
($e:expr) => ( Type::from_ref(unsafe { $e }))
}

View file

@ -443,14 +443,13 @@ pub fn align_of<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>, t: Ty<'tcx>)
}
// Want refinements! (Or case classes, I guess
#[deriving(Copy)]
pub enum named_ty {
a_struct,
an_enum,
an_unboxed_closure,
}
impl Copy for named_ty {}
pub fn llvm_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
what: named_ty,
did: ast::DefId,

View file

@ -14,10 +14,9 @@ use trans::basic_block::BasicBlock;
use trans::common::Block;
use libc::c_uint;
#[deriving(Copy)]
pub struct Value(pub ValueRef);
impl Copy for Value {}
macro_rules! opt_val { ($e:expr) => (
unsafe {
match $e {
@ -126,10 +125,9 @@ impl Value {
}
/// Wrapper for LLVM UseRef
#[deriving(Copy)]
pub struct Use(UseRef);
impl Copy for Use {}
impl Use {
pub fn get(&self) -> UseRef {
let Use(v) = *self; v