Skip to content

Commit bacab30

Browse files
committed
Auto merge of #155933 - JonathanBrouwer:rollup-UBe7V6A, r=JonathanBrouwer
Rollup of 12 pull requests Successful merges: - #151994 (switch to v0 mangling by default on stable) - #154325 (Tweak irrefutable let else warning output) - #155899 (`dlltool`: Set the working directory to workaround `--temp-prefix` bug) - #155273 (Lock stable_crate_ids once in create_crate_num) - #155361 (Document that CFI diverges from Rust wrt. ABI-compatibility rules) - #155692 (disable naked-dead-code-elimination test if no RET mnemonic is available) - #155747 (Update documentation for `wasm32-wali-linux-musl` after integrating n…) - #155768 (compiletest: Overhaul the code for running an incremental test revision) - #155907 (Handle hkl const closures) - #155910 (misc stuff from reading borrowck again :)) - #155913 (Delete the 12 year old fixme) - #155920 (remove review queue triagebot mentions)
2 parents 03c609a + 71ee7fc commit bacab30

48 files changed

Lines changed: 572 additions & 324 deletions

File tree

Some content is hidden

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

compiler/rustc_borrowck/src/handle_placeholders.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,18 @@ pub(crate) struct LoweredConstraints<'tcx> {
3535
pub(crate) placeholder_indices: PlaceholderIndices<'tcx>,
3636
}
3737

38-
impl<'d, 'tcx, A: scc::Annotation> SccAnnotations<'d, 'tcx, A> {
39-
pub(crate) fn init(definitions: &'d IndexVec<RegionVid, RegionDefinition<'tcx>>) -> Self {
40-
Self { scc_to_annotation: IndexVec::new(), definitions }
41-
}
42-
}
43-
4438
/// A Visitor for SCC annotation construction.
4539
pub(crate) struct SccAnnotations<'d, 'tcx, A: scc::Annotation> {
4640
pub(crate) scc_to_annotation: IndexVec<ConstraintSccIndex, A>,
4741
definitions: &'d IndexVec<RegionVid, RegionDefinition<'tcx>>,
4842
}
4943

44+
impl<'d, 'tcx, A: scc::Annotation> SccAnnotations<'d, 'tcx, A> {
45+
pub(crate) fn init(definitions: &'d IndexVec<RegionVid, RegionDefinition<'tcx>>) -> Self {
46+
Self { scc_to_annotation: IndexVec::new(), definitions }
47+
}
48+
}
49+
5050
impl scc::Annotations<RegionVid> for SccAnnotations<'_, '_, RegionTracker> {
5151
fn new(&self, element: RegionVid) -> RegionTracker {
5252
RegionTracker::new(element, &self.definitions[element])
@@ -118,7 +118,7 @@ impl RegionTracker {
118118
}
119119

120120
/// The largest universe this SCC can name. It's the smallest
121-
/// largest nameable universe of any reachable region, or
121+
/// max-nameable-universe of any reachable region, or
122122
/// `max_nameable(r) = min (max_nameable(r') for r' reachable from r)`
123123
pub(crate) fn max_nameable_universe(self) -> UniverseIndex {
124124
self.max_nameable_universe.0
@@ -208,7 +208,7 @@ pub(super) fn region_definitions<'tcx>(
208208
/// graph such that there is a series of constraints
209209
/// A: B: C: ... : X where
210210
/// A contains a placeholder whose universe cannot be named by X,
211-
/// add a constraint that A: 'static. This is a safe upper bound
211+
/// add a constraint that X: 'static. This is a safe upper bound
212212
/// in the face of borrow checker/trait solver limitations that will
213213
/// eventually go away.
214214
///
@@ -327,8 +327,6 @@ pub(crate) fn rewrite_placeholder_outlives<'tcx>(
327327

328328
for scc in sccs.all_sccs() {
329329
// No point in adding 'static: 'static!
330-
// This micro-optimisation makes somewhat sense
331-
// because static outlives *everything*.
332330
if scc == sccs.scc(fr_static) {
333331
continue;
334332
}

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -501,43 +501,48 @@ impl<'tcx> RegionInferenceContext<'tcx> {
501501

502502
let mut errors_buffer = RegionErrors::new(infcx.tcx);
503503

504-
// If this is a closure, we can propagate unsatisfied
505-
// `outlives_requirements` to our creator, so create a vector
506-
// to store those. Otherwise, we'll pass in `None` to the
507-
// functions below, which will trigger them to report errors
508-
// eagerly.
509-
let mut outlives_requirements = infcx.tcx.is_typeck_child(mir_def_id).then(Vec::new);
504+
// If this is a nested body, we propagate unsatisfied
505+
// outlives constraints to the parent body instead of
506+
// eagerly erroing.
507+
let mut propagated_outlives_requirements =
508+
infcx.tcx.is_typeck_child(mir_def_id).then(Vec::new);
510509

511-
self.check_type_tests(infcx, outlives_requirements.as_mut(), &mut errors_buffer);
510+
self.check_type_tests(infcx, propagated_outlives_requirements.as_mut(), &mut errors_buffer);
512511

513512
debug!(?errors_buffer);
514-
debug!(?outlives_requirements);
513+
debug!(?propagated_outlives_requirements);
515514

516515
// In Polonius mode, the errors about missing universal region relations are in the output
517516
// and need to be emitted or propagated. Otherwise, we need to check whether the
518517
// constraints were too strong, and if so, emit or propagate those errors.
519518
if infcx.tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled() {
520519
self.check_polonius_subset_errors(
521-
outlives_requirements.as_mut(),
520+
propagated_outlives_requirements.as_mut(),
522521
&mut errors_buffer,
523522
polonius_output
524523
.as_ref()
525524
.expect("Polonius output is unavailable despite `-Z polonius`"),
526525
);
527526
} else {
528-
self.check_universal_regions(outlives_requirements.as_mut(), &mut errors_buffer);
527+
self.check_universal_regions(
528+
propagated_outlives_requirements.as_mut(),
529+
&mut errors_buffer,
530+
);
529531
}
530532

531533
debug!(?errors_buffer);
532534

533-
let outlives_requirements = outlives_requirements.unwrap_or_default();
535+
let propagated_outlives_requirements = propagated_outlives_requirements.unwrap_or_default();
534536

535-
if outlives_requirements.is_empty() {
537+
if propagated_outlives_requirements.is_empty() {
536538
(None, errors_buffer)
537539
} else {
538540
let num_external_vids = self.universal_regions().num_global_and_external_regions();
539541
(
540-
Some(ClosureRegionRequirements { num_external_vids, outlives_requirements }),
542+
Some(ClosureRegionRequirements {
543+
num_external_vids,
544+
outlives_requirements: propagated_outlives_requirements,
545+
}),
541546
errors_buffer,
542547
)
543548
}

compiler/rustc_codegen_llvm/src/llvm/ffi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2350,6 +2350,7 @@ unsafe extern "C" {
23502350
pub(crate) fn LLVMRustWriteValueToString(value_ref: &Value, s: &RustString);
23512351

23522352
pub(crate) fn LLVMRustHasFeature(T: &TargetMachine, s: *const c_char) -> bool;
2353+
pub(crate) fn LLVMRustTargetHasMnemonic(T: &TargetMachine, s: *const c_char) -> bool;
23532354

23542355
pub(crate) fn LLVMRustPrintTargetCPUs(TM: &TargetMachine, OutStr: &RustString);
23552356
pub(crate) fn LLVMRustGetTargetFeaturesCount(T: &TargetMachine) -> size_t;

compiler/rustc_codegen_llvm/src/llvm_util.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,10 @@ pub(crate) fn print(req: &PrintRequest, out: &mut String, sess: &Session) {
480480
match req.kind {
481481
PrintKind::TargetCPUs => print_target_cpus(sess, tm.raw(), out),
482482
PrintKind::TargetFeatures => print_target_features(sess, tm.raw(), out),
483+
PrintKind::BackendHasMnemonic => {
484+
let mnemonic = req.arg.as_deref().expect("BackendHasMnemonic requires arg");
485+
print_target_has_mnemonic(tm.raw(), mnemonic, out)
486+
}
483487
_ => bug!("rustc_codegen_llvm can't handle print request: {:?}", req),
484488
}
485489
}
@@ -738,3 +742,10 @@ pub(crate) fn tune_cpu(sess: &Session) -> Option<&str> {
738742
let name = sess.opts.unstable_opts.tune_cpu.as_ref()?;
739743
Some(handle_native(name))
740744
}
745+
746+
fn print_target_has_mnemonic(tm: &llvm::TargetMachine, mnemonic: &str, out: &mut String) {
747+
use std::fmt::Write;
748+
let cstr = SmallCStr::new(mnemonic);
749+
let has_mnemonic = unsafe { llvm::LLVMRustTargetHasMnemonic(tm, cstr.as_ptr()) };
750+
writeln!(out, "{}", has_mnemonic).unwrap();
751+
}

compiler/rustc_codegen_ssa/src/back/archive.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,10 @@ fn create_mingw_dll_import_lib(
217217
// able to control the *exact* spelling of each of the symbols that are being imported:
218218
// hence we don't want `dlltool` adding leading underscores automatically.
219219
let dlltool = find_binutils_dlltool(sess);
220-
let temp_prefix = {
221-
let mut path = PathBuf::from(&output_path);
222-
path.pop();
223-
path.push(lib_name);
224-
path
225-
};
220+
// temp_prefix doesn't handle paths with spaces so
221+
// use a relative path and set the current working directory
222+
let cwd = output_path.parent().unwrap_or(output_path);
223+
let temp_prefix = lib_name;
226224
// dlltool target architecture args from:
227225
// https://github.com/llvm/llvm-project-release-prs/blob/llvmorg-15.0.6/llvm/lib/ToolDrivers/llvm-dlltool/DlltoolDriver.cpp#L69
228226
let (dlltool_target_arch, dlltool_target_bitness) = match &sess.target.arch {
@@ -246,7 +244,8 @@ fn create_mingw_dll_import_lib(
246244
.arg(dlltool_target_bitness)
247245
.arg("--no-leading-underscore")
248246
.arg("--temp-prefix")
249-
.arg(temp_prefix);
247+
.arg(temp_prefix)
248+
.current_dir(cwd);
250249

251250
match dlltool_cmd.output() {
252251
Err(e) => {

compiler/rustc_data_structures/src/graph/scc/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ mod tests;
2727
/// the max/min element of the SCC, or all of the above.
2828
///
2929
/// Concretely, the both merge operations must commute, e.g. where `merge`
30-
/// is `update_scc` and `update_reached`: `a.merge(b) == b.merge(a)`
30+
/// is `update_scc` and `update_reachable`: `a.merge(b) == b.merge(a)`
3131
///
3232
/// In general, what you want is probably always min/max according
3333
/// to some ordering, potentially with side constraints (min x such

compiler/rustc_driver_impl/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,6 +804,9 @@ fn print_crate_info(
804804
let calling_conventions = rustc_abi::all_names();
805805
println_info!("{}", calling_conventions.join("\n"));
806806
}
807+
BackendHasMnemonic => {
808+
codegen_backend.print(req, &mut crate_info, sess);
809+
}
807810
BackendHasZstd => {
808811
let has_zstd: bool = codegen_backend.has_zstd();
809812
println_info!("{has_zstd}");

compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "llvm/IR/Verifier.h"
2020
#include "llvm/IRPrinter/IRPrintingPasses.h"
2121
#include "llvm/LTO/LTO.h"
22+
#include "llvm/MC/MCInstrInfo.h"
2223
#include "llvm/MC/MCSubtargetInfo.h"
2324
#include "llvm/MC/TargetRegistry.h"
2425
#include "llvm/Object/ObjectFile.h"
@@ -94,6 +95,25 @@ extern "C" bool LLVMRustHasFeature(LLVMTargetMachineRef TM,
9495
return MCInfo->checkFeatures(std::string("+") + Feature);
9596
}
9697

98+
/// Check whether the target has a specific assembly mnemonic like `ret` or
99+
/// `nop`.
100+
/// This should be fast enough but if its not we have to look into another
101+
/// method of checking.
102+
extern "C" bool LLVMRustTargetHasMnemonic(LLVMTargetMachineRef TM,
103+
const char *Mnemonic) {
104+
TargetMachine *Target = unwrap(TM);
105+
const MCInstrInfo *MII = Target->getMCInstrInfo();
106+
StringRef MnemonicRef(Mnemonic);
107+
108+
for (unsigned i = 0; i < MII->getNumOpcodes(); i++) {
109+
StringRef Name = MII->getName(i);
110+
if (Name.equals_insensitive(MnemonicRef)) {
111+
return true;
112+
}
113+
}
114+
return false;
115+
}
116+
97117
enum class LLVMRustCodeModel {
98118
Tiny,
99119
Small,

compiler/rustc_middle/src/ty/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,12 +1416,12 @@ impl<'tcx> TyCtxt<'tcx> {
14161416
self,
14171417
stable_crate_id: StableCrateId,
14181418
) -> Result<TyCtxtFeed<'tcx, CrateNum>, CrateNum> {
1419-
if let Some(&existing) = self.untracked().stable_crate_ids.read().get(&stable_crate_id) {
1419+
let mut lock = self.untracked().stable_crate_ids.write();
1420+
if let Some(&existing) = lock.get(&stable_crate_id) {
14201421
return Err(existing);
14211422
}
1422-
1423-
let num = CrateNum::new(self.untracked().stable_crate_ids.read().len());
1424-
self.untracked().stable_crate_ids.write().insert(stable_crate_id, num);
1423+
let num = CrateNum::new(lock.len());
1424+
lock.insert(stable_crate_id, num);
14251425
Ok(TyCtxtFeed { key: num, tcx: self })
14261426
}
14271427

compiler/rustc_mir_build/src/errors.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -924,22 +924,24 @@ pub(crate) struct IrrefutableLetPatternsIfLetGuard {
924924
}
925925

926926
#[derive(Diagnostic)]
927-
#[diag(
928-
"irrefutable `let...else` {$count ->
929-
[one] pattern
930-
*[other] patterns
931-
}"
932-
)]
933-
#[note(
934-
"{$count ->
935-
[one] this pattern always matches, so the else clause is unreachable
936-
*[other] these patterns always match, so the else clause is unreachable
937-
}"
938-
)]
927+
#[diag("unreachable `else` clause")]
928+
#[note("this pattern always matches, so the else clause is unreachable")]
939929
pub(crate) struct IrrefutableLetPatternsLetElse {
940-
pub(crate) count: usize,
941-
#[help("remove this `else` block")]
942-
pub(crate) else_span: Option<Span>,
930+
#[subdiagnostic]
931+
pub(crate) be_replaced: Option<LetElseReplacementSuggestion>,
932+
}
933+
934+
#[derive(Subdiagnostic, Debug)]
935+
#[suggestion(
936+
"consider using `let {$lhs} = {$rhs}` to match on a specific variant",
937+
code = "let {lhs} = {rhs}",
938+
applicability = "machine-applicable"
939+
)]
940+
pub(crate) struct LetElseReplacementSuggestion {
941+
#[primary_span]
942+
pub(crate) span: Span,
943+
pub(crate) lhs: String,
944+
pub(crate) rhs: String,
943945
}
944946

945947
#[derive(Diagnostic)]

0 commit comments

Comments
 (0)