Skip to content

Commit 1e1a394

Browse files
committed
Auto merge of #147198 - matthiaskrgr:rollup-b0ryvvu, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #143069 (Add fast-path for accessing the current thread id) - #146518 (Improve the documentation around `ZERO_AR_DATE`) - #146596 (Add a dummy codegen backend) - #146617 (Don’t suggest foreign `doc(hidden)` types in "the following other types implement trait" diagnostics) - #146635 (cg_llvm: Stop using `as_c_char_ptr` for coverage-related bindings) - #147184 (Fix the bevy implied bounds hack for the next solver) r? `@ghost` `@rustbot` modify labels: rollup
2 parents fa3155a + 598ba1f commit 1e1a394

File tree

14 files changed

+243
-45
lines changed

14 files changed

+243
-45
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/llvm_cov.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,25 @@
22
33
use std::ffi::CString;
44

5-
use crate::common::AsCCharPtr;
65
use crate::coverageinfo::ffi;
76
use crate::llvm;
87

98
pub(crate) fn covmap_var_name() -> CString {
10-
CString::new(llvm::build_byte_buffer(|s| unsafe {
9+
CString::new(llvm::build_byte_buffer(|s| {
1110
llvm::LLVMRustCoverageWriteCovmapVarNameToString(s);
1211
}))
1312
.expect("covmap variable name should not contain NUL")
1413
}
1514

1615
pub(crate) fn covmap_section_name(llmod: &llvm::Module) -> CString {
17-
CString::new(llvm::build_byte_buffer(|s| unsafe {
16+
CString::new(llvm::build_byte_buffer(|s| {
1817
llvm::LLVMRustCoverageWriteCovmapSectionNameToString(llmod, s);
1918
}))
2019
.expect("covmap section name should not contain NUL")
2120
}
2221

2322
pub(crate) fn covfun_section_name(llmod: &llvm::Module) -> CString {
24-
CString::new(llvm::build_byte_buffer(|s| unsafe {
23+
CString::new(llvm::build_byte_buffer(|s| {
2524
llvm::LLVMRustCoverageWriteCovfunSectionNameToString(llmod, s);
2625
}))
2726
.expect("covfun section name should not contain NUL")
@@ -34,7 +33,7 @@ pub(crate) fn create_pgo_func_name_var<'ll>(
3433
unsafe {
3534
llvm::LLVMRustCoverageCreatePGOFuncNameVar(
3635
llfn,
37-
mangled_fn_name.as_c_char_ptr(),
36+
mangled_fn_name.as_ptr(),
3837
mangled_fn_name.len(),
3938
)
4039
}
@@ -44,7 +43,7 @@ pub(crate) fn write_filenames_to_buffer(filenames: &[impl AsRef<str>]) -> Vec<u8
4443
let (pointers, lengths) = filenames
4544
.into_iter()
4645
.map(AsRef::as_ref)
47-
.map(|s: &str| (s.as_c_char_ptr(), s.len()))
46+
.map(|s: &str| (s.as_ptr(), s.len()))
4847
.unzip::<_, _, Vec<_>, Vec<_>>();
4948

5049
llvm::build_byte_buffer(|buffer| unsafe {
@@ -89,12 +88,12 @@ pub(crate) fn write_function_mappings_to_buffer(
8988
/// Hashes some bytes into a 64-bit hash, via LLVM's `IndexedInstrProf::ComputeHash`,
9089
/// as required for parts of the LLVM coverage mapping format.
9190
pub(crate) fn hash_bytes(bytes: &[u8]) -> u64 {
92-
unsafe { llvm::LLVMRustCoverageHashBytes(bytes.as_c_char_ptr(), bytes.len()) }
91+
unsafe { llvm::LLVMRustCoverageHashBytes(bytes.as_ptr(), bytes.len()) }
9392
}
9493

9594
/// Returns LLVM's `coverage::CovMapVersion::CurrentVersion` (CoverageMapping.h)
9695
/// as a raw numeric value. For historical reasons, the numeric value is 1 less
9796
/// than the number in the version's name, so `Version7` is actually `6u32`.
9897
pub(crate) fn mapping_version() -> u32 {
99-
unsafe { llvm::LLVMRustCoverageMappingVersion() }
98+
llvm::LLVMRustCoverageMappingVersion()
10099
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2226,8 +2226,11 @@ unsafe extern "C" {
22262226
ConstraintsLen: size_t,
22272227
) -> bool;
22282228

2229+
/// A list of pointer-length strings is passed as two pointer-length slices,
2230+
/// one slice containing pointers and one slice containing their corresponding
2231+
/// lengths. The implementation will check that both slices have the same length.
22292232
pub(crate) fn LLVMRustCoverageWriteFilenamesToBuffer(
2230-
Filenames: *const *const c_char,
2233+
Filenames: *const *const c_uchar, // See "PTR_LEN_STR".
22312234
FilenamesLen: size_t,
22322235
Lengths: *const size_t,
22332236
LengthsLen: size_t,
@@ -2250,18 +2253,25 @@ unsafe extern "C" {
22502253

22512254
pub(crate) fn LLVMRustCoverageCreatePGOFuncNameVar(
22522255
F: &Value,
2253-
FuncName: *const c_char,
2256+
FuncName: *const c_uchar, // See "PTR_LEN_STR".
22542257
FuncNameLen: size_t,
22552258
) -> &Value;
2256-
pub(crate) fn LLVMRustCoverageHashBytes(Bytes: *const c_char, NumBytes: size_t) -> u64;
2259+
pub(crate) fn LLVMRustCoverageHashBytes(
2260+
Bytes: *const c_uchar, // See "PTR_LEN_STR".
2261+
NumBytes: size_t,
2262+
) -> u64;
22572263

2258-
pub(crate) fn LLVMRustCoverageWriteCovmapSectionNameToString(M: &Module, OutStr: &RustString);
2259-
2260-
pub(crate) fn LLVMRustCoverageWriteCovfunSectionNameToString(M: &Module, OutStr: &RustString);
2261-
2262-
pub(crate) fn LLVMRustCoverageWriteCovmapVarNameToString(OutStr: &RustString);
2264+
pub(crate) safe fn LLVMRustCoverageWriteCovmapSectionNameToString(
2265+
M: &Module,
2266+
OutStr: &RustString,
2267+
);
2268+
pub(crate) safe fn LLVMRustCoverageWriteCovfunSectionNameToString(
2269+
M: &Module,
2270+
OutStr: &RustString,
2271+
);
2272+
pub(crate) safe fn LLVMRustCoverageWriteCovmapVarNameToString(OutStr: &RustString);
22632273

2264-
pub(crate) fn LLVMRustCoverageMappingVersion() -> u32;
2274+
pub(crate) safe fn LLVMRustCoverageMappingVersion() -> u32;
22652275
pub(crate) fn LLVMRustDebugMetadataVersion() -> u32;
22662276
pub(crate) fn LLVMRustVersionMajor() -> u32;
22672277
pub(crate) fn LLVMRustVersionMinor() -> u32;

compiler/rustc_infer/src/infer/outlives/obligations.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ impl<'tcx> InferCtxt<'tcx> {
170170
std::mem::take(&mut self.inner.borrow_mut().region_obligations)
171171
}
172172

173+
pub fn clone_registered_region_obligations(&self) -> Vec<TypeOutlivesConstraint<'tcx>> {
174+
self.inner.borrow().region_obligations.clone()
175+
}
176+
173177
pub fn register_region_assumption(&self, assumption: ty::ArgOutlivesPredicate<'tcx>) {
174178
let mut inner = self.inner.borrow_mut();
175179
inner.undo_log.push(UndoLog::PushRegionAssumption);

compiler/rustc_interface/src/util.rs

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::any::Any;
12
use std::env::consts::{DLL_PREFIX, DLL_SUFFIX};
23
use std::path::{Path, PathBuf};
34
use std::sync::atomic::{AtomicBool, Ordering};
@@ -6,13 +7,20 @@ use std::{env, thread};
67

78
use rustc_ast as ast;
89
use rustc_attr_parsing::{ShouldEmit, validate_attr};
10+
use rustc_codegen_ssa::back::archive::ArArchiveBuilderBuilder;
11+
use rustc_codegen_ssa::back::link::link_binary;
912
use rustc_codegen_ssa::traits::CodegenBackend;
13+
use rustc_codegen_ssa::{CodegenResults, CrateInfo};
14+
use rustc_data_structures::fx::FxIndexMap;
1015
use rustc_data_structures::jobserver::Proxy;
1116
use rustc_data_structures::sync;
1217
use rustc_errors::LintBuffer;
13-
use rustc_metadata::{DylibError, load_symbol_from_dylib};
14-
use rustc_middle::ty::CurrentGcx;
15-
use rustc_session::config::{Cfg, OutFileName, OutputFilenames, OutputTypes, Sysroot, host_tuple};
18+
use rustc_metadata::{DylibError, EncodedMetadata, load_symbol_from_dylib};
19+
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
20+
use rustc_middle::ty::{CurrentGcx, TyCtxt};
21+
use rustc_session::config::{
22+
Cfg, CrateType, OutFileName, OutputFilenames, OutputTypes, Sysroot, host_tuple,
23+
};
1624
use rustc_session::output::{CRATE_TYPES, categorize_crate_type};
1725
use rustc_session::{EarlyDiagCtxt, Session, filesearch, lint};
1826
use rustc_span::edit_distance::find_best_match_for_name;
@@ -316,12 +324,13 @@ pub fn get_codegen_backend(
316324
let backend = backend_name
317325
.or(target.default_codegen_backend.as_deref())
318326
.or(option_env!("CFG_DEFAULT_CODEGEN_BACKEND"))
319-
.unwrap_or("llvm");
327+
.unwrap_or("dummy");
320328

321329
match backend {
322330
filename if filename.contains('.') => {
323331
load_backend_from_dylib(early_dcx, filename.as_ref())
324332
}
333+
"dummy" => || Box::new(DummyCodegenBackend),
325334
#[cfg(feature = "llvm")]
326335
"llvm" => rustc_codegen_llvm::LlvmCodegenBackend::new,
327336
backend_name => get_codegen_sysroot(early_dcx, sysroot, backend_name),
@@ -334,6 +343,63 @@ pub fn get_codegen_backend(
334343
unsafe { load() }
335344
}
336345

346+
struct DummyCodegenBackend;
347+
348+
impl CodegenBackend for DummyCodegenBackend {
349+
fn locale_resource(&self) -> &'static str {
350+
""
351+
}
352+
353+
fn name(&self) -> &'static str {
354+
"dummy"
355+
}
356+
357+
fn codegen_crate<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Box<dyn Any> {
358+
Box::new(CodegenResults {
359+
modules: vec![],
360+
allocator_module: None,
361+
crate_info: CrateInfo::new(tcx, String::new()),
362+
})
363+
}
364+
365+
fn join_codegen(
366+
&self,
367+
ongoing_codegen: Box<dyn Any>,
368+
_sess: &Session,
369+
_outputs: &OutputFilenames,
370+
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
371+
(*ongoing_codegen.downcast().unwrap(), FxIndexMap::default())
372+
}
373+
374+
fn link(
375+
&self,
376+
sess: &Session,
377+
codegen_results: CodegenResults,
378+
metadata: EncodedMetadata,
379+
outputs: &OutputFilenames,
380+
) {
381+
// JUSTIFICATION: TyCtxt no longer available here
382+
#[allow(rustc::bad_opt_access)]
383+
if sess.opts.crate_types.iter().any(|&crate_type| crate_type != CrateType::Rlib) {
384+
#[allow(rustc::untranslatable_diagnostic)]
385+
#[allow(rustc::diagnostic_outside_of_impl)]
386+
sess.dcx().fatal(format!(
387+
"crate type {} not supported by the dummy codegen backend",
388+
sess.opts.crate_types[0],
389+
));
390+
}
391+
392+
link_binary(
393+
sess,
394+
&ArArchiveBuilderBuilder,
395+
codegen_results,
396+
metadata,
397+
outputs,
398+
self.name(),
399+
);
400+
}
401+
}
402+
337403
// This is used for rustdoc, but it uses similar machinery to codegen backend
338404
// loading, so we leave the code here. It is potentially useful for other tools
339405
// that want to invoke the rustc binary while linking to rustc as well.

compiler/rustc_target/src/spec/base/apple/mod.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,22 @@ pub(crate) fn base(
158158
SplitDebuginfo::Off,
159159
]),
160160

161+
// Tell the linker that we would like it to avoid irreproducible binaries.
162+
//
161163
// This environment variable is pretty magical but is intended for
162164
// producing deterministic builds. This was first discovered to be used
163165
// by the `ar` tool as a way to control whether or not mtime entries in
164-
// the archive headers were set to zero or not. It appears that
165-
// eventually the linker got updated to do the same thing and now reads
166-
// this environment variable too in recent versions.
166+
// the archive headers were set to zero or not.
167+
//
168+
// In `ld64-351.8`, shipped with Xcode 9.3, the linker was updated to
169+
// read this flag too. Linker versions that don't support this flag
170+
// may embed modification timestamps in binaries (especially in debug
171+
// information).
172+
//
173+
// A cleaner alternative would be to pass the `-reproducible` flag,
174+
// though that is only supported since `ld64-819.6` shipped with Xcode
175+
// 14, which is too new for our minimum supported version:
176+
// https://doc.rust-lang.org/rustc/platform-support/apple-darwin.html#host-tooling
167177
//
168178
// For some more info see the commentary on #47086
169179
link_env: Cow::Borrowed(&[(Cow::Borrowed("ZERO_AR_DATE"), Cow::Borrowed("1"))]),

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,7 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
18971897
other: bool,
18981898
param_env: ty::ParamEnv<'tcx>,
18991899
) -> bool {
1900+
let parent_map = self.tcx.visible_parent_map(());
19001901
let alternative_candidates = |def_id: DefId| {
19011902
let mut impl_candidates: Vec<_> = self
19021903
.tcx
@@ -1921,7 +1922,21 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
19211922
// FIXME(compiler-errors): This could be generalized, both to
19221923
// be more granular, and probably look past other `#[fundamental]`
19231924
// types, too.
1924-
self.tcx.visibility(def.did()).is_accessible_from(body_def_id, self.tcx)
1925+
let mut did = def.did();
1926+
if self.tcx.visibility(did).is_accessible_from(body_def_id, self.tcx) {
1927+
// don't suggest foreign `#[doc(hidden)]` types
1928+
if !did.is_local() {
1929+
while let Some(parent) = parent_map.get(&did) {
1930+
if self.tcx.is_doc_hidden(did) {
1931+
return false;
1932+
}
1933+
did = *parent;
1934+
}
1935+
}
1936+
true
1937+
} else {
1938+
false
1939+
}
19251940
} else {
19261941
true
19271942
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ pub fn compute_implied_outlives_bounds_inner<'tcx>(
5555
span: Span,
5656
disable_implied_bounds_hack: bool,
5757
) -> Result<Vec<OutlivesBound<'tcx>>, NoSolution> {
58+
// Inside mir borrowck, each computation starts with an empty list.
59+
assert!(
60+
ocx.infcx.inner.borrow().region_obligations().is_empty(),
61+
"compute_implied_outlives_bounds assumes region obligations are empty before starting"
62+
);
63+
5864
let normalize_ty = |ty| -> Result<_, NoSolution> {
5965
// We must normalize the type so we can compute the right outlives components.
6066
// for example, if we have some constrained param type like `T: Trait<Out = U>`,
@@ -143,7 +149,7 @@ pub fn compute_implied_outlives_bounds_inner<'tcx>(
143149
&& ty.visit_with(&mut ContainsBevyParamSet { tcx: ocx.infcx.tcx }).is_break()
144150
{
145151
for TypeOutlivesConstraint { sup_type, sub_region, .. } in
146-
ocx.infcx.take_registered_region_obligations()
152+
ocx.infcx.clone_registered_region_obligations()
147153
{
148154
let mut components = smallvec![];
149155
push_outlives_components(ocx.infcx.tcx, sup_type, &mut components);

library/std/src/thread/current.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,32 @@ pub(super) fn set_current(thread: Thread) -> Result<(), Thread> {
133133
Ok(())
134134
}
135135

136-
/// Gets the id of the thread that invokes it.
136+
/// Gets the unique identifier of the thread which invokes it.
137+
///
138+
/// Calling this function may be more efficient than accessing the current
139+
/// thread id through the current thread handle. i.e. `thread::current().id()`.
137140
///
138141
/// This function will always succeed, will always return the same value for
139142
/// one thread and is guaranteed not to call the global allocator.
143+
///
144+
/// # Examples
145+
///
146+
/// ```
147+
/// #![feature(current_thread_id)]
148+
///
149+
/// use std::thread;
150+
///
151+
/// let other_thread = thread::spawn(|| {
152+
/// thread::current_id()
153+
/// });
154+
///
155+
/// let other_thread_id = other_thread.join().unwrap();
156+
/// assert_ne!(thread::current_id(), other_thread_id);
157+
/// ```
140158
#[inline]
141-
pub(crate) fn current_id() -> ThreadId {
159+
#[must_use]
160+
#[unstable(feature = "current_thread_id", issue = "147194")]
161+
pub fn current_id() -> ThreadId {
142162
// If accessing the persistent thread ID takes multiple TLS accesses, try
143163
// to retrieve it from the current thread handle, which will only take one
144164
// TLS access.

library/std/src/thread/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ mod current;
183183

184184
#[stable(feature = "rust1", since = "1.0.0")]
185185
pub use current::current;
186-
pub(crate) use current::{current_id, current_or_unnamed, current_os_id, drop_current};
186+
#[unstable(feature = "current_thread_id", issue = "147194")]
187+
pub use current::current_id;
188+
pub(crate) use current::{current_or_unnamed, current_os_id, drop_current};
187189
use current::{set_current, try_with_current};
188190

189191
mod spawnhook;

tests/ui/implied-bounds/bevy_world_query.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
#![crate_name = "bevy_ecs"]
2-
31
//@ check-pass
2+
//@ revisions: current next
3+
//@ ignore-compare-mode-next-solver (explicit revisions)
4+
//@[next] compile-flags: -Znext-solver
5+
#![crate_name = "bevy_ecs"]
46

57
// We currently special case bevy from erroring on incorrect implied bounds
68
// from normalization (issue #109628).

0 commit comments

Comments
 (0)