Auto merge of #122024 - clubby789:remove-spec-option-pe, r=jhpratt
Remove SpecOptionPartialEq With the recent LLVM bump, the specialization for Option::partial_eq on types with niches is no longer necessary. I kept the manual implementation as it still gives us better codegen than the derive (will look at this seperately). Also implemented PartialOrd/Ord by hand as it _somewhat_ improves codegen for #49892: https://godbolt.org/z/vx5Y6oW4Y
This commit is contained in:
commit
cdb683f6e4
5 changed files with 71 additions and 127 deletions
|
@ -34,13 +34,7 @@ mod newtype;
|
|||
#[proc_macro]
|
||||
#[cfg_attr(
|
||||
feature = "nightly",
|
||||
allow_internal_unstable(
|
||||
step_trait,
|
||||
rustc_attrs,
|
||||
trusted_step,
|
||||
spec_option_partial_eq,
|
||||
min_specialization
|
||||
)
|
||||
allow_internal_unstable(step_trait, rustc_attrs, trusted_step, min_specialization)
|
||||
)]
|
||||
pub fn newtype_index(input: TokenStream) -> TokenStream {
|
||||
newtype::newtype(input)
|
||||
|
|
|
@ -156,32 +156,6 @@ impl Parse for Newtype {
|
|||
}
|
||||
};
|
||||
|
||||
let spec_partial_eq_impl = if let Lit::Int(max) = &max {
|
||||
if let Ok(max_val) = max.base10_parse::<u32>() {
|
||||
quote! {
|
||||
#gate_rustc_only
|
||||
impl core::option::SpecOptionPartialEq for #name {
|
||||
#[inline]
|
||||
fn eq(l: &Option<Self>, r: &Option<Self>) -> bool {
|
||||
if #max_val < u32::MAX {
|
||||
l.map(|i| i.as_u32()).unwrap_or(#max_val+1) == r.map(|i| i.as_u32()).unwrap_or(#max_val+1)
|
||||
} else {
|
||||
match (l, r) {
|
||||
(Some(l), Some(r)) => r == l,
|
||||
(None, None) => true,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
quote! {}
|
||||
}
|
||||
} else {
|
||||
quote! {}
|
||||
};
|
||||
|
||||
Ok(Self(quote! {
|
||||
#(#attrs)*
|
||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, #(#derive_paths),*)]
|
||||
|
@ -283,8 +257,6 @@ impl Parse for Newtype {
|
|||
|
||||
#step
|
||||
|
||||
#spec_partial_eq_impl
|
||||
|
||||
impl From<#name> for u32 {
|
||||
#[inline]
|
||||
fn from(v: #name) -> u32 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue