Skip to content

Commit fd6626d

Browse files
committed
Auto merge of #140912 - fmease:rollup-rwtn31e, r=fmease
Rollup of 7 pull requests Successful merges: - #140792 (Use intrinsics for `{f16,f32,f64,f128}::{minimum,maximum}` operations) - #140795 (Prefer to suggest stable candidates rather than unstable ones) - #140865 (Make t letter looks like lowercase rather than uppercase) - #140878 (Two expand-related cleanups) - #140882 (Split duration_constructors to get non-controversial constructors out) - #140886 (Update deps of bootstrap for Cygwin) - #140903 (test intrinsic fallback bodies with Miri) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7b84c9e + 615b447 commit fd6626d

File tree

38 files changed

+580
-216
lines changed

38 files changed

+580
-216
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4314,6 +4314,7 @@ dependencies = [
43144314
"rustc_arena",
43154315
"rustc_ast",
43164316
"rustc_ast_pretty",
4317+
"rustc_attr_data_structures",
43174318
"rustc_attr_parsing",
43184319
"rustc_data_structures",
43194320
"rustc_errors",

compiler/rustc_ast/src/ast.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,6 @@ impl ParenthesizedArgs {
308308
}
309309
}
310310

311-
use crate::AstDeref;
312311
pub use crate::node_id::{CRATE_NODE_ID, DUMMY_NODE_ID, NodeId};
313312

314313
/// Modifiers on a trait bound like `~const`, `?` and `!`.
@@ -2349,7 +2348,7 @@ impl Ty {
23492348
pub fn is_maybe_parenthesised_infer(&self) -> bool {
23502349
match &self.kind {
23512350
TyKind::Infer => true,
2352-
TyKind::Paren(inner) => inner.ast_deref().is_maybe_parenthesised_infer(),
2351+
TyKind::Paren(inner) => inner.is_maybe_parenthesised_infer(),
23532352
_ => false,
23542353
}
23552354
}

compiler/rustc_ast/src/ast_traits.rs

+28-47
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,6 @@ use crate::{
1313
Ty, Variant, Visibility, WherePredicate,
1414
};
1515

16-
/// A utility trait to reduce boilerplate.
17-
/// Standard `Deref(Mut)` cannot be reused due to coherence.
18-
pub trait AstDeref {
19-
type Target;
20-
fn ast_deref(&self) -> &Self::Target;
21-
fn ast_deref_mut(&mut self) -> &mut Self::Target;
22-
}
23-
24-
macro_rules! impl_not_ast_deref {
25-
($($T:ty),+ $(,)?) => {
26-
$(
27-
impl !AstDeref for $T {}
28-
)+
29-
};
30-
}
31-
32-
impl_not_ast_deref!(AssocItem, Expr, ForeignItem, Item, Stmt);
33-
34-
impl<T> AstDeref for P<T> {
35-
type Target = T;
36-
fn ast_deref(&self) -> &Self::Target {
37-
self
38-
}
39-
fn ast_deref_mut(&mut self) -> &mut Self::Target {
40-
self
41-
}
42-
}
43-
4416
/// A trait for AST nodes having an ID.
4517
pub trait HasNodeId {
4618
fn node_id(&self) -> NodeId;
@@ -81,12 +53,12 @@ impl_has_node_id!(
8153
WherePredicate,
8254
);
8355

84-
impl<T: AstDeref<Target: HasNodeId>> HasNodeId for T {
56+
impl<T: HasNodeId> HasNodeId for P<T> {
8557
fn node_id(&self) -> NodeId {
86-
self.ast_deref().node_id()
58+
(**self).node_id()
8759
}
8860
fn node_id_mut(&mut self) -> &mut NodeId {
89-
self.ast_deref_mut().node_id_mut()
61+
(**self).node_id_mut()
9062
}
9163
}
9264

@@ -138,21 +110,21 @@ impl_has_tokens_none!(
138110
WherePredicate
139111
);
140112

141-
impl<T: AstDeref<Target: HasTokens>> HasTokens for T {
113+
impl<T: HasTokens> HasTokens for Option<T> {
142114
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
143-
self.ast_deref().tokens()
115+
self.as_ref().and_then(|inner| inner.tokens())
144116
}
145117
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
146-
self.ast_deref_mut().tokens_mut()
118+
self.as_mut().and_then(|inner| inner.tokens_mut())
147119
}
148120
}
149121

150-
impl<T: HasTokens> HasTokens for Option<T> {
122+
impl<T: HasTokens> HasTokens for P<T> {
151123
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
152-
self.as_ref().and_then(|inner| inner.tokens())
124+
(**self).tokens()
153125
}
154126
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>> {
155-
self.as_mut().and_then(|inner| inner.tokens_mut())
127+
(**self).tokens_mut()
156128
}
157129
}
158130

@@ -273,13 +245,13 @@ impl_has_attrs!(
273245
);
274246
impl_has_attrs_none!(Attribute, AttrItem, Block, Pat, Path, Ty, Visibility);
275247

276-
impl<T: AstDeref<Target: HasAttrs>> HasAttrs for T {
277-
const SUPPORTS_CUSTOM_INNER_ATTRS: bool = T::Target::SUPPORTS_CUSTOM_INNER_ATTRS;
248+
impl<T: HasAttrs> HasAttrs for P<T> {
249+
const SUPPORTS_CUSTOM_INNER_ATTRS: bool = T::SUPPORTS_CUSTOM_INNER_ATTRS;
278250
fn attrs(&self) -> &[Attribute] {
279-
self.ast_deref().attrs()
251+
(**self).attrs()
280252
}
281253
fn visit_attrs(&mut self, f: impl FnOnce(&mut AttrVec)) {
282-
self.ast_deref_mut().visit_attrs(f)
254+
(**self).visit_attrs(f);
283255
}
284256
}
285257

@@ -343,13 +315,22 @@ impl<Wrapped, Tag> AstNodeWrapper<Wrapped, Tag> {
343315
}
344316
}
345317

346-
impl<Wrapped, Tag> AstDeref for AstNodeWrapper<Wrapped, Tag> {
347-
type Target = Wrapped;
348-
fn ast_deref(&self) -> &Self::Target {
349-
&self.wrapped
318+
impl<Wrapped: HasNodeId, Tag> HasNodeId for AstNodeWrapper<Wrapped, Tag> {
319+
fn node_id(&self) -> NodeId {
320+
self.wrapped.node_id()
321+
}
322+
fn node_id_mut(&mut self) -> &mut NodeId {
323+
self.wrapped.node_id_mut()
324+
}
325+
}
326+
327+
impl<Wrapped: HasAttrs, Tag> HasAttrs for AstNodeWrapper<Wrapped, Tag> {
328+
const SUPPORTS_CUSTOM_INNER_ATTRS: bool = Wrapped::SUPPORTS_CUSTOM_INNER_ATTRS;
329+
fn attrs(&self) -> &[Attribute] {
330+
self.wrapped.attrs()
350331
}
351-
fn ast_deref_mut(&mut self) -> &mut Self::Target {
352-
&mut self.wrapped
332+
fn visit_attrs(&mut self, f: impl FnOnce(&mut AttrVec)) {
333+
self.wrapped.visit_attrs(f);
353334
}
354335
}
355336

compiler/rustc_ast/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub mod tokenstream;
4646
pub mod visit;
4747

4848
pub use self::ast::*;
49-
pub use self::ast_traits::{AstDeref, AstNodeWrapper, HasAttrs, HasNodeId, HasTokens};
49+
pub use self::ast_traits::{AstNodeWrapper, HasAttrs, HasNodeId, HasTokens};
5050

5151
/// Requirements for a `StableHashingContext` to be used in this crate.
5252
/// This is a hack to allow using the `HashStable_Generic` derive macro

compiler/rustc_builtin_macros/src/env.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::env::VarError;
88

99
use rustc_ast::token::{self, LitKind};
1010
use rustc_ast::tokenstream::TokenStream;
11-
use rustc_ast::{AstDeref, ExprKind, GenericArg, Mutability};
11+
use rustc_ast::{ExprKind, GenericArg, Mutability};
1212
use rustc_expand::base::{DummyResult, ExpandResult, ExtCtxt, MacEager, MacroExpanderResult};
1313
use rustc_span::{Ident, Span, Symbol, kw, sym};
1414
use thin_vec::thin_vec;
@@ -148,13 +148,13 @@ pub(crate) fn expand_env<'cx>(
148148
cx.dcx().emit_err(errors::EnvNotDefined::CargoEnvVar {
149149
span,
150150
var: *symbol,
151-
var_expr: var_expr.ast_deref(),
151+
var_expr: &var_expr,
152152
})
153153
} else {
154154
cx.dcx().emit_err(errors::EnvNotDefined::CustomEnvVar {
155155
span,
156156
var: *symbol,
157-
var_expr: var_expr.ast_deref(),
157+
var_expr: &var_expr,
158158
})
159159
}
160160
}

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

+37
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,43 @@ fn codegen_regular_intrinsic_call<'tcx>(
11091109
ret.write_cvalue(fx, old);
11101110
}
11111111

1112+
sym::minimumf32 => {
1113+
intrinsic_args!(fx, args => (a, b); intrinsic);
1114+
let a = a.load_scalar(fx);
1115+
let b = b.load_scalar(fx);
1116+
1117+
let val = fx.bcx.ins().fmin(a, b);
1118+
let val = CValue::by_val(val, fx.layout_of(fx.tcx.types.f32));
1119+
ret.write_cvalue(fx, val);
1120+
}
1121+
sym::minimumf64 => {
1122+
intrinsic_args!(fx, args => (a, b); intrinsic);
1123+
let a = a.load_scalar(fx);
1124+
let b = b.load_scalar(fx);
1125+
1126+
let val = fx.bcx.ins().fmin(a, b);
1127+
let val = CValue::by_val(val, fx.layout_of(fx.tcx.types.f64));
1128+
ret.write_cvalue(fx, val);
1129+
}
1130+
sym::maximumf32 => {
1131+
intrinsic_args!(fx, args => (a, b); intrinsic);
1132+
let a = a.load_scalar(fx);
1133+
let b = b.load_scalar(fx);
1134+
1135+
let val = fx.bcx.ins().fmax(a, b);
1136+
let val = CValue::by_val(val, fx.layout_of(fx.tcx.types.f32));
1137+
ret.write_cvalue(fx, val);
1138+
}
1139+
sym::maximumf64 => {
1140+
intrinsic_args!(fx, args => (a, b); intrinsic);
1141+
let a = a.load_scalar(fx);
1142+
let b = b.load_scalar(fx);
1143+
1144+
let val = fx.bcx.ins().fmax(a, b);
1145+
let val = CValue::by_val(val, fx.layout_of(fx.tcx.types.f64));
1146+
ret.write_cvalue(fx, val);
1147+
}
1148+
11121149
sym::minnumf32 => {
11131150
intrinsic_args!(fx, args => (a, b); intrinsic);
11141151
let a = a.load_scalar(fx);

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

+36
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,44 @@ fn get_simple_intrinsic<'gcc, 'tcx>(
7474
sym::fabsf64 => "fabs",
7575
sym::minnumf32 => "fminf",
7676
sym::minnumf64 => "fmin",
77+
sym::minimumf32 => "fminimumf",
78+
sym::minimumf64 => "fminimum",
79+
sym::minimumf128 => {
80+
// GCC doesn't have the intrinsic we want so we use the compiler-builtins one
81+
// https://docs.rs/compiler_builtins/latest/compiler_builtins/math/full_availability/fn.fminimumf128.html
82+
let f128_type = cx.type_f128();
83+
return Some(cx.context.new_function(
84+
None,
85+
FunctionType::Extern,
86+
f128_type,
87+
&[
88+
cx.context.new_parameter(None, f128_type, "a"),
89+
cx.context.new_parameter(None, f128_type, "b"),
90+
],
91+
"fminimumf128",
92+
false,
93+
));
94+
}
7795
sym::maxnumf32 => "fmaxf",
7896
sym::maxnumf64 => "fmax",
97+
sym::maximumf32 => "fmaximumf",
98+
sym::maximumf64 => "fmaximum",
99+
sym::maximumf128 => {
100+
// GCC doesn't have the intrinsic we want so we use the compiler-builtins one
101+
// https://docs.rs/compiler_builtins/latest/compiler_builtins/math/full_availability/fn.fmaximumf128.html
102+
let f128_type = cx.type_f128();
103+
return Some(cx.context.new_function(
104+
None,
105+
FunctionType::Extern,
106+
f128_type,
107+
&[
108+
cx.context.new_parameter(None, f128_type, "a"),
109+
cx.context.new_parameter(None, f128_type, "b"),
110+
],
111+
"fmaximumf128",
112+
false,
113+
));
114+
}
79115
sym::copysignf32 => "copysignf",
80116
sym::copysignf64 => "copysign",
81117
sym::copysignf128 => "copysignl",

compiler/rustc_codegen_llvm/src/context.rs

+16
Original file line numberDiff line numberDiff line change
@@ -1009,11 +1009,27 @@ impl<'ll> CodegenCx<'ll, '_> {
10091009
ifn!("llvm.minnum.f64", fn(t_f64, t_f64) -> t_f64);
10101010
ifn!("llvm.minnum.f128", fn(t_f128, t_f128) -> t_f128);
10111011

1012+
ifn!("llvm.minimum.f16", fn(t_f16, t_f16) -> t_f16);
1013+
ifn!("llvm.minimum.f32", fn(t_f32, t_f32) -> t_f32);
1014+
ifn!("llvm.minimum.f64", fn(t_f64, t_f64) -> t_f64);
1015+
// There are issues on x86_64 and aarch64 with the f128 variant.
1016+
// - https://github.com/llvm/llvm-project/issues/139380
1017+
// - https://github.com/llvm/llvm-project/issues/139381
1018+
// ifn!("llvm.minimum.f128", fn(t_f128, t_f128) -> t_f128);
1019+
10121020
ifn!("llvm.maxnum.f16", fn(t_f16, t_f16) -> t_f16);
10131021
ifn!("llvm.maxnum.f32", fn(t_f32, t_f32) -> t_f32);
10141022
ifn!("llvm.maxnum.f64", fn(t_f64, t_f64) -> t_f64);
10151023
ifn!("llvm.maxnum.f128", fn(t_f128, t_f128) -> t_f128);
10161024

1025+
ifn!("llvm.maximum.f16", fn(t_f16, t_f16) -> t_f16);
1026+
ifn!("llvm.maximum.f32", fn(t_f32, t_f32) -> t_f32);
1027+
ifn!("llvm.maximum.f64", fn(t_f64, t_f64) -> t_f64);
1028+
// There are issues on x86_64 and aarch64 with the f128 variant.
1029+
// - https://github.com/llvm/llvm-project/issues/139380
1030+
// - https://github.com/llvm/llvm-project/issues/139381
1031+
// ifn!("llvm.maximum.f128", fn(t_f128, t_f128) -> t_f128);
1032+
10171033
ifn!("llvm.floor.f16", fn(t_f16) -> t_f16);
10181034
ifn!("llvm.floor.f32", fn(t_f32) -> t_f32);
10191035
ifn!("llvm.floor.f64", fn(t_f64) -> t_f64);

compiler/rustc_codegen_llvm/src/intrinsic.rs

+12
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,23 @@ fn get_simple_intrinsic<'ll>(
103103
sym::minnumf64 => "llvm.minnum.f64",
104104
sym::minnumf128 => "llvm.minnum.f128",
105105

106+
sym::minimumf16 => "llvm.minimum.f16",
107+
sym::minimumf32 => "llvm.minimum.f32",
108+
sym::minimumf64 => "llvm.minimum.f64",
109+
// There are issues on x86_64 and aarch64 with the f128 variant,
110+
// let's instead use the instrinsic fallback body.
111+
// sym::minimumf128 => "llvm.minimum.f128",
106112
sym::maxnumf16 => "llvm.maxnum.f16",
107113
sym::maxnumf32 => "llvm.maxnum.f32",
108114
sym::maxnumf64 => "llvm.maxnum.f64",
109115
sym::maxnumf128 => "llvm.maxnum.f128",
110116

117+
sym::maximumf16 => "llvm.maximum.f16",
118+
sym::maximumf32 => "llvm.maximum.f32",
119+
sym::maximumf64 => "llvm.maximum.f64",
120+
// There are issues on x86_64 and aarch64 with the f128 variant,
121+
// let's instead use the instrinsic fallback body.
122+
// sym::maximumf128 => "llvm.maximum.f128",
111123
sym::copysignf16 => "llvm.copysign.f16",
112124
sym::copysignf32 => "llvm.copysign.f32",
113125
sym::copysignf64 => "llvm.copysign.f64",

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+42
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,21 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
493493
sym::minnumf64 => self.float_min_intrinsic::<Double>(args, dest)?,
494494
sym::minnumf128 => self.float_min_intrinsic::<Quad>(args, dest)?,
495495

496+
sym::minimumf16 => self.float_minimum_intrinsic::<Half>(args, dest)?,
497+
sym::minimumf32 => self.float_minimum_intrinsic::<Single>(args, dest)?,
498+
sym::minimumf64 => self.float_minimum_intrinsic::<Double>(args, dest)?,
499+
sym::minimumf128 => self.float_minimum_intrinsic::<Quad>(args, dest)?,
500+
496501
sym::maxnumf16 => self.float_max_intrinsic::<Half>(args, dest)?,
497502
sym::maxnumf32 => self.float_max_intrinsic::<Single>(args, dest)?,
498503
sym::maxnumf64 => self.float_max_intrinsic::<Double>(args, dest)?,
499504
sym::maxnumf128 => self.float_max_intrinsic::<Quad>(args, dest)?,
500505

506+
sym::maximumf16 => self.float_maximum_intrinsic::<Half>(args, dest)?,
507+
sym::maximumf32 => self.float_maximum_intrinsic::<Single>(args, dest)?,
508+
sym::maximumf64 => self.float_maximum_intrinsic::<Double>(args, dest)?,
509+
sym::maximumf128 => self.float_maximum_intrinsic::<Quad>(args, dest)?,
510+
501511
sym::copysignf16 => self.float_copysign_intrinsic::<Half>(args, dest)?,
502512
sym::copysignf32 => self.float_copysign_intrinsic::<Single>(args, dest)?,
503513
sym::copysignf64 => self.float_copysign_intrinsic::<Double>(args, dest)?,
@@ -830,6 +840,38 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
830840
interp_ok(())
831841
}
832842

843+
fn float_minimum_intrinsic<F>(
844+
&mut self,
845+
args: &[OpTy<'tcx, M::Provenance>],
846+
dest: &MPlaceTy<'tcx, M::Provenance>,
847+
) -> InterpResult<'tcx, ()>
848+
where
849+
F: rustc_apfloat::Float + rustc_apfloat::FloatConvert<F> + Into<Scalar<M::Provenance>>,
850+
{
851+
let a: F = self.read_scalar(&args[0])?.to_float()?;
852+
let b: F = self.read_scalar(&args[1])?.to_float()?;
853+
let res = a.minimum(b);
854+
let res = self.adjust_nan(res, &[a, b]);
855+
self.write_scalar(res, dest)?;
856+
interp_ok(())
857+
}
858+
859+
fn float_maximum_intrinsic<F>(
860+
&mut self,
861+
args: &[OpTy<'tcx, M::Provenance>],
862+
dest: &MPlaceTy<'tcx, M::Provenance>,
863+
) -> InterpResult<'tcx, ()>
864+
where
865+
F: rustc_apfloat::Float + rustc_apfloat::FloatConvert<F> + Into<Scalar<M::Provenance>>,
866+
{
867+
let a: F = self.read_scalar(&args[0])?.to_float()?;
868+
let b: F = self.read_scalar(&args[1])?.to_float()?;
869+
let res = a.maximum(b);
870+
let res = self.adjust_nan(res, &[a, b]);
871+
self.write_scalar(res, dest)?;
872+
interp_ok(())
873+
}
874+
833875
fn float_copysign_intrinsic<F>(
834876
&mut self,
835877
args: &[OpTy<'tcx, M::Provenance>],

0 commit comments

Comments
 (0)