Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ae8ab87

Browse files
committed
Auto merge of #138873 - jhpratt:rollup-tggrbxl, r=jhpratt
Rollup of 10 pull requests Successful merges: - #137593 (fix download-llvm logic for subtree sync branches) - #137736 (Don't attempt to export compiler-builtins symbols from rust dylibs) - #138135 (Simplify `PartialOrd` on tuples containing primitives) - #138321 ([bootstrap] Distribute split debuginfo if present) - #138574 (rustdoc: be more strict about "Methods from Deref") - #138606 (Fix missing rustfmt in msi installer - cont) - #138671 (Fix `FileType` `PartialEq` implementation on Windows) - #138728 (Update `compiler-builtins` to 0.1.152) - #138783 (Cache current_dll_path output) - #138846 (Tweaks to writeback and `Obligation -> Goal` conversion) Failed merges: - #138755 ([rustdoc] Remove duplicated loop when computing doc cfgs) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7290b04 + 0e95f96 commit ae8ab87

File tree

34 files changed

+859
-239
lines changed

34 files changed

+859
-239
lines changed

‎compiler/rustc_codegen_cranelift/patches/0029-stdlib-Disable-f16-and-f128-in-compiler-builtins.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ index 7165c3e48af..968552ad435 100644
1616

1717
[dependencies]
1818
core = { path = "../core", public = true }
19-
-compiler_builtins = { version = "=0.1.151", features = ['rustc-dep-of-std'] }
20-
+compiler_builtins = { version = "=0.1.151", features = ['rustc-dep-of-std', 'no-f16-f128'] }
19+
-compiler_builtins = { version = "=0.1.152", features = ['rustc-dep-of-std'] }
20+
+compiler_builtins = { version = "=0.1.152", features = ['rustc-dep-of-std', 'no-f16-f128'] }
2121

2222
[features]
2323
compiler-builtins-mem = ['compiler_builtins/mem']

‎compiler/rustc_codegen_ssa/src/back/linker.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,7 +1782,10 @@ fn exported_symbols_for_non_proc_macro(tcx: TyCtxt<'_>, crate_type: CrateType) -
17821782
let mut symbols = Vec::new();
17831783
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
17841784
for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| {
1785-
if info.level.is_below_threshold(export_threshold) {
1785+
// Do not export mangled symbols from cdylibs and don't attempt to export compiler-builtins
1786+
// from any cdylib. The latter doesn't work anyway as we use hidden visibility for
1787+
// compiler-builtins. Most linkers silently ignore it, but ld64 gives a warning.
1788+
if info.level.is_below_threshold(export_threshold) && !tcx.is_compiler_builtins(cnum) {
17861789
symbols.push(symbol_export::exporting_symbol_name_for_instance_in_crate(
17871790
tcx, symbol, cnum,
17881791
));
@@ -1821,7 +1824,9 @@ pub(crate) fn linked_symbols(
18211824

18221825
let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
18231826
for_each_exported_symbols_include_dep(tcx, crate_type, |symbol, info, cnum| {
1824-
if info.level.is_below_threshold(export_threshold) || info.used {
1827+
if info.level.is_below_threshold(export_threshold) && !tcx.is_compiler_builtins(cnum)
1828+
|| info.used
1829+
{
18251830
symbols.push((
18261831
symbol_export::linking_symbol_name_for_instance_in_crate(tcx, symbol, cnum),
18271832
info.kind,

‎compiler/rustc_hir_typeck/src/fn_ctxt/inspect_obligations.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A utility module to inspect currently ambiguous obligations in the current context.
22
33
use rustc_infer::traits::{self, ObligationCause, PredicateObligations};
4-
use rustc_middle::traits::solve::{Goal,GoalSource};
4+
use rustc_middle::traits::solve::GoalSource;
55
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
66
use rustc_span::Span;
77
use rustc_trait_selection::solve::inspect::{
@@ -85,7 +85,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
8585
root_cause: &obligation.cause,
8686
};
8787

88-
let goal = Goal::new(self.tcx,obligation.param_env, obligation.predicate);
88+
let goal = obligation.as_goal();
8989
self.visit_proof_tree(goal, &mut visitor);
9090
}
9191

‎compiler/rustc_hir_typeck/src/writeback.rs

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,8 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
548548
let fcx_typeck_results = self.fcx.typeck_results.borrow();
549549
assert_eq!(fcx_typeck_results.hir_owner, self.typeck_results.hir_owner);
550550
for (predicate, cause) in &fcx_typeck_results.coroutine_stalled_predicates {
551-
let (predicate, cause) = self.resolve((*predicate, cause.clone()), &cause.span);
551+
let (predicate, cause) =
552+
self.resolve_coroutine_predicate((*predicate, cause.clone()), &cause.span);
552553
self.typeck_results.coroutine_stalled_predicates.insert((predicate, cause));
553554
}
554555
}
@@ -730,7 +731,25 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
730731
T: TypeFoldable<TyCtxt<'tcx>>,
731732
{
732733
let value = self.fcx.resolve_vars_if_possible(value);
733-
let value = value.fold_with(&mut Resolver::new(self.fcx, span, self.body));
734+
let value = value.fold_with(&mut Resolver::new(self.fcx, span, self.body, true));
735+
assert!(!value.has_infer());
736+
737+
// We may have introduced e.g. `ty::Error`, if inference failed, make sure
738+
// to mark the `TypeckResults` as tainted in that case, so that downstream
739+
// users of the typeck results don't produce extra errors, or worse, ICEs.
740+
if let Err(guar) = value.error_reported() {
741+
self.typeck_results.tainted_by_errors = Some(guar);
742+
}
743+
744+
value
745+
}
746+
747+
fn resolve_coroutine_predicate<T>(&mut self, value: T, span: &dyn Locatable) -> T
748+
where
749+
T: TypeFoldable<TyCtxt<'tcx>>,
750+
{
751+
let value = self.fcx.resolve_vars_if_possible(value);
752+
let value = value.fold_with(&mut Resolver::new(self.fcx, span, self.body, false));
734753
assert!(!value.has_infer());
735754

736755
// We may have introduced e.g. `ty::Error`, if inference failed, make sure
@@ -774,8 +793,9 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
774793
fcx: &'cx FnCtxt<'cx, 'tcx>,
775794
span: &'cx dyn Locatable,
776795
body: &'tcx hir::Body<'tcx>,
796+
should_normalize: bool,
777797
) -> Resolver<'cx, 'tcx> {
778-
Resolver { fcx, span, body, should_normalize: fcx.next_trait_solver() }
798+
Resolver { fcx, span, body, should_normalize }
779799
}
780800

781801
fn report_error(&self, p: impl Into<ty::GenericArg<'tcx>>) -> ErrorGuaranteed {
@@ -805,10 +825,9 @@ impl<'cx, 'tcx> Resolver<'cx, 'tcx> {
805825
T: Into<ty::GenericArg<'tcx>> + TypeSuperFoldable<TyCtxt<'tcx>> + Copy,
806826
{
807827
let tcx = self.fcx.tcx;
808-
// We must deeply normalize in the new solver, since later lints
809-
// expect that types that show up in the typeck are fully
810-
// normalized.
811-
let mut value = if self.should_normalize {
828+
// We must deeply normalize in the new solver, since later lints expect
829+
// that types that show up in the typeck are fully normalized.
830+
let mut value = if self.should_normalize && self.fcx.next_trait_solver() {
812831
let body_id = tcx.hir_body_owner_def_id(self.body.id());
813832
let cause = ObligationCause::misc(self.span.to_span(tcx), body_id);
814833
let at = self.fcx.at(&cause, self.fcx.param_env);
@@ -864,20 +883,15 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Resolver<'cx, 'tcx> {
864883
}
865884

866885
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
867-
self.handle_term(ct, ty::Const::outer_exclusive_binder, |tcx, guar| {
868-
ty::Const::new_error(tcx, guar)
869-
})
870-
.super_fold_with(self)
886+
self.handle_term(ct, ty::Const::outer_exclusive_binder, ty::Const::new_error)
871887
}
872888

873889
fn fold_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ty::Predicate<'tcx> {
874-
// Do not normalize predicates in the new solver. The new solver is
875-
// supposed to handle unnormalized predicates and incorrectly normalizing
876-
// them can be unsound, e.g. for `WellFormed` predicates.
877-
let prev = mem::replace(&mut self.should_normalize, false);
878-
let predicate = predicate.super_fold_with(self);
879-
self.should_normalize = prev;
880-
predicate
890+
assert!(
891+
!self.should_normalize,
892+
"normalizing predicates in writeback is not generally sound"
893+
);
894+
predicate.super_fold_with(self)
881895
}
882896
}
883897

‎compiler/rustc_infer/src/infer/opaque_types/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ impl<'tcx> InferCtxt<'tcx> {
246246
.eq(DefineOpaqueTypes::Yes, prev, hidden_ty)?
247247
.obligations
248248
.into_iter()
249-
// FIXME: Shuttling between obligations and goals is awkward.
250-
.map(Goal::from),
249+
.map(|obligation| obligation.as_goal()),
251250
);
252251
}
253252
}

‎compiler/rustc_infer/src/traits/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ pub struct Obligation<'tcx, T> {
5454
pub recursion_depth: usize,
5555
}
5656

57+
impl<'tcx, T: Copy> Obligation<'tcx, T> {
58+
pub fn as_goal(&self) -> solve::Goal<'tcx, T> {
59+
solve::Goal { param_env: self.param_env, predicate: self.predicate }
60+
}
61+
}
62+
5763
impl<'tcx, T: PartialEq> PartialEq<Obligation<'tcx, T>> for Obligation<'tcx, T> {
5864
#[inline]
5965
fn eq(&self, other: &Obligation<'tcx, T>) -> bool {
@@ -75,12 +81,6 @@ impl<T: Hash> Hash for Obligation<'_, T> {
7581
}
7682
}
7783

78-
impl<'tcx, P> From<Obligation<'tcx, P>> for solve::Goal<'tcx, P> {
79-
fn from(value: Obligation<'tcx, P>) -> Self {
80-
solve::Goal { param_env: value.param_env, predicate: value.predicate }
81-
}
82-
}
83-
8484
pub type PredicateObligation<'tcx> = Obligation<'tcx, ty::Predicate<'tcx>>;
8585
pub type TraitObligation<'tcx> = Obligation<'tcx, ty::TraitPredicate<'tcx>>;
8686
pub type PolyTraitObligation<'tcx> = Obligation<'tcx, ty::PolyTraitPredicate<'tcx>>;

‎compiler/rustc_session/src/filesearch.rs

Lines changed: 66 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -60,66 +60,76 @@ pub fn make_target_bin_path(sysroot: &Path, target_triple: &str) -> PathBuf {
6060

6161
#[cfg(unix)]
6262
fn current_dll_path() -> Result<PathBuf, String> {
63-
use std::ffi::{CStr, OsStr};
64-
use std::os::unix::prelude::*;
65-
66-
#[cfg(not(target_os = "aix"))]
67-
unsafe {
68-
let addr = current_dll_path as usize as *mut _;
69-
let mut info = std::mem::zeroed();
70-
if libc::dladdr(addr, &mut info) == 0 {
71-
return Err("dladdr failed".into());
72-
}
73-
if info.dli_fname.is_null() {
74-
return Err("dladdr returned null pointer".into());
75-
}
76-
let bytes = CStr::from_ptr(info.dli_fname).to_bytes();
77-
let os = OsStr::from_bytes(bytes);
78-
Ok(PathBuf::from(os))
79-
}
80-
81-
#[cfg(target_os = "aix")]
82-
unsafe {
83-
// On AIX, the symbol `current_dll_path` references a function descriptor.
84-
// A function descriptor is consisted of (See https://reviews.llvm.org/D62532)
85-
// * The address of the entry point of the function.
86-
// * The TOC base address for the function.
87-
// * The environment pointer.
88-
// The function descriptor is in the data section.
89-
let addr = current_dll_path as u64;
90-
let mut buffer = vec![std::mem::zeroed::<libc::ld_info>(); 64];
91-
loop {
92-
if libc::loadquery(
93-
libc::L_GETINFO,
94-
buffer.as_mut_ptr() as *mut u8,
95-
(size_of::<libc::ld_info>() * buffer.len()) as u32,
96-
) >= 0
97-
{
98-
break;
99-
} else {
100-
if std::io::Error::last_os_error().raw_os_error().unwrap() != libc::ENOMEM {
101-
return Err("loadquery failed".into());
63+
use std::sync::OnceLock;
64+
65+
// This is somewhat expensive relative to other work when compiling `fn main() {}` as `dladdr`
66+
// needs to iterate over the symbol table of librustc_driver.so until it finds a match.
67+
// As such cache this to avoid recomputing if we try to get the sysroot in multiple places.
68+
static CURRENT_DLL_PATH: OnceLock<Result<PathBuf, String>> = OnceLock::new();
69+
CURRENT_DLL_PATH
70+
.get_or_init(|| {
71+
use std::ffi::{CStr, OsStr};
72+
use std::os::unix::prelude::*;
73+
74+
#[cfg(not(target_os = "aix"))]
75+
unsafe {
76+
let addr = current_dll_path as usize as *mut _;
77+
let mut info = std::mem::zeroed();
78+
if libc::dladdr(addr, &mut info) == 0 {
79+
return Err("dladdr failed".into());
10280
}
103-
buffer.resize(buffer.len() * 2, std::mem::zeroed::<libc::ld_info>());
104-
}
105-
}
106-
let mut current = buffer.as_mut_ptr() as *mut libc::ld_info;
107-
loop {
108-
let data_base = (*current).ldinfo_dataorg as u64;
109-
let data_end = data_base + (*current).ldinfo_datasize;
110-
if (data_base..data_end).contains(&addr) {
111-
let bytes = CStr::from_ptr(&(*current).ldinfo_filename[0]).to_bytes();
81+
if info.dli_fname.is_null() {
82+
return Err("dladdr returned null pointer".into());
83+
}
84+
let bytes = CStr::from_ptr(info.dli_fname).to_bytes();
11285
let os = OsStr::from_bytes(bytes);
113-
returnOk(PathBuf::from(os));
86+
Ok(PathBuf::from(os))
11487
}
115-
if (*current).ldinfo_next == 0 {
116-
break;
88+
89+
#[cfg(target_os = "aix")]
90+
unsafe {
91+
// On AIX, the symbol `current_dll_path` references a function descriptor.
92+
// A function descriptor is consisted of (See https://reviews.llvm.org/D62532)
93+
// * The address of the entry point of the function.
94+
// * The TOC base address for the function.
95+
// * The environment pointer.
96+
// The function descriptor is in the data section.
97+
let addr = current_dll_path as u64;
98+
let mut buffer = vec![std::mem::zeroed::<libc::ld_info>(); 64];
99+
loop {
100+
if libc::loadquery(
101+
libc::L_GETINFO,
102+
buffer.as_mut_ptr() as *mut u8,
103+
(size_of::<libc::ld_info>() * buffer.len()) as u32,
104+
) >= 0
105+
{
106+
break;
107+
} else {
108+
if std::io::Error::last_os_error().raw_os_error().unwrap() != libc::ENOMEM {
109+
return Err("loadquery failed".into());
110+
}
111+
buffer.resize(buffer.len() * 2, std::mem::zeroed::<libc::ld_info>());
112+
}
113+
}
114+
let mut current = buffer.as_mut_ptr() as *mut libc::ld_info;
115+
loop {
116+
let data_base = (*current).ldinfo_dataorg as u64;
117+
let data_end = data_base + (*current).ldinfo_datasize;
118+
if (data_base..data_end).contains(&addr) {
119+
let bytes = CStr::from_ptr(&(*current).ldinfo_filename[0]).to_bytes();
120+
let os = OsStr::from_bytes(bytes);
121+
return Ok(PathBuf::from(os));
122+
}
123+
if (*current).ldinfo_next == 0 {
124+
break;
125+
}
126+
current = (current as *mut i8).offset((*current).ldinfo_next as isize)
127+
as *mut libc::ld_info;
128+
}
129+
return Err(format!("current dll's address {} is not in the load map", addr));
117130
}
118-
current =
119-
(current as *mut i8).offset((*current).ldinfo_next as isize) as *mut libc::ld_info;
120-
}
121-
return Err(format!("current dll's address {} is not in the load map", addr));
122-
}
131+
})
132+
.clone()
123133
}
124134

125135
#[cfg(windows)]

‎compiler/rustc_trait_selection/src/solve/delegate.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'tcx> rustc_next_trait_solver::delegate::SolverDelegate for SolverDelegate<
9696
) -> Option<Vec<Goal<'tcx, ty::Predicate<'tcx>>>> {
9797
crate::traits::wf::unnormalized_obligations(&self.0, param_env, arg, DUMMY_SP, CRATE_DEF_ID)
9898
.map(|obligations| {
99-
obligations.into_iter().map(|obligation| obligation.into()).collect()
99+
obligations.into_iter().map(|obligation| obligation.as_goal()).collect()
100100
})
101101
}
102102

‎compiler/rustc_trait_selection/src/solve/fulfill.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl<'tcx> ObligationStorage<'tcx> {
8080
// change.
8181
// FIXME: <https://github.com/Gankra/thin-vec/pull/66> is merged, this can be removed.
8282
self.overflowed.extend(ExtractIf::new(&mut self.pending, |o| {
83-
let goal = o.clone().into();
83+
let goal = o.as_goal();
8484
let result = <&SolverDelegate<'tcx>>::from(infcx)
8585
.evaluate_root_goal(goal, GenerateProofTree::No, o.cause.span)
8686
.0;
@@ -161,7 +161,7 @@ where
161161

162162
let mut has_changed = false;
163163
for obligation in self.obligations.unstalled_for_select() {
164-
let goal = obligation.clone().into();
164+
let goal = obligation.as_goal();
165165
let result = <&SolverDelegate<'tcx>>::from(infcx)
166166
.evaluate_root_goal(goal, GenerateProofTree::No, obligation.cause.span)
167167
.0;

‎compiler/rustc_trait_selection/src/solve/fulfill/derive_errors.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::ty::error::{ExpectedFound, TypeError};
1010
use rustc_middle::ty::{self, Ty, TyCtxt};
1111
use rustc_middle::{bug, span_bug};
1212
use rustc_next_trait_solver::solve::{GenerateProofTree, SolverDelegateEvalExt as _};
13-
use rustc_type_ir::solve::{Goal,NoSolution};
13+
use rustc_type_ir::solve::NoSolution;
1414
use tracing::{instrument, trace};
1515

1616
use crate::solve::Certainty;
@@ -89,7 +89,7 @@ pub(super) fn fulfillment_error_for_stalled<'tcx>(
8989
let (code, refine_obligation) = infcx.probe(|_| {
9090
match <&SolverDelegate<'tcx>>::from(infcx)
9191
.evaluate_root_goal(
92-
root_obligation.clone().into(),
92+
root_obligation.as_goal(),
9393
GenerateProofTree::No,
9494
root_obligation.cause.span,
9595
)
@@ -155,7 +155,7 @@ fn find_best_leaf_obligation<'tcx>(
155155
.fudge_inference_if_ok(|| {
156156
infcx
157157
.visit_proof_tree(
158-
obligation.clone().into(),
158+
obligation.as_goal(),
159159
&mut BestObligation { obligation: obligation.clone(), consider_ambiguities },
160160
)
161161
.break_value()
@@ -245,7 +245,7 @@ impl<'tcx> BestObligation<'tcx> {
245245
{
246246
let nested_goal = candidate.instantiate_proof_tree_for_nested_goal(
247247
GoalSource::Misc,
248-
Goal::new(infcx.tcx,obligation.param_env, obligation.predicate),
248+
obligation.as_goal(),
249249
self.span(),
250250
);
251251
// Skip nested goals that aren't the *reason* for our goal's failure.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /