Skip to content

Commit ae3703c

Browse files
committed
Auto merge of rust-lang#133788 - matthiaskrgr:rollup-1p100a8, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - rust-lang#132723 (Unify `sysroot_target_{bin,lib}dir` handling) - rust-lang#133041 (Print name of env var in `--print=deployment-target`) - rust-lang#133325 (Reimplement `~const` trait specialization) - rust-lang#133395 (Add simd_relaxed_fma intrinsic) - rust-lang#133517 (Deeply normalize when computing implied outlives bounds) - rust-lang#133785 (Add const evaluation error UI test.) r? `@ghost` `@rustbot` modify labels: rollup
2 parents efdd9e8 + 8ae1114 commit ae3703c

File tree

44 files changed

+535
-168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+535
-168
lines changed

compiler/rustc_codegen_cranelift/src/intrinsics/simd.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,8 @@ pub(super) fn codegen_simd_intrinsic_call<'tcx>(
415415
});
416416
}
417417

418-
sym::simd_fma => {
418+
// FIXME: simd_relaxed_fma doesn't relax to non-fused multiply-add
419+
sym::simd_fma | sym::simd_relaxed_fma => {
419420
intrinsic_args!(fx, args => (a, b, c); intrinsic);
420421

421422
if !a.layout().ty.is_simd() {

compiler/rustc_codegen_gcc/src/intrinsic/simd.rs

+1
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,7 @@ pub fn generic_simd_intrinsic<'a, 'gcc, 'tcx>(
772772
sym::simd_flog => "log",
773773
sym::simd_floor => "floor",
774774
sym::simd_fma => "fma",
775+
sym::simd_relaxed_fma => "fma", // FIXME: this should relax to non-fused multiply-add when necessary
775776
sym::simd_fpowi => "__builtin_powi",
776777
sym::simd_fpow => "pow",
777778
sym::simd_fsin => "sin",

compiler/rustc_codegen_llvm/src/intrinsic.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1534,6 +1534,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
15341534
sym::simd_flog => ("log", bx.type_func(&[vec_ty], vec_ty)),
15351535
sym::simd_floor => ("floor", bx.type_func(&[vec_ty], vec_ty)),
15361536
sym::simd_fma => ("fma", bx.type_func(&[vec_ty, vec_ty, vec_ty], vec_ty)),
1537+
sym::simd_relaxed_fma => ("fmuladd", bx.type_func(&[vec_ty, vec_ty, vec_ty], vec_ty)),
15371538
sym::simd_fpowi => ("powi", bx.type_func(&[vec_ty, bx.type_i32()], vec_ty)),
15381539
sym::simd_fpow => ("pow", bx.type_func(&[vec_ty, vec_ty], vec_ty)),
15391540
sym::simd_fsin => ("sin", bx.type_func(&[vec_ty], vec_ty)),
@@ -1572,6 +1573,7 @@ fn generic_simd_intrinsic<'ll, 'tcx>(
15721573
| sym::simd_fpowi
15731574
| sym::simd_fsin
15741575
| sym::simd_fsqrt
1576+
| sym::simd_relaxed_fma
15751577
| sym::simd_round
15761578
| sym::simd_trunc
15771579
) {

compiler/rustc_codegen_ssa/src/back/apple.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ fn minimum_deployment_target(target: &Target) -> OSVersion {
9797
}
9898

9999
/// Name of the environment variable used to fetch the deployment target on the given OS.
100-
fn deployment_target_env_var(os: &str) -> &'static str {
100+
pub fn deployment_target_env_var(os: &str) -> &'static str {
101101
match os {
102102
"macos" => "MACOSX_DEPLOYMENT_TARGET",
103103
"ios" => "IPHONEOS_DEPLOYMENT_TARGET",

compiler/rustc_data_structures/src/obligation_forest/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ impl<O: ForestObligation> ObligationForest<O> {
415415
.collect()
416416
}
417417

418+
pub fn has_pending_obligations(&self) -> bool {
419+
self.nodes.iter().any(|node| node.state.get() == NodeState::Pending)
420+
}
421+
418422
fn insert_into_error_cache(&mut self, index: usize) {
419423
let node = &self.nodes[index];
420424
self.error_cache

compiler/rustc_driver_impl/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -867,8 +867,9 @@ fn print_crate_info(
867867
DeploymentTarget => {
868868
if sess.target.is_like_osx {
869869
println_info!(
870-
"deployment_target={}",
871-
apple::pretty_version(apple::deployment_target(sess))
870+
"{}={}",
871+
apple::deployment_target_env_var(&sess.target.os),
872+
apple::pretty_version(apple::deployment_target(sess)),
872873
)
873874
} else {
874875
#[allow(rustc::diagnostic_outside_of_impl)]

compiler/rustc_hir_analysis/messages.ftl

-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ hir_analysis_const_param_ty_impl_on_unsized =
113113
the trait `ConstParamTy` may not be implemented for this type
114114
.label = type is not `Sized`
115115
116-
hir_analysis_const_specialize = cannot specialize on const impl with non-const impl
117-
118116
hir_analysis_copy_impl_on_non_adt =
119117
the trait `Copy` cannot be implemented for this type
120118
.label = type is not a structure or enumeration

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,9 @@ pub fn check_intrinsic_type(
641641
| sym::simd_round
642642
| sym::simd_trunc => (1, 0, vec![param(0)], param(0)),
643643
sym::simd_fpowi => (1, 0, vec![param(0), tcx.types.i32], param(0)),
644-
sym::simd_fma => (1, 0, vec![param(0), param(0), param(0)], param(0)),
644+
sym::simd_fma | sym::simd_relaxed_fma => {
645+
(1, 0, vec![param(0), param(0), param(0)], param(0))
646+
}
645647
sym::simd_gather => (3, 0, vec![param(0), param(1), param(2)], param(0)),
646648
sym::simd_masked_load => (3, 0, vec![param(0), param(1), param(2)], param(2)),
647649
sym::simd_masked_store => (3, 0, vec![param(0), param(1), param(2)], tcx.types.unit),

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -117,13 +117,12 @@ where
117117
}
118118
f(&mut wfcx)?;
119119

120-
let assumed_wf_types = wfcx.ocx.assumed_wf_types_and_report_errors(param_env, body_def_id)?;
121-
122120
let errors = wfcx.select_all_or_error();
123121
if !errors.is_empty() {
124122
return Err(infcx.err_ctxt().report_fulfillment_errors(errors));
125123
}
126124

125+
let assumed_wf_types = wfcx.ocx.assumed_wf_types_and_report_errors(param_env, body_def_id)?;
127126
debug!(?assumed_wf_types);
128127

129128
let infcx_compat = infcx.fork();

compiler/rustc_hir_analysis/src/errors.rs

-7
Original file line numberDiff line numberDiff line change
@@ -1079,13 +1079,6 @@ pub(crate) struct EmptySpecialization {
10791079
pub base_impl_span: Span,
10801080
}
10811081

1082-
#[derive(Diagnostic)]
1083-
#[diag(hir_analysis_const_specialize)]
1084-
pub(crate) struct ConstSpecialize {
1085-
#[primary_span]
1086-
pub span: Span,
1087-
}
1088-
10891082
#[derive(Diagnostic)]
10901083
#[diag(hir_analysis_static_specialize)]
10911084
pub(crate) struct StaticSpecialize {

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

-26
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
//! on traits with methods can.
6767
6868
use rustc_data_structures::fx::FxHashSet;
69-
use rustc_hir as hir;
7069
use rustc_hir::def_id::{DefId, LocalDefId};
7170
use rustc_infer::infer::TyCtxtInferExt;
7271
use rustc_infer::infer::outlives::env::OutlivesEnvironment;
@@ -134,7 +133,6 @@ fn check_always_applicable(
134133
unconstrained_parent_impl_args(tcx, impl2_def_id, impl2_args)
135134
};
136135

137-
res = res.and(check_constness(tcx, impl1_def_id, impl2_node, span));
138136
res = res.and(check_static_lifetimes(tcx, &parent_args, span));
139137
res = res.and(check_duplicate_params(tcx, impl1_args, parent_args, span));
140138
res = res.and(check_predicates(tcx, impl1_def_id, impl1_args, impl2_node, impl2_args, span));
@@ -157,30 +155,6 @@ fn check_has_items(
157155
Ok(())
158156
}
159157

160-
/// Check that the specializing impl `impl1` is at least as const as the base
161-
/// impl `impl2`
162-
fn check_constness(
163-
tcx: TyCtxt<'_>,
164-
impl1_def_id: LocalDefId,
165-
impl2_node: Node,
166-
span: Span,
167-
) -> Result<(), ErrorGuaranteed> {
168-
if impl2_node.is_from_trait() {
169-
// This isn't a specialization
170-
return Ok(());
171-
}
172-
173-
let impl1_constness = tcx.constness(impl1_def_id.to_def_id());
174-
let impl2_constness = tcx.constness(impl2_node.def_id());
175-
176-
if let hir::Constness::Const = impl2_constness {
177-
if let hir::Constness::NotConst = impl1_constness {
178-
return Err(tcx.dcx().emit_err(errors::ConstSpecialize { span }));
179-
}
180-
}
181-
Ok(())
182-
}
183-
184158
/// Given a specializing impl `impl1`, and the base impl `impl2`, returns two
185159
/// generic parameters `(S1, S2)` that equate their trait references.
186160
/// The returned types are expressed in terms of the generics of `impl1`.

compiler/rustc_infer/src/traits/engine.rs

+2
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ pub trait TraitEngine<'tcx, E: 'tcx>: 'tcx {
8484
self.collect_remaining_errors(infcx)
8585
}
8686

87+
fn has_pending_obligations(&self) -> bool;
88+
8789
fn pending_obligations(&self) -> PredicateObligations<'tcx>;
8890

8991
/// Among all pending obligations, collect those are stalled on a inference variable which has

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1844,6 +1844,7 @@ symbols! {
18441844
simd_reduce_mul_unordered,
18451845
simd_reduce_or,
18461846
simd_reduce_xor,
1847+
simd_relaxed_fma,
18471848
simd_rem,
18481849
simd_round,
18491850
simd_saturating_add,

compiler/rustc_trait_selection/src/solve/fulfill.rs

+4
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ where
199199
errors
200200
}
201201

202+
fn has_pending_obligations(&self) -> bool {
203+
!self.obligations.pending.is_empty() || !self.obligations.overflowed.is_empty()
204+
}
205+
202206
fn pending_obligations(&self) -> PredicateObligations<'tcx> {
203207
self.obligations.clone_pending()
204208
}

compiler/rustc_trait_selection/src/traits/fulfill.rs

+4
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ where
213213
}
214214
}
215215

216+
fn has_pending_obligations(&self) -> bool {
217+
self.predicates.has_pending_obligations()
218+
}
219+
216220
fn pending_obligations(&self) -> PredicateObligations<'tcx> {
217221
self.predicates.map_pending_obligations(|o| o.obligation.clone())
218222
}

compiler/rustc_trait_selection/src/traits/normalize.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_infer::traits::{
77
FromSolverError, Normalized, Obligation, PredicateObligations, TraitEngine,
88
};
99
use rustc_macros::extension;
10+
use rustc_middle::span_bug;
1011
use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
1112
use rustc_middle::ty::{
1213
self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitable, TypeVisitableExt,
@@ -63,10 +64,18 @@ impl<'tcx> At<'_, 'tcx> {
6364
if self.infcx.next_trait_solver() {
6465
crate::solve::deeply_normalize(self, value)
6566
} else {
67+
if fulfill_cx.has_pending_obligations() {
68+
let pending_obligations = fulfill_cx.pending_obligations();
69+
span_bug!(
70+
pending_obligations[0].cause.span,
71+
"deeply_normalize should not be called with pending obligations: \
72+
{pending_obligations:#?}"
73+
);
74+
}
6675
let value = self
6776
.normalize(value)
6877
.into_value_registering_obligations(self.infcx, &mut *fulfill_cx);
69-
let errors = fulfill_cx.select_where_possible(self.infcx);
78+
let errors = fulfill_cx.select_all_or_error(self.infcx);
7079
let value = self.infcx.resolve_vars_if_possible(value);
7180
if errors.is_empty() { Ok(value) } else { Err(errors) }
7281
}

compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,16 @@ pub fn compute_implied_outlives_bounds_inner<'tcx>(
5959
param_env: ty::ParamEnv<'tcx>,
6060
ty: Ty<'tcx>,
6161
) -> Result<Vec<OutlivesBound<'tcx>>, NoSolution> {
62-
let normalize_op = |ty| {
63-
let ty = ocx.normalize(&ObligationCause::dummy(), param_env, ty);
62+
let normalize_op = |ty| -> Result<_, NoSolution> {
63+
// We must normalize the type so we can compute the right outlives components.
64+
// for example, if we have some constrained param type like `T: Trait<Out = U>`,
65+
// and we know that `&'a T::Out` is WF, then we want to imply `U: 'a`.
66+
let ty = ocx
67+
.deeply_normalize(&ObligationCause::dummy(), param_env, ty)
68+
.map_err(|_| NoSolution)?;
6469
if !ocx.select_all_or_error().is_empty() {
6570
return Err(NoSolution);
6671
}
67-
let ty = ocx.infcx.resolve_vars_if_possible(ty);
6872
let ty = OpportunisticRegionResolver::new(&ocx.infcx).fold_ty(ty);
6973
Ok(ty)
7074
};

0 commit comments

Comments
 (0)