Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #130530

Closed
wants to merge 25 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
363addc
Gate repr(Rust) correctly on non-ADT items
compiler-errors Aug 22, 2024
6b0fc97
Win: Open dir for sync access in remove_dir_all
ChrisDenton Sep 3, 2024
d0a2ca4
Implement ACP 429: add `Lazy{Cell,Lock}::get[_mut]` and `force_mut`
ChayimFriedman2 Aug 20, 2024
0fa92b4
add `Thread::{into_raw, from_raw}`
ibraheemdev Jul 12, 2022
3ecf8e9
Update the minimum external LLVM to 18
cuviper Sep 17, 2024
96a3b48
Clarify docs for std::fs::File::write
shekhirin Sep 18, 2024
69350a4
Revert "Add a hack to prevent proc_macro misopt in CI"
cuviper Sep 18, 2024
a18564c
[Clippy] Swap `manual_retain` to use diagnostic items instead of paths
GnomedDev Sep 18, 2024
bd8e88f
Do not ICE with incorrect empty suggestion
estebank Jul 19, 2024
682c5f4
Explicitly mark a hack as a HACK and elaborate its comment
fmease Sep 18, 2024
d9cdb71
library: Destabilize Lazy{Cell,Lock}::{force,deref}_mut
workingjubilee Sep 17, 2024
f22797d
library: Call it really_init_mut to avoid name collisions
workingjubilee Sep 18, 2024
0cf89b5
compiler: Use make_indirect for the wasm ABI
workingjubilee Sep 16, 2024
a800d1c
compiler: s/make_indirect_byval/pass_by_stack_offset/
workingjubilee Sep 16, 2024
b75711d
tests: Remove test for wrong wasm codegen
workingjubilee Sep 16, 2024
51718e8
tests: Move wasm32 to transparent-opaque-ptr.rs test
workingjubilee Sep 17, 2024
8d52ab1
Rollup merge of #97524 - ibraheemdev:thread-raw, r=ibraheemdev
workingjubilee Sep 18, 2024
1fa684f
Rollup merge of #127988 - estebank:dupe-derive-params, r=fmease
workingjubilee Sep 18, 2024
31e64b3
Rollup merge of #129422 - compiler-errors:repr-rust, r=fmease
workingjubilee Sep 18, 2024
c83e1f6
Rollup merge of #129934 - ChrisDenton:remove-dir-all3, r=Amanieu
workingjubilee Sep 18, 2024
3edd952
Rollup merge of #130450 - workingjubilee:these-names-are-indirect, r=…
workingjubilee Sep 18, 2024
89610c0
Rollup merge of #130476 - workingjubilee:more-lazy-methods-take-2, r=…
workingjubilee Sep 18, 2024
66df252
Rollup merge of #130487 - cuviper:min-llvm-18, r=nikic
workingjubilee Sep 18, 2024
f0dc481
Rollup merge of #130513 - shekhirin:fs-write-doc-comment, r=cuviper
workingjubilee Sep 18, 2024
457c91c
Rollup merge of #130522 - GnomedDev:clippy-manual-retain-paths, r=com…
workingjubilee Sep 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions compiler/rustc_codegen_llvm/src/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,9 +465,7 @@ impl<'ll, 'tcx> FnAbiLlvmExt<'ll, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
cx.type_array(cx.type_i8(), self.ret.layout.size.bytes()),
);
attributes::apply_to_llfn(llfn, llvm::AttributePlace::Argument(i), &[sret]);
if cx.sess().opts.optimize != config::OptLevel::No
&& llvm_util::get_version() >= (18, 0, 0)
{
if cx.sess().opts.optimize != config::OptLevel::No {
attributes::apply_to_llfn(
llfn,
llvm::AttributePlace::Argument(i),
Expand Down
18 changes: 4 additions & 14 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ use smallvec::SmallVec;
use tracing::{debug, instrument};

use crate::abi::FnAbiLlvmExt;
use crate::attributes;
use crate::common::Funclet;
use crate::context::CodegenCx;
use crate::llvm::{self, AtomicOrdering, AtomicRmwBinOp, BasicBlock, False, True};
use crate::type_::Type;
use crate::type_of::LayoutLlvmExt;
use crate::value::Value;
use crate::{attributes, llvm_util};

// All Builders must have an llfn associated with them
#[must_use]
Expand Down Expand Up @@ -1317,15 +1317,9 @@ impl<'a, 'll, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
}

fn apply_attrs_to_cleanup_callsite(&mut self, llret: &'ll Value) {
if llvm_util::get_version() < (17, 0, 2) {
// Work around https://github.com/llvm/llvm-project/issues/66984.
let noinline = llvm::AttributeKind::NoInline.create_attr(self.llcx);
attributes::apply_to_callsite(llret, llvm::AttributePlace::Function, &[noinline]);
} else {
// Cleanup is always the cold path.
let cold_inline = llvm::AttributeKind::Cold.create_attr(self.llcx);
attributes::apply_to_callsite(llret, llvm::AttributePlace::Function, &[cold_inline]);
}
// Cleanup is always the cold path.
let cold_inline = llvm::AttributeKind::Cold.create_attr(self.llcx);
attributes::apply_to_callsite(llret, llvm::AttributePlace::Function, &[cold_inline]);
}
}

Expand Down Expand Up @@ -1767,8 +1761,6 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
) {
debug!("mcdc_parameters() with args ({:?}, {:?}, {:?})", fn_name, hash, bitmap_bytes);

assert!(llvm_util::get_version() >= (18, 0, 0), "MCDC intrinsics require LLVM 18 or later");

let llfn = unsafe { llvm::LLVMRustGetInstrProfMCDCParametersIntrinsic(self.cx().llmod) };
let llty = self.cx.type_func(
&[self.cx.type_ptr(), self.cx.type_i64(), self.cx.type_i32()],
Expand Down Expand Up @@ -1802,7 +1794,6 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
"mcdc_tvbitmap_update() with args ({:?}, {:?}, {:?}, {:?}, {:?})",
fn_name, hash, bitmap_bytes, bitmap_index, mcdc_temp
);
assert!(llvm_util::get_version() >= (18, 0, 0), "MCDC intrinsics require LLVM 18 or later");

let llfn =
unsafe { llvm::LLVMRustGetInstrProfMCDCTVBitmapUpdateIntrinsic(self.cx().llmod) };
Expand Down Expand Up @@ -1844,7 +1835,6 @@ impl<'a, 'll, 'tcx> Builder<'a, 'll, 'tcx> {
"mcdc_condbitmap_update() with args ({:?}, {:?}, {:?}, {:?}, {:?})",
fn_name, hash, cond_loc, mcdc_temp, bool_value
);
assert!(llvm_util::get_version() >= (18, 0, 0), "MCDC intrinsics require LLVM 18 or later");
let llfn = unsafe { llvm::LLVMRustGetInstrProfMCDCCondBitmapIntrinsic(self.cx().llmod) };
let llty = self.cx.type_func(
&[
Expand Down
8 changes: 0 additions & 8 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,6 @@ pub(crate) unsafe fn create_module<'ll>(

let mut target_data_layout = sess.target.data_layout.to_string();
let llvm_version = llvm_util::get_version();
if llvm_version < (18, 0, 0) {
if sess.target.arch == "x86" || sess.target.arch == "x86_64" {
// LLVM 18 adjusts i128 to be 128-bit aligned on x86 variants.
// Earlier LLVMs leave this as default alignment, so remove it.
// See https://reviews.llvm.org/D86310
target_data_layout = target_data_layout.replace("-i128:128", "");
}
}

if llvm_version < (19, 0, 0) {
if sess.target.arch == "aarch64" || sess.target.arch.starts_with("arm64") {
Expand Down
25 changes: 2 additions & 23 deletions compiler/rustc_codegen_llvm/src/llvm_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,28 +258,14 @@ pub(crate) fn to_llvm_features<'a>(sess: &Session, s: &'a str) -> Option<LLVMFea
("aarch64", "fhm") => Some(LLVMFeature::new("fp16fml")),
("aarch64", "fp16") => Some(LLVMFeature::new("fullfp16")),
// Filter out features that are not supported by the current LLVM version
("aarch64", "faminmax") if get_version().0 < 18 => None,
("aarch64", "fp8") if get_version().0 < 18 => None,
("aarch64", "fp8dot2") if get_version().0 < 18 => None,
("aarch64", "fp8dot4") if get_version().0 < 18 => None,
("aarch64", "fp8fma") if get_version().0 < 18 => None,
("aarch64", "fpmr") if get_version().0 != 18 => None,
("aarch64", "lut") if get_version().0 < 18 => None,
("aarch64", "sme-f8f16") if get_version().0 < 18 => None,
("aarch64", "sme-f8f32") if get_version().0 < 18 => None,
("aarch64", "sme-fa64") if get_version().0 < 18 => None,
("aarch64", "sme-lutv2") if get_version().0 < 18 => None,
("aarch64", "ssve-fp8dot2") if get_version().0 < 18 => None,
("aarch64", "ssve-fp8dot4") if get_version().0 < 18 => None,
("aarch64", "ssve-fp8fma") if get_version().0 < 18 => None,
("aarch64", "v9.5a") if get_version().0 < 18 => None,
// In LLVM 18, `unaligned-scalar-mem` was merged with `unaligned-vector-mem` into a single feature called
// `fast-unaligned-access`. In LLVM 19, it was split back out.
("riscv32" | "riscv64", "unaligned-scalar-mem") if get_version().0 == 18 => {
Some(LLVMFeature::new("fast-unaligned-access"))
}
// For LLVM 18, enable the evex512 target feature if a avx512 target feature is enabled.
("x86", s) if get_version().0 >= 18 && s.starts_with("avx512") => {
// Enable the evex512 target feature if an avx512 target feature is enabled.
("x86", s) if s.starts_with("avx512") => {
Some(LLVMFeature::with_dependency(s, TargetFeatureFoldStrength::EnableOnly("evex512")))
}
(_, s) => Some(LLVMFeature::new(s)),
Expand Down Expand Up @@ -587,7 +573,6 @@ pub(crate) fn global_llvm_features(
// -Ctarget-features
if !only_base_features {
let supported_features = sess.target.supported_target_features();
let (llvm_major, _, _) = get_version();
let mut featsmap = FxHashMap::default();

// insert implied features
Expand Down Expand Up @@ -664,12 +649,6 @@ pub(crate) fn global_llvm_features(
return None;
}

// if the target-feature is "backchain" and LLVM version is greater than 18
// then we also need to add "+backchain" to the target-features attribute.
// otherwise, we will only add the naked `backchain` attribute to the attribute-group.
if feature == "backchain" && llvm_major < 18 {
return None;
}
// ... otherwise though we run through `to_llvm_features` when
// passing requests down to LLVM. This means that all in-language
// features also work on the command line instead of having two
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1048,7 +1048,18 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
},
);

err.span_suggestion(span, msg, "", Applicability::MaybeIncorrect);
if span.is_empty() {
// HACK: Avoid ICE when types with the same name with `derive`s are in the same scope:
// struct NotSM;
// #[derive(PartialEq, Eq)]
// struct NotSM<T>(T);
// With the above code, the suggestion would be to remove the generics of the first
// `NotSM`, which doesn't *have* generics, so we would suggest to remove no code with
// no code, which would trigger an `assert!` later. Ideally, we would do something a
// bit more principled. See closed PR #109082.
} else {
err.span_suggestion(span, msg, "", Applicability::MaybeIncorrect);
}
} else if redundant_lifetime_args && redundant_type_or_const_args {
remove_lifetime_args(err);
remove_type_or_const_args(err);
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_llvm/llvm-wrapper/ArchiveWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,14 +196,10 @@ extern "C" LLVMRustResult LLVMRustWriteArchive(
}
}

#if LLVM_VERSION_LT(18, 0)
auto Result = writeArchive(Dst, Members, WriteSymbtab, Kind, true, false);
#else
auto SymtabMode = WriteSymbtab ? SymtabWritingMode::NormalSymtab
: SymtabWritingMode::NoSymtab;
auto Result =
writeArchive(Dst, Members, SymtabMode, Kind, true, false, nullptr, isEC);
#endif
if (!Result)
return LLVMRustResult::Success;
LLVMRustSetLastError(toString(std::move(Result)).c_str());
Expand Down
13 changes: 3 additions & 10 deletions compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,10 @@ fromRust(LLVMRustCounterMappingRegionKind Kind) {
return coverage::CounterMappingRegion::GapRegion;
case LLVMRustCounterMappingRegionKind::BranchRegion:
return coverage::CounterMappingRegion::BranchRegion;
#if LLVM_VERSION_GE(18, 0)
case LLVMRustCounterMappingRegionKind::MCDCDecisionRegion:
return coverage::CounterMappingRegion::MCDCDecisionRegion;
case LLVMRustCounterMappingRegionKind::MCDCBranchRegion:
return coverage::CounterMappingRegion::MCDCBranchRegion;
#else
case LLVMRustCounterMappingRegionKind::MCDCDecisionRegion:
break;
case LLVMRustCounterMappingRegionKind::MCDCBranchRegion:
break;
#endif
}
report_fatal_error("Bad LLVMRustCounterMappingRegionKind!");
}
Expand Down Expand Up @@ -100,7 +93,7 @@ struct LLVMRustMCDCParameters {
// https://github.com/rust-lang/llvm-project/blob/66a2881a/llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h#L253-L263
// and representations in 19
// https://github.com/llvm/llvm-project/blob/843cc474faefad1d639f4c44c1cf3ad7dbda76c8/llvm/include/llvm/ProfileData/Coverage/MCDCTypes.h
#if LLVM_VERSION_GE(18, 0) && LLVM_VERSION_LT(19, 0)
#if LLVM_VERSION_LT(19, 0)
static coverage::CounterMappingRegion::MCDCParameters
fromRust(LLVMRustMCDCParameters Params) {
auto parameter = coverage::CounterMappingRegion::MCDCParameters{};
Expand All @@ -126,7 +119,7 @@ fromRust(LLVMRustMCDCParameters Params) {
}
report_fatal_error("Bad LLVMRustMCDCParametersTag!");
}
#elif LLVM_VERSION_GE(19, 0)
#else
static coverage::mcdc::Parameters fromRust(LLVMRustMCDCParameters Params) {
switch (Params.Tag) {
case LLVMRustMCDCParametersTag::None:
Expand Down Expand Up @@ -221,7 +214,7 @@ extern "C" void LLVMRustCoverageWriteMappingToBuffer(
RustMappingRegions, NumMappingRegions)) {
MappingRegions.emplace_back(
fromRust(Region.Count), fromRust(Region.FalseCount),
#if LLVM_VERSION_GE(18, 0) && LLVM_VERSION_LT(19, 0)
#if LLVM_VERSION_LT(19, 0)
// LLVM 19 may move this argument to last.
fromRust(Region.MCDCParameters),
#endif
Expand Down
42 changes: 4 additions & 38 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,19 @@
#include "llvm/Passes/StandardInstrumentations.h"
#include "llvm/Support/CBindingWrapping.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Target/TargetMachine.h"
#include "llvm/TargetParser/Host.h"
#include "llvm/Transforms/IPO/AlwaysInliner.h"
#include "llvm/Transforms/IPO/FunctionImport.h"
#include "llvm/Transforms/IPO/Internalize.h"
#include "llvm/Transforms/IPO/LowerTypeTests.h"
#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
#include "llvm/Transforms/Utils/AddDiscriminators.h"
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
#if LLVM_VERSION_GE(18, 0)
#include "llvm/TargetParser/Host.h"
#endif
#include "llvm/Support/TimeProfiler.h"
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
#include "llvm/Transforms/Instrumentation/DataFlowSanitizer.h"
#include "llvm/Transforms/Utils/AddDiscriminators.h"
#include "llvm/Transforms/Utils/FunctionImportUtils.h"
#if LLVM_VERSION_GE(19, 0)
#include "llvm/Support/PGOOptions.h"
#endif
Expand Down Expand Up @@ -240,11 +238,7 @@ enum class LLVMRustCodeGenOptLevel {
Aggressive,
};

#if LLVM_VERSION_GE(18, 0)
using CodeGenOptLevelEnum = llvm::CodeGenOptLevel;
#else
using CodeGenOptLevelEnum = llvm::CodeGenOpt::Level;
#endif

static CodeGenOptLevelEnum fromRust(LLVMRustCodeGenOptLevel Level) {
switch (Level) {
Expand Down Expand Up @@ -370,29 +364,23 @@ extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM,
}

extern "C" size_t LLVMRustGetTargetFeaturesCount(LLVMTargetMachineRef TM) {
#if LLVM_VERSION_GE(18, 0)
const TargetMachine *Target = unwrap(TM);
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
const ArrayRef<SubtargetFeatureKV> FeatTable =
MCInfo->getAllProcessorFeatures();
return FeatTable.size();
#else
return 0;
#endif
}

extern "C" void LLVMRustGetTargetFeature(LLVMTargetMachineRef TM, size_t Index,
const char **Feature,
const char **Desc) {
#if LLVM_VERSION_GE(18, 0)
const TargetMachine *Target = unwrap(TM);
const MCSubtargetInfo *MCInfo = Target->getMCSubtargetInfo();
const ArrayRef<SubtargetFeatureKV> FeatTable =
MCInfo->getAllProcessorFeatures();
const SubtargetFeatureKV Feat = FeatTable[Index];
*Feature = Feat.Key;
*Desc = Feat.Desc;
#endif
}

extern "C" const char *LLVMRustGetHostCPUName(size_t *len) {
Expand Down Expand Up @@ -569,17 +557,9 @@ enum class LLVMRustFileType {
static CodeGenFileType fromRust(LLVMRustFileType Type) {
switch (Type) {
case LLVMRustFileType::AssemblyFile:
#if LLVM_VERSION_GE(18, 0)
return CodeGenFileType::AssemblyFile;
#else
return CGFT_AssemblyFile;
#endif
case LLVMRustFileType::ObjectFile:
#if LLVM_VERSION_GE(18, 0)
return CodeGenFileType::ObjectFile;
#else
return CGFT_ObjectFile;
#endif
default:
report_fatal_error("Bad FileType.");
}
Expand Down Expand Up @@ -865,11 +845,7 @@ extern "C" LLVMRustResult LLVMRustOptimize(
// cargo run tests in multhreading mode by default
// so use atomics for coverage counters
Options.Atomic = true;
#if LLVM_VERSION_GE(18, 0)
MPM.addPass(InstrProfilingLoweringPass(Options, false));
#else
MPM.addPass(InstrProfiling(Options, false));
#endif
});
}

Expand Down Expand Up @@ -1210,15 +1186,9 @@ struct LLVMRustThinLTOData {

// Not 100% sure what these are, but they impact what's internalized and
// what's inlined across modules, I believe.
#if LLVM_VERSION_GE(18, 0)
DenseMap<StringRef, FunctionImporter::ImportMapTy> ImportLists;
DenseMap<StringRef, FunctionImporter::ExportSetTy> ExportLists;
DenseMap<StringRef, GVSummaryMapTy> ModuleToDefinedGVSummaries;
#else
StringMap<FunctionImporter::ImportMapTy> ImportLists;
StringMap<FunctionImporter::ExportSetTy> ExportLists;
StringMap<GVSummaryMapTy> ModuleToDefinedGVSummaries;
#endif
StringMap<std::map<GlobalValue::GUID, GlobalValue::LinkageTypes>> ResolvedODR;

LLVMRustThinLTOData() : Index(/* HaveGVs = */ false) {}
Expand Down Expand Up @@ -1270,11 +1240,7 @@ LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules, int num_modules,

Ret->ModuleMap[module->identifier] = mem_buffer;

#if LLVM_VERSION_GE(18, 0)
if (Error Err = readModuleSummaryIndex(mem_buffer, Ret->Index)) {
#else
if (Error Err = readModuleSummaryIndex(mem_buffer, Ret->Index, i)) {
#endif
LLVMRustSetLastError(toString(std::move(Err)).c_str());
return nullptr;
}
Expand Down
Loading
Loading