Skip to content

Commit 1122faa

Browse files
committed
Auto merge of #147175 - Zalathar:rollup-kzpdwu3, r=Zalathar
Rollup of 4 pull requests Successful merges: - #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) r? `@ghost` `@rustbot` modify labels: rollup
2 parents a2db928 + ac86d97 commit 1122faa

File tree

9 files changed

+203
-39
lines changed

9 files changed

+203
-39
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
@@ -2256,8 +2256,11 @@ unsafe extern "C" {
22562256
ConstraintsLen: size_t,
22572257
) -> bool;
22582258

2259+
/// A list of pointer-length strings is passed as two pointer-length slices,
2260+
/// one slice containing pointers and one slice containing their corresponding
2261+
/// lengths. The implementation will check that both slices have the same length.
22592262
pub(crate) fn LLVMRustCoverageWriteFilenamesToBuffer(
2260-
Filenames: *const *const c_char,
2263+
Filenames: *const *const c_uchar, // See "PTR_LEN_STR".
22612264
FilenamesLen: size_t,
22622265
Lengths: *const size_t,
22632266
LengthsLen: size_t,
@@ -2280,18 +2283,25 @@ unsafe extern "C" {
22802283

22812284
pub(crate) fn LLVMRustCoverageCreatePGOFuncNameVar(
22822285
F: &Value,
2283-
FuncName: *const c_char,
2286+
FuncName: *const c_uchar, // See "PTR_LEN_STR".
22842287
FuncNameLen: size_t,
22852288
) -> &Value;
2286-
pub(crate) fn LLVMRustCoverageHashBytes(Bytes: *const c_char, NumBytes: size_t) -> u64;
2289+
pub(crate) fn LLVMRustCoverageHashBytes(
2290+
Bytes: *const c_uchar, // See "PTR_LEN_STR".
2291+
NumBytes: size_t,
2292+
) -> u64;
22872293

2288-
pub(crate) fn LLVMRustCoverageWriteCovmapSectionNameToString(M: &Module, OutStr: &RustString);
2289-
2290-
pub(crate) fn LLVMRustCoverageWriteCovfunSectionNameToString(M: &Module, OutStr: &RustString);
2291-
2292-
pub(crate) fn LLVMRustCoverageWriteCovmapVarNameToString(OutStr: &RustString);
2294+
pub(crate) safe fn LLVMRustCoverageWriteCovmapSectionNameToString(
2295+
M: &Module,
2296+
OutStr: &RustString,
2297+
);
2298+
pub(crate) safe fn LLVMRustCoverageWriteCovfunSectionNameToString(
2299+
M: &Module,
2300+
OutStr: &RustString,
2301+
);
2302+
pub(crate) safe fn LLVMRustCoverageWriteCovmapVarNameToString(OutStr: &RustString);
22932303

2294-
pub(crate) fn LLVMRustCoverageMappingVersion() -> u32;
2304+
pub(crate) safe fn LLVMRustCoverageMappingVersion() -> u32;
22952305
pub(crate) fn LLVMRustDebugMetadataVersion() -> u32;
22962306
pub(crate) fn LLVMRustVersionMajor() -> u32;
22972307
pub(crate) fn LLVMRustVersionMinor() -> u32;

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
}

tests/ui/proc-macro/quote/not-quotable.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ LL | let _ = quote! { $ip };
1515
Cow<'_, T>
1616
Option<T>
1717
Rc<T>
18-
RepInterp<T>
19-
and 25 others
18+
bool
19+
and 24 others
2020

2121
error: aborting due to 1 previous error
2222

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,35 @@
1+
// `Foo` and `Bar` should not be suggested in diagnostics of dependents
2+
13
#[doc(hidden)]
24
pub mod hidden {
35
pub struct Foo;
46
}
57

68
pub mod hidden1 {
79
#[doc(hidden)]
8-
pub struct Foo;
10+
pub struct Bar;
911
}
1012

13+
// `Baz` and `Quux` *should* be suggested in diagnostics of dependents
1114

1215
#[doc(hidden)]
13-
pub(crate) mod hidden2 {
14-
pub struct Bar;
16+
pub mod hidden2 {
17+
pub struct Baz;
18+
}
19+
20+
pub use hidden2::Baz;
21+
22+
#[doc(hidden)]
23+
pub(crate) mod hidden3 {
24+
pub struct Quux;
1525
}
1626

17-
pub use hidden2::Bar;
27+
pub use hidden3::Quux;
28+
29+
pub trait Marker {}
30+
31+
impl Marker for Option<u32> {}
32+
impl Marker for hidden::Foo {}
33+
impl Marker for hidden1::Bar {}
34+
impl Marker for Baz {}
35+
impl Marker for Quux {}
Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ aux-build:hidden-struct.rs
2-
//@ compile-flags: --crate-type lib
32

43
extern crate hidden_struct;
54

@@ -9,7 +8,20 @@ mod local {
98
}
109

1110
pub fn test(_: Foo) {}
12-
//~^ ERROR cannot find type `Foo` in this scope
11+
//~^ ERROR [E0412]
1312

1413
pub fn test2(_: Bar) {}
15-
//~^ ERROR cannot find type `Bar` in this scope
14+
//~^ ERROR [E0412]
15+
16+
pub fn test3(_: Baz) {}
17+
//~^ ERROR [E0412]
18+
19+
pub fn test4(_: Quux) {}
20+
//~^ ERROR [E0412]
21+
22+
fn test5<T: hidden_struct::Marker>() {}
23+
24+
fn main() {
25+
test5::<i32>();
26+
//~^ ERROR [E0277]
27+
}

0 commit comments

Comments
 (0)