Skip to content

Cleanup bitflags #24964

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions src/librustc/middle/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ use std::collections::hash_map::Entry;
bitflags! {
#[derive(RustcEncodable, RustcDecodable)]
flags ConstQualif: u8 {
// Const rvalue which can be placed behind a reference.
const PURE_CONST = 0,
// Inner mutability (can not be placed behind a reference) or behind
// &mut in a non-global expression. Can be copied from static memory.
const MUTABLE_MEM = 1 << 0,
Expand Down Expand Up @@ -104,7 +102,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
{
let (old_mode, old_qualif) = (self.mode, self.qualif);
self.mode = mode;
self.qualif = ConstQualif::PURE_CONST;
self.qualif = ConstQualif::empty();
let r = f(self);
self.mode = old_mode;
self.qualif = old_qualif;
Expand All @@ -128,7 +126,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
Entry::Occupied(entry) => return *entry.get(),
Entry::Vacant(entry) => {
// Prevent infinite recursion on re-entry.
entry.insert(ConstQualif::PURE_CONST);
entry.insert(ConstQualif::empty());
}
}
self.with_mode(mode, |this| {
Expand Down Expand Up @@ -273,7 +271,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {

fn visit_expr(&mut self, ex: &ast::Expr) {
let mut outer = self.qualif;
self.qualif = ConstQualif::PURE_CONST;
self.qualif = ConstQualif::empty();

let node_ty = ty::node_id_to_type(self.tcx, ex.id);
check_expr(self, ex, node_ty);
Expand Down
7 changes: 4 additions & 3 deletions src/librustc/middle/mem_categorization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -850,9 +850,10 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
// Compute maximum lifetime of this rvalue. This is 'static if
// we can promote to a constant, otherwise equal to enclosing temp
// lifetime.
let re = match qualif & check_const::ConstQualif::NON_STATIC_BORROWS {
check_const::ConstQualif::PURE_CONST => ty::ReStatic,
_ => self.temporary_scope(id),
let re = if qualif.intersects(check_const::ConstQualif::NON_STATIC_BORROWS) {
self.temporary_scope(id)
} else {
ty::ReStatic
};
let ret = self.cat_rvalue(id, span, re, expr_ty);
debug!("cat_rvalue_node ret {}", ret.repr(self.tcx()));
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,6 @@ impl<'tcx> ctxt<'tcx> {
// recursing over the type itself.
bitflags! {
flags TypeFlags: u32 {
const NO_TYPE_FLAGS = 0,
const HAS_PARAMS = 1 << 0,
const HAS_SELF = 1 << 1,
const HAS_TY_INFER = 1 << 2,
Expand Down Expand Up @@ -2925,7 +2924,7 @@ struct FlagComputation {

impl FlagComputation {
fn new() -> FlagComputation {
FlagComputation { flags: TypeFlags::NO_TYPE_FLAGS, depth: 0 }
FlagComputation { flags: TypeFlags::empty(), depth: 0 }
}

fn for_sty(st: &sty) -> FlagComputation {
Expand Down
52 changes: 26 additions & 26 deletions src/librustc_llvm/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,32 +125,32 @@ pub enum DiagnosticSeverity {

bitflags! {
flags Attribute : u32 {
const ZExtAttribute = 1 << 0,
const SExtAttribute = 1 << 1,
const NoReturnAttribute = 1 << 2,
const InRegAttribute = 1 << 3,
const StructRetAttribute = 1 << 4,
const NoUnwindAttribute = 1 << 5,
const NoAliasAttribute = 1 << 6,
const ByValAttribute = 1 << 7,
const NestAttribute = 1 << 8,
const ReadNoneAttribute = 1 << 9,
const ReadOnlyAttribute = 1 << 10,
const NoInlineAttribute = 1 << 11,
const AlwaysInlineAttribute = 1 << 12,
const OptimizeForSizeAttribute = 1 << 13,
const StackProtectAttribute = 1 << 14,
const StackProtectReqAttribute = 1 << 15,
const AlignmentAttribute = 1 << 16,
const NoCaptureAttribute = 1 << 21,
const NoRedZoneAttribute = 1 << 22,
const NoImplicitFloatAttribute = 1 << 23,
const NakedAttribute = 1 << 24,
const InlineHintAttribute = 1 << 25,
const StackAttribute = 7 << 26,
const ReturnsTwiceAttribute = 1 << 29,
const UWTableAttribute = 1 << 30,
const NonLazyBindAttribute = 1 << 31,
const ZExt = 1 << 0,
const SExt = 1 << 1,
const NoReturn = 1 << 2,
const InReg = 1 << 3,
const StructRet = 1 << 4,
const NoUnwind = 1 << 5,
const NoAlias = 1 << 6,
const ByVal = 1 << 7,
const Nest = 1 << 8,
const ReadNone = 1 << 9,
const ReadOnly = 1 << 10,
const NoInline = 1 << 11,
const AlwaysInline = 1 << 12,
const OptimizeForSize = 1 << 13,
const StackProtect = 1 << 14,
const StackProtectReq = 1 << 15,
const Alignment = 1 << 16,
const NoCapture = 1 << 21,
const NoRedZone = 1 << 22,
const NoImplicitFloat = 1 << 23,
const Naked = 1 << 24,
const InlineHint = 1 << 25,
const Stack = 7 << 26,
const ReturnsTwice = 1 << 29,
const UWTable = 1 << 30,
const NonLazyBind = 1 << 31,
}
}

Expand Down
52 changes: 26 additions & 26 deletions src/librustc_trans/trans/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ pub fn split_stack(val: ValueRef, set: bool) {
pub fn inline(val: ValueRef, inline: InlineAttr) {
use self::InlineAttr::*;
match inline {
Hint => llvm::SetFunctionAttribute(val, llvm::Attribute::InlineHintAttribute),
Always => llvm::SetFunctionAttribute(val, llvm::Attribute::AlwaysInlineAttribute),
Never => llvm::SetFunctionAttribute(val, llvm::Attribute::NoInlineAttribute),
Hint => llvm::SetFunctionAttribute(val, llvm::Attribute::InlineHint),
Always => llvm::SetFunctionAttribute(val, llvm::Attribute::AlwaysInline),
Never => llvm::SetFunctionAttribute(val, llvm::Attribute::NoInline),
None => {
let attr = llvm::Attribute::InlineHintAttribute |
llvm::Attribute::AlwaysInlineAttribute |
llvm::Attribute::NoInlineAttribute;
let attr = llvm::Attribute::InlineHint |
llvm::Attribute::AlwaysInline |
llvm::Attribute::NoInline;
unsafe {
llvm::LLVMRemoveFunctionAttr(val, attr.bits() as c_ulonglong)
}
Expand All @@ -57,12 +57,12 @@ pub fn inline(val: ValueRef, inline: InlineAttr) {
#[inline]
pub fn emit_uwtable(val: ValueRef, emit: bool) {
if emit {
llvm::SetFunctionAttribute(val, llvm::Attribute::UWTableAttribute);
llvm::SetFunctionAttribute(val, llvm::Attribute::UWTable);
} else {
unsafe {
llvm::LLVMRemoveFunctionAttr(
val,
llvm::Attribute::UWTableAttribute.bits() as c_ulonglong,
llvm::Attribute::UWTable.bits() as c_ulonglong,
);
}
}
Expand All @@ -76,11 +76,11 @@ pub fn unwind(val: ValueRef, can_unwind: bool) {
unsafe {
llvm::LLVMRemoveFunctionAttr(
val,
llvm::Attribute::NoUnwindAttribute.bits() as c_ulonglong,
llvm::Attribute::NoUnwind.bits() as c_ulonglong,
);
}
} else {
llvm::SetFunctionAttribute(val, llvm::Attribute::NoUnwindAttribute);
llvm::SetFunctionAttribute(val, llvm::Attribute::NoUnwind);
}
}

Expand All @@ -89,12 +89,12 @@ pub fn unwind(val: ValueRef, can_unwind: bool) {
#[allow(dead_code)] // possibly useful function
pub fn set_optimize_for_size(val: ValueRef, optimize: bool) {
if optimize {
llvm::SetFunctionAttribute(val, llvm::Attribute::OptimizeForSizeAttribute);
llvm::SetFunctionAttribute(val, llvm::Attribute::OptimizeForSize);
} else {
unsafe {
llvm::LLVMRemoveFunctionAttr(
val,
llvm::Attribute::OptimizeForSizeAttribute.bits() as c_ulonglong,
llvm::Attribute::OptimizeForSize.bits() as c_ulonglong,
);
}
}
Expand All @@ -116,7 +116,7 @@ pub fn from_fn_attrs(ccx: &CrateContext, attrs: &[ast::Attribute], llfn: ValueRe
llvm::ColdAttribute as u64)
}
} else if attr.check_name("allocator") {
llvm::Attribute::NoAliasAttribute.apply_llfn(llvm::ReturnIndex as c_uint, llfn);
llvm::Attribute::NoAlias.apply_llfn(llvm::ReturnIndex as c_uint, llfn);
}
}
}
Expand Down Expand Up @@ -185,9 +185,9 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx
// The outptr can be noalias and nocapture because it's entirely
// invisible to the program. We also know it's nonnull as well
// as how many bytes we can dereference
attrs.arg(1, llvm::Attribute::StructRetAttribute)
.arg(1, llvm::Attribute::NoAliasAttribute)
.arg(1, llvm::Attribute::NoCaptureAttribute)
attrs.arg(1, llvm::Attribute::StructRet)
.arg(1, llvm::Attribute::NoAlias)
.arg(1, llvm::Attribute::NoCapture)
.arg(1, llvm::DereferenceableAttribute(llret_sz));

// Add one more since there's an outptr
Expand All @@ -199,7 +199,7 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx
// `~` pointer return values never alias because ownership
// is transferred
ty::ty_uniq(it) if common::type_is_sized(ccx.tcx(), it) => {
attrs.ret(llvm::Attribute::NoAliasAttribute);
attrs.ret(llvm::Attribute::NoAlias);
}
_ => {}
}
Expand All @@ -216,7 +216,7 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx
}

if let ty::ty_bool = ret_ty.sty {
attrs.ret(llvm::Attribute::ZExtAttribute);
attrs.ret(llvm::Attribute::ZExt);
}
}
}
Expand All @@ -230,20 +230,20 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx
// For non-immediate arguments the callee gets its own copy of
// the value on the stack, so there are no aliases. It's also
// program-invisible so can't possibly capture
attrs.arg(idx, llvm::Attribute::NoAliasAttribute)
.arg(idx, llvm::Attribute::NoCaptureAttribute)
attrs.arg(idx, llvm::Attribute::NoAlias)
.arg(idx, llvm::Attribute::NoCapture)
.arg(idx, llvm::DereferenceableAttribute(llarg_sz));
}

ty::ty_bool => {
attrs.arg(idx, llvm::Attribute::ZExtAttribute);
attrs.arg(idx, llvm::Attribute::ZExt);
}

// `~` pointer parameters never alias because ownership is transferred
ty::ty_uniq(inner) => {
let llsz = machine::llsize_of_real(ccx, type_of::type_of(ccx, inner));

attrs.arg(idx, llvm::Attribute::NoAliasAttribute)
attrs.arg(idx, llvm::Attribute::NoAlias)
.arg(idx, llvm::DereferenceableAttribute(llsz));
}

Expand All @@ -256,23 +256,23 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx
!ty::type_contents(ccx.tcx(), mt.ty).interior_unsafe() => {

let llsz = machine::llsize_of_real(ccx, type_of::type_of(ccx, mt.ty));
attrs.arg(idx, llvm::Attribute::NoAliasAttribute)
attrs.arg(idx, llvm::Attribute::NoAlias)
.arg(idx, llvm::DereferenceableAttribute(llsz));

if mt.mutbl == ast::MutImmutable {
attrs.arg(idx, llvm::Attribute::ReadOnlyAttribute);
attrs.arg(idx, llvm::Attribute::ReadOnly);
}

if let ReLateBound(_, BrAnon(_)) = *b {
attrs.arg(idx, llvm::Attribute::NoCaptureAttribute);
attrs.arg(idx, llvm::Attribute::NoCapture);
}
}

// When a reference in an argument has no named lifetime, it's impossible for that
// reference to escape this function (returned or stored beyond the call by a closure).
ty::ty_rptr(&ReLateBound(_, BrAnon(_)), mt) => {
let llsz = machine::llsize_of_real(ccx, type_of::type_of(ccx, mt.ty));
attrs.arg(idx, llvm::Attribute::NoCaptureAttribute)
attrs.arg(idx, llvm::Attribute::NoCapture)
.arg(idx, llvm::DereferenceableAttribute(llsz));
}

Expand Down
6 changes: 3 additions & 3 deletions src/librustc_trans/trans/cabi_aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ fn is_homogenous_aggregate_ty(ty: Type) -> Option<(Type, u64)> {

fn classify_ret_ty(ccx: &CrateContext, ty: Type) -> ArgType {
if is_reg_ty(ty) {
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExtAttribute) } else { None };
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None };
return ArgType::direct(ty, None, None, attr);
}
if let Some((base_ty, members)) = is_homogenous_aggregate_ty(ty) {
Expand All @@ -185,12 +185,12 @@ fn classify_ret_ty(ccx: &CrateContext, ty: Type) -> ArgType {
};
return ArgType::direct(ty, Some(llty), None, None);
}
ArgType::indirect(ty, Some(Attribute::StructRetAttribute))
ArgType::indirect(ty, Some(Attribute::StructRet))
}

fn classify_arg_ty(ccx: &CrateContext, ty: Type) -> ArgType {
if is_reg_ty(ty) {
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExtAttribute) } else { None };
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None };
return ArgType::direct(ty, None, None, attr);
}
if let Some((base_ty, members)) = is_homogenous_aggregate_ty(ty) {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_trans/trans/cabi_arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ fn ty_size(ty: Type, align_fn: TyAlignFn) -> usize {

fn classify_ret_ty(ccx: &CrateContext, ty: Type, align_fn: TyAlignFn) -> ArgType {
if is_reg_ty(ty) {
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExtAttribute) } else { None };
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None };
return ArgType::direct(ty, None, None, attr);
}
let size = ty_size(ty, align_fn);
Expand All @@ -145,12 +145,12 @@ fn classify_ret_ty(ccx: &CrateContext, ty: Type, align_fn: TyAlignFn) -> ArgType
};
return ArgType::direct(ty, Some(llty), None, None);
}
ArgType::indirect(ty, Some(Attribute::StructRetAttribute))
ArgType::indirect(ty, Some(Attribute::StructRet))
}

fn classify_arg_ty(ccx: &CrateContext, ty: Type, align_fn: TyAlignFn) -> ArgType {
if is_reg_ty(ty) {
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExtAttribute) } else { None };
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None };
return ArgType::direct(ty, None, None, attr);
}
let align = align_fn(ty);
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_trans/trans/cabi_mips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ fn ty_size(ty: Type) -> usize {

fn classify_ret_ty(ccx: &CrateContext, ty: Type) -> ArgType {
if is_reg_ty(ty) {
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExtAttribute) } else { None };
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None };
ArgType::direct(ty, None, None, attr)
} else {
ArgType::indirect(ty, Some(Attribute::StructRetAttribute))
ArgType::indirect(ty, Some(Attribute::StructRet))
}
}

Expand All @@ -105,7 +105,7 @@ fn classify_arg_ty(ccx: &CrateContext, ty: Type, offset: &mut usize) -> ArgType
*offset += align_up_to(size, align * 8) / 8;

if is_reg_ty(ty) {
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExtAttribute) } else { None };
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None };
ArgType::direct(ty, None, None, attr)
} else {
ArgType::direct(
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_trans/trans/cabi_powerpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ fn ty_size(ty: Type) -> usize {

fn classify_ret_ty(ccx: &CrateContext, ty: Type) -> ArgType {
if is_reg_ty(ty) {
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExtAttribute) } else { None };
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None };
ArgType::direct(ty, None, None, attr)
} else {
ArgType::indirect(ty, Some(Attribute::StructRetAttribute))
ArgType::indirect(ty, Some(Attribute::StructRet))
}
}

Expand All @@ -101,7 +101,7 @@ fn classify_arg_ty(ccx: &CrateContext, ty: Type, offset: &mut usize) -> ArgType
*offset += align_up_to(size, align * 8) / 8;

if is_reg_ty(ty) {
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExtAttribute) } else { None };
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None };
ArgType::direct(ty, None, None, attr)
} else {
ArgType::direct(
Expand Down
Loading