1
Fork 0

Update to bitflags 2 in the compiler

This involves lots of breaking changes. There are two big changes that
force changes. The first is that the bitflag types now don't
automatically implement normal derive traits, so we need to derive them
manually.

Additionally, bitflags now have a hidden inner type by default, which
breaks our custom derives. The bitflags docs recommend using the impl
form in these cases, which I did.
This commit is contained in:
Nilstrieb 2023-12-30 17:09:02 +01:00
parent d59f06fc64
commit ffafcd8819
32 changed files with 132 additions and 139 deletions

View file

@ -93,9 +93,10 @@ pub use attr_impl::ArgAttribute;
#[allow(unused)]
mod attr_impl {
// The subset of llvm::Attribute needed for arguments, packed into a bitfield.
#[derive(Clone, Copy, Default, Hash, PartialEq, Eq, HashStable_Generic)]
pub struct ArgAttribute(u8);
bitflags::bitflags! {
#[derive(Default, HashStable_Generic)]
pub struct ArgAttribute: u8 {
impl ArgAttribute: u8 {
const NoAlias = 1 << 1;
const NoCapture = 1 << 2;
const NonNull = 1 << 3;
@ -104,6 +105,7 @@ mod attr_impl {
const NoUndef = 1 << 6;
}
}
rustc_data_structures::external_bitflags_debug! { ArgAttribute }
}
/// Sometimes an ABI requires small integers to be extended to a full or partial register. This enum

View file

@ -39,7 +39,6 @@ use crate::abi::{Endian, Integer, Size, TargetDataLayout, TargetDataLayoutErrors
use crate::json::{Json, ToJson};
use crate::spec::abi::{lookup as lookup_abi, Abi};
use crate::spec::crt_objects::CrtObjects;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_fs_util::try_canonicalize;
use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use rustc_span::symbol::{kw, sym, Symbol};
@ -592,7 +591,7 @@ impl LinkSelfContainedDefault {
}
bitflags::bitflags! {
#[derive(Default)]
#[derive(Clone, Copy, PartialEq, Eq, Default)]
/// The `-C link-self-contained` components that can individually be enabled or disabled.
pub struct LinkSelfContainedComponents: u8 {
/// CRT objects (e.g. on `windows-gnu`, `musl`, `wasi` targets)
@ -609,6 +608,7 @@ bitflags::bitflags! {
const MINGW = 1 << 5;
}
}
rustc_data_structures::external_bitflags_debug! { LinkSelfContainedComponents }
impl LinkSelfContainedComponents {
/// Parses a single `-Clink-self-contained` well-known component, not a set of flags.
@ -667,19 +667,6 @@ impl LinkSelfContainedComponents {
}
}
impl IntoIterator for LinkSelfContainedComponents {
type Item = LinkSelfContainedComponents;
type IntoIter = std::vec::IntoIter<LinkSelfContainedComponents>;
fn into_iter(self) -> Self::IntoIter {
LinkSelfContainedComponents::all_components()
.into_iter()
.filter(|&s| self.contains(s))
.collect::<Vec<_>>()
.into_iter()
}
}
impl ToJson for LinkSelfContainedComponents {
fn to_json(&self) -> Json {
let components: Vec<_> = Self::all_components()
@ -1219,9 +1206,10 @@ impl ToJson for StackProbeType {
}
}
#[derive(Default, Clone, Copy, PartialEq, Eq, Hash, Encodable, Decodable, HashStable_Generic)]
pub struct SanitizerSet(u16);
bitflags::bitflags! {
#[derive(Default, Encodable, Decodable)]
pub struct SanitizerSet: u16 {
impl SanitizerSet: u16 {
const ADDRESS = 1 << 0;
const LEAK = 1 << 1;
const MEMORY = 1 << 2;
@ -1235,6 +1223,7 @@ bitflags::bitflags! {
const SAFESTACK = 1 << 10;
}
}
rustc_data_structures::external_bitflags_debug! { SanitizerSet }
impl SanitizerSet {
/// Return sanitizer's name
@ -1274,38 +1263,6 @@ impl fmt::Display for SanitizerSet {
}
}
impl IntoIterator for SanitizerSet {
type Item = SanitizerSet;
type IntoIter = std::vec::IntoIter<SanitizerSet>;
fn into_iter(self) -> Self::IntoIter {
[
SanitizerSet::ADDRESS,
SanitizerSet::CFI,
SanitizerSet::KCFI,
SanitizerSet::LEAK,
SanitizerSet::MEMORY,
SanitizerSet::MEMTAG,
SanitizerSet::SHADOWCALLSTACK,
SanitizerSet::THREAD,
SanitizerSet::HWADDRESS,
SanitizerSet::KERNELADDRESS,
SanitizerSet::SAFESTACK,
]
.iter()
.copied()
.filter(|&s| self.contains(s))
.collect::<Vec<_>>()
.into_iter()
}
}
impl<CTX> HashStable<CTX> for SanitizerSet {
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
self.bits().hash_stable(ctx, hasher);
}
}
impl ToJson for SanitizerSet {
fn to_json(&self) -> Json {
self.into_iter()