Skip to content

Commit 347ee73

Browse files
committed
Auto merge of #24964 - tamird:cleanup-bitflags, r=alexcrichton
Depends on #24921. r? @alexcrichton
2 parents e8b4c84 + e95241b commit 347ee73

16 files changed

+90
-93
lines changed

src/librustc/middle/check_const.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ use std::collections::hash_map::Entry;
4545
bitflags! {
4646
#[derive(RustcEncodable, RustcDecodable)]
4747
flags ConstQualif: u8 {
48-
// Const rvalue which can be placed behind a reference.
49-
const PURE_CONST = 0,
5048
// Inner mutability (can not be placed behind a reference) or behind
5149
// &mut in a non-global expression. Can be copied from static memory.
5250
const MUTABLE_MEM = 1 << 0,
@@ -104,7 +102,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
104102
{
105103
let (old_mode, old_qualif) = (self.mode, self.qualif);
106104
self.mode = mode;
107-
self.qualif = ConstQualif::PURE_CONST;
105+
self.qualif = ConstQualif::empty();
108106
let r = f(self);
109107
self.mode = old_mode;
110108
self.qualif = old_qualif;
@@ -128,7 +126,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> {
128126
Entry::Occupied(entry) => return *entry.get(),
129127
Entry::Vacant(entry) => {
130128
// Prevent infinite recursion on re-entry.
131-
entry.insert(ConstQualif::PURE_CONST);
129+
entry.insert(ConstQualif::empty());
132130
}
133131
}
134132
self.with_mode(mode, |this| {
@@ -273,7 +271,7 @@ impl<'a, 'tcx, 'v> Visitor<'v> for CheckCrateVisitor<'a, 'tcx> {
273271

274272
fn visit_expr(&mut self, ex: &ast::Expr) {
275273
let mut outer = self.qualif;
276-
self.qualif = ConstQualif::PURE_CONST;
274+
self.qualif = ConstQualif::empty();
277275

278276
let node_ty = ty::node_id_to_type(self.tcx, ex.id);
279277
check_expr(self, ex, node_ty);

src/librustc/middle/mem_categorization.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -850,9 +850,10 @@ impl<'t,'tcx,TYPER:Typer<'tcx>> MemCategorizationContext<'t,TYPER> {
850850
// Compute maximum lifetime of this rvalue. This is 'static if
851851
// we can promote to a constant, otherwise equal to enclosing temp
852852
// lifetime.
853-
let re = match qualif & check_const::ConstQualif::NON_STATIC_BORROWS {
854-
check_const::ConstQualif::PURE_CONST => ty::ReStatic,
855-
_ => self.temporary_scope(id),
853+
let re = if qualif.intersects(check_const::ConstQualif::NON_STATIC_BORROWS) {
854+
self.temporary_scope(id)
855+
} else {
856+
ty::ReStatic
856857
};
857858
let ret = self.cat_rvalue(id, span, re, expr_ty);
858859
debug!("cat_rvalue_node ret {}", ret.repr(self.tcx()));

src/librustc/middle/ty.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,6 @@ impl<'tcx> ctxt<'tcx> {
849849
// recursing over the type itself.
850850
bitflags! {
851851
flags TypeFlags: u32 {
852-
const NO_TYPE_FLAGS = 0,
853852
const HAS_PARAMS = 1 << 0,
854853
const HAS_SELF = 1 << 1,
855854
const HAS_TY_INFER = 1 << 2,
@@ -2925,7 +2924,7 @@ struct FlagComputation {
29252924

29262925
impl FlagComputation {
29272926
fn new() -> FlagComputation {
2928-
FlagComputation { flags: TypeFlags::NO_TYPE_FLAGS, depth: 0 }
2927+
FlagComputation { flags: TypeFlags::empty(), depth: 0 }
29292928
}
29302929

29312930
fn for_sty(st: &sty) -> FlagComputation {

src/librustc_llvm/lib.rs

+26-26
Original file line numberDiff line numberDiff line change
@@ -125,32 +125,32 @@ pub enum DiagnosticSeverity {
125125

126126
bitflags! {
127127
flags Attribute : u32 {
128-
const ZExtAttribute = 1 << 0,
129-
const SExtAttribute = 1 << 1,
130-
const NoReturnAttribute = 1 << 2,
131-
const InRegAttribute = 1 << 3,
132-
const StructRetAttribute = 1 << 4,
133-
const NoUnwindAttribute = 1 << 5,
134-
const NoAliasAttribute = 1 << 6,
135-
const ByValAttribute = 1 << 7,
136-
const NestAttribute = 1 << 8,
137-
const ReadNoneAttribute = 1 << 9,
138-
const ReadOnlyAttribute = 1 << 10,
139-
const NoInlineAttribute = 1 << 11,
140-
const AlwaysInlineAttribute = 1 << 12,
141-
const OptimizeForSizeAttribute = 1 << 13,
142-
const StackProtectAttribute = 1 << 14,
143-
const StackProtectReqAttribute = 1 << 15,
144-
const AlignmentAttribute = 1 << 16,
145-
const NoCaptureAttribute = 1 << 21,
146-
const NoRedZoneAttribute = 1 << 22,
147-
const NoImplicitFloatAttribute = 1 << 23,
148-
const NakedAttribute = 1 << 24,
149-
const InlineHintAttribute = 1 << 25,
150-
const StackAttribute = 7 << 26,
151-
const ReturnsTwiceAttribute = 1 << 29,
152-
const UWTableAttribute = 1 << 30,
153-
const NonLazyBindAttribute = 1 << 31,
128+
const ZExt = 1 << 0,
129+
const SExt = 1 << 1,
130+
const NoReturn = 1 << 2,
131+
const InReg = 1 << 3,
132+
const StructRet = 1 << 4,
133+
const NoUnwind = 1 << 5,
134+
const NoAlias = 1 << 6,
135+
const ByVal = 1 << 7,
136+
const Nest = 1 << 8,
137+
const ReadNone = 1 << 9,
138+
const ReadOnly = 1 << 10,
139+
const NoInline = 1 << 11,
140+
const AlwaysInline = 1 << 12,
141+
const OptimizeForSize = 1 << 13,
142+
const StackProtect = 1 << 14,
143+
const StackProtectReq = 1 << 15,
144+
const Alignment = 1 << 16,
145+
const NoCapture = 1 << 21,
146+
const NoRedZone = 1 << 22,
147+
const NoImplicitFloat = 1 << 23,
148+
const Naked = 1 << 24,
149+
const InlineHint = 1 << 25,
150+
const Stack = 7 << 26,
151+
const ReturnsTwice = 1 << 29,
152+
const UWTable = 1 << 30,
153+
const NonLazyBind = 1 << 31,
154154
}
155155
}
156156

src/librustc_trans/trans/attributes.rs

+26-26
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ pub fn split_stack(val: ValueRef, set: bool) {
3939
pub fn inline(val: ValueRef, inline: InlineAttr) {
4040
use self::InlineAttr::*;
4141
match inline {
42-
Hint => llvm::SetFunctionAttribute(val, llvm::Attribute::InlineHintAttribute),
43-
Always => llvm::SetFunctionAttribute(val, llvm::Attribute::AlwaysInlineAttribute),
44-
Never => llvm::SetFunctionAttribute(val, llvm::Attribute::NoInlineAttribute),
42+
Hint => llvm::SetFunctionAttribute(val, llvm::Attribute::InlineHint),
43+
Always => llvm::SetFunctionAttribute(val, llvm::Attribute::AlwaysInline),
44+
Never => llvm::SetFunctionAttribute(val, llvm::Attribute::NoInline),
4545
None => {
46-
let attr = llvm::Attribute::InlineHintAttribute |
47-
llvm::Attribute::AlwaysInlineAttribute |
48-
llvm::Attribute::NoInlineAttribute;
46+
let attr = llvm::Attribute::InlineHint |
47+
llvm::Attribute::AlwaysInline |
48+
llvm::Attribute::NoInline;
4949
unsafe {
5050
llvm::LLVMRemoveFunctionAttr(val, attr.bits() as c_ulonglong)
5151
}
@@ -57,12 +57,12 @@ pub fn inline(val: ValueRef, inline: InlineAttr) {
5757
#[inline]
5858
pub fn emit_uwtable(val: ValueRef, emit: bool) {
5959
if emit {
60-
llvm::SetFunctionAttribute(val, llvm::Attribute::UWTableAttribute);
60+
llvm::SetFunctionAttribute(val, llvm::Attribute::UWTable);
6161
} else {
6262
unsafe {
6363
llvm::LLVMRemoveFunctionAttr(
6464
val,
65-
llvm::Attribute::UWTableAttribute.bits() as c_ulonglong,
65+
llvm::Attribute::UWTable.bits() as c_ulonglong,
6666
);
6767
}
6868
}
@@ -76,11 +76,11 @@ pub fn unwind(val: ValueRef, can_unwind: bool) {
7676
unsafe {
7777
llvm::LLVMRemoveFunctionAttr(
7878
val,
79-
llvm::Attribute::NoUnwindAttribute.bits() as c_ulonglong,
79+
llvm::Attribute::NoUnwind.bits() as c_ulonglong,
8080
);
8181
}
8282
} else {
83-
llvm::SetFunctionAttribute(val, llvm::Attribute::NoUnwindAttribute);
83+
llvm::SetFunctionAttribute(val, llvm::Attribute::NoUnwind);
8484
}
8585
}
8686

@@ -89,12 +89,12 @@ pub fn unwind(val: ValueRef, can_unwind: bool) {
8989
#[allow(dead_code)] // possibly useful function
9090
pub fn set_optimize_for_size(val: ValueRef, optimize: bool) {
9191
if optimize {
92-
llvm::SetFunctionAttribute(val, llvm::Attribute::OptimizeForSizeAttribute);
92+
llvm::SetFunctionAttribute(val, llvm::Attribute::OptimizeForSize);
9393
} else {
9494
unsafe {
9595
llvm::LLVMRemoveFunctionAttr(
9696
val,
97-
llvm::Attribute::OptimizeForSizeAttribute.bits() as c_ulonglong,
97+
llvm::Attribute::OptimizeForSize.bits() as c_ulonglong,
9898
);
9999
}
100100
}
@@ -116,7 +116,7 @@ pub fn from_fn_attrs(ccx: &CrateContext, attrs: &[ast::Attribute], llfn: ValueRe
116116
llvm::ColdAttribute as u64)
117117
}
118118
} else if attr.check_name("allocator") {
119-
llvm::Attribute::NoAliasAttribute.apply_llfn(llvm::ReturnIndex as c_uint, llfn);
119+
llvm::Attribute::NoAlias.apply_llfn(llvm::ReturnIndex as c_uint, llfn);
120120
}
121121
}
122122
}
@@ -185,9 +185,9 @@ pub fn from_fn_type<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, fn_type: ty::Ty<'tcx
185185
// The outptr can be noalias and nocapture because it's entirely
186186
// invisible to the program. We also know it's nonnull as well
187187
// as how many bytes we can dereference
188-
attrs.arg(1, llvm::Attribute::StructRetAttribute)
189-
.arg(1, llvm::Attribute::NoAliasAttribute)
190-
.arg(1, llvm::Attribute::NoCaptureAttribute)
188+
attrs.arg(1, llvm::Attribute::StructRet)
189+
.arg(1, llvm::Attribute::NoAlias)
190+
.arg(1, llvm::Attribute::NoCapture)
191191
.arg(1, llvm::DereferenceableAttribute(llret_sz));
192192

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

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

238238
ty::ty_bool => {
239-
attrs.arg(idx, llvm::Attribute::ZExtAttribute);
239+
attrs.arg(idx, llvm::Attribute::ZExt);
240240
}
241241

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

246-
attrs.arg(idx, llvm::Attribute::NoAliasAttribute)
246+
attrs.arg(idx, llvm::Attribute::NoAlias)
247247
.arg(idx, llvm::DereferenceableAttribute(llsz));
248248
}
249249

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

258258
let llsz = machine::llsize_of_real(ccx, type_of::type_of(ccx, mt.ty));
259-
attrs.arg(idx, llvm::Attribute::NoAliasAttribute)
259+
attrs.arg(idx, llvm::Attribute::NoAlias)
260260
.arg(idx, llvm::DereferenceableAttribute(llsz));
261261

262262
if mt.mutbl == ast::MutImmutable {
263-
attrs.arg(idx, llvm::Attribute::ReadOnlyAttribute);
263+
attrs.arg(idx, llvm::Attribute::ReadOnly);
264264
}
265265

266266
if let ReLateBound(_, BrAnon(_)) = *b {
267-
attrs.arg(idx, llvm::Attribute::NoCaptureAttribute);
267+
attrs.arg(idx, llvm::Attribute::NoCapture);
268268
}
269269
}
270270

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

src/librustc_trans/trans/cabi_aarch64.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ fn is_homogenous_aggregate_ty(ty: Type) -> Option<(Type, u64)> {
163163

164164
fn classify_ret_ty(ccx: &CrateContext, ty: Type) -> ArgType {
165165
if is_reg_ty(ty) {
166-
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExtAttribute) } else { None };
166+
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None };
167167
return ArgType::direct(ty, None, None, attr);
168168
}
169169
if let Some((base_ty, members)) = is_homogenous_aggregate_ty(ty) {
@@ -185,12 +185,12 @@ fn classify_ret_ty(ccx: &CrateContext, ty: Type) -> ArgType {
185185
};
186186
return ArgType::direct(ty, Some(llty), None, None);
187187
}
188-
ArgType::indirect(ty, Some(Attribute::StructRetAttribute))
188+
ArgType::indirect(ty, Some(Attribute::StructRet))
189189
}
190190

191191
fn classify_arg_ty(ccx: &CrateContext, ty: Type) -> ArgType {
192192
if is_reg_ty(ty) {
193-
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExtAttribute) } else { None };
193+
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None };
194194
return ArgType::direct(ty, None, None, attr);
195195
}
196196
if let Some((base_ty, members)) = is_homogenous_aggregate_ty(ty) {

src/librustc_trans/trans/cabi_arm.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ fn ty_size(ty: Type, align_fn: TyAlignFn) -> usize {
131131

132132
fn classify_ret_ty(ccx: &CrateContext, ty: Type, align_fn: TyAlignFn) -> ArgType {
133133
if is_reg_ty(ty) {
134-
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExtAttribute) } else { None };
134+
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None };
135135
return ArgType::direct(ty, None, None, attr);
136136
}
137137
let size = ty_size(ty, align_fn);
@@ -145,12 +145,12 @@ fn classify_ret_ty(ccx: &CrateContext, ty: Type, align_fn: TyAlignFn) -> ArgType
145145
};
146146
return ArgType::direct(ty, Some(llty), None, None);
147147
}
148-
ArgType::indirect(ty, Some(Attribute::StructRetAttribute))
148+
ArgType::indirect(ty, Some(Attribute::StructRet))
149149
}
150150

151151
fn classify_arg_ty(ccx: &CrateContext, ty: Type, align_fn: TyAlignFn) -> ArgType {
152152
if is_reg_ty(ty) {
153-
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExtAttribute) } else { None };
153+
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None };
154154
return ArgType::direct(ty, None, None, attr);
155155
}
156156
let align = align_fn(ty);

src/librustc_trans/trans/cabi_mips.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,10 @@ fn ty_size(ty: Type) -> usize {
8888

8989
fn classify_ret_ty(ccx: &CrateContext, ty: Type) -> ArgType {
9090
if is_reg_ty(ty) {
91-
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExtAttribute) } else { None };
91+
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None };
9292
ArgType::direct(ty, None, None, attr)
9393
} else {
94-
ArgType::indirect(ty, Some(Attribute::StructRetAttribute))
94+
ArgType::indirect(ty, Some(Attribute::StructRet))
9595
}
9696
}
9797

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

107107
if is_reg_ty(ty) {
108-
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExtAttribute) } else { None };
108+
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None };
109109
ArgType::direct(ty, None, None, attr)
110110
} else {
111111
ArgType::direct(

src/librustc_trans/trans/cabi_powerpc.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ fn ty_size(ty: Type) -> usize {
8484

8585
fn classify_ret_ty(ccx: &CrateContext, ty: Type) -> ArgType {
8686
if is_reg_ty(ty) {
87-
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExtAttribute) } else { None };
87+
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None };
8888
ArgType::direct(ty, None, None, attr)
8989
} else {
90-
ArgType::indirect(ty, Some(Attribute::StructRetAttribute))
90+
ArgType::indirect(ty, Some(Attribute::StructRet))
9191
}
9292
}
9393

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

103103
if is_reg_ty(ty) {
104-
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExtAttribute) } else { None };
104+
let attr = if ty == Type::i1(ccx) { Some(Attribute::ZExt) } else { None };
105105
ArgType::direct(ty, None, None, attr)
106106
} else {
107107
ArgType::direct(

0 commit comments

Comments
 (0)