Skip to content

Commit 6e7dd2c

Browse files
committed
Auto merge of #150041 - Zalathar:rollup-sa5nez6, r=Zalathar
Rollup of 13 pull requests Successful merges: - #148756 (Warn on codegen attributes on required trait methods) - #148790 (Add new Tier-3 target: riscv64im-unknown-none-elf) - #149271 (feat: dlopen Enzyme) - #149459 (std: sys: fs: uefi: Implement set_times and set_perm) - #149771 (bootstrap readme: make easy to read when editor wrapping is not enabled) - #149856 (Provide an extended framework for type visit, for use in rust-analyzer) - #149950 (Simplify how inline asm handles `MaybeUninit`) - #150014 (Metadata loader cleanups) - #150021 (document that mpmc channels deliver an item to (at most) one receiver) - #150029 (Update books) - #150031 (assert impossible branch is impossible) - #150034 (do not add `I-prioritize` when `F-*` labels are present) - #150036 (Use the embeddable filename for coverage artifacts) r? `@ghost` `@rustbot` modify labels: rollup
2 parents cec7008 + f9d6cb5 commit 6e7dd2c

File tree

64 files changed

+1293
-494
lines changed

Some content is hidden

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

64 files changed

+1293
-494
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3613,6 +3613,7 @@ dependencies = [
36133613
"gimli 0.31.1",
36143614
"itertools",
36153615
"libc",
3616+
"libloading 0.9.0",
36163617
"measureme",
36173618
"object 0.37.3",
36183619
"rustc-demangle",

compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ impl<S: Stage> CombineAttributeParser<S> for AllowConstFnUnstableParser {
6161
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
6262
Allow(Target::Fn),
6363
Allow(Target::Method(MethodKind::Inherent)),
64-
Allow(Target::Method(MethodKind::Trait { body: false })),
6564
Allow(Target::Method(MethodKind::Trait { body: true })),
6665
Allow(Target::Method(MethodKind::TraitImpl)),
6766
]);

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ impl<S: Stage> NoArgsAttributeParser<S> for ColdParser {
5757
Allow(Target::Fn),
5858
Allow(Target::Method(MethodKind::Trait { body: true })),
5959
Allow(Target::Method(MethodKind::TraitImpl)),
60-
Allow(Target::Method(MethodKind::Trait { body: false })),
6160
Allow(Target::Method(MethodKind::Inherent)),
6261
Allow(Target::ForeignFn),
6362
Allow(Target::Closure),
@@ -343,7 +342,7 @@ impl<S: Stage> NoArgsAttributeParser<S> for TrackCallerParser {
343342
Allow(Target::Method(MethodKind::Inherent)),
344343
Allow(Target::Method(MethodKind::Trait { body: true })),
345344
Allow(Target::Method(MethodKind::TraitImpl)),
346-
Allow(Target::Method(MethodKind::Trait { body: false })),
345+
Allow(Target::Method(MethodKind::Trait { body: false })), // `#[track_caller]` is inherited from trait methods
347346
Allow(Target::ForeignFn),
348347
Allow(Target::Closure),
349348
Warn(Target::MacroDef),

compiler/rustc_attr_parsing/src/attributes/link_attrs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,6 @@ impl<S: Stage> SingleAttributeParser<S> for LinkSectionParser {
469469
Allow(Target::Static),
470470
Allow(Target::Fn),
471471
Allow(Target::Method(MethodKind::Inherent)),
472-
Allow(Target::Method(MethodKind::Trait { body: false })),
473472
Allow(Target::Method(MethodKind::Trait { body: true })),
474473
Allow(Target::Method(MethodKind::TraitImpl)),
475474
]);
@@ -587,12 +586,12 @@ impl<S: Stage> SingleAttributeParser<S> for LinkageParser {
587586
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
588587
Allow(Target::Fn),
589588
Allow(Target::Method(MethodKind::Inherent)),
590-
Allow(Target::Method(MethodKind::Trait { body: false })),
591589
Allow(Target::Method(MethodKind::Trait { body: true })),
592590
Allow(Target::Method(MethodKind::TraitImpl)),
593591
Allow(Target::Static),
594592
Allow(Target::ForeignStatic),
595593
Allow(Target::ForeignFn),
594+
Warn(Target::Method(MethodKind::Trait { body: false })), // Not inherited
596595
]);
597596

598597
const TEMPLATE: AttributeTemplate = template!(NameValueStr: [

compiler/rustc_attr_parsing/src/attributes/repr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ impl<S: Stage> AttributeParser<S> for AlignParser {
315315
Allow(Target::Method(MethodKind::Inherent)),
316316
Allow(Target::Method(MethodKind::Trait { body: true })),
317317
Allow(Target::Method(MethodKind::TraitImpl)),
318-
Allow(Target::Method(MethodKind::Trait { body: false })),
318+
Allow(Target::Method(MethodKind::Trait { body: false })), // `#[align]` is inherited from trait methods
319319
Allow(Target::ForeignFn),
320320
]);
321321

compiler/rustc_codegen_cranelift/src/inline_asm.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -857,19 +857,9 @@ fn call_inline_asm<'tcx>(
857857

858858
fn asm_clif_type<'tcx>(fx: &FunctionCx<'_, '_, 'tcx>, ty: Ty<'tcx>) -> Option<types::Type> {
859859
match ty.kind() {
860-
// Adapted from https://github.com/rust-lang/rust/blob/f3c66088610c1b80110297c2d9a8b5f9265b013f/compiler/rustc_hir_analysis/src/check/intrinsicck.rs#L136-L151
860+
// Adapted from https://github.com/rust-lang/rust/blob/df44a57fd29fca899ce473f85ed64efd0708dd7c/compiler/rustc_hir_typeck/src/inline_asm.rs#L180-L183
861861
ty::Adt(adt, args) if fx.tcx.is_lang_item(adt.did(), LangItem::MaybeUninit) => {
862-
let fields = &adt.non_enum_variant().fields;
863-
let ty = fields[FieldIdx::ONE].ty(fx.tcx, args);
864-
let ty::Adt(ty, args) = ty.kind() else {
865-
unreachable!("expected first field of `MaybeUninit` to be an ADT")
866-
};
867-
assert!(
868-
ty.is_manually_drop(),
869-
"expected first field of `MaybeUninit` to be `ManuallyDrop`"
870-
);
871-
let fields = &ty.non_enum_variant().fields;
872-
let ty = fields[FieldIdx::ZERO].ty(fx.tcx, args);
862+
let ty = args.type_at(0);
873863
fx.clif_type(ty)
874864
}
875865
_ => fx.clif_type(ty),

compiler/rustc_codegen_llvm/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ bitflags = "2.4.1"
1414
gimli = "0.31"
1515
itertools = "0.12"
1616
libc = "0.2"
17+
libloading = { version = "0.9.0", optional = true }
1718
measureme = "12.0.1"
1819
object = { version = "0.37.0", default-features = false, features = ["std", "read"] }
1920
rustc-demangle = "0.1.21"
@@ -46,7 +47,7 @@ tracing = "0.1"
4647
[features]
4748
# tidy-alphabetical-start
4849
check_only = ["rustc_llvm/check_only"]
49-
llvm_enzyme = []
50+
llvm_enzyme = ["dep:libloading"]
5051
llvm_offload = []
5152
# tidy-alphabetical-end
5253

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -528,31 +528,34 @@ fn thin_lto(
528528
}
529529
}
530530

531-
fn enable_autodiff_settings(ad: &[config::AutoDiff]) {
531+
#[cfg(feature = "llvm_enzyme")]
532+
pub(crate) fn enable_autodiff_settings(ad: &[config::AutoDiff]) {
533+
let mut enzyme = llvm::EnzymeWrapper::get_instance();
534+
532535
for val in ad {
533536
// We intentionally don't use a wildcard, to not forget handling anything new.
534537
match val {
535538
config::AutoDiff::PrintPerf => {
536-
llvm::set_print_perf(true);
539+
enzyme.set_print_perf(true);
537540
}
538541
config::AutoDiff::PrintAA => {
539-
llvm::set_print_activity(true);
542+
enzyme.set_print_activity(true);
540543
}
541544
config::AutoDiff::PrintTA => {
542-
llvm::set_print_type(true);
545+
enzyme.set_print_type(true);
543546
}
544547
config::AutoDiff::PrintTAFn(fun) => {
545-
llvm::set_print_type(true); // Enable general type printing
546-
llvm::set_print_type_fun(&fun); // Set specific function to analyze
548+
enzyme.set_print_type(true); // Enable general type printing
549+
enzyme.set_print_type_fun(&fun); // Set specific function to analyze
547550
}
548551
config::AutoDiff::Inline => {
549-
llvm::set_inline(true);
552+
enzyme.set_inline(true);
550553
}
551554
config::AutoDiff::LooseTypes => {
552-
llvm::set_loose_types(true);
555+
enzyme.set_loose_types(true);
553556
}
554557
config::AutoDiff::PrintSteps => {
555-
llvm::set_print(true);
558+
enzyme.set_print(true);
556559
}
557560
// We handle this in the PassWrapper.cpp
558561
config::AutoDiff::PrintPasses => {}
@@ -571,9 +574,9 @@ fn enable_autodiff_settings(ad: &[config::AutoDiff]) {
571574
}
572575
}
573576
// This helps with handling enums for now.
574-
llvm::set_strict_aliasing(false);
577+
enzyme.set_strict_aliasing(false);
575578
// FIXME(ZuseZ4): Test this, since it was added a long time ago.
576-
llvm::set_rust_rules(true);
579+
enzyme.set_rust_rules(true);
577580
}
578581

579582
pub(crate) fn run_pass_manager(
@@ -607,10 +610,6 @@ pub(crate) fn run_pass_manager(
607610
if enable_ad { write::AutodiffStage::DuringAD } else { write::AutodiffStage::PostAD }
608611
};
609612

610-
if enable_ad {
611-
enable_autodiff_settings(&config.autodiff);
612-
}
613-
614613
unsafe {
615614
write::llvm_optimize(cgcx, dcx, module, None, config, opt_level, opt_stage, stage);
616615
}

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,13 @@ pub(crate) unsafe fn llvm_optimize(
730730

731731
let llvm_plugins = config.llvm_plugins.join(",");
732732

733+
let enzyme_fn = if consider_ad {
734+
let wrapper = llvm::EnzymeWrapper::get_instance();
735+
wrapper.registerEnzymeAndPassPipeline
736+
} else {
737+
std::ptr::null()
738+
};
739+
733740
let result = unsafe {
734741
llvm::LLVMRustOptimize(
735742
module.module_llvm.llmod(),
@@ -749,7 +756,7 @@ pub(crate) unsafe fn llvm_optimize(
749756
vectorize_loop,
750757
config.no_builtins,
751758
config.emit_lifetime_markers,
752-
run_enzyme,
759+
enzyme_fn,
753760
print_before_enzyme,
754761
print_after_enzyme,
755762
print_passes,

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_codegen_ssa::traits::{BaseTypeCodegenMethods, ConstCodegenMethods};
77
use rustc_data_structures::fx::FxIndexMap;
88
use rustc_index::IndexVec;
99
use rustc_middle::ty::TyCtxt;
10-
use rustc_span::{RemapPathScopeComponents, SourceFile, StableSourceFileId};
10+
use rustc_span::{FileName, RemapPathScopeComponents, SourceFile, StableSourceFileId};
1111
use tracing::debug;
1212

1313
use crate::common::CodegenCx;
@@ -125,7 +125,19 @@ impl GlobalFileTable {
125125

126126
for file in all_files {
127127
raw_file_table.entry(file.stable_id).or_insert_with(|| {
128-
file.name.display(RemapPathScopeComponents::COVERAGE).to_string_lossy().into_owned()
128+
// Prefer using the embeddable filename as this filename is going to
129+
// end-up in the coverage artifacts (see rust-lang/rust#150020).
130+
if let FileName::Real(real) = &file.name {
131+
let (_work_dir, abs_name) =
132+
real.embeddable_name(RemapPathScopeComponents::COVERAGE);
133+
134+
abs_name.to_string_lossy().into_owned()
135+
} else {
136+
file.name
137+
.display(RemapPathScopeComponents::COVERAGE)
138+
.to_string_lossy()
139+
.into_owned()
140+
}
129141
});
130142
}
131143

0 commit comments

Comments
 (0)